StationCacheShelfGridService.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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 StationCacheShelfGrid::query()->whereIn('id',data_get($grids,'*.id'))->update(['material_box_id' => null, 'status' => 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)->get();
  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. }
  58. }
  59. /**
  60. * 通知HaiQ亮灯
  61. * @param Station $station
  62. * @param $pointX
  63. * @param $pointY
  64. * @return string
  65. */
  66. public function lightOn(Station $station, $pointX, $pointY)
  67. {
  68. $locCode = 'HAI' . $station['code'] . '-0' . $pointX . '-0' . $pointY;
  69. $params = [
  70. "areaCode" => "1004",
  71. "PTLAction" => 1, //1是开,0是关
  72. "PTLSettings" => [
  73. "color" => 1,
  74. "frequency" => 1
  75. ],
  76. "displayInfo" => [
  77. "detail01" => "detail01",
  78. "detail02" => "detail02",
  79. "detail03" => "detail03",
  80. "qrCode" => "qrCode",
  81. "qty00" => "11",
  82. "qty01" => 1,
  83. "qty02" => 2,
  84. "title" => "title",
  85. "uomDesc01" => "uo",
  86. "uomDesc02" => "uo"
  87. ],
  88. "locCode" => $locCode//灯条口,B1\B2=设备编号,中间号码代表从右往左数的列,右边号码时从下往上数
  89. ];
  90. // LogService::log(__METHOD__,'海柔亮灯请求',json_encode($params));
  91. $response = Http::post(config('api.haiq.storage.light'), $params);
  92. // LogService::log(__METHOD__,'海柔亮灯请求返回',json_encode($params));
  93. return $response->body();
  94. }
  95. }