97 lines
2.4 KiB
PHP
97 lines
2.4 KiB
PHP
<?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(319);
|
||
$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('操作成功');
|
||
}
|
||
}
|