diff --git a/app/Service/ServiceEvaluateService.php b/app/Service/ServiceEvaluateService.php index a6e1dc8..fee79bd 100644 --- a/app/Service/ServiceEvaluateService.php +++ b/app/Service/ServiceEvaluateService.php @@ -6,6 +6,7 @@ use App\Model\ServiceEvaluate; use Hyperf\DbConnection\Db; use Hyperf\HttpServer\Contract\RequestInterface; use Hyperf\Di\Annotation\Inject; +use Hyperf\Paginator\Paginator; class ServiceEvaluateService implements ServiceEvaluateServiceInterface { @@ -26,22 +27,35 @@ class ServiceEvaluateService implements ServiceEvaluateServiceInterface return ServiceEvaluate::create($data); } - public function getPersonnelInfo() + public function getPersonnelInfo($user_id) { - $data = $this->request->all(); $res = Db::table('lanzu_service_personnel') - ->where(['user_id' => $data['user_id']]) + ->where(['user_id' => $user_id]) ->first(); return $res; } - public function getEvaluateList() + public function getEvaluateList($service_personnel_id) { - $data = $this->request->all(); $res = Db::table('lanzu_service_evaluate') - ->where(['service_personnel_id' => $data['service_personnel_id']]) + ->where(['service_personnel_id' => $service_personnel_id]) + ->limit(4) ->get(); - return $res; +// return $res; + $currentPage = 1; + $perPage = 2; + + // 这里根据 $currentPage 和 $perPage 进行数据查询,以下使用 Collection 代替 +// $collection = new Collection([ +// ['id' => 1, 'name' => 'Tom'], +// ['id' => 2, 'name' => 'Sam'], +// ['id' => 3, 'name' => 'Tim'], +// ['id' => 4, 'name' => 'Joe'], +// ]); +// +// $users = array_values($collection->forPage($currentPage, $perPage)->toArray()); + + return new Paginator($res, $perPage, $currentPage); } } \ No newline at end of file diff --git a/app/Service/ServiceEvaluateServiceInterface.php b/app/Service/ServiceEvaluateServiceInterface.php index ee2418d..22c6aa1 100644 --- a/app/Service/ServiceEvaluateServiceInterface.php +++ b/app/Service/ServiceEvaluateServiceInterface.php @@ -9,8 +9,8 @@ interface ServiceEvaluateServiceInterface public function evaluate(); - public function getPersonnelInfo(); + public function getPersonnelInfo($user_id); - public function getEvaluateList(); + public function getEvaluateList($service_personnel_id); } \ No newline at end of file diff --git a/composer.json b/composer.json index 6dddec9..1ac7889 100644 --- a/composer.json +++ b/composer.json @@ -27,7 +27,8 @@ "hyperf/redis": "~2.0.0", "hyperf/constants": "~2.0.0", "hyperf/model-cache": "~2.0.0", - "hyperf/validation": "^2.0" + "hyperf/validation": "^2.0", + "hyperf/paginator": "^2.0" }, "require-dev": { "swoole/ide-helper": "^4.5",