PublicRpcService.php 18 KB

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