SparePartLists.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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\spare_part\SparePart;
  6. /**
  7. * SparePart列表
  8. * Class SparePartLists
  9. * @package app\workerapi\lists
  10. */
  11. class SparePartLists extends BaseWorkerDataLists implements ListsSearchInterface
  12. {
  13. /**
  14. * @notes 设置搜索条件
  15. * @return \string[][]
  16. * @author likeadmin
  17. * @date 2024/09/14 15:08
  18. */
  19. public function setSearch(): array
  20. {
  21. $this->params['spare_status'] = 1;
  22. return [
  23. '=' => ['spare_status'],
  24. '%like%' => ['spare_name']
  25. ];
  26. }
  27. /**
  28. * @notes 获取列表
  29. * @return array
  30. * @throws \think\db\exception\DataNotFoundException
  31. * @throws \think\db\exception\DbException
  32. * @throws \think\db\exception\ModelNotFoundException
  33. * @author likeadmin
  34. * @date 2024/09/14 15:08
  35. */
  36. public function lists(): array
  37. {
  38. //去除清洗的所有分类
  39. $goods_category_id = !empty($this->params['goods_category_id'])?$this->params['goods_category_id']:999999;
  40. return SparePart::where($this->searchWhere)
  41. ->where('goods_category_id',$goods_category_id)
  42. ->field(['id', 'goods_category_id', 'spare_name', 'spare_image', 'spare_number', 'spare_unit', 'company_price', 'original_price', 'offering_price', 'spare_status'])
  43. ->limit($this->limitOffset, $this->limitLength)
  44. ->order(['id' => 'desc'])
  45. ->select()
  46. ->toArray();
  47. }
  48. /**
  49. * @notes 获取数量
  50. * @return int
  51. * @author likeadmin
  52. * @date 2024/09/14 15:08
  53. */
  54. public function count(): int
  55. {
  56. return SparePart::where($this->searchWhere)->count();
  57. }
  58. }