1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- <?php
- namespace app\admin\model\shop;
- use think\Model;
- use app\common\Enum\StatusEnum;
- use app\common\Enum\GoodsLabelEnum;
- class GoodsLabel extends Model
- {
- protected $name = 'shop_goods_label';
- protected $autoWriteTimestamp = 'int';
- protected $createTime = 'createtime';
- protected $updateTime = 'updatetime';
- protected $deleteTime = 'deletetime';
- protected $append = ['status_text', 'style_type_text'];
- public function getStatusList()
- {
- return StatusEnum::getMap();
- }
- public function getStyleTypeList()
- {
- return GoodsLabelEnum::getMap();
- }
- public function getStatusTextAttr($value, $data)
- {
- $value = $value ?: ($data['status'] ?? '');
- $list = $this->getStatusList();
- return $list[$value] ?? '';
- }
- public function getStyleTypeTextAttr($value, $data)
- {
- $value = $value ?: ($data['style_type'] ?? '');
- $list = $this->getStyleTypeList();
- return $list[$value] ?? '';
- }
- public function group()
- {
- return $this->belongsTo('GoodsLabelGroup', 'group_id', 'id');
- }
- public function getColorJsonAttr($value)
- {
- return is_string($value) ? (json_decode($value, true) ?: []) : [];
- }
- public function setColorJsonAttr($value)
- {
- return is_array($value) ? json_encode($value) : $value;
- }
- }
|