wzh il y a 5 ans
Parent
commit
870d972955

+ 4 - 1
api/application/controllers/Lampcontrol.php

@@ -1793,7 +1793,10 @@ class Lampcontrol extends Base_Controller {
 
             $value['createtime'] = date('Y-m-d H:i:s',time());
             $value['projectid'] = $projectid;
-            if ($type != 1) $this->Lamp_model->add($value);
+            if ($type != 1) {
+                $this->Lamp_model->add($value);
+                $this->Project_model->add_lamp_count(['projectid'=>$projectid]);
+            }
         }
 
         if ($res || $type == 1) {

+ 15 - 0
api/application/controllers/Test.php

@@ -18,6 +18,10 @@ class Test extends CI_Controller {
 
     // 批量导入
     public function haha(){
+        $info = '91 0100 00 a800010001 0c 11 3e80 3c8c 3908 3138 2f44 3390283c2ee0245403e8007800781e05a3412cec27101e010fc3';
+        $info = '91010000a8000100010c113e803c8c390831382f443390283c2ee0245403e8007800781e05a3412cec27101e010fc3';
+        var_dump(substr($info, 34,4));
+        var_dump(round(base_convert(substr($info, 34,4), 16, 10)/1000,1));die;
         $indexArr = ['B'=>'b','C'=>'c'];
         // 文件上传成功
         // $data = $this->upload->data();
@@ -72,4 +76,15 @@ class Test extends CI_Controller {
         // 批量写入数据
         return $data;
     }
+
+
+    public function update_project_count(){
+        $list = $this->db->query('select id from project')->result_array();
+
+        foreach ($list as $key => $value) {
+            $res = $this->db->query('select count(*) as total from lampinfo where projectid = '.$value['id'])->row_array();
+            $this->db->query('update project set lampcount = '.$res['total'].' where id = '.$value['id']);
+        }
+        var_dump('ok');
+    }
 }

+ 1 - 1
api/application/models/Project_model.php

@@ -513,7 +513,7 @@ class Project_model extends Base_model {
 
 	// 添加路灯数
 	public function add_lamp_count($data){
-		$sql = "update `project` set `lampcount` = `lampcount` + 1, `faultcount` = `faultcount` + {$data['faultcount']}  WHERE `id`={$data['projectid']}";
+		$sql = "update `project` set `lampcount` = `lampcount` + 1 WHERE `id`={$data['projectid']}";
 		$this->db->query($sql);
 		if ($this->db->affected_rows() == 1) {
 			return true;