refactor: banner新增相关分类数据字段
This commit is contained in:
@@ -17,12 +17,34 @@ class SysBannerItemModel extends SysBannerItemBaseModel
|
||||
// 软删除字段
|
||||
protected $deleteTime = 'deleted_at';
|
||||
|
||||
// 绑定产品分类关联模型中字段到父模型
|
||||
protected $append = ['rel_prod_cate_id', 'rel_prod_cate_name'];
|
||||
// 要隐藏的字段或关联模型数据字段
|
||||
protected $hidden = ['prod_mapping'];
|
||||
|
||||
// 关联分类
|
||||
public function banner()
|
||||
{
|
||||
return $this->belongsTo(SysBannerModel::class, 'banner_id', 'id');
|
||||
}
|
||||
|
||||
// 关联相关产品分类中间表模型
|
||||
public function prodMapping()
|
||||
{
|
||||
return $this->hasOne(SysBannerProdCateMappingModel::class, 'banner_item_id', 'id');
|
||||
}
|
||||
|
||||
// 从产品分类关联模型中获取id字段
|
||||
public function getRelProdCateIdAttr()
|
||||
{
|
||||
return $this->prodMapping?->category?->id;
|
||||
}
|
||||
// 从产品分类关联模型中获取name字段
|
||||
public function getRelProdCateNameAttr()
|
||||
{
|
||||
return $this->prodMapping?->category?->name;
|
||||
}
|
||||
|
||||
// 按横幅标题搜索
|
||||
public function searchTitleAttr($query, $value, $data)
|
||||
{
|
||||
|
||||
19
app/admin/model/v1/SysBannerProdCateMappingModel.php
Normal file
19
app/admin/model/v1/SysBannerProdCateMappingModel.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
declare (strict_types = 1);
|
||||
|
||||
namespace app\admin\model\v1;
|
||||
|
||||
use app\common\model\SysBannerProdCateMappingBaseModel;
|
||||
|
||||
/**
|
||||
* banner与产品分类关联表模型
|
||||
* @mixin \think\Model
|
||||
*/
|
||||
class SysBannerProdCateMappingModel extends SysBannerProdCateMappingBaseModel
|
||||
{
|
||||
// 关联产品分类
|
||||
public function category()
|
||||
{
|
||||
return $this->belongsTo(ProductCategoryModel::class, 'product_category_id', 'id');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user