| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- <?php
- namespace App\Services;
- use App\Batch;
- use App\OrderCommodity;
- use App\StationTaskMaterialBox;
- use Illuminate\Support\Collection;
- use Illuminate\Support\Facades\Cache;
- class StationTaskMaterialBoxService
- {
- /** @var StationService $stationService */
- private $stationService;
- /** @var StationTypeService $stationTypeService */
- private $stationTypeService;
- /** @var StationTaskService $stationTaskService */
- private $stationTaskService;
- /** @var MaterialBoxService $materialBoxService */
- private $materialBoxService;
- public function __construct(){
- $this->stationService=null;
- $this->stationTypeService=null;
- $this->stationTaskService=null;
- $this->materialBoxService=null;
- }
- function createByBatches(array $batches,Collection $stationTasks_toAttach): Collection
- {
- $stationTaskMaterialBoxes = (function () use ($batches) {
- $stationTaskMaterialBoxes_listByBatch = new Collection();
- foreach ($batches as $batch) {
- $stationTaskMaterialBoxes_listByBatch->push(
- $this->createByBatch($batch)
- );
- }
- return $stationTaskMaterialBoxes_listByBatch;
- })();
- $this->stationTaskService
- ->registerSubTasks(
- $stationTasks_toAttach,
- $stationTaskMaterialBoxes);
- return $stationTaskMaterialBoxes;
- }
- function createByBatch(Batch $batch): Collection
- {
- $this->materialBoxService=app('MaterialBoxService');
- $this->stationTypeService=app('StationTypeService');
- $this->stationService=app('StationService');
- $stationMaterialBoxes_toCreate=new Collection();
- $order_ids=data_get($batch['orders'],'*.id');
- $orderCommodities=OrderCommodity::query()->with('orderBin')->whereIn('order_id',$order_ids)->get();
- if($orderCommodities->isEmpty())return ;
- $stationType=$this->stationTypeService->getForMaterialBox_onBatchProcess();
- foreach ($orderCommodities as $orderCommodity){
- $station=$this->stationService->getStation_byType($stationType['name']);
- $materialBox=$this->materialBoxService->firstOrCreate(['code' => $orderCommodity['location']]);
- $stationMaterialBoxes_toCreate->push([
- 'station_id'=>$station['id'],
- 'material_box_id'=>$materialBox['id'],
- 'status'=>'待处理'
- ]);
- }
- $this->insert($stationMaterialBoxes_toCreate->toArray());
- }
- function get(array $kvPairs){
- ksort($kvPairs);
- return Cache::remember('StationTaskMaterialBox'.md5(json_encode($kvPairs)), config('cache.expirations.fastChange'), function ()use($kvPairs) {
- $query = StationTaskMaterialBox::query();
- foreach ($kvPairs as $column => $value){
- if (is_array($value))$query->whereIn($column,$value);
- else $query->where($column,$value);
- }
- return $query->get();
- });
- }
- public function insert(array $stationTaskMaterialBoxes): bool
- {
- $inserted = StationTaskMaterialBox::query()->insert($stationTaskMaterialBoxes);
- LogService::log(__METHOD__,__FUNCTION__,json_encode($stationTaskMaterialBoxes).
- '||'.json_encode(array_slice(debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS),0,3)));
- return $inserted;
- }
- function markHasPut($stationTaskMaterialBox){
- //如果任务属于服务波次的
- //交给波次服务处理
- }
- function markHasTaken($stationTaskMaterialBox){
- }
- function getServingTaskType(StationTaskMaterialBox $stationTaskMaterialBox){
- // $isBatch;
- // $isStoring;
- if($stationTaskMaterialBox['station_task_batch_id']){
- }
- $stationTaskMaterialBox->task();
- }
- }
|