PublicRpcService.php 101 KB

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