PublicRpcService.php 17 KB

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