| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186 |
- <?php
- namespace App\Module\UrsPromotion\Models;
- use UCore\ModelCore;
- /**
- * URS转账手续费配置模型
- * field start
- * @property int $id 主键ID
- * @property int $house_level 房屋等级(0表示所有等级)
- * @property int $talent_level 达人等级(0表示所有等级)
- * @property string $transfer_type 转账类型:in转入,out转出
- * @property float $fee_rate 手续费率(0-1之间的小数)
- * @property string $description 配置描述
- * @property int $priority 优先级(数值越大优先级越高)
- * @property int $status 状态:1启用,0禁用
- * @property \Carbon\Carbon $created_at 创建时间
- * @property \Carbon\Carbon $updated_at 更新时间
- * field end
- *
- */
- class UrsTransferFeeConfig extends ModelCore
- {
- /**
- * 数据库表名
- */
- protected $table = 'urs_promotion_transfer_fee_configs';
- /**
- * 可批量赋值的属性
- */
- protected $fillable = [
- 'house_level',
- 'talent_level',
- 'transfer_type',
- 'fee_rate',
- 'description',
- 'priority',
- 'status',
- ];
- /**
- * 属性类型转换
- */
- protected $casts = [
- 'house_level' => 'integer',
- 'talent_level' => 'integer',
- 'transfer_type' => 'string',
- 'fee_rate' => 'decimal:4',
- 'priority' => 'integer',
- 'status' => 'integer',
- 'created_at' => 'datetime',
- 'updated_at' => 'datetime',
- ];
- /**
- * 状态常量
- */
- const STATUS_DISABLED = 0; // 禁用
- const STATUS_ENABLED = 1; // 启用
- /**
- * 转账类型常量
- */
- const TYPE_IN = 'in'; // 转入
- const TYPE_OUT = 'out'; // 转出
- /**
- * 转账类型映射
- */
- public static $typeMap = [
- self::TYPE_IN => '转入',
- self::TYPE_OUT => '转出',
- ];
- /**
- * 检查配置是否启用
- */
- public function isEnabled(): bool
- {
- return $this->status === self::STATUS_ENABLED;
- }
- /**
- * 检查是否为转入类型
- */
- public function isTransferIn(): bool
- {
- return $this->transfer_type === self::TYPE_IN;
- }
- /**
- * 检查是否为转出类型
- */
- public function isTransferOut(): bool
- {
- return $this->transfer_type === self::TYPE_OUT;
- }
- /**
- * 获取转账类型文本
- */
- public function getTransferTypeText(): string
- {
- return self::$typeMap[$this->transfer_type] ?? '未知';
- }
- /**
- * 检查是否匹配指定的房屋等级
- *
- * @param int $houseLevel 房屋等级
- * @return bool
- */
- public function matchesHouseLevel(int $houseLevel): bool
- {
- return $this->house_level === 0 || $this->house_level === $houseLevel;
- }
- /**
- * 检查是否匹配指定的达人等级
- *
- * @param int $talentLevel 达人等级
- * @return bool
- */
- public function matchesTalentLevel(int $talentLevel): bool
- {
- return $this->talent_level === 0 || $this->talent_level === $talentLevel;
- }
- /**
- * 检查是否匹配指定的房屋等级和达人等级
- *
- * @param int $houseLevel 房屋等级
- * @param int $talentLevel 达人等级
- * @param string|null $transferType 转账类型
- * @return bool
- */
- public function matches(int $houseLevel, int $talentLevel, ?string $transferType = null): bool
- {
- $matchesLevels = $this->matchesHouseLevel($houseLevel) && $this->matchesTalentLevel($talentLevel);
- if ($transferType !== null) {
- return $matchesLevels && $this->transfer_type === $transferType;
- }
- return $matchesLevels;
- }
- /**
- * 获取手续费率百分比显示
- *
- * @return string
- */
- public function getFeeRatePercentage(): string
- {
- return number_format($this->fee_rate * 100, 2) . '%';
- }
- /**
- * 获取配置的匹配条件描述
- *
- * @return string
- */
- public function getMatchConditionDescription(): string
- {
- $conditions = [];
- // 转账类型
- $conditions[] = $this->getTransferTypeText();
- if ($this->house_level > 0) {
- $conditions[] = "房屋等级{$this->house_level}级";
- } else {
- $conditions[] = "所有房屋等级";
- }
- if ($this->talent_level > 0) {
- $conditions[] = "达人等级{$this->talent_level}级";
- } else {
- $conditions[] = "所有达人等级";
- }
- return implode(' + ', $conditions);
- }
- }
|