异步更新数据

This commit is contained in:
2025-12-30 23:49:48 +08:00
parent f5187c013e
commit bb68bdd25b
2 changed files with 38 additions and 26 deletions

View File

@@ -7,6 +7,7 @@ use think\Log;
use think\Model;
use think\Session;
use think\Db;
use app\common\library\GiftQueue;
class GiveGift extends Model
{
@@ -1000,13 +1001,23 @@ class GiveGift extends Model
'type' => $type,//1金币购买 2送背包礼物
'createtime' => time(),
];
$res = Db::name('vs_give_gift')->insertGetId($data);
if(!$res){
return false;
GiftQueue::push($data);
return true;
}
//送礼回调处理任务
public function change_user_give_gift_log_callback($give_gift_id,$data)
{
$from_id = $data['from_id'];
$uid = $data['user_id'];
$to_id = $data['gift_user'];
$gift_price = $data['total_price'];
$gid = $data['gift_id'];
//记录公会流水
if($from_type==2 && $from_id > 0){
model('api/Guild')->guild_flow($from_id,$gift_price,$res);
if($from_id > 0){
model('api/Guild')->guild_flow($from_id,$gift_price,$give_gift_id);
}
//查询是否第一次送礼
$is_first_gift = db::name('vs_give_gift')->where(['user_id'=>$uid])->count();
@@ -1069,8 +1080,6 @@ class GiveGift extends Model
// }
}
}
return $res;
}

View File

@@ -8,6 +8,7 @@ use think\Db;
use think\Log;
use app\common\model\GiveGiftBase;
use think\cache\driver\Redis;
use app\api\model\GiveGift;
class GiftQueue
{
@@ -92,6 +93,7 @@ class GiftQueue
$failed = 0;
$model = new GiveGiftBase();
$gift_model = new GiveGift();
Log::info("开始处理送礼队列,批量大小: {$batchSize}");
@@ -129,6 +131,7 @@ class GiftQueue
if ($result) {
$success++;
$gift_model->change_user_give_gift_log_callback($result, $giftData);
Log::info("送礼记录处理成功: {$uuid}, ID: {$result}");
} else {
$failed++;