更新
This commit is contained in:
@@ -2,6 +2,9 @@
|
||||
|
||||
namespace app\cron\controller;
|
||||
|
||||
use app\common\model\Redpacket;
|
||||
use app\common\model\UserWallet;
|
||||
use think\Cache;
|
||||
use think\Db;
|
||||
use Yzh\YunPay;
|
||||
|
||||
@@ -30,9 +33,15 @@ class PerformPerSecond
|
||||
echo "pk发起10秒后无应答拒绝:\n";
|
||||
$this->pk_start_refuse();
|
||||
echo "\n";
|
||||
// echo "提现云账号订单状态查询:\n";
|
||||
// $this->withdraw_order_status();
|
||||
echo "房间红包清退:\n";
|
||||
$this->processExpiredRedpackets();
|
||||
echo "\n";
|
||||
// echo "房间火热值更新:\n";
|
||||
// $this->room_hot_update();
|
||||
// echo "\n";
|
||||
echo "提现云账号订单状态查询:\n";
|
||||
$this->withdraw_order_status();
|
||||
echo "\n";
|
||||
}
|
||||
|
||||
|
||||
@@ -136,6 +145,9 @@ class PerformPerSecond
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if($value['yun_order_status'] == 5077){
|
||||
continue;
|
||||
}
|
||||
echo "提现订单查询:".$value['order_sn']."\n";
|
||||
$yun_pay = new YunPay($value['order_sn'], "", "", "", "","");
|
||||
$result = $yun_pay->queryOrder($value['type']);
|
||||
@@ -145,15 +157,32 @@ class PerformPerSecond
|
||||
'status' => 6,
|
||||
'pay_time' => time(),
|
||||
'pay_message' => $result['data']['msg'],
|
||||
'updatetime' => time()
|
||||
'updatetime' => time(),
|
||||
'yun_order_status' => $result['data']['code'],
|
||||
// 'personal_tax_rate' => $result['personal_tax_rate'] ?? 0,
|
||||
'received_tax_amount' => $result['received_tax_amount'] ?? 0,
|
||||
]);
|
||||
}else{
|
||||
db::name('vs_user_withdrawal')->where('order_sn',$value['order_sn'])->update([
|
||||
'status' => 5,
|
||||
'pay_time' => time(),
|
||||
'pay_message' => $result['data']['msg'],
|
||||
'updatetime' => time()
|
||||
'updatetime' => time(),
|
||||
'yun_order_status' => $result['data']['code'],
|
||||
// 'personal_tax_rate' => $result['personal_tax_rate'] ?? 0,
|
||||
'received_tax_amount' => $result['received_tax_amount'] ?? 0,
|
||||
]);
|
||||
if(in_array($result['data']['code'],[5077,261]) && $value['yun_order_status'] == null){
|
||||
// if($result['data']['code']==5077 && $value['yun_order_status'] == null){
|
||||
//该支付宝账户不存在或未开通手机号转账功能。如有疑问,请收款用户联系支付宝客服咨询。
|
||||
//退还金币
|
||||
$res = model('api/UserWithdrawal')->withdrawal_fail($value['order_sn']);
|
||||
if($res){
|
||||
echo "提现订单失败,退回金币成功\n";
|
||||
}else{
|
||||
echo "提现订单失败,退回金币失败:".$res['msg']."\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
echo "提现订单查询成功:".$result['msg']."\n";
|
||||
@@ -162,4 +191,140 @@ class PerformPerSecond
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//房间火热值更新
|
||||
public function room_hot_update(){
|
||||
$room_id_list = db::name('vs_room_hot_value_log')->field('id,room_id')->select();
|
||||
$room_list = db::name('vs_room_hot_value_log')->field('room_id,sum(hot_value) as value')->group('room_id')->select();
|
||||
|
||||
if($room_list){
|
||||
$data_count = 0;
|
||||
$data_room_list = [];
|
||||
foreach ($room_list as $value){
|
||||
$hot_value = 0;
|
||||
$hot_values = db::name('vs_room')->where('id',$value['room_id'])->field('hot_value,today_hot_value')->find();
|
||||
if($hot_values['today_hot_value'] == $value['value'] || $value['value'] == 0){
|
||||
continue;
|
||||
}
|
||||
if($hot_values['today_hot_value'] < $value['value']){
|
||||
$hot_value = $hot_values['hot_value'] + ($value['value'] - $hot_values['today_hot_value']);
|
||||
}
|
||||
if($hot_values['today_hot_value'] > $value['value']){
|
||||
$hot_value = $hot_values['hot_value'];
|
||||
$today_hot_value = $value['value'];
|
||||
}
|
||||
|
||||
$res = db::name('vs_room')->where('id',$value['room_id'])->update([
|
||||
'today_hot_value' => $today_hot_value,
|
||||
'hot_value' => $hot_value,
|
||||
'updatetime' => time()
|
||||
]);
|
||||
if($res){
|
||||
// db::name('vs_room_hot_value_log')->where('room_id',$value['room_id'])->delete();
|
||||
$data_room_list[] = $value['room_id'];
|
||||
}
|
||||
$data_count ++;
|
||||
}
|
||||
foreach ($room_id_list as $v){
|
||||
if(in_array($v['room_id'],$data_room_list)){
|
||||
db::name('vs_room_hot_value_log')->where('id',$v['id'])->delete();
|
||||
}
|
||||
}
|
||||
echo "房间火热值更新操作-共". $data_count . "条数据\n";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 处理过期红包退款
|
||||
*/
|
||||
public function processExpiredRedpackets()
|
||||
{
|
||||
$now = time();
|
||||
$processedCount = 0;
|
||||
|
||||
// 1. 处理到时间的未开始红包,更新为进行中
|
||||
$pendingRedpackets = Db::name('redpacket')
|
||||
->where('status', Redpacket::STATUS_PENDING)
|
||||
->where('start_time', '<=', $now)
|
||||
->select();
|
||||
|
||||
foreach ($pendingRedpackets as $redpacket) {
|
||||
Db::name('redpacket')
|
||||
->where('id', $redpacket['id'])
|
||||
->update([
|
||||
'status' => Redpacket::STATUS_ACTIVE,
|
||||
'updatetime' => $now
|
||||
]);
|
||||
|
||||
// 更新Redis缓存
|
||||
$redis = Cache::store('redis')->handler();
|
||||
$redisKey = "redpacket:{$redpacket['id']}";
|
||||
$redis->hSet($redisKey, 'status', Redpacket::STATUS_ACTIVE);
|
||||
|
||||
$processedCount++;
|
||||
}
|
||||
|
||||
// 2. 处理已过期的进行中红包,更新为已结束并退款
|
||||
$expiredRedpackets = Db::name('redpacket')
|
||||
->where('status', Redpacket::STATUS_ACTIVE)
|
||||
->where('end_time', '<', $now)
|
||||
->where('left_count', '>', 0)
|
||||
->select();
|
||||
|
||||
foreach ($expiredRedpackets as $redpacket) {
|
||||
Db::startTrans();
|
||||
try {
|
||||
// 退款给发红包用户
|
||||
if ($redpacket['left_amount'] > 0) {
|
||||
// 更新用户钱包
|
||||
$coinField = $redpacket['coin_type'] == 1 ? 'coin' : 'earnings';
|
||||
//增加余额
|
||||
$addres = Db::name('user_wallet')
|
||||
->where('user_id', $redpacket['user_id'])
|
||||
->inc($coinField, $redpacket['left_amount'])
|
||||
->update();
|
||||
//记录用户金币日志
|
||||
$data = [
|
||||
'user_id' => $redpacket['user_id'],
|
||||
'change_value' => $redpacket['left_amount'],
|
||||
'room_id' => $redpacket['room_id'],
|
||||
'money_type' => $redpacket['coin_type'],
|
||||
//记录日志 32-发红包(金币),29-发红包(钻石),30-抢红包(金币),31-抢红包(钻石),33-红包剩余退回(金币),34-红包剩余退回(钻石)
|
||||
'change_type' => $redpacket['coin_type'] == 1 ? 33 : 34,
|
||||
'from_id' => $redpacket['room_id'],
|
||||
'remarks' => '红包剩余退回',
|
||||
'createtime' => time()
|
||||
];
|
||||
|
||||
$res = Db::name('vs_user_money_log')->insert($data);
|
||||
if(!$res || !$addres){
|
||||
Db::rollback();
|
||||
}
|
||||
}
|
||||
|
||||
// 更新红包状态为已结束
|
||||
Db::name('redpacket')
|
||||
->where('id', $redpacket['id'])
|
||||
->update([
|
||||
'status' => Redpacket::STATUS_FINISHED,
|
||||
'updatetime' => $now
|
||||
]);
|
||||
|
||||
// 更新Redis缓存
|
||||
$redis = Cache::store('redis')->handler();
|
||||
$redisKey = "redpacket:{$redpacket['id']}";
|
||||
$redis->hSet($redisKey, 'status', Redpacket::STATUS_FINISHED);
|
||||
|
||||
Db::commit();
|
||||
$processedCount++;
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
// 记录日志
|
||||
\think\Log::error("红包退款失败: {$redpacket['id']}, 错误: " . $e->getMessage());
|
||||
}
|
||||
}
|
||||
echo "处理过期红包-共". $processedCount . "条数据\n";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -30,10 +30,10 @@ class Subsidy
|
||||
*/
|
||||
public function createGuildSubsidyData(){
|
||||
//获取上周第一天时间
|
||||
$week_start_time = strtotime('last monday');
|
||||
$week_end_time = strtotime(date('Y-m-d 23:59:59',strtotime('last sunday')));
|
||||
// $week_start_time = strtotime('2025-08-11');
|
||||
// $week_end_time = strtotime('2025-08-17 23:59:59');
|
||||
$week_start_time = strtotime('last week Monday');
|
||||
$week_end_time = strtotime(date('Y-m-d 23:59:59',strtotime('last week Sunday')));
|
||||
// $week_start_time = strtotime('2025-09-29');
|
||||
// $week_end_time = strtotime('2025-09-29 23:59:59');
|
||||
|
||||
//获取上周时间
|
||||
$time_value = date('o-W', $week_start_time);
|
||||
@@ -43,12 +43,24 @@ class Subsidy
|
||||
$data_count = 0;
|
||||
foreach ($guild_list as $key => $value) {
|
||||
//获取所有工会房间ID
|
||||
$room_ids = db::name('vs_guild_user')->where('guild_id', $value['id'])->field('room_id')->select();
|
||||
$room_ids = array_column($room_ids, 'room_id');
|
||||
$transaction = db::name('vs_give_gift')
|
||||
->whereIn('from_id',$room_ids)
|
||||
->where(['from'=>['in',[2,3,6]],'createtime' => ['between', [$week_start_time, $week_end_time]]])
|
||||
->sum('total_price');
|
||||
$guild_user_data = db::name('vs_guild_user')->where('guild_id', $value['id'])->field('room_id,createtime,quit_time')->select();
|
||||
$transaction = 0;
|
||||
foreach ($guild_user_data as $k => $v) {
|
||||
$week_start_time_seach = $week_start_time;
|
||||
$week_end_time_seach = $week_end_time;
|
||||
if($v['createtime'] && $week_start_time_seach < $v['createtime']){
|
||||
$week_start_time_seach = $v['createtime'];
|
||||
}
|
||||
if($v['quit_time'] && ($week_end_time_seach > $v['quit_time'])){
|
||||
$week_end_time_seach = $v['quit_time'];
|
||||
}
|
||||
$transaction_one = db::name('vs_give_gift')
|
||||
->whereIn('from_id',$v['room_id'])
|
||||
->where(['from'=>['in',[2,3,6]],'createtime' => ['between', [$week_start_time_seach, $week_end_time_seach]]])
|
||||
->sum('total_price');
|
||||
$transaction += $transaction_one;
|
||||
}
|
||||
|
||||
if($transaction > 0){
|
||||
//判断是否已经生成过
|
||||
if (db::name('vs_guild_subsidy')->where(['guild_id'=>$value['id'],'week'=>$time_value])->find()) {
|
||||
@@ -65,7 +77,7 @@ class Subsidy
|
||||
foreach ($config as $k => $v) {
|
||||
if ($transaction >= $v['end_amount']) {
|
||||
$subsidy_ratio = $v['subsidy_ratio'];
|
||||
$subsidy_amount = $transaction * ($subsidy_ratio / 100);
|
||||
$subsidy_amount = ($transaction * ($subsidy_ratio / 100)) / get_system_config_value('rmb_coin_ratio');//转为钻石
|
||||
break; // 找到匹配项后提前退出循环
|
||||
}
|
||||
}
|
||||
@@ -81,6 +93,7 @@ class Subsidy
|
||||
'status' => 0,
|
||||
'createtime' => time(),
|
||||
];
|
||||
// echo "工会".$value['id']."生成数据:流水金额:{$transaction} 补贴比例:{$subsidy_ratio}% 补贴金额:{$subsidy_amount}\n";
|
||||
$subsidy_id = Db::name('vs_guild_subsidy')->insertGetId($data);
|
||||
if ($subsidy_id) {
|
||||
echo "工会".$value['id']."生成成功(补贴ID:".$subsidy_id." 补贴金额:".$subsidy_amount.")\n";
|
||||
@@ -130,7 +143,7 @@ class Subsidy
|
||||
foreach ($config as $k => $v) {
|
||||
if ($transaction >= $v['end_amount']) {
|
||||
$subsidy_ratio = $v['subsidy_ratio'];
|
||||
$subsidy_amount = $transaction * ($subsidy_ratio / 100);
|
||||
$subsidy_amount = ($transaction * ($subsidy_ratio / 100)) / get_system_config_value('rmb_coin_ratio');//转为钻石;
|
||||
break; // 找到匹配项后提前退出循环
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,9 +18,14 @@ class TenSeconds
|
||||
echo "房间在线人数:\n";
|
||||
$this->auction_end_notice();//拍卖房结束提醒
|
||||
echo "\n";
|
||||
//清理切后台超过5分钟的用户
|
||||
echo "清理切后台超过5分钟的用户\n";
|
||||
$this->clear_offline_user();
|
||||
echo "\n";
|
||||
}
|
||||
|
||||
|
||||
//在线人数
|
||||
protected function auction_end_notice()
|
||||
{
|
||||
$auction_list = db::name('vs_room')->field('id')->where(['room_status'=>1,'apply_status' => 2,'type_id' =>['<>',6]])->select();
|
||||
@@ -40,17 +45,6 @@ class TenSeconds
|
||||
$data_number++;
|
||||
}
|
||||
}
|
||||
// else{
|
||||
// if($on_pit_num > 0){
|
||||
// $text = [
|
||||
// 'online_number' => $on_pit_num,
|
||||
// 'room_id' => $value['id'],//接受房间id
|
||||
// ];
|
||||
// model('api/Chat')->sendMsg(1036,$value['id'],$text);
|
||||
// $data_number++;
|
||||
// }
|
||||
// }
|
||||
|
||||
$data_count++;
|
||||
}
|
||||
}
|
||||
@@ -58,4 +52,18 @@ class TenSeconds
|
||||
echo "房间在线人数>0 的总共" . $data_number . "条数据\n";
|
||||
}
|
||||
|
||||
//清理切后台超过5分钟的用户
|
||||
protected function clear_offline_user()
|
||||
{
|
||||
$time = time() - 300;
|
||||
$user_list = db::name('vs_user_in_room_bg')->where('updatetime', '<=', $time)->select();
|
||||
if($user_list){
|
||||
foreach ($user_list as $v){
|
||||
//删除
|
||||
db::name('vs_user_in_room_bg')->delete($v['id']);
|
||||
model('api/Room')->quit_room($v['user_id'], $v['room_id'],$v['user_id'],2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user