Browse Source

no message

wzh 5 năm trước cách đây
mục cha
commit
347bd84906
2 tập tin đã thay đổi với 200 bổ sung20 xóa
  1. 190 15
      api/application/controllers/Home.php
  2. 10 5
      api/application/controllers/Project.php

+ 190 - 15
api/application/controllers/Home.php

@@ -114,8 +114,27 @@ class Home extends Base_Controller {
             $data['day_faulty_count'] = $total['total'];
         }else{
             $company = $this->get_user_info('company');
-            $where = ['P.company ='=>$company];
-            if (!empty($projectIdArr)) $where['P.id'] = $projectIdArr;
+            $type = $this->get_user_info('role');
+            // $where = ['P.company ='=>$company];
+            $where = array();
+
+            if ($role == 2) {
+                // $filter .= ' AND L.manu = '.$company;
+                $where['L.manu ='] = $company;
+                // $countWhere[] = 'manu = '.$company;
+            }elseif ($role == 3) {
+                // $filter .= ' AND L.supplier = '.$company;
+                // $countWhere[] = 'supplier = '.$company;
+                $where['L.supplier ='] = $company;
+            }elseif ($role == 4) {
+                // $filter .= ' AND L.po = '.$company;
+                // $countWhere[] = 'po = '.$company;
+                $where['L.po ='] = $company;
+            }else {
+                // $filter .= ' AND P.cityid = '.$company;
+                $where['P.cityid ='] = $company;
+            }
+            // if (!empty($projectIdArr)) $where['P.id'] = $projectIdArr;
             $join = [
                 ['table'=>'project as P','cond'=>'P.id = L.projectid','type'=>'inner']
             ];
@@ -179,7 +198,24 @@ class Home extends Base_Controller {
         $where = array();
         if ($role != SYSTEM_ADMIN){
             $company = $this->get_user_info('company');
-            $where['P.company'] = $company;
+            // $where['P.company'] = $company;
+
+            if ($role == 2) {
+                // $filter .= ' AND L.manu = '.$company;
+                $where['L.manu ='] = $company;
+                // $countWhere[] = 'manu = '.$company;
+            }elseif ($role == 3) {
+                // $filter .= ' AND L.supplier = '.$company;
+                // $countWhere[] = 'supplier = '.$company;
+                $where['L.supplier ='] = $company;
+            }elseif ($role == 4) {
+                // $filter .= ' AND L.po = '.$company;
+                // $countWhere[] = 'po = '.$company;
+                $where['L.po ='] = $company;
+            }else {
+                // $filter .= ' AND P.cityid = '.$company;
+                $where['P.cityid ='] = $company;
+            }
         }
 
         if (!empty($projectIdArr)) $where['L.projectid'] = $projectIdArr;
@@ -224,7 +260,24 @@ class Home extends Base_Controller {
         $where = array();
         if ($role != SYSTEM_ADMIN){
             $company = $this->get_user_info('company');
-            $where[] = 'P.company = '.$company;
+            // $where[] = 'P.company = '.$company;
+
+            if ($role == 2) {
+                // $filter .= ' AND L.manu = '.$company;
+                $where[] = 'L.manu = '.$company;
+                // $countWhere[] = 'manu = '.$company;
+            }elseif ($role == 3) {
+                // $filter .= ' AND L.supplier = '.$company;
+                // $countWhere[] = 'supplier = '.$company;
+                $where[] = 'L.supplier = '.$company;
+            }elseif ($role == 4) {
+                // $filter .= ' AND L.po = '.$company;
+                // $countWhere[] = 'po = '.$company;
+                $where[] = 'L.po = '.$company;
+            }else {
+                // $filter .= ' AND P.cityid = '.$company;
+                $where[] = 'P.cityid = '.$company;
+            }
         }
 
         if ($type == 2) {
@@ -341,7 +394,24 @@ class Home extends Base_Controller {
         $where = array();
         if ($role != SYSTEM_ADMIN){
             $company = $this->get_user_info('company');
-            $where[] = 'P.company = '.$company;
+            // $where[] = 'P.company = '.$company;
+
+            if ($role == 2) {
+                // $filter .= ' AND L.manu = '.$company;
+                $where[] = 'L.manu = '.$company;
+                // $countWhere[] = 'manu = '.$company;
+            }elseif ($role == 3) {
+                // $filter .= ' AND L.supplier = '.$company;
+                // $countWhere[] = 'supplier = '.$company;
+                $where[] = 'L.supplier = '.$company;
+            }elseif ($role == 4) {
+                // $filter .= ' AND L.po = '.$company;
+                // $countWhere[] = 'po = '.$company;
+                $where[] = 'L.po = '.$company;
+            }else {
+                // $filter .= ' AND P.cityid = '.$company;
+                $where[] = 'P.cityid = '.$company;
+            }
         }
 
         if (!empty($projectIdArr)) $where[] = 'P.id in ('.implode(',', $projectIdArr).')';
@@ -581,10 +651,27 @@ class Home extends Base_Controller {
         $where = array();
         if ($role != SYSTEM_ADMIN) {
             $company = $this->get_user_info('company');
-            $where['company'] = $company;
+            $type = $this->get_user_info('role');
+            // $where['company'] = $company;
+
+            if ($type == 2) {
+                // $filter .= ' AND L.manu = '.$company;
+                $where['L.manu'] = $company;
+            }elseif ($type == 3) {
+                // $filter .= ' AND L.supplier = '.$company;
+                $where['L.supplier'] = $company;
+            }elseif ($type == 4) {
+                // $filter .= ' AND L.po = '.$company;
+                $where['L.po'] = $company;
+            }else {
+                $where['P.cityid'] = $company;
+            }
         }
 
-        $pro_list = $this->Project_model->get_list($where,'cityid');
+        // $pro_list = $this->Project_model->get_list($where,'P.cityid');
+        $join = array();
+        $join[] = ['table'=>'project as P','cond'=>'P.id = L.projectid','type'=>'left'];
+        $pro_list = $this->Lamp_model->get_list_by_join($where, 'P.cityid',NULL, NULL, $join, null, 'L.projectid', 'L');
         $cityArr = array_unique(array_column($pro_list, 'cityid'));
         $list = $this->Global_location_model->get_list(['id'=>$cityArr],'id,english_name as name,level,pid');
         $areaList = array();
@@ -635,10 +722,27 @@ class Home extends Base_Controller {
         $where = array();
         if ($role != SYSTEM_ADMIN) {
             $company = $this->get_user_info('company');
-            $where['company'] = $company;
+            $type = $this->get_user_info('role');
+            // $where['company'] = $company;
+
+            if ($type == 2) {
+                // $filter .= ' AND L.manu = '.$company;
+                $where['L.manu'] = $company;
+            }elseif ($type == 3) {
+                // $filter .= ' AND L.supplier = '.$company;
+                $where['L.supplier'] = $company;
+            }elseif ($type == 4) {
+                // $filter .= ' AND L.po = '.$company;
+                $where['L.po'] = $company;
+            }else {
+                $where['P.cityid'] = $company;
+            }
         }
 
-        $pro_list = $this->Project_model->get_list($where,'cityid');
+        // $pro_list = $this->Project_model->get_list($where,'cityid');
+        $join = array();
+        $join[] = ['table'=>'project as P','cond'=>'P.id = L.projectid','type'=>'left'];
+        $pro_list = $this->Lamp_model->get_list_by_join($where, 'P.cityid',NULL, NULL, $join, null, 'L.projectid', 'L');
         $cityArr = array_unique(array_column($pro_list, 'cityid'));
         $list = $this->Global_location_model->get_list(['id'=>$cityArr],'id,english_name as name,level,pid');
         $areaList = array();
@@ -706,7 +810,24 @@ class Home extends Base_Controller {
         $company = $this->get_user_info('company');
         $where = array();
 
-        if ($role != SYSTEM_ADMIN) $where['P.company'] = $company;
+        if ($role != SYSTEM_ADMIN) {
+            if ($role == 2) {
+                // $filter .= ' AND L.manu = '.$company;
+                $where['L.manu = '] = $company;
+                // $countWhere[] = 'manu = '.$company;
+            }elseif ($role == 3) {
+                // $filter .= ' AND L.supplier = '.$company;
+                // $countWhere[] = 'supplier = '.$company;
+                $where['L.supplier = '] = $company;
+            }elseif ($role == 4) {
+                // $filter .= ' AND L.po = '.$company;
+                // $countWhere[] = 'po = '.$company;
+                $where['L.po = '] = $company;
+            }else {
+                // $filter .= ' AND P.cityid = '.$company;
+                $where['P.cityid = '] = $company;
+            }
+        }
         $where['G3.level'] = 2;
         $where['G3.pid'] = 92;
         $join = array();
@@ -714,9 +835,10 @@ class Home extends Base_Controller {
         $join[] = ['table'=>'global_location as G2','cond'=>'G3.id = G2.pid AND G2.level = 3','type'=>'left'];
         $join[] = ['table'=>'global_location as G1','cond'=>'G2.id = G1.pid AND G1.level = 4','type'=>'left'];
         $join[] = ['table'=>'project as P','cond'=>'G1.id = P.cityid AND G1.level = 4','type'=>'left'];
+        $join[] = ['table'=>'lampinfo as L','cond'=>'L.projectid = P.id','type'=>'left'];
         
         // $join[] = ['table'=>'global_location as G3','cond'=>'G3.id = G2.pid AND G3.level = 2','type'=>'left'];
-        $list = $this->Global_location_model->get_list_by_join($where, 'G3.id,G3.english_name as name,sum(P.lampcount) as lampcount',NULL, NULL, $join, NULL, 'G3.id', 'G3');
+        $list = $this->Global_location_model->get_list_by_join($where, 'G3.id,G3.english_name as name,count(L.id) as lampcount',NULL, NULL, $join, NULL, 'G3.id', 'G3');
         foreach ($list as $key => $value) {
             $list[$key]['lampcount'] = intval($value['lampcount']);
         }
@@ -731,14 +853,33 @@ class Home extends Base_Controller {
         $proId = intval($this->input->post('proId',true));
 
         if (!empty($proId)) $where['G2.pid'] = $proId;
-        if ($role != SYSTEM_ADMIN) $where['P.company'] = $company;
+        if ($role != SYSTEM_ADMIN) {
+            if ($role == 2) {
+                // $filter .= ' AND L.manu = '.$company;
+                $where['L.manu = '] = $company;
+                // $countWhere[] = 'manu = '.$company;
+            }elseif ($role == 3) {
+                // $filter .= ' AND L.supplier = '.$company;
+                // $countWhere[] = 'supplier = '.$company;
+                $where['L.supplier = '] = $company;
+            }elseif ($role == 4) {
+                // $filter .= ' AND L.po = '.$company;
+                // $countWhere[] = 'po = '.$company;
+                $where['L.po = '] = $company;
+            }else {
+                // $filter .= ' AND P.cityid = '.$company;
+                $where['P.cityid = '] = $company;
+            }
+        }
         $where['G2.level'] = 3;
         $join = array();
 
         $join[] = ['table'=>'global_location as G1','cond'=>'G2.id = G1.pid','type'=>'left'];
         $join[] = ['table'=>'project as P','cond'=>'G1.id = P.cityid AND G1.level = 4','type'=>'left'];
+        $join[] = ['table'=>'project as P','cond'=>'G1.id = P.cityid AND G1.level = 4','type'=>'left'];
+        $join[] = ['table'=>'lampinfo as L','cond'=>'L.projectid = P.id','type'=>'left'];
         // $join[] = ['table'=>'global_location as G2','cond'=>'G2.id = G1.pid','type'=>'left'];
-        $list = $this->Global_location_model->get_list_by_join($where, 'G2.id,G2.english_name as name,sum(P.lampcount) as lampcount',NULL, NULL, $join, NULL, 'G2.id', 'G2');
+        $list = $this->Global_location_model->get_list_by_join($where, 'G2.id,G2.english_name as name,count(L.id) as lampcount',NULL, NULL, $join, NULL, 'G2.id', 'G2');
         foreach ($list as $key => $value) {
             $list[$key]['lampcount'] = intval($value['lampcount']);
         }
@@ -753,11 +894,29 @@ class Home extends Base_Controller {
         $cityId = intval($this->input->post('cityId',true));
 
         if (!empty($cityId)) $where['G1.pid'] = $cityId;
-        if ($role != SYSTEM_ADMIN) $where['P.company'] = $company;
+        if ($role != SYSTEM_ADMIN) {
+            if ($role == 2) {
+                // $filter .= ' AND L.manu = '.$company;
+                $where['L.manu = '] = $company;
+                // $countWhere[] = 'manu = '.$company;
+            }elseif ($role == 3) {
+                // $filter .= ' AND L.supplier = '.$company;
+                // $countWhere[] = 'supplier = '.$company;
+                $where['L.supplier = '] = $company;
+            }elseif ($role == 4) {
+                // $filter .= ' AND L.po = '.$company;
+                // $countWhere[] = 'po = '.$company;
+                $where['L.po = '] = $company;
+            }else {
+                // $filter .= ' AND P.cityid = '.$company;
+                $where['P.cityid = '] = $company;
+            }
+        }
         $where['G1.level'] = 4;
         $join = array();
 
         $join[] = ['table'=>'project as P','cond'=>'G1.id = P.cityid AND G1.level = 4','type'=>'left'];
+        $join[] = ['table'=>'lampinfo as L','cond'=>'L.projectid = P.id','type'=>'left'];
         // $join[] = ['table'=>'global_location as G1','cond'=>'G1.id = P.cityid','type'=>'left'];
 
         $list = $this->Global_location_model->get_list_by_join($where, 'G1.id,G1.english_name as name,sum(P.lampcount) as lampcount',NULL, NULL, $join, NULL, 'G1.id', 'G1');
@@ -789,7 +948,23 @@ class Home extends Base_Controller {
         $where[] = 'P.id in ('.implode(',', $projectIdArr).')';
         if ($role != SYSTEM_ADMIN){
             $company = $this->get_user_info('company');
-            $where[] = 'P.company = '.$company;
+            // $where[] = 'P.company = '.$company;
+            if ($role == 2) {
+                // $filter .= ' AND L.manu = '.$company;
+                $where[] = 'L.manu = '.$company;
+                // $countWhere[] = 'manu = '.$company;
+            }elseif ($role == 3) {
+                // $filter .= ' AND L.supplier = '.$company;
+                // $countWhere[] = 'supplier = '.$company;
+                $where[] = 'L.supplier = '.$company;
+            }elseif ($role == 4) {
+                // $filter .= ' AND L.po = '.$company;
+                // $countWhere[] = 'po = '.$company;
+                $where[] = 'L.po = '.$company;
+            }else {
+                // $filter .= ' AND P.cityid = '.$company;
+                $where[] = 'P.cityid = '.$company;
+            }
             $data['project_count'] = $this->Project_model->get_count(['id'=>$projectIdArr,'company'=>$company]);
         }else{
             $data['project_count'] = count($projectIdArr);

+ 10 - 5
api/application/controllers/Project.php

@@ -439,38 +439,43 @@ class Project extends Base_Controller {
                 exit(json_result('0000',$this->response['0000'],$data));
             }
         }else{
-            if ($role != SYSTEM_ADMIN) $where['P.company'] = $company;
+            // if ($role != SYSTEM_ADMIN) $where['P.company'] = $company;
 
             $join = [];
             $join[] = ['table'=>'project as P','cond'=>'L.projectid = P.id','type'=>'inner'];
             if ($type == 2) {
-                $sectionWhere = ['manu !='=>0];
+                if ($role != SYSTEM_ADMIN) $where['P.company'] = $company;
+                // $sectionWhere = ['manu !='=>0];
                 $join[] = ['table'=>'company as C','cond'=>'L.manu = C.id','type'=>'inner'];
                 $group = 'L.manu,L.projectid';
                 $order = 'convert(C.name using gbk) asc';
                 $fields = 'C.name as company,C.no,P.projectname,P.id,C.id as cId,count(*) as lampcount';
             }elseif ($type == 3) {
-                $sectionWhere = ['supplier !='=>0];
+                $sectionWhere = ['supplier'=>$company];
+                if ($role != SYSTEM_ADMIN) $where = ['L.supplier'=>$company];
                 $join[] = ['table'=>'company as C','cond'=>'L.supplier = C.id','type'=>'inner'];
                 $group = 'L.supplier,L.projectid';
                 $order = 'convert(C.name using gbk) asc';
                 $fields = 'C.name as company,C.no,P.projectname,P.id,C.id as cId,count(*) as lampcount';
             }elseif ($type == 4) {
-                $sectionWhere = ['po !='=>0];
+                $sectionWhere = ['po'=>$company];
+                if ($role != SYSTEM_ADMIN) $where = ['L.po'=>$company];
                 $join[] = ['table'=>'company as C','cond'=>'L.po = C.id','type'=>'inner'];
                 $group = 'L.po,L.projectid';
                 $order = 'convert(C.name using gbk) asc';
                 $fields = 'C.name as company,C.no,P.projectname,P.id,C.id as cId,count(*) as lampcount';
             }else {
                 // $sectionWhere = ['upazilla !='=>0];
+                if ($role != SYSTEM_ADMIN) $where = ['P.cityid'=>$company];
                 $join[] = ['table'=>'global_location as G','cond'=>'G.id = P.cityid','type'=>'left'];
                 // $join[] = ['table'=>'project as P','cond'=>'P.id = L.projectid','type'=>'left'];
                 $group = 'P.cityid,p.id';
                 $order = 'convert(G.english_name using gbk) asc';
                 $fields = 'G.english_name as company,P.projectname,P.id,G.id as cId,count(*) as lampcount';
             }
-
+            // var_dump($where);die;
             $data = $this->Lamp_model->get_list_by_join($where, $fields,NULL, NULL, $join, $order, $group, 'L');
+            // var_dump($data);die;
             if (!empty($data)) {
                 $temp = array();
                 $temp2 = array();