PublicRpcService.php 44 KB

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