PublicRpcService.php 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950
  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. #[RpcService(name: "PublicRpcService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
  25. class PublicRpcService implements PublicRpcServiceInterface
  26. {
  27. #[Inject]
  28. protected Redis $redis;
  29. /**
  30. * @param array $data
  31. * @return array
  32. */
  33. public function getDistrictList(array $data): array
  34. {
  35. $where = [];
  36. if (isset($data['keyWord'])) {
  37. $where = [
  38. ['name', 'like', '%' . $data['keyWord'] . '%']
  39. ];
  40. }
  41. $result = [];
  42. if (isset($data['pageSize'])) {
  43. $rep = District::where($where)->limit($data['pageSize'])->offset(($data['page'] - 1) * $data['pageSize'])->orderBy("code", "asc")->get();
  44. $count = District::where($where)->count();
  45. $result = [
  46. 'rows' => $rep,
  47. 'count' => $count
  48. ];
  49. } else {
  50. $result = District::where($data)->orderBy("code", "asc")->get();
  51. }
  52. return $result ? Result::success($result) : Result::error("没有查到数据");
  53. }
  54. /**
  55. * @param array $data
  56. * @return array
  57. */
  58. public function getUserLevelList(array $data): array
  59. {
  60. $where = [];
  61. if (isset($data['keyWord'])) {
  62. $where = [
  63. ['name', 'like', '%' . $data['keyWord'] . '%'],
  64. ];
  65. }
  66. $result = [];
  67. if (isset($data['pageSize'])) {
  68. $rep = UserLevel::where($where)->limit($data['pageSize'])->offset(($data['page'] - 1) * $data['pageSize'])->orderBy("id", "asc")->get();
  69. $count = UserLevel::where($where)->count();
  70. $result = [
  71. 'rows' => $rep,
  72. 'count' => $count,
  73. ];
  74. } else {
  75. $result = UserLevel::orderBy("id", "asc")->get();
  76. }
  77. return $result ? Result::success($result) : Result::error("没有查到数据");
  78. }
  79. /**
  80. * 添加用户等级
  81. * @param array $data
  82. * @return array
  83. */
  84. public function addUserLevel(array $data): array
  85. {
  86. LevelUser::insertGetId($data);
  87. return Result::success([]);
  88. }
  89. /**
  90. * 更新等级
  91. * @param array $data
  92. * @return array
  93. */
  94. public function updateUserLevel(array $data): array
  95. {
  96. $result = LevelUser::where(['id' => $data['id']])->update($data);
  97. if ($result) {
  98. return Result::success($result);
  99. }
  100. return Result::error("更新失败");
  101. }
  102. /**
  103. * 删除等级
  104. * @param array $data
  105. * @return array
  106. */
  107. public function delUserLevel(array $data): array
  108. {
  109. $result = LevelUser::where(['id' => $data['id']])->delete();
  110. if ($result) {
  111. return Result::success($result);
  112. }
  113. return Result::error("删除失败");
  114. }
  115. /**
  116. * 查询投诉举报信息
  117. * @param array $data
  118. * @return array
  119. */
  120. public function getLetterOfComplaint(array $data = []): array
  121. {
  122. var_dump("====");
  123. $where = [];
  124. if (isset($data['user_id']) && !empty($data['user_id'])) {
  125. array_push($where, ['letter_of_complaint.user_id', '=', $data['user_id']]);
  126. }
  127. if (isset($data['nature']) && !empty($data['nature'])) {
  128. array_push($where, ['letter_of_complaint.nature', '=', $data['nature']]);
  129. }
  130. if (isset($data['nature_level0']) && !empty($data['nature_level0'])) {
  131. array_push($where, ['letter_of_complaint.nature_level0', '=', $data['nature_level0']]);
  132. }
  133. if (isset($data['status']) && !empty($data['status'])) {
  134. array_push($where, ['letter_of_complaint.status', '=', $data['status']]);
  135. }
  136. $result = [];
  137. if (isset($data['pageSize'])) {
  138. $rep = LetterOfComplaint::where($where)
  139. ->leftJoin("letter_type as type_a", "letter_of_complaint.nature", "type_a.id")
  140. ->leftJoin("letter_type as type_c", "letter_of_complaint.nature_level0", "type_c.id")
  141. ->leftJoin("letter_type as type_b", "letter_of_complaint.nature_level1", "type_b.id")
  142. ->leftJoin("letter_type as type_e", "letter_of_complaint.nature_level3", "type_e.id")
  143. ->leftJoin("letter_type as type_d", "letter_of_complaint.status", "type_d.id")
  144. ->select(
  145. "letter_of_complaint.*",
  146. "type_a.type_name as nature_name",
  147. "type_b.type_name as nature_name1",
  148. "type_c.type_name as nature_name0",
  149. "type_d.type_name as status_name",
  150. "type_e.type_name as nature_name3"
  151. )
  152. ->limit($data['pageSize'])->offset(($data['page'] - 1) * $data['pageSize'])->orderBy("letter_of_complaint.id", "desc")->get();
  153. $count = LetterOfComplaint::where($where)->count();
  154. if ($rep) {
  155. foreach ($rep as $val) {
  156. if ($val['judgment']) {
  157. $val['judgment'] = json_decode($val['judgment']);
  158. }
  159. if ($val['audio_and_video']) {
  160. $val['audio_and_video'] = json_decode($val['audio_and_video']);
  161. }
  162. if ($val['contract']) {
  163. $val['contract'] = json_decode($val['contract']);
  164. }
  165. if ($val['qualifications']) {
  166. $val['qualifications'] = json_decode($val['qualifications']);
  167. }
  168. }
  169. }
  170. $result = [
  171. 'rows' => $rep,
  172. 'count' => $count,
  173. ];
  174. } else {
  175. $result = LetterOfComplaint::where($where)
  176. ->leftJoin("letter_type as type_a", "letter_of_complaint.nature", "type_a.id")
  177. ->leftJoin("letter_type as type_c", "letter_of_complaint.nature_level0", "type_c.id")
  178. ->leftJoin("letter_type as type_b", "letter_of_complaint.nature_level1", "type_b.id")
  179. ->leftJoin("letter_type as type_e", "letter_of_complaint.nature_level3", "type_e.id")
  180. ->leftJoin("letter_type as type_d", "letter_of_complaint.status", "type_d.id")
  181. ->select(
  182. "letter_of_complaint.*",
  183. "type_a.type_name as nature_name",
  184. "type_b.type_name as nature_name1",
  185. "type_c.type_name as nature_name0",
  186. "type_d.type_name as status_name",
  187. "type_e.type_name as nature_name3"
  188. )
  189. ->orderBy("letter_of_complaint.id", "desc")->get();
  190. }
  191. return $result ? Result::success($result) : Result::error("没有查到数据");
  192. }
  193. /**
  194. * 添加投诉举报信息
  195. * @param array $data
  196. * @return array
  197. */
  198. public function addLetterOfComplaint(array $data): array
  199. {
  200. $data['judgment'] = $data['judgment'] ? json_encode($data['judgment']) : '';
  201. $data['audio_and_video'] = $data['audio_and_video'] ? json_encode($data['audio_and_video']) : '';
  202. $data['contract'] = $data['contract'] ? json_encode($data['contract']) : '';
  203. $data['qualifications'] = $data['qualifications'] ? json_encode($data['qualifications']) : '';
  204. unset($data['id']);
  205. $result = LetterOfComplaint::insertGetId($data);
  206. if (empty($result)) {
  207. return Result::error("创建失败", 0);
  208. } else {
  209. return Result::success(["id" => $result]);
  210. }
  211. }
  212. /**
  213. * 用户端更新投诉举报
  214. * @param array $data
  215. * @return array
  216. */
  217. public function userUpLetterOfComplaint(array $data): array
  218. {
  219. $data['judgment'] = $data['judgment'] ? json_encode($data['judgment']) : '';
  220. $data['audio_and_video'] = $data['audio_and_video'] ? json_encode($data['audio_and_video']) : '';
  221. $data['contract'] = $data['contract'] ? json_encode($data['contract']) : '';
  222. $data['qualifications'] = $data['qualifications'] ? json_encode($data['qualifications']) : '';
  223. $result = LetterOfComplaint::where(['id' => $data['id']])->update($data);
  224. if (empty($result)) {
  225. return Result::error("创建失败", 0);
  226. } else {
  227. return Result::success(["id" => $result]);
  228. }
  229. }
  230. /**
  231. * 管理后台更新投诉举报信息
  232. * @param array $data
  233. * @return array
  234. */
  235. public function upLetterOfComplaint(array $data): array
  236. {
  237. var_dump("admin:", $data);
  238. $where = [
  239. 'id' => $data['id'],
  240. ];
  241. $filtered_array = array_filter($data, function ($value) {
  242. return $value !== "" && $value !== null && $value !== false && !is_array($value) || !empty($value);
  243. });
  244. $filtered_array['judgment'] = isset($filtered_array['judgment']) ? json_encode($filtered_array['judgment']) : '';
  245. $filtered_array['audio_and_video'] = isset($filtered_array['audio_and_video']) ? json_encode($filtered_array['audio_and_video']) : '';
  246. $filtered_array['contract'] = isset($filtered_array['contract']) ? json_encode($filtered_array['contract']) : '';
  247. $filtered_array['qualifications'] = isset($filtered_array['qualifications']) ? json_encode($filtered_array['qualifications']) : '';
  248. unset($filtered_array['nature_name']);
  249. unset($filtered_array['type_name']);
  250. unset($filtered_array['nature_level_name']);
  251. unset($filtered_array['status_name']);
  252. unset($filtered_array['is_admin']);
  253. unset($filtered_array['type_level_name']);
  254. $result = LetterOfComplaint::where($where)->update($filtered_array);
  255. if ($result) {
  256. return Result::success($result);
  257. }
  258. return Result::error("更新失败", 0);
  259. }
  260. /**
  261. * 查询投诉举报记录
  262. * @param array $data
  263. * @return array
  264. */
  265. public function getLetterOfComplaintInfo(array $data): array
  266. {
  267. $where = [
  268. 'letter_of_complaint.id' => $data['id'],
  269. ];
  270. if (isset($data['user_id']) && !empty($data['user_id'])) {
  271. array_push($where, ['letter_of_complaint.user_id', '=', $data['user_id']]);
  272. }
  273. $result = LetterOfComplaint::where($where)
  274. ->leftJoin("letter_type as type_a", "letter_of_complaint.nature", "type_a.id")
  275. ->leftJoin("letter_type as type_c", "letter_of_complaint.nature_level0", "type_c.id")
  276. ->leftJoin("letter_type as type_b", "letter_of_complaint.nature_level1", "type_b.id")
  277. ->leftJoin("letter_type as type_e", "letter_of_complaint.nature_level3", "type_e.id")
  278. ->leftJoin("letter_type as type_d", "letter_of_complaint.status", "type_d.id")
  279. ->select(
  280. "letter_of_complaint.*",
  281. "type_a.type_name as nature_name",
  282. "type_b.type_name as nature_name1",
  283. "type_c.type_name as nature_name0",
  284. "type_d.type_name as status_name",
  285. "type_e.type_name as nature_name3"
  286. )
  287. ->first();
  288. return Result::success($result);
  289. }
  290. /**
  291. * 删除投诉举报信息
  292. * @param array $data
  293. * @return array
  294. */
  295. public function delLetterOfComplaint(array $data): array
  296. {
  297. $result = LetterOfComplaint::when($data, function ($query) use ($data) {
  298. if (isset($data['id']) && !empty($data['id'])) {
  299. $query->where(['id' => $data['id']]);
  300. }
  301. if (isset($data['user_id']) && !empty($data['user_id'])) {
  302. $query->where(['user_id' => $data['user_id']]);
  303. }
  304. })->delete();
  305. if (empty($result)) {
  306. return Result::error("删除失败", 0);
  307. } else {
  308. return Result::success();
  309. }
  310. }
  311. /**
  312. * 获取举报信息类型
  313. * @param array $data
  314. * @return array
  315. */
  316. public function getLetterType(array $data): array
  317. {
  318. $where = [];
  319. if (isset($data['type'])) {
  320. array_push($where, ['type', '=', $data['type']]);
  321. }
  322. if (isset($data['pid']) && $data['pid'] > 0) {
  323. array_push($where, ['pid', '=', $data['pid']]);
  324. }
  325. $result = LetterType::where($where)->orderBy('sort', 'asc')->get();
  326. return $result ? Result::success($result) : Result::error("没有查到数据");
  327. }
  328. /**
  329. * 更新举报类型
  330. * @param array $data
  331. * @return array
  332. */
  333. public function upLetterType(array $data): array
  334. {
  335. return [];
  336. }
  337. /**
  338. * 添加举报类型
  339. * @param array $data
  340. * @return array
  341. */
  342. public function addLetterType(array $data): array
  343. {
  344. $result = LetterType::insertGetId($data);
  345. if (empty($result)) {
  346. return Result::error("创建失败", 0);
  347. } else {
  348. return Result::success(["id" => $result]);
  349. }
  350. }
  351. /**
  352. * 删除举报类型
  353. * @param array $data
  354. * @return array
  355. */
  356. public function delLetterType(array $data): array
  357. {
  358. $result = LetterType::where('id', $data['id'])->delete();
  359. if (empty($result)) {
  360. return Result::error("删除失败", 0);
  361. } else {
  362. return Result::success();
  363. }
  364. }
  365. /**
  366. * 检测是否已经被接案
  367. * @param array $data
  368. * @return array
  369. */
  370. public function checkMeasure(array $data): array
  371. {
  372. $where = [
  373. 'id' => $data['id'],
  374. ];
  375. $letterOfComplaintInfo = LetterOfComplaint::where($where)->first();
  376. var_dump("查询数据:", $letterOfComplaintInfo['admin_id'], $data['user_id']);
  377. //操作人和当前登陆用户id 相等说明是当前人接收的案件
  378. if (($letterOfComplaintInfo['admin_id'] == $data['user_id']) || empty($letterOfComplaintInfo['admin_id'])) {
  379. return Result::success();
  380. } else {
  381. return Result::error("您不能处理其他人已经接过的案件", 0);
  382. }
  383. }
  384. /**
  385. * 后台获取职能部门
  386. * @param array $data
  387. * @return array
  388. */
  389. public function getZhinengbumenList(array $data): array
  390. {
  391. // 获取分页参数,默认每页 10 条记录
  392. $page = isset($data['page']) ? (int) $data['page'] : 1;
  393. $perPage = isset($data['pagesize']) ? (int) $data['pagesize'] : 10;
  394. // 查询数据并分页
  395. $query = Department::query();
  396. // 可以在这里添加更多的查询条件
  397. if (isset($data['search'])) {
  398. $query->where('name', 'like', '%' . $data['search'] . '%');
  399. }
  400. // 执行分页查询
  401. $result = $query->paginate($perPage, ['*'], 'page', $page);
  402. // 返回分页结果
  403. return Result::success([
  404. 'count' => $result->total(),
  405. 'current_page' => $result->currentPage(),
  406. 'last_page' => $result->lastPage(),
  407. 'pagesize' => $result->perPage(),
  408. 'rows' => $result->items(),
  409. ]);
  410. }
  411. /**
  412. * 添加获取职能部门
  413. * @param array $data
  414. * @return array
  415. */
  416. public function addZhinengbumen(array $data): array
  417. {
  418. $result = Department::insertGetId($data);
  419. if (empty($result)) {
  420. return Result::error("创建失败", 0);
  421. } else {
  422. return Result::success(["id" => $result]);
  423. }
  424. }
  425. public function delZhinengbumen(array $data): array
  426. {
  427. $result = Department::where('id', $data['id'])->delete();
  428. if (empty($result)) {
  429. return Result::error("删除失败", 0);
  430. } else {
  431. return Result::success();
  432. }
  433. }
  434. public function getZhinengbumen(array $data): array
  435. {
  436. $result = Department::where('id', $data['id'])->first();
  437. return Result::success($result);
  438. }
  439. public function getPidZhinengbumen(array $data): array
  440. {
  441. if (empty($data['pid'])) {
  442. $data['pid'] = 0;
  443. }
  444. $result = Department::where('pid', $data['pid'])->get();
  445. return Result::success($result);
  446. }
  447. public function modZhinengbumen(array $data): array
  448. {
  449. $result = Department::where('id', $data['id'])->update($data);
  450. if (empty($result)) {
  451. return Result::error("修改失败", 0);
  452. } else {
  453. return Result::success();
  454. }
  455. }
  456. /**
  457. * 查询职能列表
  458. * @param array $data
  459. * @return array
  460. */
  461. public function getDepartment(array $data): array
  462. {
  463. $where = [];
  464. if (isset($data['pid'])) {
  465. $where = [
  466. 'pid' => $data['pid'] ?? 0
  467. ];
  468. }
  469. $result = Department::when(!empty($where), function ($query) use ($where) {
  470. $query->where($where);
  471. })->orderBy("sort", "desc")->get();
  472. if (empty($result)) {
  473. return Result::error("查询失败", 0);
  474. } else {
  475. return Result::success($result);
  476. }
  477. }
  478. /**
  479. * 获取所有的buckets
  480. * @param array $data
  481. * @return array
  482. */
  483. public function getBuckets(array $data): array
  484. {
  485. $result = new MinioService();
  486. // 调用服务层的方法获取存储桶列表
  487. $bucketsResponse = $result->listBuckets();
  488. // 直接返回服务层生成的响应
  489. return Result::success($bucketsResponse['data']);
  490. }
  491. /**
  492. * 上传文件
  493. * @param array $data
  494. * @return array
  495. */
  496. public function uploadFile(array $data): array
  497. {
  498. $result = new MinioService();
  499. $rep = $result->uploadFile($data);
  500. if ($rep['code'] == 200) {
  501. return Result::success($rep['data']);
  502. } else {
  503. return Result::error("上传失败!");
  504. }
  505. }
  506. /**
  507. * 黑名单管理
  508. * @param array $data
  509. * @return array
  510. */
  511. public function getBlackWordList(array $data): array
  512. {
  513. $result = BlackWord::when($data, function ($query) use ($data) {
  514. if (isset($data['name']) && $data['name']) {
  515. $query->where('black_word.name', 'like', '%' . $data['name'] . '%');
  516. }
  517. })->orderBy('black_word.id', 'desc')
  518. ->paginate(
  519. intval($data['pageSize']),
  520. [
  521. 'black_word.*',
  522. ],
  523. 'page',
  524. intval($data['page'])
  525. );
  526. $count = $result->total();
  527. $returnData = [
  528. 'rows' => $result->items(),
  529. 'count' => $count
  530. ];
  531. return Result::success($returnData);
  532. }
  533. /**
  534. * 添加黑名单
  535. * @param array $data
  536. * @return array
  537. */
  538. public function addBlackWord(array $data): array
  539. {
  540. Db::beginTransaction();
  541. try {
  542. $info = BlackWord::where(['name' => $data['name']])->first();
  543. if ($info) {
  544. Db::rollBack();
  545. return Result::error("该黑名单已存在", 0);
  546. }
  547. $data['type'] = 10;
  548. $result = BlackWord::insertGetId($data);
  549. $redisKey = 'black_word';
  550. $this->redis->sAdd($redisKey, $data['name']);
  551. Db::commit();
  552. return Result::success(["id" => $result]);
  553. } catch (\Exception $e) {
  554. Db::rollBack();
  555. return Result::error("创建失败" . $e->getMessage(), 0);
  556. }
  557. }
  558. /**
  559. * 删除黑名单
  560. * @param array $data
  561. * @return array
  562. */
  563. public function delBlackWord(array $data): array
  564. {
  565. Db::beginTransaction();
  566. try {
  567. BlackWord::where(['name' => $data['name']])->delete();
  568. $redisKey = 'black_word';
  569. $this->redis->sRem($redisKey, $data['name']);
  570. Db::commit();
  571. return Result::success([]);
  572. } catch (\Exception $e) {
  573. Db::rollBack();
  574. return Result::error("删除失败" . $e->getMessage(), 0);
  575. }
  576. }
  577. /**
  578. * 修改违禁词
  579. * @param array $data
  580. * @return array
  581. */
  582. public function upBlackWord(array $data): array
  583. {
  584. Db::beginTransaction();
  585. try {
  586. $checkInfo = BlackWord::where(['name' => $data['name']])->first();
  587. if ($checkInfo) {
  588. Db::rollBack();
  589. return Result::error("该违禁词已经存在", 0);
  590. }
  591. $blackWordInfo = BlackWord::where(['id' => $data['id']])->first();
  592. if ($blackWordInfo) {
  593. //先删除redis
  594. $blackWordInfo = $blackWordInfo->toArray();
  595. $redisKey = 'black_word';
  596. $this->redis->sRem($redisKey, $blackWordInfo['name']);
  597. $this->redis->sAdd($redisKey, $data['name']);
  598. BlackWord::where(['id' => $data['id']])->update(['name' => $data['name']]);
  599. Db::commit();
  600. return Result::success([]);
  601. } else {
  602. Db::rollBack();
  603. return Result::error("系统错误", 0);
  604. }
  605. } catch (\Exception $e) {
  606. Db::rollBack();
  607. return Result::error("修改失败" . $e->getMessage(), 0);
  608. }
  609. }
  610. /**
  611. * 获取getTemplateClass
  612. * @param array $data
  613. * @return array
  614. */
  615. public function getTemplateClass(array $data): array
  616. {
  617. $result = TemplateClass::get();
  618. return Result::success($result);
  619. }
  620. public function getTemplateList(array $data): array
  621. {
  622. $where = [];
  623. if (!empty($data['template_class_id'])) {
  624. $where['template_class_id'] = $data['template_class_id'];
  625. }
  626. if (!empty($data['template_name'])) {
  627. $where['template_name'] = $data['template_name'];
  628. }
  629. $result = Template::where($where)
  630. ->leftJoin('template_class', 'template.template_class_id', 'template_class.id')
  631. ->select('template.*', 'template_class.name as template_class_name')
  632. ->orderBy('template.id', 'desc')
  633. ->paginate($data['page_size'], ['*'], 'mypage_name', $data['page']);
  634. // 使用 items 方法获取分页数据
  635. // $items = collect($result->items());
  636. // $items->each(function ($item) {
  637. // $item['template_content'] = json_decode($item['template_content'], true);
  638. // });
  639. return Result::success($result);
  640. }
  641. public function getTemplateInfo(array $data): array
  642. {
  643. $result = Template::where('template.id', $data['id'])
  644. ->leftJoin('template_class', 'template.template_class_id', 'template_class.id')
  645. ->select('template.*', 'template_class.name as template_class_name')
  646. ->first();
  647. return Result::success($result);
  648. }
  649. public function addTemplate(array $data): array
  650. {
  651. var_dump($data);
  652. unset($data['user_id']);
  653. $result = Template::insertGetId($data);
  654. if ($result) {
  655. $returData = Template::where('id', $result)->first();
  656. return Result::success($returData);
  657. } else {
  658. return Result::error("添加失败", 0);
  659. }
  660. }
  661. public function delTemplate(array $data): array
  662. {
  663. $result = Template::where('id', $data['id'])->delete();
  664. var_dump($result, '-------------------delete');
  665. if ($result) {
  666. return Result::success($result);
  667. } else {
  668. return Result::error("删除失败", 0);
  669. }
  670. }
  671. public function updateTemplate(array $data): array
  672. {
  673. unset($data['user_id']);
  674. $result = Template::where('id', $data['id'])->update($data);
  675. var_dump($result, '-------------------update');
  676. if (!$result) {
  677. return Result::error("更新失败", 0);
  678. } else {
  679. return Result::success('更新成功');
  680. }
  681. }
  682. public function getSectorList(array $data): array
  683. {
  684. $where = [];
  685. if (!empty($data['template_class_id'])) {
  686. $where['template_class.id'] = $data['template_class_id'];
  687. }
  688. if (!empty($data['template_class_name'])) {
  689. $where[] = ['template_class.name', 'like', '%' . $data['template_class_name'] . '%'];
  690. }
  691. if (!empty($data['sector_name'])) {
  692. if (!empty($data['sector_name'])) {
  693. // $where['sector_name'] = $data['sector_name'];
  694. $where[] = ['sector.sector_name', 'like', '%' . $data['sector_name'] . '%'];
  695. }
  696. }
  697. $result = Sector::where($where)
  698. ->leftJoin('template', 'template.id', '=', 'sector.template_id')
  699. ->leftJoin('template_class', 'template_class.id', '=', 'sector.template_id') // 添加这一行
  700. ->select('sector.*', 'sector.sector_name', 'template.template_name', 'template_class.name as template_class_name', 'template_class.id as template_class_id') // 修改这一行
  701. ->orderBy('sector.id', 'desc')
  702. ->paginate($data['page_size'], ['*'], 'mypage_name', $data['page']);
  703. return Result::success($result);
  704. }
  705. public function getSectorInfo(array $data): array
  706. {
  707. $where = [];
  708. $where[] = ['sector.id', '=', $data['id']];
  709. $result = Sector::where($where)
  710. ->leftJoin('template', 'template.id', '=', 'sector.template_id')
  711. ->leftJoin('template_class', 'template_class.id', '=', 'template.template_class_id') // 添加这一行
  712. ->select('sector.*', 'template.template_name', 'template_class.name as template_class_name', 'template_class.id as template_class_id') // 修改这一行
  713. ->orderBy('sector.id', 'desc')
  714. ->get();
  715. return Result::success($result);
  716. }
  717. /**
  718. * 获取经纬度信息
  719. * @return void
  720. */
  721. public function getIpInfo(array $data) :array
  722. {
  723. $client_ip = isset($data['ip']) && $data['ip']??$_SERVER['REMOTE_ADDR'];
  724. // 使用 IPinfo 服务获取 IP 信息
  725. $api_url = "https://ipinfo.io/{$client_ip}/json";
  726. $ch = curl_init($api_url);
  727. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  728. $response = curl_exec($ch);
  729. curl_close($ch);
  730. // 解析 JSON 响应
  731. $ip_info = json_decode($response, true);
  732. // 提取地址和经纬度
  733. if ($ip_info && !isset($ip_info['bogon'])) {
  734. $latitude = explode(',', $ip_info['loc'])[0];
  735. $longitude = explode(',', $ip_info['loc'])[1];
  736. $ip_info['latitude'] = $latitude;
  737. $ip_info['longitude'] = $longitude;
  738. return Result::success($ip_info);
  739. } else {
  740. $data['ip'] = '101.254.114.212';
  741. $this->getIpinfo(["ip"=>$data['ip']]);
  742. }
  743. }
  744. /**
  745. * 获取天气
  746. * @param array $data
  747. * @return array
  748. */
  749. public function getWeatherInfo(array $data) :array
  750. {
  751. $month = $data['month'] ?? date('m');
  752. $day = $data['day'] ?? date('d');
  753. // 使用缓存键
  754. $cacheKey = "tsbb_data_weather_{$month}_{$day}";
  755. // 尝试从缓存获取数据
  756. $container = \Hyperf\Context\ApplicationContext::getContainer();
  757. $cache = $container->get(\Psr\SimpleCache\CacheInterface::class);
  758. if ($cachedData = $cache->get($cacheKey)) {
  759. return Result::success(unserialize($cachedData));
  760. }
  761. $location = $data['latitude'].":".$data['longitude'];
  762. $api_url = "https://api.seniverse.com/v3/weather/now.json?key=".\Hyperf\Support\env('WEATHER_KEY')."&location=".$location."&language=zh-Hans&unit=c";
  763. $ch = curl_init($api_url);
  764. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  765. $response = curl_exec($ch);
  766. curl_close($ch);
  767. // 解析 JSON 响应
  768. $WeatherInfo = json_decode($response, true);
  769. // 缓存结果,设置1小时过期
  770. $cache->set($cacheKey, serialize($WeatherInfo), 3600);
  771. if($WeatherInfo){
  772. return Result::success($WeatherInfo);
  773. }else{
  774. return Result::error("获取天气失败", 0);
  775. }
  776. }
  777. /**
  778. * 获取农历信息
  779. * @return void
  780. */
  781. public function getCalendar(array $data) :array
  782. {
  783. $calendar = new Calendar();
  784. $result = $calendar->solar($data['year'], $data['month'], $data['day'], $data['hour']); // 阳历
  785. return Result::success($result);
  786. }
  787. public function addSector(array $data): array
  788. {
  789. unset($data['user_id']);
  790. // $data['page_type'] = json_encode($data['page_type']);
  791. $result = Sector::insertGetId($data);
  792. return Result::success();
  793. }
  794. public function delSector(array $data): array
  795. {
  796. $result = Sector::where('id', $data['id'])->delete();
  797. if ($result == 1) {
  798. return Result::success('删除成功');
  799. } else {
  800. return Result::error('删除失败');
  801. }
  802. }
  803. public function updateSector(array $data): array
  804. {
  805. unset($data['user_id']);
  806. $result = Sector::where('id', $data['id'])->update($data);
  807. if ($result == 1) {
  808. return Result::success('修改成功');
  809. } else {
  810. return Result::error('修改失败');
  811. }
  812. }
  813. public function getComponentList(array $data): array
  814. {
  815. var_dump($data, '---------');
  816. $where = [];
  817. // $where[] = ['sector.id', '=', $data['id']];
  818. if (!empty($data['template_class_id'])) {
  819. $where['template_class.id'] = $data['template_class_id'];
  820. }
  821. if (!empty($data['component_name'])) {
  822. $where['component.component_name'] = $data['component_name'];
  823. }
  824. if (!empty($data['sector_id'])) {
  825. $where['sector.id'] = $data['sector_id'];
  826. };
  827. $result = Component::where($where)
  828. ->leftJoin('template', 'template.id', '=', 'component.template_id')
  829. ->leftJoin('template_class', 'template_class.id', '=', 'template.template_class_id') // 添加这一行
  830. ->leftJoin('sector', 'sector.id', '=', 'component.sector_id')
  831. ->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') // 修改这一行)
  832. ->orderBy('sector.updated_at', 'desc')
  833. ->orderBy('sector.created_at', 'desc')
  834. ->paginate($data['page_size'], ['*'], 'mypage_name', $data['page']);
  835. return Result::success($result);
  836. }
  837. public function getComponentInfo(array $data): array
  838. {
  839. $where = [];
  840. $result = Component::where($where)
  841. ->leftJoin('template', 'template.id', '=', 'component.template_id')
  842. ->leftJoin('template_class', 'template_class.id', '=', 'template.template_class_id') // 添加这一行
  843. ->leftJoin('sector', 'sector.id', '=', 'component.sector_id')
  844. ->select('template_class.name as template_class_name', 'template.template_name as template_name', 'sector.sector_name as sector_name', 'component.*')
  845. ->get();
  846. return Result::success($result);
  847. }
  848. public function addComponent(array $data): array
  849. {
  850. unset($data['user_id']);
  851. $result = Component::insertGetId($data);
  852. if ($result) {
  853. return Result::success($result);
  854. } else {
  855. return Result::error('添加失败');
  856. }
  857. }
  858. public function delComponent(array $data): array
  859. {
  860. $result = Component::where('id', $data['id'])->delete();
  861. return Result::success($result);
  862. }
  863. public function updateComponent(array $data): array
  864. {
  865. $result = Component::where('id', $data['id'])->update($data);
  866. return Result::success($result);
  867. }
  868. public function getWebsiteTemplateList(array $data): array
  869. {
  870. $where = [];
  871. $result = WebsiteTemplateInfo::where($where)
  872. ->leftJoin('website', 'website_template_info.website_id', '=', 'website.id')
  873. ->select('website_template_info.*', 'website.website_name')
  874. ->orderBy('website_template_info.id', 'desc')
  875. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  876. if ($result) {
  877. return Result::success($result);
  878. } else {
  879. return Result::error('暂无数据');
  880. }
  881. }
  882. public function getWebsiteTemplateInfo(array $data)
  883. {
  884. $where = [];
  885. if (isset($data['id'])) {
  886. $where[] = ['id', '=', $data['id']];
  887. }
  888. $result = WebsiteTemplateInfo::where($where)
  889. ->leftJoin('website', 'website_template_info.website_id', '=', 'website.id')
  890. ->leftJoin('website_template', 'website_template_info.template_id', '=', 'website_template.id')
  891. ->select('website_template_info.*', 'website.website_name')
  892. ->get();
  893. if ($result) {
  894. return Result::success($result);
  895. } else {
  896. return Result::error('暂无数据');
  897. }
  898. }
  899. }