PublicRpcService.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485
  1. <?php
  2. namespace App\JsonRpc;
  3. use App\Model\Department;
  4. use App\Model\LetterOfComplaint;
  5. use App\Model\District;
  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. var_dump("====");
  108. $where = [];
  109. if (isset($data['user_id']) && !empty($data['user_id'])) {
  110. array_push($where, ['letter_of_complaint.user_id', '=', $data['user_id']]);
  111. }
  112. if (isset($data['nature']) && !empty($data['nature'])) {
  113. array_push($where, ['letter_of_complaint.nature', '=', $data['nature']]);
  114. }
  115. if (isset($data['nature_level0']) && !empty($data['nature_level0'])) {
  116. array_push($where, ['letter_of_complaint.nature_level0', '=', $data['nature_level0']]);
  117. }
  118. if (isset($data['status']) && !empty($data['status'])) {
  119. array_push($where, ['letter_of_complaint.status', '=', $data['status']]);
  120. }
  121. $result = [];
  122. if (isset($data['pageSize'])) {
  123. $rep = LetterOfComplaint::where($where)
  124. ->leftJoin("letter_type as type_a", "letter_of_complaint.nature", "type_a.id")
  125. ->leftJoin("letter_type as type_c", "letter_of_complaint.nature_level0", "type_c.id")
  126. ->leftJoin("letter_type as type_b", "letter_of_complaint.nature_level1", "type_b.id")
  127. ->leftJoin("letter_type as type_e", "letter_of_complaint.nature_level3", "type_e.id")
  128. ->leftJoin("letter_type as type_d", "letter_of_complaint.status", "type_d.id")
  129. ->select("letter_of_complaint.*",
  130. "type_a.type_name as nature_name",
  131. "type_b.type_name as nature_name1",
  132. "type_c.type_name as nature_name0",
  133. "type_d.type_name as status_name",
  134. "type_e.type_name as nature_name3")
  135. ->limit($data['pageSize'])->offset(($data['page'] - 1) * $data['pageSize'])->orderBy("letter_of_complaint.id", "desc")->get();
  136. $count = LetterOfComplaint::where($where)->count();
  137. if ($rep) {
  138. foreach ($rep as $val) {
  139. if ($val['judgment']) {
  140. $val['judgment'] = json_decode($val['judgment']);
  141. }
  142. if ($val['audio_and_video']) {
  143. $val['audio_and_video'] = json_decode($val['audio_and_video']);
  144. }
  145. if ($val['contract']) {
  146. $val['contract'] = json_decode($val['contract']);
  147. }
  148. if ($val['qualifications']) {
  149. $val['qualifications'] = json_decode($val['qualifications']);
  150. }
  151. }
  152. }
  153. $result = [
  154. 'rows' => $rep,
  155. 'count' => $count,
  156. ];
  157. } else {
  158. $result = LetterOfComplaint::where($where)
  159. ->leftJoin("letter_type as type_a", "letter_of_complaint.nature", "type_a.id")
  160. ->leftJoin("letter_type as type_c", "letter_of_complaint.nature_level0", "type_c.id")
  161. ->leftJoin("letter_type as type_b", "letter_of_complaint.nature_level1", "type_b.id")
  162. ->leftJoin("letter_type as type_e", "letter_of_complaint.nature_level3", "type_e.id")
  163. ->leftJoin("letter_type as type_d", "letter_of_complaint.status", "type_d.id")
  164. ->select("letter_of_complaint.*",
  165. "type_a.type_name as nature_name",
  166. "type_b.type_name as nature_name1",
  167. "type_c.type_name as nature_name0",
  168. "type_d.type_name as status_name",
  169. "type_e.type_name as nature_name3")
  170. ->orderBy("letter_of_complaint.id", "desc")->get();
  171. }
  172. return $result ? Result::success($result) : Result::error("没有查到数据");
  173. }
  174. /**
  175. * 添加投诉举报信息
  176. * @param array $data
  177. * @return array
  178. */
  179. public function addLetterOfComplaint(array $data): array
  180. {
  181. $data['judgment'] = $data['judgment'] ? json_encode($data['judgment']) : '';
  182. $data['audio_and_video'] = $data['audio_and_video'] ? json_encode($data['audio_and_video']) : '';
  183. $data['contract'] = $data['contract'] ? json_encode($data['contract']) : '';
  184. $data['qualifications'] = $data['qualifications'] ? json_encode($data['qualifications']) : '';
  185. unset($data['id']);
  186. $result = LetterOfComplaint::insertGetId($data);
  187. if (empty($result)) {
  188. return Result::error("创建失败", 0);
  189. } else {
  190. return Result::success(["id" => $result]);
  191. }
  192. }
  193. /**
  194. * 用户端更新投诉举报
  195. * @param array $data
  196. * @return array
  197. */
  198. public function userUpLetterOfComplaint(array $data): array
  199. {
  200. $data['judgment'] = $data['judgment'] ? json_encode($data['judgment']) : '';
  201. $data['audio_and_video'] = $data['audio_and_video'] ? json_encode($data['audio_and_video']) : '';
  202. $data['contract'] = $data['contract'] ? json_encode($data['contract']) : '';
  203. $data['qualifications'] = $data['qualifications'] ? json_encode($data['qualifications']) : '';
  204. $result = LetterOfComplaint::where(['id' => $data['id']])->update($data);
  205. if (empty($result)) {
  206. return Result::error("创建失败", 0);
  207. } else {
  208. return Result::success(["id" => $result]);
  209. }
  210. }
  211. /**
  212. * 管理后台更新投诉举报信息
  213. * @param array $data
  214. * @return array
  215. */
  216. public function upLetterOfComplaint(array $data): array
  217. {
  218. var_dump("admin:", $data);
  219. $where = [
  220. 'id' => $data['id'],
  221. ];
  222. $filtered_array = array_filter($data, function ($value) {
  223. return $value !== "" && $value !== null && $value !== false && !is_array($value) || !empty($value);
  224. });
  225. $filtered_array['judgment'] = isset($filtered_array['judgment']) ? json_encode($filtered_array['judgment']) : '';
  226. $filtered_array['audio_and_video'] = isset($filtered_array['audio_and_video']) ? json_encode($filtered_array['audio_and_video']) : '';
  227. $filtered_array['contract'] = isset($filtered_array['contract']) ? json_encode($filtered_array['contract']) : '';
  228. $filtered_array['qualifications'] = isset($filtered_array['qualifications']) ? json_encode($filtered_array['qualifications']) : '';
  229. unset($filtered_array['nature_name']);
  230. unset($filtered_array['type_name']);
  231. unset($filtered_array['nature_level_name']);
  232. unset($filtered_array['status_name']);
  233. unset($filtered_array['is_admin']);
  234. unset($filtered_array['type_level_name']);
  235. $result = LetterOfComplaint::where($where)->update($filtered_array);
  236. if ($result) {
  237. return Result::success($result);
  238. }
  239. return Result::error("更新失败", 0);
  240. }
  241. /**
  242. * 查询投诉举报记录
  243. * @param array $data
  244. * @return array
  245. */
  246. public function getLetterOfComplaintInfo(array $data): array
  247. {
  248. $where = [
  249. 'letter_of_complaint.id' => $data['id'],
  250. ];
  251. if (isset($data['user_id']) && !empty($data['user_id'])) {
  252. array_push($where, ['letter_of_complaint.user_id', '=', $data['user_id']]);
  253. }
  254. $result = LetterOfComplaint::where($where)
  255. ->leftJoin("letter_type as type_a", "letter_of_complaint.nature", "type_a.id")
  256. ->leftJoin("letter_type as type_c", "letter_of_complaint.nature_level0", "type_c.id")
  257. ->leftJoin("letter_type as type_b", "letter_of_complaint.nature_level1", "type_b.id")
  258. ->leftJoin("letter_type as type_e", "letter_of_complaint.nature_level3", "type_e.id")
  259. ->leftJoin("letter_type as type_d", "letter_of_complaint.status", "type_d.id")
  260. ->select("letter_of_complaint.*",
  261. "type_a.type_name as nature_name",
  262. "type_b.type_name as nature_name1",
  263. "type_c.type_name as nature_name0",
  264. "type_d.type_name as status_name",
  265. "type_e.type_name as nature_name3")
  266. ->first();
  267. return Result::success($result);
  268. }
  269. /**
  270. * 删除投诉举报信息
  271. * @param array $data
  272. * @return array
  273. */
  274. public function delLetterOfComplaint(array $data): array
  275. {
  276. $where = [
  277. 'id' => $data['id'],
  278. 'user_id' => $data['user_id'],
  279. ];
  280. $result = LetterOfComplaint::where($where)->delete();
  281. if (empty($result)) {
  282. return Result::error("删除失败", 0);
  283. } else {
  284. return Result::success();
  285. }
  286. }
  287. /**
  288. * 获取举报信息类型
  289. * @param array $data
  290. * @return array
  291. */
  292. public function getLetterType(array $data): array
  293. {
  294. $where = [];
  295. if (isset($data['type'])) {
  296. array_push($where, ['type', '=', $data['type']]);
  297. }
  298. if (isset($data['pid']) && $data['pid']>0) {
  299. array_push($where, ['pid', '=', $data['pid']]);
  300. }
  301. $result = LetterType::where($where)->orderBy('sort','asc')->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. }