PublicRpcService.php 52 KB

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