1234567891011121314151617181920212223242526272829303132333435363738 |
- <?php
- namespace App\Admin\Actions\Device;
- use App\Model\DeviceBox;
- use App\Model\DeviceInfo;
- use App\Server\DeviceServer;
- use Encore\Admin\Actions\RowAction;
- use Illuminate\Database\Eloquent\Model;
- use Illuminate\Http\Request;
- use Illuminate\Support\Facades\Log;
- class getRule extends RowAction
- {
- public $name = '属性上报';
- public function handle(Model $model, Request $request)
- {
- $id = $this->row->id;
- $device_name = $this->row->device_name;
- $box_info = DeviceBox::where(['device_id'=>$id])->get();
- $box_arr = DeviceInfo::getTypeNumber();
- $box_num = $box_arr[$this->row->device_type];
- if(!empty($box_info)){
- for ($i=1; $i<=$box_num ; $i++){
- $rule = ['get'=>'box'.$i];
- if(!empty($rule)){
- Log::info(json_encode($rule).PHP_EOL);
- $res = (new DeviceServer())->sendMsg($device_name,json_encode($rule));
- sleep(20);
- }
- }
- return $this->response()->success('上报属性成功')->refresh();
- }
- }
- }
|