PublicRpcService.php 46 KB

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