UrsTransferFeeConfig.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. <?php
  2. namespace App\Module\UrsPromotion\Models;
  3. use UCore\ModelCore;
  4. /**
  5. * URS转账手续费配置模型
  6. * field start
  7. * @property int $id 主键ID
  8. * @property int $house_level 房屋等级(0表示所有等级)
  9. * @property int $talent_level 达人等级(0表示所有等级)
  10. * @property string $transfer_type 转账类型:in转入,out转出
  11. * @property float $fee_rate 手续费率(0-1之间的小数)
  12. * @property string $description 配置描述
  13. * @property int $priority 优先级(数值越大优先级越高)
  14. * @property int $status 状态:1启用,0禁用
  15. * @property \Carbon\Carbon $created_at 创建时间
  16. * @property \Carbon\Carbon $updated_at 更新时间
  17. * field end
  18. *
  19. */
  20. class UrsTransferFeeConfig extends ModelCore
  21. {
  22. /**
  23. * 数据库表名
  24. */
  25. protected $table = 'urs_promotion_transfer_fee_configs';
  26. /**
  27. * 可批量赋值的属性
  28. */
  29. protected $fillable = [
  30. 'house_level',
  31. 'talent_level',
  32. 'transfer_type',
  33. 'fee_rate',
  34. 'description',
  35. 'priority',
  36. 'status',
  37. ];
  38. /**
  39. * 属性类型转换
  40. */
  41. protected $casts = [
  42. 'house_level' => 'integer',
  43. 'talent_level' => 'integer',
  44. 'transfer_type' => 'string',
  45. 'fee_rate' => 'decimal:4',
  46. 'priority' => 'integer',
  47. 'status' => 'integer',
  48. 'created_at' => 'datetime',
  49. 'updated_at' => 'datetime',
  50. ];
  51. /**
  52. * 状态常量
  53. */
  54. const STATUS_DISABLED = 0; // 禁用
  55. const STATUS_ENABLED = 1; // 启用
  56. /**
  57. * 转账类型常量
  58. */
  59. const TYPE_IN = 'in'; // 转入
  60. const TYPE_OUT = 'out'; // 转出
  61. /**
  62. * 转账类型映射
  63. */
  64. public static $typeMap = [
  65. self::TYPE_IN => '转入',
  66. self::TYPE_OUT => '转出',
  67. ];
  68. /**
  69. * 检查配置是否启用
  70. */
  71. public function isEnabled(): bool
  72. {
  73. return $this->status === self::STATUS_ENABLED;
  74. }
  75. /**
  76. * 检查是否为转入类型
  77. */
  78. public function isTransferIn(): bool
  79. {
  80. return $this->transfer_type === self::TYPE_IN;
  81. }
  82. /**
  83. * 检查是否为转出类型
  84. */
  85. public function isTransferOut(): bool
  86. {
  87. return $this->transfer_type === self::TYPE_OUT;
  88. }
  89. /**
  90. * 获取转账类型文本
  91. */
  92. public function getTransferTypeText(): string
  93. {
  94. return self::$typeMap[$this->transfer_type] ?? '未知';
  95. }
  96. /**
  97. * 检查是否匹配指定的房屋等级
  98. *
  99. * @param int $houseLevel 房屋等级
  100. * @return bool
  101. */
  102. public function matchesHouseLevel(int $houseLevel): bool
  103. {
  104. return $this->house_level === 0 || $this->house_level === $houseLevel;
  105. }
  106. /**
  107. * 检查是否匹配指定的达人等级
  108. *
  109. * @param int $talentLevel 达人等级
  110. * @return bool
  111. */
  112. public function matchesTalentLevel(int $talentLevel): bool
  113. {
  114. return $this->talent_level === 0 || $this->talent_level === $talentLevel;
  115. }
  116. /**
  117. * 检查是否匹配指定的房屋等级和达人等级
  118. *
  119. * @param int $houseLevel 房屋等级
  120. * @param int $talentLevel 达人等级
  121. * @param string|null $transferType 转账类型
  122. * @return bool
  123. */
  124. public function matches(int $houseLevel, int $talentLevel, ?string $transferType = null): bool
  125. {
  126. $matchesLevels = $this->matchesHouseLevel($houseLevel) && $this->matchesTalentLevel($talentLevel);
  127. if ($transferType !== null) {
  128. return $matchesLevels && $this->transfer_type === $transferType;
  129. }
  130. return $matchesLevels;
  131. }
  132. /**
  133. * 获取手续费率百分比显示
  134. *
  135. * @return string
  136. */
  137. public function getFeeRatePercentage(): string
  138. {
  139. return number_format($this->fee_rate * 100, 2) . '%';
  140. }
  141. /**
  142. * 获取配置的匹配条件描述
  143. *
  144. * @return string
  145. */
  146. public function getMatchConditionDescription(): string
  147. {
  148. $conditions = [];
  149. // 转账类型
  150. $conditions[] = $this->getTransferTypeText();
  151. if ($this->house_level > 0) {
  152. $conditions[] = "房屋等级{$this->house_level}级";
  153. } else {
  154. $conditions[] = "所有房屋等级";
  155. }
  156. if ($this->talent_level > 0) {
  157. $conditions[] = "达人等级{$this->talent_level}级";
  158. } else {
  159. $conditions[] = "所有达人等级";
  160. }
  161. return implode(' + ', $conditions);
  162. }
  163. }