StationTaskBatchService.php 2.0 KB

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