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