105 lines
3.1 KiB
PHP
105 lines
3.1 KiB
PHP
<?php
|
|
|
|
namespace app\api\lists\cate;
|
|
|
|
|
|
use app\admin\lists\BaseAdminDataLists;
|
|
use app\common\model\cate\Cate;
|
|
use app\common\lists\ListsSearchInterface;
|
|
use app\common\model\store_product\StoreProduct;
|
|
use app\Request;
|
|
use think\facade\Db;
|
|
|
|
/**
|
|
* 商品分类列表
|
|
* Class GoodsclassLists
|
|
* @package app\admin\listsgoods
|
|
*/
|
|
class CateLists extends BaseAdminDataLists implements ListsSearchInterface
|
|
{
|
|
|
|
protected $where;
|
|
/**
|
|
* @notes 设置搜索条件
|
|
* @return \string[][]
|
|
* @author likeadmin
|
|
* @date 2024/04/23 10:27
|
|
*/
|
|
public function setSearch(): array
|
|
{
|
|
return [
|
|
'=' => ['name', 'data', 'sort'],
|
|
];
|
|
}
|
|
|
|
|
|
/**
|
|
* @notes 获取商品分类列表
|
|
* @return array
|
|
* @throws \think\db\exception\DataNotFoundException
|
|
* @throws \think\db\exception\DbException
|
|
* @throws \think\db\exception\ModelNotFoundException
|
|
* @author likeadmin
|
|
* @date 2024/04/23 10:27
|
|
*/
|
|
public function lists(): array
|
|
{
|
|
$level = Request()->get('level', 1);
|
|
$source = Request()->get('source');
|
|
$pid = $this->request->get('pid',0);
|
|
// $this->searchWhere[] = ['stock', '>', 0];
|
|
$this->searchWhere[] = ['is_show', '=', 1];
|
|
if($source && $source==4){
|
|
$this->searchWhere[] = ['product_type', '=', 5];
|
|
}
|
|
if($pid && $level ==2){
|
|
$this->searchWhere[] = ['top_cate_id','=',$pid];
|
|
$cate_arr = StoreProduct::where($this->searchWhere)->distinct()
|
|
->column('two_cate_id');
|
|
}elseif($pid && $level ==3){
|
|
$this->searchWhere[] = ['two_cate_id','=',$pid];
|
|
$cate_arr = StoreProduct::where($this->searchWhere)->distinct()
|
|
->column('cate_id');
|
|
}else{
|
|
$cate_arr = StoreProduct::where($this->searchWhere)->distinct()
|
|
->column('top_cate_id');
|
|
}
|
|
$lists = [];
|
|
if ($cate_arr) {
|
|
return Cate::where('id', 'in', $cate_arr)
|
|
->field(['id', 'pid', 'name', 'data', 'pic', 'sort'])
|
|
->limit($this->limitOffset, $this->limitLength)
|
|
->order(['sort' => 'desc', 'id' => 'desc'])
|
|
->select()->toArray();
|
|
}
|
|
return $lists;
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
* @notes 获取商品分类数量
|
|
* @return int
|
|
* @author likeadmin
|
|
* @date 2024/04/23 10:27
|
|
*/
|
|
public function count(): int
|
|
{
|
|
$level = Request()->get('level', 1);
|
|
$pid = $this->request->get('pid',0);
|
|
if($pid && $level ==2){
|
|
$this->searchWhere[] = ['top_cate_id','=',$pid];
|
|
$cate_arr = StoreProduct::where($this->searchWhere)->distinct()
|
|
->column('two_cate_id');
|
|
}elseif($pid && $level ==3){
|
|
$this->searchWhere[] = ['two_cate_id','=',$pid];
|
|
$cate_arr = StoreProduct::where($this->searchWhere)->distinct()
|
|
->column('cate_id');
|
|
}else{
|
|
$cate_arr = StoreProduct::where($this->searchWhere)->distinct()
|
|
->column('top_cate_id');
|
|
}
|
|
return Cate::where('id', 'in', $cate_arr)->count();
|
|
}
|
|
}
|