| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- <?php
- namespace app\api\lists;
- use app\api\logic\GoodsLogic;
- use app\common\model\goods_category\GoodsCategory;
- use app\common\lists\ListsSearchInterface;
- /**
- * GoodsCategory列表
- * Class GoodsCategoryLists
- * @package app\api\lists\goods_category
- */
- class GoodsCategoryLists extends BaseApiDataLists implements ListsSearchInterface
- {
- /**
- * @notes 设置搜索条件
- * @return \string[][]
- * @author likeadmin
- * @date 2024/07/07 18:23
- */
- public function setSearch(): array
- {
- return [
- '=' => ['category_type', 'name', 'is_goods', 'status'],
- ];
- }
- public function queryWhere()
- {
- $where = [];
- if (isset($this->params['platform_appid']) && !empty($this->params['platform_appid'])) {
- $ids = GoodsLogic::getPlatformCategoryIds($this->params['platform_appid']);
- $where[] = ['id','in' ,$ids];
- }
- return $where;
- }
- /**
- * @notes 获取列表
- * @return array
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- * @author whitef
- * @date 2024/07/07 18:23
- */
- public function lists(): array
- {
- $lists = GoodsCategory::where($this->searchWhere)->where($this->queryWhere())->where('status',1)
- ->field(['id', 'pid' ,'picture', 'name'])
- ->order(['weigh' => 'desc'])
- ->select()
- ->toArray();
- return linear_to_tree($lists, 'children', 'id', 'pid');
- }
- /**
- * @notes 获取数量
- * @return int
- * @author whitef
- * @date 2024/07/07 18:23
- */
- public function count(): int
- {
- return GoodsCategory::where($this->searchWhere)->where($this->queryWhere())->count();
- }
- }
|