ShuanghongS пре 1 година
родитељ
комит
8b509b9c1c
4 измењених фајлова са 90 додато и 55 уклоњено
  1. 29 25
      service/login.class.php
  2. 12 10
      service/ocean_booking.class.php
  3. 14 12
      service/ocean_order.class.php
  4. 35 8
      utils/common.class.php

+ 29 - 25
service/login.class.php

@@ -1174,10 +1174,23 @@ class login {
     }
 
     private function getTrackingInfo($reference_number){
-        $sql = "SELECT m_eta as _m_eta,  h_bol as _h_bol, m_bol as _m_bol,job_no as _job_bol,
+        $reference_number = strtolower($reference_number);
+        $sql = "with o as(
+            SELECT  o.* 
+                from public.ocean o 
+                where o.status::text <> 'Cancelled'::text AND o.bol_type::text <> 'BOOKING'::text AND o.bol_type::text <> 'QUOTE'::text AND o.iscts = true 
+                    AND o.iscts IS NOT NULL and ARRAY['$reference_number'] && array_append(array[lower(tracking_no)::text,lower(booking_no)::text,lower(h_bol)::text,lower(m_bol)::text, lower(po_no),lower(quote_no)::text,lower(invoice_no)],'')
+            union       
+            SELECT  o.* 
+                from public.ocean o 
+                where o.status::text <> 'Cancelled'::text AND o.bol_type::text <> 'BOOKING'::text AND o.bol_type::text <> 'QUOTE'::text AND o.iscts = true 
+                    AND o.iscts IS NOT NULL and exists (select 1 from oc_container oc where o.serial_no = oc.serial_no and oc.ctnr = '$reference_number')
+
+        )
+        SELECT m_eta as _m_eta,  h_bol as _h_bol, m_bol as _m_bol,job_no as _job_bol,
                 o.* ,sh.*, cn.* ,aa.*,dd.*,fd.*,oo.*,
                 (select uncode from ports where  code = o.port_of_transshipment) as port_of_transshipment_un
