CommonController.php
1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
/**
* Created by PhpStorm.
* User: 29925
* Date: 2018/9/19
* Time: 11:07
*/
namespace app\user\controller;
use app\member\model\MemberModel;
use app\user\model\CodeModel;
use cmf\controller\HomeBaseController;
class CommonController extends HomeBaseController
{
/**
* 发送手机验证码
* @param $mobile 手机号码
*/
public function sendCode() {
if($this->request->isAjax()) {
$mobile = $this->request->param('mobile');
$is_login = $this->request->param('is_login',0,'intval');
$member_model = new MemberModel();
$where = [
'mobile' => $mobile,
'delete_time' => 0
];
$member = $member_model->where($where)->find();
if($is_login == 1) {
if(!$member) {
$this->error('该手机号码未注册');
}
} else {
if($member) {
$this->error('该手机号码已注册');
}
}
$code = $this->generate_code();
// 记录验证码数据
$code_insert = [
'mobile' => $mobile,
'code' => $code,
'over_time' => time()+600
];
$code_model = new CodeModel();
$code_model->addCode($code_insert);
$result = explode(',',$this->sendSMS($mobile,$code));
if($result[0] != 1) {
$this->error($result[0]);
}
$this->success('发送成功');
}
}
}