PublicRpcService.php 16 KB

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