| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- <?php
- namespace App\Module\Promotion\Models;
- use App\Module\Promotion\Enums\PROFIT_SOURCE_TYPE;
- use UCore\ModelCore;
- /**
- * 收益分成规则
- *
- * field start
- * field end
- */
- class PromotionProfitRule extends ModelCore
- {
- /**
- * 与模型关联的表名
- *
- * @var string
- */
- protected $table = 'promotion_profit_rules';
- // attrlist start
- protected $fillable = [
- ];
- // 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;
- }
- }
|