getRule.php 1021 B

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. namespace App\Admin\Actions\Device;
  3. use App\Model\DeviceBox;
  4. use App\Server\DeviceServer;
  5. use Encore\Admin\Actions\RowAction;
  6. use Illuminate\Database\Eloquent\Model;
  7. use Illuminate\Http\Request;
  8. use Illuminate\Support\Facades\Log;
  9. class getRule extends RowAction
  10. {
  11. public $name = '属性上报';
  12. public function handle(Model $model, Request $request)
  13. {
  14. $id = $this->row->id;
  15. $device_name = $this->row->device_name;
  16. $box_info = DeviceBox::where(['device_id'=>$id])->get();
  17. if(!empty($box_info)){
  18. foreach ($box_info as $box){
  19. $box_name = $box->name;
  20. $rule = ['get'=>$box_name];
  21. if(!empty($rule)){
  22. Log::info(json_encode($rule).PHP_EOL);
  23. $res = (new DeviceServer())->sendMsg($device_name,json_encode($rule));
  24. sleep(12);
  25. }
  26. }
  27. return $this->response()->success('上报属性成功')->refresh();
  28. }
  29. }
  30. }