PublicRpcService.php 47 KB

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