소스 검색

common search

ShuanghongS 1 년 전
부모
커밋
e5639d5ab1
3개의 변경된 파일113개의 추가작업 그리고 106개의 파일을 삭제
  1. 13 5
      main_new_version.php
  2. 97 100
      service/login.class.php
  3. 3 1
      service/ocean_order.class.php

+ 13 - 5
main_new_version.php

@@ -621,11 +621,19 @@ switch ($action) {
         //           {"lng":"-122.28640000","lat":"37.79784000","label":"Transfer","infor":"OAKLAND, CA, USA","sort":"2","stime":null,"ptype":"pod"}]';
         //$rss = json_decode($json,true);
         //global $mapdb;
-        //查询实线
-        //$solidLine = $mapdb->GetAll("select * from get_track_data('$serial_no',true)");
-        //查询虚线
-        //$dottedLine = $mapdb->GetAll("select * from get_track_data('$serial_no',false)");
-        //$data = array("point"=>$rss,"solidLine"=>$solidLine,"dottedLine"=>$dottedLine);
+        //查询线(包含所有的线)
+        // $Line = $mapdb->GetAll("select * from get_track_data('$serial_no',true)");
+        // $solidLine = array();
+        // $dottedLine = array();
+        // foreach($Line as $line){
+        //     if($line['tp'] == "1"){
+        //         $solidLine[] = $line;
+        //     }else{
+        //         $dottedLine[] = $line;
+        //     }
+        // }
+        // $data = array("point"=>$rss,"solidLine"=>$solidLine,"dottedLine"=>$dottedLine);
+        // common::echo_json_encode(200, $data);
         common::echo_json_encode(200, $rss);
         exit();
         break;

+ 97 - 100
service/login.class.php

@@ -1147,7 +1147,18 @@ class login {
             common::echo_json_encode(400, $data);
             exit();
         }else{
-            $data =  $this->getTrackingInfo($reference_number);
+            $reference_number_lower = strtolower($reference_number);
+            $online_ocean_sql = "select serial_no,order_from from online_ocean 
+                where ((ARRAY['$reference_number_lower'] && array_append(ARRAY[lower(booking_no::text), lower(h_bol::text), lower(m_bol), lower(carrier_booking), lower(quote_no), lower(tracking_no)]||string_to_array(lower(ctnrs),','), ''::text))
+                    or text_search @@ (str_to_tsquery('$reference_number')))";
+            $online_ocean_arr = common::excuteListSql($online_ocean_sql);        
+            if(empty($online_ocean_arr)){
+                $data = array("msg" =>"No matches");
+            }elseif(!empty($online_ocean_arr) && count($online_ocean_arr) > 1){
+                $data = array("msg" =>"Multiple results");
+            }else{
+                $data =  $this->getTrackingInfo($online_ocean_arr[0]["serial_no"],$online_ocean_arr[0]["order_from"]);
+            }
             common::echo_json_encode(200, $data);
             //记录查询log情况
             $detail = "";
@@ -1199,94 +1210,13 @@ class login {
         }
     }
 
-    private function getTrackingInfo($reference_number){
-        $reference_number_lower = 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_lower'] && 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 o 
-            LEFT JOIN LATERAL ( SELECT tracking_no as _tracking_no,shippr_uncode,shipper_city,
-                    consignee_uncode,consignee_city,incoterms,
-                    fport_of_loading_un,
-                    mport_of_discharge_un,
-                    place_of_receipt_un,
-                    place_of_delivery_un,
-                    (select time_zone from public.city_timezone where uncode = oo.fport_of_loading_un limit 1) as pol_timezone,
-                    (select uncity from public.ports where uncode = oo.fport_of_loading_un limit 1) as pol_uncity,
-                    (select time_zone from public.city_timezone where uncode = oo.mport_of_discharge_un limit 1) as mpod_timezone,
-                    (select uncity from public.ports where uncode = oo.mport_of_discharge_un limit 1) as mpod_uncity,
-                    (select time_zone from public.city_timezone where uncode = oo.place_of_receipt_un limit 1) as por_timezone,
-                    (select uncity from public.ports where uncode = oo.place_of_receipt_un limit 1) as por_uncity,
-                    (select time_zone from public.city_timezone where uncode = oo.place_of_delivery_un limit 1) as pod_timezone,
-                    (select uncity from public.ports where uncode = oo.place_of_delivery_un limit 1) as pod_uncity,
-                    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_iffdel is null) THEN 'Created'::text
-                        WHEN ((m_iffcpu is not null or m_iffrec is not null) and m_iffdep is null and m_iffarr is null and m_iffdel is null) THEN 'Cargo Received'::text
-                        WHEN (m_iffdep is not null and m_iffarr is null and m_iffdel is null) THEN 'Departure'::text
-                        WHEN (m_iffarr is not null and m_iffdel is null) THEN 'Arrived'::text
-                        WHEN (m_iffdel is not null) THEN 'Completed'::text
-                        ELSE 'Created'::text
-                    END AS new_status
-                FROM  public.online_ocean oo WHERE oo.serial_no::text = o.serial_no::text) oo ON true
-            LEFT JOIN LATERAL ( SELECT company as cn_company,
-                address_1 as cn_address_1,
-                address_2 as cn_address_2,
-                address_3 as cn_address_3,
-                address_4 as cn_address_4,
-                city as cn_city, state as cn_state, zipcode as cn_zipcode, country as cn_country,
-                phone_1 as cn_phone
-            FROM ocean.contacts c WHERE o.consignee::text = c.contact_id::text) cn ON true
-            LEFT JOIN LATERAL ( SELECT company as sh_company,
-                address_1 as sh_address_1,
-                address_2 as sh_address_2,
-                address_3 as sh_address_3,
-                address_4 as sh_address_4,
-                city as sh_city, state as sh_state, zipcode as sh_zipcode, country as sh_country,
-                phone_1 as sh_phone
-            FROM ocean.contacts c WHERE o.shipper::text = c.contact_id::text) sh ON true
-            LEFT JOIN LATERAL ( SELECT company as aa_company,
-                address_1 as aa_address_1,
-                address_2 as aa_address_2,
-                address_3 as aa_address_3,
-                address_4 as aa_address_4,
-                city as aa_city, state as aa_state, zipcode as aa_zipcode, country as aa_country,
-                phone_1 as aa_phone,
-                (select time_zone from public.city_timezone where uncode = LEFT(country, 2) || COALESCE(city_code,'') limit 1) as aa_timezone
-            FROM ocean.contacts c WHERE o.origin_station::text = c.contact_id::text) aa ON true
-            LEFT JOIN LATERAL ( SELECT company as dd_company,
-                address_1 as dd_address_1,
-                address_2 as dd_address_2,
-                address_3 as dd_address_3,
-                address_4 as dd_address_4,
-                city as dd_city, state as dd_state, zipcode as dd_zipcode, country as dd_country,
-                phone_1 as dd_phone,
-                (select time_zone from public.city_timezone where uncode = LEFT(country, 2) || COALESCE(city_code,'') limit 1) as dd_timezone
-            FROM ocean.contacts c WHERE o.destination_station::text = c.contact_id::text) dd ON true
-            LEFT JOIN LATERAL ( SELECT 
-                city as fd_city,
-                (select time_zone from public.city_timezone where uncode = 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";
+    private function getTrackingInfo($serial_no,$order_from){
+        $sql = $this->trackingSql($serial_no,$order_from);
         $ocean_arr = common::excuteListSql($sql);
 
         if(empty($ocean_arr)){
-            $sql = $this->trackingSfsSql($reference_number);
-            $ocean_arr = common::excuteListSql($sql);
-            if(empty($ocean_arr)){
-                $data = array("msg" =>"No matches");
-                return $data;
-            }
+            $data = array("msg" =>"No matches");
+            return $data;
         }
         if(!empty($ocean_arr) && count($ocean_arr) > 1){
             $data = array("msg" =>"Multiple results");
@@ -1313,7 +1243,7 @@ class login {
         $vessel = utils::outDisplayForMerge($ocean['f_vessel'],$ocean['m_vessel']);
         $voyage = utils::outDisplayForMerge($ocean['f_voyage'],$ocean['m_voyage']);
         $basicInfo = array("MAWB/MBL No." =>$ocean['m_bol'],"HAWB/HBOL" => $ocean['h_bol'],"Carrier_Booking_No" =>$ocean['booking_no'],
-            "PO_NO" =>$ocean['po_no'],"Vessel/Airline" =>$vessel,"Voyage/Filght" =>$voyage,
+            "PO_NO" =>$ocean['_po_no'],"Vessel/Airline" =>$vessel,"Voyage/Filght" =>$voyage,
             "Incoterm" =>$ocean['incoterms'],"Service_Type" =>$ocean['service']);
 
         //处理 拼接地址 ocean表单exp 字段无法精准分割电话和地址信息,只能从contacts表里查询
@@ -1430,18 +1360,80 @@ class login {
         return array("msg" =>"success","data" =>$data);
     }
 
-    private function trackingSfsSql($reference_number){
-        $reference_number_lower = strtolower($reference_number);
-        $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_lower'] && 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 sfs.oc_container oc where o.serial_no = oc.serial_no and oc.ctnr = '$reference_number')
+    private function trackingSql($serial_no,$order_from){
+        $public_sql = "with o as(
+            SELECT  o.* from public.ocean o where o.serial_no = '$serial_no')
+        )
+        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 o 
+            LEFT JOIN LATERAL ( SELECT tracking_no as _tracking_no,shippr_uncode,shipper_city,
+                    consignee_uncode,consignee_city,incoterms,
+                    fport_of_loading_un,
+                    mport_of_discharge_un,
+                    place_of_receipt_un,
+                    place_of_delivery_un,
+                    (select time_zone from public.city_timezone where uncode = oo.fport_of_loading_un limit 1) as pol_timezone,
+                    (select uncity from public.ports where uncode = oo.fport_of_loading_un limit 1) as pol_uncity,
+                    (select time_zone from public.city_timezone where uncode = oo.mport_of_discharge_un limit 1) as mpod_timezone,
+                    (select uncity from public.ports where uncode = oo.mport_of_discharge_un limit 1) as mpod_uncity,
+                    (select time_zone from public.city_timezone where uncode = oo.place_of_receipt_un limit 1) as por_timezone,
+                    (select uncity from public.ports where uncode = oo.place_of_receipt_un limit 1) as por_uncity,
+                    (select time_zone from public.city_timezone where uncode = oo.place_of_delivery_un limit 1) as pod_timezone,
+                    (select uncity from public.ports where uncode = oo.place_of_delivery_un limit 1) as pod_uncity,
+                    po_no as _po_no,
+                    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_iffdel is null) THEN 'Created'::text
+                        WHEN ((m_iffcpu is not null or m_iffrec is not null) and m_iffdep is null and m_iffarr is null and m_iffdel is null) THEN 'Cargo Received'::text
+                        WHEN (m_iffdep is not null and m_iffarr is null and m_iffdel is null) THEN 'Departure'::text
+                        WHEN (m_iffarr is not null and m_iffdel is null) THEN 'Arrived'::text
+                        WHEN (m_iffdel is not null) THEN 'Completed'::text
+                        ELSE 'Created'::text
+                    END AS new_status
+                FROM  public.online_ocean oo WHERE oo.serial_no::text = o.serial_no::text) oo ON true
+            LEFT JOIN LATERAL ( SELECT company as cn_company,
+                address_1 as cn_address_1,
+                address_2 as cn_address_2,
+                address_3 as cn_address_3,
+                address_4 as cn_address_4,
+                city as cn_city, state as cn_state, zipcode as cn_zipcode, country as cn_country,
+                phone_1 as cn_phone
+            FROM ocean.contacts c WHERE o.consignee::text = c.contact_id::text) cn ON true
+            LEFT JOIN LATERAL ( SELECT company as sh_company,
+                address_1 as sh_address_1,
+                address_2 as sh_address_2,
+                address_3 as sh_address_3,
+                address_4 as sh_address_4,
+                city as sh_city, state as sh_state, zipcode as sh_zipcode, country as sh_country,
+                phone_1 as sh_phone
+            FROM ocean.contacts c WHERE o.shipper::text = c.contact_id::text) sh ON true
+            LEFT JOIN LATERAL ( SELECT company as aa_company,
+                address_1 as aa_address_1,
+                address_2 as aa_address_2,
+                address_3 as aa_address_3,
+                address_4 as aa_address_4,
+                city as aa_city, state as aa_state, zipcode as aa_zipcode, country as aa_country,
+                phone_1 as aa_phone,
+                (select time_zone from public.city_timezone where uncode = LEFT(country, 2) || COALESCE(city_code,'') limit 1) as aa_timezone
+            FROM ocean.contacts c WHERE o.origin_station::text = c.contact_id::text) aa ON true
+            LEFT JOIN LATERAL ( SELECT company as dd_company,
+                address_1 as dd_address_1,
+                address_2 as dd_address_2,
+                address_3 as dd_address_3,
+                address_4 as dd_address_4,
+                city as dd_city, state as dd_state, zipcode as dd_zipcode, country as dd_country,
+                phone_1 as dd_phone,
+                (select time_zone from public.city_timezone where uncode = LEFT(country, 2) || COALESCE(city_code,'') limit 1) as dd_timezone
+            FROM ocean.contacts c WHERE o.destination_station::text = c.contact_id::text) dd ON true
+            LEFT JOIN LATERAL ( SELECT 
+                city as fd_city,
+                (select time_zone from public.city_timezone where uncode = 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";
+
+        $sfs_sql = "with o as(
+                SELECT  o.* from sfs.ocean o where o.serial_no = '$serial_no')
+            )
         )
         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.*,
@@ -1461,6 +1453,7 @@ class login {
                     (select uncity from public.ports where uncode = oo.place_of_receipt_un limit 1) as por_uncity,
                     (select time_zone from public.city_timezone where uncode = oo.place_of_delivery_un limit 1) as pod_timezone,
                     (select uncity from public.ports where uncode = oo.place_of_delivery_un limit 1) as pod_uncity,
+                    po_no as _po_no,
                     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_iffdel is null) THEN 'Created'::text
                         WHEN ((m_iffcpu is not null or m_iffrec is not null) and m_iffdep is null and m_iffarr is null and m_iffdel is null) THEN 'Cargo Received'::text
@@ -1508,7 +1501,11 @@ class login {
                 city as fd_city,
                 (select time_zone from public.city_timezone where uncode = 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";
-        return $sql;
+        if(strtolower($order_from) == "public"){
+            return $public_sql;
+        }else{
+            return $sfs_sql;
+        }    
     }
 
     private function AES_encrypted($encrypted_string,$isbase64_encode = true){

+ 3 - 1
service/ocean_order.class.php

@@ -397,7 +397,9 @@ class ocean_order {
             //     $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),lower(tracking_no)],''))";
+            //$sqlWhere .= " and (ARRAY[$more_param] && array_append(array[lower(booking_no)::text,lower(h_bol)::text, lower(po_no),lower(carrier_booking),lower(tracking_no)],''))";
+            $sqlWhere .= " and ((ARRAY[$more_param] && array_append(ARRAY[lower(booking_no::text), lower(h_bol::text), lower(m_bol), lower(carrier_booking), lower(quote_no), lower(tracking_no)]||string_to_array(lower(ctnrs),','), ''::text)) 
+                or text_search @@ (str_to_tsquery('" . common::check_input($_POST["_textSearch"]) . "')))";
         }
         //移除filterTag
         $sqlWhere_befrom_filterTag  = $sqlWhere;