PublicRpcService.php 100 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511
  1. <?php
  2. namespace App\JsonRpc;
  3. use _PHPStan_62c6a0a8b\OndraM\CiDetector\Env;
  4. use App\Model\BlackWord;
  5. use App\Model\Department;
  6. use App\Model\District;
  7. use App\Model\LetterOfComplaint;
  8. use App\Model\LetterType;
  9. use App\Model\LevelUser;
  10. use App\Model\UserLevel;
  11. use App\Tools\Result;
  12. use Hyperf\DbConnection\Db;
  13. use Hyperf\Di\Annotation\Inject;
  14. use Hyperf\RpcServer\Annotation\RpcService;
  15. use App\Service\MinioService;
  16. use Hyperf\Redis\Redis;
  17. use Overtrue\ChineseCalendar\Calendar;
  18. use App\Model\TemplateClass;
  19. use App\Model\Template;
  20. use App\Model\WebsiteTemplate;
  21. use App\Model\WebsiteTemplateInfo;
  22. use App\Model\Sector;
  23. use App\Model\Component;
  24. use App\Model\Link;
  25. use App\Model\FooterCategory;
  26. use App\Model\Size;
  27. use function Hyperf\Support\retry;
  28. use Hyperf\Paginator\Paginator;
  29. use App\Model\User;
  30. use App\Model\Website;
  31. use App\Constants\ErrorCode;
  32. use GuzzleHttp\Client;
  33. use GuzzleHttp\Exception\GuzzleException;
  34. use App\Model\SectorPlace;
  35. use App\Model\ComponentType;
  36. use App\Model\Article;
  37. use App\Model\WebsiteCategory;
  38. use App\Model\AdPlace;
  39. use App\Model\WebsiteImg;
  40. use App\Model\SectorComponent;
  41. #[RpcService(name: "PublicRpcService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
  42. class PublicRpcService implements PublicRpcServiceInterface
  43. {
  44. #[Inject]
  45. protected Redis $redis;
  46. /**
  47. * @param array $data
  48. * @return array
  49. */
  50. public function getDistrictList(array $data): array
  51. {
  52. $where = [];
  53. if (isset($data['keyWord'])) {
  54. $where = [
  55. ['name', 'like', '%' . $data['keyWord'] . '%']
  56. ];
  57. }
  58. $result = [];
  59. if (isset($data['pageSize'])) {
  60. $rep = District::where($where)->limit($data['pageSize'])->offset(($data['page'] - 1) * $data['pageSize'])->orderBy("code", "asc")->get();
  61. $count = District::where($where)->count();
  62. $result = [
  63. 'rows' => $rep,
  64. 'count' => $count
  65. ];
  66. } else {
  67. $result = District::where($data)->orderBy("code", "asc")->get();
  68. }
  69. return $result ? Result::success($result) : Result::error("没有查到数据");
  70. }
  71. /**
  72. * @param array $data
  73. * @return array
  74. */
  75. public function getUserLevelList(array $data): array
  76. {
  77. $where = [];
  78. if (isset($data['keyWord'])) {
  79. $where = [
  80. ['name', 'like', '%' . $data['keyWord'] . '%'],
  81. ];
  82. }
  83. $result = [];
  84. if (isset($data['pageSize'])) {
  85. $rep = UserLevel::where($where)->limit($data['pageSize'])->offset(($data['page'] - 1) * $data['pageSize'])->orderBy("id", "asc")->get();
  86. $count = UserLevel::where($where)->count();
  87. $result = [
  88. 'rows' => $rep,
  89. 'count' => $count,
  90. ];
  91. } else {
  92. $result = UserLevel::orderBy("id", "asc")->get();
  93. }
  94. return $result ? Result::success($result) : Result::error("没有查到数据");
  95. }
  96. /**
  97. * 添加用户等级
  98. * @param array $data
  99. * @return array
  100. */
  101. public function addUserLevel(array $data): array
  102. {
  103. LevelUser::insertGetId($data);
  104. return Result::success([]);
  105. }
  106. /**
  107. * 更新等级
  108. * @param array $data
  109. * @return array
  110. */
  111. public function updateUserLevel(array $data): array
  112. {
  113. $result = LevelUser::where(['id' => $data['id']])->update($data);
  114. if ($result) {
  115. return Result::success($result);
  116. }
  117. return Result::error("更新失败");
  118. }
  119. /**
  120. * 删除等级
  121. * @param array $data
  122. * @return array
  123. */
  124. public function delUserLevel(array $data): array
  125. {
  126. $result = LevelUser::where(['id' => $data['id']])->delete();
  127. if ($result) {
  128. return Result::success($result);
  129. }
  130. return Result::error("删除失败");
  131. }
  132. /**
  133. * 查询投诉举报信息
  134. * @param array $data
  135. * @return array
  136. */
  137. public function getLetterOfComplaint(array $data = []): array
  138. {
  139. var_dump("====");
  140. $where = [];
  141. if (isset($data['user_id']) && !empty($data['user_id'])) {
  142. array_push($where, ['letter_of_complaint.user_id', '=', $data['user_id']]);
  143. }
  144. if (isset($data['nature']) && !empty($data['nature'])) {
  145. array_push($where, ['letter_of_complaint.nature', '=', $data['nature']]);
  146. }
  147. if (isset($data['nature_level0']) && !empty($data['nature_level0'])) {
  148. array_push($where, ['letter_of_complaint.nature_level0', '=', $data['nature_level0']]);
  149. }
  150. if (isset($data['status']) && !empty($data['status'])) {
  151. array_push($where, ['letter_of_complaint.status', '=', $data['status']]);
  152. }
  153. $result = [];
  154. if (isset($data['pageSize'])) {
  155. $rep = LetterOfComplaint::where($where)
  156. ->leftJoin("letter_type as type_a", "letter_of_complaint.nature", "type_a.id")
  157. ->leftJoin("letter_type as type_c", "letter_of_complaint.nature_level0", "type_c.id")
  158. ->leftJoin("letter_type as type_b", "letter_of_complaint.nature_level1", "type_b.id")
  159. ->leftJoin("letter_type as type_e", "letter_of_complaint.nature_level3", "type_e.id")
  160. ->leftJoin("letter_type as type_d", "letter_of_complaint.status", "type_d.id")
  161. ->select(
  162. "letter_of_complaint.*",
  163. "type_a.type_name as nature_name",
  164. "type_b.type_name as nature_name1",
  165. "type_c.type_name as nature_name0",
  166. "type_d.type_name as status_name",
  167. "type_e.type_name as nature_name3"
  168. )
  169. ->limit($data['pageSize'])->offset(($data['page'] - 1) * $data['pageSize'])->orderBy("letter_of_complaint.id", "desc")->get();
  170. $count = LetterOfComplaint::where($where)->count();
  171. if ($rep) {
  172. foreach ($rep as $val) {
  173. if ($val['judgment']) {
  174. $val['judgment'] = json_decode($val['judgment']);
  175. }
  176. if ($val['audio_and_video']) {
  177. $val['audio_and_video'] = json_decode($val['audio_and_video']);
  178. }
  179. if ($val['contract']) {
  180. $val['contract'] = json_decode($val['contract']);
  181. }
  182. if ($val['qualifications']) {
  183. $val['qualifications'] = json_decode($val['qualifications']);
  184. }
  185. }
  186. }
  187. $result = [
  188. 'rows' => $rep,
  189. 'count' => $count,
  190. ];
  191. } else {
  192. $result = LetterOfComplaint::where($where)
  193. ->leftJoin("letter_type as type_a", "letter_of_complaint.nature", "type_a.id")
  194. ->leftJoin("letter_type as type_c", "letter_of_complaint.nature_level0", "type_c.id")
  195. ->leftJoin("letter_type as type_b", "letter_of_complaint.nature_level1", "type_b.id")
  196. ->leftJoin("letter_type as type_e", "letter_of_complaint.nature_level3", "type_e.id")
  197. ->leftJoin("letter_type as type_d", "letter_of_complaint.status", "type_d.id")
  198. ->select(
  199. "letter_of_complaint.*",
  200. "type_a.type_name as nature_name",
  201. "type_b.type_name as nature_name1",
  202. "type_c.type_name as nature_name0",
  203. "type_d.type_name as status_name",
  204. "type_e.type_name as nature_name3"
  205. )
  206. ->orderBy("letter_of_complaint.id", "desc")->get();
  207. }
  208. return $result ? Result::success($result) : Result::error("没有查到数据");
  209. }
  210. /**
  211. * 添加投诉举报信息
  212. * @param array $data
  213. * @return array
  214. */
  215. public function addLetterOfComplaint(array $data): array
  216. {
  217. $data['judgment'] = $data['judgment'] ? json_encode($data['judgment']) : '';
  218. $data['audio_and_video'] = $data['audio_and_video'] ? json_encode($data['audio_and_video']) : '';
  219. $data['contract'] = $data['contract'] ? json_encode($data['contract']) : '';
  220. $data['qualifications'] = $data['qualifications'] ? json_encode($data['qualifications']) : '';
  221. unset($data['id']);
  222. $result = LetterOfComplaint::insertGetId($data);
  223. if (empty($result)) {
  224. return Result::error("创建失败", 0);
  225. } else {
  226. return Result::success(["id" => $result]);
  227. }
  228. }
  229. /**
  230. * 用户端更新投诉举报
  231. * @param array $data
  232. * @return array
  233. */
  234. public function userUpLetterOfComplaint(array $data): array
  235. {
  236. $data['judgment'] = $data['judgment'] ? json_encode($data['judgment']) : '';
  237. $data['audio_and_video'] = $data['audio_and_video'] ? json_encode($data['audio_and_video']) : '';
  238. $data['contract'] = $data['contract'] ? json_encode($data['contract']) : '';
  239. $data['qualifications'] = $data['qualifications'] ? json_encode($data['qualifications']) : '';
  240. $result = LetterOfComplaint::where(['id' => $data['id']])->update($data);
  241. if (empty($result)) {
  242. return Result::error("创建失败", 0);
  243. } else {
  244. return Result::success(["id" => $result]);
  245. }
  246. }
  247. /**
  248. * 管理后台更新投诉举报信息
  249. * @param array $data
  250. * @return array
  251. */
  252. public function upLetterOfComplaint(array $data): array
  253. {
  254. var_dump("admin:", $data);
  255. $where = [
  256. 'id' => $data['id'],
  257. ];
  258. $filtered_array = array_filter($data, function ($value) {
  259. return $value !== "" && $value !== null && $value !== false && !is_array($value) || !empty($value);
  260. });
  261. $filtered_array['judgment'] = isset($filtered_array['judgment']) ? json_encode($filtered_array['judgment']) : '';
  262. $filtered_array['audio_and_video'] = isset($filtered_array['audio_and_video']) ? json_encode($filtered_array['audio_and_video']) : '';
  263. $filtered_array['contract'] = isset($filtered_array['contract']) ? json_encode($filtered_array['contract']) : '';
  264. $filtered_array['qualifications'] = isset($filtered_array['qualifications']) ? json_encode($filtered_array['qualifications']) : '';
  265. unset($filtered_array['nature_name']);
  266. unset($filtered_array['type_name']);
  267. unset($filtered_array['nature_level_name']);
  268. unset($filtered_array['status_name']);
  269. unset($filtered_array['is_admin']);
  270. unset($filtered_array['type_level_name']);
  271. $result = LetterOfComplaint::where($where)->update($filtered_array);
  272. if ($result) {
  273. return Result::success($result);
  274. }
  275. return Result::error("更新失败", 0);
  276. }
  277. /**
  278. * 查询投诉举报记录
  279. * @param array $data
  280. * @return array
  281. */
  282. public function getLetterOfComplaintInfo(array $data): array
  283. {
  284. $where = [
  285. 'letter_of_complaint.id' => $data['id'],
  286. ];
  287. if (isset($data['user_id']) && !empty($data['user_id'])) {
  288. array_push($where, ['letter_of_complaint.user_id', '=', $data['user_id']]);
  289. }
  290. $result = LetterOfComplaint::where($where)
  291. ->leftJoin("letter_type as type_a", "letter_of_complaint.nature", "type_a.id")
  292. ->leftJoin("letter_type as type_c", "letter_of_complaint.nature_level0", "type_c.id")
  293. ->leftJoin("letter_type as type_b", "letter_of_complaint.nature_level1", "type_b.id")
  294. ->leftJoin("letter_type as type_e", "letter_of_complaint.nature_level3", "type_e.id")
  295. ->leftJoin("letter_type as type_d", "letter_of_complaint.status", "type_d.id")
  296. ->select(
  297. "letter_of_complaint.*",
  298. "type_a.type_name as nature_name",
  299. "type_b.type_name as nature_name1",
  300. "type_c.type_name as nature_name0",
  301. "type_d.type_name as status_name",
  302. "type_e.type_name as nature_name3"
  303. )
  304. ->first();
  305. return Result::success($result);
  306. }
  307. /**
  308. * 删除投诉举报信息
  309. * @param array $data
  310. * @return array
  311. */
  312. public function delLetterOfComplaint(array $data): array
  313. {
  314. $result = LetterOfComplaint::when($data, function ($query) use ($data) {
  315. if (isset($data['id']) && !empty($data['id'])) {
  316. $query->where(['id' => $data['id']]);
  317. }
  318. if (isset($data['user_id']) && !empty($data['user_id'])) {
  319. $query->where(['user_id' => $data['user_id']]);
  320. }
  321. })->delete();
  322. if (empty($result)) {
  323. return Result::error("删除失败", 0);
  324. } else {
  325. return Result::success();
  326. }
  327. }
  328. /**
  329. * 获取举报信息类型
  330. * @param array $data
  331. * @return array
  332. */
  333. public function getLetterType(array $data): array
  334. {
  335. $where = [];
  336. if (isset($data['type'])) {
  337. array_push($where, ['type', '=', $data['type']]);
  338. }
  339. if (isset($data['pid']) && $data['pid'] > 0) {
  340. array_push($where, ['pid', '=', $data['pid']]);
  341. }
  342. $result = LetterType::where($where)->orderBy('sort', 'asc')->get();
  343. return $result ? Result::success($result) : Result::error("没有查到数据");
  344. }
  345. /**
  346. * 更新举报类型
  347. * @param array $data
  348. * @return array
  349. */
  350. public function upLetterType(array $data): array
  351. {
  352. return [];
  353. }
  354. /**
  355. * 添加举报类型
  356. * @param array $data
  357. * @return array
  358. */
  359. public function addLetterType(array $data): array
  360. {
  361. $result = LetterType::insertGetId($data);
  362. if (empty($result)) {
  363. return Result::error("创建失败", 0);
  364. } else {
  365. return Result::success(["id" => $result]);
  366. }
  367. }
  368. /**
  369. * 删除举报类型
  370. * @param array $data
  371. * @return array
  372. */
  373. public function delLetterType(array $data): array
  374. {
  375. $result = LetterType::where('id', $data['id'])->delete();
  376. if (empty($result)) {
  377. return Result::error("删除失败", 0);
  378. } else {
  379. return Result::success();
  380. }
  381. }
  382. /**
  383. * 检测是否已经被接案
  384. * @param array $data
  385. * @return array
  386. */
  387. public function checkMeasure(array $data): array
  388. {
  389. $where = [
  390. 'id' => $data['id'],
  391. ];
  392. $letterOfComplaintInfo = LetterOfComplaint::where($where)->first();
  393. var_dump("查询数据:", $letterOfComplaintInfo['admin_id'], $data['user_id']);
  394. //操作人和当前登陆用户id 相等说明是当前人接收的案件
  395. if (($letterOfComplaintInfo['admin_id'] == $data['user_id']) || empty($letterOfComplaintInfo['admin_id'])) {
  396. return Result::success();
  397. } else {
  398. return Result::error("您不能处理其他人已经接过的案件", 0);
  399. }
  400. }
  401. /**
  402. * 后台获取职能部门
  403. * @param array $data
  404. * @return array
  405. */
  406. public function getZhinengbumenList(array $data): array
  407. {
  408. // 获取分页参数,默认每页 10 条记录
  409. $page = isset($data['page']) ? (int) $data['page'] : 1;
  410. $perPage = isset($data['pagesize']) ? (int) $data['pagesize'] : 10;
  411. // 查询数据并分页
  412. $query = Department::query();
  413. // 可以在这里添加更多的查询条件
  414. if (isset($data['search'])) {
  415. $query->where('name', 'like', '%' . $data['search'] . '%');
  416. }
  417. // 执行分页查询
  418. $result = $query->paginate($perPage, ['*'], 'page', $page);
  419. // 返回分页结果
  420. return Result::success([
  421. 'count' => $result->total(),
  422. 'current_page' => $result->currentPage(),
  423. 'last_page' => $result->lastPage(),
  424. 'pagesize' => $result->perPage(),
  425. 'rows' => $result->items(),
  426. ]);
  427. }
  428. /**
  429. * 添加获取职能部门
  430. * @param array $data
  431. * @return array
  432. */
  433. public function addZhinengbumen(array $data): array
  434. {
  435. $result = Department::insertGetId($data);
  436. if (empty($result)) {
  437. return Result::error("创建失败", 0);
  438. } else {
  439. return Result::success(["id" => $result]);
  440. }
  441. }
  442. public function delZhinengbumen(array $data): array
  443. {
  444. $result = Department::where('id', $data['id'])->delete();
  445. if (empty($result)) {
  446. return Result::error("删除失败", 0);
  447. } else {
  448. return Result::success();
  449. }
  450. }
  451. public function getZhinengbumen(array $data): array
  452. {
  453. $result = Department::where('id', $data['id'])
  454. ->orderBy('department', 'desc')
  455. ->first();
  456. return Result::success($result);
  457. }
  458. public function getPidZhinengbumen(array $data): array
  459. {
  460. if (empty($data['pid'])) {
  461. $data['pid'] = 0;
  462. }
  463. $result = Department::where('pid', $data['pid'])->get();
  464. return Result::success($result);
  465. }
  466. public function modZhinengbumen(array $data): array
  467. {
  468. $result = Department::where('id', $data['id'])->update($data);
  469. if (empty($result)) {
  470. return Result::error("修改失败", 0);
  471. } else {
  472. return Result::success();
  473. }
  474. }
  475. /**
  476. * 查询职能列表
  477. * @param array $data
  478. * @return array
  479. */
  480. public function getDepartment(array $data): array
  481. {
  482. $where = [];
  483. if (isset($data['pid'])) {
  484. $where = [
  485. 'pid' => $data['pid'] ?? 0
  486. ];
  487. }
  488. $result = Department::when(!empty($where), function ($query) use ($where) {
  489. $query->where($where);
  490. })->orderBy("sort", "desc")->get();
  491. if (empty($result)) {
  492. return Result::error("查询失败", 0);
  493. } else {
  494. return Result::success($result);
  495. }
  496. }
  497. /**
  498. * 获取所有的buckets
  499. * @param array $data
  500. * @return array
  501. */
  502. public function getBuckets(array $data): array
  503. {
  504. $result = new MinioService();
  505. // 调用服务层的方法获取存储桶列表
  506. $bucketsResponse = $result->listBuckets();
  507. // 直接返回服务层生成的响应
  508. return Result::success($bucketsResponse['data']);
  509. }
  510. /**
  511. * 上传文件
  512. * @param array $data
  513. * @return array
  514. */
  515. public function uploadFile(array $data): array
  516. {
  517. $result = new MinioService();
  518. $rep = $result->uploadFile($data);
  519. if ($rep['code'] == 200) {
  520. return Result::success($rep['data']);
  521. } else {
  522. return Result::error("上传失败!");
  523. }
  524. }
  525. /**
  526. * 黑名单管理
  527. * @param array $data
  528. * @return array
  529. */
  530. public function getBlackWordList(array $data): array
  531. {
  532. $result = BlackWord::when($data, function ($query) use ($data) {
  533. if (isset($data['name']) && $data['name']) {
  534. $query->where('black_word.name', 'like', '%' . $data['name'] . '%');
  535. }
  536. })->orderBy('black_word.id', 'desc')
  537. ->paginate(
  538. intval($data['pageSize']),
  539. [
  540. 'black_word.*',
  541. ],
  542. 'page',
  543. intval($data['page'])
  544. );
  545. $count = $result->total();
  546. $returnData = [
  547. 'rows' => $result->items(),
  548. 'count' => $count
  549. ];
  550. return Result::success($returnData);
  551. }
  552. /**
  553. * 添加黑名单
  554. * @param array $data
  555. * @return array
  556. */
  557. public function addBlackWord(array $data): array
  558. {
  559. Db::beginTransaction();
  560. try {
  561. $info = BlackWord::where(['name' => $data['name']])->first();
  562. if ($info) {
  563. Db::rollBack();
  564. return Result::error("该黑名单已存在", 0);
  565. }
  566. $data['type'] = 10;
  567. $result = BlackWord::insertGetId($data);
  568. $redisKey = 'black_word';
  569. $this->redis->sAdd($redisKey, $data['name']);
  570. Db::commit();
  571. return Result::success(["id" => $result]);
  572. } catch (\Exception $e) {
  573. Db::rollBack();
  574. return Result::error("创建失败" . $e->getMessage(), 0);
  575. }
  576. }
  577. /**
  578. * 删除黑名单
  579. * @param array $data
  580. * @return array
  581. */
  582. public function delBlackWord(array $data): array
  583. {
  584. Db::beginTransaction();
  585. try {
  586. BlackWord::where(['name' => $data['name']])->delete();
  587. $redisKey = 'black_word';
  588. $this->redis->sRem($redisKey, $data['name']);
  589. Db::commit();
  590. return Result::success([]);
  591. } catch (\Exception $e) {
  592. Db::rollBack();
  593. return Result::error("删除失败" . $e->getMessage(), 0);
  594. }
  595. }
  596. /**
  597. * 修改违禁词
  598. * @param array $data
  599. * @return array
  600. */
  601. public function upBlackWord(array $data): array
  602. {
  603. Db::beginTransaction();
  604. try {
  605. $checkInfo = BlackWord::where(['name' => $data['name']])->first();
  606. if ($checkInfo) {
  607. Db::rollBack();
  608. return Result::error("该违禁词已经存在", 0);
  609. }
  610. $blackWordInfo = BlackWord::where(['id' => $data['id']])->first();
  611. if ($blackWordInfo) {
  612. //先删除redis
  613. $blackWordInfo = $blackWordInfo->toArray();
  614. $redisKey = 'black_word';
  615. $this->redis->sRem($redisKey, $blackWordInfo['name']);
  616. $this->redis->sAdd($redisKey, $data['name']);
  617. BlackWord::where(['id' => $data['id']])->update(['name' => $data['name']]);
  618. Db::commit();
  619. return Result::success([]);
  620. } else {
  621. Db::rollBack();
  622. return Result::error("系统错误", 0);
  623. }
  624. } catch (\Exception $e) {
  625. Db::rollBack();
  626. return Result::error("修改失败" . $e->getMessage(), 0);
  627. }
  628. }
  629. /**
  630. * 获取风格
  631. * @return void
  632. */
  633. public function getTemplateClassList(array $data): array
  634. {
  635. $where = [];
  636. if (isset($data['name']) && $data['name']) {
  637. array_push($where, ['template_class.name', 'like', '%' . $data['name'] . '%']);
  638. }
  639. if (isset($data['keyword']) && $data['keyword']) {
  640. array_push($where, ['template_class.keyword', 'like', '%' . $data['keyword'] . '%']);
  641. }
  642. $template = TemplateClass::when($where, function ($query) use ($where) {
  643. $query->where($where);
  644. });
  645. $count = $template->count();
  646. // $countQuery = clone $template;
  647. $row = $template
  648. ->leftJoin('template', function ($join) {
  649. $join->on('template_class.class_id', '=', 'template.template_class_id');
  650. })
  651. ->select('template_class.*', DB::raw('COUNT(template.template_class_id) as template_count'))
  652. ->groupBy('template_class.id')
  653. ->orderBy('template_class.id', 'desc')
  654. ->offset(($data['page'] - 1) * $data['pageSize'])
  655. ->limit($data['pageSize'])
  656. ->get();
  657. $result = [
  658. 'rows' => $row,
  659. 'count' => $count,
  660. ];
  661. if ($row->isEmpty()) {
  662. return Result::error("暂无风格", 0);
  663. } else {
  664. return Result::success($result);
  665. }
  666. }
  667. /**
  668. * 添加风格
  669. * @param
  670. * @return void
  671. */
  672. public function addTemplateClass(array $data): array
  673. {
  674. $data['keyword'] = json_encode($data['keyword']);
  675. $template_class = TemplateClass::where('name', $data['name'])
  676. ->orWhere('class_id', $data['class_id'])
  677. ->first();
  678. if ($template_class) {
  679. return Result::error("风格名称或者风格编号已存在,不可添加!", 0);
  680. }
  681. $result = TemplateClass::insertGetId($data);
  682. if (empty($result)) {
  683. return Result::error("创建风格失败", 0);
  684. } else {
  685. return Result::success(["id" => $result]);
  686. }
  687. }
  688. /**
  689. * 更新风格
  690. * @param array $data
  691. * @return array
  692. */
  693. public function upTemplateClass(array $data): array
  694. {
  695. $where = [
  696. 'id' => $data['id'],
  697. ];
  698. $template_class = TemplateClass::where($where)->first();
  699. if (empty($template_class)) {
  700. return Result::error("未查询到风格", 0);
  701. }
  702. if ($template_class->type == 1) {
  703. return Result::error("默认风格不能修改", 0);
  704. }
  705. $template = TemplateClass::where('id', '!=', $data['id'])
  706. // ->where(['name' => $data['name']])
  707. // ->orWhere(['class_id' => $data['class_id']])
  708. ->where(function ($query) use ($data) {
  709. $query->where('name', $data['name'])
  710. ->orWhere('class_id', $data['class_id']);
  711. })
  712. ->first();
  713. if ($template) {
  714. return Result::error("风格名称或者风格编号已存在,不可编辑!", 0);
  715. }
  716. $updateData = [
  717. 'name' => $data['name'],
  718. 'keyword' => json_encode($data['keyword']),
  719. 'class_id' => $data['class_id'],
  720. ];
  721. $result = TemplateClass::where($where)->update($updateData);
  722. if (empty($result)) {
  723. return Result::error("更新失败", 0);
  724. } else {
  725. return Result::success($result);
  726. }
  727. }
  728. /**
  729. * 删除风格
  730. * @param array $data
  731. * @return array
  732. */
  733. public function delTemplateClass(array $data): array
  734. {
  735. $where = [
  736. 'id' => $data['id'],
  737. ];
  738. $template_class = TemplateClass::where($where)->first();
  739. if (empty($template_class)) {
  740. return Result::error("未查询到风格", 0);
  741. }
  742. if ($template_class->type == 1) {
  743. return Result::error("默认风格不能删除", 0);
  744. }
  745. $template = Template::where('template_class_id', $template_class['class_id'])->get();
  746. if (!empty($template->all())) {
  747. try {
  748. // 默认风格 1
  749. Db::beginTransaction();
  750. $template = Template::where('template_class_id', $template['class_id'])->update(['template_class_id' => 1]);
  751. if (empty($template)) {
  752. Db::rollBack();
  753. return Result::error("删除失败", 0);
  754. }
  755. $result = TemplateClass::where($where)->delete();
  756. } catch (\Exception $e) {
  757. return Result::error("删除失败" . $e->getMessage(), 0);
  758. }
  759. } else {
  760. $result = TemplateClass::where('id', $data['id'])->delete();
  761. }
  762. if (empty($result)) {
  763. return Result::error("删除失败", 0);
  764. }
  765. return Result::success($result);
  766. }
  767. /**
  768. * 根据风格名称-获取获取所有风格
  769. * @param array $data
  770. * @return array
  771. */
  772. public function getTemplateClass(array $data): array
  773. {
  774. $where = [];
  775. if (!empty($data['template_name'])) {
  776. $where['name'] = $data['template_name'];
  777. }
  778. $result = TemplateClass::where($where)->get();
  779. if (empty($result)) {
  780. return Result::error("暂无风格", 0);
  781. }
  782. return Result::success($result);
  783. }
  784. /**
  785. * 获取皮肤列表
  786. * @param array $data
  787. * @return array
  788. */
  789. public function getTemplateList(array $data): array
  790. {
  791. $where = [];
  792. if (!empty($data['template_class_id'])) {
  793. $where['template_class_id'] = $data['template_class_id'];
  794. }
  795. if (!empty($data['template_name'])) {
  796. array_push($where, ['template_name', 'like', '%' . $data['template_name'] . '%']);
  797. }
  798. if (!empty($data['template_keyword'])) {
  799. array_push($where, ['template_keyword', 'like', '%' . $data['template_keyword'] . '%']);
  800. }
  801. $result = Template::where($where)
  802. ->leftJoin('template_class', 'template.template_class_id', 'template_class.class_id')
  803. ->select('template.*', 'template_class.name as template_class_name')
  804. ->orderBy('template.id', 'desc')
  805. ->paginate($data['page_size'], ['*'], 'mypage_name', $data['page']);
  806. if (empty($result)) {
  807. return Result::error("暂无皮肤", 0);
  808. }
  809. return Result::success($result);
  810. }
  811. public function getTemplateInfo(array $data): array
  812. {
  813. $result = Template::where('template.id', $data['id'])
  814. ->leftJoin('template_class', 'template.template_class_id', 'template_class.class_id')
  815. ->select('template.*', 'template_class.name as template_class_name')
  816. ->first();
  817. if (empty($result)) {
  818. return Result::error("暂无皮肤", 0);
  819. }
  820. return Result::success($result);
  821. }
  822. /**
  823. * 添加皮肤
  824. * @param array $data
  825. * @return array
  826. */
  827. public function addTemplate(array $data): array
  828. {
  829. var_dump($data);
  830. unset($data['user_id']);
  831. $template = Template::where('template_name', $data['template_name'])
  832. ->orWhere('template_id', $data['template_id'])
  833. ->first();
  834. if ($template) {
  835. return Result::error("皮肤名称或者皮肤编号已存在,不可添加!", 0);
  836. }
  837. $data['template_keyword'] = json_encode($data['template_keyword']) ?? '';
  838. $page_type = json_decode($data['page_type'], true);
  839. $data['page_type'] = json_encode(array_values(array_unique($page_type)));
  840. $result = Template::insertGetId($data);
  841. if (empty($result)) {
  842. return Result::error("创建失败", 0);
  843. } else {
  844. return Result::success($result);
  845. }
  846. }
  847. /**
  848. * 删除皮肤
  849. * @param array $data
  850. * @return array
  851. */
  852. public function delTemplate(array $data): array
  853. {
  854. $rector = Sector::where('template_id', $data['id'])->first();
  855. if (!empty($rector)) {
  856. return Result::error("此皮肤已被绑定通栏,不可删除", 0);
  857. }
  858. $template = WebsiteTemplateInfo::where('template_id', $data['id'])->first();
  859. if (empty($template)) {
  860. return Result::error("此皮肤已被绑定网站,不可删除", 0);
  861. }
  862. if ($template->type == 1) {
  863. return Result::error("默认皮肤不能删除", 0);
  864. }
  865. $result = Template::where('id', $data['id'])->delete();
  866. var_dump($result, '-------------------delete');
  867. if ($result) {
  868. return Result::success($result);
  869. } else {
  870. return Result::error("删除失败", 0);
  871. }
  872. }
  873. /**
  874. * 更新皮肤
  875. * @param array $data
  876. * @return array
  877. */
  878. public function updateTemplate(array $data): array
  879. {
  880. unset($data['user_id']);
  881. $template = Template::where('id', $data['id'])
  882. ->first();
  883. if (empty($template)) {
  884. return Result::error("此皮肤不存在!", 0);
  885. }
  886. $template = Template::where('id', '!=', $data['id'])
  887. ->where(function ($query) use ($data) {
  888. $query->where('template_name', $data['template_name'])
  889. ->orWhere('template_id', $data['template_id']);
  890. })
  891. ->first();
  892. if ($template) {
  893. return Result::error("皮肤名称或者皮肤编号已存在,不可编辑!", 0);
  894. }
  895. $data['template_keyword'] = json_encode($data['template_keyword']) ?? '';
  896. $page_type = json_decode($data['page_type'], true);
  897. $data['page_type'] = json_encode(array_values(array_unique($page_type)));
  898. $result = Template::where('id', $data['id'])->update($data);
  899. var_dump($result, '-------------------update');
  900. if (!$result) {
  901. return Result::error("更新失败", 0);
  902. } else {
  903. return Result::success('更新成功');
  904. }
  905. }
  906. /**
  907. * 获取所有尺寸
  908. * @param array $data
  909. * @return array
  910. */
  911. public function getAllSize(array $data): array
  912. {
  913. if(isset($data['id']) && !empty($data['id'])){
  914. $result = Size::where('id', $data['id'])->get()->all();
  915. }else{
  916. $result = Size::get()->all();
  917. }
  918. if(empty($result)){
  919. return Result::error("暂无尺寸", 0);
  920. }
  921. return Result::success($result);
  922. }
  923. /**
  924. * 根据皮肤名称-获取所有皮肤
  925. * @param array $data
  926. * @return array
  927. */
  928. public function getAllTemplate(array $data): array
  929. {
  930. $where = [];
  931. if (isset($data['template_class_id']) && !empty($data['template_class_id'])) {
  932. $where[] = ['template_class_id', $data['template_class_id']];
  933. }
  934. if (isset($data['template_name']) && !empty($data['template_name'])) {
  935. $where[] = ['template_name', 'like', '%' . $data['template_name'] . '%'];
  936. }
  937. $result = Template::where($where)->get()->all();
  938. if (empty($result)) {
  939. return Result::error("暂无皮肤", 0);
  940. }
  941. return Result::success($result);
  942. }
  943. /**
  944. * 获取通栏列表
  945. * @param array $data
  946. * @return array
  947. */
  948. public function getSectorList(array $data): array
  949. {
  950. $where = [];
  951. if (isset($data['template_class_id']) && !empty($data['template_class_id'])) {
  952. $where['template.template_class_id'] = $data['template_class_id'];
  953. }
  954. if (isset($data['template_id']) && !empty($data['template_id'])) {
  955. array_push($where, ['template.template_id', $data['template_id']]);
  956. }
  957. if (isset($data['sector_name']) && !empty($data['sector_name'])) {
  958. array_push($where, ['sector.sector_name', 'like', '%' . $data['sector_name'] . '%']);
  959. }
  960. if (isset($data['width']) && !empty($data['width']) && isset($data['height']) && !empty($data['height'])) {
  961. $size_id = Size::where('width', 'like', '%' . $data['width'] . '%')->where('height', 'like', '%' . $data['height'] . '%')->pluck('id');
  962. } else if (isset($data['width']) && !empty($data['width'])) {
  963. $size_id = Size::where('width', 'like', '%' . $data['width'] . '%')->pluck('id');
  964. } else if (isset($data['height']) && !empty($data['height'])) {
  965. $size_id = Size::where('height', 'like', '%' . $data['height'] . '%')->pluck('id');
  966. } else {
  967. $size_id = [];
  968. }
  969. if(isset($data['page_type']) && !empty($data['page_type'])){
  970. array_push($where, ['sector.page_type', 'like', '%' . $data['page_type'] . '%']);
  971. }
  972. $result = Sector::when(!empty($size_id), function ($query) use ($size_id) {
  973. $query->whereIn('sector.size_id', $size_id);
  974. })
  975. ->leftJoin('size', 'size.id', '=', 'sector.size_id')
  976. ->leftJoin('template', 'template.template_id', '=', 'sector.template_id')
  977. ->leftJoin('template_class', 'template_class.class_id', '=', 'template.template_class_id')
  978. ->leftJoin('sector_place', 'sector_place.sector_type', '=', 'sector.place_type')
  979. ->where($where)
  980. ->where('sector_place.type_id', 1)
  981. ->select('sector.*', 'size.width', 'size.height', 'template_class.name as class_name', 'template_class.class_id', 'template.template_name',
  982. 'sector_place.name as place_name', 'sector_place.sector_img as place_img')
  983. ->orderBy('sector.id', 'desc')
  984. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  985. if(empty($result)){
  986. return Result::error('暂无通栏!');
  987. }
  988. return Result::success($result);
  989. }
  990. /**
  991. * 获取通栏详情
  992. * @param array $data
  993. * @return array
  994. */
  995. public function getSectorInfo(array $data): array
  996. {
  997. $where = [];
  998. $where[] = ['sector.id', '=', $data['id']];
  999. $result = Sector::where($where)
  1000. ->leftJoin('size', 'size.id', '=', 'sector.size_id')
  1001. ->select('sector.*', 'size.width', 'size.height')
  1002. ->orderBy('sector.id', 'desc')
  1003. ->first();
  1004. if (empty($result)) {
  1005. return Result::error('此通栏不存在!');
  1006. }
  1007. return Result::success($result);
  1008. }
  1009. /**
  1010. * 获取经纬度信息
  1011. * @return void
  1012. */
  1013. public function getIpInfo(array $data): array
  1014. {
  1015. if (empty($data['ip'])) {
  1016. // 在RPC服务中,依赖$_SERVER是不可靠的,强制要求调用方传入IP
  1017. return Result::error('IP地址不能为空!');
  1018. }
  1019. $client_ip = $data['ip'];
  1020. try {
  1021. // 直接从容器获取 Guzzle 客户端实例
  1022. /** @var \GuzzleHttp\Client $client */
  1023. $client = \Hyperf\Context\ApplicationContext::getContainer()->get(Client::class);
  1024. // 使用新的 GeoJS API 地址
  1025. $api_url = "https://get.geojs.io/v1/ip/geo/{$client_ip}.json";
  1026. // 将 timeout 作为请求选项传递
  1027. $response = $client->get($api_url, ['timeout' => 5]);
  1028. if ($response->getStatusCode() !== 200) {
  1029. return Result::error('IP查询接口请求失败,状态码:' . $response->getStatusCode());
  1030. }
  1031. $ip_info = json_decode($response->getBody()->getContents(), true);
  1032. // GeoJS 的成功响应不包含 'status' 字段,直接检查关键数据是否存在
  1033. if ($ip_info && isset($ip_info['latitude']) && isset($ip_info['longitude'])) {
  1034. // GeoJS 返回的经纬度是字符串,转换为浮点数
  1035. $ip_info['latitude'] = floatval($ip_info['latitude']);
  1036. $ip_info['longitude'] = floatval($ip_info['longitude']);
  1037. return Result::success($ip_info);
  1038. }
  1039. // 如果返回的数据不符合预期,提供一个通用错误
  1040. $errorMessage = $ip_info['message'] ?? '获取IP地理位置信息失败';
  1041. return Result::error($errorMessage);
  1042. } catch (GuzzleException $e) {
  1043. // 这个异常会给出详细的网络错误信息,如超时、无法解析域名等
  1044. return Result::error('请求IP查询接口异常: ' . $e->getMessage());
  1045. } catch (\Throwable $e) {
  1046. return Result::error('获取IP信息时发生未知错误: ' . $e->getMessage());
  1047. }
  1048. }
  1049. /**
  1050. * 获取天气
  1051. * @param array $data
  1052. * @return array
  1053. */
  1054. public function getWeatherInfo(array $data): array
  1055. {
  1056. $month = $data['month'] ?? date('m');
  1057. $day = $data['day'] ?? date('d');
  1058. // 使用缓存键
  1059. $cacheKey = "tsbb_data_weather_{$month}_{$day}";
  1060. // 尝试从缓存获取数据
  1061. $container = \Hyperf\Context\ApplicationContext::getContainer();
  1062. $cache = $container->get(\Psr\SimpleCache\CacheInterface::class);
  1063. if ($cachedData = $cache->get($cacheKey)) {
  1064. return Result::success(unserialize($cachedData));
  1065. }
  1066. $location = $data['latitude'] . ":" . $data['longitude'];
  1067. $api_url = "https://api.seniverse.com/v3/weather/now.json?key=" . \Hyperf\Support\env('WEATHER_KEY') . "&location=" . $location . "&language=zh-Hans&unit=c";
  1068. $ch = curl_init($api_url);
  1069. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  1070. $response = curl_exec($ch);
  1071. curl_close($ch);
  1072. // 解析 JSON 响应
  1073. $WeatherInfo = json_decode($response, true);
  1074. // 缓存结果,设置1小时过期
  1075. $cache->set($cacheKey, serialize($WeatherInfo), 3600);
  1076. if ($WeatherInfo) {
  1077. return Result::success($WeatherInfo);
  1078. } else {
  1079. return Result::error("获取天气失败", 0);
  1080. }
  1081. }
  1082. /**
  1083. * 获取农历信息
  1084. * @return void
  1085. */
  1086. public function getCalendar(array $data): array
  1087. {
  1088. $calendar = new Calendar();
  1089. $result = $calendar->solar($data['year'], $data['month'], $data['day'], $data['hour']); // 阳历
  1090. return Result::success($result);
  1091. }
  1092. /**
  1093. * 添加通栏
  1094. * @param array $data
  1095. * @return array
  1096. */
  1097. public function addSector(array $data): array
  1098. {
  1099. unset($data['user_id']);
  1100. // 对传入的 page_type 数组进行去重、转换为整数并重新索引
  1101. $data['page_type'] = array_values(array_unique(array_map('intval', $data['page_type'])));
  1102. $data['page_type'] = json_encode($data['page_type']);
  1103. $template = Template::where('template_id', $data['template_id'])
  1104. ->first();
  1105. if (empty($template)) {
  1106. return Result::error('皮肤不存在!');
  1107. }
  1108. $sector_id = Sector::where('sector_id',$data['sector_id'])->first();
  1109. if(!empty($sector_id)){
  1110. return Result::error('通栏编号已存在!');
  1111. }
  1112. $sector_place = SectorPlace::where('sector_type',$data['place_type'])->get();
  1113. if(empty($sector_place)){
  1114. return Result::error('位置不存在!');
  1115. }
  1116. $sort = json_decode($data['component_code'],true);
  1117. $kw = 0;
  1118. $flattened = [];
  1119. $component = [];
  1120. $sector_component = [];
  1121. foreach ($sort as $key => $subArray) {
  1122. foreach ($subArray as $k => $item) {
  1123. $component[] = $item;
  1124. $sector_component[] = [
  1125. 'sector_id' => $data['sector_id'],
  1126. 'component_id' => $item,
  1127. 'sort_id' => $key + 1,
  1128. 'place_id' => $data['place_type'],
  1129. ];
  1130. }
  1131. }
  1132. $component_num = count($component);
  1133. $count = count(array_unique($component));
  1134. // return Result::success($sector_component);
  1135. if(count($sort) != $data['component_num'] || $component_num != $count){
  1136. return Result::error('组件关联错误!');
  1137. }
  1138. // 通栏分类:1:资讯类:2:通栏广告类;3:混合类;4:头条类;5:轮播图类;
  1139. $sector_code = [
  1140. 'sectorName' => $data['sector_name'],
  1141. 'sectorId' => $data['sector_id'],
  1142. 'sectorType' => $data['sector_type'],
  1143. 'sectorPlace' => $data['place_type'],
  1144. ];
  1145. // return Result::success($sector_code);
  1146. $data['sector_code'] = json_encode($sector_code);
  1147. Db::beginTransaction();
  1148. try {
  1149. $com_sector = SectorComponent::insert($sector_component);
  1150. if(empty($com_sector)){
  1151. Db::rollBack();
  1152. return Result::error('通栏关联组件失败!');
  1153. }
  1154. // $up_component = Component::whereIn('component_type',$sector_component['component_id'])->update(['status' => 2]);
  1155. // if(empty($up_component)){
  1156. // Db::rollBack();
  1157. // return Result::error('通栏关联组件失败!');
  1158. // }
  1159. $result = Sector::insertGetId($data);
  1160. if (empty($result)) {
  1161. Db::rollBack();
  1162. return Result::error('添加失败');
  1163. }
  1164. Db::commit();
  1165. return Result::success($result);
  1166. } catch (\Exception $e) {
  1167. Db::rollBack();
  1168. return Result::error($e->getMessage());
  1169. }
  1170. }
  1171. /**
  1172. * 删除通栏
  1173. * @param array $data
  1174. * @return array
  1175. */
  1176. public function delSector(array $data): array
  1177. {
  1178. $sector = Sector::where('id', $data['id'])->first();
  1179. if (empty($sector)) {
  1180. return Result::error('通栏不存在!');
  1181. }
  1182. Db::beginTransaction();
  1183. try {
  1184. $component_id = SectorComponent::where('sector_id', $sector['sector_id'])->delete();
  1185. if (empty($component_id)) {
  1186. Db::rollBack();
  1187. return Result::error('解除相关组件关联关系失败!');
  1188. }
  1189. $result = Sector::where('id', $data['id'])->delete();
  1190. if (empty($result)) {
  1191. Db::rollBack();
  1192. return Result::error('通栏删除失败!');
  1193. }
  1194. Db::commit();
  1195. return Result::success('通栏删除成功!');
  1196. } catch (\Exception $e) {
  1197. Db::rollBack();
  1198. return Result::error($e->getMessage());
  1199. }
  1200. }
  1201. /**
  1202. * 修改通栏
  1203. * @param array $data
  1204. * @return array
  1205. */
  1206. public function updateSector(array $data): array
  1207. {
  1208. unset($data['user_id']);
  1209. $sector = Sector::where('id', $data['id'])->first();
  1210. if (empty($sector)) {
  1211. return Result::error('通栏不存在!');
  1212. }
  1213. if($sector['sector_id'] != $data['sector_id']){
  1214. $sector_id = Sector::where('sector_id',$data['sector_id'])->first();
  1215. if(!empty($sector_id)){
  1216. return Result::error('通栏编号已存在!');
  1217. }
  1218. }
  1219. $sector_code = [
  1220. 'sectorName' => strval($data['sector_name']),
  1221. 'sectorId' => intval($data['sector_id']),
  1222. 'sectorType' => intval($data['sector_type']),
  1223. 'sectorPlace' => intval($data['place_type']),
  1224. ];
  1225. // return Result::success($sector_code);
  1226. $data['sector_code'] = json_encode($sector_code);
  1227. // 对传入的 page_type 数组进行去重、转换为整数并重新索引
  1228. $data['page_type'] = array_values(array_unique(array_map('intval', $data['page_type'])));
  1229. $data['page_type'] = json_encode($data['page_type']);
  1230. $template = Template::where('template_id', $data['template_id'])
  1231. ->whereRaw("JSON_CONTAINS(template.page_type, ?)", [$data['page_type']])
  1232. ->first();
  1233. if (empty($template)) {
  1234. return Result::error('皮肤不存在!');
  1235. }
  1236. $sort = json_decode($data['component_code'],true);
  1237. $kw = 0;
  1238. $flattened = [];
  1239. $component = [];
  1240. $sector_component = [];
  1241. foreach ($sort as $key => $subArray) {
  1242. foreach ($subArray as $k => $item) {
  1243. $component[] = $item;
  1244. $sector_component[] = [
  1245. 'sector_id' => $data['sector_id'],
  1246. 'component_id' => $item,
  1247. 'sort_id' => $key + 1,
  1248. 'place_id' => $data['place_type'],
  1249. ];
  1250. }
  1251. }
  1252. // // 批量插入数据到 ComponentSector 表
  1253. // \App\Model\ComponentSector::insert($sector_component);
  1254. $component_num = count($component);
  1255. $count = count(array_unique($component));
  1256. // return Result::success($sector_component);
  1257. if(count($sort) != $data['component_num'] || $component_num != $count){
  1258. return Result::error('组件关联错误!');
  1259. }
  1260. $data['sector_code'] = json_encode($sector_code);
  1261. Db::beginTransaction();
  1262. try {
  1263. $com_sector = SectorComponent::where('sector_id', $data['sector_id'])->pluck('component_id');
  1264. if(empty($com_sector)){
  1265. Db::rollBack();
  1266. return Result::error('通栏解除组件关联失败!');
  1267. }
  1268. // $up_component = Component::whereIn('component_type',$com_sector)->update(['status' => 1]);
  1269. // if(empty($up_component)){
  1270. // Db::rollBack();
  1271. // return Result::error('通栏解除组件关联失败!');
  1272. // }
  1273. $del_SectorComponent = SectorComponent::where('sector_id', $data['sector_id'])->delete();
  1274. if(empty($del_SectorComponent)){
  1275. Db::rollBack();
  1276. return Result::error('通栏解除组件关联失败!');
  1277. }
  1278. $com_sector = SectorComponent::insert($sector_component);
  1279. if(empty($com_sector)){
  1280. Db::rollBack();
  1281. return Result::error('通栏关联组件失败!');
  1282. }
  1283. // $up_component = Component::whereIn('component_id',$sector_component['component_type'])
  1284. // ->update(['status' => 2,]);
  1285. // if(empty($up_component)){
  1286. // Db::rollBack();
  1287. // return Result::error('通栏关联组件失败!');
  1288. // }
  1289. $result = Sector::where('id', $data['id'])->update($data);
  1290. if (empty($result)) {
  1291. Db::rollBack();
  1292. return Result::error('修改失败');
  1293. }
  1294. Db::commit();
  1295. return Result::success($result);
  1296. } catch (\Exception $e) {
  1297. Db::rollBack();
  1298. return Result::error($e->getMessage());
  1299. }
  1300. }
  1301. public function getComponentList(array $data): array
  1302. {
  1303. $where = [];
  1304. if (isset($data['component_name']) && !empty($data['component_name'])) {
  1305. array_push($where, ['component.component_name', 'like', '%' . $data['component_name'] . '%']);
  1306. }
  1307. if (isset($data['width']) && !empty($data['width']) && isset($data['height']) && !empty($data['height'])) {
  1308. array_push($where, ['component.component_width', 'like', '%' . $data['width'] . '%']);
  1309. array_push($where, ['component.component_height', 'like', '%' . $data['height'] . '%']);
  1310. } else if (isset($data['width']) && !empty($data['width'])) {
  1311. array_push($where, ['component.component_width', 'like', '%' . $data['width'] . '%']);
  1312. } else if (isset($data['height']) && !empty($data['height'])) {
  1313. array_push($where, ['component.component_height', 'like', '%' . $data['height'] . '%']);
  1314. } else {
  1315. }
  1316. if(isset($data['type_id']) && !empty($data['type_id'])){
  1317. $where['component.type_id'] = $data['type_id'];
  1318. }
  1319. $result = Component::where($where)
  1320. ->leftJoin('component_type','component_type.id','=','component.type_id')
  1321. ->select( 'component.*', 'component_type.com_typename')
  1322. ->orderBy('component.updated_at', 'desc')
  1323. ->paginate($data['page_size'], ['*'], 'mypage_name', $data['page']);
  1324. if(empty($result)){
  1325. return Result::error('暂无数据');
  1326. }
  1327. return Result::success($result);
  1328. }
  1329. public function getComponentInfo(array $data): array
  1330. {
  1331. $where = ['component.id'=>$data['id']];
  1332. $result = Component::where($where)
  1333. ->leftJoin('component_type','component_type.id','=','component.type_id')
  1334. ->select( 'component.*','component_type.com_typename')
  1335. ->get();
  1336. if(empty($result)){
  1337. return Result::error('暂无数据');
  1338. }
  1339. return Result::success($result);
  1340. }
  1341. /*
  1342. 新增组件
  1343. */
  1344. public function addComponent(array $data): array
  1345. {
  1346. unset($data['user_id']);
  1347. $component_id = Component::where('component_type',$data['component_type'])->first();
  1348. if(!empty($component_id)){
  1349. return Result::error('组件编号已存在!');
  1350. }
  1351. $component_type = ComponentType::where('id',$data['type_id'])->first();
  1352. if(empty($component_type)){
  1353. return Result::error('组件分类不存在!');
  1354. }
  1355. // 组件分类:1:资讯-头条组件;2:资讯-轮播组件;3:资讯-推荐图类组件;4:资讯-最新类组件;5:资讯-推荐类;6:资讯-热点类组件;
  1356. // 7:资讯-栏目类组件;8:列表类组件;9:详情类组件;10:二级导航栏类组件;11:广告类;12:静态资源类;13:底部导航类;
  1357. $data['type_id'] = intval($data['type_id']);
  1358. $add_arr = [
  1359. // 'template_id' => intval($data['template_id']),
  1360. 'component_type' => intval($data['component_type']),
  1361. 'component_name' => $data['component_name'],
  1362. 'component_img' => $data['component_img'],
  1363. 'component_width' => $data['component_width'],
  1364. 'component_height' => $data['component_height'],
  1365. 'type_id' => intval($data['type_id']),
  1366. 'component_keyword' => $data['component_keyword'],
  1367. ];
  1368. $component_head_code = [
  1369. 'component_type' => $add_arr['component_type'],
  1370. 'type_id' => $add_arr['type_id'],
  1371. 'component_name' => $add_arr['component_name'],
  1372. ];
  1373. $add_arr['component_code'] = json_encode($component_head_code,true);
  1374. switch($data['type_id']){
  1375. case 1: //1:资讯-头条组件;
  1376. case 2: //2:资讯-轮播组件;
  1377. case 3: //3:资讯-推荐图类组件;
  1378. case 4: //4:资讯-最新类组件;
  1379. case 5: //5:资讯-推荐类组件;
  1380. case 6: //6:资讯-热点类组件;
  1381. $add_arr['level'] = $data['type_id'];
  1382. $add_arr['img_num'] = intval($data['img_num']);
  1383. $add_arr['text_num'] = intval($data['text_num']);
  1384. $component_data['componentData'] = [
  1385. 'category_id' => '',
  1386. 'level' => $add_arr['level'],
  1387. 'imgSize' => $data['img_num'] ?? '',
  1388. 'textSize' => $data['text_num'] ?? '',
  1389. 'child' => [
  1390. 'id' => '',
  1391. 'imgSize' => '',
  1392. 'textSize' => ''
  1393. ]
  1394. ];
  1395. $add_arr['component_data'] = json_encode($component_data, true);
  1396. $add_arr['component_column'] = $component_type['com_code'] ?? '';
  1397. break;
  1398. case 7: //7:资讯-栏目类组件;
  1399. $add_arr['img_num'] = intval($data['img_num']);
  1400. $add_arr['text_num'] = intval($data['text_num']);
  1401. $add_arr['child_imgnum'] = intval($data['child_imgnum'] ?? null);
  1402. $add_arr['child_textnum'] = intval($data['child_textnum'] ?? null);
  1403. $component_data['componentData'] = [
  1404. 'category_id' => '',
  1405. 'level' => '',
  1406. 'imgSize' => $add_arr['img_num'] ?? '',
  1407. 'textSize' => $add_arr['text_num'] ?? '',
  1408. 'child' => [
  1409. 'id' => '',
  1410. 'imgSize' => $add_arr['child_imgnum'] ?? '',
  1411. 'textSize' => $add_arr['child_textnum'] ?? '',
  1412. ]
  1413. ];
  1414. $add_arr['component_data'] = json_encode($component_data,true);
  1415. $add_arr['component_column'] = $component_type['com_code'] ?? '';
  1416. break;
  1417. case 8: //8:列表类组件;
  1418. $add_arr['pageSize'] = intval($data['pageSize']);
  1419. $component_data['componentData'] = [
  1420. 'category_id' => '',
  1421. 'pageType' => [
  1422. 'page' => 1,
  1423. 'pageSize' => $add_arr['pageSize'] ?? '',
  1424. ]
  1425. ];
  1426. $add_arr['component_data'] = json_encode($component_data,true);
  1427. $add_arr['component_column'] = $component_type['com_code'] ?? '';
  1428. break;
  1429. case 9: //9:详情类组件;
  1430. $component_data['componentData'] = [
  1431. 'article_id' => '',
  1432. ];
  1433. $add_arr['component_data'] = json_encode($component_data,true);
  1434. $add_arr['component_column'] = $component_type['com_code'] ?? '';
  1435. break;
  1436. case 10: //10:二级导航类组件;
  1437. $add_arr['cate_place'] = 1;
  1438. $add_arr['num'] = intval($data['num']);
  1439. $component_data['componentData'] = [
  1440. 'pid' => '',
  1441. 'placeid' => 1,
  1442. 'num' => $add_arr['num'],
  1443. ];
  1444. $add_arr['component_data'] = json_encode($component_data,true);
  1445. $add_arr['component_column'] = $component_type['com_code'] ?? '';
  1446. break;
  1447. case 11: //11:广告类;
  1448. $add_arr['ad_width'] = intval($data['ad_width']);
  1449. $add_arr['ad_height'] = intval($data['ad_height']);
  1450. $add_arr['component_width'] = intval($data['ad_width']);
  1451. $add_arr['component_height'] = intval($data['ad_height']);
  1452. $add_arr['ad_type'] = intval($data['ad_type']);
  1453. $add_arr['ad_img'] = $data['ad_img'];
  1454. $ad = [
  1455. 'width' => $add_arr['ad_width'],
  1456. 'height' => $add_arr['ad_height'],
  1457. 'name' => '',
  1458. 'price' => '',
  1459. 'introduce' => '',
  1460. 'website_id' => '',
  1461. 'thumb' => $add_arr['ad_img'],
  1462. 'typeid' => $add_arr['ad_type'],
  1463. 'ad_tag' => '',
  1464. ];
  1465. $add_arr['ad'] = json_encode($ad,true);
  1466. $add_arr['component_column'] = $component_type['com_code'] ?? '';
  1467. $add_arr['adimg_info'] = $data['img_info'];
  1468. $ad_imginfo = json_decode($data['img_info'],true);
  1469. break;
  1470. case 13: //13:底部导航类;
  1471. $component_data['componentData'] = [
  1472. 'fcat_id' => '',
  1473. ];
  1474. $add_arr['component_data'] = json_encode($component_data,true);
  1475. $add_arr['component_column'] = $component_type['com_code'] ?? '';
  1476. break;
  1477. case 14:
  1478. $add_arr['ad_width'] = intval($data['ad_width']);
  1479. $add_arr['ad_height'] = intval($data['ad_height']);
  1480. $add_arr['component_width'] = intval($data['component_width']);
  1481. $add_arr['component_height'] = intval($data['component_height']);
  1482. $add_arr['ad_type'] = intval($data['ad_type']);
  1483. $add_arr['ad_img'] = $data['ad_img'];
  1484. $add_arr['img_num'] = intval($data['img_num']);
  1485. $add_arr['text_num'] = intval($data['text_num']);
  1486. $add_arr['child_imgnum'] = intval($data['child_imgnum'] ?? null);
  1487. $add_arr['child_textnum'] = intval($data['child_textnum'] ?? null);
  1488. $component_data['componentData'] = [
  1489. 'category_id' => '',
  1490. 'level' => '',
  1491. 'imgSize' => $data['img_num'] ?? '',
  1492. 'textSize' => $data['text_num'] ?? '',
  1493. 'child' => [
  1494. 'id' => '',
  1495. 'imgSize' => $data['child_imgnum'] ?? '',
  1496. 'textSize' => $data['child_textnum'] ?? '',
  1497. ]
  1498. ];
  1499. $ad = [
  1500. 'width' => $add_arr['ad_width'],
  1501. 'height' => $add_arr['ad_height'],
  1502. 'name' => '',
  1503. 'price' => '',
  1504. 'introduce' => '',
  1505. 'website_id' => '',
  1506. 'thumb' => $add_arr['ad_img'],
  1507. 'typeid' => $add_arr['ad_type'],
  1508. 'ad_tag' => '',
  1509. ];
  1510. $add_arr['ad'] = json_encode($ad,true);
  1511. $add_arr['component_data'] = json_encode($component_data,true);
  1512. $add_arr['component_column'] = $component_type['com_code'] ?? '';
  1513. $add_arr['adimg_info'] = $data['img_info'];
  1514. $ad_imginfo = json_decode($data['img_info'],true);
  1515. break;
  1516. default:
  1517. break;
  1518. }
  1519. if($data['type_id'] == 11 || $data['type_id'] == 14){
  1520. Db::beginTransaction();
  1521. try{
  1522. $website_img = WebsiteImg::insertGetId($ad_imginfo);
  1523. var_dump($website_img);
  1524. $add_arr['ad_imgid'] = $website_img;
  1525. if(empty($website_img)){
  1526. Db::rollBack();
  1527. return Result::error('广告默认图上传失败!');
  1528. }
  1529. $result = Component::insertGetId($add_arr);
  1530. if(empty($result)){
  1531. Db::rollBack();
  1532. return Result::error('添加失败!');
  1533. }
  1534. Db::commit();
  1535. }catch(\Exception $e){
  1536. Db::rollback();
  1537. return Result::error('添加失败!');
  1538. }
  1539. }else{
  1540. $result = Component::insertGetId($add_arr);
  1541. if(empty($result)){
  1542. return Result::error('添加组件失败!');
  1543. }
  1544. }
  1545. return Result::success($result);
  1546. }
  1547. public function delComponent(array $data): array
  1548. {
  1549. $component = Component::where('id', $data['id'])->first();
  1550. if(empty($component)){
  1551. return Result::error('组件不存在!');
  1552. }
  1553. $component_id = SectorComponent::where('component_id', $component['component_type'])->first();
  1554. if (!empty($component_id)) {
  1555. return Result::error('请先解除相关组件关联关系!');
  1556. }
  1557. Db::beginTransaction();
  1558. try{
  1559. if($component['type_id'] == 11 || $component['type_id'] == 14){
  1560. $ad_img = WebsiteImg::where('id',$component['ad_imgid'])->first();
  1561. if(!empty($ad_img)){
  1562. $ad_img = WebsiteImg::where('id',$component['ad_imgid'])->delete();
  1563. if(empty($ad_img)){
  1564. Db::rollBack();
  1565. return Result::error('删除广告默认图失败!');
  1566. }
  1567. }
  1568. }
  1569. $result = Component::where('id',$data['id'])->delete();
  1570. if(empty($result)){
  1571. Db::rollBack();
  1572. return Result::error('删除失败!');
  1573. }
  1574. Db::commit();
  1575. return Result::success($result);
  1576. }catch(\Exception $e){
  1577. Db::rollback();
  1578. return Result::error('删除失败!');
  1579. }
  1580. }
  1581. public function updateComponent(array $data): array
  1582. {
  1583. unset($data['user_id']);
  1584. $id = $data['id'];
  1585. unset($data['id']);
  1586. $component_id = Component::where('id','!=',$id)->where('component_type',$data['component_type'])->first();
  1587. if(!empty($component_id) || $component_id != null){
  1588. return Result::error('组件编号已存在!');
  1589. }
  1590. $component_type = ComponentType::where('id',$data['type_id'])->first();
  1591. if(empty($component_type)){
  1592. return Result::error('组件分类不存在!');
  1593. }
  1594. $component = Component::where('id',$id)->first();
  1595. if(empty($component)){
  1596. return Result::error('组件不存在!');
  1597. }
  1598. // 组件分类:1:资讯-头条组件;2:资讯-轮播组件;3:资讯-推荐图类组件;4:资讯-最新类组件;5:资讯-推荐类;6:资讯-热点类组件;
  1599. // 7:资讯-栏目类组件;8:列表类组件;9:详情类组件;10:二级导航栏类组件;11:广告类;12:静态资源类;13:底部导航类;
  1600. $data['type_id'] = intval($data['type_id']);
  1601. $add_arr = [
  1602. // 'template_id' => intval($data['template_id']),
  1603. 'component_type' => intval($data['component_type']),
  1604. 'component_name' => $data['component_name'],
  1605. 'component_img' => $data['component_img'],
  1606. 'component_width' => $data['component_width'],
  1607. 'component_height' => $data['component_height'],
  1608. 'type_id' => intval($data['type_id']),
  1609. 'component_keyword' => $data['component_keyword'],
  1610. ];
  1611. $component_head_code = [
  1612. 'component_type' => $add_arr['component_type'],
  1613. 'type_id' => $add_arr['type_id'],
  1614. 'component_name' => $add_arr['component_name'],
  1615. ];
  1616. $add_arr['component_code'] = json_encode($component_head_code,true);
  1617. switch($data['type_id']){
  1618. case 1: //1:资讯-头条组件;
  1619. case 2: //2:资讯-轮播组件;
  1620. case 3: //3:资讯-推荐图类组件;
  1621. case 4: //4:资讯-最新类组件;
  1622. case 5: //5:资讯-推荐类组件;
  1623. case 6: //6:资讯-热点类组件;
  1624. $add_arr['level'] = $data['type_id'];
  1625. $add_arr['img_num'] = intval($data['img_num']);
  1626. $add_arr['text_num'] = intval($data['text_num']);
  1627. $component_data['componentData'] = [
  1628. 'category_id' => '',
  1629. 'level' => $add_arr['level'],
  1630. 'imgSize' => $data['img_num'] ?? '',
  1631. 'textSize' => $data['text_num'] ?? '',
  1632. 'child' => [
  1633. 'id' => '',
  1634. 'imgSize' => '',
  1635. 'textSize' => ''
  1636. ]
  1637. ];
  1638. $add_arr['component_data'] = json_encode($component_data, true);
  1639. $add_arr['component_column'] = $component_type['com_code'] ?? '';
  1640. break;
  1641. case 7: //7:资讯-栏目类组件;
  1642. $add_arr['img_num'] = intval($data['img_num']);
  1643. $add_arr['text_num'] = intval($data['text_num']);
  1644. $add_arr['child_imgnum'] = intval($data['child_imgnum'] ?? null);
  1645. $add_arr['child_textnum'] = intval($data['child_textnum'] ?? null);
  1646. $component_data['componentData'] = [
  1647. 'category_id' => '',
  1648. 'level' => '',
  1649. 'imgSize' => $add_arr['img_num'] ?? '',
  1650. 'textSize' => $add_arr['text_num'] ?? '',
  1651. 'child' => [
  1652. 'id' => '',
  1653. 'imgSize' => $add_arr['child_imgnum'] ?? '',
  1654. 'textSize' => $add_arr['child_textnum'] ?? '',
  1655. ]
  1656. ];
  1657. $add_arr['component_data'] = json_encode($component_data,true);
  1658. $add_arr['component_column'] = $component_type['com_code'] ?? '';
  1659. break;
  1660. case 8: //8:列表类组件;
  1661. $add_arr['pageSize'] = intval($data['pageSize']);
  1662. $component_data['componentData'] = [
  1663. 'category_id' => '',
  1664. 'pageType' => [
  1665. 'page' => 1,
  1666. 'pageSize' => $add_arr['pageSize'] ?? '',
  1667. ]
  1668. ];
  1669. $add_arr['component_data'] = json_encode($component_data,true);
  1670. $add_arr['component_column'] = $component_type['com_code'] ?? '';
  1671. break;
  1672. case 9: //9:详情类组件;
  1673. $component_data['componentData'] = [
  1674. 'article_id' => '',
  1675. ];
  1676. $add_arr['component_data'] = json_encode($component_data,true);
  1677. $add_arr['component_column'] = $component_type['com_code'] ?? '';
  1678. break;
  1679. case 10: //10:二级导航类组件;
  1680. $add_arr['cate_place'] = 1;
  1681. $add_arr['num'] = intval($data['num']);
  1682. $component_data['componentData'] = [
  1683. 'pid' => '',
  1684. 'placeid' => 1,
  1685. 'num' => $add_arr['num'],
  1686. ];
  1687. $add_arr['component_data'] = json_encode($component_data,true);
  1688. $add_arr['component_column'] = $component_type['com_code'] ?? '';
  1689. break;
  1690. case 11: //11:广告类;
  1691. $add_arr['ad_width'] = intval($data['ad_width']);
  1692. $add_arr['ad_height'] = intval($data['ad_height']);
  1693. $add_arr['component_width'] = intval($data['ad_width']);
  1694. $add_arr['component_height'] = intval($data['ad_height']);
  1695. $add_arr['ad_type'] = intval($data['ad_type']);
  1696. $add_arr['ad_img'] = $data['ad_img'];
  1697. $ad = [
  1698. 'width' => $add_arr['ad_width'],
  1699. 'height' => $add_arr['ad_height'],
  1700. 'name' => '',
  1701. 'price' => '',
  1702. 'introduce' => '',
  1703. 'website_id' => '',
  1704. 'thumb' => $add_arr['ad_img'],
  1705. 'typeid' => $add_arr['ad_type'],
  1706. 'ad_tag' => '',
  1707. ];
  1708. $add_arr['ad'] = json_encode($ad,true);
  1709. $add_arr['component_column'] = $component_type['com_code'] ?? '';
  1710. $add_arr['adimg_info'] = $data['img_info'];
  1711. $ad_imginfo = json_decode($data['img_info'],true);
  1712. break;
  1713. case 13: //13:底部导航类;
  1714. $component_data['componentData'] = [
  1715. 'fcat_id' => '',
  1716. ];
  1717. $add_arr['component_data'] = json_encode($component_data,true);
  1718. $add_arr['component_column'] = $component_type['com_code'] ?? '';
  1719. break;
  1720. case 14:
  1721. $add_arr['ad_width'] = intval($data['ad_width']);
  1722. $add_arr['ad_height'] = intval($data['ad_height']);
  1723. $add_arr['component_width'] = intval($data['component_width']);
  1724. $add_arr['component_height'] = intval($data['component_height']);
  1725. $add_arr['ad_type'] = intval($data['ad_type']);
  1726. $add_arr['ad_img'] = $data['ad_img'];
  1727. $add_arr['img_num'] = intval($data['img_num']);
  1728. $add_arr['text_num'] = intval($data['text_num']);
  1729. $add_arr['child_imgnum'] = intval($data['child_imgnum'] ?? null);
  1730. $add_arr['child_textnum'] = intval($data['child_textnum'] ?? null);
  1731. $component_data['componentData'] = [
  1732. 'category_id' => '',
  1733. 'level' => '',
  1734. 'imgSize' => $data['img_num'] ?? '',
  1735. 'textSize' => $data['text_num'] ?? '',
  1736. 'child' => [
  1737. 'id' => '',
  1738. 'imgSize' => $data['child_imgnum'] ?? '',
  1739. 'textSize' => $data['child_textnum'] ?? '',
  1740. ]
  1741. ];
  1742. $ad = [
  1743. 'width' => $add_arr['ad_width'],
  1744. 'height' => $add_arr['ad_height'],
  1745. 'name' => '',
  1746. 'price' => '',
  1747. 'introduce' => '',
  1748. 'website_id' => '',
  1749. 'thumb' => $add_arr['ad_img'],
  1750. 'typeid' => $add_arr['ad_type'],
  1751. 'ad_tag' => '',
  1752. ];
  1753. $add_arr['ad'] = json_encode($ad,true);
  1754. $add_arr['component_data'] = json_encode($component_data,true);
  1755. $add_arr['component_column'] = $component_type['com_code'] ?? '';
  1756. $add_arr['adimg_info'] = $data['img_info'];
  1757. $ad_imginfo = json_decode($data['img_info'],true);
  1758. break;
  1759. default:
  1760. break;
  1761. }
  1762. // var_dump("ad_imginfo:",$ad_imginfo);
  1763. $cll_column = [
  1764. 'img_num' => null,
  1765. 'text_num' => null,
  1766. 'child_imgnum' => null,
  1767. 'child_textnum' => null,
  1768. 'category_id' => null,
  1769. 'child_id' => null,
  1770. 'num' => null,
  1771. 'level' => null,
  1772. 'fcatid' => null,
  1773. 'article_id' => null,
  1774. 'cate_place' => null,
  1775. 'pageSize' => null,
  1776. 'ad_img' => null,
  1777. 'ad_width' => null,
  1778. 'ad_height' => null,
  1779. 'ad' => '',
  1780. 'ad_type' => null,
  1781. 'ad_imgid' => null,
  1782. 'adimg_info' => '[]',
  1783. ];
  1784. Db::beginTransaction();
  1785. try{
  1786. // return Result::success($add_arr);
  1787. if(($component['type_id'] == 11 || $component['type_id'] == 14) && ($data['type_id'] != 11 && $data['type_id'] != 14)){
  1788. $website_img = WebsiteImg::where('id',$component['ad_imgid'])->delete();
  1789. if(empty($website_img)){
  1790. Db::rollBack();
  1791. return Result::error('广告默认图删除失败!');
  1792. }
  1793. var_dump("删除",$website_img);
  1794. }
  1795. if(($data['type_id'] == 11 || $data['type_id'] == 14) && ($component['type_id'] != 11 && $component['type_id'] != 14)){
  1796. $website_img = WebsiteImg::insertGetId($ad_imginfo);
  1797. $add_arr['ad_imgid'] = $website_img;
  1798. if(empty($website_img)){
  1799. Db::rollBack();
  1800. return Result::error('广告默认图上传失败!');
  1801. }
  1802. var_dump("上传",$website_img);
  1803. }
  1804. if(($component['type_id'] == 11 || $component['type_id'] == 14) && ($data['type_id'] == 11 || $data['type_id'] == 14)){
  1805. $website_img = WebsiteImg::where('id',$component['ad_imgid'])->first();
  1806. if(empty($website_img)){
  1807. $website_img = WebsiteImg::insertGetId($ad_imginfo);
  1808. $add_arr['ad_imgid'] = $website_img;
  1809. }else{
  1810. $website_img = WebsiteImg::where('id',$component['ad_imgid'])->update($ad_imginfo);
  1811. $add_arr['ad_imgid'] = $component['ad_imgid'];
  1812. }
  1813. if(empty($website_img)){
  1814. Db::rollBack();
  1815. return Result::error('广告默认图修改失败!');
  1816. }
  1817. }
  1818. $add_arr = array_merge($cll_column,$add_arr);
  1819. $result = Component::where('id',$id)->update($add_arr);
  1820. if(empty($result)){
  1821. Db::rollBack();
  1822. return Result::error('修改失败!');
  1823. }
  1824. Db::commit();
  1825. }catch(\Exception $e){
  1826. Db::rollBack();
  1827. return Result::error('修改失败!');
  1828. }
  1829. return Result::success($result);
  1830. }
  1831. public function getWebsiteTemplateInfo(array $data)
  1832. {
  1833. $where = [];
  1834. if (isset($data['id'])) {
  1835. $where[] = ['id', '=', $data['id']];
  1836. }
  1837. $result = WebsiteTemplateInfo::where($where)
  1838. ->leftJoin('website', 'website_template_info.website_id', '=', 'website.id')
  1839. ->leftJoin('website_template', 'website_template_info.template_id', '=', 'website_template.id')
  1840. ->select('website_template_info.*', 'website.website_name')
  1841. ->get();
  1842. if ($result) {
  1843. return Result::success($result);
  1844. } else {
  1845. return Result::error('暂无数据');
  1846. }
  1847. }
  1848. /**
  1849. * 自助建站----1.获取页面类型回显
  1850. * @param array $data
  1851. * @return array
  1852. */
  1853. public function getWebPageType(array $data): array
  1854. {
  1855. // 1:图片 2:文字 3:底部
  1856. $friend_link = Link::where('website_id', $data['website_id'])->where('type', 3)->get();
  1857. if (empty($friend_link->toArray())) {
  1858. return Result::error('暂无友情链接数据!');
  1859. }
  1860. $footer_category = FooterCategory::where('website_id', $data['website_id'])->get();
  1861. if (empty($footer_category->toArray())) {
  1862. return Result::error('暂无底部导航数据!');
  1863. }
  1864. $page_type = WebsiteTemplateInfo::where('website_id', $data['website_id'])->value('page_type');
  1865. if (empty($page_type)) {
  1866. $page_type = [];
  1867. } else {
  1868. $page_type = json_decode($page_type, true);
  1869. }
  1870. // '网站页面类型(存数组)1:首页 2:分类页 3:列表页 4:详情页 5:搜索页 6:特殊列表 7:特殊详情页
  1871. if (isset($page_type) && in_array(5, $page_type)) {
  1872. $page_type = 1;
  1873. } else {
  1874. $page_type = 0;
  1875. }
  1876. $result = [
  1877. 'friend_link' => $friend_link,
  1878. 'footer_category' => $footer_category,
  1879. 'page_type' => $page_type,
  1880. ];
  1881. return Result::success($result);
  1882. }
  1883. /**
  1884. * 自助建站----2.添加页面类型
  1885. * @param array $data
  1886. * @return array
  1887. */
  1888. public function addWebPageType(array $data): array
  1889. {
  1890. // return Result::success($data);
  1891. // 1:首页 2:频道页 3:列表页 4:详情页 5:搜索页 6:特殊列表 7:特殊详情页'
  1892. if ($data['is_search'] == 1) {
  1893. $page_type = json_encode([1, 2, 3, 4, 5, 6, 7]);
  1894. } else {
  1895. $page_type = json_encode([1, 2, 3, 4, 6, 7]);
  1896. }
  1897. // 0:未构建;1:已填写基础信息;2:已选择模板; action_id
  1898. $website_template_info = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first();
  1899. // return Result::success($website_template_info);
  1900. // return Result::success(empty($website_template_info));
  1901. if (empty($website_template_info)) {
  1902. $result = WebsiteTemplateInfo::insertGetId(['website_id' => $data['website_id'], 'page_type' => $page_type, 'user_id' => $data['user_id']]);
  1903. } else {
  1904. if ($website_template_info['status'] == 2) {
  1905. return Result::error('网站已应用,不可再次修改!');
  1906. }
  1907. $result = WebsiteTemplateInfo::where('website_id', $data['website_id'])->update(['page_type' => $page_type], ['action_id' => 1, 'user_id' => $data['user_id']]);
  1908. }
  1909. if ($result) {
  1910. return Result::success($result);
  1911. } else {
  1912. return Result::error('添加失败');
  1913. }
  1914. }
  1915. /**
  1916. * 自助建站---流程---3.选择皮肤列表
  1917. * @param array $data
  1918. * @return array
  1919. */
  1920. public function getWebsiteTemplateList(array $data): array
  1921. {
  1922. $where = [];
  1923. if (isset($data['template_class_id']) && $data['template_class_id']) {
  1924. $where[] = ['template_class_id', '=', $data['template_class_id']];
  1925. }
  1926. // 0:未构建 1:未应用 2:已应用 status
  1927. $templste_info = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first();
  1928. if (empty($templste_info)) {
  1929. return Result::error('请先填写网站基础信息!');
  1930. }
  1931. if ($templste_info['status'] == 2) {
  1932. return Result::error('网站已应用,不可再次修改!');
  1933. }
  1934. if (isset($data['keyword']) && !empty($data['keyword'])) {
  1935. if (is_array($data['keyword'])) {
  1936. // 拼接多个模糊查询条件
  1937. $query = Template::query();
  1938. foreach ($data['keyword'] as $kw) {
  1939. $escapedKw = addcslashes($kw, '%_'); // 转义通配符
  1940. $query->WhereRaw("JSON_EXTRACT(template_keyword, '$[*]') LIKE ?", ["%$escapedKw%"]);
  1941. }
  1942. } else {
  1943. $escapedKeyword = addcslashes($data['keyword'], '%_'); // 转义通配符
  1944. $where[] = [DB::raw("JSON_EXTRACT(template_keyword, '$[*]') LIKE ?"), "%$escapedKeyword%"];
  1945. }
  1946. } else {
  1947. $query = Template::where($where);
  1948. }
  1949. $template_id = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first(['template_id', 'page_type']);
  1950. // return Result::success($template_id);
  1951. if (!empty($template_id['page_type']) && $templste_info['page_type'] != '[]' && is_string($templste_info['page_type'])) {
  1952. $template_page = is_string($templste_info['page_type']) ? json_decode($templste_info['page_type'], true) : [];
  1953. } else {
  1954. $template_page = [];
  1955. }
  1956. if (!empty($template_id['template_id'])) {
  1957. $result['template_id'] = $templste_info['template_id'];
  1958. }
  1959. // 确保 $template_page 为有效数据,避免 SQL 注入风险,这里使用参数绑定
  1960. $template_page_str = json_encode($template_page);
  1961. $result['template'] = $query->where($where)
  1962. ->whereRaw("JSON_CONTAINS(template.page_type, ?)", [$template_page_str])
  1963. ->orderBy('updated_at', 'desc')
  1964. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  1965. if (empty($result['template'])) {
  1966. $result['template'] = Template::orderBy('updated_at', 'desc')
  1967. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  1968. }
  1969. $template = WebsiteTemplateInfo::where('website_id', $data['website_id'])->value('template_id');
  1970. if ($template) {
  1971. $result['template_id'] = $template;
  1972. } else {
  1973. $result['template_id'] = 0;
  1974. }
  1975. return Result::success($result);
  1976. }
  1977. /**
  1978. * 自助建站---流程---4.选择皮肤
  1979. * @param array $data
  1980. * @return array
  1981. */
  1982. public function chooseWebsiteTemplate(array $data): array
  1983. {
  1984. $website_template_info = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first();
  1985. if (empty($website_template_info)) {
  1986. return Result::error('请先填写网站基础信息!');
  1987. }
  1988. // 0:未构建 1:未应用 2:已应用 status
  1989. if ($website_template_info['status'] == 2) {
  1990. return Result::error('网站已应用,不可再次修改!');
  1991. }
  1992. $template = Template::where('template_id', $data['template_id'])->first();
  1993. if (empty($template)) {
  1994. return Result::error('未查询到皮肤!');
  1995. }
  1996. // 0:未构建;1:已填写基础信息;2:已选择模板; action_id
  1997. $web_template = WebsiteTemplateInfo::where('website_id', $data['website_id'])->update(['template_id' => $data['template_id'], 'action_id' => 2]);
  1998. if ($web_template) {
  1999. return Result::success($web_template);
  2000. } else {
  2001. return Result::error('选择皮肤失败!');
  2002. }
  2003. }
  2004. /**
  2005. * 自助建站---流程---5.保存模版
  2006. * @param array $data
  2007. * @return array
  2008. */
  2009. public function saveWebsiteTemplate(array $data): array
  2010. {
  2011. // return Result::success($data);
  2012. $website_template_info = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first();
  2013. if (empty($website_template_info) || empty($website_template_info->template_id) || empty($website_template_info->page_type)) {
  2014. return Result::error('请先填写网站基础信息!');
  2015. }
  2016. // 0:未构建 1:未应用 2:已应用 status
  2017. if ($website_template_info['status'] == 2) {
  2018. return Result::error('网站已应用,不可再次保存!');
  2019. }
  2020. if ($website_template_info['action_id'] != 2) {
  2021. return Result::error('请完成之前的步骤!');
  2022. }
  2023. $template_info = WebsiteTemplate::where('website_id', $data['website_id'])->first();
  2024. // var_dump($data['template_data']);
  2025. try {
  2026. Db::beginTransaction();
  2027. if (empty($template_info)) {
  2028. $template = WebsiteTemplate::insertGetId([
  2029. 'website_id' => $data['website_id'],
  2030. 'template_data' => $data['template_data'],
  2031. 'user_id' => $data['user_id'],
  2032. 'canvas_data' => $data['canvas_data'],
  2033. 'page_type' => $website_template_info['page_type'],
  2034. 'template_id' => $website_template_info['template_id'],
  2035. ]);
  2036. } else {
  2037. $template = WebsiteTemplate::where('website_id', $data['website_id'])->update(
  2038. [
  2039. 'template_data' => $data['template_data'],
  2040. 'user_id' => $data['user_id'],
  2041. 'canvas_data' => $data['canvas_data'],
  2042. 'page_type' => $website_template_info['page_type'],
  2043. 'template_id' => $website_template_info['template_id'],
  2044. ]
  2045. );
  2046. }
  2047. if (empty($template)) {
  2048. Db::rollback();
  2049. return Result::error('保存失败!');
  2050. } else {
  2051. $tempalte_info = WebsiteTemplateInfo::where('website_id', $data['website_id'])->update(['status' => 1]);
  2052. if (empty($tempalte_info)) {
  2053. Db::rollback();
  2054. return Result::error('保存失败!');
  2055. }
  2056. Db::commit();
  2057. }
  2058. } catch (\Exception $e) {
  2059. return Result::error('模版数据格式错误!');
  2060. }
  2061. return Result::success($template);
  2062. }
  2063. /**
  2064. * 自助建站---流程---6.返显保存的模版
  2065. * @param array $data
  2066. * @return array
  2067. */
  2068. public function getWebsiteTemplate(array $data): array
  2069. {
  2070. $web = Website::where('id', $data['website_id'])->first();
  2071. if (empty($web)) {
  2072. return Result::error('未查询到网站信息!');
  2073. }
  2074. $template = WebsiteTemplate::where('website_id', $data['website_id'])
  2075. ->first(['website_id', 'template_id', 'page_type', 'template_data', 'canvas_data']);
  2076. if (empty($template)) {
  2077. return Result::error('未查询到模版!');
  2078. }
  2079. return Result::success($template);
  2080. }
  2081. /**
  2082. * 通栏版式管理-获取通栏版式列表
  2083. */
  2084. public function getSectorPlaceList(array $data): array
  2085. {
  2086. $where['sector_place.type_id'] = $data['type_id'];
  2087. if(isset($data['component_num']) && !empty($data['component_num'])){
  2088. $where['sector_place.component_num'] = $data['component_num'];
  2089. }
  2090. if(isset($data['sector_type']) && !empty($data['sector_type'])){
  2091. $where['sector_place.sector_type'] = $data['sector_type'];
  2092. }
  2093. // if(isset($data['component_type']) && !empty($data['component_type'])){
  2094. // $where['sector_place.component_type'] = $data['component_type'];
  2095. // }
  2096. if(isset($data['name']) && !empty($data['name'])){
  2097. array_push($where,['sector_place.name', 'like', '%'.$data['name'].'%']);
  2098. }
  2099. if (isset($data['width']) && !empty($data['width']) && isset($data['height']) && !empty($data['height'])){
  2100. array_push($where,['sector_place.width','like','%'.$data['width'].'%']);
  2101. array_push($where,['sector_place.height','like','%'.$data['height'].'%']);
  2102. } else if( isset($data['width']) && !empty($data['width'])){
  2103. array_push($where,['sector_place.width','like','%'.$data['width'].'%']);
  2104. }else if( isset($data['height']) && !empty($data['height'])){
  2105. array_push($where,['sector_place.height','like','%'.$data['height'].'%']);
  2106. }else{
  2107. $size_id = [];
  2108. }
  2109. $sector_place = SectorPlace::where($where)
  2110. // ->when(!empty($size_id), function ($query) use ($size_id) {
  2111. // $query->whereIn('sector_place.size_id', $size_id);
  2112. // })
  2113. // ->leftJoin('size','sector_place.size_id','=','size.id')
  2114. ->select('sector_place.*');
  2115. $result['count'] = $sector_place->count();
  2116. $result['row'] =$sector_place->paginate($data['page_size'], ['*'], 'page', $data['page']);
  2117. if(empty($result['count'])){
  2118. return Result::error("暂无相关版式数据!");
  2119. }
  2120. return Result::success($result);
  2121. }
  2122. /**
  2123. * 通栏版式管理-添加通栏版式
  2124. */
  2125. public function addSectorPlace(array $data): array
  2126. {
  2127. // 1:通栏;2:组件;
  2128. if($data['type_id'] == 1){
  2129. $sector_place = SectorPlace::where('sector_type', $data['type'])->first();
  2130. if(!empty($sector_place)){
  2131. return Result::error('通栏版式类别编号已存在!');
  2132. }
  2133. $data = [
  2134. 'name' => $data['name'],
  2135. 'component_num' => $data['component_num'],
  2136. 'size_id' => $data['size_id'],
  2137. 'sort_id' => 0,
  2138. 'sector_img' => $data['sector_img'],
  2139. 'sector_type' => $data['type'],
  2140. 'type_id' => $data['type_id'],
  2141. 'status' => 0,
  2142. ];
  2143. }else{
  2144. $sector_type = SectorPlace::where('sector_type', $data['sector_type'])->where('type_id',1)->first();
  2145. if(empty($sector_type)){
  2146. return Result::error('通栏版式类别不存在!');
  2147. }
  2148. // $com_query = SectorPlace::where('type_id',2);
  2149. // ->query(function($query) use ($data){
  2150. // $query->where('component_type', $data['type'])
  2151. // ->Subquery(function($subQuery) use ($data) {
  2152. // $subQuery->where('sector_type', $data['sector_type'])
  2153. // ->where('sort_id', $data['sort']);
  2154. // });
  2155. // }) //若是组件版式编号或者组件版式位置重复用此语句筛选
  2156. // ->where('sector_type',$data['sector_type']) //若是组件版式编号在同一个通栏版式下不重复就行,则启用此语句
  2157. $component = SectorPlace::where('type_id',2)->where('component_type',$data['type'])->first();
  2158. if(!empty($component)){
  2159. return Result::error('组件版式类别编号已存在!');
  2160. }
  2161. // $com_query = clone $com_query;
  2162. $com_num = SectorPlace::where('type_id',2)->where('sector_type',$data['sector_type'])->count('sort_id');
  2163. // return Result::success($com_num);
  2164. if($sector_type['component_num'] = $com_num){
  2165. $sector = SectorPlace::where('sector_type',$data['sector_type'])->where('type_id',1)->update(['status'=>1]);
  2166. if(empty($sector)){
  2167. return Result::error('通栏版式状态修改失败!');
  2168. }
  2169. }
  2170. $data = [
  2171. 'name' => $data['name'],
  2172. 'component_num' => 0,
  2173. 'size_id' => $data['size_id'],
  2174. 'sort_id' => $data['sort_id'],
  2175. 'sector_img' => $data['sector_img'],
  2176. 'component_type' => $data['type'],
  2177. 'type_id' => $data['type_id'],
  2178. 'sector_type' => $data['sector_type'],
  2179. ];
  2180. }
  2181. $result = SectorPlace::insertGetId($data);
  2182. if(empty($result)){
  2183. return Result::error('添加失败!');
  2184. }
  2185. return Result::success('添加成功!',$result);
  2186. }
  2187. /**
  2188. * 通栏版式管理-修改通栏版式
  2189. */
  2190. public function upSectorPlace(array $data): array
  2191. {
  2192. $id = $data['id'];
  2193. // 1:通栏;2:组件;
  2194. if($data['type_id'] == 1){
  2195. $sector_place = SectorPlace::where('id','!=',$id)->where('sector_type', $data['type'])->where('type_id',1)->first();
  2196. if(!empty($sector_place)){
  2197. return Result::error('通栏版式类别编号已存在!');
  2198. }
  2199. $data = [
  2200. 'name' => $data['name'],
  2201. 'component_num' => $data['component_num'],
  2202. 'size_id' => $data['size_id'],
  2203. 'sort_id' => 0,
  2204. 'sector_img' => $data['sector_img'],
  2205. 'sector_type' => $data['type'],
  2206. 'type_id' => $data['type_id'],
  2207. ];
  2208. }else{
  2209. $sector_type = SectorPlace::where('sector_type', $data['sector_type'])->where('type_id',1)->first();
  2210. if(empty($sector_type)){
  2211. return Result::error('通栏版式类别不存在!');
  2212. }
  2213. $component = SectorPlace::where('id','!=',$id)
  2214. ->where('component_type', $data['type'])
  2215. ->where('type_id',2)
  2216. ->first();
  2217. if(!empty($component)){
  2218. return Result::error('组件版式类别编号已存在!');
  2219. }
  2220. $data = [
  2221. 'name' => $data['name'],
  2222. 'component_num' => 0,
  2223. 'size_id' => $data['size_id'],
  2224. 'sort_id' => $data['sort_id'],
  2225. 'sector_img' => $data['sector_img'],
  2226. 'component_type' => $data['type'],
  2227. 'type_id' => $data['type_id'],
  2228. 'sector_type' => $data['sector_type'],
  2229. ];
  2230. }
  2231. $result = SectorPlace::where('id',$id)->update($data);
  2232. if(empty($result)){
  2233. return Result::error('修改失败!');
  2234. }
  2235. return Result::success('修改成功!',$result);
  2236. }
  2237. /**
  2238. * 通栏版式管理-删除通栏版式
  2239. */
  2240. public function delSectorPlace(array $data): array
  2241. {
  2242. $sector_place = SectorPlace::where('id',$data['id'])->first();
  2243. if(empty($sector_place)){
  2244. return Result::error('通栏版式不存在!');
  2245. }
  2246. if($sector_place['type_id'] == 1){
  2247. $sector = Sector::where('place_type', $sector_place['sector_type'])->first();
  2248. $component = SectorPlace::where('sector_type', $sector_place['sector_type'])
  2249. ->where('type_id',2)
  2250. ->first();
  2251. if(!empty($sector) || !empty($component)){
  2252. return Result::error('通栏版式分类已应用,暂不可删除!');
  2253. }
  2254. }else{
  2255. $sector = Component::where('place_type', $sector_place['component_type'])->first();
  2256. if(!empty($sector)){
  2257. return Result::error('组件版式分类已应用,暂不可删除!');
  2258. }
  2259. $component_num = SectorPlace::where('sector_type', $sector_place['sector_type'])
  2260. ->where('type_id',1)->update(['status'=> 0]);
  2261. if(empty($component_num)){
  2262. return Result::error('通栏版式状态修改失败!');
  2263. }
  2264. }
  2265. $result = SectorPlace::where('id',$data['id'])->delete();
  2266. if(empty($result)){
  2267. return Result::error('删除失败!');
  2268. }
  2269. return Result::success('删除成功!');
  2270. }
  2271. /**
  2272. * 自助建站-通栏版式管理-获取通栏版式详情
  2273. */
  2274. public function getSectorPlaceInfo(array $data): array
  2275. {
  2276. $result = SectorPlace::where('sector_place.id',$data['id'])
  2277. ->leftJoin('size','sector_place.size_id','=','size.id')
  2278. ->select('sector_place.*','size.width','size.height')
  2279. ->first();
  2280. if(empty($result)){
  2281. return Result::error('通栏版式不存在!');
  2282. }
  2283. return Result::success($result);
  2284. }
  2285. /**
  2286. * 自助建站-通栏版式管理-获取通栏版式列表
  2287. */
  2288. public function getSectorPlaceSort(array $data): array
  2289. {
  2290. $sector = SectorPlace::where('sector_type',$data['sector_type'])->first();
  2291. if(empty($sector)){
  2292. return Result::error('通栏版式不存在!');
  2293. }
  2294. $component = SectorPlace::where('type_id',2)->where('sector_type',$sector['sector_type'])->pluck('sort_id')->toArray();
  2295. if(count($component) < $sector['component_num']){
  2296. // 根据 $sector['component_num'] 的值生成对应元素数量的数组
  2297. if (isset($sector['component_num']) && is_numeric($sector['component_num'])) {
  2298. $num = intval($sector['component_num']);
  2299. if ($num > 0 && $num <= 10) {
  2300. // 使用 range 函数生成一个从 1 到 $num 的连续整数数组,存储到 $sector_arr 中
  2301. $sector_arr = range(1, $num);
  2302. } else {
  2303. $sector_arr = [];
  2304. }
  2305. } else {
  2306. $sector_arr = [];
  2307. }
  2308. // 获取 $sector_arr 中不在 $component 里的元素
  2309. $sort = array_diff($sector_arr, $component);
  2310. // return Result::success($sort);
  2311. }
  2312. if(!empty($sort)){
  2313. $sort = array_values(array_map(function($value) {
  2314. return ['id' => $value];
  2315. }, $sort));
  2316. }else{
  2317. return Result::error("组件版式数量已达上限!");
  2318. }
  2319. return Result::success($sort);
  2320. }
  2321. /**
  2322. * 获取所有通栏版式
  2323. */
  2324. public function getAllSectorPlace(array $data): array
  2325. {
  2326. $where['type_id'] = $data['type_id'];
  2327. // if($data['type_id'] == 1){
  2328. // $where['status'] = 1;
  2329. // }
  2330. if(isset($data['sector_type']) && !empty($data['sector_type'])){
  2331. $where['sector_type'] = $data['sector_type'];
  2332. }
  2333. if(isset($data['component_num']) && !empty($data['component_num'])){
  2334. $where['component_num'] = $data['component_num'];
  2335. }
  2336. $sector_place = SectorPlace::where($where)
  2337. // ->select('sector_place.*','size.width','size.height')
  2338. ->get()->all();
  2339. if($data['type_id'] == 2){
  2340. foreach($sector_place as $key => $value){
  2341. $sector_place[$key]['component'] = Component::where('type_id',$value['type'])
  2342. ->where('component_width',$value['width'])
  2343. ->where('component_height',$value['height'])
  2344. ->get()->all();
  2345. }
  2346. }
  2347. if(empty($sector_place)){
  2348. return Result::error('通栏版式不存在!');
  2349. }
  2350. return Result::success($sector_place);
  2351. }
  2352. /**
  2353. * 组件管理-获取组件类型
  2354. */
  2355. public function getComponentType(array $data): array
  2356. {
  2357. $where = [];
  2358. if(isset($data['id']) && !empty($data['id'])){
  2359. $where['id'] = $data['id'];
  2360. }
  2361. $component_type = ComponentType::where($where)->get()->all();
  2362. if(empty($component_type)){
  2363. return Result::error('组件类型不存在!');
  2364. }
  2365. if(count($component_type) == 1){
  2366. $all_code = json_decode($component_type[0]['com_code'] ?? '',true);
  2367. $component_type[0]['all_code'] = $all_code['listType'] ?? [];
  2368. $result = $component_type[0];
  2369. }else{
  2370. $result = $component_type;
  2371. }
  2372. if(empty($component_type)){
  2373. return Result::error('组件类型不存在!');
  2374. }
  2375. return Result::success($component_type);
  2376. }
  2377. /**
  2378. * 组件管理-获取所有组件
  2379. */
  2380. public function getAllComponent(array $data): array
  2381. {
  2382. $where = [];
  2383. if((isset($data['sector_id']) && !empty($data['sector_id'])) || (isset($data['sort_id']) && !empty($data['sort_id']))){
  2384. $sector['sector_component.sector_id'] = $data['sector_id'];
  2385. $sector['sector_component.sort_id'] = $data['sort_id'];
  2386. $where = SectorComponent::where($sector)->pluck('component_id')->toArray();
  2387. $component = Component::whereIn('id',$where)->get()->all();
  2388. }else{
  2389. if(isset($data['type_id']) && !empty($data['type_id'])){
  2390. $where['component.type_id'] = $data['type_id'];
  2391. }
  2392. if(isset($data['width']) && !empty($data['width'])){
  2393. $where['component.component_width'] = $data['width'];
  2394. }
  2395. if(isset($data['height']) && !empty($data['height'])){
  2396. $where['component.component_height'] = $data['height'];
  2397. }
  2398. $component = Component::where($where)
  2399. // ->leftJoin('size','component.size_id','=','size.id')
  2400. // ->select('component.*','size.width','size.height')
  2401. ->get()->all();
  2402. }
  2403. if(empty($component)){
  2404. return Result::error('组件不存在!');
  2405. }
  2406. return Result::success($component);
  2407. }
  2408. /**
  2409. * 自助建站-流程管理-获取所有通栏
  2410. */
  2411. public function getAllSector(array $data): array
  2412. {
  2413. $where = [];
  2414. if(isset($data['template_id']) && !empty($data['template_id'])){
  2415. $where['template_id'] = $data['template_id'];
  2416. }
  2417. if(isset($data['page_type']) && !empty($data['page_type'])){
  2418. array_push($where,['page_type', 'like', '%'.$data['page_type'].'%']);
  2419. }
  2420. if(isset($data['status']) && !empty($data['status'])){
  2421. array_push($where,['status','!=',0]);
  2422. }
  2423. $sector = Sector::where($where)
  2424. ->leftJoin('size','sector.size_id','=','size.id')
  2425. ->select('sector.*','size.width','size.height')
  2426. ->get()->all();
  2427. if(empty($sector)){
  2428. return Result::error('通栏不存在!');
  2429. }
  2430. return Result::success($sector);
  2431. }
  2432. }