|
@@ -29,7 +29,7 @@ class Eggnew extends Api
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 查找下一个奖池
|
|
|
+ * 查找下一个奖池ID
|
|
|
*/
|
|
|
private function getNextJackpot($jackpot_id) {
|
|
|
$type = \app\common\model\EggJackpot::where(['id'=>$jackpot_id])->value('type');
|
|
@@ -50,7 +50,7 @@ class Eggnew extends Api
|
|
|
public function strike() {
|
|
|
// $this->error("系统正在维护中。。。");
|
|
|
|
|
|
- $num = $this->request->request("num");
|
|
|
+ $num = $this->request->request("num");
|
|
|
$type = $this->request->request("type",1);
|
|
|
$party_id = $this->request->request("party_id", 0);// 派对ID
|
|
|
if($num <=0) {
|
|
@@ -73,18 +73,18 @@ class Eggnew extends Api
|
|
|
Db::startTrans();
|
|
|
try{
|
|
|
// 查找正在开放的奖池
|
|
|
- $jackpot = \app\common\model\EggJackpot::where(["status"=>1,'type'=>$type])->find();
|
|
|
+ $jackpot = \app\common\model\EggJackpot::where(["status"=>1,'type'=>$type])->order('weigh asc,id asc')->find();
|
|
|
if($jackpot) { // 有开放的奖池
|
|
|
-// \app\common\model\EggJackpot::order("id","asc")->find();
|
|
|
$jackpot_id = $jackpot["id"];
|
|
|
} else { // 没有开放的奖池
|
|
|
- $jackpotInfo = \app\common\model\EggJackpot::where('type',$type)->order('weigh asc,id asc')->find();
|
|
|
- if(!empty($jackpotInfo)){
|
|
|
+ $jackpot = \app\common\model\EggJackpot::where('type',$type)->order('weigh asc,id asc')->find();
|
|
|
+ if(empty($jackpot)){
|
|
|
Db::rollback();
|
|
|
$this->error('暂时还没有奖池');
|
|
|
}
|
|
|
- $jackpot_id = $jackpotInfo["id"];
|
|
|
+ $jackpot_id = $jackpot["id"];
|
|
|
\app\common\model\EggJackpot::update(["status"=>1],["id"=>$jackpot_id]);//打开
|
|
|
+ \app\common\model\EggGift::update(["is_use"=>0],["Jackpot_id"=>$jackpot_id]);//重置礼物
|
|
|
}
|
|
|
|
|
|
// 查找奖池对应的奖池礼物
|
|
@@ -93,14 +93,13 @@ class Eggnew extends Api
|
|
|
$giftCount = count($jackpotGift);
|
|
|
$next_jackpot_id = $this->getNextJackpot($jackpot_id);
|
|
|
|
|
|
- if($giftCount <= $num) {
|
|
|
+ if($giftCount <= $num) { //当前奖池已不足,或需要启用下一池
|
|
|
// 先获取$giftCount个礼物
|
|
|
$giftArr1 = $jackpotGift;
|
|
|
|
|
|
// 更新礼物抽取状态
|
|
|
$giftids = array_column($giftArr1,"id");
|
|
|
$res1 = \app\common\model\EggGift::update(["is_use"=>1],["id"=>["in",$giftids]]);
|
|
|
-// $res1Info = \app\common\model\EggGift::where(["id"=>["in",$giftids]])->select();
|
|
|
|
|
|
|
|
|
// 更新奖池
|
|
@@ -111,28 +110,16 @@ class Eggnew extends Api
|
|
|
$res4 = \app\common\model\EggGift::update(["is_use"=>0],["Jackpot_id"=>$next_jackpot_id]);
|
|
|
|
|
|
// 获取下个奖池礼物
|
|
|
- $nextjackpotGift = \app\common\model\EggGift::where(["Jackpot_id"=>$next_jackpot_id])->select();
|
|
|
+ $nextjackpotGift = \app\common\model\EggGift::where(["Jackpot_id"=>$next_jackpot_id,"is_use"=>0])->select();
|
|
|
|
|
|
$newnum = $num-$giftCount;
|
|
|
|
|
|
if($newnum == 0) {
|
|
|
- /*
|
|
|
- $giftArr = [];
|
|
|
- foreach($nextjackpotGift as $k => $v) $giftArr[$v["id"]] = $v;
|
|
|
|
|
|
- if(!$giftArr) $this->error("奖池礼物待更新,请耐心等待!");
|
|
|
-
|
|
|
- $giftids = array_rand($giftArr,50);
|
|
|
-
|
|
|
- // 更新礼物抽取状态
|
|
|
- \app\common\model\EggGift::where(["id"=>["in",$giftids]])->select();
|
|
|
-
|
|
|
- $res5 = \app\common\model\EggGift::update(["updatetime"=>time()],["id"=>["in",$giftids]]);
|
|
|
- */
|
|
|
$res5 = true;
|
|
|
$giftdata = $giftArr1;
|
|
|
} else {
|
|
|
- if($newnum > count($nextjackpotGift)){
|
|
|
+ if($newnum > count($nextjackpotGift)){ //需要开启下下个奖池
|
|
|
Db::rollback();
|
|
|
$this->error("奖池礼物待更新,请耐心等待!");
|
|
|
}
|
|
@@ -155,6 +142,9 @@ class Eggnew extends Api
|
|
|
$giftdata = array_merge($giftArr1,$res5Info);
|
|
|
}
|
|
|
|
|
|
+ //在这里记录奖池产出统计
|
|
|
+ //在这里记录奖池产出统计
|
|
|
+
|
|
|
} else {
|
|
|
// 随机抽取$num个礼物
|
|
|
$giftArr = [];
|
|
@@ -165,31 +155,7 @@ class Eggnew extends Api
|
|
|
$res1 = \app\common\model\EggGift::update(["is_use"=>1],["id"=>["in",$giftids]]);
|
|
|
$res1Info = \app\common\model\EggGift::where(["id"=>["in",$giftids]])->select();
|
|
|
|
|
|
-/*
|
|
|
- // ------------------ 附加逻辑开始 ---------------------//
|
|
|
- // 更新奖池
|
|
|
- $res2 = \app\common\model\EggJackpot::update(["updatetime"=>time()],["tes"=>1]);
|
|
|
- $res3 = \app\common\model\EggJackpot::update(["updatetime"=>time()],["id"=>$next_jackpot_id]);
|
|
|
|
|
|
- // 下个奖池所有礼物改为未使用
|
|
|
- $res4 = \app\common\model\EggGift::update(["updatetime"=>time()],["Jackpot_id"=>$next_jackpot_id]);
|
|
|
- // 获取下个奖池礼物
|
|
|
- $nextjackpotGift = \app\common\model\EggGift::where(["Jackpot_id"=>$next_jackpot_id])->select();
|
|
|
-
|
|
|
- $giftArr = [];
|
|
|
- foreach($nextjackpotGift as $k => $v) $giftArr[$v["id"]] = $v;
|
|
|
-
|
|
|
- if(!$giftArr) $this->error("奖池礼物待更新,请耐心等待!");
|
|
|
-
|
|
|
- $giftids = array_rand($giftArr,50);
|
|
|
-
|
|
|
- // 更新礼物抽取状态
|
|
|
- \app\common\model\EggGift::where(["id"=>["in",$giftids]])->select();
|
|
|
-
|
|
|
- $res5 = \app\common\model\EggGift::update(["updatetime"=>time()],["id"=>["in",$giftids]]);
|
|
|
-
|
|
|
- // ------------------ 附加逻辑结束 ---------------------//
|
|
|
-*/
|
|
|
$res2 = true;
|
|
|
$res3 = true;
|
|
|
$res4 = true;
|
|
@@ -235,8 +201,6 @@ class Eggnew extends Api
|
|
|
];
|
|
|
}
|
|
|
$data && $res5 = \app\common\model\EggDo::insertAll($data);
|
|
|
- // 扣除用户小锤子
|
|
|
- $res6 = true;
|
|
|
|
|
|
// 添加到用户背包
|
|
|
$backdata && $res7 = \app\common\model\GiftBack::insertAll($backdata);
|
|
@@ -248,19 +212,9 @@ class Eggnew extends Api
|
|
|
Db::rollback();
|
|
|
}
|
|
|
|
|
|
- if($res1 !== false && $res2 !== false && $res3 !== false && $res4 !== false && $res5 !== false && $res6 && $res7) {
|
|
|
+ if($res1 !== false && $res2 !== false && $res3 !== false && $res4 !== false && $res5 !== false && $res7 !== false) {
|
|
|
Db::commit();
|
|
|
- /*$eggStrikeNotice = config("site.eggStrikeNotice");
|
|
|
- if($party_id){
|
|
|
- $partyInfo = \app\common\model\Party::field("id,room_type,party_name")->where(["id"=>$party_id])->find();
|
|
|
- foreach ($backdata as $backdatum) {
|
|
|
- $realMoney = $backdatum['value'] / 100;
|
|
|
- if ($realMoney >= $eggStrikeNotice){
|
|
|
- $giftUserParty = ['number'=>$backdatum['number'],'gift_name'=>$backdatum['name'],'gift_gif_image'=>$backdatum['image']];
|
|
|
- QueueApi::sendGroupMessage(73, '', $this->auth->nickname, $partyInfo, $giftUserParty);
|
|
|
- }
|
|
|
- }
|
|
|
- }*/
|
|
|
+
|
|
|
} else {
|
|
|
Db::rollback();
|
|
|
$this->error('开奖失败');
|