123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- <?php
- namespace App\JsonRpc;
- use App\Model\District;
- use App\Model\LevelUser;
- use Hyperf\RpcServer\Annotation\RpcService;
- use App\Tools\Result;
- #[RpcService(name: "PublicRpcService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
- class PublicRpcService implements PublicRpcServiceInterface
- {
- /**
- * @param array $data
- * @return array
- */
- public function getDistrictList(array $data): array
- {
- $where = [];
- if(isset($data['keyWord'])){
- $where = [
- ['name','like','%'.$data['keyWord'].'%']
- ];
- }
- $result = [];
- if(isset($data['pageSize'])){
- $rep = District::where($where)->limit($data['pageSize'])->offset(($data['page']-1)*$data['pageSize'])->orderBy("code","asc")->get();
- $count = District::where($where)->count();
- $result = [
- 'rows'=>$rep,
- 'count'=>$count
- ];
- }else{
- $result = District::where($data)->orderBy("code","asc")->get();
- }
- return $result?Result::success($result):Result::error("没有查到数据");
- }
- /**
- * @param array $data
- * @return array
- */
- public function getUserLevelList(array $data): array
- {
- $where = [];
- if(isset($data['keyWord'])){
- $where = [
- ['name','like','%'.$data['keyWord'].'%']
- ];
- }
- $result = [];
- if(isset($data['pageSize'])){
- $rep = LevelUser::where($where)->limit($data['pageSize'])->offset(($data['page']-1)*$data['pageSize'])->orderBy("id","asc")->get();
- $count = LevelUser::where($where)->count();
- $result = [
- 'rows'=>$rep,
- 'count'=>$count
- ];
- }else{
- $result = LevelUser::orderBy("id","asc")->get();
- }
- return $result?Result::success($result):Result::error("没有查到数据");
- }
- /**
- * 添加用户等级
- * @param array $data
- * @return array
- */
- public function addUserLevel(array $data) :array
- {
- LevelUser::insertGetId($data);
- return Result::success([]);
- }
- /**
- * 更新等级
- * @param array $data
- * @return array
- */
- public function updateUserLevel(array $data) :array
- {
- $result = LevelUser::where(['id'=>$data['id']])->update($data);
- if ($result) {
- return Result::success($result);
- }
- return Result::error("更新失败");
- }
- /**
- * 删除等级
- * @param array $data
- * @return array
- */
- public function delUserLevel(array $data) :array
- {
- $result = LevelUser::where(['id'=>$data['id']])->delete();
- if ($result) {
- return Result::success($result);
- }
- return Result::error("删除失败");
- }
- }
|