code.php 920 B

123456789101112131415161718192021222324252627
  1. <?php
  2. $groupList = sqlite("groups")->select();
  3. // 获取所有网关列表
  4. $gatewayList = sqlite("gateways")->select();
  5. foreach ($gatewayList as $gateway){
  6. // 查询分库所有gid为0的设备
  7. $light = sqlite("light", "light/".$gateway["eth_ip"].".db")->where(["group_id"=>0])->select();
  8. foreach ($light as $light_v){
  9. // 获取当前设备绑定的群组
  10. $gid = sqlite("group_device")->where([
  11. "gwid"=>$gateway["id"],
  12. "device_id"=>$light_v["did"],
  13. "btype"=>1,
  14. ])->value("gid");
  15. if(!$gid) continue; // 此设备未绑定群组,跳过
  16. foreach ($groupList as $group){
  17. if($group["id"] == $gid){
  18. sqlite("light", "light/".$gateway["eth_ip"].".db")->where(["did"=>$light_v["did"]])->update(["group_id"=>$group["id"], "group_type"=>$group["type"]]);
  19. break;
  20. }
  21. }
  22. }
  23. }