PublicRpcService.php 94 KB

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