-            from public.ocean o 
+            from o 
             LEFT JOIN LATERAL ( SELECT tracking_no as _tracking_no,shippr_uncode,shipper_city,
                     consignee_uncode,consignee_city,incoterms,
                     fport_of_loading_un,
@@ -1239,17 +1252,7 @@ class login {
             LEFT JOIN LATERAL ( SELECT 
                 city as fd_city,
                 (select timezonecode from public.city_ports where ctrycitycode = LEFT(country, 2) || COALESCE(city_code,'') limit 1) as fd_timezone
-            FROM ocean.contacts c WHERE o.final_desination::text = c.contact_id::text) fd ON true
-            where o.status::text <> 'Cancelled'::text AND o.bol_type::text <> 'BOOKING'::text AND o.bol_type::text <> 'QUOTE'::text AND o.iscts = true 
-                AND o.iscts IS NOT NULL 
-                AND (lower(tracking_no) = '" . strtolower($reference_number) . "' 
-                or lower(booking_no) = '" . strtolower($reference_number) . "'
-                or lower(h_bol) = '" . strtolower($reference_number) . "'
-                or lower(m_bol) = '" . strtolower($reference_number) . "'
-                or lower(po_no) = '" . strtolower($reference_number) . "'
-                or lower(quote_no) = '" . strtolower($reference_number) . "'
-                or lower(invoice_no) = '" . strtolower($reference_number) . "'
-                or exists (select 1 from oc_container oc where o.serial_no = oc.serial_no and oc.ctnr = '$reference_number'))";
+            FROM ocean.contacts c WHERE o.final_desination::text = c.contact_id::text) fd ON true";
         $ocean_arr = common::excuteListSql($sql);
 
         if(empty($ocean_arr)){
@@ -1403,7 +1406,18 @@ class login {
     }
 
     private function trackingSfsSql($reference_number){
-        $sql = "SELECT m_eta as _m_eta,  h_bol as _h_bol, m_bol as _m_bol,job_no as _job_bol,
+        $sql = "with o as(
+            SELECT  o.* 
+                from sfs.ocean o 
+                where o.status::text <> 'Cancelled'::text AND o.bol_type::text <> 'BOOKING'::text AND o.bol_type::text <> 'QUOTE'::text AND o.iscts = true 
+                    AND o.iscts IS NOT NULL and ARRAY['$reference_number'] && array_append(array[lower(tracking_no)::text,lower(booking_no)::text,lower(h_bol)::text,lower(m_bol)::text, lower(po_no),lower(quote_no)::text,lower(invoice_no)],'')
+            union       
+            SELECT  o.* 
+                from sfs.ocean o 
+                where o.status::text <> 'Cancelled'::text AND o.bol_type::text <> 'BOOKING'::text AND o.bol_type::text <> 'QUOTE'::text AND o.iscts = true 
+                    AND o.iscts IS NOT NULL and exists (select 1 from oc_container oc where o.serial_no = oc.serial_no and oc.ctnr = '$reference_number')
+        )
+        SELECT m_eta as _m_eta,  h_bol as _h_bol, m_bol as _m_bol,job_no as _job_bol,
                 o.* ,sh.*, cn.* ,aa.*,dd.*,fd.*,oo.*,
                 (select uncode from ports where  code = o.port_of_transshipment) as port_of_transshipment_un
             from sfs.ocean o 
@@ -1468,17 +1482,7 @@ class login {
             LEFT JOIN LATERAL ( SELECT 
                 city as fd_city,
                 (select timezonecode from public.city_ports where ctrycitycode = LEFT(country, 2) || COALESCE(city_code,'') limit 1) as fd_timezone
-            FROM sfs.contacts c WHERE o.final_desination::text = c.contact_id::text) fd ON true
-        where o.status::text <> 'Cancelled'::text AND o.bol_type::text <> 'BOOKING'::text AND o.bol_type::text <> 'QUOTE'::text AND o.iscts = true 
-            AND o.iscts IS NOT NULL 
-            AND (lower(tracking_no) = '" . strtolower($reference_number) . "' 
-            or lower(booking_no) = '" . strtolower($reference_number) . "'
-            or lower(h_bol) = '" . strtolower($reference_number) . "'
-            or lower(m_bol) = '" . strtolower($reference_number) . "'
-            or lower(po_no) = '" . strtolower($reference_number) . "'
-            or lower(quote_no) = '" . strtolower($reference_number) . "'
-            or lower(invoice_no) = '" . strtolower($reference_number) . "'
-            or exists (select 1 from oc_container oc where o.serial_no = oc.serial_no and oc.ctnr = '$reference_number'))";
+            FROM sfs.contacts c WHERE o.final_desination::text = c.contact_id::text) fd ON true";
         return $sql;
     }
 

+ 12 - 10
service/ocean_booking.class.php

@@ -141,16 +141,18 @@ class ocean_booking {
             if(!is_array($textSearch_arr)){
                 $textSearch_arr = array($textSearch_arr);
             }
-            $more_sql = "1<>1";
-            foreach($textSearch_arr as $tsv){
-                $more_sql .= " or  booking_no ilike '%" . common::check_input(trim($tsv)) . "%'";
-                $more_sql .= " or  h_bol ilike '%" . common::check_input(trim($tsv)) . "%'";
-                $more_sql .= " or  po_no ilike '%" . common::check_input(trim($tsv)) . "%'";
-                $more_sql .= " or  carrier_booking ilike '%" . common::check_input(trim($tsv)) . "%'";
-            }
-            if ($more_sql <> "1<>1"){
-                $sqlWhere .= " and ($more_sql)";
-            } 
+            // $more_sql = "1<>1";
+            // foreach($textSearch_arr as $tsv){
+            //     $more_sql .= " or  booking_no ilike '%" . common::check_input(trim($tsv)) . "%'";
+            //     $more_sql .= " or  h_bol ilike '%" . common::check_input(trim($tsv)) . "%'";
+            //     $more_sql .= " or  po_no ilike '%" . common::check_input(trim($tsv)) . "%'";
+            //     $more_sql .= " or  carrier_booking ilike '%" . common::check_input(trim($tsv)) . "%'";
+            // }
+            // if ($more_sql <> "1<>1"){
+            //     $sqlWhere .= " and ($more_sql)";
+            // }
+            $more_param = common::getInNotInSqlForSearch(strtolower(implode(';',$textSearch_arr)));
+            $sqlWhere .= " and (ARRAY[$more_param] && array_append(array[lower(booking_no)::text,lower(h_bol)::text, lower(po_no),lower(carrier_booking)],''))"; 
         } 
         //为了移除filterTag条件
         $sqlWhere_befrom_filterTag  = $sqlWhere;

+ 14 - 12
service/ocean_order.class.php

@@ -386,16 +386,18 @@ class ocean_order {
             if(!is_array($textSearch_arr)){
                 $textSearch_arr = array($textSearch_arr);
             }
-            $more_sql = "1<>1";
-            foreach($textSearch_arr as $tsv){
-                $more_sql .= " or  booking_no ilike '%" . common::check_input(trim($tsv)) . "%'";
-                $more_sql .= " or  h_bol ilike '%" . common::check_input(trim($tsv)) . "%'";
-                $more_sql .= " or  po_no ilike '%" . common::check_input(trim($tsv)) . "%'";
-                $more_sql .= " or  carrier_booking ilike '%" . common::check_input(trim($tsv)) . "%'";
-            }
-            if ($more_sql <> "1<>1"){
-                $sqlWhere .= " and ($more_sql)";
-            } 
+            // $more_sql = "1<>1";
+            // foreach($textSearch_arr as $tsv){
+            //     $more_sql .= " or  booking_no ilike '%" . common::check_input(trim($tsv)) . "%'";
+            //     $more_sql .= " or  h_bol ilike '%" . common::check_input(trim($tsv)) . "%'";
+            //     $more_sql .= " or  po_no ilike '%" . common::check_input(trim($tsv)) . "%'";
+            //     $more_sql .= " or  carrier_booking ilike '%" . common::check_input(trim($tsv)) . "%'";
+            // }
+            // if ($more_sql <> "1<>1"){
+            //     $sqlWhere .= " and ($more_sql)";
+            // }
+            $more_param = common::getInNotInSqlForSearch(strtolower(implode(';',$textSearch_arr)));
+            $sqlWhere .= " and (ARRAY[$more_param] && array_append(array[lower(booking_no)::text,lower(h_bol)::text, lower(po_no),lower(carrier_booking)],''))";
         }
         //移除filterTag
         $sqlWhere_befrom_filterTag  = $sqlWhere;
@@ -454,7 +456,7 @@ class ocean_order {
         if ($rc == - 1 || true) {
             $sql = "select count(1) as rc,
                 sum(case when $filterTag_param then 1 else 0 end) as seach_rc, 
-                sum(case when ((m_iffbcf is not null or m_iffbcf is null) and m_iffcpu is null and m_iffrec is null and m_iffdep is null and m_iffarr is null and m_iffafd is null)
+                sum(case when (m_iffcpu is null and m_iffrec is null and m_iffdep is null and m_iffarr is null and m_iffafd is null)
                      then 1 else 0 end) 
                 as created, 
                 sum(case when ((m_iffcpu is not null or m_iffrec is not null) and m_iffdep is null and m_iffarr is null and m_iffafd is null)
@@ -1163,7 +1165,7 @@ class ocean_order {
                 city as fd_city,
                 (select timezonecode from public.city_ports where ctrycitycode = LEFT(country, 2) || COALESCE(city_code,'') limit 1) as fd_timezone
             FROM $_schemas.contacts c WHERE o.final_desination::text = c.contact_id::text) fd ON true
-        where lower(serial_no) = '" . strtolower($serial_no) . "'";
+        where serial_no = '" . $serial_no . "'";
         //error_log($sql);
         return $sql;
     }

+ 35 - 8
utils/common.class.php

@@ -200,14 +200,16 @@ class common {
             {
                 return "1=1";
             }
-            return " (schem_not_display is null or schem_not_display=false)";
+            //return " (schem_not_display is null or schem_not_display=false)";
+            return " (COALESCE(schem_not_display,false) = false)";
         }
         if (_isDocAdmin($user["user_login"])) {
             if(strtolower($type) == "air_booking" ) //|| strtolower($type) == "air"
             {
                 return "1=1";
             }
-            return ' (schem_not_display is null or schem_not_display=false)';
+            //return ' (schem_not_display is null or schem_not_display=false)';
+            return ' (COALESCE(schem_not_display,false) = false)';
         }
         if (strtolower($type) != "ocean" && strtolower($type) != "booking" && strtolower($type) != "air_booking"&& strtolower($type) != "air") {
             return " 1<>1";
@@ -436,6 +438,31 @@ class common {
         }
     }
 
+    public static function getInNotInSqlForSearch($contact_id, $type = 'in') {
+        if (empty($contact_id))
+            return " =''";
+        $contact_id = trim($contact_id);
+        $contact_id = trim($contact_id, ";");
+        $contact_id = trim($contact_id);
+        $contact_id = strtolower($contact_id);
+        if ($type == 'in') {
+            if (utils::checkExist($contact_id, ";")) {
+                $ss = "";
+                $aa = explode(";", $contact_id);
+                foreach ($aa as $k => $v) {
+                    $v = trim($v);
+                    if (empty($ss))
+                        $ss = "'" . common::check_input($v) . "'";
+                    else
+                        $ss .= ",'" . common::check_input($v) . "'";
+                }
+                return  $ss;
+            } else {
+                return "'" . common::check_input($contact_id) . "'";
+            }
+        }
+    }
+
      /*
      * Encrypt a SQL query statement used to be passed as a parameter to get excel output
       encode  :DeCode('str','E');
@@ -1202,12 +1229,12 @@ class common {
         //先查询总的排放量sea air road,确定排名后,在分别查询对应的sea air road
         if ($type == "co2e_orgin"){
             $co2e_shippr_sql = "select SUM(COALESCE(carbon_emission,0)::numeric(12,10)) as catnum ,
-                shippr_uncode as station from online_ocean  where 1=1 and COALESCE(shippr_uncode)<>'' $sqlWhere group by shippr_uncode order by catnum desc limit 10";
+                shippr_uncode as station from online_ocean  where 1=1 and COALESCE(shippr_uncode,'')<>'' $sqlWhere group by shippr_uncode order by catnum desc limit 10";
             $co2e_aLL = common::excuteListSql($co2e_shippr_sql);
         }
         if ($type == "co2e_destination"){
             $co2e_consignee_sql = "select SUM(COALESCE(carbon_emission,0)::numeric(12,10)) as catnum,
-                consignee_uncode as station from online_ocean  where 1=1 and COALESCE(consignee_uncode)<>'' $sqlWhere group by consignee_uncode order by catnum desc limit 10";
+                consignee_uncode as station from online_ocean  where 1=1 and COALESCE(consignee_uncode,'')<>'' $sqlWhere group by consignee_uncode order by catnum desc limit 10";
             $co2e_aLL = common::excuteListSql($co2e_consignee_sql);
         }
         //最大Y值
@@ -1278,7 +1305,7 @@ class common {
         $toporiginType = "shippr_uncode";
         $shippr_uncode_10_sql ="with aa as  (select count(shippr_uncode) as num,shippr_uncode,
                                 (array_agg(shipper_city))[1] AS shipper_city from online_ocean  
-                        where 1=1 and COALESCE(shippr_uncode)<>'' $sqlWhere group by shippr_uncode order by num desc limit 10)
+                        where 1=1 and COALESCE(shippr_uncode,'')<>'' $sqlWhere group by shippr_uncode order by num desc limit 10)
             select   aa.*,dd.* from  aa  
             left join LATERAL ( select lon as lng, lat as lat,
                 '' as label, '' as infor, 3 as sort,
@@ -1289,7 +1316,7 @@ class common {
         if(count($shippr_uncode_10) == 1 && empty($shippr_uncode_10[0]["shippr_uncode"])){
             $toporiginType = "fport_of_loading_un";
             $shippr_uncode_10_sql = "with aa as  (select count(fport_of_loading_un) as num,fport_of_loading_un as shippr_uncode 
-                    from online_ocean where 1=1 and COALESCE(fport_of_loading_un)<>'' $sqlWhere group by fport_of_loading_un order by num desc limit 10)
+                    from online_ocean where 1=1 and COALESCE(fport_of_loading_un,'')<>'' $sqlWhere group by fport_of_loading_un order by num desc limit 10)
                     select   aa.*,dd.* from  aa  
                         left join LATERAL ( select lon as lng, lat as lat,
                             '' as label, '' as infor, 3 as sort,
@@ -1302,7 +1329,7 @@ class common {
         $topdestinationinType = "consignee_uncode";
         $consignee_uncode_10_sql = "with aa as  (select count(consignee_uncode) as num,consignee_uncode,
                     (array_agg(consignee_city))[1] AS consignee_city 
-                from online_ocean  where 1=1  and COALESCE(consignee_uncode)<>''  $sqlWhere group by consignee_uncode order by num desc limit 10)
+                from online_ocean  where 1=1  and COALESCE(consignee_uncode,'')<>''  $sqlWhere group by consignee_uncode order by num desc limit 10)
         select   aa.*,dd.* from  aa  
         left join LATERAL ( select lon as lng, lat as lat,
             '' as label, '' as infor, 3 as sort,
@@ -1313,7 +1340,7 @@ class common {
         //如果值没有:客户地址-->站点地址-->Port地址(POL/POD) 
         if(count($consignee_uncode_10) == 1 && empty($consignee_uncode_10[0]["consignee_uncode"])){
             $topdestinationinType = "mport_of_discharge_un";
-            $consignee_uncode_10_sql = "with aa as  (select count(mport_of_discharge_un) as num,mport_of_discharge_un as consignee_uncode from online_ocean where 1=1 and COALESCE(mport_of_discharge_un)<>'' $sqlWhere group by mport_of_discharge_un order by num desc limit 10)
+            $consignee_uncode_10_sql = "with aa as  (select count(mport_of_discharge_un) as num,mport_of_discharge_un as consignee_uncode from online_ocean where 1=1 and COALESCE(mport_of_discharge_un,'')<>'' $sqlWhere group by mport_of_discharge_un order by num desc limit 10)
                 select   aa.*,dd.* from  aa  
                 left join LATERAL ( select lon as lng, lat as lat,
                     '' as label, '' as infor, 3 as sort,