Browse Source

奖池产出

lizhen_gitee 1 year ago
parent
commit
3dd9116cff
1 changed files with 36 additions and 6 deletions
  1. 36 6
      application/api/controller/Eggnew.php

+ 36 - 6
application/api/controller/Eggnew.php

@@ -67,17 +67,17 @@ class Eggnew extends Api
 
 
         $do_no = createUniqueNo('E',$user_id);
-
+        $jockpot_finish = 0; //产出统计
 
 
         Db::startTrans();
         try{
             // 查找正在开放的奖池
-            $jackpot = \app\common\model\EggJackpot::where(["status"=>1,'type'=>$type])->order('weigh asc,id asc')->find();
+            $jackpot = \app\common\model\EggJackpot::where(["status"=>1,'type'=>$type])->order('weigh asc,id asc')->lock(true)->find();
             if($jackpot) { // 有开放的奖池
                 $jackpot_id = $jackpot["id"];
             } else { // 没有开放的奖池
-                $jackpot = \app\common\model\EggJackpot::where('type',$type)->order('weigh asc,id asc')->find();
+                $jackpot = \app\common\model\EggJackpot::where('type',$type)->order('weigh asc,id asc')->lock(true)->find();
                 if(empty($jackpot)){
                     Db::rollback();
                     $this->error('暂时还没有奖池');
@@ -85,6 +85,10 @@ class Eggnew extends Api
                 $jackpot_id = $jackpot["id"];
                 \app\common\model\EggJackpot::update(["status"=>1,'starttime'=>$nowtime],["id"=>$jackpot_id]);//打开,启用时间
                 \app\common\model\EggGift::update(["is_use"=>0,'starttime'=>$nowtime],["Jackpot_id"=>$jackpot_id]);//重置礼物,启用时间
+
+                //省的再查一次
+                $jackpot['status'] = 1;
+                $jackpot['starttime'] = $nowtime;
             }
 
             // 查找奖池对应的奖池礼物
@@ -142,9 +146,8 @@ class Eggnew extends Api
                     $giftdata = array_merge($giftArr1,$res5Info);
                 }
 
-                //在这里记录奖池产出统计,老一轮的奖池已经消耗完毕
-
-                //在这里记录奖池产出统计
+                //产出统计,在这里记录奖池产出统计,老一轮的奖池已经消耗完毕
+                $jockpot_finish = 1;
 
             } else {
                 // 随机抽取$num个礼物
@@ -215,6 +218,33 @@ class Eggnew extends Api
                 Db::rollback();
             }
 
+            //每一期奖池的产出统计
+            if($jockpot_finish == 1){
+                $jackpot_chanchu = [
+                    //奖池的
+                    'jp_giftnum'   => Db::name('egg_gift')->where('Jackpot_id',$jackpot_id)->count(), //总礼物数量
+                    'jp_giftprice' => Db::name('egg_gift')->where('Jackpot_id',$jackpot_id)->sum('price'), //总礼物价值
+                    //抽奖的
+                    'do_payfee'    => Db::name('egg_do')->where('Jackpot_id',$jackpot_id)->where('starttime',$jackpot['starttime'])->sum('pay_fee'), //物抽总礼奖费用
+                    'do_usercount' => Db::name('egg_do')->where('Jackpot_id',$jackpot_id)->where('starttime',$jackpot['starttime'])->group('user_id')->count('id'),//抽奖总人数
+                    'do_usertimes' => Db::name('egg_do')->where('Jackpot_id',$jackpot_id)->where('starttime',$jackpot['starttime'])->group('do_no')->count('id'),//抽奖总次数
+                    'do_giftnum'   => Db::name('egg_do')->where('Jackpot_id',$jackpot_id)->where('starttime',$jackpot['starttime'])->count('id'),//抽奖总礼物数量
+                    'do_giftprice' => Db::name('egg_do')->where('Jackpot_id',$jackpot_id)->where('starttime',$jackpot['starttime'])->sum('price'),//抽奖总礼物价值
+
+                    //基础信息
+                    'jackpot_id' => $jackpot_id,
+                    'starttime'  => $jackpot['starttime'],
+                    'createtime' => time(),
+                ];
+                //产出比
+                $jackpot_chanchu['chanchu'] = bidiv($jackpot_chanchu['do_giftprice'],$jackpot_chanchu['jp_giftprice'],2);
+                $rs_chanchu = Db::name('egg_jackpot_chanchu')->insertGetId($jackpot_chanchu);
+                if(!$rs_chanchu){
+                    Db::rollback();
+                    $this->error('开奖失败');
+                }
+            }
+
             if($res1 !== false && $res2 !== false && $res3 !== false && $res4 !== false && $res5 !== false && $res7 !== false) {
                 Db::commit();