SparePartLists.php 1.5 KB

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