AddEnterpriseController.class.php
4.35 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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
<?php
/**
* 添加企业信息(此接口暂时不用)
* Created by PhpStorm.
* User: 何岳龙
* Date: 2016年8月2日13:54:51
*/
namespace Apicp\Controller\SysSetting;
use Com\Model;
use Com\Validator;
use VcySDK\Adminer;
use VcySDK\Enterprise;
use VcySDK\Service;
use VcySDK\Sms;
class AddEnterpriseController extends AbstractController
{
/**
* 是否必须登录
*
* @var string
*/
protected $_require_login = false;
/**
* @type Sms
*/
protected $_sms;
/**
* @type Enterprise
*/
protected $_enterprise;
/**
* @type Adminer
*/
protected $_admin;
// 前置操作
public function before_action($action = '')
{
if (parent::before_action($action) === false) {
return false;
}
// 实例化SDK
$service =& Service::instance();
$this->_sms = new Sms($service);
$this->_enterprise = new Enterprise($service);
$this->_admin = new Adminer($service);
return true;
}
public function Index()
{
$mobile = I('post.epContactmobile');
$code = I('post.code');
// 验证密码
if (! $this->pwd()) {
return false;
}
// 如果不为手机号
if (! Validator::is_phone($mobile)) {
$this->_set_error('_ERR_PHONE_FORMAT');
return false;
}
// 获取验证码信息
$sms = $this->_sms->verifyCode(array('scMobile' => $mobile, 'scCode' => $code));
// 验证码错误
if ($sms['code'] !== "SUCCESS") {
$this->_set_error('_ERR_PHONE_CODE');
return false;
}
// 添加企业
if (! $this->addetr(I('post.'))) {
return false;
}
// 添加管理员
$admin = $this->addAdmin(I('post.'));
// 添加管理员是否成功
if (! $admin) {
return false;
}
return true;
}
/**
* 注册企业信息
*
* @param array $data post数据
*
* @return bool
*/
protected function addetr($data)
{
$values = array(
'domain' => $_SERVER['HTTP_HOST'] . "/" . QY_DOMAIN . "/",
'epDomain' => $_SERVER['HTTP_HOST'] . "/" . QY_DOMAIN . "/",
'isStandard' => 1,
'epEnumber' => $data['epEnumber'],
'epName' => $data['epName'],
'epContactmobile' => $data['epContactmobile'],
'epContactemail' => $data['epContactemail'],
'epContacter' => $data['epContacter'],
'epCity' => serialize(array(
'epProvince' => $data['epProvince'],
'epCity' => $data['epCity'],
'epCounty' => $data['epCounty']
)),
'epIndustry' => $data['epIndustry'],
'epCompanysize' => $data['epCompanysize']
);
// 注册企业
$result = $this->_enterprise->register($values);
// 企业注册失败
if (empty($result['epId'])) {
$this->_set_error('_ERR_RGQY_REG');
return false;
}
return true;
}
/**
* 注册管理员
*
* @param array $data post数据
*
* @return bool
*/
protected function addAdmin($data)
{
$values = array(
'eaMobile' => $data['epContactmobile'],
'eaRealname' => $data['epContacter'],
'eaPassword' => $data['pwd'],
'eaUserstatus' => Model::ST_CREATE,
'ea_level' => Adminer::SUPER_MANAGER,
'eaCpmenu' => ''
);
// 注册管理员
$result = $this->_admin->register($values);
// 管理员注册失败
if (empty($result['eaId'])) {
$this->_set_error('_ERR_EDIT_ADMIN');
return false;
}
return true;
}
/**
* 密码验证
*
* @return bool
*/
protected function pwd()
{
$pwd = I('post.pwd');
$repeatpwd = I('post.repeatpwd');
// 密码不能为空
if (empty($pwd)) {
$this->_set_error('_ERR_PWD_EMPTY');
return false;
}
// 登录密码和确认密码不相等
if ($pwd != $repeatpwd) {
$this->_set_error('_ERR_PWD_NOT_EQ');
return false;
}
return true;
}
}