From c67d511ee7b31a0f3666bbdbcb33b0e27b7aca63 Mon Sep 17 00:00:00 2001 From: gcd Date: Wed, 23 Apr 2025 00:04:20 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=AE=9A=E6=9C=9F=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E4=BD=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/services/WorkerService.php | 36 ++++++++++++++++++++++++ application/worker/controller/Worker.php | 17 +++++++++++ application/worker/validate/Worker.php | 3 ++ 3 files changed, 56 insertions(+) diff --git a/application/services/WorkerService.php b/application/services/WorkerService.php index 80587f6..b053f81 100644 --- a/application/services/WorkerService.php +++ b/application/services/WorkerService.php @@ -149,4 +149,40 @@ class WorkerService extends BaseService return true; } + + /** + * 更新师傅位置 + * @param int $workerId + * @param float $latitude + * @param float $longitude + * @return true + */ + public function updateWorkerLocation(int $workerId, float $latitude, float $longitude) + { + $worker = $this->getWorkerModel()->find($workerId); + if (empty($worker)) { + $this->apiError('更新位置失败,用户不存在'); + } + + $worker->lat = $latitude; + $worker->lng = $longitude; + $worker->location_update_time = datetime(time()); + $worker->update_time = datetime(time()); + $worker->save(); + + return true; + } } + + + + + + + + + + + + + diff --git a/application/worker/controller/Worker.php b/application/worker/controller/Worker.php index 38eecc0..5b42d65 100644 --- a/application/worker/controller/Worker.php +++ b/application/worker/controller/Worker.php @@ -77,4 +77,21 @@ class Worker extends WorkerApi { $this->success('操作成功', $this->user); } + + /** + * 更新师傅位置 + * @return void + */ + public function updateWorkerLocation() + { + $params = $this->request->request(); + $validate = $this->validate($params, \app\worker\validate\Worker::class . '.updateWorkerLocation'); + if ($validate !== true) { + $this->error($validate); + } + + $this->getWorkerService()->updateWorkerLocation($this->user['id'], $params['latitude'], $params['longitude']); + + $this->success('操作成功'); + } } diff --git a/application/worker/validate/Worker.php b/application/worker/validate/Worker.php index 43c1b06..db2a52b 100644 --- a/application/worker/validate/Worker.php +++ b/application/worker/validate/Worker.php @@ -9,6 +9,8 @@ class Worker extends Validate protected $rule = [ 'code' => 'require|max:128', 'vendor_token' => 'require|max:128', + 'latitude' => 'require|number', + 'longitude' => 'require|number', ]; protected $message = [ @@ -18,5 +20,6 @@ class Worker extends Validate protected $scene = [ 'login' => ['code'], 'bindPhoneNumber' => ['code', 'vendor_token'], + 'updateWorkerLocation' => ['latitude', 'longitude'], ]; }