Blame view

yohobuy/m.yohobuy.com/application/modules/Passport/controllers/Bind.php 9.64 KB
xiaowei authored
1 2 3
<?php

use Action\AbstractAction;
xiaowei authored
4
use LibModels\Wap\Passport\BindData;
xiaowei authored
5
use LibModels\Wap\Passport\RegData;
xiaowei authored
6 7 8 9 10 11 12 13 14 15 16 17 18
use Plugin\Helpers;

/**
 * 登录的控制器
 */
class BindController extends AbstractAction
{

    /**
     * 登录到bind页面
     */
    public function indexAction()
    {
xiaowei authored
19
        $refer = $this->get('refer');
20
        if (!empty($refer)) {
xiaowei authored
21 22 23
            $this->setCookie('refer', $refer);
        }
xiaowei authored
24
        $this->setTitle('绑定手机号');
hf authored
25
xiaowei authored
26 27
        $openId = $this->get('openId');
        $sourceType = $this->get('sourceType');
xiaowei authored
28
        $nickname = $this->get('nickname');
xiaowei authored
29
        $data = array(
hf authored
30 31
            'bindIndex' => true, //js标识
            'backUrl' => Helpers::url('/signin.html'), // 返回的URL链接
xiaowei authored
32 33
            'showHeaderImg' => true, // 控制显示头部图片
            'isPassportPage' => true, // 模板中模块标识
xiaowei authored
34
            'sourceType' => $sourceType, // 第三方登录来源
hf authored
35
            'platform' => $sourceType,
xiaowei authored
36
            'openId' => $openId, // openId
hf authored
37 38
            'areaCode' => '+86', //默认区号
            'countrys' => RegData::getAreasData(), //国别码
xiaowei authored
39
            'nickname' => $nickname, //昵称
xiaowei authored
40 41 42 43 44 45
        );

        // 渲染模板
        $this->_view->display('index', $data);
    }
xiaowei authored
46 47 48 49 50 51
    /**
     * 手机验证码页面
     */
    public function codeAction()
    {
        $this->setTitle('验证手机');
52
xiaowei authored
53 54
        $openId = $this->get('openId');
        $sourceType = $this->get('sourceType');
xiaowei authored
55 56
        $nickname = $this->get('nickname');
        $areaCode = $this->get('areaCode', '86');
xiaowei authored
57
        $isReg = $this->get('isReg');
hf authored
58 59
        $phoneNum = $this->get('phoneNum');
xiaowei authored
60
        $data = array(
hf authored
61 62
            'bindCode' => true, //js标识
            'backUrl' => Helpers::url('/signin.html'), // 返回的URL链接
xiaowei authored
63 64
            'showHeaderImg' => true, // 控制显示头部图片
            'isPassportPage' => true, // 模板中模块标识
xiaowei authored
65 66
            'sourceType' => $sourceType, // 第三方登录来源
            'openId' => $openId, // openId
xiaowei authored
67
            'nickname' => $nickname, //昵称
xiaowei authored
68
            'isReg' => $isReg, //是否是已注册过的手机号
hf authored
69 70
            'areaCode' => $areaCode, //国别码
            'phoneNum' => $phoneNum, //手机号码
xiaowei authored
71 72 73 74 75 76 77 78 79 80 81 82 83 84
        );

        // 渲染模板
        $this->_view->display('code', $data);
    }

