<?php
declare (strict_types = 1);

namespace app\model\api;

use library\basic\BaseModel;
use think\Model;

/**
 * @mixin \think\Model
 */
class SmsYzm extends BaseModel
{

    /**
     * 手机验证
     * @param $mobile
     * @param $yzm
     * @param $active
     * @param $sassid
     */
    public function VerCode($mobile,$yzm,$active,$sassid) {
        $time = time();
        $smsCode = $this->where("mobile",$mobile)
            ->where("action",$active)
            ->where('sassid',$sassid)
            ->where("status",0)
            ->order("time","desc")
            ->find();
        if (empty($smsCode) ||  $smsCode['code'] != $yzm || $time - $smsCode['time'] > 30 * 60) {
            self::setErrorInfo("请输入正确的验证码");
            return false;
        }
        (new self)->where("id",$smsCode['id'])->save(array("status"=>1));
        return true;
    }

}
