红包超时退回
This commit is contained in:
@@ -50,16 +50,16 @@ class UserWallet extends Model
|
||||
// 1.系统调节 2.充值 3.提现 4.金币转增(送出) 5.每日任务奖励 6.充值返利 7.购买装扮
|
||||
// 8.礼盒奖励 9.房间补贴 10.购买礼物 11.收礼增加收益 12.工会补贴 13.转赠金币(接收) 14.收益兑换
|
||||
// 15.首充 16.天降好礼充值 17.退出工会扣款 18.房主收益 19.主持人收益,20.发布头条扣除余额,21.公会长收益,22.提现驳回或提现失败返还,23.财富等级奖励金币领取,24.删除关系扣金币
|
||||
//27.小时榜获得,28-新人充值好礼,32-发红包(金币),29-发红包(钻石),30-抢红包(金币),31-抢红包(钻石)
|
||||
//27.小时榜获得,28-新人充值好礼,32-发红包(金币),29-发红包(钻石),30-抢红包(金币),31-抢红包(钻石) 33-红包剩余退回(金币),34-红包剩余退回(钻石)
|
||||
if($gift_type == 1){ //1金币,2收益(钻石)
|
||||
if($in_out_type == 1){//1收入
|
||||
$in_out_types = [2,5,6,8,13,14,15,16,22,23,26,27,30,28];
|
||||
$in_out_types = [2,5,6,8,13,14,15,16,22,23,26,27,30,28,33];
|
||||
}elseif($in_out_type == 2){//2支出
|
||||
$in_out_types = [4,7,10,17,20,24,25,32];
|
||||
}
|
||||
}elseif($gift_type == 2){ //1金币,2收益(钻石)
|
||||
if($in_out_type == 1){//1收入
|
||||
$in_out_types = [6,9,11,12,18,19,21,22,31,28];
|
||||
$in_out_types = [6,9,11,12,18,19,21,22,31,28,34];
|
||||
}elseif($in_out_type == 2){//2支出
|
||||
$in_out_types = [3,14,29];
|
||||
}
|
||||
|
||||
@@ -86,6 +86,10 @@ class UserWallet extends Model
|
||||
const RED_PACKET_COIN_RECEIVE = 30;
|
||||
//抢红包(钻石)
|
||||
const RED_PACKET_DIAMOND_RECEIVE = 31;
|
||||
//红包剩余退回(金币),34-红包剩余退回(钻石)
|
||||
const RED_PACKET_LEFT_COIN = 33;
|
||||
//红包剩余退回(钻石)
|
||||
const RED_PACKET_LEFT_DIAMOND = 34;
|
||||
|
||||
//金币支出类型数组
|
||||
public $coin_consumption_type_array = [
|
||||
@@ -156,6 +160,8 @@ class UserWallet extends Model
|
||||
self::RED_PACKET_DIAMOND => '发红包(钻石)',
|
||||
self::RED_PACKET_COIN_RECEIVE => '抢红包(金币)',
|
||||
self::RED_PACKET_DIAMOND_RECEIVE => '抢红包(钻石)',
|
||||
self::RED_PACKET_LEFT_COIN => '红包剩余退回(金币)',
|
||||
self::RED_PACKET_LEFT_DIAMOND => '红包剩余退回(钻石)',
|
||||
];
|
||||
return $status[$type] ?? '';
|
||||
}
|
||||
|
||||
@@ -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,6 +33,9 @@ class PerformPerSecond
|
||||
echo "pk发起10秒后无应答拒绝:\n";
|
||||
$this->pk_start_refuse();
|
||||
echo "\n";
|
||||
echo "房间红包清退:\n";
|
||||
$this->processExpiredRedpackets();
|
||||
echo "\n";
|
||||
// echo "房间火热值更新:\n";
|
||||
// $this->room_hot_update();
|
||||
// echo "\n";
|
||||
@@ -228,4 +234,74 @@ class PerformPerSecond
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 处理过期红包退款
|
||||
*/
|
||||
public function processExpiredRedpackets()
|
||||
{
|
||||
$now = time();
|
||||
$redpacketModel = new Redpacket();
|
||||
|
||||
// 查找已结束但未退款的红包
|
||||
$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_REFUNDED,
|
||||
'updatetime' => $now
|
||||
]);
|
||||
|
||||
// 清理Redis缓存
|
||||
$redis = Cache::store('redis')->handler();
|
||||
$redisKey = "redpacket:{$redpacket['id']}";
|
||||
$redis->del($redisKey);
|
||||
|
||||
Db::commit();
|
||||
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
// 记录日志
|
||||
\think\Log::error("红包退款失败: {$redpacket['id']}, 错误: " . $e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user