diff --git a/application/adminapi/controller/BlindBox.php b/application/adminapi/controller/BlindBox.php index 960b0d3..3758880 100644 --- a/application/adminapi/controller/BlindBox.php +++ b/application/adminapi/controller/BlindBox.php @@ -184,6 +184,8 @@ class BlindBox extends adminApi public function blind_box_edit(){ $id = input('id', ''); $quantity = input('quantity', 0); + $is_world_show = input('is_world_show', 0); + $gift_id = input('gift_id', 0); if(empty($id)){ return V(0,"参数错误"); } @@ -195,8 +197,10 @@ class BlindBox extends adminApi $data = []; $data['quantity'] = $quantity; $data['remaining_number'] = $quantity; - if($weight){ - $data['weight'] = $weight; + $data['$is_world_show'] = $is_world_show; + $data['weight'] = $weight; + if(!empty($gift_id)){ + $data['foreign_id'] = $gift_id; } $res = db::name($this->table)->where(['id'=>$id])->update($data); if($res){ diff --git a/application/api/controller/BlindBoxTurntable.php b/application/api/controller/BlindBoxTurntable.php index 32923a7..aa1eb35 100644 --- a/application/api/controller/BlindBoxTurntable.php +++ b/application/api/controller/BlindBoxTurntable.php @@ -48,4 +48,27 @@ class BlindBoxTurntable extends BaseCom $reslut = model('BlindBoxTurntableGift')->gift_send($send_id); return v($reslut['code'], $reslut['msg'], $reslut['data']); } + + /* + * 获取我的抽奖记录 + */ + public function get_my_record(){ + $user_id = $this->uid; + $gift_bag_id = input('gift_bag_id',0); + $page = input('page',1); + $page_size = input('page_size',12); + $reslut = model('BlindBoxTurntableGift')->get_user_record($gift_bag_id,$user_id,$page,$page_size); + return v($reslut['code'], $reslut['msg'], $reslut['data']); + } + + /* + * 获取全服抽奖记录 + */ + public function get_all_record(){ + $gift_bag_id = input('gift_bag_id',0); + $page = input('page',1); + $page_size = input('page_size',12); + $reslut = model('BlindBoxTurntableGift')->get_all_record($gift_bag_id,$page,$page_size); + return v($reslut['code'], $reslut['msg'], $reslut['data']); + } } \ No newline at end of file diff --git a/application/api/model/BlindBoxTurntableGift.php b/application/api/model/BlindBoxTurntableGift.php index 7d2178b..9daec1c 100644 --- a/application/api/model/BlindBoxTurntableGift.php +++ b/application/api/model/BlindBoxTurntableGift.php @@ -40,6 +40,7 @@ class BlindBoxTurntableGift extends Model $result_data = [ 'title' => $box['name'], 'rule_url' => get_system_config_value('web_site')."/api/Page/get_gift_box_rule?box_id=".$box["id"], + 'rule' => $ext['introd'], 'box_price' => $box_gift['gift_price'], 'gift_list' => $gift_list, ]; @@ -54,9 +55,23 @@ class BlindBoxTurntableGift extends Model $ext = json_decode($bag_data['ext'],true); $bag_gift = db::name("vs_gift")->where(['gid'=>$ext['gift_id']])->find();// 获取盲盒信息 $toarray = explode(',',$gift_user_ids); + //判断是否有足够的金币 + $user_waller = db::name('user_wallet')->where(['user_id'=>$user_id])->find(); + if ($user_waller['coin'] < $bag_gift['gift_price'] * $num) { + return ['code' => 0, 'msg' => '用户金币不足', 'data' => null]; + } + //盲盒转盘抽奖记录 + $box_turntable_log = db::name('vs_blind_box_turntable_log')->insertGetId([ + 'user_id' => $user_id, + 'gift_bag_id' => $gift_bag_id, + 'num' => $num, + 'room_id' => $room_id, + 'bag_price' => $bag_gift['gift_price'], + 'createtime' => time() + ]); foreach ($toarray as $gift_user_id){ for($i = 0; $i < $num; $i++){ - $reslut_draw_gift_data = $this->draw_gift_one($gift_bag_id, $user_id, $gift_user_id,$bag_gift['gift_price'],$bag_data['periods'],$room_id); + $reslut_draw_gift_data = $this->draw_gift_one($gift_bag_id, $user_id, $gift_user_id,$bag_gift['gift_price'],$bag_data['periods'],$room_id,$box_turntable_log); $reslut_draw_gift[] = $reslut_draw_gift_data['data']; } } @@ -89,16 +104,18 @@ class BlindBoxTurntableGift extends Model } } $reslut_gift = array_values($reslut_gift); - //盲盒转盘抽奖记录 - $box_turntable_log = db::name('vs_blind_box_turntable_log')->insertGetId([ - 'user_id' => $user_id, - 'gift_bag_id' => $gift_bag_id, - 'num' => $num, - 'room_id' => $room_id, - 'bag_price' => $bag_gift['gift_price'], - 'lottery_result' => json_encode($reslut_gift), - 'createtime' => time() - ]); + foreach ($reslut_gift as $key => $value) { + db::name('vs_blind_box_turntable_results_log')->insert([ + 'tid' => $box_turntable_log, + 'gift_user_id' => $value['gift_user_id'], + 'gift_id' => $value['gift_id'], + 'count' => $value['count'], + 'gift_price' => $value['gift_price'], + 'all_gift_price' => $value['gift_price'] * $value['count'], + 'createtime' => time() + ]); + } + $reslut = []; $reslut['blind_box_turntable_id'] = $box_turntable_log; $reslut['reslut_list'] = array_values($reslut_data); return V(1,"成功", $reslut); @@ -106,7 +123,7 @@ class BlindBoxTurntableGift extends Model /* * 单人单次抽奖 */ - public function draw_gift_one($gift_bag_id, $user_id, $gift_user_id,$gift_price,$periods,$room_id=0){ + public function draw_gift_one($gift_bag_id, $user_id, $gift_user_id,$gift_price,$periods,$room_id=0,$box_turntable_log=0){ //随机获取一个礼物 $where = [ 'gift_bag_id' => $gift_bag_id, @@ -151,6 +168,7 @@ class BlindBoxTurntableGift extends Model $data = []; $data['user_id'] = $user_id; $data['gift_user_id'] = $gift_user_id; + $data['parent_id'] = $box_turntable_log; $data['gift_bag_id'] = $gift_bag_id; $data['gift_id'] = $gift_bag_detail['foreign_id']; $data['periods'] = $periods; @@ -194,14 +212,72 @@ class BlindBoxTurntableGift extends Model if(!$blind_box_turntable){ return ['code' => 0, 'msg' => '数据不存在']; } - $reslut_gift = json_decode($blind_box_turntable['lottery_result'],true); - foreach ($reslut_gift as $key => $value) { - $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']); + $blind_box_turntable_log = db('vs_blind_box_turntable_results_log')->where('tid',$send_id)->select(); + if(!$blind_box_turntable_log){ + return ['code' => 0, 'msg' => '开奖数据不存在']; + } + //获取盲盒配置 + $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'],$give_gift_ext); if (isset($res) && $res['code'] != 1) { return V(0, $res['msg']); } + db('vs_blind_box_turntable_results_log')->where('id', $value['id'])->update(['is_sued' => 1, 'updatetime' => time()]); } - $res = db('vs_blind_box_turntable_log')->where('id', $blind_box_turntable['id'])->update(['is_sued' => 1, 'updatetime' => time()]); - return ['code' => 1, 'msg' => '成功', 'data' => $res]; + return ['code' => 1, 'msg' => '成功', 'data' => null]; + } + + /* + * 获取用户抽奖记录 + */ + public function get_user_record($gift_bag_id,$user_id=0,$page=1,$page_size=12){ + $where = []; + $where['b.gift_bag_id'] = $gift_bag_id; + if($user_id > 0){ + $where['b.user_id'] = $user_id; + } + $list = db('vs_blind_box_turntable_results_log') + ->alias('a') + ->join('vs_blind_box_turntable_log b','b.id = a.tid','left') + ->join('user c','a.gift_user_id = c.id','left') + ->join('vs_gift d','d.gid = a.gift_id','left') + ->field('a.gift_id,a.count,a.gift_user_id,b.createtime,c.nickname,d.gift_name as gift_name,d.play_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 get_all_record($gift_bag_id,$page=1,$page_size=12){ + $where = []; + $where['b.gift_bag_id'] = $gift_bag_id; + $where['d.gift_bag_id'] = $gift_bag_id; + $where['d.is_world_show'] = 1; + $list = db('vs_blind_box_turntable_results_log') + ->alias('a') + ->join('vs_blind_box_turntable_log b','b.id = a.tid','left') + ->join('user c','b.user_id = c.id','left') + ->join('vs_gift_bag_detail d','d.foreign_id = a.gift_id','left') + ->join('vs_gift e','e.gid = a.gift_id','left') + ->field('a.gift_id,a.count,a.gift_user_id,b.createtime,c.nickname,d.name as gift_name,e.play_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]; } } diff --git a/application/api/model/GiveGift.php b/application/api/model/GiveGift.php index 7dd6dc6..b982270 100644 --- a/application/api/model/GiveGift.php +++ b/application/api/model/GiveGift.php @@ -38,7 +38,7 @@ class GiveGift extends Model * @return array * 用户,在房间中,给谁,送了什么礼物,多少个,来源 */ - public function give_gift($uid,$to_uid,$gid,$num,$from_type,$type,$from_id = 0,$pit_number = 0,$change_type = 0) + public function give_gift($uid,$to_uid,$gid,$num,$from_type,$type,$from_id = 0,$pit_number = 0,$change_type = 0,$ext = []) { //送的礼物信息 $gift_info = Db::name('vs_gift')->where(['gid'=>$gid]) @@ -133,22 +133,35 @@ class GiveGift extends Model //查询礼物是否是盲盒 if($gift_info['label'] == 2){//趣味礼物(盲盒) $gift_price_box = 0; - for($i = 0; $i < $num; $i++){ - $gift_box1[$i] = $this -> open_box($gid,$uid,$to_id,$from_id); - if($gift_box1[$i]['code'] != 1){ - Db::rollback(); - return ['code' => 0, 'msg' => '盲盒配置有误请联系管理员'.$gift_box1[$i]['msg'], 'data' => null]; - } - $gift_box[$i] = $gift_box1[$i]['data']; - //记录一下收礼记录 - $give_gift = $this -> change_user_give_gift_log($uid,$gift_box[$i]['gift_id'],$gift_box[$i]['gift_price'],1,$to_id,$from_type,$type,$from_id,$pit_number,2); + if(isset($ext['is_draw_gift']) && $ext['is_draw_gift'] == 1){ + //收礼记录行为日志 + $give_gift = $this -> change_user_give_gift_log($uid,$ext['gift_id'],$ext['all_gift_price'],$ext['count'],$to_id,$from_type,$type,$from_id,$pit_number,2); if(!$give_gift){ Db::rollback(); return ['code' => 0, 'msg' => '送礼失败', 'data' => null]; } - $gift_box[$i]['give_gift_id'] = $give_gift; - $gift_price_box += $gift_box[$i]['gift_price']; - Log::record("盲盒礼物".json_encode($gift_box1),"info"); + $gift_price_box = $ext['all_gift_price']; + $gift_box[0]['gift_id'] = $ext['gift_id']; + $gift_box[0]['gift_price'] = $ext['all_gift_price']; + $gift_box[0]['give_gift_id'] = $give_gift; + }else{ + for($i = 0; $i < $num; $i++){ + $gift_box1[$i] = $this -> open_box($gid,$uid,$to_id,$from_id); + if($gift_box1[$i]['code'] != 1){ + Db::rollback(); + return ['code' => 0, 'msg' => '盲盒配置有误请联系管理员'.$gift_box1[$i]['msg'], 'data' => null]; + } + $gift_box[$i] = $gift_box1[$i]['data']; + //记录一下收礼记录 + $give_gift = $this -> change_user_give_gift_log($uid,$gift_box[$i]['gift_id'],$gift_box[$i]['gift_price'],1,$to_id,$from_type,$type,$from_id,$pit_number,2); + if(!$give_gift){ + Db::rollback(); + return ['code' => 0, 'msg' => '送礼失败', 'data' => null]; + } + $gift_box[$i]['give_gift_id'] = $give_gift; + $gift_price_box += $gift_box[$i]['gift_price']; + Log::record("盲盒礼物".json_encode($gift_box1),"info"); + } } $gift_total += $gift_price_box; $gift_price = $gift_price_box; @@ -366,101 +379,146 @@ class GiveGift extends Model } //推送礼物特效 if($gift_info['label'] == 2){ - //循环开出来的盲盒,相同的礼物只推送一次,消息推送为$FromUserInfo['nickname'] . ' 送给 ' . $ToUserInfo['nickname'].' 趣味礼物 ' .$gift_inf['gift_name'].' x 多少'; - if($gift_box){ - // 统计相同礼物的数量 - $giftCount = []; - foreach ($gift_box as $gv) { - if (isset($giftCount[$gv['gift_id']])) { - $giftCount[$gv['gift_id']]['count']++; - } else { - $giftCount[$gv['gift_id']] = [ - 'gift_info' => Db::name('vs_gift')->where(['gid'=>$gv['gift_id']]) - ->field('gid as gift_id,gift_name,gift_price,file_type,base_image,play_image,gift_type,label,is_public_server')->find(), - 'count' => 1 - ]; - } - } - - // 构建文字消息内容 - $giftTextList = []; - foreach ($giftCount as $giftData) { - $gift_inf = $giftData['gift_info']; - $count = $giftData['count']; - $giftTextList[] = $gift_inf['gift_name'].' X'.$count; - } - - // 推送文字消息 (格式: 张三 送给 李四 趣味礼物 礼物名1 X2,礼物2 X4) - $textMessage = $FromUserInfo['nickname'] . ' 送给 ' . $ToUserInfo['nickname'].' 趣味礼物 ' . implode(',', $giftTextList); - $textData = [ + if(isset($ext['is_draw_gift']) && $ext['is_draw_gift'] == 1){ + $draw_gift = Db::name('vs_gift')->where(['gid'=>$ext['gift_id']])->find(); + $textMessage = $FromUserInfo['nickname'] . ' 送给 ' . $ToUserInfo['nickname'].' 盲盒转盘礼物 ' . $draw_gift['gift_name'].' x ' .$ext['count']; + $text = [ 'FromUserInfo' => $FromUserInfo, + 'ToUserInfo' => $ToUserInfo, + 'GiftInfo' => $draw_gift, + 'GiftNum' => $draw_gift['gift_name'], + 'text' => $textMessage + ]; + //聊天室推送系统消息 + model('Chat')->sendMsg(1005,$from_id,$text); + $roomtype = Db::name('vs_room')->where(['id' => $from_id])->value('type_id'); + if($roomtype == 6){ + //推送消息 + $hot_value = db::name('vs_give_gift')->where('from_id', $from_id)->where('from',6) + ->sum('total_price'); + $text1 = [ + 'room_id' => $from_id, + 'hot_value' => $hot_value * 10, + 'text' => '房间心动值变化' + ]; + //聊天室推送系统消息 + model('Chat')->sendMsg(1028,$from_id,$text1); + }else{ + if($draw_gift['is_public_server'] == 1){ + //推送礼物横幅 + $push = new Push(UID, $from_id); + $room_name = Db::name('vs_room')->where(['id' => $from_id, 'apply_status' => 2])->value('room_name'); + $text = $FromUserInfo['nickname'] . '在' . $room_name . '房间送给了' . $ToUserInfo['nickname'] . $draw_gift['gift_name'] . 'X' . $num; + $text_list_new = [ + 'text' => $text, + 'gift_picture' => $draw_gift['base_image'], + 'room_id' => $from_id, + 'fromUserName' => $FromUserInfo['nickname'], + 'toUserName' => $ToUserInfo['nickname'], + 'giftName' => $draw_gift['gift_name'], + 'roomId' => $from_id, + 'number' => $num, + ]; + $push->giftBanner($text_list_new); + } + + } + }else{ + //循环开出来的盲盒,相同的礼物只推送一次,消息推送为$FromUserInfo['nickname'] . ' 送给 ' . $ToUserInfo['nickname'].' 趣味礼物 ' .$gift_inf['gift_name'].' x 多少'; + if($gift_box){ + // 统计相同礼物的数量 + $giftCount = []; + foreach ($gift_box as $gv) { + if (isset($giftCount[$gv['gift_id']])) { + $giftCount[$gv['gift_id']]['count']++; + } else { + $giftCount[$gv['gift_id']] = [ + 'gift_info' => Db::name('vs_gift')->where(['gid'=>$gv['gift_id']]) + ->field('gid as gift_id,gift_name,gift_price,file_type,base_image,play_image,gift_type,label,is_public_server')->find(), + 'count' => 1 + ]; + } + } + + // 构建文字消息内容 + $giftTextList = []; + foreach ($giftCount as $giftData) { + $gift_inf = $giftData['gift_info']; + $count = $giftData['count']; + $giftTextList[] = $gift_inf['gift_name'].' X'.$count; + } + + // 推送文字消息 (格式: 张三 送给 李四 趣味礼物 礼物名1 X2,礼物2 X4) + $textMessage = $FromUserInfo['nickname'] . ' 送给 ' . $ToUserInfo['nickname'].' 趣味礼物 ' . implode(',', $giftTextList); + $textData = [ + 'FromUserInfo' => $FromUserInfo, // 'ToUserInfo' => $ToUserInfo, // 'GiftInfo' => $gift_info, // 'GiftNum' => $num, - 'text' => $textMessage - ]; - // 聊天室推送文字消息 - model('Chat')->sendMsg(1038,$from_id,$textData); - - // 循环推送每个礼物的特效消息 - foreach ($giftCount as $giftId => $giftData) { - $gift_inf = $giftData['gift_info']; - $count = $giftData['count']; - - // 推送礼物特效消息 - $effectData = [ - 'FromUserInfo' => $FromUserInfo, - 'ToUserInfo' => $ToUserInfo, - 'GiftInfo' => $gift_inf, - 'GiftNum' => $count, - 'text' => null + 'text' => $textMessage ]; + // 聊天室推送文字消息 + model('Chat')->sendMsg(1038,$from_id,$textData); - // 聊天室推送礼物特效消息 - model('Chat')->sendMsg(1005,$from_id,$effectData); + // 循环推送每个礼物的特效消息 + foreach ($giftCount as $giftId => $giftData) { + $gift_inf = $giftData['gift_info']; + $count = $giftData['count']; - $roomtype = Db::name('vs_room')->where(['id' => $from_id])->value('type_id'); - if($roomtype == 6){ - //推送消息 - $hot_value = db::name('vs_give_gift')->where('from_id', $from_id)->where('from',6) - ->sum('total_price'); - $text1 = [ - 'room_id' => $from_id, - 'hot_value' => $hot_value * 10, - 'text' => '房间心动值变化' + // 推送礼物特效消息 + $effectData = [ + 'FromUserInfo' => $FromUserInfo, + 'ToUserInfo' => $ToUserInfo, + 'GiftInfo' => $gift_inf, + 'GiftNum' => $count, + 'text' => null ]; - //聊天室推送系统消息 - model('Chat')->sendMsg(1028,$from_id,$text1); - //电影房推送结束时间点 - $text2 = [ - 'room_id' => $from_id, - 'end_time' => time() + 60 * 60 * 24 * 7, - 'text' => '房间结束时间点' - ]; - model('Chat')->sendMsg(1042,$from_id,$text2); - }else{ - if($gift_inf['is_public_server'] == 1){ - //推送礼物横幅 - $push = new Push(UID, $from_id); - $room_name = Db::name('vs_room')->where(['id' => $from_id, 'apply_status' => 2])->value('room_name'); - $bannerText = $FromUserInfo['nickname'] . '在' . $room_name . '房间送给了' . $ToUserInfo['nickname'] . $gift_inf['gift_name'] . 'X' . $count; - $text_list_new = [ - 'text' => $bannerText, - 'gift_picture' => $gift_inf['base_image'], + // 聊天室推送礼物特效消息 + model('Chat')->sendMsg(1005,$from_id,$effectData); + + $roomtype = Db::name('vs_room')->where(['id' => $from_id])->value('type_id'); + if($roomtype == 6){ + //推送消息 + $hot_value = db::name('vs_give_gift')->where('from_id', $from_id)->where('from',6) + ->sum('total_price'); + $text1 = [ 'room_id' => $from_id, - 'fromUserName' => $FromUserInfo['nickname'], - 'toUserName' => $ToUserInfo['nickname'], - 'giftName' => $gift_inf['gift_name'], - 'roomId' => $from_id, - 'number' => $count, + 'hot_value' => $hot_value * 10, + 'text' => '房间心动值变化' ]; - $push->giftBanner($text_list_new); + //聊天室推送系统消息 + model('Chat')->sendMsg(1028,$from_id,$text1); + + //电影房推送结束时间点 + $text2 = [ + 'room_id' => $from_id, + 'end_time' => time() + 60 * 60 * 24 * 7, + 'text' => '房间结束时间点' + ]; + model('Chat')->sendMsg(1042,$from_id,$text2); + }else{ + if($gift_inf['is_public_server'] == 1){ + //推送礼物横幅 + $push = new Push(UID, $from_id); + $room_name = Db::name('vs_room')->where(['id' => $from_id, 'apply_status' => 2])->value('room_name'); + $bannerText = $FromUserInfo['nickname'] . '在' . $room_name . '房间送给了' . $ToUserInfo['nickname'] . $gift_inf['gift_name'] . 'X' . $count; + $text_list_new = [ + 'text' => $bannerText, + 'gift_picture' => $gift_inf['base_image'], + 'room_id' => $from_id, + 'fromUserName' => $FromUserInfo['nickname'], + 'toUserName' => $ToUserInfo['nickname'], + 'giftName' => $gift_inf['gift_name'], + 'roomId' => $from_id, + 'number' => $count, + ]; + $push->giftBanner($text_list_new); + } } } } } - }else{ $text = $FromUserInfo['nickname'] . ' 送给 ' . $ToUserInfo['nickname'].' 礼物 ' .$gift_info['gift_name'].' x ' .$num; $text = [ @@ -1023,7 +1081,7 @@ class GiveGift extends Model /* * 开盲盒 */ - public function open_box($gift_id,$user_id,$gift_user_id,$room_id=0){ + public function open_box($gift_id,$user_id,$gift_user_id,$room_id=0,$gift_bag_id=0){ //获取盲盒配置 $bag_list = db::name("vs_gift_bag")->field('id,name,ext,periods')->where(['activities_id'=>4,'status'=>1])->select(); $gift_bag_id = 0;