CacheShelfService.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. namespace App\Services;
  3. use App\Events\BroadcastToStation;
  4. use App\Exceptions\ErrorException;
  5. use App\MaterialBox;
  6. use App\Station;
  7. use App\StationCacheShelfGrid;
  8. use App\StationTask;
  9. use App\StationTaskMaterialBox;
  10. use App\Traits\ServiceAppAop;
  11. use Illuminate\Support\Facades\Http;
  12. class CacheShelfService
  13. {
  14. use ServiceAppAop;
  15. protected $modelClass=Station::class;
  16. /**
  17. * 缓存架上架料箱
  18. * @param Station $station
  19. * @param MaterialBox $materialBox
  20. * @param $pointX
  21. * @param $pointY
  22. * @return string
  23. * @throws ErrorException
  24. */
  25. public function pushTask(Station $station,MaterialBox $materialBox,$pointX, $pointY)
  26. {
  27. $grid = (3-$pointX)*3 + (3-$pointX);
  28. $params = ['station'=>$station['id'],'grid_id'=>$grid];
  29. $stationCacheShelfGrid = StationCacheShelfGrid::query()->firstOrCreate($params,$params);
  30. $stationCacheShelfGrid->update(['material_box_id' => $materialBox['id'],'status'=> 0]);
  31. /** 推送任务至海柔机器人 */
  32. if($this->putBinToStore($station,$materialBox)){
  33. $stationCacheShelfGrid->update(['material_box_id' => $materialBox['id'],'status'=> 1]);
  34. /** 亮灯 */
  35. return $this->lightOn($station,$pointX, $pointY);
  36. }
  37. else return false;
  38. }
  39. /**
  40. * 获取缓存架任务
  41. * @param Station $station
  42. */
  43. public function getTasks(Station $station)
  44. {
  45. $grids = StationCacheShelfGrid::query()->with('materialBox:code')->where('station_id',$station['id'])->where('status',1)->orderBy('grid_id')->get();
  46. $station->setRelation('grids',$grids);
  47. }
  48. /**
  49. * 缓存架 【亮灯】
  50. * @param Station $station
  51. * @param $pointX
  52. * @param $pointY
  53. * @return string
  54. */
  55. public function lightOn(Station $station,$pointX,$pointY): string
  56. {
  57. $locCode = 'HAI'.$station['code'].'-0'.$pointX.'-0'.$pointY;
  58. $params = [
  59. "areaCode"=> "1004",
  60. "PTLAction"=> 1, //1是开,0是关
  61. "PTLSettings"=> [
  62. "color"=> 1,
  63. "frequency"=> 1
  64. ],
  65. "displayInfo"=> [
  66. "detail01"=> "detail01",
  67. "detail02"=> "detail02",
  68. "detail03"=> "detail03",
  69. "qrCode"=> "qrCode",
  70. "qty00"=> "11",
  71. "qty01"=> 1,
  72. "qty02"=> 2,
  73. "title"=> "title",
  74. "uomDesc01"=> "uo",
  75. "uomDesc02"=> "uo"
  76. ],
  77. "locCode"=> $locCode//灯条口,B1\B2=设备编号,中间号码代表从右往左数的列,右边号码时从下往上数
  78. ];
  79. $response = Http::post(config('api.haiq.storage.light'),$params);
  80. return $response->body();
  81. }
  82. /**
  83. * 推送到海柔的任务
  84. * @param Station $station
  85. * @param MaterialBox $materialBox
  86. * @return bool
  87. * @throws ErrorException
  88. */
  89. public function putBinToStore(Station $station,MaterialBox $materialBox): bool
  90. {
  91. $stationTaskMaterialBox = new StationTaskMaterialBox();
  92. $stationTaskMaterialBox->setRelation('station',$station);
  93. $stationTaskMaterialBox->setRelation('materialBox',$materialBox);
  94. /** @var ForeignHaiRoboticsService $foreignHaiRoboticsService */
  95. $foreignHaiRoboticsService = app(ForeignHaiRoboticsService::class);
  96. return $foreignHaiRoboticsService->putBinToStore_fromCacheShelf($stationTaskMaterialBox);
  97. }
  98. }