ServiceWorkSparePartLists.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. namespace app\workerapi\lists;
  3. use app\common\lists\ListsSearchInterface;
  4. use app\common\model\works\ServiceWork;
  5. use app\common\model\works\ServiceWorkSpare;
  6. /**
  7. * SparePart列表
  8. * Class SparePartLists
  9. * @package app\workerapi\lists
  10. */
  11. class ServiceWorkSparePartLists extends BaseWorkerDataLists implements ListsSearchInterface
  12. {
  13. protected $count = 0;
  14. /**
  15. * 设置搜索条件
  16. * @return array[]
  17. * @author liuguanci
  18. * @date 2024/7/11 下午1:46
  19. */
  20. public function setSearch(): array
  21. {
  22. if(isset($this->params['user_id']) && !empty($this->params['user_id'])){
  23. $this->params['master_worker_id'] = $this->params['user_id'];
  24. }
  25. return [
  26. '=' => ['work_sn','master_worker_id'],
  27. ];
  28. }
  29. /*
  30. * 查询条件
  31. * @return array
  32. * @author liuguanci
  33. * @date 2024/7/11 下午1:46
  34. */
  35. public function queryWhere(){
  36. $where = [];
  37. if(isset($this->params['spare_name']) && !empty($this->params['spare_name'])){
  38. $where[] = ['spare_name','like','%'.$this->params['spare_name'].'%'];
  39. }
  40. return $where;
  41. }
  42. /**
  43. * @notes 获取列表
  44. * @return array
  45. * @throws \think\db\exception\DataNotFoundException
  46. * @throws \think\db\exception\DbException
  47. * @throws \think\db\exception\ModelNotFoundException
  48. * @author likeadmin
  49. * @date 2024/09/14 15:08
  50. */
  51. public function lists(): array
  52. {
  53. // 配件信息
  54. $id = ServiceWork::where($this->searchWhere)->value('id');
  55. $spare_parts = [];
  56. if($id){
  57. $spare_parts['spare_parts'] = ServiceWorkSpare::getLists($id, 1);
  58. $spare_parts['self_spare_parts'] = ServiceWorkSpare::getLists($id, 2);
  59. }
  60. return $spare_parts?array_values($spare_parts):[];
  61. }
  62. /**
  63. * @notes 获取数量
  64. * @return int
  65. * @author likeadmin
  66. * @date 2024/09/14 15:08
  67. */
  68. public function count(): int
  69. {
  70. return $this->count;
  71. }
  72. }