    /**
     * 设置登录密码页面
     */
    public function passwordAction()
    {
        $this->setTitle('重新设置登录密码');
        $openId = $this->get('openId');
        $sourceType = $this->get('sourceType');
xiaowei authored
85 86
        $nickname = $this->get('nickname');
        $areaCode = $this->get('areaCode', '86');
hf authored
87
        $phoneNum = $this->get('phoneNum');
xiaowei authored
88
        $data = array(
hf authored
89 90
            'bindPwd' => true, //js标识
            'backUrl' => Helpers::url('/signin.html'), // 返回的URL链接
xiaowei authored
91 92
            'showHeaderImg' => true, // 控制显示头部图片
            'isPassportPage' => true, // 模板中模块标识
xiaowei authored
93 94
            'sourceType' => $sourceType, // 第三方登录来源
            'openId' => $openId, // openId
xiaowei authored
95
            'nickname' => $nickname, //昵称
hf authored
96
            'areaCode' => $areaCode, //国别码
xiaowei authored
97
            'phoneNum' => $phoneNum   //国别码
xiaowei authored
98 99 100 101 102 103
        );

        // 渲染模板
        $this->_view->display('password', $data);
    }
104 105 106
    /**
     * 绑定前手机号校验
     */
xiaowei authored
107 108 109 110
    public function bindCheckAction()
    {
        $data = array('code' => 400, 'message' => '', 'data' => '');
111
        do {
xiaowei authored
112
            /* 判断是不是AJAX请求 */
113
            if (!$this->isAjax()) {
xiaowei authored
114 115 116
                break;
            }
xiaowei authored
117
            $phoneNum = $this->post('phoneNum');
xiaowei authored
118
            $openId = $this->post('openId');
xiaowei authored
119
            $areaCode = $this->post('areaCode', '86');
xiaowei authored
120
            $sourceType = $this->post('sourceType');
xiaowei authored
121
            $nickname = $this->post('nickname');
122
            
123
            if (!is_numeric($phoneNum) || !$openId || !$areaCode || !$sourceType) {
xiaowei authored
124 125 126
                break;
            }
127
            $res = BindData::bindCheck($phoneNum, $openId, $sourceType, $areaCode);
128
            if (!isset($res['code'])) {
xiaowei authored
129 130
                break;
            }
131
132 133
            if ($res['code'] == 200) {
                $next = Helpers::url('/passport/bind/code', array(
134 135 136 137 138 139
                    'isReg' => $res['data']['is_register'],
                    'openId' => $openId,
                    'sourceType' => $sourceType,
                    'areaCode' => $areaCode,
                    'phoneNum' => $phoneNum,
                    'nickname' => $nickname,
140
                ));
xiaowei authored
141
                $data = array('code' => $res['code'], 'message' => $res['message'], 'data' => array('isReg' => $res['data']['is_register'], 'next' => $next));
142
            } else {
hf authored
143
                $data = array('code' => $res['code'], 'message' => $res['message'], 'data' => isset($res['data']) ? $res['data'] : '');
xiaowei authored
144
            }
145
        } while (false);
xiaowei authored
146
xiaowei authored
147 148 149
        $this->echoJson($data);
    }
150 151 152
    /**
     * 发送验证码
     */
xiaowei authored
153 154 155 156
    public function sendBindMsgAction()
    {
        $data = array('code' => 400, 'message' => '', 'data' => '');
157
        do {
xiaowei authored
158
            /* 判断是不是AJAX请求 */
159
            if (!$this->isAjax()) {
xiaowei authored
160 161 162
                break;
            }
xiaowei authored
163
            $phoneNum = $this->post('phoneNum');
xiaowei authored
164
            $areaCode = $this->post('areaCode');
xiaowei authored
165
166
            if (!is_numeric($phoneNum) || !$areaCode) {
xiaowei authored
167 168 169
                break;
            }
hf authored
170
            $data = BindData::sendBindMsg($areaCode, $phoneNum);
171
            if (!isset($data['code'])) {
xiaowei authored
172 173
                break;
            }
174
        } while (false);
xiaowei authored
175 176 177 178

        $this->echoJson($data);
    }
179 180 181
    /**
     * 校验短信验证码
     */
xiaowei authored
182 183 184 185
    public function checkBindMsgAction()
    {
        $data = array('code' => 400, 'message' => '', 'data' => '');
186
        do {
xiaowei authored
187
            /* 判断是不是AJAX请求 */
188
            if (!$this->isAjax()) {
xiaowei authored
189 190 191
                break;
            }
xiaowei authored
192
            $phoneNum = $this->post('phoneNum');
xiaowei authored
193
            $code = $this->post('code');
xiaowei authored
194
            $areaCode = $this->post('areaCode');
xiaowei authored
195
196
            if (!is_numeric($phoneNum) || !$code || !$areaCode) {
xiaowei authored
197 198 199
                break;
            }
hf authored
200
            $data = BindData::checkBindCode($areaCode, $phoneNum, $code);
201
            if (!isset($data['code'])) {
xiaowei authored
202 203
                break;
            }
204
        } while (false);
xiaowei authored
205 206 207 208

        $this->echoJson($data);
    }
209 210 211
    /**
     * 绑定手机号
     */
xiaowei authored
212 213 214 215
    public function bindMobileAction()
    {
        $data = array('code' => 400, 'message' => '', 'data' => '');
216
        do {
xiaowei authored
217
            /* 判断是不是AJAX请求 */
218
            if (!$this->isAjax()) {
xiaowei authored
219 220 221
                break;
            }
xiaowei authored
222
            $phoneNum = $this->post('phoneNum');
xiaowei authored
223
            $openId = $this->post('openId');
xiaowei authored
224
            $areaCode = $this->post('areaCode', '86');
xiaowei authored
225
            $sourceType = $this->post('sourceType');
226
//            $nickname = $this->post('nickname');//nickname不同步信息
227 228
            $password = $this->post('password');
            $password = !empty($password) ? $password : '';
xiaowei authored
229
230
            if (!is_numeric($phoneNum) || !$openId || !$sourceType || !$areaCode) {
xiaowei authored
231 232 233
                break;
            }
234
            $res = BindData::bindMobile($openId, $sourceType, $phoneNum, $areaCode, $password);
235
            if (!isset($res['code'])) {
xiaowei authored
236 237 238 239 240
                break;
            }

            //绑定成功,跳转页面
            $refer = $this->getCookie('refer');
241
            if (empty($refer)) {
xiaowei authored
242
                $refer = SITE_MAIN . '/?go=1';
243
            } else {
xiaowei authored
244 245
                $refer = rawurldecode($refer);
            }
hf authored
246
247
            if (isset($res['code']) && $res['code'] == 200 && !empty($res['data']['uid'])) {
xiaowei authored
248 249
                $token = Helpers::makeToken($res['data']['uid']);
                $this->setSession('_TOKEN', $token);
250 251
                $this->setSession('_LOGIN_UID', $res['data']['uid']);
                $this->setCookie('_TOKEN', $token);
xiaowei authored
252
                $refer = Helpers::syncUserSession($res['data']['uid'], $refer);
xiaowei authored
253
                $data = array('code' => $res['code'], 'message' => $res['message'], 'data' => array('refer' => $refer));
254
            } else {
xiaowei authored
255 256
                $data = array('code' => $res['code'], 'message' => $res['message'], 'data' => array('refer' => $refer));
            }
257
        } while (false);
xiaowei authored
258 259 260 261

        $this->echoJson($data);
    }
262 263 264
    /**
     * 换绑check
     */
xiaowei authored
265 266 267 268
    public function changeCheckAction()
    {
        $data = array('code' => 400, 'message' => '', 'data' => '');
269
        do {
xiaowei authored
270
            /* 判断是不是AJAX请求 */
271
            if (!$this->isAjax()) {
xiaowei authored
272 273 274 275 276 277
                break;
            }

            $phoneNum = $this->post('phoneNum');
            $areaCode = $this->post('areaCode');
278
            if (!is_numeric($phoneNum) || !$areaCode) {
xiaowei authored
279 280 281 282
                break;
            }

            $data = BindData::changeCheck($phoneNum, $areaCode);
283
            if (!isset($data['code'])) {
xiaowei authored
284 285
                break;
            }
286
        } while (false);
xiaowei authored
287 288 289 290

        $this->echoJson($data);
    }
291 292 293
    /**
     * 换绑mobile
     */
xiaowei authored
294 295 296 297
    public function changeMobileAction()
    {
        $data = array('code' => 400, 'message' => '', 'data' => '');
298
        do {
xiaowei authored
299
            /* 判断是不是AJAX请求 */
300
            if (!$this->isAjax()) {
xiaowei authored
301 302 303 304 305 306 307
                break;
            }
            $uid = $this->getUid(true);
            $phoneNum = $this->post('phoneNum');
            $areaCode = $this->post('areaCode');
            $code = $this->post('code');
308
            if (!is_numeric($phoneNum) || !$areaCode || !$code || !$uid) {
xiaowei authored
309 310 311 312
                break;
            }

            $data = BindData::changeMobile($uid, $phoneNum, $areaCode, $code);
313
            if (!isset($data['code'])) {
xiaowei authored
314 315
                break;
            }
316
        } while (false);
xiaowei authored
317 318 319

        $this->echoJson($data);
    }
xiaowei authored
320 321

}