| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- <?php
- namespace App\Services;
- use App\Batch;
- use App\StationTaskBatch;
- use App\StationTaskBatchType;
- use Exception;
- use Illuminate\Support\Collection;
- use Illuminate\Support\Facades\Cache;
- class StationTaskBatchService
- {
- /** @var StationService $stationService */
- private $stationService;
- /** @var StationTaskBatchTypeService $stationTaskBatchTypeService */
- private $stationTaskBatchTypeService;
- /** @var BatchService $batchService */
- private $batchService;
- public function __construct(){
- $this->stationService=null;
- $this->stationTaskBatchTypeService=null;
- $this->batchService=null;
- }
- /**
- * @param $batches Batch[]
- * @throws Exception
- */
- public function createByBatches(array $batches){
- $this->stationService=app('StationService');
- $this->stationTaskBatchTypeService=app('StationTaskBatchTypeService');
- $this->batchService=app('BatchService');
- $stationMissionBatches_toCreate=new Collection();
- $station=$this->stationService->getDefaultStation('料箱出货口');
- $id_stationMissionBatchType=$this->stationTaskBatchTypeService->firstByWhere('name','U型线分捡');
- $batches_handled=[];
- foreach ($batches as $batch){
- if ($batch['status']=='未处理'){
- $stationMissionBatches_toCreate->push([
- 'batch_id'=>$batch['id'],
- 'station_id'=>$station['id'],
- 'station_mission_batch_type_id'=> $id_stationMissionBatchType,
- 'status'=>'待处理'
- ]);
- $batches_handled[]=$batch;
- }
- }
- $this->batchService->updateWhereIn('id',data_get($batches_handled,'*.id'),['status'=>'处理中']);
- $this->insert($stationMissionBatches_toCreate->toArray());
- return $stationMissionBatches_toCreate;
- }
- public function insert(array $stationMissionBatches_inArray){
- return StationTaskBatch::query()->insert($stationMissionBatches_inArray);
- }
- }
|