Browse Source

抽奖修改

lizhen_gitee 1 year ago
parent
commit
c7f52eeae5
1 changed files with 8 additions and 22 deletions
  1. 8 22
      application/api/controller/Eggnew.php

+ 8 - 22
application/api/controller/Eggnew.php

@@ -51,6 +51,7 @@ class Eggnew extends Api
 //        $this->error("系统正在维护中。。。");
 
         $num = $this->request->request("num");
+        $type = $this->request->request("type",1);
         $party_id = $this->request->request("party_id", 0);// 派对ID
         if($num <=0) {
             $this->error("参数错误");
@@ -68,42 +69,27 @@ class Eggnew extends Api
         if($redisconfig['redis_selectdb'] > 0){
             $redis->select($redisconfig['redis_selectdb']);
         }
-//        if($redis->lLen("hammer_num_".$user_id) < $num) $this->error("小金锤数量不足!");
+
 
         $do_no = date("YmdHis").rand(10000,99999);
-        $userinfo = \app\common\model\User::lock(true)->find($this->auth->id);
-        if($userinfo->hammer < $num) {
-            $this->error("小金锤数量不足!");
-        }
 
-        for($i=1;$i<=$num;$i++) { // 扣除
-            $redis->lpop("hammer_num_".$user_id);
-        }
+
 
         Db::startTrans();
         try{
             // 查找正在开放的奖池
-            $jackpot = \app\common\model\EggJackpot::where(["status"=>1])->find();
+            $jackpot = \app\common\model\EggJackpot::where(["status"=>1,'type'=>$type])->find();
             if($jackpot) { // 有开放的奖池
-                \app\common\model\EggJackpot::order("id","asc")->find();
+
                 $jackpot_id = $jackpot["id"];
             } else { // 没有开放的奖池
-                $jackpotInfo = \app\common\model\EggJackpot::order("id","asc")->find();
+                $jackpotInfo = \app\common\model\EggJackpot::where('type',$type)->order('weigh asc,id asc')->find();
                 $jackpot_id = $jackpotInfo["id"];
-                \app\common\model\EggJackpot::update(["status"=>1],["id"=>$jackpot_id]);
+                \app\common\model\EggJackpot::update(["status"=>1],["id"=>$jackpot_id]);//打开
             }
 
-            $currentNotUsedWhere = [];
-            if (in_array($num, [1, 10])) {
-                // 砸一锤 最大出11111,砸十锤 最大出88888, 奖池数不够时不受限制
-                $priceSection = $num == 1 ? '11111' : '88888';
-                $currentNotUsedCount = \app\common\model\EggGift::where(["Jackpot_id" => $jackpot_id, "is_use" => 0])->where('price', '<=', $priceSection)->count();
-                if ($currentNotUsedCount >= $num) {
-                    $currentNotUsedWhere['price'] = ['<=', $priceSection];
-                }
-            }
             // 查找奖池对应的奖池礼物
-            $jackpotGift = \app\common\model\EggGift::where(["Jackpot_id"=>$jackpot_id,"is_use"=>0])->where($currentNotUsedWhere)->select();
+            $jackpotGift = \app\common\model\EggGift::where(["Jackpot_id"=>$jackpot_id,"is_use"=>0])->select();
 
             $giftCount = count($jackpotGift);
             $next_jackpot_id = $this->getNextJackpot($jackpot_id);