StationTaskBatchService.php 1.9 KB

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