| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- <?php
- namespace App\Module\UrsPromotion\Services;
- use App\Module\UrsPromotion\Logics\UrsProfitLogic;
- use App\Module\UrsPromotion\Enums\UrsProfitType;
- /**
- * URS收益分成服务
- *
- * 对外提供URS收益分成相关的服务接口
- */
- class UrsProfitService
- {
- /**
- * 分发推广收益
- *
- * 当新用户注册时调用此方法分发推广收益(按人头奖励)
- *
- * @param int $userId 新注册用户ID
- * @param string $sourceType 收益来源类型
- * @param int $sourceId 收益来源ID
- * @return array 分成记录
- */
- public static function distributePromotionReward(
- int $userId,
- string $sourceType,
- int $sourceId
- ): array {
- $logic = new UrsProfitLogic();
- return $logic->distributePromotionReward(
- $userId,
- $sourceType,
- $sourceId
- );
- }
-
- /**
- * 分发种植收益
- *
- * 当下级用户收获作物时调用此方法分发种植收益
- *
- * @param int $userId 产生收益的用户ID
- * @param string $sourceType 收益来源类型
- * @param int $sourceId 收益来源ID
- * @param int $originalAmount 原始收益数量(整数)
- * @param int $itemId 收获的物品ID
- * @return array 分成记录
- */
- public static function distributePlantingReward(
- int $userId,
- string $sourceType,
- int $sourceId,
- int $originalAmount,
- int $itemId
- ): array {
- $logic = new UrsProfitLogic();
- return $logic->distributePlantingReward(
- $userId,
- $sourceType,
- $sourceId,
- $originalAmount,
- $itemId
- );
- }
-
- /**
- * 获取用户的收益统计
- *
- * @param int $userId 用户ID
- * @param string|null $profitType 收益类型
- * @param string|null $startDate 开始日期
- * @param string|null $endDate 结束日期
- * @return array
- */
- public static function getUserProfitStats(
- int $userId,
- ?string $profitType = null,
- ?string $startDate = null,
- ?string $endDate = null
- ): array {
- $logic = new UrsProfitLogic();
-
- $profitTypeEnum = null;
- if ($profitType) {
- $profitTypeEnum = UrsProfitType::fromString($profitType);
- }
-
- return $logic->getUserProfitStats($userId, $profitTypeEnum, $startDate, $endDate);
- }
-
- /**
- * 获取用户的推广收益统计
- *
- * @param int $userId 用户ID
- * @param string|null $startDate 开始日期
- * @param string|null $endDate 结束日期
- * @return array
- */
- public static function getUserPromotionRewardStats(
- int $userId,
- ?string $startDate = null,
- ?string $endDate = null
- ): array {
- return self::getUserProfitStats($userId, UrsProfitType::PROMOTION_REWARD->value, $startDate, $endDate);
- }
-
- /**
- * 获取用户的种植收益统计
- *
- * @param int $userId 用户ID
- * @param string|null $startDate 开始日期
- * @param string|null $endDate 结束日期
- * @return array
- */
- public static function getUserPlantingRewardStats(
- int $userId,
- ?string $startDate = null,
- ?string $endDate = null
- ): array {
- return self::getUserProfitStats($userId, UrsProfitType::PLANTING_REWARD->value, $startDate, $endDate);
- }
- }
|