用户反馈推广信息接口响应中缺少 today_reward 和 total_reward 字段数据,日志显示这两个字段没有数据。
promotionInfo 中没有 today_reward 和 total_reward 字段user_logs 表发现用户39077确实有URS推广奖励记录通过查看 user_logs 表发现用户39077有以下URS推广奖励:
-- 用户39077的URS推广奖励记录
ID: 741001 - "urs_promotion_harvest获得萝卜 11" (2025-06-22)
ID: 707198 - "urs_promotion_harvest获得辣椒 10" (2025-06-21)
ID: 707158 - "urs_promotion_harvest获得萝卜 6" (2025-06-21)
对应的 item_transaction_logs 记录:
ID: 11027 - 萝卜(item_id:2) 11个, source_type: 'urs_promotion_harvest'
ID: 11011 - 辣椒(item_id:3) 10个, source_type: 'urs_promotion_harvest'
ID: 10991 - 萝卜(item_id:2) 6个, source_type: 'urs_promotion_harvest'
查询逻辑错误:InfoHandler 中的 getRewardStatsFromLogs 方法只查询了 game_reward_logs 表,但实际的URS推广奖励记录存储在 item_transaction_logs 表中。
修改 InfoHandler 确保 today_reward 和 total_reward 字段始终存在:
setEmptyResponse 方法设置空奖励字段createEmptyReward 方法创建空奖励对象在 getRewardStatsFromLogs 方法中添加对 ItemTransactionLog 表的查询:
item_transaction_logs 表的查询逻辑transaction_type = 1(收入类型)且 source_type 为URS推广相关类型App\Module\GameItems\Models\ItemTransactionLogapp/Module/AppGame/Handler/Promotion/InfoHandler.php// 设置收益数据 - 始终设置奖励字段,没有数据时使用空奖励对象
$todayReward = $rewardStats['today_reward'] ?? $this->createEmptyReward();
$totalReward = $rewardStats['total_reward'] ?? $this->createEmptyReward();
$response->setTodayReward($todayReward);
$response->setTotalReward($totalReward);
// 设置空的奖励对象
$emptyReward = $this->createEmptyReward();
$response->setTodayReward($emptyReward);
$response->setTotalReward($emptyReward);
private function createEmptyReward(): Reward
{
$reward = new Reward();
$reward->setItems([]);
$reward->setCoins([]);
$reward->setGods([]);
$reward->setLands([]);
$reward->setPets([]);
$reward->setPetPowers([]);
$reward->setSkins([]);
return $reward;
}
// 1.1. 从物品交易日志表中统计URS推广奖励(补充查询)
$itemQuery = \App\Module\GameItems\Models\ItemTransactionLog::where('user_id', $farmUserId)
->where('transaction_type', 1) // 收入类型
->whereIn('source_type', $ursPromotionSourceTypes);
if ($startDate) {
$itemQuery->where('created_at', '>=', $startDate);
}
if ($endDate) {
$itemQuery->where('created_at', '<=', $endDate);
}
$itemLogs = $itemQuery->get();
foreach ($itemLogs as $log) {
$stats['total_count']++;
$itemId = $log->item_id;
$quantity = $log->quantity;
if ($itemId > 0) {
// 累加相同物品的数量
if (isset($stats['items'][$itemId])) {
$stats['items'][$itemId] += $quantity;
} else {
$stats['items'][$itemId] = $quantity;
}
}
// 按来源类型统计
$sourceType = $log->source_type;
if (!isset($stats['by_source_type'][$sourceType])) {
$stats['by_source_type'][$sourceType] = ['amount' => 0, 'count' => 0];
}
$stats['by_source_type'][$sourceType]['count']++;
}
{
"promotionInfo": {
"totalCount": "1",
"directCount": "1",
"activeCount": "1",
"directActiveCount": "1"
// 缺少 todayReward 和 totalReward 字段
}
}
{
"promotionInfo": {
"totalCount": "1",
"directCount": "1",
"activeCount": "1",
"directActiveCount": "1",
"todayReward": {
"items": [
{
"itemId": "2",
"quantity": "11"
}
]
},
"totalReward": {
"items": [
{
"itemId": "2",
"quantity": "17"
},
{
"itemId": "3",
"quantity": "10"
}
]
}
}
}
通过分析用户日志发现了查询逻辑的根本问题,URS推广奖励实际存储在 item_transaction_logs 表而非 game_reward_logs 表。修复后接口能够正确显示用户的推广奖励数据,解决了前端显示问题。