浏览代码

fix(user): 修复签到信息缓存逻辑并添加显示控制字段

- 移除重复的缓存检查逻辑,优化代码结构
- 添加 show 字段用于控制签到界面显示状态
- 重构缓存设置逻辑,确保今日签到状态正确更新
- 修复连续签到天数计算的条件判断
shichen 3 月之前
父节点
当前提交
f07ea7f630
共有 1 个文件被更改,包括 13 次插入14 次删除
  1. 13 14
      app/controller/api/user/User.php

+ 13 - 14
app/controller/api/user/User.php

@@ -3323,19 +3323,6 @@ class User extends BaseController
3323 3323
     public function new_sign_info()
3324 3324
     {
3325 3325
         $uid = $this->request->uid();
3326
-        $key = 'user_sign_score_' . $uid;
3327
-        if (Cache::get($key)) {
3328
-            $data = [
3329
-                'today' => 1,
3330
-                'day'   => 0
3331
-            ];
3332
-            return app('json')->success($data);
3333
-        }
3334
-
3335
-        $now = time();
3336
-        $todayEnd = strtotime('today 23:59:59');
3337
-        $remainingSeconds = $todayEnd - $now;
3338
-        Cache::set($key, 1, $remainingSeconds);
3339 3326
 
3340 3327
         // 查询今天是否已经签到
3341 3328
         $today_signin_info = Db::name('user_sign_score')->where(array('uid' => $uid))->whereDay('signin_time')->find();
@@ -3345,7 +3332,8 @@ class User extends BaseController
3345 3332
 
3346 3333
         $data = [
3347 3334
             'today' => 0,
3348
-            'day'   => 0
3335
+            'day'   => 0,
3336
+            'show' => 1
3349 3337
         ];
3350 3338
 
3351 3339
         if ($yes_signin_info) $data['day'] = (int)$yes_signin_info['continuity_day'];
@@ -3354,6 +3342,17 @@ class User extends BaseController
3354 3342
             $data['today'] = 1;
3355 3343
             $data['day'] = $data['day'] + 1;
3356 3344
         }
3345
+
3346
+        $key = 'user_sign_score_' . $uid;
3347
+        if (Cache::get($key)) {
3348
+            $data['show'] = 0;
3349
+        }
3350
+
3351
+        $now = time();
3352
+        $todayEnd = strtotime('today 23:59:59');
3353
+        $remainingSeconds = $todayEnd - $now;
3354
+        Cache::set($key, 1, $remainingSeconds);
3355
+
3357 3356
         return app('json')->success($data);
3358 3357
     }
3359 3358