| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- <?php
- namespace App\Module\Team\Models;
- use App\Module\Team\Enums\PROFIT_SOURCE_TYPE;
- use UCore\ModelCore;
- /**
- * 收益分成规则
- *
- * field start
- * @property int $id 主键ID
- * @property \App\Module\Team\Enums\PROFIT_SOURCE_TYPE $source_type 来源类型
- * @property float $direct_profit_rate 直推分成比例
- * @property int $max_indirect_level 最大间推层级
- * @property bool $status 状态:1有效,0无效
- * @property array $rules 特殊规则
- * @property \Carbon\Carbon $created_at 创建时间
- * @property \Carbon\Carbon $updated_at 更新时间
- * field end
- */
- class TeamProfitRule extends ModelCore
- {
- /**
- * 与模型关联的表名
- *
- * @var string
- */
- protected $table = 'team_profit_rules';
- // attrlist start
- protected $fillable = [
- 'id',
- 'source_type',
- 'direct_profit_rate',
- 'max_indirect_level',
- 'status',
- 'rules',
- ];
- // attrlist end
- /**
- * 应该被转换为原生类型的属性
- *
- * @var array
- */
- protected $casts = [
- 'source_type' => PROFIT_SOURCE_TYPE::class,
- 'direct_profit_rate' => 'float',
- 'status' => 'boolean',
- 'rules' => 'json',
- ];
- /**
- * 获取规则的特定属性
- *
- * @param string $key
- * @param mixed $default
- * @return mixed
- */
- public function getRuleAttribute(string $key, $default = null)
- {
- if (empty($this->rules)) {
- return $default;
- }
- $rules = is_array($this->rules) ? $this->rules : json_decode($this->rules, true);
- return $rules[$key] ?? $default;
- }
- /**
- * 判断规则是否有效
- *
- * @return bool
- */
- public function isActive(): bool
- {
- return (bool)$this->status;
- }
- }
|