PublicRpcService.php 51 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399
  1. <?php
  2. namespace App\JsonRpc;
  3. use App\Model\BlackWord;
  4. use App\Model\Department;
  5. use App\Model\District;
  6. use App\Model\LetterOfComplaint;
  7. use App\Model\LetterType;
  8. use App\Model\LevelUser;
  9. use App\Model\UserLevel;
  10. use App\Tools\Result;
  11. use Hyperf\DbConnection\Db;
  12. use Hyperf\Di\Annotation\Inject;
  13. use Hyperf\RpcServer\Annotation\RpcService;
  14. use App\Service\MinioService;
  15. use Hyperf\Redis\Redis;
  16. use Overtrue\ChineseCalendar\Calendar;
  17. use App\Model\TemplateClass;
  18. use App\Model\Template;
  19. use App\Model\WebsiteTemplate;
  20. use App\Model\WebsiteTemplateInfo;
  21. use App\Model\Sector;
  22. use App\Model\Component;
  23. use App\Model\Link;
  24. use App\Model\FooterCategory;
  25. use App\Model\Size;
  26. #[RpcService(name: "PublicRpcService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
  27. class PublicRpcService implements PublicRpcServiceInterface
  28. {
  29. #[Inject]
  30. protected Redis $redis;
  31. /**
  32. * @param array $data
  33. * @return array
  34. */
  35. public function getDistrictList(array $data): array
  36. {
  37. $where = [];
  38. if (isset($data['keyWord'])) {
  39. $where = [
  40. ['name', 'like', '%' . $data['keyWord'] . '%']
  41. ];
  42. }
  43. $result = [];
  44. if (isset($data['pageSize'])) {
  45. $rep = District::where($where)->limit($data['pageSize'])->offset(($data['page'] - 1) * $data['pageSize'])->orderBy("code", "asc")->get();
  46. $count = District::where($where)->count();
  47. $result = [
  48. 'rows' => $rep,
  49. 'count' => $count
  50. ];
  51. } else {
  52. $result = District::where($data)->orderBy("code", "asc")->get();
  53. }
  54. return $result ? Result::success($result) : Result::error("没有查到数据");
  55. }
  56. /**
  57. * @param array $data
  58. * @return array
  59. */
  60. public function getUserLevelList(array $data): array
  61. {
  62. $where = [];
  63. if (isset($data['keyWord'])) {
  64. $where = [
  65. ['name', 'like', '%' . $data['keyWord'] . '%'],
  66. ];
  67. }
  68. $result = [];
  69. if (isset($data['pageSize'])) {
  70. $rep = UserLevel::where($where)->limit($data['pageSize'])->offset(($data['page'] - 1) * $data['pageSize'])->orderBy("id", "asc")->get();
  71. $count = UserLevel::where($where)->count();
  72. $result = [
  73. 'rows' => $rep,
  74. 'count' => $count,
  75. ];
  76. } else {
  77. $result = UserLevel::orderBy("id", "asc")->get();
  78. }
  79. return $result ? Result::success($result) : Result::error("没有查到数据");
  80. }
  81. /**
  82. * 添加用户等级
  83. * @param array $data
  84. * @return array
  85. */
  86. public function addUserLevel(array $data): array
  87. {
  88. LevelUser::insertGetId($data);
  89. return Result::success([]);
  90. }
  91. /**
  92. * 更新等级
  93. * @param array $data
  94. * @return array
  95. */
  96. public function updateUserLevel(array $data): array
  97. {
  98. $result = LevelUser::where(['id' => $data['id']])->update($data);
  99. if ($result) {
  100. return Result::success($result);
  101. }
  102. return Result::error("更新失败");
  103. }
  104. /**
  105. * 删除等级
  106. * @param array $data
  107. * @return array
  108. */
  109. public function delUserLevel(array $data): array
  110. {
  111. $result = LevelUser::where(['id' => $data['id']])->delete();
  112. if ($result) {
  113. return Result::success($result);
  114. }
  115. return Result::error("删除失败");
  116. }
  117. /**
  118. * 查询投诉举报信息
  119. * @param array $data
  120. * @return array
  121. */
  122. public function getLetterOfComplaint(array $data = []): array
  123. {
  124. var_dump("====");
  125. $where = [];
  126. if (isset($data['user_id']) && !empty($data['user_id'])) {
  127. array_push($where, ['letter_of_complaint.user_id', '=', $data['user_id']]);
  128. }
  129. if (isset($data['nature']) && !empty($data['nature'])) {
  130. array_push($where, ['letter_of_complaint.nature', '=', $data['nature']]);
  131. }
  132. if (isset($data['nature_level0']) && !empty($data['nature_level0'])) {
  133. array_push($where, ['letter_of_complaint.nature_level0', '=', $data['nature_level0']]);
  134. }
  135. if (isset($data['status']) && !empty($data['status'])) {
  136. array_push($where, ['letter_of_complaint.status', '=', $data['status']]);
  137. }
  138. $result = [];
  139. if (isset($data['pageSize'])) {
  140. $rep = LetterOfComplaint::where($where)
  141. ->leftJoin("letter_type as type_a", "letter_of_complaint.nature", "type_a.id")
  142. ->leftJoin("letter_type as type_c", "letter_of_complaint.nature_level0", "type_c.id")
  143. ->leftJoin("letter_type as type_b", "letter_of_complaint.nature_level1", "type_b.id")
  144. ->leftJoin("letter_type as type_e", "letter_of_complaint.nature_level3", "type_e.id")
  145. ->leftJoin("letter_type as type_d", "letter_of_complaint.status", "type_d.id")
  146. ->select(
  147. "letter_of_complaint.*",
  148. "type_a.type_name as nature_name",
  149. "type_b.type_name as nature_name1",
  150. "type_c.type_name as nature_name0",
  151. "type_d.type_name as status_name",
  152. "type_e.type_name as nature_name3"
  153. )
  154. ->limit($data['pageSize'])->offset(($data['page'] - 1) * $data['pageSize'])->orderBy("letter_of_complaint.id", "desc")->get();
  155. $count = LetterOfComplaint::where($where)->count();
  156. if ($rep) {
  157. foreach ($rep as $val) {
  158. if ($val['judgment']) {
  159. $val['judgment'] = json_decode($val['judgment']);
  160. }
  161. if ($val['audio_and_video']) {
  162. $val['audio_and_video'] = json_decode($val['audio_and_video']);
  163. }
  164. if ($val['contract']) {
  165. $val['contract'] = json_decode($val['contract']);
  166. }
  167. if ($val['qualifications']) {
  168. $val['qualifications'] = json_decode($val['qualifications']);
  169. }
  170. }
  171. }
  172. $result = [
  173. 'rows' => $rep,
  174. 'count' => $count,
  175. ];
  176. } else {
  177. $result = LetterOfComplaint::where($where)
  178. ->leftJoin("letter_type as type_a", "letter_of_complaint.nature", "type_a.id")
  179. ->leftJoin("letter_type as type_c", "letter_of_complaint.nature_level0", "type_c.id")
  180. ->leftJoin("letter_type as type_b", "letter_of_complaint.nature_level1", "type_b.id")
  181. ->leftJoin("letter_type as type_e", "letter_of_complaint.nature_level3", "type_e.id")
  182. ->leftJoin("letter_type as type_d", "letter_of_complaint.status", "type_d.id")
  183. ->select(
  184. "letter_of_complaint.*",
  185. "type_a.type_name as nature_name",
  186. "type_b.type_name as nature_name1",
  187. "type_c.type_name as nature_name0",
  188. "type_d.type_name as status_name",
  189. "type_e.type_name as nature_name3"
  190. )
  191. ->orderBy("letter_of_complaint.id", "desc")->get();
  192. }
  193. return $result ? Result::success($result) : Result::error("没有查到数据");
  194. }
  195. /**
  196. * 添加投诉举报信息
  197. * @param array $data
  198. * @return array
  199. */
  200. public function addLetterOfComplaint(array $data): array
  201. {
  202. $data['judgment'] = $data['judgment'] ? json_encode($data['judgment']) : '';
  203. $data['audio_and_video'] = $data['audio_and_video'] ? json_encode($data['audio_and_video']) : '';
  204. $data['contract'] = $data['contract'] ? json_encode($data['contract']) : '';
  205. $data['qualifications'] = $data['qualifications'] ? json_encode($data['qualifications']) : '';
  206. unset($data['id']);
  207. $result = LetterOfComplaint::insertGetId($data);
  208. if (empty($result)) {
  209. return Result::error("创建失败", 0);
  210. } else {
  211. return Result::success(["id" => $result]);
  212. }
  213. }
  214. /**
  215. * 用户端更新投诉举报
  216. * @param array $data
  217. * @return array
  218. */
  219. public function userUpLetterOfComplaint(array $data): array
  220. {
  221. $data['judgment'] = $data['judgment'] ? json_encode($data['judgment']) : '';
  222. $data['audio_and_video'] = $data['audio_and_video'] ? json_encode($data['audio_and_video']) : '';
  223. $data['contract'] = $data['contract'] ? json_encode($data['contract']) : '';
  224. $data['qualifications'] = $data['qualifications'] ? json_encode($data['qualifications']) : '';
  225. $result = LetterOfComplaint::where(['id' => $data['id']])->update($data);
  226. if (empty($result)) {
  227. return Result::error("创建失败", 0);
  228. } else {
  229. return Result::success(["id" => $result]);
  230. }
  231. }
  232. /**
  233. * 管理后台更新投诉举报信息
  234. * @param array $data
  235. * @return array
  236. */
  237. public function upLetterOfComplaint(array $data): array
  238. {
  239. var_dump("admin:", $data);
  240. $where = [
  241. 'id' => $data['id'],
  242. ];
  243. $filtered_array = array_filter($data, function ($value) {
  244. return $value !== "" && $value !== null && $value !== false && !is_array($value) || !empty($value);
  245. });
  246. $filtered_array['judgment'] = isset($filtered_array['judgment']) ? json_encode($filtered_array['judgment']) : '';
  247. $filtered_array['audio_and_video'] = isset($filtered_array['audio_and_video']) ? json_encode($filtered_array['audio_and_video']) : '';
  248. $filtered_array['contract'] = isset($filtered_array['contract']) ? json_encode($filtered_array['contract']) : '';
  249. $filtered_array['qualifications'] = isset($filtered_array['qualifications']) ? json_encode($filtered_array['qualifications']) : '';
  250. unset($filtered_array['nature_name']);
  251. unset($filtered_array['type_name']);
  252. unset($filtered_array['nature_level_name']);
  253. unset($filtered_array['status_name']);
  254. unset($filtered_array['is_admin']);
  255. unset($filtered_array['type_level_name']);
  256. $result = LetterOfComplaint::where($where)->update($filtered_array);
  257. if ($result) {
  258. return Result::success($result);
  259. }
  260. return Result::error("更新失败", 0);
  261. }
  262. /**
  263. * 查询投诉举报记录
  264. * @param array $data
  265. * @return array
  266. */
  267. public function getLetterOfComplaintInfo(array $data): array
  268. {
  269. $where = [
  270. 'letter_of_complaint.id' => $data['id'],
  271. ];
  272. if (isset($data['user_id']) && !empty($data['user_id'])) {
  273. array_push($where, ['letter_of_complaint.user_id', '=', $data['user_id']]);
  274. }
  275. $result = LetterOfComplaint::where($where)
  276. ->leftJoin("letter_type as type_a", "letter_of_complaint.nature", "type_a.id")
  277. ->leftJoin("letter_type as type_c", "letter_of_complaint.nature_level0", "type_c.id")
  278. ->leftJoin("letter_type as type_b", "letter_of_complaint.nature_level1", "type_b.id")
  279. ->leftJoin("letter_type as type_e", "letter_of_complaint.nature_level3", "type_e.id")
  280. ->leftJoin("letter_type as type_d", "letter_of_complaint.status", "type_d.id")
  281. ->select(
  282. "letter_of_complaint.*",
  283. "type_a.type_name as nature_name",
  284. "type_b.type_name as nature_name1",
  285. "type_c.type_name as nature_name0",
  286. "type_d.type_name as status_name",
  287. "type_e.type_name as nature_name3"
  288. )
  289. ->first();
  290. return Result::success($result);
  291. }
  292. /**
  293. * 删除投诉举报信息
  294. * @param array $data
  295. * @return array
  296. */
  297. public function delLetterOfComplaint(array $data): array
  298. {
  299. $result = LetterOfComplaint::when($data, function ($query) use ($data) {
  300. if (isset($data['id']) && !empty($data['id'])) {
  301. $query->where(['id' => $data['id']]);
  302. }
  303. if (isset($data['user_id']) && !empty($data['user_id'])) {
  304. $query->where(['user_id' => $data['user_id']]);
  305. }
  306. })->delete();
  307. if (empty($result)) {
  308. return Result::error("删除失败", 0);
  309. } else {
  310. return Result::success();
  311. }
  312. }
  313. /**
  314. * 获取举报信息类型
  315. * @param array $data
  316. * @return array
  317. */
  318. public function getLetterType(array $data): array
  319. {
  320. $where = [];
  321. if (isset($data['type'])) {
  322. array_push($where, ['type', '=', $data['type']]);
  323. }
  324. if (isset($data['pid']) && $data['pid'] > 0) {
  325. array_push($where, ['pid', '=', $data['pid']]);
  326. }
  327. $result = LetterType::where($where)->orderBy('sort', 'asc')->get();
  328. return $result ? Result::success($result) : Result::error("没有查到数据");
  329. }
  330. /**
  331. * 更新举报类型
  332. * @param array $data
  333. * @return array
  334. */
  335. public function upLetterType(array $data): array
  336. {
  337. return [];
  338. }
  339. /**
  340. * 添加举报类型
  341. * @param array $data
  342. * @return array
  343. */
  344. public function addLetterType(array $data): array
  345. {
  346. $result = LetterType::insertGetId($data);
  347. if (empty($result)) {
  348. return Result::error("创建失败", 0);
  349. } else {
  350. return Result::success(["id" => $result]);
  351. }
  352. }
  353. /**
  354. * 删除举报类型
  355. * @param array $data
  356. * @return array
  357. */
  358. public function delLetterType(array $data): array
  359. {
  360. $result = LetterType::where('id', $data['id'])->delete();
  361. if (empty($result)) {
  362. return Result::error("删除失败", 0);
  363. } else {
  364. return Result::success();
  365. }
  366. }
  367. /**
  368. * 检测是否已经被接案
  369. * @param array $data
  370. * @return array
  371. */
  372. public function checkMeasure(array $data): array
  373. {
  374. $where = [
  375. 'id' => $data['id'],
  376. ];
  377. $letterOfComplaintInfo = LetterOfComplaint::where($where)->first();
  378. var_dump("查询数据:", $letterOfComplaintInfo['admin_id'], $data['user_id']);
  379. //操作人和当前登陆用户id 相等说明是当前人接收的案件
  380. if (($letterOfComplaintInfo['admin_id'] == $data['user_id']) || empty($letterOfComplaintInfo['admin_id'])) {
  381. return Result::success();
  382. } else {
  383. return Result::error("您不能处理其他人已经接过的案件", 0);
  384. }
  385. }
  386. /**
  387. * 后台获取职能部门
  388. * @param array $data
  389. * @return array
  390. */
  391. public function getZhinengbumenList(array $data): array
  392. {
  393. // 获取分页参数,默认每页 10 条记录
  394. $page = isset($data['page']) ? (int) $data['page'] : 1;
  395. $perPage = isset($data['pagesize']) ? (int) $data['pagesize'] : 10;
  396. // 查询数据并分页
  397. $query = Department::query();
  398. // 可以在这里添加更多的查询条件
  399. if (isset($data['search'])) {
  400. $query->where('name', 'like', '%' . $data['search'] . '%');
  401. }
  402. // 执行分页查询
  403. $result = $query->paginate($perPage, ['*'], 'page', $page);
  404. // 返回分页结果
  405. return Result::success([
  406. 'count' => $result->total(),
  407. 'current_page' => $result->currentPage(),
  408. 'last_page' => $result->lastPage(),
  409. 'pagesize' => $result->perPage(),
  410. 'rows' => $result->items(),
  411. ]);
  412. }
  413. /**
  414. * 添加获取职能部门
  415. * @param array $data
  416. * @return array
  417. */
  418. public function addZhinengbumen(array $data): array
  419. {
  420. $result = Department::insertGetId($data);
  421. if (empty($result)) {
  422. return Result::error("创建失败", 0);
  423. } else {
  424. return Result::success(["id" => $result]);
  425. }
  426. }
  427. public function delZhinengbumen(array $data): array
  428. {
  429. $result = Department::where('id', $data['id'])->delete();
  430. if (empty($result)) {
  431. return Result::error("删除失败", 0);
  432. } else {
  433. return Result::success();
  434. }
  435. }
  436. public function getZhinengbumen(array $data): array
  437. {
  438. $result = Department::where('id', $data['id'])->first();
  439. return Result::success($result);
  440. }
  441. public function getPidZhinengbumen(array $data): array
  442. {
  443. if (empty($data['pid'])) {
  444. $data['pid'] = 0;
  445. }
  446. $result = Department::where('pid', $data['pid'])->get();
  447. return Result::success($result);
  448. }
  449. public function modZhinengbumen(array $data): array
  450. {
  451. $result = Department::where('id', $data['id'])->update($data);
  452. if (empty($result)) {
  453. return Result::error("修改失败", 0);
  454. } else {
  455. return Result::success();
  456. }
  457. }
  458. /**
  459. * 查询职能列表
  460. * @param array $data
  461. * @return array
  462. */
  463. public function getDepartment(array $data): array
  464. {
  465. $where = [];
  466. if (isset($data['pid'])) {
  467. $where = [
  468. 'pid' => $data['pid'] ?? 0
  469. ];
  470. }
  471. $result = Department::when(!empty($where), function ($query) use ($where) {
  472. $query->where($where);
  473. })->orderBy("sort", "desc")->get();
  474. if (empty($result)) {
  475. return Result::error("查询失败", 0);
  476. } else {
  477. return Result::success($result);
  478. }
  479. }
  480. /**
  481. * 获取所有的buckets
  482. * @param array $data
  483. * @return array
  484. */
  485. public function getBuckets(array $data): array
  486. {
  487. $result = new MinioService();
  488. // 调用服务层的方法获取存储桶列表
  489. $bucketsResponse = $result->listBuckets();
  490. // 直接返回服务层生成的响应
  491. return Result::success($bucketsResponse['data']);
  492. }
  493. /**
  494. * 上传文件
  495. * @param array $data
  496. * @return array
  497. */
  498. public function uploadFile(array $data): array
  499. {
  500. $result = new MinioService();
  501. $rep = $result->uploadFile($data);
  502. if ($rep['code'] == 200) {
  503. return Result::success($rep['data']);
  504. } else {
  505. return Result::error("上传失败!");
  506. }
  507. }
  508. /**
  509. * 黑名单管理
  510. * @param array $data
  511. * @return array
  512. */
  513. public function getBlackWordList(array $data): array
  514. {
  515. $result = BlackWord::when($data, function ($query) use ($data) {
  516. if (isset($data['name']) && $data['name']) {
  517. $query->where('black_word.name', 'like', '%' . $data['name'] . '%');
  518. }
  519. })->orderBy('black_word.id', 'desc')
  520. ->paginate(
  521. intval($data['pageSize']),
  522. [
  523. 'black_word.*',
  524. ],
  525. 'page',
  526. intval($data['page'])
  527. );
  528. $count = $result->total();
  529. $returnData = [
  530. 'rows' => $result->items(),
  531. 'count' => $count
  532. ];
  533. return Result::success($returnData);
  534. }
  535. /**
  536. * 添加黑名单
  537. * @param array $data
  538. * @return array
  539. */
  540. public function addBlackWord(array $data): array
  541. {
  542. Db::beginTransaction();
  543. try {
  544. $info = BlackWord::where(['name' => $data['name']])->first();
  545. if ($info) {
  546. Db::rollBack();
  547. return Result::error("该黑名单已存在", 0);
  548. }
  549. $data['type'] = 10;
  550. $result = BlackWord::insertGetId($data);
  551. $redisKey = 'black_word';
  552. $this->redis->sAdd($redisKey, $data['name']);
  553. Db::commit();
  554. return Result::success(["id" => $result]);
  555. } catch (\Exception $e) {
  556. Db::rollBack();
  557. return Result::error("创建失败" . $e->getMessage(), 0);
  558. }
  559. }
  560. /**
  561. * 删除黑名单
  562. * @param array $data
  563. * @return array
  564. */
  565. public function delBlackWord(array $data): array
  566. {
  567. Db::beginTransaction();
  568. try {
  569. BlackWord::where(['name' => $data['name']])->delete();
  570. $redisKey = 'black_word';
  571. $this->redis->sRem($redisKey, $data['name']);
  572. Db::commit();
  573. return Result::success([]);
  574. } catch (\Exception $e) {
  575. Db::rollBack();
  576. return Result::error("删除失败" . $e->getMessage(), 0);
  577. }
  578. }
  579. /**
  580. * 修改违禁词
  581. * @param array $data
  582. * @return array
  583. */
  584. public function upBlackWord(array $data): array
  585. {
  586. Db::beginTransaction();
  587. try {
  588. $checkInfo = BlackWord::where(['name' => $data['name']])->first();
  589. if ($checkInfo) {
  590. Db::rollBack();
  591. return Result::error("该违禁词已经存在", 0);
  592. }
  593. $blackWordInfo = BlackWord::where(['id' => $data['id']])->first();
  594. if ($blackWordInfo) {
  595. //先删除redis
  596. $blackWordInfo = $blackWordInfo->toArray();
  597. $redisKey = 'black_word';
  598. $this->redis->sRem($redisKey, $blackWordInfo['name']);
  599. $this->redis->sAdd($redisKey, $data['name']);
  600. BlackWord::where(['id' => $data['id']])->update(['name' => $data['name']]);
  601. Db::commit();
  602. return Result::success([]);
  603. } else {
  604. Db::rollBack();
  605. return Result::error("系统错误", 0);
  606. }
  607. } catch (\Exception $e) {
  608. Db::rollBack();
  609. return Result::error("修改失败" . $e->getMessage(), 0);
  610. }
  611. }
  612. /**
  613. * 获取风格
  614. * @return void
  615. */
  616. public function getTemplateClassList(array $data): array
  617. {
  618. $where = [];
  619. if (isset($data['name']) && $data['name']) {
  620. array_push($where, ['template_class.name', 'like', '%' . $data['name'] . '%']);
  621. }
  622. if(isset($data['keyword']) && $data['keyword']){
  623. array_push($where, ['template_class.keyword', 'like', '%'. $data['keyword']. '%']);
  624. }
  625. $template = TemplateClass::when($where, function ($query) use ($where) {
  626. $query->where($where);
  627. });
  628. $count = $template->count();
  629. // $countQuery = clone $template;
  630. $row = $template
  631. ->leftJoin('template', 'template_class.id', '=', 'template.template_class_id')
  632. ->select('template_class.*', DB::raw('COUNT(template.id) as template_count'))
  633. ->groupBy('template_class.id')
  634. ->orderBy('template_class.id', 'desc')
  635. ->offset(($data['page'] - 1) * $data['pageSize'])
  636. ->limit($data['pageSize'])
  637. ->get();
  638. $result = [
  639. 'rows' => $row,
  640. 'count' => $count,
  641. ];
  642. if ($row->isEmpty()) {
  643. return Result::error("暂无风格", 0);
  644. } else {
  645. return Result::success($result);
  646. }
  647. }
  648. /**
  649. * 添加风格
  650. * @param
  651. * @return void
  652. */
  653. public function addTemplateClass(array $data): array
  654. {
  655. $data['keyword'] = json_encode($data['keyword']);
  656. $template_class = TemplateClass::where('name', $data['name'])
  657. ->orWhere('class_id', $data['class_id'])
  658. ->first();
  659. if ($template_class) {
  660. return Result::error("风格名称或者风格编号已存在,不可添加!", 0);
  661. }
  662. $result = TemplateClass::insertGetId($data);
  663. if (empty($result)) {
  664. return Result::error("创建风格失败", 0);
  665. } else {
  666. return Result::success(["id" => $result]);
  667. }
  668. }
  669. /**
  670. * 更新风格
  671. * @param array $data
  672. * @return array
  673. */
  674. public function upTemplateClass(array $data): array
  675. {
  676. $where = [
  677. 'id' => $data['id'],
  678. ];
  679. $template_class = TemplateClass::where($where)->first();
  680. if (empty($template_class)) {
  681. return Result::error("未查询到风格", 0);
  682. }
  683. if($template_class->type == 1){
  684. return Result::error("默认风格不能修改", 0);
  685. }
  686. $template = TemplateClass::where('id','!=',$data['id'])
  687. // ->where(['name' => $data['name']])
  688. // ->orWhere(['class_id' => $data['class_id']])
  689. ->where(function ($query) use ($data) {
  690. $query->where('name', $data['name'])
  691. ->orWhere('class_id', $data['class_id']);
  692. })
  693. ->first();
  694. if ($template) {
  695. return Result::error("风格名称或者风格编号已存在,不可编辑!", 0);
  696. }
  697. $updateData = [
  698. 'name' => $data['name'],
  699. 'keyword' => json_encode($data['keyword']),
  700. 'class_id' => $data['class_id'],
  701. ];
  702. $result = TemplateClass::where($where)->update($updateData);
  703. if (empty($result)) {
  704. return Result::error("更新失败", 0);
  705. } else {
  706. return Result::success($result);
  707. }
  708. }
  709. /**
  710. * 删除风格
  711. * @param array $data
  712. * @return array
  713. */
  714. public function delTemplateClass(array $data): array
  715. {
  716. $where = [
  717. 'id' => $data['id'],
  718. ];
  719. $template = TemplateClass::where($where)->first();
  720. if (empty($template)) {
  721. return Result::error("未查询到风格", 0);
  722. }
  723. if($template->type == 1){
  724. return Result::error("默认风格不能删除", 0);
  725. }
  726. try{
  727. // 默认风格 1
  728. $template = Template::where('template_class_id',$data['id'])->update(['template_class_id'=>1]);
  729. if(empty($template)){
  730. Db::rollBack();
  731. return Result::error("删除失败", 0);
  732. }
  733. $result = TemplateClass::where($where)->delete();
  734. }catch (\Exception $e){
  735. return Result::error("删除失败".$e->getMessage(), 0);
  736. }
  737. return Result::success($result);
  738. }
  739. /**
  740. * 根据风格名称-获取获取所有风格
  741. * @param array $data
  742. * @return array
  743. */
  744. public function getTemplateClass(array $data): array
  745. {
  746. $result = TemplateClass::where('name','like','%'.$data['template_name'].'%')->get();
  747. if(empty($result)){
  748. return Result::error("暂无风格", 0);
  749. }
  750. return Result::success($result);
  751. }
  752. /**
  753. * 获取皮肤列表
  754. * @param array $data
  755. * @return array
  756. */
  757. public function getTemplateList(array $data): array
  758. {
  759. $where = [];
  760. if (!empty($data['template_class_id'])) {
  761. $where['template_class_id'] = $data['template_class_id'];
  762. }
  763. if (!empty($data['template_name'])) {
  764. array_push($where, ['template_name', 'like', '%'. $data['template_name']. '%']);
  765. }
  766. if (!empty($data['template_keyword'])) {
  767. array_push($where, ['template_keyword', 'like', '%'. $data['template_keyword']. '%']);
  768. }
  769. $result = Template::where($where)
  770. ->leftJoin('template_class', 'template.template_class_id', 'template_class.class_id')
  771. ->select('template.*', 'template_class.name as template_class_name')
  772. ->orderBy('template.id', 'desc')
  773. ->paginate($data['page_size'], ['*'], 'mypage_name', $data['page']);
  774. if(empty($result)){
  775. return Result::error("暂无皮肤", 0);
  776. }
  777. return Result::success($result);
  778. }
  779. public function getTemplateInfo(array $data): array
  780. {
  781. $result = Template::where('template.id', $data['id'])
  782. ->leftJoin('template_class', 'template.template_class_id', 'template_class.class_id')
  783. ->select('template.*', 'template_class.name as template_class_name')
  784. ->first();
  785. if(empty($result)){
  786. return Result::error("暂无皮肤", 0);
  787. }
  788. return Result::success($result);
  789. }
  790. /**
  791. * 添加皮肤
  792. * @param array $data
  793. * @return array
  794. */
  795. public function addTemplate(array $data): array
  796. {
  797. var_dump($data);
  798. unset($data['user_id']);
  799. $template = Template::where('template_name', $data['template_name'])
  800. ->orWhere('template_id', $data['template_id'])
  801. ->first();
  802. if ($template) {
  803. return Result::error("皮肤名称或者皮肤编号已存在,不可添加!", 0);
  804. }
  805. $data['template_keyword'] = json_encode($data['template_keyword']) ?? '';
  806. $page_type = json_decode($data['page_type'], true);
  807. $data['page_type'] = json_encode(array_values(array_unique($page_type)));
  808. $result = Template::insertGetId($data);
  809. if(empty($result)){
  810. return Result::error("创建失败", 0);
  811. }else{
  812. return Result::success($result);
  813. }
  814. }
  815. /**
  816. * 删除皮肤
  817. * @param array $data
  818. * @return array
  819. */
  820. public function delTemplate(array $data): array
  821. {
  822. $rector = Sector::where('template_id', $data['id'])->first();
  823. if (!empty($rector)) {
  824. return Result::error("此皮肤已被绑定,不可删除", 0);
  825. }
  826. $result = Template::where('id', $data['id'])->delete();
  827. var_dump($result, '-------------------delete');
  828. if ($result) {
  829. return Result::success($result);
  830. } else {
  831. return Result::error("删除失败", 0);
  832. }
  833. }
  834. /**
  835. * 更新皮肤
  836. * @param array $data
  837. * @return array
  838. */
  839. public function updateTemplate(array $data): array
  840. {
  841. unset($data['user_id']);
  842. $template = Template::where('id', $data['id'])
  843. ->first();
  844. if (empty($template)) {
  845. return Result::error("此皮肤不存在!", 0);
  846. }
  847. $template = Template::where('id', '!=', $data['id'])
  848. ->where(function ($query) use ($data) {
  849. $query->where('template_name', $data['template_name'])
  850. ->orWhere('template_id', $data['template_id']);
  851. })
  852. ->first();
  853. if ($template) {
  854. return Result::error("皮肤名称或者皮肤编号已存在,不可编辑!", 0);
  855. }
  856. $data['template_keyword'] = json_encode($data['template_keyword']) ?? '';
  857. $page_type = json_decode($data['page_type'], true);
  858. $data['page_type'] = json_encode(array_values(array_unique($page_type)));
  859. $result = Template::where('id', $data['id'])->update($data);
  860. var_dump($result, '-------------------update');
  861. if (!$result) {
  862. return Result::error("更新失败", 0);
  863. } else {
  864. return Result::success('更新成功');
  865. }
  866. }
  867. /**
  868. * 根据皮肤名称-获取所有皮肤
  869. * @param array $data
  870. * @return array
  871. */
  872. public function getAllTemplate(array $data): array
  873. {
  874. $result = Template::where('template_name','like','%'.$data['template_name'].'%')->get();
  875. if(empty($result)){
  876. return Result::error("暂无皮肤", 0);
  877. }
  878. return Result::success($result);
  879. }
  880. /**
  881. * 获取通栏列表
  882. * @param array $data
  883. * @return array
  884. */
  885. public function getSectorList(array $data): array
  886. {
  887. $where = [];
  888. if (isset($data['template_class_id']) && !empty($data['template_class_id'])) {
  889. $where['template_class_id'] = $data['template_class_id'];
  890. }
  891. if (isset($data['template_id']) && !empty($data['template_id'])) {
  892. array_push($where, ['template_id', $data['template_id']]);
  893. }
  894. if (isset($data['sector_name']) && !empty($data['sector_name'])) {
  895. array_push($where, ['sector.sector_name', 'like', '%' . $data['sector_name'] . '%']);
  896. }
  897. if (isset($data['width']) && !empty($data['width']) && isset($data['height']) && !empty($data['height'])){
  898. $size_id = Size::where('width','like','%' .$data['width'].'%')->where('height','like','%' .$data['height'].'%')->pluck('id');
  899. } else if( isset($data['width']) && !empty($data['width'])){
  900. $size_id = Size::where('width','like','%' .$data['width'].'%')->pluck('id');
  901. }else if( isset($data['height']) && !empty($data['height'])){
  902. $size_id = Size::where('height','like','%' .$data['height'].'%')->pluck('id');
  903. }else{
  904. $size_id = [];
  905. }
  906. // $size_id = $size_id->toArray();
  907. $result = Sector::where($where)
  908. ->when(!empty($size_id), function ($query) use ($size_id) {
  909. $query->whereIn('size_id', $size_id);
  910. })
  911. ->leftJoin('size', 'size.id', '=', 'sector.size_id')
  912. ->select('sector.*', 'size.width','size.height')
  913. ->orderBy('sector.id', 'desc')
  914. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  915. return Result::success($result);
  916. }
  917. /**
  918. * 获取通栏详情
  919. * @param array $data
  920. * @return array
  921. */
  922. public function getSectorInfo(array $data): array
  923. {
  924. $where = [];
  925. $where[] = ['sector.id', '=', $data['id']];
  926. $result = Sector::where($where)
  927. ->leftJoin('size', 'size.id', '=', 'sector.size_id')
  928. ->select('sector.*', 'size.width','size.height')
  929. ->orderBy('sector.id', 'desc')
  930. ->first();
  931. if(empty($result)){
  932. return Result::error('此通栏不存在!');
  933. }
  934. return Result::success($result);
  935. }
  936. /**
  937. * 获取经纬度信息
  938. * @return void
  939. */
  940. public function getIpInfo(array $data) :array
  941. {
  942. $client_ip = isset($data['ip']) && $data['ip']??$_SERVER['REMOTE_ADDR'];
  943. // 使用 IPinfo 服务获取 IP 信息
  944. $api_url = "https://ipinfo.io/{$client_ip}/json";
  945. $ch = curl_init($api_url);
  946. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  947. $response = curl_exec($ch);
  948. curl_close($ch);
  949. // 解析 JSON 响应
  950. $ip_info = json_decode($response, true);
  951. // 提取地址和经纬度
  952. if ($ip_info && !isset($ip_info['bogon'])) {
  953. $latitude = explode(',', $ip_info['loc'])[0];
  954. $longitude = explode(',', $ip_info['loc'])[1];
  955. $ip_info['latitude'] = $latitude;
  956. $ip_info['longitude'] = $longitude;
  957. return Result::success($ip_info);
  958. } else {
  959. $data['ip'] = '101.254.114.212';
  960. $this->getIpinfo(["ip"=>$data['ip']]);
  961. }
  962. }
  963. /**
  964. * 获取天气
  965. * @param array $data
  966. * @return array
  967. */
  968. public function getWeatherInfo(array $data) :array
  969. {
  970. $month = $data['month'] ?? date('m');
  971. $day = $data['day'] ?? date('d');
  972. // 使用缓存键
  973. $cacheKey = "tsbb_data_weather_{$month}_{$day}";
  974. // 尝试从缓存获取数据
  975. $container = \Hyperf\Context\ApplicationContext::getContainer();
  976. $cache = $container->get(\Psr\SimpleCache\CacheInterface::class);
  977. if ($cachedData = $cache->get($cacheKey)) {
  978. return Result::success(unserialize($cachedData));
  979. }
  980. $location = $data['latitude'].":".$data['longitude'];
  981. $api_url = "https://api.seniverse.com/v3/weather/now.json?key=".\Hyperf\Support\env('WEATHER_KEY')."&location=".$location."&language=zh-Hans&unit=c";
  982. $ch = curl_init($api_url);
  983. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  984. $response = curl_exec($ch);
  985. curl_close($ch);
  986. // 解析 JSON 响应
  987. $WeatherInfo = json_decode($response, true);
  988. // 缓存结果,设置1小时过期
  989. $cache->set($cacheKey, serialize($WeatherInfo), 3600);
  990. if($WeatherInfo){
  991. return Result::success($WeatherInfo);
  992. }else{
  993. return Result::error("获取天气失败", 0);
  994. }
  995. }
  996. /**
  997. * 获取农历信息
  998. * @return void
  999. */
  1000. public function getCalendar(array $data) :array
  1001. {
  1002. $calendar = new Calendar();
  1003. $result = $calendar->solar($data['year'], $data['month'], $data['day'], $data['hour']); // 阳历
  1004. return Result::success($result);
  1005. }
  1006. /**
  1007. * 添加通栏
  1008. * @param array $data
  1009. * @return array
  1010. */
  1011. public function addSector(array $data): array
  1012. {
  1013. unset($data['user_id']);
  1014. // 对传入的 page_type 数组进行去重、转换为整数并重新索引
  1015. $data['page_type'] = array_values(array_unique(array_map('intval', $data['page_type'])));
  1016. $data['page_type'] = json_encode($data['page_type']);
  1017. $template = Template::where('template_id', $data['template_id'])
  1018. ->whereRaw("JSON_CONTAINS(template.page_type, ?)", [$data['page_type']])
  1019. ->first();
  1020. if(empty($template)){
  1021. return Result::error('皮肤不存在!');
  1022. }
  1023. // 皮肤相关信息
  1024. $data['template_name'] = $template['template_name'];
  1025. $data['template_id'] = $template['template_id'];
  1026. // 风格相关信息
  1027. $template_class = TemplateClass::where('class_id',$template['template_class_id'])->first();
  1028. if(empty($template_class)){
  1029. return Result::error('所属风格不存在!');
  1030. }
  1031. // $data['sector_keyword'] = json_encode($data['sector_keyword']);
  1032. $data['template_class_id'] = $template_class['class_id'];
  1033. $data['template_class_name'] = $template_class['name'];
  1034. $result = Sector::insertGetId($data);
  1035. if(empty($result)){
  1036. return Result::error('添加失败');
  1037. }
  1038. return Result::success($result);
  1039. }
  1040. /**
  1041. * 删除通栏
  1042. * @param array $data
  1043. * @return array
  1044. */
  1045. public function delSector(array $data): array
  1046. {
  1047. $component_id = Component::where('sector_id', $data['id'])->pluck('id')->toArray();
  1048. if(!empty($component_id)){
  1049. return Result::error('请先删除相关组件!');
  1050. }
  1051. $result = Sector::where('id', $data['id'])->delete();
  1052. if ($result == 1) {
  1053. return Result::success('删除成功');
  1054. } else {
  1055. return Result::error('删除失败');
  1056. }
  1057. }
  1058. /**
  1059. * 修改通栏
  1060. * @param array $data
  1061. * @return array
  1062. */
  1063. public function updateSector(array $data): array
  1064. {
  1065. unset($data['user_id']);
  1066. $sector = Sector::where('id', $data['id'])->first();
  1067. if(empty($sector)){
  1068. return Result::error('通栏不存在!');
  1069. }
  1070. // 对传入的 page_type 数组进行去重、转换为整数并重新索引
  1071. $data['page_type'] = array_values(array_unique(array_map('intval', $data['page_type'])));
  1072. $data['page_type'] = json_encode($data['page_type']);
  1073. $template = Template::where('template_id', $data['template_id'])
  1074. ->whereRaw("JSON_CONTAINS(template.page_type, ?)", [$data['page_type']])
  1075. ->first();
  1076. if(empty($template)){
  1077. return Result::error('皮肤不存在!');
  1078. }
  1079. // 皮肤相关信息
  1080. $data['template_name'] = $template['template_name'];
  1081. $data['template_id'] = $template['template_id'];
  1082. // 风格相关信息
  1083. $template_class = TemplateClass::where('class_id',$template['template_class_id'])->first();
  1084. if(empty($template_class)){
  1085. return Result::error('所属风格不存在!');
  1086. }
  1087. // $data['sector_keyword'] = json_encode($data['sector_keyword']);
  1088. $data['template_class_id'] = $template_class['class_id'];
  1089. $data['template_class_name'] = $template_class['name'];
  1090. $result = Sector::where('id', $data['id'])->update($data);
  1091. if ($result == 1) {
  1092. return Result::success('修改成功');
  1093. } else {
  1094. return Result::error('修改失败');
  1095. }
  1096. }
  1097. public function getComponentList(array $data): array
  1098. {
  1099. var_dump($data, '---------');
  1100. $where = [];
  1101. // $where[] = ['sector.id', '=', $data['id']];
  1102. if (!empty($data['template_class_id'])) {
  1103. $where['template_class.id'] = $data['template_class_id'];
  1104. }
  1105. if (!empty($data['component_name'])) {
  1106. $where['component.component_name'] = $data['component_name'];
  1107. }
  1108. if (!empty($data['sector_id'])) {
  1109. $where['sector.id'] = $data['sector_id'];
  1110. };
  1111. $result = Component::where($where)
  1112. ->leftJoin('template', 'template.id', '=', 'component.template_id')
  1113. ->leftJoin('template_class', 'template_class.id', '=', 'template.template_class_id') // 添加这一行
  1114. ->leftJoin('sector', 'sector.id', '=', 'component.sector_id')
  1115. ->select('template_class.name as template_class_name', 'template.template_name as template_name', 'template_class.id as template_class_id', 'sector.sector_name as sector_name', 'component.*', 'sector.id as sector_id') // 修改这一行)
  1116. ->orderBy('sector.updated_at', 'desc')
  1117. ->orderBy('sector.created_at', 'desc')
  1118. ->paginate($data['page_size'], ['*'], 'mypage_name', $data['page']);
  1119. return Result::success($result);
  1120. }
  1121. public function getComponentInfo(array $data): array
  1122. {
  1123. $where = [];
  1124. $result = Component::where($where)
  1125. ->leftJoin('template', 'template.id', '=', 'component.template_id')
  1126. ->leftJoin('template_class', 'template_class.id', '=', 'template.template_class_id') // 添加这一行
  1127. ->leftJoin('sector', 'sector.id', '=', 'component.sector_id')
  1128. ->select('template_class.name as template_class_name', 'template.template_name as template_name', 'sector.sector_name as sector_name', 'component.*')
  1129. ->get();
  1130. return Result::success($result);
  1131. }
  1132. public function addComponent(array $data): array
  1133. {
  1134. unset($data['user_id']);
  1135. $result = Component::insertGetId($data);
  1136. if ($result) {
  1137. return Result::success($result);
  1138. } else {
  1139. return Result::error('添加失败');
  1140. }
  1141. }
  1142. public function delComponent(array $data): array
  1143. {
  1144. $result = Component::where('id', $data['id'])->delete();
  1145. return Result::success($result);
  1146. }
  1147. public function updateComponent(array $data): array
  1148. {
  1149. $result = Component::where('id', $data['id'])->update($data);
  1150. return Result::success($result);
  1151. }
  1152. public function getWebsiteTemplateInfo(array $data)
  1153. {
  1154. $where = [];
  1155. if (isset($data['id'])) {
  1156. $where[] = ['id', '=', $data['id']];
  1157. }
  1158. $result = WebsiteTemplateInfo::where($where)
  1159. ->leftJoin('website', 'website_template_info.website_id', '=', 'website.id')
  1160. ->leftJoin('website_template', 'website_template_info.template_id', '=', 'website_template.id')
  1161. ->select('website_template_info.*', 'website.website_name')
  1162. ->get();
  1163. if ($result) {
  1164. return Result::success($result);
  1165. } else {
  1166. return Result::error('暂无数据');
  1167. }
  1168. }
  1169. /**
  1170. * 自助建站----1.获取页面类型回显
  1171. * @param array $data
  1172. * @return array
  1173. */
  1174. public function getWebPageType(array $data): array
  1175. {
  1176. // 1:图片 2:文字 3:底部
  1177. $friend_link = Link::where('website_id', $data['website_id'])->where('type',3)->get();
  1178. if(empty($friend_link->toArray())){
  1179. return Result::error('暂无友情链接数据!');
  1180. }
  1181. $footer_category = FooterCategory::where('website_id', $data['website_id'])->get();
  1182. if(empty($footer_category->toArray())){
  1183. return Result::error('暂无底部导航数据!');
  1184. }
  1185. $result = [
  1186. 'friend_link' => $friend_link,
  1187. 'footer_category' => $footer_category,
  1188. ];
  1189. return Result::success($result);
  1190. }
  1191. /**
  1192. * 自助建站----2.添加页面类型
  1193. * @param array $data
  1194. * @return array
  1195. */
  1196. public function addWebPageType(array $data): array
  1197. {
  1198. // return Result::success($data);
  1199. // 1:首页 2:频道页 3:列表页 4:详情页 5:搜索页 6:特殊列表 7:特殊详情页'
  1200. if($data['is_search'] == 1){
  1201. $page_type = json_encode([1,2,3,4,5,6,7]);
  1202. }else{
  1203. $page_type = json_encode([1,2,3,4,6,7]);
  1204. }
  1205. // 0:未构建;1:已填写基础信息;2:已选择模板; action_id
  1206. $website_template_info = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first();
  1207. // return Result::success($website_template_info);
  1208. // return Result::success(empty($website_template_info));
  1209. if(empty($website_template_info)){
  1210. $result = WebsiteTemplateInfo::insertGetId(['website_id' => $data['website_id'], 'page_type' => $page_type, 'user_id' => $data['user_id']]);
  1211. }else{
  1212. if($website_template_info['action_id'] == 2){
  1213. return Result::error('网站已应用,不可再次修改!');
  1214. }
  1215. $result = WebsiteTemplateInfo::where('website_id', $data['website_id'])->update(['page_type' => $page_type],['action_id' => 1,'user_id' => $data['user_id']]);
  1216. }
  1217. if ($result) {
  1218. return Result::success($result);
  1219. } else {
  1220. return Result::error('添加失败');
  1221. }
  1222. }
  1223. /**
  1224. * 自助建站---流程---3.选择皮肤列表
  1225. * @param array $data
  1226. * @return array
  1227. */
  1228. public function getWebsiteTemplateList(array $data): array
  1229. {
  1230. $where = [];
  1231. if(isset($data['template_class_id']) && $data['template_class_id']){
  1232. $where[] = ['template_class_id', '=', $data['template_class_id']];
  1233. }
  1234. // 0:未构建 1:未应用 2:已应用 status
  1235. $templste_info = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first();
  1236. if(empty($templste_info)){
  1237. return Result::error('请先填写网站基础信息!');
  1238. }
  1239. if($templste_info['status'] == 2){
  1240. return Result::error('网站已应用,不可再次修改!');
  1241. }
  1242. if(isset($data['keyword']) && !empty($data['keyword'])){
  1243. if (is_array($data['keyword'])) {
  1244. // 拼接多个模糊查询条件
  1245. $query = Template::query();
  1246. foreach ($data['keyword'] as $kw) {
  1247. $escapedKw = addcslashes($kw, '%_'); // 转义通配符
  1248. $query->WhereRaw("JSON_EXTRACT(template_keyword, '$[*]') LIKE ?", ["%$escapedKw%"]);
  1249. }
  1250. } else {
  1251. $escapedKeyword = addcslashes($data['keyword'], '%_'); // 转义通配符
  1252. $where[] = [DB::raw("JSON_EXTRACT(template_keyword, '$[*]') LIKE ?"), "%$escapedKeyword%"];
  1253. }
  1254. }
  1255. $template_id = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first(['template_id', 'page_type']);
  1256. // return Result::success($template_id);
  1257. if(!empty($template_id['page_type']) && $templste_info['page_type'] != '[]' && is_string($templste_info['page_type'])){
  1258. $template_page = is_string($templste_info['page_type']) ? json_decode($templste_info['page_type'], true) : [];
  1259. }else{
  1260. $template_page = [];
  1261. }
  1262. if(!empty($template_id['template_id'])){
  1263. $result['template_id'] = $templste_info['template_id'];
  1264. }
  1265. // 确保 $template_page 为有效数据,避免 SQL 注入风险,这里使用参数绑定
  1266. $template_page_str = json_encode($template_page);
  1267. if (isset($query)) {
  1268. $result['template'] = $query->where($where)
  1269. ->whereRaw("JSON_CONTAINS(template.page_type, ?)", [$template_page_str])
  1270. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  1271. } else {
  1272. $result['template'] = Template::where($where)
  1273. ->whereRaw("JSON_CONTAINS(template.page_type, ?)", [$template_page_str])
  1274. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  1275. }
  1276. if (empty($result['template']['data'])) {
  1277. $result['template'] = Template::orderBy('updated_at','desc')
  1278. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  1279. }
  1280. return Result::success($result);
  1281. }
  1282. /**
  1283. * 自助建站---流程---4.选择皮肤
  1284. * @param array $data
  1285. * @return array
  1286. */
  1287. public function chooseWebsiteTemplate(array $data): array
  1288. {
  1289. $website_template_info = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first();
  1290. if(empty($website_template_info)){
  1291. return Result::error('请先填写网站基础信息!');
  1292. }
  1293. // 0:未构建 1:未应用 2:已应用 status
  1294. if($website_template_info['status'] == 2){
  1295. return Result::error('网站已应用,不可再次修改!');
  1296. }
  1297. $template = Template::where('id', $data['template_id'])->first();
  1298. if(empty($template)){
  1299. return Result::error('未查询到皮肤!');
  1300. }
  1301. // 0:未构建;1:已填写基础信息;2:已选择模板; action_id
  1302. $web_template = WebsiteTemplateInfo::where('website_id', $data['website_id'])->update(['template_id' => $data['template_id'],'action_id' => 2]);
  1303. if ($web_template) {
  1304. return Result::success($web_template);
  1305. } else {
  1306. return Result::error('选择皮肤失败!');
  1307. }
  1308. }
  1309. /**
  1310. * 自助建站---流程---5.保存模版
  1311. * @param array $data
  1312. * @return array
  1313. */
  1314. public function saveWebsiteTemplate(array $data): array
  1315. {
  1316. $website_template_info = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first();
  1317. if(empty($website_template_info)){
  1318. return Result::error('请先填写网站基础信息!');
  1319. }
  1320. // 0:未构建 1:未应用 2:已应用 status
  1321. if($website_template_info['status'] == 2){
  1322. return Result::error('网站已应用,不可再次保存!');
  1323. }
  1324. if($website_template_info['action_id'] != 2){
  1325. return Result::error('请完成之前的步骤!');
  1326. }
  1327. $template_info = WebsiteTemplate::where('website_id', $data['website_id'])->first();
  1328. var_dump($data['template_data']);
  1329. if(empty($template_info)){
  1330. $template = WebsiteTemplate::insertGetId([
  1331. 'website_id' => $data['website_id'],
  1332. 'template_data' => $data['template_data']
  1333. ]);
  1334. }else{
  1335. $template = WebsiteTemplate::where('website_id', $data['website_id'])->update(['template_data' => $data['template_data']]);
  1336. }
  1337. if(empty($template)){
  1338. return Result::error('保存失败!');
  1339. }else{
  1340. return Result::success($template);
  1341. }
  1342. }
  1343. }