getRule.php 1.1 KB

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