PublicRpcService.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523
  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. $where = [
  278. 'id' => $data['id'],
  279. 'user_id' => $data['user_id'],
  280. ];
  281. $result = LetterOfComplaint::where($where)->delete();
  282. if (empty($result)) {
  283. return Result::error("删除失败", 0);
  284. } else {
  285. return Result::success();
  286. }
  287. }
  288. /**
  289. * 获取举报信息类型
  290. * @param array $data
  291. * @return array
  292. */
  293. public function getLetterType(array $data): array
  294. {
  295. $where = [];
  296. if (isset($data['type'])) {
  297. array_push($where, ['type', '=', $data['type']]);
  298. }
  299. if (isset($data['pid']) && $data['pid']>0) {
  300. array_push($where, ['pid', '=', $data['pid']]);
  301. }
  302. $result = LetterType::where($where)->orderBy('sort','asc')->get();
  303. return $result ? Result::success($result) : Result::error("没有查到数据");
  304. }
  305. /**
  306. * 更新举报类型
  307. * @param array $data
  308. * @return array
  309. */
  310. public function upLetterType(array $data): array
  311. {
  312. return [];
  313. }
  314. /**
  315. * 添加举报类型
  316. * @param array $data
  317. * @return array
  318. */
  319. public function addLetterType(array $data): array
  320. {
  321. $result = LetterType::insertGetId($data);
  322. if (empty($result)) {
  323. return Result::error("创建失败", 0);
  324. } else {
  325. return Result::success(["id" => $result]);
  326. }
  327. }
  328. /**
  329. * 删除举报类型
  330. * @param array $data
  331. * @return array
  332. */
  333. public function delLetterType(array $data): array
  334. {
  335. $result = LetterType::where('id', $data['id'])->delete();
  336. if (empty($result)) {
  337. return Result::error("删除失败", 0);
  338. } else {
  339. return Result::success();
  340. }
  341. }
  342. /**
  343. * 检测是否已经被接案
  344. * @param array $data
  345. * @return array
  346. */
  347. public function checkMeasure(array $data): array
  348. {
  349. $where = [
  350. 'id' => $data['id'],
  351. ];
  352. $letterOfComplaintInfo = LetterOfComplaint::where($where)->first();
  353. var_dump("查询数据:", $letterOfComplaintInfo['admin_id'], $data['user_id']);
  354. //操作人和当前登陆用户id 相等说明是当前人接收的案件
  355. if (($letterOfComplaintInfo['admin_id'] == $data['user_id']) || empty($letterOfComplaintInfo['admin_id'])) {
  356. return Result::success();
  357. } else {
  358. return Result::error("您不能处理其他人已经接过的案件", 0);
  359. }
  360. }
  361. /**
  362. * 后台获取职能部门
  363. * @param array $data
  364. * @return array
  365. */
  366. public function getZhinengbumenList(array $data): array
  367. {
  368. // 获取分页参数,默认每页 10 条记录
  369. $page = isset($data['page']) ? (int) $data['page'] : 1;
  370. $perPage = isset($data['pagesize']) ? (int) $data['pagesize'] : 10;
  371. // 查询数据并分页
  372. $query = Department::query();
  373. // 可以在这里添加更多的查询条件
  374. if (isset($data['search'])) {
  375. $query->where('name', 'like', '%' . $data['search'] . '%');
  376. }
  377. // 执行分页查询
  378. $result = $query->paginate($perPage, ['*'], 'page', $page);
  379. // 返回分页结果
  380. return Result::success([
  381. 'count' => $result->total(),
  382. 'current_page' => $result->currentPage(),
  383. 'last_page' => $result->lastPage(),
  384. 'pagesize' => $result->perPage(),
  385. 'rows' => $result->items(),
  386. ]);
  387. }
  388. /**
  389. * 添加获取职能部门
  390. * @param array $data
  391. * @return array
  392. */
  393. public function addZhinengbumen(array $data): array
  394. {
  395. $result = Department::insertGetId($data);
  396. if (empty($result)) {
  397. return Result::error("创建失败", 0);
  398. } else {
  399. return Result::success(["id" => $result]);
  400. }
  401. }
  402. public function delZhinengbumen(array $data): array
  403. {
  404. $result = Department::where('id', $data['id'])->delete();
  405. if (empty($result)) {
  406. return Result::error("删除失败", 0);
  407. } else {
  408. return Result::success();
  409. }
  410. }
  411. public function getZhinengbumen(array $data): array
  412. {
  413. $result = Department::where('id', $data['id'])->first();
  414. return Result::success($result);
  415. }
  416. public function getPidZhinengbumen(array $data): array
  417. {
  418. if (empty($data['pid'])) {
  419. $data['pid'] = 0;
  420. }
  421. $result = Department::where('pid', $data['pid'])->get();
  422. return Result::success($result);
  423. }
  424. public function modZhinengbumen(array $data): array
  425. {
  426. $result = Department::where('id', $data['id'])->update($data);
  427. if (empty($result)) {
  428. return Result::error("修改失败", 0);
  429. } else {
  430. return Result::success();
  431. }
  432. }
  433. /**
  434. * 查询职能列表
  435. * @param array $data
  436. * @return array
  437. */
  438. public function getDepartment(array $data) :array
  439. {
  440. $where = [];
  441. if(isset($data['pid'])){
  442. $where = [
  443. 'pid'=>$data['pid']??0
  444. ];
  445. }
  446. $result = Department::when(!empty($where),function ($query) use ($where){
  447. $query->where($where);
  448. })->orderBy("sort","desc")->get();
  449. if (empty($result)) {
  450. return Result::error("查询失败", 0);
  451. }else{
  452. return Result::success($result);
  453. }
  454. }
  455. /**
  456. * 获取所有的buckets
  457. * @param array $data
  458. * @return array
  459. */
  460. public function getBuckets(array $data) :array
  461. {
  462. $result = new MinioService();
  463. // 调用服务层的方法获取存储桶列表
  464. $bucketsResponse =$result->listBuckets();
  465. // 直接返回服务层生成的响应
  466. return Result::success($bucketsResponse['data']);
  467. }
  468. /**
  469. * 上传文件
  470. * @param array $data
  471. * @return array
  472. */
  473. public function uploadFile(array $data) :array
  474. {
  475. $result = new MinioService();
  476. $rep = $result->uploadFile($data);
  477. if($rep['code']==200){
  478. return Result::success($rep['data']);
  479. }else{
  480. return Result::error("上传失败!");
  481. }
  482. }
  483. }