diff --git a/application/api/controller/BlindBoxTurntable.php b/application/api/controller/BlindBoxTurntable.php index c64e302..91793f6 100644 --- a/application/api/controller/BlindBoxTurntable.php +++ b/application/api/controller/BlindBoxTurntable.php @@ -91,4 +91,25 @@ class BlindBoxTurntable extends BaseCom $reslut = model('BlindBoxTurntableGift')->xlh_draw_gift($user_id,$num,$room_id); return v($reslut['code'], $reslut['msg'], $reslut['data']); } + /* + * 获取我的巡乐会记录 + */ + public function get_xlh_my_record(){ + $page = input('page',1); + $page_size = input('page_size',12); + $user_id = $this->uid; + $room_id = input('room_id',0); + $reslut = model('BlindBoxTurntableGift')->xlh_get_user_record($user_id,$room_id,$page,$page_size); + return v($reslut['code'], $reslut['msg'], $reslut['data']); + } + /* + * 获取全服巡乐会记录(榜单) + */ + public function get_xlh_all_record(){ + $page = input('page',1); + $page_size = input('page_size',12); + $room_id = input('room_id',0); + $reslut = model('BlindBoxTurntableGift')->xlh_ranking($room_id,$page,$page_size); + return v($reslut['code'], $reslut['msg'], $reslut['data']); + } } \ No newline at end of file diff --git a/application/api/controller/Cron.php b/application/api/controller/Cron.php index ef881dc..0dcafaf 100644 --- a/application/api/controller/Cron.php +++ b/application/api/controller/Cron.php @@ -9,6 +9,9 @@ class Cron { $cron = new \app\cron\controller\PerformPerSecond(); $cron->index(); + //巡乐会结束 礼物发放 + $cron = new \app\cron\controller\RoomPan(); + $cron->index(); } //每周执行 @@ -31,4 +34,10 @@ class Cron $cron = new \app\cron\controller\DaySeconds(); $cron->index(); } + + //巡乐会结束 礼物发放 + public function XlhSend(){ + $cron = new \app\cron\controller\RoomPan(); + $cron->index(); + } } \ No newline at end of file diff --git a/application/api/model/BlindBoxTurntableGift.php b/application/api/model/BlindBoxTurntableGift.php index 34bfcac..2dbccb7 100644 --- a/application/api/model/BlindBoxTurntableGift.php +++ b/application/api/model/BlindBoxTurntableGift.php @@ -310,15 +310,15 @@ class BlindBoxTurntableGift extends Model return ['code' => 0, 'msg' => '开奖数据不存在','data' => null]; } //获取盲盒配置 - $bag_data = db::name("vs_gift_bag")->field('id,name,ext,periods')->where('id',$blind_box_turntable['gift_bag_id'])->find(); - $ext = json_decode($bag_data['ext'],true); +// $bag_data = db::name("vs_gift_bag")->field('id,name,ext,periods')->where('id',$blind_box_turntable['gift_bag_id'])->find(); +// $ext = json_decode($bag_data['ext'],true); foreach ($blind_box_turntable_log as $key => $value) { $give_gift_ext['gift_id'] = $value['gift_id']; $give_gift_ext['count'] = $value['count']; $give_gift_ext['gift_price'] = $value['gift_price']; $give_gift_ext['all_gift_price'] = $value['all_gift_price']; $give_gift_ext['is_draw_gift'] = 1; - $res = model('GiveGift')->give_gift($blind_box_turntable['user_id'], $value['gift_user_id'], $ext['gift_id'], $value['count'],2,1, $blind_box_turntable['room_id'],0,0,$give_gift_ext); + $res = model('GiveGift')->give_gift($blind_box_turntable['user_id'], $value['gift_user_id'], $value['gift_id'], $value['count'],2,1, $blind_box_turntable['room_id'],0,0,$give_gift_ext); if (isset($res) && $res['code'] != 1) { return V(0, $res['msg']); } @@ -455,6 +455,10 @@ class BlindBoxTurntableGift extends Model return ['code' => 0, 'msg' => '该房间未开启盲盒转盘', 'data' => null]; } //开始抽奖 + $pan_xlh = db::name('vs_room_pan_xlh')->where(['room_id'=>$room_id,'periods'=>$room['blind_box_turntable_periods']])->find(); + if(empty($pan_xlh)){ + return ['code' => 0, 'msg' => '未开始', 'data' => null]; + } for($i = 0; $i < $num; $i++){ //随机获取一个礼物 $where = [ @@ -510,40 +514,24 @@ class BlindBoxTurntableGift extends Model //处理抽中礼物命中主奖品逻辑 if($gift_bag_detail['foreign_id'] == $ext['locking_condition']['selected_gift_id']){ //中奖 - $pan_xlh = db::name('vs_room_pan_xlh')->where(['room_id'=>$room_id,'periods'=>$room['blind_box_turntable_periods']])->find(); - if($pan_xlh){ - db::name('vs_room_pan_xlh')->where('id',$pan_xlh['id'])->update([ - 'user_id' => $user_id, - 'num' => $pan_xlh['num'] + 1, - ]); - if($pan_xlh['num'] == 0){ - $end_time = time() + $ext['locking_time']['tow_no_locking_time'] * 60; - }else{ - $end_time = time() + ($ext['locking_time']['tow_no_locking_time']-$ext['locking_time']['next_time']) * 60; - } - db::name('vs_room_pan_xlh_log')->insertGetId([ - 'xlh_id' => $pan_xlh['id'], - 'user_id' => $user_id, - 'num' => isset($pan_xlh['num']) ? $pan_xlh['num']+1 : 1, - 'locking_end_time' => $end_time, - 'createtime' => time() - ]); + if($pan_xlh['num'] == 0){ + $end_time = time() + $ext['locking_time']['tow_no_locking_time'] * 60; + }else{ + $end_time = time() + ($ext['locking_time']['tow_no_locking_time']-$ext['locking_time']['next_time']) * 60; } - } - //处理礼包发放记录表 - $data = []; - $data['user_id'] = $user_id; - $data['parent_id'] = 0; - $data['gift_bag_id'] = $gift_bag_id; - $data['gift_id'] = $gift_bag_detail['foreign_id']; - $data['periods'] = $room['blind_box_turntable_periods']; - $data['room_id'] = $room_id; - $data['gift_price'] = $gift['gift_price']; - $data['bag_price'] = $ext['xlh_box_price']; - $data['createtime'] = time(); - $result = db::name("vs_gift_bag_receive_log")->insert($data); - if(!$result){ - return ['code' => 0, 'msg' => '失败,', 'data' => []]; + db::name('vs_room_pan_xlh')->where('id',$pan_xlh['id'])->update([ + 'user_id' => $user_id, + 'num' => $pan_xlh['num'] + 1, + 'end_time' => $end_time, + 'updatetime' => time() + ]); + db::name('vs_room_pan_xlh_log')->insertGetId([ + 'xlh_id' => $pan_xlh['id'], + 'user_id' => $user_id, + 'num' => isset($pan_xlh['num']) ? $pan_xlh['num']+1 : 1, + 'locking_end_time' => $end_time, + 'createtime' => time() + ]); } //减去盲盒包礼物数量 $ret = db::name("vs_room_pan")->where(['room_id'=>$room_id,'gift_bag_detail_id'=>$gift_bag_detail['id']])->setDec('remaining_number',1); @@ -566,6 +554,37 @@ class BlindBoxTurntableGift extends Model 'is_public_screen'=>$gift['is_public_screen'], ]; } + $reslut_data = []; + foreach ($result_data as $key => $value) { + $gift_id = $value['gift_id']; + if (!isset($reslut_data[$gift_id])) { + $reslut_data[$gift_id] = [ + 'gift_id' => $gift_id, + 'gift_price'=>$value['gift_price'], + 'count' => 1 + ]; + }else { + $reslut_data[$gift_id]['count']++; + } + } + foreach ($reslut_data as $key => $value) { + //处理礼包发放记录表 + $data = []; + $data['user_id'] = $user_id; + $data['parent_id'] = $pan_xlh['id']; + $data['gift_bag_id'] = $gift_bag_id; + $data['gift_id'] = $value['gift_id']; + $data['periods'] = $room['blind_box_turntable_periods']; + $data['room_id'] = $room_id; + $data['num'] = $value['count']; + $data['gift_price'] = $value['gift_price']; + $data['bag_price'] = $ext['xlh_box_price']; + $data['createtime'] = time(); + $result = db::name("vs_gift_bag_receive_log")->insert($data); + if(!$result){ + return ['code' => 0, 'msg' => '失败,', 'data' => []]; + } + } // 添加活动记录 $reslut = Db::name('vs_activities_receive')->insert([ 'user_id' => $user_id, @@ -576,4 +595,50 @@ class BlindBoxTurntableGift extends Model ]); return ['code' => 1, 'msg' => '成功', 'data' => $result_data]; } + + /* + * 巡乐会抽奖记录 + */ + public function xlh_get_user_record($user_id,$room_id,$page=1,$page_size=12){ + $where = []; + $where['a.gift_bag_id'] = 13; + $where['a.user_id'] = $user_id; + $where['a.room_id'] = $room_id; + $list = db('vs_gift_bag_receive_log') + ->alias('a') + ->join('vs_room_pan_xlh b','b.id = a.parent_id','left') + ->join('vs_gift c','c.gid = a.gift_id','left') + ->field('a.gift_id,a.num,b.createtime,c.gift_name as gift_name,c.base_image') + ->where($where) + ->page($page,$page_size) + ->select(); + foreach ($list as &$v){ + $v['createtime'] = date('Y-m-d H:i:s',$v['createtime']); + } + return ['code' => 1, 'msg' => '成功', 'data' => $list]; + } + + /* + * 巡乐会榜单 + */ + public function xlh_ranking($room_id,$page=1,$page_size=12){ + $where = []; + $where['a.gift_bag_id'] = 13; + $where['a.room_id'] = $room_id; + $where['e.is_world_show'] = 1; + $list = db('vs_gift_bag_receive_log') + ->alias('a') + ->join('vs_room_pan_xlh b','b.id = a.parent_id','left') + ->join('vs_gift c','c.gid = a.gift_id','left') + ->join('fa_user d','d.id = a.user_id','left') + ->join('vs_gift_bag_detail e','e.foreign_id = a.gift_id','left') + ->field('a.gift_id,a.num,b.createtime,c.gift_name as gift_name,c.base_image,d.nickname') + ->where($where) + ->page($page,$page_size) + ->select(); + foreach ($list as &$v){ + $v['createtime'] = date('Y-m-d H:i:s',$v['createtime']); + } + return ['code' => 1, 'msg' => '成功', 'data' => $list]; + } } diff --git a/application/cron/controller/RoomPan.php b/application/cron/controller/RoomPan.php new file mode 100644 index 0000000..7ed7412 --- /dev/null +++ b/application/cron/controller/RoomPan.php @@ -0,0 +1,95 @@ +xlh_gift_send();//拍卖房结束提醒 + echo "礼物发放结束 \n"; + + echo "盲盒转盘礼物补发:\n"; + $this->blind_box_turntable_gift_send();//盲盒转盘礼物补发 + echo "盲盒转盘礼物补发结束 \n"; + } + + /* + * 盲盒转盘礼物补发 + */ + public function blind_box_turntable_gift_send(){ + $blind_box_turntable_log = db('vs_blind_box_turntable_results_log')->where(['is_sued'=>0])->select(); + if(empty($blind_box_turntable_log)){ + echo "没有需要发放的礼物 \n"; + } + echo "开始发放".count($blind_box_turntable_log)." \n"; + foreach ($blind_box_turntable_log as $key => $value) { + $blind_box_turntable = db('vs_blind_box_turntable_log')->field('user_id,room_id')->where('id',$value['tid'])->find(); + $give_gift_ext['gift_id'] = $value['gift_id']; + $give_gift_ext['count'] = $value['count']; + $give_gift_ext['gift_price'] = $value['gift_price']; + $give_gift_ext['all_gift_price'] = $value['all_gift_price']; + $give_gift_ext['is_draw_gift'] = 1; + echo "发放Id:".$value['id']." 补发用户Id:".$value['gift_user_id']." 礼物Id:".$value['gift_id']." 礼物数量:".$value['count']."\n"; + $res = model('GiveGift')->give_gift($blind_box_turntable['user_id'], $value['gift_user_id'], $value['gift_id'], $value['count'],2,1, $blind_box_turntable['room_id'],0,0,$give_gift_ext); + if (isset($res) && $res['code'] != 1) { + echo "礼物发放失败".$res['msg']."\n"; + continue; + } + db('vs_blind_box_turntable_results_log')->where('id', $value['id'])->update(['is_sued' => 1, 'updatetime' => time()]); + echo "补发成功 \n"; + } + } + + /* + * 巡乐会结束 礼物发放 【定时脚本】 + */ + public function xlh_gift_send(){ + $xlh_list = db::name('vs_room_pan_xlh')->where(['send_time'=>0,'user_id'=>['neq',0],'end_time'=>['<',time()]])->select(); + if(empty($xlh_list)){ + echo "没有需要发放的礼物 \n"; + } + foreach ($xlh_list as $key=>$value){ + //发放 + //抽中礼物落包 + $res = []; + $res = model('api/UserGiftPack')->change_user_gift_pack($value['user_id'],$value['gift_id'],$value['num'],model('UserGiftPack')::XLH_DRAW_GIFT_GET,"巡乐会中奖发放"); + if ($res['code'] != 1) { + echo $res['msg']."\n"; + continue; + } + echo "巡乐会中奖礼物发放成功 用户Id:".$value['user_id']."\n"; + //房主礼物落包 + $res = []; + //获取房主id + $user_id = db::name('vs_room')->where(['id'=>$value['room_id']])->value('user_id'); + $res = model('api/UserGiftPack')->change_user_gift_pack($user_id,$value['homeowner_gift_id'],1,model('UserGiftPack')::XLH_DRAW_GIFT_GET,"巡乐会中奖后房主礼物发放"); + if ($res['code'] != 1) { + echo $res['msg']."\n"; + continue; + } + echo "巡乐会中奖后房主礼物发放成功 房主Id:".$user_id."\n"; + //处理发放记录 + $res = []; + $res = db::name('vs_room_pan_xlh')->where('id',$value['id'])->update([ + 'send_time' => time() + ]); + if ($res === false) { + echo "处理发放记录失败 \n"; + continue; + } + //推送 + + } + } +} \ No newline at end of file