|
|
@@ -2,6 +2,8 @@
|
|
|
|
|
|
namespace App\Module\UrsPromotion\Logics;
|
|
|
|
|
|
+use App\Module\UrsPromotion\Enums\UrsProfitType;
|
|
|
+use App\Module\UrsPromotion\Models\UrsProfit;
|
|
|
use App\Module\UrsPromotion\Services\UrsReferralService;
|
|
|
use App\Module\UrsPromotion\Services\UrsTalentService;
|
|
|
use App\Module\UrsPromotion\Models\UrsTalentConfig;
|
|
|
@@ -12,14 +14,14 @@ use Illuminate\Support\Facades\DB;
|
|
|
|
|
|
/**
|
|
|
* URS推荐奖励补发逻辑层
|
|
|
- *
|
|
|
+ *
|
|
|
* 处理用户首次进入农场时的推荐奖励补发核心逻辑
|
|
|
*/
|
|
|
class UrsBackfillRewardLogic
|
|
|
{
|
|
|
/**
|
|
|
* 为用户补发推荐奖励
|
|
|
- *
|
|
|
+ *
|
|
|
* @param int $ursUserId URS用户ID
|
|
|
* @param int $farmUserId 农场用户ID
|
|
|
* @return array 补发结果
|
|
|
@@ -106,6 +108,41 @@ class UrsBackfillRewardLogic
|
|
|
'items_count' => count($directResult->items)
|
|
|
];
|
|
|
$totalBackfilledCount += count($directResult->items);
|
|
|
+ // 创建收益记录
|
|
|
+ $profit = UrsProfit::create([
|
|
|
+ 'urs_user_id' => $ursUserId,
|
|
|
+ 'urs_promotion_member_id' => 0,
|
|
|
+ 'promotion_member_farm_user_id' => 0,
|
|
|
+ 'farm_user_id' => $farmUserId,
|
|
|
+ 'source_id' => $directResult->sourceId,
|
|
|
+ 'source_type' => REWARD_SOURCE_TYPE::URSPROMOTION_BACKFILL->value(),
|
|
|
+ 'profit_type' => UrsProfitType::PLANTING_REWARD->value,
|
|
|
+ 'relation_level' => 1,
|
|
|
+ 'original_amount' => (string)0,
|
|
|
+ 'profit_amount' => (string)0, // 记录实际发放的物品数量
|
|
|
+ 'profit_rate' => 1,
|
|
|
+ 'reward_group_id' => $rewardGroups['direct'], // 种植收益不使用奖励组
|
|
|
+ 'talent_level' => $talentLevel,
|
|
|
+ 'status' => UrsProfit::STATUS_NORMAL,
|
|
|
+ ]);
|
|
|
+ }else{
|
|
|
+ // 创建收益记录-跳过
|
|
|
+ $profit = UrsProfit::create([
|
|
|
+ 'urs_user_id' => $ursUserId,
|
|
|
+ 'urs_promotion_member_id' => 0,
|
|
|
+ 'promotion_member_farm_user_id' => 0,
|
|
|
+ 'farm_user_id' => $farmUserId,
|
|
|
+ 'source_id' => 0,
|
|
|
+ 'source_type' => REWARD_SOURCE_TYPE::URSPROMOTION_BACKFILL->value(),
|
|
|
+ 'profit_type' => UrsProfitType::PLANTING_REWARD->value,
|
|
|
+ 'relation_level' => 1,
|
|
|
+ 'original_amount' => (string)0,
|
|
|
+ 'profit_amount' => (string)0, // 记录实际发放的物品数量
|
|
|
+ 'profit_rate' => 1,
|
|
|
+ 'reward_group_id' => $rewardGroups['direct'], // 种植收益不使用奖励组
|
|
|
+ 'talent_level' => $talentLevel,
|
|
|
+ 'status' => UrsProfit::STATUS_SKIPPED,
|
|
|
+ ]);
|
|
|
}
|
|
|
|
|
|
// 间推奖励
|
|
|
@@ -137,6 +174,41 @@ class UrsBackfillRewardLogic
|
|
|
'items_count' => count($indirectResult->items)
|
|
|
];
|
|
|
$totalBackfilledCount += count($indirectResult->items);
|
|
|
+ // 创建收益记录
|
|
|
+ $profit = UrsProfit::create([
|
|
|
+ 'urs_user_id' => $ursUserId,
|
|
|
+ 'urs_promotion_member_id' => 0,
|
|
|
+ 'promotion_member_farm_user_id' => 0,
|
|
|
+ 'farm_user_id' => $farmUserId,
|
|
|
+ 'source_id' => $directResult->sourceId,
|
|
|
+ 'source_type' => REWARD_SOURCE_TYPE::URSPROMOTION_BACKFILL->value(),
|
|
|
+ 'profit_type' => UrsProfitType::PLANTING_REWARD->value,
|
|
|
+ 'relation_level' => 2,
|
|
|
+ 'original_amount' => (string)0,
|
|
|
+ 'profit_amount' => (string)0, // 记录实际发放的物品数量
|
|
|
+ 'profit_rate' => 1,
|
|
|
+ 'reward_group_id' => $rewardGroups['direct'], // 种植收益不使用奖励组
|
|
|
+ 'talent_level' => $talentLevel,
|
|
|
+ 'status' => UrsProfit::STATUS_NORMAL,
|
|
|
+ ]);
|
|
|
+ }else{
|
|
|
+ // 创建收益记录-跳过
|
|
|
+ $profit = UrsProfit::create([
|
|
|
+ 'urs_user_id' => $ursUserId,
|
|
|
+ 'urs_promotion_member_id' => 0,
|
|
|
+ 'promotion_member_farm_user_id' => 0,
|
|
|
+ 'farm_user_id' => $farmUserId,
|
|
|
+ 'source_id' => 0,
|
|
|
+ 'source_type' => REWARD_SOURCE_TYPE::URSPROMOTION_BACKFILL->value(),
|
|
|
+ 'profit_type' => UrsProfitType::PLANTING_REWARD->value,
|
|
|
+ 'relation_level' => 2,
|
|
|
+ 'original_amount' => (string)0,
|
|
|
+ 'profit_amount' => (string)0, // 记录实际发放的物品数量
|
|
|
+ 'profit_rate' => 1,
|
|
|
+ 'reward_group_id' => $rewardGroups['direct'], // 种植收益不使用奖励组
|
|
|
+ 'talent_level' => $talentLevel,
|
|
|
+ 'status' => UrsProfit::STATUS_SKIPPED,
|
|
|
+ ]);
|
|
|
}
|
|
|
|
|
|
// 三推奖励
|
|
|
@@ -168,6 +240,41 @@ class UrsBackfillRewardLogic
|
|
|
'items_count' => count($thirdResult->items)
|
|
|
];
|
|
|
$totalBackfilledCount += count($thirdResult->items);
|
|
|
+ // 创建收益记录
|
|
|
+ $profit = UrsProfit::create([
|
|
|
+ 'urs_user_id' => $ursUserId,
|
|
|
+ 'urs_promotion_member_id' => 0,
|
|
|
+ 'promotion_member_farm_user_id' => 0,
|
|
|
+ 'farm_user_id' => $farmUserId,
|
|
|
+ 'source_id' => $directResult->sourceId,
|
|
|
+ 'source_type' => REWARD_SOURCE_TYPE::URSPROMOTION_BACKFILL->value(),
|
|
|
+ 'profit_type' => UrsProfitType::PLANTING_REWARD->value,
|
|
|
+ 'relation_level' => 2,
|
|
|
+ 'original_amount' => (string)0,
|
|
|
+ 'profit_amount' => (string)0, // 记录实际发放的物品数量
|
|
|
+ 'profit_rate' => 1,
|
|
|
+ 'reward_group_id' => $rewardGroups['direct'], // 种植收益不使用奖励组
|
|
|
+ 'talent_level' => $talentLevel,
|
|
|
+ 'status' => UrsProfit::STATUS_NORMAL,
|
|
|
+ ]);
|
|
|
+ }else{
|
|
|
+ // 创建收益记录-跳过
|
|
|
+ $profit = UrsProfit::create([
|
|
|
+ 'urs_user_id' => $ursUserId,
|
|
|
+ 'urs_promotion_member_id' => 0,
|
|
|
+ 'promotion_member_farm_user_id' => 0,
|
|
|
+ 'farm_user_id' => $farmUserId,
|
|
|
+ 'source_id' => 0,
|
|
|
+ 'source_type' => REWARD_SOURCE_TYPE::URSPROMOTION_BACKFILL->value(),
|
|
|
+ 'profit_type' => UrsProfitType::PLANTING_REWARD->value,
|
|
|
+ 'relation_level' => 3,
|
|
|
+ 'original_amount' => (string)0,
|
|
|
+ 'profit_amount' => (string)0, // 记录实际发放的物品数量
|
|
|
+ 'profit_rate' => 1,
|
|
|
+ 'reward_group_id' => $rewardGroups['direct'], // 种植收益不使用奖励组
|
|
|
+ 'talent_level' => $talentLevel,
|
|
|
+ 'status' => UrsProfit::STATUS_SKIPPED,
|
|
|
+ ]);
|
|
|
}
|
|
|
|
|
|
DB::commit();
|
|
|
@@ -198,7 +305,7 @@ class UrsBackfillRewardLogic
|
|
|
|
|
|
/**
|
|
|
* 检查用户是否需要补发推荐奖励
|
|
|
- *
|
|
|
+ *
|
|
|
* @param int $ursUserId URS用户ID
|
|
|
* @return bool
|
|
|
*/
|
|
|
@@ -249,14 +356,14 @@ class UrsBackfillRewardLogic
|
|
|
|
|
|
/**
|
|
|
* 获取用户当前达人等级
|
|
|
- *
|
|
|
+ *
|
|
|
* @param int $ursUserId URS用户ID
|
|
|
* @return int 达人等级,最低为0(青铜级)
|
|
|
*/
|
|
|
private function getUserTalentLevel(int $ursUserId): int
|
|
|
{
|
|
|
$talentDto = UrsTalentService::getTalentInfo($ursUserId);
|
|
|
-
|
|
|
+
|
|
|
// 如果用户没有达人等级记录,返回最低级(青铜级)
|
|
|
if (!$talentDto) {
|
|
|
return 0;
|