CacheShelfService.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. * @param MaterialBox $materialBox
  18. * @param $pointX
  19. * @param $pointY
  20. * @return string
  21. * @throws ErrorException
  22. */
  23. public function pushTask(Station $station,MaterialBox $materialBox,$pointX, $pointY)
  24. {
  25. /** 推送任务 */
  26. if($this->putBinToStore($station,$materialBox)){
  27. /** 亮灯 */
  28. return $this->lightOn($station,$pointX, $pointY);
  29. }
  30. else return false;
  31. }
  32. /**
  33. * 获取缓存架任务
  34. * @param Station $station
  35. */
  36. public function getTasks(Station $station)
  37. {
  38. $grids = StationCacheShelfGrid::query()->with('materialBox:code')->where('station_id',$station['id'])->where('status',2)->orderBy('grid_id')->get();
  39. $station->setRelation('grids',$grids);
  40. }
  41. /**
  42. * 缓存架 【亮灯】
  43. * @param Station $station
  44. * @param $pointX
  45. * @param $pointY
  46. * @return string
  47. */
  48. public function lightOn(Station $station,$pointX,$pointY): string
  49. {
  50. $locCode = 'HAI'.$station['code'].'-0'.$pointX.'-0'.$pointY;
  51. $params = [
  52. "areaCode"=> "1004",
  53. "PTLAction"=> 1, //1是开,0是关
  54. "PTLSettings"=> [
  55. "color"=> 1,
  56. "frequency"=> 1
  57. ],
  58. "displayInfo"=> [
  59. "detail01"=> "detail01",
  60. "detail02"=> "detail02",
  61. "detail03"=> "detail03",
  62. "qrCode"=> "qrCode",
  63. "qty00"=> "11",
  64. "qty01"=> 1,
  65. "qty02"=> 2,
  66. "title"=> "title",
  67. "uomDesc01"=> "uo",
  68. "uomDesc02"=> "uo"
  69. ],
  70. "locCode"=> $locCode//灯条口,B1\B2=设备编号,中间号码代表从右往左数的列,右边号码时从下往上数
  71. ];
  72. $response = Http::post(config('api.haiq.storage.light'),$params);
  73. return $response->body();
  74. }
  75. /**
  76. * 推送到海柔的任务
  77. * @param Station $station
  78. * @param MaterialBox $materialBox
  79. * @return bool
  80. * @throws ErrorException
  81. */
  82. public function putBinToStore(Station $station,MaterialBox $materialBox): bool
  83. {
  84. $stationTaskMaterialBox = new StationTaskMaterialBox();
  85. $stationTaskMaterialBox->setRelation('station',$station);
  86. $stationTaskMaterialBox->setRelation('materialBox',$materialBox);
  87. /** @var ForeignHaiRoboticsService $foreignHaiRoboticsService */
  88. $foreignHaiRoboticsService = app(ForeignHaiRoboticsService::class);
  89. return $foreignHaiRoboticsService->putBinToStore_fromCacheShelf($stationTaskMaterialBox);
  90. }
  91. }