<?php
/**
 *
 *User:Administrator
 *Date:2021/10/8
 */

namespace app\api\controller\v1;

use app\api\business\LoginBus;
use app\api\validate\User;
use app\BaseController;
use think\exception\ValidateException;

class Login extends BaseController
{
    //登录
    public function login()
    {
        if (!$this->request->isPost()) return showError(config('status.illegal_request'));
         $data = [
            'username'=>$this->request->param('login_name', '', 'trim'),
            'password'=>$this->request->param('pwd', '', 'trim'),
        ];
        try {
            validate(User::class)->scene('login')->check($data);
        } catch (ValidateException $exception) {
            return show(config('status.err_validate'),$exception->getError());
        }
        $res=(new LoginBus())->login($data['username'],$data['password']);
        return showSuccess($res);
    }

    //登出
    public function logout()
    {

    }
}