75 lines
1.8 KiB
PHP
75 lines
1.8 KiB
PHP
<?php
|
||
/**
|
||
* 时间:2023年03月02日
|
||
* 作者:墨楠小
|
||
* 邮箱:monanxiao@qq.com
|
||
* 商品分类模型
|
||
*
|
||
*/
|
||
namespace app\admin\model;
|
||
|
||
use think\Model;
|
||
|
||
class StoreCategory extends Model
|
||
{
|
||
// 设置当前模型的数据库连接
|
||
protected $connection = 'shop';
|
||
|
||
// 设置当前模型对应的完整数据表名称
|
||
protected $table = 'eb_store_category';
|
||
protected $pk = 'store_category_id';
|
||
|
||
/**
|
||
* 关联商品分类
|
||
*/
|
||
public function storeCategory()
|
||
{
|
||
return $this->hasOne(StoreCategory::class, 'store_category_id', 'pid');
|
||
}
|
||
|
||
/**
|
||
* 获取商品分类表数据
|
||
*@author Liuxiaoquan
|
||
*
|
||
*@param array $where 查询条件
|
||
*@return object|array $list 查询商品分类结果集
|
||
*/
|
||
public function getList($where)
|
||
{
|
||
$where['is_show'] = empty($where['is_show'])? 1 : $where['is_show'];
|
||
$list = self::search($where)
|
||
->field('store_category_id as id,pid,cate_name,path,sort,pic,level,is_hot')
|
||
->order('sort DESC')->select();
|
||
|
||
return $list;
|
||
}
|
||
|
||
/**
|
||
* 查询语句构建
|
||
*@author Liuxiaoquan
|
||
*
|
||
*@param array $where 查询条件
|
||
*@return Query
|
||
*/
|
||
protected function search($where)
|
||
{
|
||
$query = self::when(isset($where['mer_id'])&&$where['mer_id']!=='',
|
||
function ($query)use($where) {
|
||
$query->where('mer_id', $where['mer_id']);
|
||
}
|
||
)
|
||
->when(isset($where['level'])&&$where['level']!=='',
|
||
function($query)use($where){
|
||
$query->where('level', $where['level']);
|
||
}
|
||
)
|
||
->when(isset($where['is_show'])&&$where['is_show']!=='',
|
||
function($query)use($where){
|
||
$query->where('is_show', $where['is_show']);
|
||
}
|
||
);
|
||
|
||
return $query;
|
||
}
|
||
|
||
} |