123456789101112131415161718192021222324252627 |
- <?php
- $groupList = sqlite("groups")->select();
- // 获取所有网关列表
- $gatewayList = sqlite("gateways")->select();
- foreach ($gatewayList as $gateway){
- // 查询分库所有gid为0的设备
- $light = sqlite("light", "light/".$gateway["eth_ip"].".db")->where(["group_id"=>0])->select();
- foreach ($light as $light_v){
- // 获取当前设备绑定的群组
- $gid = sqlite("group_device")->where([
- "gwid"=>$gateway["id"],
- "device_id"=>$light_v["did"],
- "btype"=>1,
- ])->value("gid");
- if(!$gid) continue; // 此设备未绑定群组,跳过
- foreach ($groupList as $group){
- if($group["id"] == $gid){
- sqlite("light", "light/".$gateway["eth_ip"].".db")->where(["did"=>$light_v["did"]])->update(["group_id"=>$group["id"], "group_type"=>$group["type"]]);
- break;
- }
- }
- }
- }
|