PublicRpcService.php 121 KB

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