PublicRpcService.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. namespace App\JsonRpc;
  3. use App\Model\District;
  4. use App\Model\LevelUser;
  5. use Hyperf\RpcServer\Annotation\RpcService;
  6. use App\Tools\Result;
  7. #[RpcService(name: "PublicRpcService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
  8. class PublicRpcService implements PublicRpcServiceInterface
  9. {
  10. /**
  11. * @param array $data
  12. * @return array
  13. */
  14. public function getDistrictList(array $data): array
  15. {
  16. $where = [
  17. ['name','like','%'.$data['keyWord'].'%']
  18. ];
  19. $result = [];
  20. if(isset($data['pageSize'])){
  21. $rep = District::where($where)->limit($data['pageSize'])->offset(($data['page']-1)*$data['pageSize'])->orderBy("code","asc")->get();
  22. $count = District::where($where)->count();
  23. $result = [
  24. 'rows'=>$rep,
  25. 'count'=>$count
  26. ];
  27. }else{
  28. $result = District::where($data)->orderBy("code","asc")->get();
  29. }
  30. return $result?Result::success($result):Result::error("没有查到数据");
  31. }
  32. /**
  33. * @param array $data
  34. * @return array
  35. */
  36. public function getUserLevelList(array $data): array
  37. {
  38. var_dump("关键词:",$data['keyWord']);
  39. $where = [
  40. ['name','like','%'.$data['keyWord'].'%']
  41. ];
  42. $result = [];
  43. if(isset($data['pageSize'])){
  44. $rep = LevelUser::where($where)->limit($data['pageSize'])->offset(($data['page']-1)*$data['pageSize'])->orderBy("id","asc")->get();
  45. $count = LevelUser::where($where)->count();
  46. $result = [
  47. 'rows'=>$rep,
  48. 'count'=>$count
  49. ];
  50. }else{
  51. $result = LevelUser::orderBy("id","asc")->get();
  52. }
  53. return $result?Result::success($result):Result::error("没有查到数据");
  54. }
  55. /**
  56. * 添加用户等级
  57. * @param array $data
  58. * @return array
  59. */
  60. public function addUserLevel(array $data) :array
  61. {
  62. LevelUser::insertGetId($data);
  63. return Result::success([]);
  64. }
  65. /**
  66. * 更新等级
  67. * @param array $data
  68. * @return array
  69. */
  70. public function updateUserLevel(array $data) :array
  71. {
  72. $result = LevelUser::where(['id'=>$data['id']])->update($data);
  73. if ($result) {
  74. return Result::success($result);
  75. }
  76. return Result::error("更新失败");
  77. }
  78. /**
  79. * 删除等级
  80. * @param array $data
  81. * @return array
  82. */
  83. public function delUserLevel(array $data) :array
  84. {
  85. $result = LevelUser::where(['id'=>$data['id']])->delete();
  86. if ($result) {
  87. return Result::success($result);
  88. }
  89. return Result::error("删除失败");
  90. }
  91. }