allocatr/application/worker/controller/Worker.php
2025-07-03 11:37:18 +08:00

97 lines
2.4 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace app\worker\controller;
use app\common\controller\WorkerApi;
class Worker extends WorkerApi
{
protected $noNeedLogin = ['login', 'bindPhoneNumber', 'guestLogin'];
/**
* 微信登录
*/
public function login()
{
$params = $this->request->request();
$validate = $this->validate($params, \app\worker\validate\Worker::class . '.login');
if ($validate !== true) {
$this->error($validate);
}
$workerVendor = $this->getWorkerService()->login($params['code']);
//存在师傅id直接登录
if ($workerVendor['worker_id']) {
$this->workerLogin($workerVendor['worker_id']);
$this->success('登录成功', $this->user);
}
$this->error('请绑定手机号', ['vendor_token' => $this->getTokenByUserId($workerVendor['id'])]);
}
/**
* 绑定手机号
* @return void
*/
public function bindPhoneNumber()
{
$params = $this->request->request();
$validate = $this->validate($params, \app\worker\validate\Worker::class . '.bindPhoneNumber');
if ($validate !== true) {
$this->error($validate);
}
$workerId = $this->getWorkerService()->bindPhoneNumber($params['code'], $params['vendor_token']);
$this->workerLogin($workerId);
$this->success('绑定成功', $this->user);
}
/**
* 游客登录
* @return void
*/
public function guestLogin()
{
$this->workerLogin(1059);
$this->success('登录成功', $this->user);
}
/**
* 退出登录
* @return void
*/
public function logout()
{
$this->workerLogout();
$this->success('操作成功');
}
/**
* 获取当前登录师傅信息
* @return void
*/
public function show()
{
$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('操作成功');
}
}