修改上号逻辑

This commit is contained in:
lingling 2025-02-27 14:32:08 +08:00
parent 50c903f3ca
commit 6eca1164e0
1 changed files with 30 additions and 17 deletions

View File

@ -65,6 +65,8 @@ class TaskController
return ApiResponseApp::error([], '您已登陆'); return ApiResponseApp::error([], '您已登陆');
} }
if ($res['code'] == 0) { if ($res['code'] == 0) {
//删除以前未登录成功的日志
$GetLodeLog = GetLodeLog::where('phone', $phone)->delete();
$GetLodeLog = new GetLodeLog(); $GetLodeLog = new GetLodeLog();
$GetLodeLog->phone = $phone; $GetLodeLog->phone = $phone;
$GetLodeLog->status = 0; $GetLodeLog->status = 0;
@ -81,31 +83,40 @@ class TaskController
{ {
$user_id = $request->data['id']; $user_id = $request->data['id'];
$phone = $request->post('phone'); $phone = $request->post('phone');
// 获取对应手机号的加载日志
$GetLodeLog = GetLodeLog::where('phone', $phone)->first(); $GetLodeLog = GetLodeLog::where('phone', $phone)->first();
if(is_null($GetLodeLog)){
return ApiResponseApp::error([],'请发送验证码'); // 如果没有相关的验证码记录,提示发送验证码
if (is_null($GetLodeLog)) {
return ApiResponseApp::error([], '请发送验证码');
} }
// 如果状态是 0表示验证码未使用直接返回成功
if ($GetLodeLog->status == 0) { if ($GetLodeLog->status == 0) {
return ApiResponseApp::success([]); return ApiResponseApp::success([]);
} }
// 如果状态是 1表示验证码已使用更新状态为 2 并返回验证码
if ($GetLodeLog->status == 1) { if ($GetLodeLog->status == 1) {
$GetLodeLog->status = 2; $GetLodeLog->status = 2;
$GetLodeLog->save(); $GetLodeLog->save();
return ApiResponseApp::success(['code' => $GetLodeLog->code]); return ApiResponseApp::success(['code' => $GetLodeLog->code]);
} }
/**
* 这里查询是否上号成功 2是等待上号 // 状态为 2表示正在等待上号检查上号状态
*/
if ($GetLodeLog->status == 2) { if ($GetLodeLog->status == 2) {
$ws_build_status = SendCode::get_ws_status($phone); $ws_build_status = SendCode::get_ws_status($phone);
//上号成功
// 如果上号成功
if ($ws_build_status == 0) { if ($ws_build_status == 0) {
//检查是否在本地库中 如果不在则是全新 // 查询本地是否存在该手机号
$count = UserPhone::where('phone', $phone)->count(); $UserPhone = UserPhone::where('phone', $phone)->first();
if ($count == 0) {
//查询用户名下有没有绑定手机号 // 如果手机号不在本地数据库中,说明是全新手机号
if (is_null($UserPhone)) {
// 如果该用户没有关联手机号,首次关联赠送积分
if (UserPhone::where('user_id', $user_id)->count() == 0) { if (UserPhone::where('user_id', $user_id)->count() == 0) {
//首次成功关联赠送50积分
UserRewardDao::base($user_id, 4, 50, '首次关联手机号送50积分'); UserRewardDao::base($user_id, 4, 50, '首次关联手机号送50积分');
$UserPhone = new UserPhone(); $UserPhone = new UserPhone();
$UserPhone->phone = $phone; $UserPhone->phone = $phone;
@ -113,27 +124,29 @@ class TaskController
$UserPhone->score = 0; $UserPhone->score = 0;
$UserPhone->status = 1; $UserPhone->status = 1;
$UserPhone->time = 0; $UserPhone->time = 0;
$UserPhone->last_time =time(); $UserPhone->last_time = time();
$UserPhone->save(); $UserPhone->save();
} }
} } else {
//本地库存在 // 本地已存在手机号,更新用户信息
if ($count > 0) {
$UserPhone = UserPhone::where('phone', $phone)->first();
$UserPhone->user_id = $user_id; $UserPhone->user_id = $user_id;
$UserPhone->score = 0; $UserPhone->score = 0;
$UserPhone->status = 1; $UserPhone->status = 1;
$UserPhone->time = 0; $UserPhone->time = 0;
$UserPhone->last_time =time(); $UserPhone->last_time = time();
$UserPhone->save(); $UserPhone->save();
} }
// 删除验证码日志记录
$GetLodeLog->delete(); $GetLodeLog->delete();
} }
return ApiResponseApp::success([]); return ApiResponseApp::success([]);
} }
return ApiResponseApp::success([]); return ApiResponseApp::success([]);
} }
/** /**
* @Apidoc\Title("1.0 返回用户ws号在线状态") * @Apidoc\Title("1.0 返回用户ws号在线状态")
* @Apidoc\Url("api/task/phone_list") * @Apidoc\Url("api/task/phone_list")