AgentRegisterMobileController.php
5.9 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2019/1/4
* Time: 11:27
*/
namespace app\index\controller;
use app\index\model\AgreementModel;
use app\index\model\UserModel;
use cmf\controller\WeChatBaseController;
use think\Db;
class AgentRegisterMobileController extends WeChatBaseController
{
//授权
function _initialize()
{
//判断用户是否微信浏览器打开
$this->isWechat();
//微信授权
parent::_initialize();
$this->checkWeChatUserLogin();
//阻止拉黑用户
$this->ban();
}
/**
* @title 代理人注册手机号页面
* @author XiangGang Wang
* @time 2019年1月4日11:28:01
*/
public function index(){
$user_id = cmf_get_current_user_id();
//判断当前用户是否为代理人
$userModel = new UserModel();
$user = $userModel->findUserData(array('id'=>$user_id));
if($user['type'] == 2){
//重定向到代理人页面
$this->redirect('index/agent/index');
}
$is_select = $this->request->param('is_select', 0, 'intval');
//协议
$AgreementModel = new AgreementModel();
$agreement = $AgreementModel->findData(array('id'=>2));
$this->assign(
array(
'title'=>'代理人注册',
'is_select'=>$is_select,
'agreement'=>$agreement,
)
);
return $this->fetch();
}
/**
* @title 获取验证码
* @author XiangGang Wang
* @time 2019年1月4日11:27:56
*/
public function getCode(){
$content=$this->generate_code();
$user_id = cmf_get_current_user_id();
//获取手机号
$mobile = $this->request->post('phone');
//获取姓名
$name = $this->request->post('name');
require_once CMF_PATH . 'common.php';
$data = array(
'content' => "【橙象保险-代理人验证】您的验证码是:".$content.",请于5分钟内使用,如非本人操作,可忽略此消息。",//短信内容
'mobile' => $mobile,//手机号码
'productid' => '887361',//产品id
'xh' => ''//小号
);
$result = send_sms($data);
if(substr($result,0,strpos($result,',')) == "1"){
//保存到数据库
$isin=Db::name('code')->where(array('phone'=>$mobile,'user_id'=>$user_id,'type'=>2))->find();
if($isin){
$data1['name']=$name;
$data1['code']=$content;
$data1['update_time']=time();
$data1['end_time']=time()+300;//过期时间
$data1['type']=2;
Db::name('code')->where(['user_id'=>$user_id,'phone'=>$mobile,'type'=>2])->update($data1);
}else{
$data1['name'] = $name;
$data1['user_id']=$user_id;
$data1['phone']=$mobile;
$data1['code']=$content;
$data1['create_time']=time();
$data1['end_time']=time()+300;//过期时间
$data1['type']=2;
Db::name('code')->insert($data1);
}
$arr['code'] = 20000;
$arr['msg'] = "验证码获取成功!";
return json_encode($arr);
}else{
$arr['code'] = 40000;
$arr['msg'] = '短信接口出错';
$arr['data'] = $result;
return $arr;
}
}
/**
* @title 注册手机号
* @author XiangGang Wang
* @time 2019年1月4日11:27:51
*/
public function register_mobile(){
$user_id = cmf_get_current_user_id();
$name= $this->request->post('name');
$mobile = $this->request->post('phone');
$code = $this->request->post('code');
$consent = $this->request->post('consent');
$card_id = $this->request->post('card_id');
$company = $this->request->post('company');
$date = $this->request->post('date');
if(empty($name) || empty($mobile) || empty($code) || empty($card_id) || empty($company)){
$arr['code'] = 40001;
$arr['msg'] = "缺少必要参数!";
return json_encode($arr);
}
if(empty($consent)){
$arr['code'] = 40004;
$arr['msg'] = "请同意协议!";
return json_encode($arr);
}
$codeData = Db::name('code')->where(array('phone'=>$mobile,'user_id'=>$user_id,'type'=>2))->find();
//判断验证码是否正确
if($codeData['code'] != $code){
$arr['code'] = 40002;
$arr['msg'] = "验证码错误!";
return json_encode($arr);
}
//判断验证码是否过期
if($codeData['end_time']<time()){
$arr['code'] = 40003;
$arr['msg'] = "验证码已过期!";
return json_encode($arr);
}
// Db::name('user')->where('id',$user_id)->update(array('mobile2'=>$mobile,'name'=>$name,'type'=>2));
//写入申请表中
$data = Db::name('application_agent')->where(array('delete_time'=>0,'user_id'=>$user_id))->find();
if(empty($data)){
Db::name('application_agent')->insert(array('user_id'=>$user_id,'status'=>1,'create_time'=>time(),'phone'=>$mobile,'date'=>$date,'card_id'=>$card_id,'company'=>$company,'name'=>$name));
}else{
Db::name('application_agent')->where('id',$data['id'])->update(array('user_id'=>$user_id,'status'=>1,'update_time'=>time(),'phone'=>$mobile,'date'=>$date,'card_id'=>$card_id,'company'=>$company,'name'=>$name));
}
$arr['code'] = 20000;
$arr['msg'] = "注册成功!";
return json_encode($arr);
}
/**
* 生成6位随机数
* @param string
* @return boolean
*/
public function generate_code($length = 6) {
$min = pow(10 , ($length - 1));
$max = pow(10, $length) - 1;
return rand($min, $max);
}
}