更新
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";
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user