110 lines
4.7 KiB
PHP
110 lines
4.7 KiB
PHP
<?php
|
||
|
||
namespace app\cron\controller;
|
||
|
||
use app\common\controller\Push;
|
||
use think\Db;
|
||
|
||
|
||
/*
|
||
* 定时任务,每秒执行的方法
|
||
*/
|
||
class RoomPan
|
||
{
|
||
/*
|
||
* 运行函数
|
||
*/
|
||
function index()
|
||
{
|
||
echo "巡乐会结束 礼物发放:\n";
|
||
$this->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,'createtime'=>['>=',time()-60*10]])->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;
|
||
}
|
||
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(['id'=>$value['gift_id']])->value('gift_name');
|
||
$text = $FromUserInfo['nickname'] . ' 用户在 ' . $room_name.' 房间巡乐会中 ' .$gift_name.'礼物 x ' .$value['num']." 已收入背包";
|
||
//推送礼物横幅
|
||
$push = new Push(UID, $value['room_id']);
|
||
$text_list_new = [
|
||
'text' => $text,
|
||
'room_id' => $value['room_id'],
|
||
'from_type' => 3
|
||
];
|
||
$push->xunlehui($text_list_new);
|
||
}
|
||
}
|
||
} |