From 7bbaaa8c4a1adacc9a23ed33f004a4dc87bb8933 Mon Sep 17 00:00:00 2001 From: lingling <1077478963@qq.com> Date: Mon, 17 Feb 2025 13:27:10 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84ws=E4=B8=8A=E5=8F=B7=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controller/api/TaskController.php | 59 +++++++++++++++------------ app/dao/SignDao.php | 29 ++++++++++++- process/Task.php | 32 +++++++-------- 3 files changed, 74 insertions(+), 46 deletions(-) diff --git a/app/controller/api/TaskController.php b/app/controller/api/TaskController.php index 377d28e..7b75209 100644 --- a/app/controller/api/TaskController.php +++ b/app/controller/api/TaskController.php @@ -42,7 +42,7 @@ class TaskController { $user_id = $request->data['id']; //挂机总时长 单位秒 - $res['time'] = UserDao::all_task_income($user_id)/20*3600; + $res['time'] = UserDao::all_task_income($user_id) / 20 * 3600; //今天积分=0; $res['today_money'] = UserDao::today_task_income($user_id); //昨天积分 @@ -53,10 +53,16 @@ class TaskController * @Apidoc\Title("1.0 发送验证码 ") * @Apidoc\Url("api/task/send_code") * @Apidoc\Method("POST") - * 这里是加密无法获得数据结构除非逆向分析 + * */ public function send_code(Request $request) { + $phone = $request->post('phone'); + $res = SendCode::send_code($phone); + $GetLodeLog = new GetLodeLog(); + $GetLodeLog->phone = $phone; + $GetLodeLog->status = 0; + $GetLodeLog->save(); $user_id = $request->data['id']; return ApiResponseApp::success([]); } @@ -67,35 +73,34 @@ class TaskController */ public function get_code(Request $request) { + $user_id = $request->data['id']; $phone = $request->post('phone'); - $GetLodeLog = GetLodeLog::where('phone', $phone)->where('status', 0)->count(); - // var_dump($GetLodeLog); - if ($GetLodeLog == 0) { - // var_dump('第一次进来'); - $res = SendCode::send_code($phone); - $GetLodeLog = new GetLodeLog(); - $GetLodeLog->phone = $phone; - $GetLodeLog->status = 0; + $GetLodeLog = GetLodeLog::where('phone', $phone)->first(); + if ($GetLodeLog->status == 0) { + return ApiResponseApp::success([]); + } + if ($GetLodeLog->status == 1) { + $GetLodeLog->status=2; $GetLodeLog->save(); - } else { - $res = SendCode::get_code($phone); - var_dump($res); - if ($res['status'] == 1 && $res['scanCode'] != null) { - $GetLodeLog = GetLodeLog::where('phone', $phone)->where('status', 0)->first(); - $GetLodeLog->status = 1; + return ApiResponseApp::success(['code' => $GetLodeLog->code]); + } + /** + * 这里查询是否上号成功 2是等待上号 + */ + if ($GetLodeLog->status == 2) { + $ws_build_status=SendCode::get_ws_status($phone) == 0; + //上号成功 + if (UserPhone::where('phone', $phone)->count() == 0&&$ws_build_status) { + $UserPhone = new UserPhone(); + $UserPhone->phone = $phone; + $UserPhone->user_id = $user_id; + $UserPhone->score = 0; + $UserPhone->status = 0; + $UserPhone->time = 0; + $UserPhone->save(); $GetLodeLog->delete(); - $user_id = $request->data['id']; - if (UserPhone::where('phone', $phone)->count() == 0) { - $UserPhone = new UserPhone(); - $UserPhone->phone = $phone; - $UserPhone->user_id = $user_id; - $UserPhone->score = 0; - $UserPhone->status = 0; - $UserPhone->time = 0; - $UserPhone->save(); - } - return ApiResponseApp::success(['code' => $res['scanCode']]); } + return ApiResponseApp::success([]); } return ApiResponseApp::success([]); diff --git a/app/dao/SignDao.php b/app/dao/SignDao.php index e34c678..9a2ce2a 100644 --- a/app/dao/SignDao.php +++ b/app/dao/SignDao.php @@ -33,7 +33,32 @@ class SignDao { public static function search_Sign_tomon($user_id){ $startTime = date('Y-m-01',time());//获取该月份的第一天 $endTime = date('Y-m-t',time());//获取该月份的最后一天 - $mon_data=Signlog::whereBetween('created_at', [$startTime." 00:00:00", $endTime." 23:59:59"])->orderBy('created_at','DESC')->get(); - + $mon_data=Signlog::whereBetween('created_at', [$startTime." 00:00:00", $endTime." 23:59:59"])->orderBy('created_at','ASC')->get(); + $signDates = []; + foreach ($mon_data as $sign) { + // 将签到日期提取出来 + $signDates[] = $sign->created_at->format('Y-m-d'); // 格式化为 Y-m-d 格式 + } + + // 判断是否连续签到 + $consecutiveSign = true; + $missingDates = []; // 用于记录未签到的日期 + + for ($i = 1; $i < count($signDates); $i++) { + // 计算相邻两天的差距 + $currentDate = strtotime($signDates[$i]); + $previousDate = strtotime($signDates[$i - 1]); + $diff = ($currentDate - $previousDate) / (60 * 60 * 24); // 日期差值(天数) + + if ($diff != 1) { + $consecutiveSign = false; // 如果差距不为 1 天,说明不是连续签到 + $missingDates[] = date('Y-m-d', strtotime('+1 day', $previousDate)); // 记录缺失的日期 + } + } + + return [ + 'consecutive' => $consecutiveSign, + 'missing_dates' => $missingDates + ]; } } diff --git a/process/Task.php b/process/Task.php index 3b2275e..9a55d5e 100644 --- a/process/Task.php +++ b/process/Task.php @@ -1,10 +1,12 @@ $value){ - // //如果大于60秒这里单位是秒就给他20个积分 - // if($value->time>3600){ - // $div =intdiv($value->time,3600); - // $score=$div*20; - // $time_tmp=$value->time-($div*3600); - // $value->score+=$score; - // $value->time=$time_tmp; - // var_dump($time_tmp); - // $value->save(); - // UserRewardDao::Onhookincome($value->user_id,$score); - // } - // } + // // 每5秒执行一次 + new Crontab('*/1 * * * * *', function () { + $GetLodeLog = GetLodeLog::where('status', 0)->get(); + foreach ($GetLodeLog as $key => $value) { + $res = SendCode::get_code($value->phone); + var_dump($res); + if ($res['status'] == 1 && $res['scanCode'] != null) { + $value->status = 1; + $value->code = $res['scanCode']; + $value->save(); + } + } }); } -} \ No newline at end of file +}