CacheShelfService.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <?php
  2. namespace App\Services;
  3. use App\Exceptions\ErrorException;
  4. use App\MaterialBox;
  5. use App\Station;
  6. use App\StationCacheShelfGrid;
  7. use App\StationTaskMaterialBox;
  8. use App\Traits\ServiceAppAop;
  9. use Illuminate\Support\Facades\Http;
  10. class CacheShelfService
  11. {
  12. use ServiceAppAop;
  13. protected $modelClass = Station::class;
  14. /** @var StationTaskMaterialBoxService $stationTaskMaterialBoxService */
  15. private $stationTaskMaterialBoxService;
  16. /** @var StationCacheShelfGridService $stationCacheShelfGridService */
  17. private $stationCacheShelfGridService;
  18. /** @var ForeignHaiRoboticsService $foreignHaiRoboticsService */
  19. private $foreignHaiRoboticsService;
  20. /**
  21. * 获取现有的缓存架任务
  22. * @param Station $station
  23. */
  24. public function getTasks(Station $station)
  25. {
  26. $grids = StationCacheShelfGrid::query()->with('materialBox:code')->where('station_id', $station['id'])->where('status', 1)->orderBy('grid_id')->get();
  27. $station->setRelation('grids', $grids);
  28. }
  29. /**
  30. * 亮灯
  31. * @param Station $station
  32. * @param $pointX
  33. * @param $pointY
  34. * @return string
  35. */
  36. public function lightOn(Station $station, $pointX, $pointY): string
  37. {
  38. $locCode = 'HAI' . $station['code'] . '-0' . $pointX . '-0' . $pointY;
  39. $params = [
  40. "areaCode" => "1004",
  41. "PTLAction" => 1, //1是开,0是关
  42. "PTLSettings" => [
  43. "color" => 1,
  44. "frequency" => 1
  45. ],
  46. "displayInfo" => [
  47. "detail01" => "detail01",
  48. "detail02" => "detail02",
  49. "detail03" => "detail03",
  50. "qrCode" => "qrCode",
  51. "qty00" => "11",
  52. "qty01" => 1,
  53. "qty02" => 2,
  54. "title" => "title",
  55. "uomDesc01" => "uo",
  56. "uomDesc02" => "uo"
  57. ],
  58. "locCode" => $locCode//灯条口,B1\B2=设备编号,中间号码代表从右往左数的列,右边号码时从下往上数
  59. ];
  60. $response = Http::post(config('api.haiq.storage.light'), $params);
  61. return $response->body();
  62. }
  63. /**
  64. * 拍灯
  65. * @param Station $station
  66. * @param MaterialBox $materialBox
  67. * @param StationCacheShelfGrid $grid
  68. * @return bool
  69. * @throws ErrorException
  70. */
  71. public function putBinToStore(Station $station, MaterialBox $materialBox, StationCacheShelfGrid $grid): bool
  72. {
  73. $this->instant($this->stationTaskMaterialBoxService,'StationTaskMaterialBoxService');
  74. $this->instant($this->stationCacheShelfGridService,'StationCacheShelfGridService');
  75. $this->instant($this->foreignHaiRoboticsService,'ForeignHaiRoboticsService');
  76. /** @var StationTaskMaterialBox $stationTaskMaterialBox */
  77. $stationTaskMaterialBox = $this->stationTaskMaterialBoxService->createByStationMaterialBox($station, $materialBox);
  78. $this->stationCacheShelfGridService->processGrid($grid,$station,$materialBox);
  79. $station->setRelation('grids', $grid);
  80. $stationTaskMaterialBox->setRelation('station', $station);
  81. $stationTaskMaterialBox->setRelation('materialBox', $materialBox);
  82. return $this->foreignHaiRoboticsService->putBinToStore_fromCacheShelf($stationTaskMaterialBox);
  83. }
  84. /**
  85. * 入库任务完成
  86. * @param $params
  87. */
  88. public function putBinToStoreFinish($params)
  89. {
  90. $this->instant($this->stationTaskMaterialBoxService,'StationTaskMaterialBoxService');
  91. $locCode = $params['locCode'];
  92. list($stationCode, $gridId) = StationCacheShelfGrid::getGridByCode($locCode);
  93. $station = Station::query()->where('code', $stationCode)->first();
  94. $stationCacheShelfGrid = StationCacheShelfGrid::query()->with('materialBox')->where('station_id', $station)->where('grid_id', $gridId)->first();
  95. $stationCacheShelfGrid->update(['status' => '0', 'material_box_id' => null]);
  96. $StationTaskMaterialBox = StationTaskMaterialBox::query()->where('station_id', $station['id'])->where('material_box_id', $stationCacheShelfGrid['$stationCacheShelfGrid'])->first();
  97. $this->stationTaskMaterialBoxService->set($StationTaskMaterialBox, ['status' => '已完成']);
  98. }
  99. /**
  100. * 取消格口任务
  101. * @param Station $station
  102. * @param array $girds
  103. */
  104. public function cancelTask(Station $station, array $girds = [])
  105. {
  106. $gridQuery = StationCacheShelfGrid::query()->where('station_id', $station['id']);
  107. if (count($girds) > 0) $gridQuery->whereIn('grid_id', $girds);
  108. $this->stationCacheShelfGridService->cancelTask($gridQuery->get());
  109. }
  110. }