allocatr/application/worker/controller/Worker.php
2025-03-29 14:19:40 +08:00

56 lines
1.5 KiB
PHP
Raw 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'])]);
}
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);
}
public function guestLogin()
{
$this->workerLogin(1);
$this->success('登录成功', $this->user);
}
public function logout()
{
$this->workerLogout();
$this->success('操作成功');
}
}