StationTaskMaterialBoxService.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. namespace App\Services;
  3. use App\Batch;
  4. use App\OrderCommodity;
  5. use App\StationTaskMaterialBox;
  6. use Illuminate\Support\Collection;
  7. use Illuminate\Support\Facades\Cache;
  8. class StationTaskMaterialBoxService
  9. {
  10. /** @var StationService $stationService */
  11. private $stationService;
  12. /** @var StationTypeService $stationTypeService */
  13. private $stationTypeService;
  14. /** @var StationTaskService $stationTaskService */
  15. private $stationTaskService;
  16. /** @var MaterialBoxService $materialBoxService */
  17. private $materialBoxService;
  18. public function __construct(){
  19. $this->stationService=null;
  20. $this->stationTypeService=null;
  21. $this->stationTaskService=null;
  22. $this->materialBoxService=null;
  23. }
  24. function createByBatches(array $batches,Collection $stationTasks_toAttach): Collection
  25. {
  26. $stationTaskMaterialBoxes = (function () use ($batches) {
  27. $stationTaskMaterialBoxes_listByBatch = new Collection();
  28. foreach ($batches as $batch) {
  29. $stationTaskMaterialBoxes_listByBatch->push(
  30. $this->createByBatch($batch)
  31. );
  32. }
  33. return $stationTaskMaterialBoxes_listByBatch;
  34. })();
  35. $this->stationTaskService
  36. ->registerSubTasks(
  37. $stationTasks_toAttach,
  38. $stationTaskMaterialBoxes);
  39. return $stationTaskMaterialBoxes;
  40. }
  41. function createByBatch(Batch $batch): Collection
  42. {
  43. $this->materialBoxService=app('MaterialBoxService');
  44. $this->stationTypeService=app('StationTypeService');
  45. $this->stationService=app('StationService');
  46. $stationMaterialBoxes_toCreate=new Collection();
  47. $order_ids=data_get($batch['orders'],'*.id');
  48. $orderCommodities=OrderCommodity::query()->with('orderBin')->whereIn('order_id',$order_ids)->get();
  49. if($orderCommodities->isEmpty())return ;
  50. $stationType=$this->stationTypeService->getForMaterialBox_onBatchProcess();
  51. foreach ($orderCommodities as $orderCommodity){
  52. $station=$this->stationService->getStation_byType($stationType['name']);
  53. $materialBox=$this->materialBoxService->firstOrCreate(['code' => $orderCommodity['location']]);
  54. $stationMaterialBoxes_toCreate->push([
  55. 'station_id'=>$station['id'],
  56. 'material_box_id'=>$materialBox['id'],
  57. 'status'=>'待处理'
  58. ]);
  59. }
  60. $this->insert($stationMaterialBoxes_toCreate->toArray());
  61. }
  62. function get(array $kvPairs){
  63. ksort($kvPairs);
  64. return Cache::remember('StationTaskMaterialBox'.md5(json_encode($kvPairs)), config('cache.expirations.fastChange'), function ()use($kvPairs) {
  65. $query = StationTaskMaterialBox::query();
  66. foreach ($kvPairs as $column => $value){
  67. if (is_array($value))$query->whereIn($column,$value);
  68. else $query->where($column,$value);
  69. }
  70. return $query->get();
  71. });
  72. }
  73. public function insert(array $stationTaskMaterialBoxes): bool
  74. {
  75. $inserted = StationTaskMaterialBox::query()->insert($stationTaskMaterialBoxes);
  76. LogService::log(__METHOD__,__FUNCTION__,json_encode($stationTaskMaterialBoxes).
  77. '||'.json_encode(array_slice(debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS),0,3)));
  78. return $inserted;
  79. }
  80. function markHasPut($stationTaskMaterialBox){
  81. //如果任务属于服务波次的
  82. //交给波次服务处理
  83. }
  84. function markHasTaken($stationTaskMaterialBox){
  85. }
  86. function getServingTaskType(StationTaskMaterialBox $stationTaskMaterialBox){
  87. // $isBatch;
  88. // $isStoring;
  89. if($stationTaskMaterialBox['station_task_batch_id']){
  90. }
  91. $stationTaskMaterialBox->task();
  92. }
  93. }