StationService.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. namespace App\Services;
  3. use App\Station;
  4. use App\StationTask;
  5. use App\StationType;
  6. use Exception;
  7. use Illuminate\Support\Facades\Cache;
  8. class StationService
  9. {
  10. /**
  11. * @param string $typeName
  12. * @return Station
  13. * @throws Exception
  14. */
  15. function getDefaultStation(string $typeName):Station{
  16. $station= Cache::remember('StationType_default_name_'.$typeName,config('rarelyChange'), function ()use($typeName) {
  17. $stationType= StationType::query()->where('name',$typeName)->orderBy('id')->get('id')->first();
  18. if(!$stationType) throw new Exception('指定站类型获取不到');
  19. return Station::query()->where('station_type_id',$stationType['id'])->first();
  20. });
  21. if(!$station)throw new Exception('默认站获取不到');
  22. return $station;
  23. }
  24. function broadcast($station_id, $json_data){
  25. //...
  26. //event(new BroadcastToStation($station_id,$json_data))
  27. }
  28. function broadcastBinMonitor($station_id, StationTask $stationTask){
  29. //...
  30. //$stationTask->stationTaskBatch
  31. //$stationTask->stationTaskMaterialBox
  32. //$stationTask->stationCommodities
  33. //$batch= $stationTask->stationTaskBatch->batch
  34. //$orders= $batch->....
  35. //.....
  36. //$json_data=['batch_code','stationCommodities']
  37. //$this->broadcast($station_id, $json_data)
  38. }
  39. function broadcastBinMonitorWarning($warnText, $station_id, StationTask $stationTask){
  40. //...
  41. //$this->broadcast($station_id, $json_data)
  42. }
  43. }