ShuanghongS преди 9 месеца
родител
ревизия
123b976b31
променени са 6 файла, в които са добавени 338 реда и са изтрити 59 реда
  1. 4 1
      main_new_version.php
  2. 3 3
      service/login.class.php
  3. 1 1
      service/ocean_booking.class.php
  4. 147 54
      service/tools.class.php
  5. 175 0
      utils/common.class.php
  6. 8 0
      utils/utils.class.php

+ 4 - 1
main_new_version.php

@@ -772,7 +772,10 @@ switch ($action) {
         break;
     case 'monitoring_setting':
         tools::getInstance()->user_monitoring_setting();
-         break;         
+        break;
+    case 'notifications_rules':
+        tools::getInstance()->notifications_rules();
+        break;              
     case 'user_guide':
         $rootPath = realpath(dirname(__FILE__)) . DS;
         //common::download_file($rootPath."images\ACE-M1_ISF_ACI_User_Guide\ACE-M1_ISF_ACI_User_Guide.pdf", "ACE-M1_ISF_ACI_User_Guide_V2.0.pdf");

+ 3 - 3
service/login.class.php

@@ -1223,7 +1223,7 @@ class login {
     }
 
     private function getTrackingInfo($serial_no,$order_from){
-        $sql = $this->trackingSql($serial_no,$order_from);
+        $sql = common::trackingSql($serial_no,$order_from);
         $ocean_arr = common::excuteListSql($sql);
 
         if(empty($ocean_arr)){
@@ -1280,7 +1280,7 @@ class login {
         $marksAndDescription = array("marks"=>$ocean['marks'],"description"=>$ocean['description']);
         
         if($ocean['transport_mode'] == "sea"){
-            $sql = "SELECT " . column::getInstance()->getSearchSql('Ocean_Container') . " ,net_lbs from oc_container where lower(serial_no) = '" . strtolower($ocean['serial_no']) . "'";
+            $sql = "SELECT " . column::getInstance()->getSearchSql('Ocean_Container') . " ,net_lbs from $order_from.oc_container where lower(serial_no) = '" . strtolower($ocean['serial_no']) . "'";
             $rss = common::excuteListSql($sql);
 
             $quantity_unit = array();
@@ -1320,7 +1320,7 @@ class login {
         //sea 才有EDI315
         if($ocean['transport_mode'] == "sea"){
             $serial_no = $ocean["serial_no"];
-            $ctnr_sql = "SELECT oc.ctnr, oc.serial_no,oc.size FROM oc_container oc LEFT JOIN ocean o ON oc.serial_no = o.serial_no 
+            $ctnr_sql = "SELECT oc.ctnr, oc.serial_no,oc.size FROM $order_from.oc_container oc LEFT JOIN ocean o ON oc.serial_no = o.serial_no 
                     WHERE o.serial_no='$serial_no'";
             $ctnr_data = common::excuteListSql($ctnr_sql); 
             foreach ($ctnr_data as $cd){

+ 1 - 1
service/ocean_booking.class.php

@@ -346,7 +346,7 @@ class ocean_booking {
             $_schemas = "ocean";
         }
         $sql = "with o as(
-            SELECT  o.*,'' as incoterms from ocean o where serial_no = '" .$serial_no . "''
+            SELECT  o.*,'' as incoterms from ocean o where serial_no = '" .$serial_no . "'
         )
         SELECT o.booking_no as _booking_no,
             o.* ,sh.*, cn.* ,aa.*,dd.*,ob.* ,

+ 147 - 54
service/tools.class.php

@@ -357,46 +357,61 @@ class tools {
         $operate = utils::_get('operate');
         $operate = strtolower($operate);
 
-        if ($operate == "notifications"){
-            $rules_type = common::check_input($_POST ['rules_type']); 
+        if ($operate == "notifications_init"){
+            $rules_type = common::check_input($_REQUEST['rules_type']);
+            $milestoneData = array();
+            $containerData = array();
+            $delayData = array();
+            $changeData = array(); 
             if ($rules_type == "all"){
-                $sql = "select *,
-                        (select o.h_bol from public.kln_ocean o where o.serial_no = ni.serial_no limit 1) 
-                    from public.kln_notifiation_info ni
-                    where lower(ni.user_login) = '"._getLoginName()."' 
-                        and (ni.frequency_type = 'Instant' 
-                            or (ni.frequency_type = 'Daily'  and timezone(ni.daily_time_zone, NOW()::time) > ni.daily_time::time)
-                            or (ni.frequency_type = 'Weekly' and timezone(ni.weekly_time_zone, NOW()::time) > ni.weekly_time::time 
-                                and  ni.weekly_week ilike '%'|| EXTRACT(dow FROM timezone(ni.weekly_time_zone, NOW())) ||'%')) 
-                        and ni.notifications_method = true and ni.is_send_message = false order by ni.insert_date desc";   
-            }else{
-                $sql = "select case when COALESCE(ni.milestone_code,'') <> ''  and ni.milestone_transport_mode = 'sea'
-                                    then  (select description from  public.customer_service_milestone_sno where type = 'sea' and code = ni.milestone_code)
-                                else (select description from  public.customer_service_milestone_sno where type = 'air' and code = ni.milestone_code) end as milestone_desc,
-                        ni.milestone_code,*
-                    (select o.h_bol from public.kln_ocean o where o.serial_no = ni.serial_no limit 1)
-                from public.kln_notifiation_info ni
-                    where lower(ni.user_login) = '"._getLoginName()."' 
-                        and ni.rules_type = '".$rules_type."'
-                        and (ni.frequency_type = 'Instant' 
-                            or (ni.frequency_type = 'Daily'  and timezone(ni.daily_time_zone, NOW()::time) > ni.daily_time::time)
-                            or (ni.frequency_type = 'Weekly' and timezone(ni.weekly_time_zone, NOW()::time) > ni.weekly_time::time 
-                                and  ni.weekly_week ilike '%'|| EXTRACT(dow FROM timezone(ni.weekly_time_zone, NOW())) ||'%')) 
-                        and ni.notifications_method = true and ni.is_send_message = false order by ni.insert_date desc";
+                $milestoneData = $this->getNotifications("Milestone_Update","all");
+                $containerData = $this->getNotifications("Container_Status_Update","all");
+                $delayData = $this->getNotifications("Departure/Arrival_Delay","all");
+                $changeData = $this->getNotifications("ETD/ETA_Change","all");
+            } else {
+                $data = $this->getNotifications($rules_type,"all");
+                if($rules_type == "Milestone_Update"){
+                    $milestoneData = $data;
+                }elseif($rules_type == "Container_Status_Update"){
+                    $containerData = $data;
+                }elseif($rules_type == "Departure/Arrival_Delay"){
+                    $delayData = $data;
+                }elseif($rules_type == "ETD/ETA_Change"){
+                    $changeData = $data;
+                }
             }
-            $notifications = common::excuteListSql($sql);
 
-            $all_rules = array("Milestone_Update","Container_Status_Update","Departure/Arrival_Delay","ETD/ETA_Change");
-            
-            foreach($notifications as $notification){
-                if($notification["notifiation_type"] == "Milestone_Update"){
-                    if ($notification["frequency_type"] == "Instant"){
-                        $milestoneInstantMessage[] = array("mode"=>$notification["milestone_transport_mode"],"HBOL"=>$notification["milestone_transport_mode"],
-                            "HBOL"=>$notification["milestone_transport_mode"]);
+            $data = array("milestoneData"=>$milestoneData,"containerData"=>$containerData,"delayData"=>$delayData,"changeData"=>$changeData);
+            $instant_sum = array();
+            foreach($data as $v){
+                if(!empty($v['instant'])){
+                    foreach($v['instant'] as $instant){
+                        $instant_sum[] = $instant;
                     }
-
+                }
+                if(!empty($v['daily'])){
+                    //取第一个显示
+                    $v['daily'][0]['numericRecords'] = count($v['daily']);
+                    $instant_sum[]= $v['daily'][0];
+                }
+                if(!empty($milestoneData['weekly'])){
+                    $v['weekly'][0]['numericRecords'] = count($v['weekly']);
+                    $instant_sum[]= $v['weekly'][0];
                 }
             }
+            //根据时间顺序排序
+            $insert_dates = array_column($instant_sum, 'insert_date');
+            array_multisort($insert_dates, SORT_ASC, $instant_sum);
+
+            $info = array();
+            foreach($instant_sum as $mInfo){
+                $eventCard = $this->getEventCard($mInfo,"Milestone_Update");
+                $Info[] = $eventCard;
+            }
+
+            $returnData = array("notificationType"=>"event","info" =>$info);
+            common::echo_json_encode(200,$returnData);
+            exit();
 
         }
     }
@@ -821,30 +836,108 @@ class tools {
     }
 
 
-    public function getNotifications($rules_type){
-
-        //$all_rules = array("Milestone_Update","Container_Status_Update","Departure/Arrival_Delay","ETD/ETA_Change");
-        if($rules_type == "Milestone_Update"){
-            $sql = "select case when COALESCE(ni.milestone_code,'') <> '' and ni.milestone_transport_mode = 'sea'
-                                then  (select description from  public.customer_service_milestone_sno where type = 'sea' and code = ni.milestone_code)
-                            else (select description from  public.customer_service_milestone_sno where type = 'air' and code = ni.milestone_code)
-                            end as milestone_desc,
-                        case when ni.milestone_code in ('IFFBCF','IFFBCR','IFFSIL','IFFEDO','IFFECC') 
-                                then '' 
-                            when ni.milestone_code in ('IFFREC','IFFECP')
-                                then ''
-                        ni.milestone_date,ni.milestone_time,
-                        (select o.h_bol from public.kln_ocean o where o.serial_no = ni.serial_no limit 1)
-                    from public.kln_notifiation_info ni
-                        where lower(ni.user_login) = '"._getLoginName()."' 
-                        and ni.rules_type = '".$rules_type."'
-                        and (ni.frequency_type = 'Instant' 
+    public function getNotifications($notifiation_type,$frequency_type){
+        if ($frequency_type == "all"){
+            $sql_where = " and (ni.frequency_type = 'Instant' 
                             or (ni.frequency_type = 'Daily'  and timezone(ni.daily_time_zone, NOW()::time) > ni.daily_time::time)
                             or (ni.frequency_type = 'Weekly' and timezone(ni.weekly_time_zone, NOW()::time) > ni.weekly_time::time 
-                                    and  ni.weekly_week ilike '%'|| EXTRACT(dow FROM timezone(ni.weekly_time_zone, NOW())) ||'%')) 
-                        and ni.notifications_method = true and ni.is_send_message = false order by ni.insert_date desc";
+                                    and  ni.weekly_week ilike '%'|| EXTRACT(dow FROM timezone(ni.weekly_time_zone, NOW())) ||'%'))";
+        } elseif($frequency_type == "Daily"){
+            $sql_where = " and (ni.frequency_type = 'Daily'  and timezone(ni.daily_time_zone, NOW()::time) > ni.daily_time::time)";
+        } elseif($frequency_type == "Weekly"){
+            $sql_where = " and (ni.frequency_type = 'Weekly' and timezone(ni.weekly_time_zone, NOW()::time) > ni.weekly_time::time 
+                                    and  ni.weekly_week ilike '%'|| EXTRACT(dow FROM timezone(ni.weekly_time_zone, NOW())) ||'%')";
+        }
+        
+        if ($notifiation_type == "Milestone_Update"){
+            $sql = "select ni.*,
+                    case when COALESCE(ni.frequency_type,'') = 'Daily'
+                            then to_char(timezone(ni.daily_time_zone, insert_date),'Mon DD, YYYY')
+                        when COALESCE(ni.frequency_type,'') = 'Weekly'  
+                            then to_char(timezone(ni.weekly_time_zone, insert_date),'Mon DD, YYYY')
+                        else '' 
+                    end  as insert_date_format,
+                        ccc.order_from,ccc.h_bol,ccc.transport_mode,ccc.milestone_desc
+                    from public.kln_notifiation_info ni
+                        left join LATERAL (select oo.h_bol,oo.transport_mode,oo.order_from,
+                                case when COALESCE(ni.milestone_code,'') <> '' and oo.transport_mode = 'sea'
+                                        then  (select description from  public.customer_service_milestone_sno where type = 'sea' and code = ni.milestone_code)
+                                    else (select description from  public.customer_service_milestone_sno where type = 'air' and code = ni.milestone_code)
+                                end as milestone_desc
+                              from public.kln_ocean oo 
+                            where oo.serial_no = ni.serial_no limit 1) ccc on true
+                    where lower(ni.user_login) = '"._getLoginName()."' 
+                        and ni.notifiation_type = '".$notifiation_type."'
+                        ".$sql_where." and ni.notifications_method = true and ni.is_send_message = false order by ni.insert_date desc";
+        }
+        if ($notifiation_type == "Milestone_Update"){
+
+        }
+
+        error_log($sql);
+        $data = common::excuteListSql($sql);
+        //统一处理数据Instant Daily weekly_week 先分开在处理
+        $instant = array();
+        $daily = array();
+        $daily_uniqe = array();
+        $weekly  = array();
+        $weekly_uniqe = array();
+        foreach($data as $d){
+            if ($d['frequency_type'] == "Instant"){
+                $instant[] = $d;
+            }
+            if ($d['frequency_type'] == "Daily"){
+                if(utils::in_array($d['serial_no'],$daily_uniqe)){
+                    $temp = $daily[$d['serial_no']];
+                    $temp[] = $d;
+                    $daily[$d['serial_no']] = $temp;
+                } else {
+                    $daily[$d['serial_no']] = $d['serial_no'];
+                    $daily_uniqe[] = $d;
+                }
+            }
+            if ($d['frequency_type'] == "Weekly"){
+                if(utils::in_array($d['serial_no'],$weekly_uniqe)){
+                    $temp = $weekly[$d['serial_no']];
+                    $temp[] = $d;
+                    $weekly[$d['serial_no']] = $temp;
+                } else {
+                    $weekly[$d['serial_no']] = $d;
+                    $weekly_uniqe[] = $d['serial_no'];
+                }
+            }
+        }
+
+        return array("instant" =>$instant,"daily" =>utils::arrayKeyToInt($daily),"weekly"=>utils::arrayKeyToInt($weekly));
+    }
+
+    public function getEventCard($mInfo,$notifiation_type){
+        if($notifiation_type == "Milestone_Update"){
+            $timeAndlocations = common::getMilestoneTimeAndlocations($mInfo["milestone_code"],$mInfo["transport_mode"],$mInfo["serial_no"],$mInfo["order_from"]);
+            $eventCard = array("type" =>'milestone',
+                    "numericRecords"=>0,
+                    "isRead"=>false,
+                    "title"=>"Milestone Update",
+                    "mode"=>$mInfo["transport_mode"],
+                    "no"=>$mInfo["h_bol"],
+                    "tag"=>$mInfo["milestone_desc"],
+                    "location"=>$timeAndlocations["locations"],
+                    "timezone"=>$timeAndlocations["timezone"],
+                    "time"=>$mInfo["milestone_date"]." ".$mInfo["milestone_time"],
+                    "previous"=>"",
+                    "frequency_type"=>$mInfo["frequency_type"],
+                    "delayInfo"=>array(),"changeInfo"=>array());
+
+            if ($mInfo["frequency_type"] == "Daily"){
+                $eventCard["numericRecords"] = $mInfo["numericRecords"];
+                $eventCard["title"] = "Milestone Update Daily Summary(".$mInfo["insert_date_format"].")";
+            } else if($mInfo["frequency_type"] == "Weekly"){
+                $eventCard["numericRecords"] = $mInfo["numericRecords"];
+                $eventCard["title"] = "Milestone Update Weekly Summary(".$mInfo["insert_date_format"].")";
+            }
         }
 
+        return $eventCard;
     }
 }
 

+ 175 - 0
utils/common.class.php

@@ -1963,6 +1963,181 @@ class common {
         return $EDI315TimeAndLocation;
     }
 
+    public static function getMilestoneTimeAndlocations($milestone_code,$transport_mode,$serial_no,$order_from){
+        $EDI315TimeAndLocation = array();
+        if($transport_mode == "sea"){
+            $ctnr_sql = "SELECT oc.ctnr, oc.serial_no,oc.size FROM $order_from.oc_container oc LEFT JOIN ocean o ON oc.serial_no = o.serial_no 
+                    WHERE o.serial_no='$serial_no'";
+            $ctnr_data = common::excuteListSql($ctnr_sql); 
+            foreach ($ctnr_data as $cd){
+                //存在柜号为空的数据情况
+                if(empty($cd['ctnr'])){
+                    continue;
+                }
+                $ctnr_status_sql = "select s.source_id, s.event_base as event,
+                        to_char(to_timestamp(s.event_date, 'YYYYMMDD'), 'YYYY-MM-DD') as eventdate,
+                        to_char(to_timestamp(s.event_time, 'HH24MI'), 'HH24:MI') as eventtime,
+                        e.description,s.event_type as eventtype, 
+                        s.event_code as eventcode, s.event_city as eventcity,
+                        (select time_zone from public.city_timezone where uncode = s.event_code) as timezone,
+                        (select uncity from public.ports where uncode = s.event_code) as uncity,
+                        case when s.event_base ='I'  then 'IFFREC'::text
+                            when s.event_base ='AE'  then 'IFFONB'::text
+                            when s.event_base ='VD'  then 'IFFDEP'::text
+                            when s.event_base ='EB' or s.event_base ='VA' then 'IFFARR'::text
+                            when s.event_base ='UV'  then 'IFFUND'::text
+                            when s.event_base ='VA'  then 'IFFAFD'::text
+                            when s.event_base ='AV'  then 'IFFCTA'::text
+                            when s.event_base ='CT'  then 'IFFICC'::text
+                            when s.event_base ='OA' or s.event_base ='D'  then 'IFFPPD'::text
+                            when s.event_base ='EE'  then 'IFFECP'::text
+                            else '' ::text
+                        end as milestone_code  
+                    from public.ra_online_container_status_v s 
+                        left join ra_online_edi_event e on s.event_base = e.ra_name 
+                    where s.serial_no = '" . pg_escape_string($cd['serial_no']) . "' 
+                        and s.container_no = '" . pg_escape_string($cd['ctnr']) . "' and is_display = true 
+                    order by to_timestamp(s.event_date, 'YYYYMMDD') asc,
+                        to_timestamp(s.event_time, 'HH24MI') asc,e.ra_order asc";
+                $ctnr_status = common::excuteListSql($ctnr_status_sql);       
+                //记录所有的信息
+                $EDI315TimeAndLocation = array();
+                foreach($ctnr_status as $event){
+                    if(!empty($EDI315TimeAndLocation['IFFARR']) && $EDI315TimeAndLocation['IFFARR']['code'] == "EB"){
+                        //如果存在EB 的EB 的优先级最高
+                        continue;
+                    }
+                    if(!empty($EDI315TimeAndLocation['IFFPPD']) && $EDI315TimeAndLocation['IFFARR']['code'] == "OA"){
+                        //如果存在OA 的OA 的优先级最高
+                        continue;
+                    }
+                    $EDI315TimeAndLocation[$event['milestone_code']] = array("code"=>$event['event'],"timezone"=>$event['timezone'],"location"=>$event['uncity']);
+                }
+            }
+        }
+
+        //当前数据的所有time city 查询
+        $sql = common::trackingSql($serial_no,$order_from);
+        $data_arr = common::excuteListSql($sql);
+        $data = $data_arr[0];
+
+        //EDI315 有关联查询,以那个为准。但是如果是手工录入或者不是EDI 进去的Milestone的情况,这以这个为准
+        $Milestones_NO_Mapping = common::getMilestones_NO_Mapping_Data($data);
+
+        $timezone = "";
+        $IFFICC_locations ="";
+        if(!empty($EDI315TimeAndLocation[$milestone_code])){
+            $edi315Info = $EDI315TimeAndLocation[$milestone_code];
+            if(!empty($edi315Info)){
+                $timezone = $edi315Info['timezone'];
+            }
+            //IFFICC 比较特殊用EDI的locations
+            if($milestone_code == "IFFICC"){
+                $IFFICC_locations = $edi315Info['location'];
+            }
+        }else{
+            $edi315Info =  $Milestones_NO_Mapping[$milestone_code];
+            if(!empty($edi315Info)){
+                $timezone = $edi315Info['timezone'];
+            }
+        }
+        //locations 以配置的信息为准
+        $locations = "";
+        $edi315Info =  $Milestones_NO_Mapping[$milestone_code];
+        if(!empty($edi315Info)){
+            $locations = $edi315Info['location'];
+            if($milestone_code == "IFFICC" && !empty($IFFICC_locations)){
+                $locations = $IFFICC_locations;
+            }
+        }
+        return  array("timezone" =>$timezone,"locations" =>$locations);
+    }
+
+    public static function trackingSql($serial_no,$order_from){
+        $_schemas = $order_from;
+        if($_schemas == 'public'){
+            $_schemas = "ocean";
+        }
+        $sql = "with o as(
+            SELECT  oo.*,m_bol as _m_bol, h_bol as _h_bol,
+                    (select time_zone from public.city_timezone where uncode = oo.fport_of_loading_un limit 1) as pol_timezone,
+                    case when oo.transport_mode ='sea' 
+                            then (select uncity from $order_from.ports where uncode = oo.fport_of_loading_un limit 1)
+                        else (select city from sfs.airport where coalesce(airport.country_abb,'')||airport.airport_code = oo.fport_of_loading_un limit 1)
+                    end as pol_uncity,
+                    (select time_zone from public.city_timezone where uncode = oo.mport_of_discharge_un limit 1) as mpod_timezone,
+                    case when oo.transport_mode ='sea' 
+                            then (select uncity from $order_from.ports where uncode = oo.mport_of_discharge_un limit 1)
+                        else (select city from sfs.airport where coalesce(airport.country_abb,'')||airport.airport_code = oo.mport_of_discharge_un limit 1)
+                    end as mpod_uncity,
+                    (select time_zone from public.city_timezone where uncode = oo.place_of_receipt_un limit 1) as por_timezone,
+                    case when oo.transport_mode ='sea' 
+                            then (select uncity from $order_from.ports where uncode = oo.place_of_receipt_un limit 1)
+                        else (select city from sfs.airport where coalesce(airport.country_abb,'')||airport.airport_code = oo.place_of_receipt_un limit 1)
+                    end as por_uncity,
+                    (select time_zone from public.city_timezone where uncode = oo.place_of_delivery_un limit 1) as pod_timezone,
+                    case when oo.transport_mode ='sea' 
+                            then (select uncity from $order_from.ports where uncode = oo.place_of_delivery_un limit 1)
+                        else (select city from sfs.airport where coalesce(airport.country_abb,'')||airport.airport_code = oo.place_of_delivery_un limit 1)
+                    end as pod_uncity,
+                    (select time_zone from public.city_timezone where uncode = oo.final_desination_uncode limit 1) as _fd_timezone,
+                    case when oo.transport_mode ='sea' 
+                            then (select uncity from $order_from.ports where uncode = oo.final_desination_uncode limit 1)
+                        else (select city from sfs.airport where coalesce(airport.country_abb,'')||airport.airport_code = oo.final_desination_uncode limit 1)
+                    end as _pd_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.kln_ocean oo where oo.serial_no = '" . $serial_no . "' and oo.order_from = '$order_from'
+        )
+        SELECT  o.* ,sh.*, cn.*,aa.*,dd.*,fd.*
+        from o
+            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 $_schemas.contacts c WHERE o.consignee_id::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 $_schemas.contacts c WHERE o.shipper_id::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(c.country, 2) || COALESCE(c.city_code,'') limit 1) as aa_timezone
+            FROM $_schemas.contacts c WHERE o.origin::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(c.country, 2) || COALESCE(c.city_code,'') limit 1) as dd_timezone
+            FROM $_schemas.contacts c WHERE o.agent::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(c.country, 2) || COALESCE(c.city_code,'') limit 1) as fd_timezone
+            FROM $_schemas.contacts c WHERE o.final_desination::text = c.contact_id::text) fd ON true";
+        return $sql;
+    }
+
     public static function getDashboardTransportationSqlWhere(){
         $transportation = $_REQUEST["transportation"];
         if(!is_array($transportation)){

+ 8 - 0
utils/utils.class.php

@@ -749,5 +749,13 @@ class utils {
             return false; // 不是支持的文件类型
         }
     } 
+
+    public static function arrayKeyToInt($arr){
+        $ret = array();
+        foreach($arr as $key => $val){
+            $ret[] = $val;
+        }
+        return $ret;
+    }
 }
 ?>