Files

83 lines
1.8 KiB
PHP

<?php
namespace app\admin\model\app\physical;
use think\Model;
class Goods extends Model
{
// 表名
protected $name = 'app_physical_goods';
// 自动写入时间戳字段
protected $autoWriteTimestamp = 'integer';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
protected $deleteTime = false;
// 追加属性
protected $append = [
'status_text',
'spec_type_text'
];
// 允许填充的字段
protected $field = true;
public function getStatusList()
{
return [1 => '上架', 0 => '下架'];
}
public function getSpecTypeList()
{
return ['single' => '单规格', 'multi' => '多规格'];
}
public function getIsHiddenList()
{
return ['0' => '否', '1' => '是'];
}
public function getStatusTextAttr($value, $data)
{
$value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
$list = $this->getStatusList();
return isset($list[$value]) ? $list[$value] : '';
}
public function getSpecTypeTextAttr($value, $data)
{
$value = $value ? $value : (isset($data['spec_type']) ? $data['spec_type'] : '');
$list = $this->getSpecTypeList();
return isset($list[$value]) ? $list[$value] : '';
}
public function getCarouselAttr($value, $data)
{
$value = $value ? $value : (isset($data['carousel']) ? $data['carousel'] : '');
if (empty($value)) {
return [];
}
$carousel = json_decode($value, true);
return is_array($carousel) ? $carousel : [];
}
public function skus()
{
return $this->hasMany('app\admin\model\app\physical\Sku', 'goods_id', 'id');
}
}