multi-store/app/api/lists/cate/CateLists.php

87 lines
2.3 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\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 [
'=' => ['pid', 'name', 'data', 'store_id', '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
{
$leve = Request()->get('leve', 1);
$this->searchWhere[] = ['leve', '=', $leve];
$this->searchWhere[] = ['count', '>', 0];
$cate_arr = Db::name('store_product_cate')->where($this->searchWhere)->column('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();
}
// ->each(function ($item) {
// $a = Goodsclass::where('pid', $item['id'])->field(['id', 'pid', 'name', 'data', 'pic', 'sort'])->select();
// $item['children'] = $a;
// foreach ($a as $k => &$v) {
// $b = Goodsclass::where('pid', $v['id'])->field(['id', 'pid', 'name', 'data', 'pic', 'sort'])->select();
// $v['children'] = $b;
// }
// })->toArray();
return $lists;
// return linear_to_tree($lists, 'children');
}
/**
* @notes 获取商品分类数量
* @return int
* @author likeadmin
* @date 2024/04/23 10:27
*/
public function count(): int
{
return Db::name('store_product_cate')->where($this->searchWhere)
->count();
}
}