PublicRpcService.php 44 KB

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