// +---------------------------------------------------------------------- declare (strict_types = 1); namespace app\common\model; use app\common\library\helper; /** * 优惠券商品模型 * Class Coupon * @package app\common\model */ class CouponGood extends BaseModel { // 定义表名 protected $name = 'coupon_goods'; // 定义主键 protected $pk = 'id'; const EXCEPT_YES = 1; public function image() { $model = "app\\common\\model\\UploadFile"; return $this->belongsTo($model, 'image_id', 'file_id'); } /** * 获取器:规格属性 * @param $value * @return array */ public function getGoodsPropsAttr($value) { return helper::jsonDecode($value); } /** * 设置器:规格属性 * @param $value * @return string */ public function setGoodsPropsAttr($value) { return !empty($value) ? helper::jsonEncode($value) : ''; } /** * 获取记录 * @param int $id * @param array $with * @return static */ public static function detail(int $id, array $with = []) { return static::get($id, $with); } }