| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- <?php
- namespace app\workerapi\lists;
- use app\common\lists\ListsSearchInterface;
- use app\common\model\goods_category\GoodsCategory;
- use app\common\model\master_worker\MasterWorker;
- use think\facade\Log;
- /**
- * GoodsCategory列表
- * Class GoodsCategoryLists
- * @package app\api\lists\goods_category
- */
- class GoodsCategoryLists extends BaseWorkerDataLists 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(!empty($this->userId)){
- $ids = explode(',', MasterWorker::where('id', $this->userId)->value('category_ids'));
- if(!empty($ids)){
- $category_types = GoodsCategory::where('id', 'in', $ids)->group('category_type')->column('category_type');
- $where[] = ['category_type','in', implode(',', $category_types)];
- }
- }
- 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())
- ->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();
- }
- }
|