getUserByMobliePhone($mobile_phone); $data = [ 'uid' => $this->mid, 'user_agent' => $this->userAgent, 'status' => 1, 'mobile_phone' => $mobile_phone, 'is_bind_mobile' => 1, ]; //根据不同平台 生成平台用户信息及实例化相关平台模型 switch ($this->userAgent) { case 'app': //APP $data['app_id'] = $info['app_user_id']; $data['app_device_id'] = $info['device_id']; $data['is_bind_app'] = 1; $platform_user_model = new AppUser(); $uni_where = [ ['uid', '=', $this->mid], ['device_id', '=', $info['device_id']] ]; break; case 'mp_weixin': //微信小程序 $data['mpweixin_id'] = $info['mpweixin_user_id']; $data['mpweixin_openid'] = $info['openid']; $data['is_bind_mpweixin'] = 1; $platform_user_model = new MpweixinUser(); $uni_where = [ ['uid', '=', $this->mid], ['openid', '=', $info['openid']] ]; break; case 'weixin': //公众号 $data['wechat_id'] = $info['wechat_user_id']; $data['wechat_openid'] = $info['openid']; $data['is_bind_wechat'] = 1; $platform_user_model = new WechatUser(); $uni_where = [ ['uid', '=', $this->mid], ['openid', '=', $info['openid']] ]; break; case 'mp_alipay': //支付宝小程序 $data['mpalipay_id'] = $info['mpalipay_user_id']; $data['mpalipay_openid'] = $info['openid']; $data['is_bind_mpalipay'] = 1; $platform_user_model = new MpalipayUser(); $uni_where = [ ['uid', '=', $this->mid], ['openid', '=', $info['openid']] ]; } // 更新用户 $res = $user_model->updateUser($data); $user_id = $res['user_id']; $type = $res['type']; //1--注册新用户 2--之前注册过 if (!$user_id) { return sendErrorArray(3001, '更新用户失败'); } //更新平台用户信息 if (!empty($platform_user_model)) { $res = $platform_user_model->dataUpdate(['user_id' => $user_id], $uni_where); if (!$res) { return sendErrorArray(3002, '更新平台用户失败'); } } if ($type == 1) { // 获取默认头像和昵称 $config = $config_user_model->getDefaultInfo(); if (empty($config)) { //没有设置默认头像的话做如下定义 #TODO 是否要随机头像 $config['head_img_default'] = ''; $config['nick_name_default'] = '匿名'; } // 新增用户info $info_data = [ 'uid' => UID, 'user_agent' => USER_AGENT, 'user_id' => $user_id, 'head_img' => $config['head_img_default'], 'nick_name' => $config['nick_name_default'], ]; $res = $info_model->dataUpdate($info_data); if (!$res) { return sendErrorArray(3002, '新增用户信息失败'); } // 加入统计系统(新增用户) $statistics_class = new \jucheng\tongji\Statistics(); $result = $statistics_class -> updateUserNumber(1); //建立三级分销关系 $distribution_logic->buildRelation($user_id, $last_user_id); } #TODO 是否被其他用户端绑定 如果被绑定需要如何操作需要和产品确认 //有三方授权的情况更新三方授权(仅限APP用户端有三方授权登录) if ($info['user_agent'] == 'app' && !empty($third_type)) { if ($third_type == 'weixin') { $third_platform_user_model = new AppWeixinUser(); } else if ($third_type == 'qq') { $third_platform_user_model = new AppQqUser(); } else if ($third_type == 'sinaweibo') { $third_platform_user_model = new AppSinaweiboUser(); } else if ($third_type == 'apple') { $third_platform_user_model = new AppAppleUser(); } $res = $third_platform_user_model->dataUpdate([ 'id' => $third_id, 'user_id' => $user_id ]); if (!$res) { return sendErrorMessage(4001, '更新三方授权失败'); } } return sendSuccessArray(['user_id' => $user_id]); } /** * 校验用户密码 * @param string $mobile_phone 手机号 * @param string $password 密码 * @date 2021-02-25 */ public function checkPassword($mobile_phone, $password) { $user_model = new \app\base\model\user\User(); $user = $user_model->getUserByMobliePhone($mobile_phone); if (empty($user)) { return sendErrorArray(3001, '用户不存在'); } if (empty($user['password'])) { return sendErrorArray(3002, '未设置密码,无法登录'); } if (md5WithKey($password) !== $user['password']) { return sendErrorArray(3003, '密码有误'); } return sendSuccessArray(['user_id' => $user['id']]); } }