|
|
@@ -348,7 +348,7 @@ class Login extends Manager
|
|
|
if (!$user_info) return json_send(['code' => 'error', 'msg' => '未找到用户信息']);
|
|
|
//查询openid是否绑定其它用户
|
|
|
$openid_user_info = $EmployeeOpenidModel->where(['openid' => $tokenData['openid']])->first();
|
|
|
- if($openid_user_info && $openid_user_info->employee_id != $uid){
|
|
|
+ if ($openid_user_info && $openid_user_info->employee_id != $uid) {
|
|
|
return json_send(['code' => 'error', 'msg' => '该微信已绑定其它账号']);
|
|
|
}
|
|
|
DB::beginTransaction();
|
|
|
@@ -358,14 +358,24 @@ class Login extends Manager
|
|
|
//查询是否存在绑定记录
|
|
|
$band_wechat_data = $EmployeeOpenidModel->where(['employee_id' => $uid, 'type' => '3'])->first();
|
|
|
if (!$band_wechat_data) {
|
|
|
- $EmployeeOpenidModel->insertGetId([
|
|
|
- 'company_id' => $company_id,
|
|
|
- 'employee_id' => $uid,
|
|
|
- 'unionid' => $tokenData['unionid'] ?? '',
|
|
|
- 'openid' => $tokenData['openid'],
|
|
|
- 'type' => '3',
|
|
|
- 'insert_time' => time()
|
|
|
- ]);
|
|
|
+ //查询关注公众号记录
|
|
|
+ $unionid = $tokenData['unionid'] ?? '';
|
|
|
+ $official_user_info = $EmployeeOpenidModel->where(['unionid' => $unionid])->first();
|
|
|
+ if ($official_user_info) {
|
|
|
+ $official_user_info->employee_id = $uid;
|
|
|
+ $official_user_info->openid = $tokenData['openid'];
|
|
|
+ $official_user_info->update_time = time();
|
|
|
+ $official_user_info->save();
|
|
|
+ } else {
|
|
|
+ $EmployeeOpenidModel->insertGetId([
|
|
|
+ 'company_id' => $company_id,
|
|
|
+ 'employee_id' => $uid,
|
|
|
+ 'unionid' => $tokenData['unionid'] ?? '',
|
|
|
+ 'openid' => $tokenData['openid'],
|
|
|
+ 'type' => '3',
|
|
|
+ 'insert_time' => time()
|
|
|
+ ]);
|
|
|
+ }
|
|
|
} else {
|
|
|
$band_wechat_data->unionid = $tokenData['unionid'] ?? '';
|
|
|
$band_wechat_data->openid = $tokenData['openid'];
|