|
|
|
@ -43,7 +43,67 @@ class Login extends BaseService |
|
|
|
|
|
|
|
|
|
// 用于生成token的自定义盐 |
|
|
|
|
const TOKEN_SALT = 'user_salt'; |
|
|
|
|
/** |
|
|
|
|
* 执行用户登录 |
|
|
|
|
* @param array $data |
|
|
|
|
* @return bool |
|
|
|
|
* @throws BaseException |
|
|
|
|
* @throws \think\Exception |
|
|
|
|
* @throws \think\db\exception\DataNotFoundException |
|
|
|
|
* @throws \think\db\exception\DbException |
|
|
|
|
* @throws \think\db\exception\ModelNotFoundException |
|
|
|
|
*/ |
|
|
|
|
public function accountLogin(array $data): bool |
|
|
|
|
{ |
|
|
|
|
|
|
|
|
|
$data['partyData']['code'] = ""; |
|
|
|
|
$data['partyData']['oauth'] = ""; |
|
|
|
|
$data['isParty'] = false; |
|
|
|
|
$userInfo = UserModel::detail(['mobile' => $data['mobile']]); |
|
|
|
|
if (!$userInfo) { |
|
|
|
|
throwError("账号不存在"); |
|
|
|
|
} |
|
|
|
|
if ($userInfo['password'] && ($userInfo['password'] != md5($data['password']))) { |
|
|
|
|
throwError("密码不正确"); |
|
|
|
|
} |
|
|
|
|
$this->updateUser($userInfo, $data['isParty'], $data['partyData']); |
|
|
|
|
|
|
|
|
|
// 记录登录态 |
|
|
|
|
return $this->setSession(); |
|
|
|
|
} |
|
|
|
|
/** |
|
|
|
|
* 执行用户登录 |
|
|
|
|
* @param array $data |
|
|
|
|
* @return bool |
|
|
|
|
* @throws BaseException |
|
|
|
|
* @throws \think\Exception |
|
|
|
|
* @throws \think\db\exception\DataNotFoundException |
|
|
|
|
* @throws \think\db\exception\DbException |
|
|
|
|
* @throws \think\db\exception\ModelNotFoundException |
|
|
|
|
*/ |
|
|
|
|
public function accountRegister(array $data): bool |
|
|
|
|
{ |
|
|
|
|
$data['partyData']['code'] = ""; |
|
|
|
|
$data['partyData']['oauth'] = ""; |
|
|
|
|
$data['isParty'] = false; |
|
|
|
|
// 自动登录注册 |
|
|
|
|
// 查询用户是否已存在 |
|
|
|
|
// 用户存在: 更新用户登录信息 |
|
|
|
|
$userInfo = UserModel::detail(['mobile' => $data['mobile']]); |
|
|
|
|
if ($userInfo) { |
|
|
|
|
throwError("账号已存在"); |
|
|
|
|
} |
|
|
|
|
// 推荐人ID |
|
|
|
|
$refereeId = 0; |
|
|
|
|
if (!empty($data['refereeId'])) { |
|
|
|
|
$refereeId = intval($data['refereeId']); |
|
|
|
|
} |
|
|
|
|
$data['partyData']['password'] = $data['password']; |
|
|
|
|
// 用户不存在: 创建一个新用户 |
|
|
|
|
$this->createUser($data['mobile'], $data['isParty'], $data['partyData'], $refereeId); |
|
|
|
|
// 记录登录态 |
|
|
|
|
return $this->setSession(); |
|
|
|
|
} |
|
|
|
|
/** |
|
|
|
|
* 执行用户登录 |
|
|
|
|
* @param array $data |
|
|
|
@ -409,8 +469,11 @@ class Login extends BaseService |
|
|
|
|
'nick_name' => !empty($mobile) ? \hide_mobile($mobile) : '', |
|
|
|
|
'platform' => \getPlatform(), |
|
|
|
|
'last_login_time' => \time(), |
|
|
|
|
'store_id' => $this->storeId |
|
|
|
|
'store_id' => $this->storeId, |
|
|
|
|
]; |
|
|
|
|
if (isset($partyData['password']) && $partyData['password']) { |
|
|
|
|
$data['password'] = md5($partyData['password']); |
|
|
|
|
} |
|
|
|
|
// 写入用户信息(第三方) |
|
|
|
|
if ($isParty === true && !empty($partyData)) { |
|
|
|
|
$partyUserInfo = PartyService::partyUserInfo($partyData, true); |
|
|
|
|