allen 3 jaren geleden
bovenliggende
commit
2fb61bca5e
2 gewijzigde bestanden met toevoegingen van 212 en 26 verwijderingen
  1. 211 25
      app/index/controller/Index.php
  2. 1 1
      app/index/controller/Video.php

+ 211 - 25
app/index/controller/Index.php

@@ -186,31 +186,31 @@ class Index extends Controller
 
 //        $duration = Safe::$body['duration'];
 //        $number = Safe::$body['number'];
-        $duration = Request::post("duration");
-        $number = Request::post("number");
-
-        $date = date('Y-m-d');
-
-        $userInfo = Db::table('awards_user_info')->where('uid', Safe::$user['uid'])->find();
-        if (empty($userInfo)) {
-            return $this->response(403, '没有登录');
-        }
-
-        $count = Db::table('awards_user_task_log')->where('uid', Safe::$user['uid'])->count('id');
-        if ($count >= $userInfo['count']) {
-            return $this->response(5002, '没有参与次数');
-        }
-
-        $log = [
-            'uid' => Safe::$user['uid'],
-            'date' => $date,
-            'duration' => $duration,
-            'number' => $number,
-            'create_at' => time()
-        ];
-        if (0 == Db::table('awards_user_task_log')->insert($log)) {
-            return $this->response(5001, '系统错误,请稍后再试~');
-        }
+//        $duration = Request::post("duration");
+//        $number = Request::post("number");
+//
+//        $date = date('Y-m-d');
+//
+//        $userInfo = Db::table('awards_user_info')->where('uid', Safe::$user['uid'])->find();
+//        if (empty($userInfo)) {
+//            return $this->response(403, '没有登录');
+//        }
+//
+//        $count = Db::table('awards_user_task_log')->where('uid', Safe::$user['uid'])->count('id');
+//        if ($count >= $userInfo['count']) {
+//            return $this->response(5002, '没有参与次数');
+//        }
+//
+//        $log = [
+//            'uid' => Safe::$user['uid'],
+//            'date' => $date,
+//            'duration' => $duration,
+//            'number' => $number,
+//            'create_at' => time()
+//        ];
+//        if (0 == Db::table('awards_user_task_log')->insert($log)) {
+//            return $this->response(5001, '系统错误,请稍后再试~');
+//        }
 
         return $this->successResponse(null, '提交成功');
     }
@@ -255,6 +255,192 @@ class Index extends Controller
         }
     }
 
