PublicRpcService.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636
  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. #[RpcService(name: "PublicRpcService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
  17. class PublicRpcService implements PublicRpcServiceInterface
  18. {
  19. #[Inject]
  20. protected Redis $redis;
  21. /**
  22. * @param array $data
  23. * @return array
  24. */
  25. public function getDistrictList(array $data): array
  26. {
  27. $where = [];
  28. if(isset($data['keyWord'])){
  29. $where = [
  30. ['name','like','%'.$data['keyWord'].'%']
  31. ];
  32. }
  33. $result = [];
  34. if(isset($data['pageSize'])){
  35. $rep = District::where($where)->limit($data['pageSize'])->offset(($data['page']-1)*$data['pageSize'])->orderBy("code","asc")->get();
  36. $count = District::where($where)->count();
  37. $result = [
  38. 'rows'=>$rep,
  39. 'count'=>$count
  40. ];
  41. }else{
  42. $result = District::where($data)->orderBy("code","asc")->get();
  43. }
  44. return $result?Result::success($result):Result::error("没有查到数据");
  45. }
  46. /**
  47. * @param array $data
  48. * @return array
  49. */
  50. public function getUserLevelList(array $data): array
  51. {
  52. $where = [];
  53. if (isset($data['keyWord'])) {
  54. $where = [
  55. ['name', 'like', '%' . $data['keyWord'] . '%'],
  56. ];
  57. }
  58. $result = [];
  59. if (isset($data['pageSize'])) {
  60. $rep = UserLevel::where($where)->limit($data['pageSize'])->offset(($data['page'] - 1) * $data['pageSize'])->orderBy("id", "asc")->get();
  61. $count = UserLevel::where($where)->count();
  62. $result = [
  63. 'rows' => $rep,
  64. 'count' => $count,
  65. ];
  66. } else {
  67. $result = UserLevel::orderBy("id", "asc")->get();
  68. }
  69. return $result ? Result::success($result) : Result::error("没有查到数据");
  70. }
  71. /**
  72. * 添加用户等级
  73. * @param array $data
  74. * @return array
  75. */
  76. public function addUserLevel(array $data): array
  77. {
  78. LevelUser::insertGetId($data);
  79. return Result::success([]);
  80. }
  81. /**
  82. * 更新等级
  83. * @param array $data
  84. * @return array
  85. */
  86. public function updateUserLevel(array $data): array
  87. {
  88. $result = LevelUser::where(['id' => $data['id']])->update($data);
  89. if ($result) {
  90. return Result::success($result);
  91. }
  92. return Result::error("更新失败");
  93. }
  94. /**
  95. * 删除等级
  96. * @param array $data
  97. * @return array
  98. */
  99. public function delUserLevel(array $data): array
  100. {
  101. $result = LevelUser::where(['id' => $data['id']])->delete();
  102. if ($result) {
  103. return Result::success($result);
  104. }
  105. return Result::error("删除失败");
  106. }
  107. /**
  108. * 查询投诉举报信息
  109. * @param array $data
  110. * @return array
  111. */
  112. public function getLetterOfComplaint(array $data = []): array
  113. {
  114. var_dump("====");
  115. $where = [];
  116. if (isset($data['user_id']) && !empty($data['user_id'])) {
  117. array_push($where, ['letter_of_complaint.user_id', '=', $data['user_id']]);
  118. }
  119. if (isset($data['nature']) && !empty($data['nature'])) {
  120. array_push($where, ['letter_of_complaint.nature', '=', $data['nature']]);
  121. }
  122. if (isset($data['nature_level0']) && !empty($data['nature_level0'])) {
  123. array_push($where, ['letter_of_complaint.nature_level0', '=', $data['nature_level0']]);
  124. }
  125. if (isset($data['status']) && !empty($data['status'])) {
  126. array_push($where, ['letter_of_complaint.status', '=', $data['status']]);
  127. }
  128. $result = [];
  129. if (isset($data['pageSize'])) {
  130. $rep = LetterOfComplaint::where($where)
  131. ->leftJoin("letter_type as type_a", "letter_of_complaint.nature", "type_a.id")
  132. ->leftJoin("letter_type as type_c", "letter_of_complaint.nature_level0", "type_c.id")
  133. ->leftJoin("letter_type as type_b", "letter_of_complaint.nature_level1", "type_b.id")
  134. ->leftJoin("letter_type as type_e", "letter_of_complaint.nature_level3", "type_e.id")
  135. ->leftJoin("letter_type as type_d", "letter_of_complaint.status", "type_d.id")
  136. ->select("letter_of_complaint.*",
  137. "type_a.type_name as nature_name",
  138. "type_b.type_name as nature_name1",
  139. "type_c.type_name as nature_name0",
  140. "type_d.type_name as status_name",
  141. "type_e.type_name as nature_name3")
  142. ->limit($data['pageSize'])->offset(($data['page'] - 1) * $data['pageSize'])->orderBy("letter_of_complaint.id", "desc")->get();
  143. $count = LetterOfComplaint::where($where)->count();
  144. if ($rep) {
  145. foreach ($rep as $val) {
  146. if ($val['judgment']) {
  147. $val['judgment'] = json_decode($val['judgment']);
  148. }
  149. if ($val['audio_and_video']) {
  150. $val['audio_and_video'] = json_decode($val['audio_and_video']);
  151. }
  152. if ($val['contract']) {
  153. $val['contract'] = json_decode($val['contract']);
  154. }
  155. if ($val['qualifications']) {
  156. $val['qualifications'] = json_decode($val['qualifications']);
  157. }
  158. }
  159. }
  160. $result = [
  161. 'rows' => $rep,
  162. 'count' => $count,
  163. ];
  164. } else {
  165. $result = LetterOfComplaint::where($where)
  166. ->leftJoin("letter_type as type_a", "letter_of_complaint.nature", "type_a.id")
  167. ->leftJoin("letter_type as type_c", "letter_of_complaint.nature_level0", "type_c.id")
  168. ->leftJoin("letter_type as type_b", "letter_of_complaint.nature_level1", "type_b.id")
  169. ->leftJoin("letter_type as type_e", "letter_of_complaint.nature_level3", "type_e.id")
  170. ->leftJoin("letter_type as type_d", "letter_of_complaint.status", "type_d.id")
  171. ->select("letter_of_complaint.*",
  172. "type_a.type_name as nature_name",
  173. "type_b.type_name as nature_name1",
  174. "type_c.type_name as nature_name0",
  175. "type_d.type_name as status_name",
  176. "type_e.type_name as nature_name3")
  177. ->orderBy("letter_of_complaint.id", "desc")->get();
  178. }
  179. return $result ? Result::success($result) : Result::error("没有查到数据");
  180. }
  181. /**
  182. * 添加投诉举报信息
  183. * @param array $data
  184. * @return array
  185. */
  186. public function addLetterOfComplaint(array $data): array
  187. {
  188. $data['judgment'] = $data['judgment'] ? json_encode($data['judgment']) : '';
  189. $data['audio_and_video'] = $data['audio_and_video'] ? json_encode($data['audio_and_video']) : '';
  190. $data['contract'] = $data['contract'] ? json_encode($data['contract']) : '';
  191. $data['qualifications'] = $data['qualifications'] ? json_encode($data['qualifications']) : '';
  192. unset($data['id']);
  193. $result = LetterOfComplaint::insertGetId($data);
  194. if (empty($result)) {
  195. return Result::error("创建失败", 0);
  196. } else {
  197. return Result::success(["id" => $result]);
  198. }
  199. }
  200. /**
  201. * 用户端更新投诉举报
  202. * @param array $data
  203. * @return array
  204. */
  205. public function userUpLetterOfComplaint(array $data): array
  206. {
  207. $data['judgment'] = $data['judgment'] ? json_encode($data['judgment']) : '';
  208. $data['audio_and_video'] = $data['audio_and_video'] ? json_encode($data['audio_and_video']) : '';
  209. $data['contract'] = $data['contract'] ? json_encode($data['contract']) : '';
  210. $data['qualifications'] = $data['qualifications'] ? json_encode($data['qualifications']) : '';
  211. $result = LetterOfComplaint::where(['id' => $data['id']])->update($data);
  212. if (empty($result)) {
  213. return Result::error("创建失败", 0);
  214. } else {
  215. return Result::success(["id" => $result]);
  216. }
  217. }
  218. /**
  219. * 管理后台更新投诉举报信息
  220. * @param array $data
  221. * @return array
  222. */
  223. public function upLetterOfComplaint(array $data): array
  224. {
  225. var_dump("admin:", $data);
  226. $where = [
  227. 'id' => $data['id'],
  228. ];
  229. $filtered_array = array_filter($data, function ($value) {
  230. return $value !== "" && $value !== null && $value !== false && !is_array($value) || !empty($value);
  231. });
  232. $filtered_array['judgment'] = isset($filtered_array['judgment']) ? json_encode($filtered_array['judgment']) : '';
  233. $filtered_array['audio_and_video'] = isset($filtered_array['audio_and_video']) ? json_encode($filtered_array['audio_and_video']) : '';
  234. $filtered_array['contract'] = isset($filtered_array['contract']) ? json_encode($filtered_array['contract']) : '';
  235. $filtered_array['qualifications'] = isset($filtered_array['qualifications']) ? json_encode($filtered_array['qualifications']) : '';
  236. unset($filtered_array['nature_name']);
  237. unset($filtered_array['type_name']);
  238. unset($filtered_array['nature_level_name']);
  239. unset($filtered_array['status_name']);
  240. unset($filtered_array['is_admin']);
  241. unset($filtered_array['type_level_name']);
  242. $result = LetterOfComplaint::where($where)->update($filtered_array);
  243. if ($result) {
  244. return Result::success($result);
  245. }
  246. return Result::error("更新失败", 0);
  247. }
  248. /**
  249. * 查询投诉举报记录
  250. * @param array $data
  251. * @return array
  252. */
  253. public function getLetterOfComplaintInfo(array $data): array
  254. {
  255. $where = [
  256. 'letter_of_complaint.id' => $data['id'],
  257. ];
  258. if (isset($data['user_id']) && !empty($data['user_id'])) {
  259. array_push($where, ['letter_of_complaint.user_id', '=', $data['user_id']]);
  260. }
  261. $result = LetterOfComplaint::where($where)
  262. ->leftJoin("letter_type as type_a", "letter_of_complaint.nature", "type_a.id")
  263. ->leftJoin("letter_type as type_c", "letter_of_complaint.nature_level0", "type_c.id")
  264. ->leftJoin("letter_type as type_b", "letter_of_complaint.nature_level1", "type_b.id")
  265. ->leftJoin("letter_type as type_e", "letter_of_complaint.nature_level3", "type_e.id")
  266. ->leftJoin("letter_type as type_d", "letter_of_complaint.status", "type_d.id")
  267. ->select("letter_of_complaint.*",
  268. "type_a.type_name as nature_name",
  269. "type_b.type_name as nature_name1",
  270. "type_c.type_name as nature_name0",
  271. "type_d.type_name as status_name",
  272. "type_e.type_name as nature_name3")
  273. ->first();
  274. return Result::success($result);
  275. }
  276. /**
  277. * 删除投诉举报信息
  278. * @param array $data
  279. * @return array
  280. */
  281. public function delLetterOfComplaint(array $data): array
  282. {
  283. $result = LetterOfComplaint::when($data,function ($query) use ($data){
  284. if(isset($data['id']) && !empty($data['id'])){
  285. $query->where(['id'=>$data['id']]);
  286. }
  287. if(isset($data['user_id']) && !empty($data['user_id'])){
  288. $query->where(['user_id'=>$data['user_id']]);
  289. }
  290. })->delete();
  291. if (empty($result)) {
  292. return Result::error("删除失败", 0);
  293. } else {
  294. return Result::success();
  295. }
  296. }
  297. /**
  298. * 获取举报信息类型
  299. * @param array $data
  300. * @return array
  301. */
  302. public function getLetterType(array $data): array
  303. {
  304. $where = [];
  305. if (isset($data['type'])) {
  306. array_push($where, ['type', '=', $data['type']]);
  307. }
  308. if (isset($data['pid']) && $data['pid']>0) {
  309. array_push($where, ['pid', '=', $data['pid']]);
  310. }
  311. $result = LetterType::where($where)->orderBy('sort','asc')->get();
  312. return $result ? Result::success($result) : Result::error("没有查到数据");
  313. }
  314. /**
  315. * 更新举报类型
  316. * @param array $data
  317. * @return array
  318. */
  319. public function upLetterType(array $data): array
  320. {
  321. return [];
  322. }
  323. /**
  324. * 添加举报类型
  325. * @param array $data
  326. * @return array
  327. */
  328. public function addLetterType(array $data): array
  329. {
  330. $result = LetterType::insertGetId($data);
  331. if (empty($result)) {
  332. return Result::error("创建失败", 0);
  333. } else {
  334. return Result::success(["id" => $result]);
  335. }
  336. }
  337. /**
  338. * 删除举报类型
  339. * @param array $data
  340. * @return array
  341. */
  342. public function delLetterType(array $data): array
  343. {
  344. $result = LetterType::where('id', $data['id'])->delete();
  345. if (empty($result)) {
  346. return Result::error("删除失败", 0);
  347. } else {
  348. return Result::success();
  349. }
  350. }
  351. /**
  352. * 检测是否已经被接案
  353. * @param array $data
  354. * @return array
  355. */
  356. public function checkMeasure(array $data): array
  357. {
  358. $where = [
  359. 'id' => $data['id'],
  360. ];
  361. $letterOfComplaintInfo = LetterOfComplaint::where($where)->first();
  362. var_dump("查询数据:", $letterOfComplaintInfo['admin_id'], $data['user_id']);
  363. //操作人和当前登陆用户id 相等说明是当前人接收的案件
  364. if (($letterOfComplaintInfo['admin_id'] == $data['user_id']) || empty($letterOfComplaintInfo['admin_id'])) {
  365. return Result::success();
  366. } else {
  367. return Result::error("您不能处理其他人已经接过的案件", 0);
  368. }
  369. }
  370. /**
  371. * 后台获取职能部门
  372. * @param array $data
  373. * @return array
  374. */
  375. public function getZhinengbumenList(array $data): array
  376. {
  377. // 获取分页参数,默认每页 10 条记录
  378. $page = isset($data['page']) ? (int) $data['page'] : 1;
  379. $perPage = isset($data['pagesize']) ? (int) $data['pagesize'] : 10;
  380. // 查询数据并分页
  381. $query = Department::query();
  382. // 可以在这里添加更多的查询条件
  383. if (isset($data['search'])) {
  384. $query->where('name', 'like', '%' . $data['search'] . '%');
  385. }
  386. // 执行分页查询
  387. $result = $query->paginate($perPage, ['*'], 'page', $page);
  388. // 返回分页结果
  389. return Result::success([
  390. 'count' => $result->total(),
  391. 'current_page' => $result->currentPage(),
  392. 'last_page' => $result->lastPage(),
  393. 'pagesize' => $result->perPage(),
  394. 'rows' => $result->items(),
  395. ]);
  396. }
  397. /**
  398. * 添加获取职能部门
  399. * @param array $data
  400. * @return array
  401. */
  402. public function addZhinengbumen(array $data): array
  403. {
  404. $result = Department::insertGetId($data);
  405. if (empty($result)) {
  406. return Result::error("创建失败", 0);
  407. } else {
  408. return Result::success(["id" => $result]);
  409. }
  410. }
  411. public function delZhinengbumen(array $data): array
  412. {
  413. $result = Department::where('id', $data['id'])->delete();
  414. if (empty($result)) {
  415. return Result::error("删除失败", 0);
  416. } else {
  417. return Result::success();
  418. }
  419. }
  420. public function getZhinengbumen(array $data): array
  421. {
  422. $result = Department::where('id', $data['id'])->first();
  423. return Result::success($result);
  424. }
  425. public function getPidZhinengbumen(array $data): array
  426. {
  427. if (empty($data['pid'])) {
  428. $data['pid'] = 0;
  429. }
  430. $result = Department::where('pid', $data['pid'])->get();
  431. return Result::success($result);
  432. }
  433. public function modZhinengbumen(array $data): array
  434. {
  435. $result = Department::where('id', $data['id'])->update($data);
  436. if (empty($result)) {
  437. return Result::error("修改失败", 0);
  438. } else {
  439. return Result::success();
  440. }
  441. }
  442. /**
  443. * 查询职能列表
  444. * @param array $data
  445. * @return array
  446. */
  447. public function getDepartment(array $data) :array
  448. {
  449. $where = [];
  450. if(isset($data['pid'])){
  451. $where = [
  452. 'pid'=>$data['pid']??0
  453. ];
  454. }
  455. $result = Department::when(!empty($where),function ($query) use ($where){
  456. $query->where($where);
  457. })->orderBy("sort","desc")->get();
  458. if (empty($result)) {
  459. return Result::error("查询失败", 0);
  460. }else{
  461. return Result::success($result);
  462. }
  463. }
  464. /**
  465. * 获取所有的buckets
  466. * @param array $data
  467. * @return array
  468. */
  469. public function getBuckets(array $data) :array
  470. {
  471. $result = new MinioService();
  472. // 调用服务层的方法获取存储桶列表
  473. $bucketsResponse =$result->listBuckets();
  474. // 直接返回服务层生成的响应
  475. return Result::success($bucketsResponse['data']);
  476. }
  477. /**
  478. * 上传文件
  479. * @param array $data
  480. * @return array
  481. */
  482. public function uploadFile(array $data) :array
  483. {
  484. $result = new MinioService();
  485. $rep = $result->uploadFile($data);
  486. if($rep['code']==200){
  487. return Result::success($rep['data']);
  488. }else{
  489. return Result::error("上传失败!");
  490. }
  491. }
  492. /**
  493. * 黑名单管理
  494. * @param array $data
  495. * @return array
  496. */
  497. public function getBlackWordList(array $data) :array
  498. {
  499. $result = BlackWord::when($data, function ($query) use ($data) {
  500. if (isset($data['name']) && $data['name']){
  501. $query->where('black_word.name', 'like', '%'.$data['name'].'%');
  502. }
  503. })->orderBy('black_word.id','desc')
  504. ->paginate(intval($data['pageSize']),
  505. [
  506. 'black_word.*',
  507. ],
  508. 'page', intval($data['page']));
  509. $count = $result->total();
  510. $returnData = [
  511. 'rows'=>$result->items(),
  512. 'count'=>$count
  513. ];
  514. return Result::success($returnData);
  515. }
  516. /**
  517. * 添加黑名单
  518. * @param array $data
  519. * @return array
  520. */
  521. public function addBlackWord(array $data) :array
  522. {
  523. Db::beginTransaction();
  524. try {
  525. $info = BlackWord::where(['name'=>$data['name']])->first();
  526. if($info){
  527. Db::rollBack();
  528. return Result::error("该黑名单已存在", 0);
  529. }
  530. $data['type'] = 10;
  531. $result = BlackWord::insertGetId($data);
  532. $redisKey = 'black_word';
  533. $this->redis->sAdd($redisKey, $data['name']);
  534. Db::commit();
  535. return Result::success(["id" => $result]);
  536. }catch (\Exception $e){
  537. Db::rollBack();
  538. return Result::error("创建失败".$e->getMessage(), 0);
  539. }
  540. }
  541. /**
  542. * 删除黑名单
  543. * @param array $data
  544. * @return array
  545. */
  546. public function delBlackWord(array $data) :array
  547. {
  548. Db::beginTransaction();
  549. try {
  550. BlackWord::where(['name'=>$data['name']])->delete();
  551. $redisKey = 'black_word';
  552. $this->redis->sRem($redisKey, $data['name']);
  553. Db::commit();
  554. return Result::success([]);
  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 upBlackWord(array $data) :array
  566. {
  567. Db::beginTransaction();
  568. try {
  569. $checkInfo = BlackWord::where(['name'=>$data['name']])->first();
  570. if($checkInfo){
  571. Db::rollBack();
  572. return Result::error("该违禁词已经存在", 0);
  573. }
  574. $blackWordInfo = BlackWord::where(['id'=>$data['id']])->first();
  575. if($blackWordInfo){
  576. //先删除redis
  577. $blackWordInfo = $blackWordInfo->toArray();
  578. $redisKey = 'black_word';
  579. $this->redis->sRem($redisKey, $blackWordInfo['name']);
  580. $this->redis->sAdd($redisKey, $data['name']);
  581. BlackWord::where(['id'=>$data['id']])->update(['name'=>$data['name']]);
  582. Db::commit();
  583. return Result::success([]);
  584. }else{
  585. Db::rollBack();
  586. return Result::error("系统错误", 0);
  587. }
  588. }catch (\Exception $e){
  589. Db::rollBack();
  590. return Result::error("修改失败".$e->getMessage(), 0);
  591. }
  592. }
  593. }