<?php
/**
 * Created by PhpStorm.
 * User: asus
 * Date: 2019/6/12
 * Time: 11:08
 */

namespace app\api\controller;


use think\captcha\Captcha;
use think\Validate;
use app\api\model\Manager as ManagerModel;
class Com extends Base
{
    /**
     * @name:获取验证码
     * @method:get
    */
    public function code(){
        $this->response('验证码',200,'111');
        $config =    [
            // 验证码字体大小
            'fontSize'    =>    30,
            // 验证码位数
            'length'      =>    6,
            // 关闭验证码杂点
            'useNoise'    =>    false,
        ];
        $captcha = new Captcha($config);
        $this->response('验证码',200,$captcha->entry());
    }
    /**
     * 管理员登录
     * @method:post
     * @param $account $password
    */
    public function login(){
        $rule = [
            ['account','require|max:15','账号不能为空|最多不能超过25个字符'],
            ['password','require|max:30','密码不能为空|必须在1~50字符之间'],
        ];
            $validate = new Validate($rule);
        if ($validate->check($this->param) === false) {
            $this->response($validate->getError(), 202);
        }
        $manager = new ManagerModel();
        $info = $manager->login($this->param['account'],$this->param['password']);
        if(empty($info)){
            $this->response('账号或者密码错误',202,[]);
        }
        $this->response('登录成功',200,$info);
    }
}