苹果用户 上架版本更新

This commit is contained in:
2025-12-30 19:31:56 +08:00
parent f05205b3c1
commit f5187c013e

View File

@@ -7,6 +7,7 @@ use think\Cache;
use think\Db;
use think\Log;
use app\common\model\GiveGiftBase;
use think\cache\driver\Redis;
class GiftQueue
{
@@ -40,7 +41,10 @@ class GiftQueue
$data = json_encode($queueData, JSON_UNESCAPED_UNICODE);
// 使用Redis列表存储
Cache::handler()->lpush(self::QUEUE_KEY, $data);
// Cache::handler()->lpush(self::QUEUE_KEY, $data);
$redis = new Redis(config('cache'));
$redis->handler()->lpush(self::QUEUE_KEY, $data);
Log::info("送礼记录已加入队列: {$queueData['uuid']}, 用户: {$giftData['user_id']}, 收礼人: {$giftData['gift_user']}");
@@ -94,7 +98,9 @@ class GiftQueue
for ($i = 0; $i < $batchSize; $i++) {
try {
// 从队列取数据
$data = Cache::handler()->rpop(self::QUEUE_KEY);
// $data = Cache::handler()->rpop(self::QUEUE_KEY);
$redis = new Redis(config('cache'));
$data = $redis->handler()->rpop(self::QUEUE_KEY);
if (!$data) {
break;
}
@@ -165,13 +171,17 @@ class GiftQueue
if ($queueData['retry_count'] <= self::MAX_RETRY) {
// 重新加入队列
$newData = json_encode($queueData, JSON_UNESCAPED_UNICODE);
Cache::handler()->lpush(self::QUEUE_KEY, $newData);
// Cache::handler()->lpush(self::QUEUE_KEY, $newData);
$redis = new Redis(config('cache'));
$redis->handler()->lpush(self::QUEUE_KEY, $newData);
Log::info("重试送礼记录: {$queueData['uuid']}, 重试次数: {$queueData['retry_count']}");
} else {
// 记录到失败队列
$queueData['fail_time'] = time();
$failedData = json_encode($queueData, JSON_UNESCAPED_UNICODE);
Cache::handler()->lpush(self::QUEUE_FAILED_KEY, $failedData);
// Cache::handler()->lpush(self::QUEUE_FAILED_KEY, $failedData);
$redis = new Redis(config('cache'));
$redis->handler()->lpush(self::QUEUE_FAILED_KEY, $failedData);
Log::error("送礼记录重试超过最大次数: {$queueData['uuid']}, 数据: " . json_encode($queueData['data']));
}
}
@@ -183,7 +193,9 @@ class GiftQueue
public static function size()
{
try {
return Cache::handler()->llen(self::QUEUE_KEY);
// return Cache::handler()->llen(self::QUEUE_KEY);
$redis = new Redis(config('cache'));
return $redis->handler()->lLen(self::QUEUE_KEY);
} catch (\Exception $e) {
Log::error('获取队列长度失败: ' . $e->getMessage());
return 0;
@@ -197,7 +209,9 @@ class GiftQueue
public static function failedSize()
{
try {
return Cache::handler()->llen(self::QUEUE_FAILED_KEY);
// return Cache::handler()->llen(self::QUEUE_FAILED_KEY);
$redis = new Redis(config('cache'));
return $redis->handler()->lLen(self::QUEUE_FAILED_KEY);
} catch (\Exception $e) {
Log::error('获取失败队列长度失败: ' . $e->getMessage());
return 0;
@@ -224,7 +238,9 @@ class GiftQueue
public static function clear()
{
try {
Cache::handler()->del(self::QUEUE_KEY);
// Cache::handler()->del(self::QUEUE_KEY);
$redis = new Redis(config('cache'));
$redis->handler()->del(self::QUEUE_KEY);
Log::info('送礼队列已清空');
return true;
} catch (\Exception $e) {
@@ -240,7 +256,9 @@ class GiftQueue
public static function clearFailed()
{
try {
Cache::handler()->del(self::QUEUE_FAILED_KEY);
// Cache::handler()->del(self::QUEUE_FAILED_KEY);
$redis = new Redis(config('cache'));
$redis->handler()->del(self::QUEUE_FAILED_KEY);
Log::info('送礼失败队列已清空');
return true;
} catch (\Exception $e) {