GoodsCategoryLists.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. namespace app\workerapi\lists;
  3. use app\common\lists\ListsSearchInterface;
  4. use app\common\model\goods_category\GoodsCategory;
  5. use app\common\model\master_worker\MasterWorker;
  6. /**
  7. * GoodsCategory列表
  8. * Class GoodsCategoryLists
  9. * @package app\api\lists\goods_category
  10. */
  11. class GoodsCategoryLists extends BaseWorkerDataLists 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. $where = [];
  27. if(!empty($this->userId)){
  28. $ids = explode(',', MasterWorker::where('id', $this->userId)->value('category_ids'));
  29. $ids && $where[] = ['id', 'in', $ids];
  30. }
  31. return $where;
  32. }
  33. /**
  34. * @notes 获取列表
  35. * @return array
  36. * @throws \think\db\exception\DataNotFoundException
  37. * @throws \think\db\exception\DbException
  38. * @throws \think\db\exception\ModelNotFoundException
  39. * @author whitef
  40. * @date 2024/07/07 18:23
  41. */
  42. public function lists(): array
  43. {
  44. $lists = GoodsCategory::where($this->searchWhere)
  45. //->where($this->queryWhere())
  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)->count();
  61. }
  62. }