'ain_users_model', 'fish' => 'fish_users_model' ]; public function __construct() { parent::__construct($this->table_name, 'default'); $this->load->model('agent/pingan/pingan_users_model'); $this->load->model('agent/organization/organization_model'); } /** * @param $openid * @param string $accountId 平安用户编码 * @param string $from ain fish * @param array $otherInfo * @return MyResponse */ public function initUser($mobile, $openid, $accountId, $from = '', $otherInfo = []) { try { $userModel = self::MAP_USER_MODEL[$from]; if ($userModel) { $this->load->model('agent/pingan/' . $userModel, 'pingAnUsers'); } else { $this->load->model('agent/pingan/pingan_users_model', 'pingAnUsers'); } $user = $this->get(['mobile' => $mobile, 'openid' => $openid]); if (!$user) { $user = [ 'mobile' => $mobile, 'openid' => $openid, 'createTime' => date('Y-m-d H:i:s'), ]; if ($accountId) { $this->organization_model->getTeamLevel($accountId); $pingAnUsers = $this->pingAnUsers->get(['userCode' => $accountId, 'status' => Pingan_users_model::STATUS_NORMAL]); $teamLevel = 0; if ($pingAnUsers['orgTeamId']) { $teamLevel = $this->organization_model->getTeamLevel($pingAnUsers['orgTeamId']); } if ($teamLevel >= 4) { $user['teamId'] = $pingAnUsers['teamId'] ?: 0; } $user['depId'] = $pingAnUsers['depId'] ?: 0; $user['areaId'] = $pingAnUsers['areaId'] ?: 0; $user['pinganUserId'] = $pingAnUsers['id'] ?: 0; $user['orgId'] = $pingAnUsers['orgId'] ?: 0; $user['orgTeamId'] = $pingAnUsers['orgTeamId'] ?: 0; } $otherInfo['nickname'] && $user['nickname'] = $otherInfo['nickname']; $otherInfo['headimg'] && $user['headimg'] = $otherInfo['headimg']; $otherInfo['unionid'] && $user['unionid'] = $otherInfo['unionid']; $userId = $this->add($user); if (!$userId) { throw new Exception('添加用户失败'); } $user['id'] = $userId; } else { if ($user['status'] != self::STATUS_NORMAL) { throw new Exception('账号已被禁用'); } //更新用户信息 $updateData = []; $otherInfo['nickname'] && $updateData['nickname'] = $otherInfo['nickname']; $otherInfo['headimg'] && $updateData['headimg'] = $otherInfo['headimg']; $updateData && $this->update($updateData, ['id' => $user['id']]); } return new MyResponse(EXIT_SUCCESS, 'success', $user); } catch (Exception $e) { return new MyResponse(EXIT_ERROR, $e->getMessage()); } } }