GoodsCategoryLists.php 1.8 KB

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