|
|
@@ -232,7 +232,6 @@ class Login extends Api
|
|
|
{
|
|
|
// 验证规则
|
|
|
$Request->scene('wechat_phone')->validate();
|
|
|
- $company_id = request('access_token.company_id', '0');
|
|
|
// 接收数据
|
|
|
$auth_code = request('auth_code', '');
|
|
|
$open_code = $Request->input('open_code', '');
|
|
|
@@ -245,9 +244,10 @@ class Login extends Api
|
|
|
if (empty($result['purePhoneNumber'])) return json_send(['code' => 'error', 'msg' => '未获取到手机号', 'data' => ['error' => '未获取到手机号']]);
|
|
|
$phone = $result['purePhoneNumber'];
|
|
|
// 查询用户
|
|
|
- $phone_user_data = $EmployeeOpenidModel->where(['mobile' => $phone])->first(['company_id', 'id as uid', 'name as username', 'mobile as phone', 'status', 'password', 'insert_time', 'update_time']);
|
|
|
+ $phone_user_data = $EmployeeModel->where(['mobile' => $phone])->first(['company_id', 'id as uid', 'name as username', 'mobile as phone', 'status', 'password', 'insert_time', 'update_time']);
|
|
|
if (!$phone_user_data) return json_send(['code' => 'error', 'msg' => '手机号码未授权']);
|
|
|
if ($phone_user_data['status']) return json_send(['code' => 'error', 'msg' => '该账号已停用']);
|
|
|
+ $company_id = $phone_user_data->company_id;
|
|
|
$uid = $phone_user_data->employee_id;
|
|
|
//获取用户的openid
|
|
|
$tokenData = OpenPlat::jscode2session($open_code, $appId);
|
|
|
@@ -260,14 +260,22 @@ class Login extends Api
|
|
|
try {
|
|
|
$phone_user_data->band_wechat = 1; //绑定微信0=未绑定1=已绑定
|
|
|
$phone_user_data->save();
|
|
|
- $EmployeeOpenidModel->insertGetId([
|
|
|
- 'company_id' => $company_id,
|
|
|
- 'employee_id' => $uid,
|
|
|
- 'unionid' => $tokenData['unionid'] ?? '',
|
|
|
- 'mini_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->mini_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'] ?? '',
|
|
|
+ 'mini_openid' => $tokenData['openid'],
|
|
|
+ 'insert_time' => time()
|
|
|
+ ]);
|
|
|
+ }
|
|
|
DB::commit();
|
|
|
} catch (\Exception $e) {
|
|
|
DB::rollBack();
|
|
|
@@ -276,7 +284,6 @@ class Login extends Api
|
|
|
} else {
|
|
|
$user_open_data->unionid = $tokenData['unionid'] ?? '';
|
|
|
$user_open_data->mini_openid = $tokenData['openid'];
|
|
|
- $user_open_data->type = '3';
|
|
|
$user_open_data->update_time = time();
|
|
|
$user_open_data->save();
|
|
|
}
|