CacheShelfService.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. /**
  15. * 获取现有的缓存架任务
  16. * @param Station $station
  17. */
  18. public function getTasks(Station $station)
  19. {
  20. $grids = StationCacheShelfGrid::query()->with('materialBox:code')->where('station_id',$station['id'])->where('status',1)->orderBy('grid_id')->get();
  21. $station->setRelation('grids',$grids);
  22. }
  23. /**
  24. * 亮灯
  25. * @param Station $station
  26. * @param $pointX
  27. * @param $pointY
  28. * @return string
  29. */
  30. public function lightOnApi(Station $station,$pointX,$pointY): string
  31. {
  32. $locCode = 'HAI'.$station['code'].'-0'.$pointX.'-0'.$pointY;
  33. $params = [
  34. "areaCode"=> "1004",
  35. "PTLAction"=> 1, //1是开,0是关
  36. "PTLSettings"=> [
  37. "color"=> 1,
  38. "frequency"=> 1
  39. ],
  40. "displayInfo"=> [
  41. "detail01"=> "detail01",
  42. "detail02"=> "detail02",
  43. "detail03"=> "detail03",
  44. "qrCode"=> "qrCode",
  45. "qty00"=> "11",
  46. "qty01"=> 1,
  47. "qty02"=> 2,
  48. "title"=> "title",
  49. "uomDesc01"=> "uo",
  50. "uomDesc02"=> "uo"
  51. ],
  52. "locCode"=> $locCode//灯条口,B1\B2=设备编号,中间号码代表从右往左数的列,右边号码时从下往上数
  53. ];
  54. $response = Http::post(config('api.haiq.storage.light'),$params);
  55. return $response->body();
  56. }
  57. /**
  58. * 拍灯
  59. * @param Station $station
  60. * @param MaterialBox $materialBox
  61. * @param StationCacheShelfGrid $grid
  62. * @return bool
  63. * @throws ErrorException
  64. */
  65. public function putBinToStore(Station $station,MaterialBox $materialBox,StationCacheShelfGrid $grid): bool
  66. {
  67. // 生成任务
  68. /** @var StationTaskMaterialBox $stationTaskMaterialBox */
  69. $stationTaskMaterialBox = StationTaskMaterialBox::query()->create([
  70. 'station_id' => $station['id'],
  71. 'material_box_id' => $materialBox['id'],
  72. 'status' => '待处理'
  73. ]);
  74. // 格口状态修改
  75. $grid->update(['station_id'=>$station['id'],'status'=>1]);
  76. $station->setRelation('grids',$grid);
  77. $stationTaskMaterialBox->setRelation('station',$station);
  78. $stationTaskMaterialBox->setRelation('materialBox',$materialBox);
  79. // 推送任务给海柔
  80. /** @var ForeignHaiRoboticsService $foreignHaiRoboticsService */
  81. $foreignHaiRoboticsService = app(ForeignHaiRoboticsService::class);
  82. return $foreignHaiRoboticsService->putBinToStore_fromCacheShelf($stationTaskMaterialBox);
  83. }
  84. /**
  85. * 入库任务完成
  86. * @param $params
  87. */
  88. public function putBinToStoreFinish($params)
  89. {
  90. $locCode = $params['locCode'];
  91. list($stationCode,$gridId) = StationCacheShelfGrid::getGridByCode($locCode);
  92. $station = Station::query()->where('code',$stationCode)->first();
  93. $stationCacheShelfGrid = StationCacheShelfGrid::query()->with('materialBox')->where('station_id',$station)->where('grid_id',$gridId)->first();
  94. $stationCacheShelfGrid->update(['status'=>'0','material_box_id' => null]);
  95. $StationTaskMaterialBox = StationTaskMaterialBox::query()->where('station_id',$station['id'])->where('material_box_id',$stationCacheShelfGrid['$stationCacheShelfGrid'])->first();
  96. /** @var StationTaskMaterialBoxService $stationTaskMaterialBoxService */
  97. $stationTaskMaterialBoxService = app(StationTaskMaterialBoxService::class);
  98. $stationTaskMaterialBoxService->set($StationTaskMaterialBox,['status'=>'已完成']);
  99. }
  100. }