StationTaskMaterialBoxService.php 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. return $this->stationTaskService
  27. ->registerSubTasks(
  28. $stationTasks_toAttach,
  29. (function()use($batches){
  30. $stationTaskMaterialBoxes_listByBatch=new Collection();
  31. foreach ($batches as $batch){
  32. $stationTaskMaterialBoxes_listByBatch->push(
  33. $this->createByBatch($batch)
  34. );
  35. }
  36. return $stationTaskMaterialBoxes_listByBatch;
  37. })());
  38. }
  39. function createByBatch(Batch $batch): Collection
  40. {
  41. $this->materialBoxService=app('MaterialBoxService');
  42. $this->stationTypeService=app('StationTypeService');
  43. $this->stationService=app('StationService');
  44. $stationMaterialBoxes_toCreate=new Collection();
  45. $order_ids=data_get($batch['orders'],'*.id');
  46. $orderCommodities=OrderCommodity::query()->with('orderBin')->whereIn('order_id',$order_ids)->get();
  47. foreach ($orderCommodities as $orderCommodity){
  48. $stationType=$this->stationTypeService->getForMaterialBox();
  49. $station=$this->stationService->getStation_byType($stationType['name']);
  50. $materialBox=$this->materialBoxService->firstOrCreate(['code' => $orderCommodity['location']]);
  51. $stationMaterialBoxes_toCreate->push([
  52. 'station_id'=>$station['id'],
  53. 'material_box_id'=>$materialBox['id'],
  54. 'status'=>'待处理'
  55. ]);
  56. }
  57. $this->insert($stationMaterialBoxes_toCreate->toArray());
  58. }
  59. function get(array $kvPairs){
  60. ksort($kvPairs);
  61. return Cache::remember('StationTaskMaterialBox'.md5(json_encode($kvPairs)), config('cache.expirations.fastChange'), function ()use($kvPairs) {
  62. $query = StationTaskMaterialBox::query();
  63. foreach ($kvPairs as $column => $value){
  64. if (is_array($value))$query->whereIn($column,$value);
  65. else $query->where($column,$value);
  66. }
  67. return $query->get();
  68. });
  69. }
  70. public function insert(array $stationTaskMaterialBoxes): bool
  71. {
  72. $inserted = StationTaskMaterialBox::query()->insert($stationTaskMaterialBoxes);
  73. LogService::log(__METHOD__,__FUNCTION__,json_encode($stationTaskMaterialBoxes).
  74. '||'.json_encode(array_slice(debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS),0,3)));
  75. return $inserted;
  76. }
  77. function markHasPut($taskCode,$binCode){
  78. //如果
  79. //标记箱子任务处理中
  80. //标记箱子关联的商品任务处理中
  81. //标记波次处理中
  82. }
  83. function markHasTaken($taskCode,$binCode){
  84. }
  85. }