PublicRpcService.php 53 KB

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