DistrictService.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. namespace App\JsonRpc;
  3. use App\Model\District;
  4. use Hyperf\RpcServer\Annotation\RpcService;
  5. use App\Tools\Result;
  6. #[RpcService(name: "DistrictService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
  7. class DistrictService implements DistrictServiceInterface
  8. {
  9. /**
  10. * @param int $id
  11. * @return array
  12. */
  13. public function getDistrictInfo(int $id): array
  14. {
  15. $adInfo = District::query()->find($id);
  16. if (empty($adInfo)) {
  17. return Result::error("没有数据",0);
  18. }
  19. return Result::success($adInfo->toArray());
  20. }
  21. /**
  22. * @param string $keyword
  23. * @param int $page
  24. * @param int $pageSize
  25. * @return array
  26. */
  27. public function getDistrictList(string $keyword, int $pid=0): array
  28. {
  29. $where = [
  30. ['name','like','%'.$keyword.'%'],
  31. ['pid','=',$pid],
  32. ];
  33. $districtList = District::where($where)->get();
  34. if (empty($districtList)) {
  35. return Result::error("没有数据",0);
  36. }
  37. return Result::success($districtList->toArray());
  38. }
  39. }