StationCacheShelfGridService.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. * 修改格口的状态
  14. * @param $stationCacheShelfGrid
  15. * @param $station
  16. * @param $materialBox
  17. */
  18. public function processGrid($stationCacheShelfGrid, $station, $materialBox)
  19. {
  20. $stationCacheShelfGrid->update(['station_id' => $station['id'], 'material_box_id' => $materialBox['id'], 'status' => 1]);
  21. }
  22. /**
  23. * 清空任务
  24. * @param $grids
  25. * @return bool
  26. */
  27. public function cancelTask($grids): bool
  28. {
  29. return $grids->update(['material_box_id' => null, 'status' => 0]) > 0;
  30. }
  31. /**
  32. * 格口灭灯
  33. * @param $locCode
  34. * @param $PTLAction
  35. */
  36. public function lightOff($locCode, $PTLAction)
  37. {
  38. if ($PTLAction == '0') {
  39. list($stationCode, $gridId, $x, $y) = StationCacheShelfGrid::getGridByCode($locCode);
  40. $station = Station::query()->where('code', $stationCode)->first();
  41. $json = json_encode([
  42. 'code' => $stationCode,
  43. 'x' => $x,
  44. 'y' => $y,
  45. 'id' => $station['id'] ?? '',
  46. 'grid_id' => $gridId,
  47. ]);
  48. broadcast(new BroadcastToStation($station['id'] ?? '', $json));
  49. StationCacheShelfGrid::query()->where('station_id', $station['id'])->where('grid_id', $gridId)->update(['material_box_id' => null, 'status' => 0]);
  50. }
  51. }
  52. public function lightOn(Station $station, $pointX, $pointY)
  53. {
  54. $locCode = 'HAI' . $station['code'] . '-0' . $pointX . '-0' . $pointY;
  55. $params = [
  56. "areaCode" => "1004",
  57. "PTLAction" => 1, //1是开,0是关
  58. "PTLSettings" => [
  59. "color" => 1,
  60. "frequency" => 1
  61. ],
  62. "displayInfo" => [
  63. "detail01" => "detail01",
  64. "detail02" => "detail02",
  65. "detail03" => "detail03",
  66. "qrCode" => "qrCode",
  67. "qty00" => "11",
  68. "qty01" => 1,
  69. "qty02" => 2,
  70. "title" => "title",
  71. "uomDesc01" => "uo",
  72. "uomDesc02" => "uo"
  73. ],
  74. "locCode" => $locCode//灯条口,B1\B2=设备编号,中间号码代表从右往左数的列,右边号码时从下往上数
  75. ];
  76. LogService::log(__METHOD__,'海柔亮灯请求',json_encode($params));
  77. $response = Http::post(config('api.haiq.storage.light'), $params);
  78. LogService::log(__METHOD__,'海柔亮灯请求返回',json_encode($params));
  79. return $response->body();
  80. }
  81. }