Просмотр исходного кода

活动抽奖,开奖,一次开多个奖

lizhen_gitee 2 месяцев назад
Родитель
Сommit
7224e26a03
1 измененных файлов с 19 добавлено и 4 удалено
  1. 19 4
      application/api/controller/Active.php

+ 19 - 4
application/api/controller/Active.php

@@ -80,12 +80,27 @@ class Active extends Api
             $this->error('今天已开奖');
         }
 
-        //中奖号码。所有号码中随机拿个一,就一定会中奖
-        $box = Db::name('active_user_number')->whereTime('createtime','today')->column('number');
-        $gift_number = $box[rand(0,count($box)-1)];
+        //中奖号码组。
+        $box_count_config = [
+            1 => 1,
+            2 => 1,
+            3 => 2,
+            4 => 2,
+            5 => 3,
+            6 => 3,
+            7 => 4,
+        ];
+        $box_count = $box_count_config[date('N')];//今天开N个
+
+        //所有已存在的不重复号码,打乱之后,取前N个
+        $box = Db::name('active_user_number')->whereTime('createtime','today')->group('number')->column('number');
+        shuffle($box);
+        $box_count = $box_count > count($box) ? count($box) : $box_count;
+        $gift_number = array_chunk($box,$box_count)[0]; //中奖数组,不重复
+        $gift_number = implode(',',$gift_number);
 
         //中奖列表
-        $list = Db::name('active_user_number')->whereTime('createtime','today')->where('number',$gift_number)->select();
+        $list = Db::name('active_user_number')->whereTime('createtime','today')->where('number','IN',$gift_number)->select();
         $log_ids = array_column($list,'id');//id更新快一点
 
         //每股中奖额度