PublicRpcService.php 17 KB

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