PublicRpcService.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. if(isset($data['keyWord'])){
  18. $where = [
  19. ['name','like','%'.$data['keyWord'].'%']
  20. ];
  21. }
  22. $result = [];
  23. if(isset($data['pageSize'])){
  24. $rep = District::where($where)->limit($data['pageSize'])->offset(($data['page']-1)*$data['pageSize'])->orderBy("code","asc")->get();
  25. $count = District::where($where)->count();
  26. $result = [
  27. 'rows'=>$rep,
  28. 'count'=>$count
  29. ];
  30. }else{
  31. $result = District::where($data)->orderBy("code","asc")->get();
  32. }
  33. return $result?Result::success($result):Result::error("没有查到数据");
  34. }
  35. /**
  36. * @param array $data
  37. * @return array
  38. */
  39. public function getUserLevelList(array $data): array
  40. {
  41. $where = [];
  42. if(isset($data['keyWord'])){
  43. $where = [
  44. ['name','like','%'.$data['keyWord'].'%']
  45. ];
  46. }
  47. $result = [];
  48. if(isset($data['pageSize'])){
  49. $rep = LevelUser::where($where)->limit($data['pageSize'])->offset(($data['page']-1)*$data['pageSize'])->orderBy("id","asc")->get();
  50. $count = LevelUser::where($where)->count();
  51. $result = [
  52. 'rows'=>$rep,
  53. 'count'=>$count
  54. ];
  55. }else{
  56. $result = LevelUser::orderBy("id","asc")->get();
  57. }
  58. return $result?Result::success($result):Result::error("没有查到数据");
  59. }
  60. /**
  61. * 添加用户等级
  62. * @param array $data
  63. * @return array
  64. */
  65. public function addUserLevel(array $data) :array
  66. {
  67. LevelUser::insertGetId($data);
  68. return Result::success([]);
  69. }
  70. /**
  71. * 更新等级
  72. * @param array $data
  73. * @return array
  74. */
  75. public function updateUserLevel(array $data) :array
  76. {
  77. $result = LevelUser::where(['id'=>$data['id']])->update($data);
  78. if ($result) {
  79. return Result::success($result);
  80. }
  81. return Result::error("更新失败");
  82. }
  83. /**
  84. * 删除等级
  85. * @param array $data
  86. * @return array
  87. */
  88. public function delUserLevel(array $data) :array
  89. {
  90. $result = LevelUser::where(['id'=>$data['id']])->delete();
  91. if ($result) {
  92. return Result::success($result);
  93. }
  94. return Result::error("删除失败");
  95. }
  96. }