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; } }