| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- <?php
- namespace App\Services;
- use App\Station;
- use App\StationTask;
- use App\StationType;
- use Exception;
- use Illuminate\Support\Facades\Cache;
- class StationService
- {
- /**
- * @param string $typeName
- * @return Station
- * @throws Exception
- */
- function getDefaultStation(string $typeName):Station{
- $station= Cache::remember('StationType_default_name_'.$typeName,config('rarelyChange'), function ()use($typeName) {
- $stationType= StationType::query()->where('name',$typeName)->orderBy('id')->get('id')->first();
- if(!$stationType) throw new Exception('指定站类型获取不到');
- return Station::query()->where('station_type_id',$stationType['id'])->first();
- });
- if(!$station)throw new Exception('默认站获取不到');
- return $station;
- }
- function broadcast($station_id, $json_data){
- //...
- //event(new BroadcastToStation($station_id,$json_data))
- }
- function broadcastBinMonitor($station_id, StationTask $stationTask){
- //...
- //$stationTask->stationTaskBatch
- //$stationTask->stationTaskMaterialBox
- //$stationTask->stationCommodities
- //$batch= $stationTask->stationTaskBatch->batch
- //$orders= $batch->....
- //.....
- //$json_data=['batch_code','stationCommodities']
- //$this->broadcast($station_id, $json_data)
- }
- function broadcastBinMonitorWarning($warnText, $station_id, StationTask $stationTask){
- //...
- //$this->broadcast($station_id, $json_data)
- }
- }
|