dggjimai/application/common/model/Goods.php

44 lines
866 B
PHP
Executable File

<?php
/**
* 商品模型
*/
namespace app\common\model;
use think\model\concern\SoftDelete;
class Goods extends Model
{
use SoftDelete;
public $softDelete = true;
protected $name = 'goods';
protected $autoWriteTimestamp = true;
//可搜索字段
protected $searchField = ['name',];
//是否上架获取器
public function getStatusTextAttr($value, $data)
{
return self::BOOLEAN_TEXT[$data['status']];
}
//关联商品分类
public function goodsCategory()
{
return $this->belongsTo(GoodsCategory::class);
}
//关联商品尺寸
public function goodsItem()
{
return $this->hasMany('goods_item', 'goods_id', 'id');
}
//关联品牌
public function goodsBrand()
{
return $this->hasOne('goods_brand','id','brand_id')->field('id,name');
}
}