+    public function startGame()
+    {
+        $activity = Db::table('awards_activity')->where('begin_at', '<=', time())
+            ->where('end_at', '>=', time())->find();
+        if (empty($activity)) {
+            return $this->response(5002, '活动末开始');
+        }
+
+        $userInfo = Db::table('awards_user_info')->where('uid', Safe::$user['uid'])->find();
+        if (empty($userInfo)) {
+            return $this->response(403, '没有登录');
+        }
+
+        $count = Db::table('awards_user_task_log')->where('uid', Safe::$user['uid'])->count('id');
+        if ($count >= $userInfo['count']) {
+            return $this->response(5002, '没有参与次数');
+        }
+
+        $game = Db::table('awards_user_game')
+            ->where('uid', '=', Safe::$user['uid'])
+            ->where('state', '=', 1)
+            ->find();
+        if (!empty($game)) {
+            Db::table('awards_user_game')->where('id', '=', $game['id'])->delete(true);
+        }
+
+        $gameId = $this->uuid();
+        $attr = [
+            'game_id' => $gameId,
+            'uid' => Safe::$user['uid'],
+            'begin_at' => time(),
+            'end_at' => 0,
+            'state' => 1,
+            'create_at' => time()
+        ];
+
+        Db::table('awards_user_game')->insert($attr);
+
+        return $this->successResponse(['gameId' => $gameId], '开始游戏成功');
+    }
+
+    public function endGame()
+    {
+        $activity = Db::table('awards_activity')->where('begin_at', '<=', time())
+            ->where('end_at', '>=', time())->find();
+        if (empty($activity)) {
+            return $this->response(5002, '活动末开始');
+        }
+
+        $userInfo = Db::table('awards_user_info')->where('uid', Safe::$user['uid'])->find();
+        if (empty($userInfo)) {
+            return $this->response(403, '没有登录');
+        }
+
+        $gameId = Request::post("gameId");
+        $game = Db::table('awards_user_game')
+            ->where('uid', '=', Safe::$user['uid'])
+            ->where('game_id', '=', $gameId)
+            ->where('state', '=', 1)
+            ->find();
+        if (empty($game)) {
+            return $this->response(6001, '游戏不存在');
+        }
+
+        if((time() - $game['begin_at']) > 122 || (time() - $game['begin_at']) < 13) {
+            return $this->response(6003, '游戏参数有误');
+        }
+
+        $endAt = time();
+
+        $duration = $endAt - $game['begin_at'];
+        if($duration < 14) {
+            return $this->response(6001, '游戏有误');
+        }
+
+        Db::table('awards_user_game')->where('game_id', '=', $gameId)->update([
+            'end_at' => $endAt,
+            'state' => 2,
+            'update_at' => time()
+        ]);
+
+        $count = Db::table('awards_user_task_log')->where('uid', Safe::$user['uid'])->count('id');
+        if ($count >= $userInfo['count']) {
+            return $this->response(5002, '没有参与次数');
+        }
+
+        $number = Db::table('awards_user_game_log')
+            ->where('uid', '=', Safe::$user['uid'])
+            ->where('game_id', '=', $gameId)
+            ->count('id');
+
+        $date = date('Y-m-d');
+        $log = [
+            'uid' => Safe::$user['uid'],
+            'date' => $date,
+            'duration' => $duration,
+            'number' => $number,
+            'create_at' => time()
+        ];
+        Db::table('awards_user_task_log')->insert($log);
+
+        return $this->successResponse(null, '提交成功');
+    }
+
+    public function submitEasterEgg()
+    {
+        $easterEgg = Request::post("easterEgg");
+        if (!in_array($easterEgg, [1, 2, 3,4 ,5 ,6,7, 8, 9, 10, 11, 12, 13, 14, 15])) {
+            return $this->response(6003, '游戏参数有误');
+        }
+
+        $activity = Db::table('awards_activity')->where('begin_at', '<=', time())
+            ->where('end_at', '>=', time())->find();
+        if (empty($activity)) {
+            return $this->response(5002, '活动末开始');
+        }
+
+        $userInfo = Db::table('awards_user_info')->where('uid', Safe::$user['uid'])->find();
+        if (empty($userInfo)) {
+            return $this->response(403, '没有登录');
+        }
+
+
+        $gameId = Request::post("gameId");
+
+        $game = Db::table('awards_user_game')
+            ->where('uid', '=', Safe::$user['uid'])
+            ->where('game_id', '=', $gameId)
+            ->where('state', '=', 1)
+            ->find();
+        if (empty($game)) {
+            return $this->response(6001, '游戏不存在');
+        }
+
+        if((time() - $game['begin_at']) > 120) {
+            return $this->response(6003, '游戏已结束');
+        }
+
+        $log = Db::table('awards_user_game_log')
+            ->where('uid', '=', Safe::$user['uid'])
+            ->where('game_id', '=', $gameId)
+            ->where('draw', '=', $easterEgg)
+            ->find();
+        if (!empty($log)) {
+            return $this->successResponse(null, '提交成功');
+        }
+
+        $log = Db::table('awards_user_game_log')
+            ->where('uid', '=', Safe::$user['uid'])
+            ->where('game_id', '=', $gameId)
+            ->order('create_at', 'desc')
+            ->find();
+        if (empty($log)) {
+            $startTime = $game['begin_at'];
+        } else {
+            $startTime = $log['create_at'];
+        }
+
+        $duration = time() - $startTime;
+        if ($duration < 0) {
+            return $this->response(6002, '游戏参数有误');
+        }
+
+        $attr = [
+            'uid' => Safe::$user['uid'],
+            'game_id' => $gameId,
+            'draw' => $easterEgg,
+            'duration' => $duration,
+            'create_at' => time()
+        ];
+        Db::table('awards_user_game_log')->insert($attr);
+
+        return $this->successResponse(null, '提交成功');
+    }
+
+    function uuid()
+    {
+        $chars = md5(uniqid(mt_rand(), true));
+        $uuid = substr ( $chars, 0, 8 )
+            . substr ( $chars, 8, 4 )
+            . substr ( $chars, 12, 4 )
+            . substr ( $chars, 16, 4 )
+            . substr ( $chars, 20, 12 );
+        return $uuid ;
+    }
+
     /**
      * 头号排行接口
      * @throws FuncNotFoundException

+ 1 - 1
app/index/controller/Video.php

@@ -62,7 +62,7 @@ class Video extends Controller
                 'portrait' => $user['profile_image_url'],
                 'nickname' => $user['name'],
                 'is_share' => 0,
-                'count' => 1,
+                'count' => 3,
                 'create_at' => time()
             ];
             Db::table('awards_user_info')->insert($userAttr);