PublicRpcService.php 46 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274
  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. #[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', 'template_class.id', '=', 'template.template_class_id')
  633. ->select('template_class.*', DB::raw('COUNT(template.id) as template_count'))
  634. ->groupBy('template_class.id')
  635. ->orderBy('template_class.id', 'desc')
  636. ->offset(($data['page'] - 1) * $data['pageSize'])
  637. ->limit($data['pageSize'])
  638. ->get();
  639. $result = [
  640. 'rows' => $row,
  641. 'count' => $count,
  642. ];
  643. if ($row->isEmpty()) {
  644. return Result::error("暂无风格", 0);
  645. } else {
  646. return Result::success($result);
  647. }
  648. }
  649. /**
  650. * 添加风格
  651. * @param
  652. * @return void
  653. */
  654. public function addTemplateClass(array $data): array
  655. {
  656. $data['keyword'] = json_encode($data['keyword']);
  657. $template_class = TemplateClass::where('name', $data['name'])
  658. ->orWhere('class_id', $data['class_id'])
  659. ->first();
  660. if ($template_class) {
  661. return Result::error("风格名称或者风格编号已存在,不可添加!", 0);
  662. }
  663. $result = TemplateClass::insertGetId($data);
  664. if (empty($result)) {
  665. return Result::error("创建风格失败", 0);
  666. } else {
  667. return Result::success(["id" => $result]);
  668. }
  669. }
  670. /**
  671. * 更新风格
  672. * @param array $data
  673. * @return array
  674. */
  675. public function upTemplateClass(array $data): array
  676. {
  677. $where = [
  678. 'id' => $data['id'],
  679. ];
  680. $template_class = TemplateClass::where($where)->first();
  681. if (empty($template_class)) {
  682. return Result::error("未查询到风格", 0);
  683. }
  684. if($template_class->type == 1){
  685. return Result::error("默认风格不能修改", 0);
  686. }
  687. $template = TemplateClass::where('id','!=',$data['id'])
  688. // ->where(['name' => $data['name']])
  689. // ->orWhere(['class_id' => $data['class_id']])
  690. ->where(function ($query) use ($data) {
  691. $query->where('name', $data['name'])
  692. ->orWhere('class_id', $data['class_id']);
  693. })
  694. ->first();
  695. if ($template) {
  696. return Result::error("风格名称或者风格编号已存在,不可编辑!", 0);
  697. }
  698. $updateData = [
  699. 'name' => $data['name'],
  700. 'keyword' => json_encode($data['keyword']),
  701. 'class_id' => $data['class_id'],
  702. ];
  703. $result = TemplateClass::where($where)->update($updateData);
  704. if (empty($result)) {
  705. return Result::error("更新失败", 0);
  706. } else {
  707. return Result::success($result);
  708. }
  709. }
  710. /**
  711. * 删除风格
  712. * @param array $data
  713. * @return array
  714. */
  715. public function delTemplateClass(array $data): array
  716. {
  717. $where = [
  718. 'id' => $data['id'],
  719. ];
  720. $template = TemplateClass::where($where)->first();
  721. if (empty($template)) {
  722. return Result::error("未查询到风格", 0);
  723. }
  724. if($template->type == 1){
  725. return Result::error("默认风格不能删除", 0);
  726. }
  727. $result = TemplateClass::where($where)->delete();
  728. if (empty($result)) {
  729. return Result::error("删除失败", 0);
  730. } else {
  731. return Result::success($result);
  732. }
  733. }
  734. /**
  735. * 获取getTemplateClass
  736. * @param array $data
  737. * @return array
  738. */
  739. public function getTemplateClass(array $data): array
  740. {
  741. $result = TemplateClass::get();
  742. return Result::success($result);
  743. }
  744. /**
  745. * 获取皮肤列表
  746. * @param array $data
  747. * @return array
  748. */
  749. public function getTemplateList(array $data): array
  750. {
  751. $where = [];
  752. if (!empty($data['template_class_id'])) {
  753. $where['template_class_id'] = $data['template_class_id'];
  754. }
  755. if (!empty($data['template_name'])) {
  756. array_push($where, ['template_name', 'like', '%'. $data['template_name']. '%']);
  757. }
  758. if (!empty($data['template_keyword'])) {
  759. array_push($where, ['template_keyword', 'like', '%'. $data['template_keyword']. '%']);
  760. }
  761. $result = Template::where($where)
  762. ->leftJoin('template_class', 'template.template_class_id', 'template_class.id')
  763. ->select('template.*', 'template_class.name as template_class_name')
  764. ->orderBy('template.id', 'desc')
  765. ->paginate($data['page_size'], ['*'], 'mypage_name', $data['page']);
  766. if(empty($result)){
  767. return Result::error("暂无皮肤", 0);
  768. }
  769. return Result::success($result);
  770. }
  771. public function getTemplateInfo(array $data): array
  772. {
  773. $result = Template::where('template.id', $data['id'])
  774. ->leftJoin('template_class', 'template.template_class_id', 'template_class.id')
  775. ->select('template.*', 'template_class.name as template_class_name')
  776. ->first();
  777. if(empty($result)){
  778. return Result::error("暂无皮肤", 0);
  779. }
  780. return Result::success($result);
  781. }
  782. /**
  783. * 添加皮肤
  784. * @param array $data
  785. * @return array
  786. */
  787. public function addTemplate(array $data): array
  788. {
  789. var_dump($data);
  790. unset($data['user_id']);
  791. $template = Template::where('template_name', $data['template_name'])
  792. ->orWhere('template_id', $data['template_id'])
  793. ->first();
  794. if ($template) {
  795. return Result::error("皮肤名称或者皮肤编号已存在,不可添加!", 0);
  796. }
  797. $data['template_keyword'] = json_encode($data['template_keyword']) ?? '';
  798. $page_type = json_decode($data['page_type'], true);
  799. $data['page_type'] = json_encode(array_values(array_unique($page_type)));
  800. $result = Template::insertGetId($data);
  801. if(empty($result)){
  802. return Result::error("创建失败", 0);
  803. }else{
  804. return Result::success($result);
  805. }
  806. }
  807. /**
  808. * 删除皮肤
  809. * @param array $data
  810. * @return array
  811. */
  812. public function delTemplate(array $data): array
  813. {
  814. $result = Template::where('id', $data['id'])->delete();
  815. var_dump($result, '-------------------delete');
  816. if ($result) {
  817. return Result::success($result);
  818. } else {
  819. return Result::error("删除失败", 0);
  820. }
  821. }
  822. /**
  823. * 更新皮肤
  824. * @param array $data
  825. * @return array
  826. */
  827. public function updateTemplate(array $data): array
  828. {
  829. unset($data['user_id']);
  830. $template = Template::where('id', $data['id'])
  831. ->first();
  832. if (empty($template)) {
  833. return Result::error("此皮肤不存在!", 0);
  834. }
  835. $template = Template::where('id', '!=', $data['id'])
  836. ->where(function ($query) use ($data) {
  837. $query->where('template_name', $data['template_name'])
  838. ->orWhere('template_id', $data['template_id']);
  839. })
  840. ->first();
  841. if ($template) {
  842. return Result::error("皮肤名称或者皮肤编号已存在,不可编辑!", 0);
  843. }
  844. $data['template_keyword'] = json_encode($data['template_keyword']) ?? '';
  845. $page_type = json_decode($data['page_type'], true);
  846. $data['page_type'] = json_encode(array_values(array_unique($page_type)));
  847. $result = Template::where('id', $data['id'])->update($data);
  848. var_dump($result, '-------------------update');
  849. if (!$result) {
  850. return Result::error("更新失败", 0);
  851. } else {
  852. return Result::success('更新成功');
  853. }
  854. }
  855. public function getSectorList(array $data): array
  856. {
  857. $where = [];
  858. if (!empty($data['template_class_id'])) {
  859. $where['template_class.id'] = $data['template_class_id'];
  860. }
  861. if (!empty($data['template_class_name'])) {
  862. $where[] = ['template_class.name', 'like', '%' . $data['template_class_name'] . '%'];
  863. }
  864. if (!empty($data['sector_name'])) {
  865. if (!empty($data['sector_name'])) {
  866. // $where['sector_name'] = $data['sector_name'];
  867. $where[] = ['sector.sector_name', 'like', '%' . $data['sector_name'] . '%'];
  868. }
  869. }
  870. $result = Sector::where($where)
  871. ->leftJoin('template', 'template.id', '=', 'sector.template_id')
  872. ->leftJoin('template_class', 'template_class.id', '=', 'sector.template_id') // 添加这一行
  873. ->select('sector.*', 'sector.sector_name', 'template.template_name', 'template_class.name as template_class_name', 'template_class.id as template_class_id') // 修改这一行
  874. ->orderBy('sector.id', 'desc')
  875. ->paginate($data['page_size'], ['*'], 'mypage_name', $data['page']);
  876. return Result::success($result);
  877. }
  878. public function getSectorInfo(array $data): array
  879. {
  880. $where = [];
  881. $where[] = ['sector.id', '=', $data['id']];
  882. $result = Sector::where($where)
  883. ->leftJoin('template', 'template.id', '=', 'sector.template_id')
  884. ->leftJoin('template_class', 'template_class.id', '=', 'template.template_class_id') // 添加这一行
  885. ->select('sector.*', 'template.template_name', 'template_class.name as template_class_name', 'template_class.id as template_class_id') // 修改这一行
  886. ->orderBy('sector.id', 'desc')
  887. ->get();
  888. return Result::success($result);
  889. }
  890. /**
  891. * 获取经纬度信息
  892. * @return void
  893. */
  894. public function getIpInfo(array $data) :array
  895. {
  896. $client_ip = isset($data['ip']) && $data['ip']??$_SERVER['REMOTE_ADDR'];
  897. // 使用 IPinfo 服务获取 IP 信息
  898. $api_url = "https://ipinfo.io/{$client_ip}/json";
  899. $ch = curl_init($api_url);
  900. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  901. $response = curl_exec($ch);
  902. curl_close($ch);
  903. // 解析 JSON 响应
  904. $ip_info = json_decode($response, true);
  905. // 提取地址和经纬度
  906. if ($ip_info && !isset($ip_info['bogon'])) {
  907. $latitude = explode(',', $ip_info['loc'])[0];
  908. $longitude = explode(',', $ip_info['loc'])[1];
  909. $ip_info['latitude'] = $latitude;
  910. $ip_info['longitude'] = $longitude;
  911. return Result::success($ip_info);
  912. } else {
  913. $data['ip'] = '101.254.114.212';
  914. $this->getIpinfo(["ip"=>$data['ip']]);
  915. }
  916. }
  917. /**
  918. * 获取天气
  919. * @param array $data
  920. * @return array
  921. */
  922. public function getWeatherInfo(array $data) :array
  923. {
  924. $month = $data['month'] ?? date('m');
  925. $day = $data['day'] ?? date('d');
  926. // 使用缓存键
  927. $cacheKey = "tsbb_data_weather_{$month}_{$day}";
  928. // 尝试从缓存获取数据
  929. $container = \Hyperf\Context\ApplicationContext::getContainer();
  930. $cache = $container->get(\Psr\SimpleCache\CacheInterface::class);
  931. if ($cachedData = $cache->get($cacheKey)) {
  932. return Result::success(unserialize($cachedData));
  933. }
  934. $location = $data['latitude'].":".$data['longitude'];
  935. $api_url = "https://api.seniverse.com/v3/weather/now.json?key=".\Hyperf\Support\env('WEATHER_KEY')."&location=".$location."&language=zh-Hans&unit=c";
  936. $ch = curl_init($api_url);
  937. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  938. $response = curl_exec($ch);
  939. curl_close($ch);
  940. // 解析 JSON 响应
  941. $WeatherInfo = json_decode($response, true);
  942. // 缓存结果,设置1小时过期
  943. $cache->set($cacheKey, serialize($WeatherInfo), 3600);
  944. if($WeatherInfo){
  945. return Result::success($WeatherInfo);
  946. }else{
  947. return Result::error("获取天气失败", 0);
  948. }
  949. }
  950. /**
  951. * 获取农历信息
  952. * @return void
  953. */
  954. public function getCalendar(array $data) :array
  955. {
  956. $calendar = new Calendar();
  957. $result = $calendar->solar($data['year'], $data['month'], $data['day'], $data['hour']); // 阳历
  958. return Result::success($result);
  959. }
  960. public function addSector(array $data): array
  961. {
  962. unset($data['user_id']);
  963. // $data['page_type'] = json_encode($data['page_type']);
  964. $result = Sector::insertGetId($data);
  965. return Result::success();
  966. }
  967. public function delSector(array $data): array
  968. {
  969. $result = Sector::where('id', $data['id'])->delete();
  970. if ($result == 1) {
  971. return Result::success('删除成功');
  972. } else {
  973. return Result::error('删除失败');
  974. }
  975. }
  976. public function updateSector(array $data): array
  977. {
  978. unset($data['user_id']);
  979. $result = Sector::where('id', $data['id'])->update($data);
  980. if ($result == 1) {
  981. return Result::success('修改成功');
  982. } else {
  983. return Result::error('修改失败');
  984. }
  985. }
  986. public function getComponentList(array $data): array
  987. {
  988. var_dump($data, '---------');
  989. $where = [];
  990. // $where[] = ['sector.id', '=', $data['id']];
  991. if (!empty($data['template_class_id'])) {
  992. $where['template_class.id'] = $data['template_class_id'];
  993. }
  994. if (!empty($data['component_name'])) {
  995. $where['component.component_name'] = $data['component_name'];
  996. }
  997. if (!empty($data['sector_id'])) {
  998. $where['sector.id'] = $data['sector_id'];
  999. };
  1000. $result = Component::where($where)
  1001. ->leftJoin('template', 'template.id', '=', 'component.template_id')
  1002. ->leftJoin('template_class', 'template_class.id', '=', 'template.template_class_id') // 添加这一行
  1003. ->leftJoin('sector', 'sector.id', '=', 'component.sector_id')
  1004. ->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') // 修改这一行)
  1005. ->orderBy('sector.updated_at', 'desc')
  1006. ->orderBy('sector.created_at', 'desc')
  1007. ->paginate($data['page_size'], ['*'], 'mypage_name', $data['page']);
  1008. return Result::success($result);
  1009. }
  1010. public function getComponentInfo(array $data): array
  1011. {
  1012. $where = [];
  1013. $result = Component::where($where)
  1014. ->leftJoin('template', 'template.id', '=', 'component.template_id')
  1015. ->leftJoin('template_class', 'template_class.id', '=', 'template.template_class_id') // 添加这一行
  1016. ->leftJoin('sector', 'sector.id', '=', 'component.sector_id')
  1017. ->select('template_class.name as template_class_name', 'template.template_name as template_name', 'sector.sector_name as sector_name', 'component.*')
  1018. ->get();
  1019. return Result::success($result);
  1020. }
  1021. public function addComponent(array $data): array
  1022. {
  1023. unset($data['user_id']);
  1024. $result = Component::insertGetId($data);
  1025. if ($result) {
  1026. return Result::success($result);
  1027. } else {
  1028. return Result::error('添加失败');
  1029. }
  1030. }
  1031. public function delComponent(array $data): array
  1032. {
  1033. $result = Component::where('id', $data['id'])->delete();
  1034. return Result::success($result);
  1035. }
  1036. public function updateComponent(array $data): array
  1037. {
  1038. $result = Component::where('id', $data['id'])->update($data);
  1039. return Result::success($result);
  1040. }
  1041. public function getWebsiteTemplateInfo(array $data)
  1042. {
  1043. $where = [];
  1044. if (isset($data['id'])) {
  1045. $where[] = ['id', '=', $data['id']];
  1046. }
  1047. $result = WebsiteTemplateInfo::where($where)
  1048. ->leftJoin('website', 'website_template_info.website_id', '=', 'website.id')
  1049. ->leftJoin('website_template', 'website_template_info.template_id', '=', 'website_template.id')
  1050. ->select('website_template_info.*', 'website.website_name')
  1051. ->get();
  1052. if ($result) {
  1053. return Result::success($result);
  1054. } else {
  1055. return Result::error('暂无数据');
  1056. }
  1057. }
  1058. /**
  1059. * 自助建站----1.获取页面类型回显
  1060. * @param array $data
  1061. * @return array
  1062. */
  1063. public function getWebPageType(array $data): array
  1064. {
  1065. // 1:图片 2:文字 3:底部
  1066. $friend_link = Link::where('website_id', $data['website_id'])->where('type',3)->get();
  1067. if(empty($friend_link->toArray())){
  1068. return Result::error('暂无友情链接数据!');
  1069. }
  1070. $footer_category = FooterCategory::where('website_id', $data['website_id'])->get();
  1071. if(empty($footer_category->toArray())){
  1072. return Result::error('暂无底部导航数据!');
  1073. }
  1074. $result = [
  1075. 'friend_link' => $friend_link,
  1076. 'footer_category' => $footer_category,
  1077. ];
  1078. return Result::success($result);
  1079. }
  1080. /**
  1081. * 自助建站----2.添加页面类型
  1082. * @param array $data
  1083. * @return array
  1084. */
  1085. public function addWebPageType(array $data): array
  1086. {
  1087. // 1:首页 2:频道页 3:列表页 4:详情页 5:搜索页 6:特殊列表 7:特殊详情页'
  1088. if($data['is_search'] == 1){
  1089. $page_type = json_encode([1,2,3,4,5,6,7]);
  1090. }else{
  1091. $page_type = json_encode([1,2,3,4,6,7]);
  1092. }
  1093. // 0:未构建;1:已填写基础信息;2:已选择模板; action_id
  1094. $result = WebsiteTemplateInfo::where('website_id', $data['website_id'])->update(['page_type' => $page_type],['action_id' => 1]);
  1095. if ($result) {
  1096. return Result::success($result);
  1097. } else {
  1098. return Result::error('添加失败');
  1099. }
  1100. }
  1101. /**
  1102. * 自助建站---流程---3.选择皮肤列表
  1103. * @param array $data
  1104. * @return array
  1105. */
  1106. public function getWebsiteTemplateList(array $data): array
  1107. {
  1108. $where = [];
  1109. if(isset($data['template_class_id']) && $data['template_class_id']){
  1110. $where[] = ['template_class_id', '=', $data['template_class_id']];
  1111. }
  1112. // 0:未构建 1:未应用 2:已应用 status
  1113. $templste_info = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first();
  1114. if(empty($templste_info)){
  1115. return Result::error('请先填写网站基础信息!');
  1116. }
  1117. if($templste_info['status'] == 2){
  1118. return Result::error('网站已应用,不可再次修改!');
  1119. }
  1120. if(isset($data['keyword']) && !empty($data['keyword'])){
  1121. if (is_array($data['keyword'])) {
  1122. // 拼接多个模糊查询条件
  1123. $query = Template::query();
  1124. foreach ($data['keyword'] as $kw) {
  1125. $escapedKw = addcslashes($kw, '%_'); // 转义通配符
  1126. $query->WhereRaw("JSON_EXTRACT(template_keyword, '$[*]') LIKE ?", ["%$escapedKw%"]);
  1127. }
  1128. } else {
  1129. $escapedKeyword = addcslashes($data['keyword'], '%_'); // 转义通配符
  1130. $where[] = [DB::raw("JSON_EXTRACT(template_keyword, '$[*]') LIKE ?"), "%$escapedKeyword%"];
  1131. }
  1132. }
  1133. $template_id = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first(['template_id', 'page_type']);
  1134. // return Result::success($template_id);
  1135. if(!empty($template_id['page_type']) && $templste_info['page_type'] != '[]' && is_string($templste_info['page_type'])){
  1136. $template_page = is_string($templste_info['page_type']) ? json_decode($templste_info['page_type'], true) : [];
  1137. }else{
  1138. $template_page = [];
  1139. }
  1140. if(!empty($template_id['template_id'])){
  1141. $result['template_id'] = $templste_info['template_id'];
  1142. }
  1143. // 确保 $template_page 为有效数据,避免 SQL 注入风险,这里使用参数绑定
  1144. $template_page_str = json_encode($template_page);
  1145. if (isset($query)) {
  1146. $result['template'] = $query->where($where)
  1147. ->whereRaw("JSON_CONTAINS(template.page_type, ?)", [$template_page_str])
  1148. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  1149. } else {
  1150. $result['template'] = Template::where($where)
  1151. ->whereRaw("JSON_CONTAINS(template.page_type, ?)", [$template_page_str])
  1152. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  1153. }
  1154. if (empty($result['template']['data'])) {
  1155. $result['template'] = Template::orderBy('updated_at','desc')
  1156. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  1157. }
  1158. return Result::success($result);
  1159. }
  1160. /**
  1161. * 自助建站---流程---4.选择皮肤
  1162. * @param array $data
  1163. * @return array
  1164. */
  1165. public function chooseWebsiteTemplate(array $data): array
  1166. {
  1167. $website_template_info = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first();
  1168. if(empty($website_template_info)){
  1169. return Result::error('请先填写网站基础信息!');
  1170. }
  1171. // 0:未构建 1:未应用 2:已应用 status
  1172. if($website_template_info['status'] == 2){
  1173. return Result::error('网站已应用,不可再次修改!');
  1174. }
  1175. $template = Template::where('id', $data['template_id'])->first();
  1176. if(empty($template)){
  1177. return Result::error('未查询到皮肤!');
  1178. }
  1179. // 0:未构建;1:已填写基础信息;2:已选择模板; action_id
  1180. $web_template = WebsiteTemplateInfo::where('website_id', $data['website_id'])->update(['template_id' => $data['template_id'],'action_id' => 2]);
  1181. if ($web_template) {
  1182. return Result::success($web_template);
  1183. } else {
  1184. return Result::error('选择皮肤失败!');
  1185. }
  1186. }
  1187. /**
  1188. * 自助建站---流程---5.选择组件
  1189. * @param array $data
  1190. * @return array
  1191. */
  1192. public function saveWebsiteTemplate(array $data): array
  1193. {
  1194. $website_template_info = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first();
  1195. if(empty($website_template_info)){
  1196. return Result::error('请先填写网站基础信息!');
  1197. }
  1198. // 0:未构建 1:未应用 2:已应用 status
  1199. if($website_template_info['status'] == 2){
  1200. return Result::error('网站已应用,不可再次保存!');
  1201. }
  1202. if($website_template_info['action_id'] != 2){
  1203. return Result::error('请完成之前的步骤!');
  1204. }
  1205. $template_info = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first();
  1206. if(empty($template_info)){
  1207. $template = WebsiteTemplate::insertGetId(['website_id' => $data['website_id'],'template_data' => $data['template_data']]);
  1208. }else{
  1209. $template = WebsiteTemplate::where('website_id', $data['website_id'])->update(['template_data' => $data['template_data']]);
  1210. }
  1211. if(empty($template)){
  1212. return Result::error('保存失败!');
  1213. }else{
  1214. return Result::success($template);
  1215. }
  1216. }
  1217. }