From 9df7c0be82847911a44839b4c0c4d9ff1a29e290 Mon Sep 17 00:00:00 2001 From: "DESKTOP-GG6FIN9\\Administrator" <15040771@qq.com> Date: Fri, 24 Jul 2020 18:31:18 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AF=84=E8=AE=BA=E5=88=97=E8=A1=A8=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Service/ServiceEvaluateService.php | 28 ++++++++++++++----- .../ServiceEvaluateServiceInterface.php | 4 +-- composer.json | 3 +- 3 files changed, 25 insertions(+), 10 deletions(-) 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",