PublicRpcService.php 16 KB

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