|
@@ -627,7 +627,6 @@ class User extends Api
|
|
*/
|
|
*/
|
|
public function bindmobile()
|
|
public function bindmobile()
|
|
{
|
|
{
|
|
- Db::startTrans();
|
|
|
|
try {
|
|
try {
|
|
$code = $this->request->param('code');
|
|
$code = $this->request->param('code');
|
|
$mobile = $this->request->param('mobile');
|
|
$mobile = $this->request->param('mobile');
|
|
@@ -643,13 +642,29 @@ class User extends Api
|
|
if (!$result) {
|
|
if (!$result) {
|
|
throw new Exception(__('Captcha is incorrect'));
|
|
throw new Exception(__('Captcha is incorrect'));
|
|
}
|
|
}
|
|
- $where['mobile'] = $mobile;
|
|
|
|
- $userData = model('User')->where($where)->find();//老用户
|
|
|
|
|
|
+
|
|
$wechatCodeWhere['code'] = $code;
|
|
$wechatCodeWhere['code'] = $code;
|
|
$wechatCode = Db::name('wechat_code')->where($wechatCodeWhere)->find();
|
|
$wechatCode = Db::name('wechat_code')->where($wechatCodeWhere)->find();
|
|
if (empty($wechatCode)) {
|
|
if (empty($wechatCode)) {
|
|
throw new Exception('请先微信登录');
|
|
throw new Exception('请先微信登录');
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ //检查appid绑定的用户
|
|
|
|
+ $user = Db::name('user')->where('openid',$wechatCode['openid'])->find();
|
|
|
|
+ if ($user) {
|
|
|
|
+ if ($user['status'] == -1) {
|
|
|
|
+ $this->error('账户已注销');
|
|
|
|
+ }
|
|
|
|
+ if ($user['status'] != 1) {
|
|
|
|
+ $this->error(__('Account is locked'));
|
|
|
|
+ }
|
|
|
|
+ //如果已经有账号则直接登录
|
|
|
|
+ $ret = $this->auth->direct($user['id']);
|
|
|
|
+ $this->success('success',$this->userInfo('return'));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $where['mobile'] = $mobile;
|
|
|
|
+ $userData = model('User')->where($where)->find();//老用户
|
|
if (!empty($userData)) {
|
|
if (!empty($userData)) {
|
|
if (empty($userData['openid'])) {
|
|
if (empty($userData['openid'])) {
|
|
model('User')->update(['openid' => $wechatCode['openid']],$where);//老用户更新openid
|
|
model('User')->update(['openid' => $wechatCode['openid']],$where);//老用户更新openid
|
|
@@ -670,10 +685,8 @@ class User extends Api
|
|
}
|
|
}
|
|
|
|
|
|
Sms::flush($mobile, 'changemobile');
|
|
Sms::flush($mobile, 'changemobile');
|
|
- Db::commit();
|
|
|
|
$this->success('success',$this->userInfo('return'));
|
|
$this->success('success',$this->userInfo('return'));
|
|
} catch (Exception $e) {
|
|
} catch (Exception $e) {
|
|
- Db::rollback();
|
|
|
|
$this->error($e->getMessage());
|
|
$this->error($e->getMessage());
|
|
}
|
|
}
|
|
}
|
|
}
|