12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- <?php
- namespace app\admin\model;
- use think\Model;
- class Product extends Model
- {
-
-
- // 表名
- protected $name = 'product';
-
- // 自动写入时间戳字段
- protected $autoWriteTimestamp = 'int';
- // 定义时间戳字段名
- protected $createTime = 'createtime';
- protected $updateTime = false;
- protected $deleteTime = false;
- // 追加属性
- protected $append = [
- 'attribute_text'
- ];
-
-
- public function getAttributeList()
- {
- return ['新上架产品' => __('新上架产品'), '在售产品' => __('在售产品'), '停售产品' => __('停售产品')];
- }
- public function getAttributeTextAttr($value, $data)
- {
- $value = $value ? $value : (isset($data['attribute']) ? $data['attribute'] : '');
- $list = $this->getAttributeList();
- return isset($list[$value]) ? $list[$value] : '';
- }
- public function company()
- {
- return $this->belongsTo('company','company_id','id',[],'LEFT')->setEagerlyType(0);
- }
- public function category()
- {
- return $this->belongsTo('category','category_id','id',[],'LEFT')->setEagerlyType(0);
- }
- }
|