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 = db('vs_blind_box_turntable_log')->where(['is_sued'=>0,'createtime'=>['>=',time()-60*30]])->limit(1000)->select(); if(empty($blind_box_turntable)){ echo "没有需要发放的礼物 \n"; } echo "开始发放".count($blind_box_turntable)." \n"; foreach ($blind_box_turntable as $k => $v) { $blind_box_turntable_results_log = db('vs_blind_box_turntable_results_log')->where('tid',$v['id'])->select(); if(empty($blind_box_turntable_results_log)){ echo $v['id']." 没有需要发放的礼物 \n"; continue; } $room_id = $v['room_id']; $room_name = Db::name('vs_room')->where(['id' => $room_id, 'apply_status' => 2])->value('room_name'); $FromUserInfo = Db::name('user')->where(['id'=>$v['user_id']])->find(); $FromUserInfo['icon'][0] = model('UserData')->user_wealth_icon($v['user_id']);//财富图标 $FromUserInfo['icon'][1] = model('UserData')->user_charm_icon($v['user_id']);//魅力图标 $user_nickname = $FromUserInfo['nickname']; $textMessage = $user_nickname; $text_message = $user_nickname; foreach ($blind_box_turntable_results_log as $key => $value) { $ToUserInfo = Db::name('user')->where(['id' => $value['gift_user_id']])->field('id as user_id,nickname,avatar,sex')->find(); $draw_gift = Db::name('vs_gift')->where(['gid'=>$value['gift_id']])->find(); $textMessage = $textMessage . ' 送给 ' . $ToUserInfo['nickname']. ' 盲盒转盘礼物 ' . $draw_gift['gift_name'].' x ' .$value['count']."\n"; $play_image[] = $draw_gift['play_image']; $gift_names[] = $draw_gift['gift_name']; $text_message = $text_message . '在' . $room_name . '房间送给了' . $ToUserInfo['nickname'] . $draw_gift['gift_name'] . 'X' . $value['count']."\n"; if($draw_gift['is_public_server'] == 1) { $text_list_new[] = [ 'text' => $text_message, 'gift_picture' => $draw_gift['base_image'], 'room_id' => $room_id, 'fromUserName' => $FromUserInfo['nickname'], 'toUserName' => $ToUserInfo['nickname'], 'giftName' => $draw_gift['gift_name'], 'roomId' => $room_id, 'number' => $value['count'], ]; } $ToUserInfosList[$value['gift_user_id']] = $ToUserInfo; } foreach($ToUserInfosList as &$userInfo) { $userInfo['icon'][0] = model('UserData')->user_wealth_icon($userInfo['user_id']);//财富图标 $userInfo['icon'][1] = model('UserData')->user_charm_icon($userInfo['user_id']);//魅力图标 $userInfo['charm'] = db::name('vs_room_user_charm')->where(['user_id' => $userInfo['user_id'],'room_id' => $room_id])->value('charm');//魅力 $ToUserInfos[] = $userInfo; } $text = [ 'FromUserInfo' => $FromUserInfo, 'ToUserInfos' => $ToUserInfos, 'GiftInfo' => [ 'play_image' => implode(',',$play_image), 'gift_name' => implode(',',$gift_names), ], 'text' => rtrim($textMessage, "\n") ]; //聊天室推送系统消息 model('Chat')->sendMsg(1005,$room_id,$text); $roomtype = Db::name('vs_room')->where(['id' => $room_id])->value('type_id'); if($roomtype == 6){ //推送消息 $hot_value = db::name('vs_give_gift')->where('from_id', $room_id)->where('from',6) ->sum('total_price'); $text1 = [ 'room_id' => $room_id, 'hot_value' => $hot_value * 10, 'text' => '房间心动值变化' ]; //聊天室推送系统消息 model('Chat')->sendMsg(1028,$room_id,$text1); }else{ if(!empty($text_list_new)){ //推送礼物横幅 $push = new Push($v['user_id'], $room_id); $push->giftBanner($text_list_new); } } db::name('vs_blind_box_turntable_log')->where('id', $v['id'])->update(['is_sued' => 1, 'updatetime' => time()]); } } /* * 巡乐会结束 礼物发放 【定时脚本】 */ public function xlh_gift_send(){ $xlh_list = db::name('vs_room_pan_xlh')->where(['send_time'=>0,'end_time'=>['<=',time()]])->select(); if(empty($xlh_list)){ echo "没有需要发放的礼物 \n"; } foreach ($xlh_list as $key=>$value){ try{ if($value['user_id'] == 0){ echo "第.".$value['periods']." 巡乐会结束 没有中奖用户 \n"; $res = db::name('vs_room_pan_xlh')->where('id',$value['id'])->update([ 'send_time' => time() ]); db::name("vs_room")->where('id',$value['room_id'])->update([ 'xlh_periods_num' => 0 ]); //推送礼物横幅 $text = "本轮巡乐会已结束,请大家重新开始下一轮巡乐会"; $push = new Push(0, $value['room_id']); $text_list_new = [ 'text' => $text, 'room_id' => $value['room_id'], 'from_type' => 3 ]; $push->xunlehui($text_list_new); continue; } //发放 //抽中礼物落包 $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() ]); $xlh_log = db::name('vs_room_pan_xlh_log')->where(['xlh_id'=>$value['id'],'user_id'=>$value['user_id']])->order('id desc')->find(); $res = db::name('vs_room_pan_xlh_log')->where('id',$xlh_log['id'])->update([ 'is_send' => 1 ]); if ($res === false) { echo "处理发放记录失败 \n"; continue; } db::name("vs_room")->where('id',$value['room_id'])->update([ 'xlh_periods_num' => 0 ]); //推送 $FromUserInfo = db::name('user')->field('nickname,avatar')->where(['id'=>$value['user_id']])->find(); $room_name = db::name('vs_room')->where(['id'=>$value['room_id']])->value('room_name'); $gift_name = db::name('vs_gift')->where(['gid'=>$value['gift_id']])->value('gift_name'); $text = $FromUserInfo['nickname'] . ' 用户在 ' . $room_name.' 房间巡乐会中 ' .$gift_name.'礼物 x ' .$value['num']." 已收入背包"; //推送礼物横幅 $push = new Push(0, $value['room_id']); $text_list_new = [ 'text' => $text, 'room_id' => $value['room_id'], 'from_type' => 3 ]; $push->xunlehui($text_list_new); }catch (\Exception $e){ echo $e->getMessage()."\n"; } } } }