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; } }