StationCacheShelfGridService.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php
  2. namespace App\Services;
  3. use App\Events\BroadcastToStation;
  4. use App\Station;
  5. use App\Traits\ServiceAppAop;
  6. use App\StationCacheShelfGrid;
  7. use Illuminate\Support\Facades\Http;
  8. class StationCacheShelfGridService
  9. {
  10. use ServiceAppAop;
  11. protected $modelClass = StationCacheShelfGrid::class;
  12. /**
  13. * processGrid 格口上放入料箱
  14. * lightOff 解析HaiQ格口灭灯请求 完成格口上的任务 进行灭灯完成后的广播
  15. * cancelTask 完成格口上的任务
  16. * lightOn 发送给HaiQ的格口亮灯
  17. */
  18. /**
  19. * 修改格口的状态
  20. * @param $stationCacheShelfGrid
  21. * @param $station
  22. * @param $materialBox
  23. */
  24. public function processGrid($stationCacheShelfGrid, $station, $materialBox)
  25. {
  26. $stationCacheShelfGrid->update(['station_id' => $station['id'], 'material_box_id' => $materialBox['id'], 'status' => 1]);
  27. }
  28. /**
  29. * 清空任务
  30. * @param $grids
  31. * @return bool
  32. */
  33. public function cancelTask($grids): bool
  34. {
  35. return $grids->update(['material_box_id' => null, 'status' => 0]) > 0;
  36. }
  37. /**
  38. * 格口灭灯完成后的广播
  39. * @param $locCode
  40. * @param $PTLAction
  41. */
  42. public function lightOff($locCode, $PTLAction)
  43. {
  44. if ($PTLAction == '0') {
  45. list($stationCode, $gridId, $x, $y) = StationCacheShelfGrid::getGridByCode($locCode);
  46. $station = Station::query()->where('code', $stationCode)->first();
  47. $gird = StationCacheShelfGrid::query()->where('station_id',$station['id'])->where('grid_id',$gridId)->first();
  48. $this->cancelTask($gird);
  49. $json = json_encode([
  50. 'code' => $stationCode,
  51. 'x' => $x,
  52. 'y' => $y,
  53. 'id' => $station['id'] ?? '',
  54. 'grid_id' => $gridId,
  55. ]);
  56. broadcast(new BroadcastToStation($station['id'] ?? '', $json));
  57. StationCacheShelfGrid::query()->where('station_id', $station['id'])->where('grid_id', $gridId)->update(['material_box_id' => null, 'status' => 0]);
  58. }
  59. }
  60. /**
  61. * 通知HaiQ亮灯
  62. * @param Station $station
  63. * @param $pointX
  64. * @param $pointY
  65. * @return string
  66. */
  67. public function lightOn(Station $station, $pointX, $pointY)
  68. {
  69. $locCode = 'HAI' . $station['code'] . '-0' . $pointX . '-0' . $pointY;
  70. $params = [
  71. "areaCode" => "1004",
  72. "PTLAction" => 1, //1是开,0是关
  73. "PTLSettings" => [
  74. "color" => 1,
  75. "frequency" => 1
  76. ],
  77. "displayInfo" => [
  78. "detail01" => "detail01",
  79. "detail02" => "detail02",
  80. "detail03" => "detail03",
  81. "qrCode" => "qrCode",
  82. "qty00" => "11",
  83. "qty01" => 1,
  84. "qty02" => 2,
  85. "title" => "title",
  86. "uomDesc01" => "uo",
  87. "uomDesc02" => "uo"
  88. ],
  89. "locCode" => $locCode//灯条口,B1\B2=设备编号,中间号码代表从右往左数的列,右边号码时从下往上数
  90. ];
  91. // LogService::log(__METHOD__,'海柔亮灯请求',json_encode($params));
  92. $response = Http::post(config('api.haiq.storage.light'), $params);
  93. // LogService::log(__METHOD__,'海柔亮灯请求返回',json_encode($params));
  94. return $response->body();
  95. }
  96. }