allen 3 år sedan
förälder
incheckning
c6856c9ce2
2 ändrade filer med 62 tillägg och 26 borttagningar
  1. 2 2
      app/admin/controller/Award.php
  2. 60 24
      app/index/controller/Index.php

+ 2 - 2
app/admin/controller/Award.php

@@ -40,7 +40,7 @@ class Award extends Controller
     left join awards_user_info as u on l.uid = u.uid 
     left join awards_order as o on o.uid = l.uid 
     left join awards_gift as g on o.gift_id = g.id
-where u.portrait != '' and u.portrait is not null  and l.duration > 15 group by l.uid order by l.number desc, l.duration asc, l.id asc limit 50");
+where u.portrait != '' and u.portrait is not null  and l.number >= 15 group by l.uid order by l.id desc limit 100");
         $this->assign('lists', $lists);
         $this->fetch();
     }
@@ -59,7 +59,7 @@ where u.portrait != '' and u.portrait is not null  and l.duration > 15 group by
     left join awards_user_info as u on l.uid = u.uid 
     left join awards_order as o on o.uid = l.uid 
     left join awards_gift as g on o.gift_id = g.id
-where u.portrait != '' and u.portrait is not null and l.duration > 15 group by l.uid order by l.number desc, l.duration asc, l.id asc limit 50");
+where u.portrait != '' and u.portrait is not null and l.number >= 15 group by l.uid order by l.id desc limit 100");
 
         //实例化
         $objExcel = new \PHPExcel();

+ 60 - 24
app/index/controller/Index.php

@@ -448,7 +448,7 @@ class Index extends Controller
     {
 
         $ranking = Db::query("select u.nickname, u.portrait, l.uid, l.duration, l.number from awards_user_task_log as l left join awards_user_info as u on l.uid = u.uid
-where u.portrait != '' and u.portrait is not null and l.duration > 15 group by l.uid order by l.number desc, l.duration asc, l.id asc limit 50");
+where u.portrait != '' and u.portrait is not null and l.number >= 15 group by l.uid order by l.id desc limit 100");
 
         $userInfo = Db::table('awards_user_task_log')->alias('l')
             ->leftJoin('awards_user_info u', 'l.uid = u.uid')
@@ -670,40 +670,76 @@ where u.portrait != '' and u.portrait is not null  and l.duration > 15 group by
         }
 
         $gifts = Db::table('awards_gift')->where('type', 1)->select();
-        $logCount = Db::table('awards_user_task_log')->distinct('uid')->count('id');
-
-        $limit = 5000;
-        $userRate = rand(0, $limit);
+//        $logCount = Db::table('awards_user_task_log')->distinct('uid')->count('id');
+
+        /**
+         * 活动专属周边礼包 id 4:中奖概率30%,每天中出去1个
+         * 电影票代金券 id 5:中奖概率40%,每天中出去2个
+         */
+        $rate = [4 => 30, 5 => 40];
+
+        /**
+         * 活动专属周边礼包 id 4:每天中出去1个
+         * 电影票代金券 id 5:每天中出去2个
+         */
+        $giftDayCount = [4 => 1, 5 => 2];
+
+        $limit = 100;
+        $userRate = rand(1, $limit);
         $giftId = 0;
+        $beginAt = strtotime(date('Y-m-d',time()));
+        $endAt = time();
         foreach ($gifts as $gift) {
-            $orderCount = Db::table('awards_order')->where('type', 1)->where('gift_id', $gift['id'])->count('id');
+
+            // 判断奖品库存
+            $orderCount = Db::table('awards_order')
+                ->where('type', 1)
+                ->where('gift_id', $gift['id'])
+                ->count('id');
             if ($orderCount >= $gift['count']) {
                 continue;
             }
 
-            // 如果参与活动人数 5000人内 有人中奖过,那么不在计算。
-            $total = $logCount + 1;
-            if ($orderCount == floor($total/$limit)) {
-                $isWinAward = 0;
-                $giftId = 0;
-                break;
-            }
-
-            for ($i=0;$i<$gift['count'];$i++) {
-                $giftRage = rand(0, $limit);
-                if ($userRate == $giftRage) {
-                    $isWinAward = 1;
-                    $giftId = $gift['id'];
-                    break;
-                }
+            // 判断奖品当天是否有中奖记录
+            $orderCount = Db::table('awards_order')
+                ->where('type', 1)
+                ->where('gift_id', $gift['id'])
+                ->where('create_at', '>=', $beginAt)
+                ->where('create_at', '<', $endAt)
+                ->count('id');
+            if ($orderCount >= $giftDayCount[$gift['id']]) {
+                continue;
             }
 
-            // 如果参与活动人数 5000人内 还没有人中奖那最后一人必中。
-            if ($orderCount < floor($total/$limit) && $isWinAward ==0 && ($total%$limit) == 0) {
+            // 判断是否中奖
+            if ($userRate <= $rate[$gift['id']]) {
                 $isWinAward = 1;
                 $giftId = $gift['id'];
-                break;
             }
+
+            // 如果参与活动人数 5000人内 有人中奖过,那么不在计算。
+//            $total = $logCount + 1;
+//            if ($orderCount == floor($total/$limit)) {
+//                $isWinAward = 0;
+//                $giftId = 0;
+//                break;
+//            }
+//
+//            for ($i=0;$i<$gift['count'];$i++) {
+//                $giftRage = rand(0, $limit);
+//                if ($userRate == $giftRage) {
+//                    $isWinAward = 1;
+//                    $giftId = $gift['id'];
+//                    break;
+//                }
+//            }
+//
+//            // 如果参与活动人数 5000人内 还没有人中奖那最后一人必中。
+//            if ($orderCount < floor($total/$limit) && $isWinAward ==0 && ($total%$limit) == 0) {
+//                $isWinAward = 1;
+//                $giftId = $gift['id'];
+//                break;
+//            }
         }
 
         // 如果中奖 插入用户中奖信息