GoodsCategoryLists.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. namespace app\workerapi\lists;
  3. use app\common\lists\ListsSearchInterface;
  4. use app\common\model\goods_category\GoodsCategory;
  5. /**
  6. * GoodsCategory列表
  7. * Class GoodsCategoryLists
  8. * @package app\api\lists\goods_category
  9. */
  10. class GoodsCategoryLists extends BaseWorkerDataLists implements ListsSearchInterface
  11. {
  12. /**
  13. * @notes 设置搜索条件
  14. * @return \string[][]
  15. * @author likeadmin
  16. * @date 2024/07/07 18:23
  17. */
  18. public function setSearch(): array
  19. {
  20. return [
  21. '=' => ['category_type', 'name', 'is_goods', 'status'],
  22. ];
  23. }
  24. /**
  25. * @notes 获取列表
  26. * @return array
  27. * @throws \think\db\exception\DataNotFoundException
  28. * @throws \think\db\exception\DbException
  29. * @throws \think\db\exception\ModelNotFoundException
  30. * @author whitef
  31. * @date 2024/07/07 18:23
  32. */
  33. public function lists(): array
  34. {
  35. $lists = GoodsCategory::where($this->searchWhere)
  36. ->field(['id', 'pid' ,'picture', 'name'])
  37. ->order(['weigh' => 'desc'])
  38. ->select()
  39. ->toArray();
  40. return linear_to_tree($lists, 'children', 'id', 'pid');
  41. }
  42. /**
  43. * @notes 获取数量
  44. * @return int
  45. * @author whitef
  46. * @date 2024/07/07 18:23
  47. */
  48. public function count(): int
  49. {
  50. return GoodsCategory::where($this->searchWhere)->count();
  51. }
  52. }