作者 jinglong

修改数据验证

... ... @@ -135,11 +135,11 @@ class Common
* @ApiInternal
*/
public static function validateMobileCode($post){
$mc = new MobileCode();
$res_find = $mc->where(['mobile' => $post['mobile'], 'mobile_code' => $post['mobile_code'], 'is_use' => 0, 'create_date' => date('Y-m-d'),])
$mobileCodeModel = new MobileCode();
$res_find = $mobileCodeModel->where(['mobile' => $post['mobile'], 'mobile_code' => $post['mobile_code'], 'is_use' => 0, 'create_date' => date('Y-m-d'),])
->where('expire_time','gt',time())->find();
if($res_find){
$res_update = $mc->where('id',$res_find['id'])->setField('is_use',1);
$res_update = $mobileCodeModel->where('id',$res_find['id'])->setField('is_use',1);
if($res_update){
return true;
}
... ...
... ... @@ -258,17 +258,18 @@ class User extends Api
public function sendMobileCode(){
if($this->request->isPost()){
$mobile = $this->request->post('mobile');
$mc = new MobileCode();
$mobileCodeModel = new MobileCode();
$search = '/^0?1[3|4|5|6|7|8|9][0-9]\d{8}$/';
if (!preg_match($search,$mobile)) {
$this->error('手机号格式有误');
}
$mobile_code = rand(100000, 999999);
$content = "【除螨】您的验证码为".$mobile_code.",如非本人操作请忽略本短信!";
$info = $mc->where([
'mobile' => $mobile,
'create_date' => date('Y-m-d')
])->find();
$info = $mobileCodeModel->where(['mobile' => $mobile, 'create_date' => date('Y-m-d')])->find();
$where['mobile'] = $mobile;
$where['mobile_code'] = $mobile_code;
$where['is_use'] = 0;
$where['expire_time'] = time()+600;
if($info){
if(time() < $info['create_time']+60 && $info['is_use'] == 0){
$this->error('不能频繁发送验证码');
... ... @@ -276,23 +277,13 @@ class User extends Api
if($info['count'] > 10){
$this->error('今天发送验证码的次数已达到了上限');
}
$res = $mc->where('id',$info['id'])->data([
'mobile' => $mobile,
'mobile_code' => $mobile_code,
'is_use' => 0,
'expire_time' => time()+600,
'count' => $info['count'] +1
])->update();
$where['count'] = $info['count'] + 1;
$res = $mobileCodeModel->where('id',$info['id'])->data($where)->update();
}else{
$res = $mc->insert([
'mobile' => $mobile,
'mobile_code' => $mobile_code,
'is_use' => 0,
'expire_time' => time()+600,
'count' => 1,
'create_time' => time(),
'create_date' => date('Y-m-d')
]);
$where['count'] = 1;
$where['create_time'] = time();
$where['create_date'] = date('Y-m-d');
$res = $mobileCodeModel->insert($where);
}
if($res) {
//发送验证码
... ...