PublicRpcService.php 107 KB

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