StationTaskBatchService.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. namespace App\Services;
  3. use App\Batch;
  4. use App\Station;
  5. use App\StationTaskBatch;
  6. use App\StationTaskBatchType;
  7. use Exception;
  8. use Illuminate\Support\Collection;
  9. use Illuminate\Support\Facades\Cache;
  10. class StationTaskBatchService
  11. {
  12. /** @var StationService $stationService */
  13. private $stationService;
  14. /** @var StationTaskBatchTypeService $stationTaskBatchTypeService */
  15. private $stationTaskBatchTypeService;
  16. /** @var BatchService $batchService */
  17. private $batchService;
  18. public function __construct(){
  19. $this->stationService=null;
  20. $this->stationTaskBatchTypeService=null;
  21. $this->batchService=null;
  22. }
  23. /**
  24. * @param $batches Batch[]
  25. * @param Station $station
  26. * @return Collection
  27. */
  28. public function createByBatches(array $batches,Station $station): Collection
  29. {
  30. $this->stationService=app('StationService');
  31. $this->stationTaskBatchTypeService=app('StationTaskBatchTypeService');
  32. $this->batchService=app('BatchService');
  33. $stationMissionBatches_toCreate=new Collection();
  34. // $station=$this->stationService->getDefaultStation('料箱出货口');
  35. $id_stationMissionBatchType=$this->stationTaskBatchTypeService->firstByWhere('name','U型线分捡');
  36. $batches_handled=[];
  37. foreach ($batches as $batch){
  38. if ($batch['status']=='未处理'){
  39. $stationMissionBatches_toCreate->push([
  40. 'batch_id'=>$batch['id'],
  41. 'station_id'=>$station['id'],
  42. 'station_mission_batch_type_id'=> $id_stationMissionBatchType,
  43. 'status'=>'待处理'
  44. ]);
  45. $batches_handled[]=$batch;
  46. }
  47. }
  48. $this->batchService->updateWhereIn('id',data_get($batches_handled,'*.id'),['status'=>'处理中']);
  49. $this->insert($stationMissionBatches_toCreate->toArray());
  50. return $stationMissionBatches_toCreate;
  51. }
  52. public function insert(array $stationMissionBatches_inArray){
  53. return StationTaskBatch::query()->insert($stationMissionBatches_inArray);
  54. }
  55. }