UrsProfitService.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <?php
  2. namespace App\Module\UrsPromotion\Services;
  3. use App\Module\UrsPromotion\Logics\UrsProfitLogic;
  4. use App\Module\UrsPromotion\Enums\UrsProfitType;
  5. /**
  6. * URS收益分成服务
  7. *
  8. * 对外提供URS收益分成相关的服务接口
  9. */
  10. class UrsProfitService
  11. {
  12. /**
  13. * 分发推广收益
  14. *
  15. * 当新用户注册时调用此方法分发推广收益(按人头奖励)
  16. *
  17. * @param int $userId 新注册用户ID
  18. * @param string $sourceType 收益来源类型
  19. * @param int $sourceId 收益来源ID
  20. * @return array 分成记录
  21. */
  22. public static function distributePromotionReward(
  23. int $userId,
  24. string $sourceType,
  25. int $sourceId
  26. ): array {
  27. $logic = new UrsProfitLogic();
  28. return $logic->distributePromotionReward(
  29. $userId,
  30. $sourceType,
  31. $sourceId
  32. );
  33. }
  34. /**
  35. * 分发种植收益
  36. *
  37. * 当下级用户收获作物时调用此方法分发种植收益
  38. *
  39. * @param int $userId 产生收益的用户ID
  40. * @param string $sourceType 收益来源类型
  41. * @param int $sourceId 收益来源ID
  42. * @param int $originalAmount 原始收益数量(整数)
  43. * @param int $itemId 收获的物品ID
  44. * @return array 分成记录
  45. */
  46. public static function distributePlantingReward(
  47. int $userId,
  48. string $sourceType,
  49. int $sourceId,
  50. int $originalAmount,
  51. int $itemId
  52. ): array {
  53. $logic = new UrsProfitLogic();
  54. return $logic->distributePlantingReward(
  55. $userId,
  56. $sourceType,
  57. $sourceId,
  58. $originalAmount,
  59. $itemId
  60. );
  61. }
  62. /**
  63. * 获取用户的收益统计
  64. *
  65. * @param int $userId 用户ID
  66. * @param string|null $profitType 收益类型
  67. * @param string|null $startDate 开始日期
  68. * @param string|null $endDate 结束日期
  69. * @return array
  70. */
  71. public static function getUserProfitStats(
  72. int $userId,
  73. ?string $profitType = null,
  74. ?string $startDate = null,
  75. ?string $endDate = null
  76. ): array {
  77. $logic = new UrsProfitLogic();
  78. $profitTypeEnum = null;
  79. if ($profitType) {
  80. $profitTypeEnum = UrsProfitType::fromString($profitType);
  81. }
  82. return $logic->getUserProfitStats($userId, $profitTypeEnum, $startDate, $endDate);
  83. }
  84. /**
  85. * 获取用户的推广收益统计
  86. *
  87. * @param int $userId 用户ID
  88. * @param string|null $startDate 开始日期
  89. * @param string|null $endDate 结束日期
  90. * @return array
  91. */
  92. public static function getUserPromotionRewardStats(
  93. int $userId,
  94. ?string $startDate = null,
  95. ?string $endDate = null
  96. ): array {
  97. return self::getUserProfitStats($userId, UrsProfitType::PROMOTION_REWARD->value, $startDate, $endDate);
  98. }
  99. /**
  100. * 获取用户的种植收益统计
  101. *
  102. * @param int $userId 用户ID
  103. * @param string|null $startDate 开始日期
  104. * @param string|null $endDate 结束日期
  105. * @return array
  106. */
  107. public static function getUserPlantingRewardStats(
  108. int $userId,
  109. ?string $startDate = null,
  110. ?string $endDate = null
  111. ): array {
  112. return self::getUserProfitStats($userId, UrsProfitType::PLANTING_REWARD->value, $startDate, $endDate);
  113. }
  114. }