<?php
/**
 * Created by PhpStorm.
 * User: lldream
 * Date: 2018/11/14
 * Time: 18:32
 */

class smslogModel extends Model{
    public function __construct()
    {
        parent::__construct("smslog");
    }
    
    //获取所有的日志
    public function getall($page=0,$limit=10){
        $page = $page==""?0:($page-1);
        $limit= $limit==""?0:$limit;
        return $this->limit($page*$limit,$limit)->all();
    }
    //添加日志
    public function addlog($user,$log,$type)
    {
        $data['user']   = $user;    //手机号
        $data['log']    = $log;     //日志说明
        $data['type']   = isset($type)?$type:"普通";    //发送类型
        $data['dtime']  = date("Y-m-d H:i:s");   //添加时间 Y-m-d H:i:s

        $this->insert($data);
    }
    //验证验证码的正确性
    public function validationCode($arr){
        $one = $this->where(['user'=>$arr['phone'],'log'=>$arr['code']])->orderBy('id desc')->one();
        if (empty($one)){
            returnFail(config('code')['3008'],[],3008);
        }
        $time = strtotime($one['dtime']);
        $now = time();
        if(($time+300)<$now){
            returnFail(config('code')['3009'],[],3009);
        }
    }
}