www.maiwd.cn // +---------------------------------------------------------------------- namespace app\admin\model\wdsxh\mall; use think\Model; use traits\model\SoftDelete; class Goods extends Model { use SoftDelete; // 表名 protected $name = 'wdsxh_mall_goods'; // 自动写入时间戳字段 protected $autoWriteTimestamp = 'integer'; // 定义时间戳字段名 protected $createTime = 'createtime'; protected $updateTime = 'updatetime'; protected $deleteTime = 'deletetime'; // 追加属性 protected $append = [ 'is_hot_text', 'status_text' ]; protected static function init() { self::afterInsert(function ($row) { $pk = $row->getPk(); $row->getQuery()->where($pk, $row[$pk])->update(['weigh' => $row[$pk]]); }); } public function getIsHotList() { return ['1' => __('Is_hot 1'), '0' => __('Is_hot 0')]; } public function getStatusList() { return ['normal' => __('Status normal'), 'hidden' => __('Status hidden')]; } public function getIsHotTextAttr($value, $data) { $value = $value ? $value : (isset($data['is_hot']) ? $data['is_hot'] : ''); $list = $this->getIsHotList(); return isset($list[$value]) ? $list[$value] : ''; } public function getStatusTextAttr($value, $data) { $value = $value ? $value : (isset($data['status']) ? $data['status'] : ''); $list = $this->getStatusList(); return isset($list[$value]) ? $list[$value] : ''; } public function category() { return $this->belongsTo('app\admin\model\wdsxh\mall\GoodsCategory','category_id','id')->setEagerlyType(0); } }