ShuanghongS 9 달 전
부모
커밋
c81414fb9a
5개의 변경된 파일179개의 추가작업 그리고 23개의 파일을 삭제
  1. 1 0
      main_new_version.php
  2. 20 5
      service/login.class.php
  3. 26 11
      service/ocean_order.class.php
  4. 99 7
      service/tools.class.php
  5. 33 0
      utils/common.class.php

+ 1 - 0
main_new_version.php

@@ -723,6 +723,7 @@ switch ($action) {
                     "timezone"=>$timezone,
                     "_schemas"=>$value["_schemas"],
                     "transport_mode"=>$value["transport_mode"],
+                    'is_subscribe' =>common::checkedSubscribe($value['serial_no']),
                     "a" =>common::deCode($value['serial_no'], 'E'));
             }
             $data  = common::getManagement();

+ 20 - 5
service/login.class.php

@@ -1393,15 +1393,30 @@ class login {
         $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,
-                    (select uncity from public.ports where uncode = oo.fport_of_loading_un limit 1) as pol_uncity,
+                    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,
-                    (select uncity from public.ports where uncode = oo.mport_of_discharge_un limit 1) as mpod_uncity,
+                    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,
-                    (select uncity from public.ports where uncode = oo.place_of_receipt_un limit 1) as por_uncity,
+                    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,
-                    (select uncity from public.ports where uncode = oo.place_of_delivery_un limit 1) as pod_uncity,
+                    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,
-                    (select uncity from public.ports where uncode = oo.final_desination_uncode limit 1) as _pd_uncity, 
+                    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

+ 26 - 11
service/ocean_order.class.php

@@ -951,6 +951,8 @@ class ocean_order {
 
             $sql = "with oo  as (SELECT order_from as _schemas,serial_no as __serial_no, serial_no,transport_mode,
                     h_bol as _hbol, isf_bol as _isfbol, consignee_city as _consignee_city,
+                    (select user_login from kln_user_subscribed us  
+                        where lower(us.user_login) = '".strtolower(_getLoginName())."' and us.subscribed_serial_no = kln_ocean.serial_no) as is_subscribe,
                     CASE
 	    	            WHEN (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
@@ -972,6 +974,8 @@ class ocean_order {
 
             $tmp_search_without_limit = "with oo  as (SELECT order_from as _schemas,serial_no as __serial_no, serial_no,transport_mode,
                     h_bol as _hbol, isf_bol as _isfbol, consignee_city as _consignee_city,
+                    (select user_login from kln_user_subscribed us  
+                        where lower(us.user_login) = '".strtolower(_getLoginName())."' and us.subscribed_serial_no = kln_ocean.serial_no) as is_subscribe,
                     CASE
 	    	            WHEN (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
@@ -1002,6 +1006,13 @@ class ocean_order {
                 $rs[$index]["Mode"] = $val['transport_mode'] == 'sea' ? "Ocean Freight" : ($val['transport_mode'] == 'air' ? "Air Freight": "");
                 //status 改为ocean_milestone里的信息
                 $rs[$index]["Status"] = $rs[$index]["new_status"];
+                //订阅的参数
+                if(empty($rs[$index]["is_subscribe"])){
+                    $rs[$index]['is_subscribe'] = false;
+                }else{
+                    $rs[$index]['is_subscribe'] = true;
+                }
+                $rs[$index]["a"] = common::deCode($val['__serial_no'], 'E');
             }
         
             $arrTmp = array('searchData' => $rs, 
@@ -1258,6 +1269,8 @@ class ocean_order {
                         '_schemas' =>$_schemas,
                         'uncode' =>$uncode,
                         'serial_no' =>$serial_no,
+                        'is_subscribe' =>common::checkedSubscribe($serial_no),
+                        'a' =>common::deCode($serial_no, 'E'),
                         'can_upload_doc' => strtolower($_SESSION['ONLINE_USER']['can_upload_doc']) == 't' || strtolower($_SESSION['ONLINE_USER']['can_view_doc']) == 't',
                         'canEdiVgm' => _canEdiVgm(),
                         'canViewAMSLog'=>_canViewAMSLog(),
@@ -1415,6 +1428,8 @@ class ocean_order {
                         'uncode' =>"",
                         'transport_mode' =>"air",
                         'serial_no' =>$serial_no,
+                        'is_subscribe' =>common::checkedSubscribe($serial_no),
+                        'a' =>common::deCode($serial_no, 'E'),
                         'can_upload_doc' => strtolower($_SESSION['ONLINE_USER']['can_upload_doc']) == 't' || strtolower($_SESSION['ONLINE_USER']['can_view_doc']) == 't',
                         'canEdiVgm' => _canEdiVgm(),
                         'canViewAMSLog'=>_canViewAMSLog(),
@@ -1825,7 +1840,7 @@ class ocean_order {
         )
         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
+                (select uncode from $order_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,
@@ -1834,15 +1849,15 @@ class ocean_order {
                     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 uncity from $order_from.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 uncity from $order_from.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 uncity from $order_from.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,
+                    (select uncity from $order_from.ports where uncode = oo.place_of_delivery_un limit 1) as pod_uncity,
                     (select time_zone from public.city_timezone where uncode = oo.final_desination_uncode limit 1) as _fd_timezone,
-                    (select uncity from public.ports where uncode = oo.final_desination_uncode limit 1) as _pd_uncity,
+                    (select uncity from $order_from.ports where uncode = oo.final_desination_uncode limit 1) as _pd_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
@@ -1904,15 +1919,15 @@ class ocean_order {
         $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,
-                    (select uncity from public.ports where uncode = oo.fport_of_loading_un limit 1) as pol_uncity,
+                    (select city from sfs.airport where coalesce(airport.country_abb,'')||airport.airport_code = 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 city from sfs.airport where coalesce(airport.country_abb,'')||airport.airport_code = 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 city from sfs.airport where coalesce(airport.country_abb,'')||airport.airport_code = 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,
+                    (select city from sfs.airport where coalesce(airport.country_abb,'')||airport.airport_code = oo.place_of_delivery_un limit 1) as pod_uncity,
                     (select time_zone from public.city_timezone where uncode = oo.final_desination_uncode limit 1) as _fd_timezone,
-                    (select uncity from public.ports where uncode = oo.final_desination_uncode limit 1) as _pd_uncity, 
+                    (select city from sfs.airport where coalesce(airport.country_abb,'')||airport.airport_code = oo.final_desination_uncode limit 1) 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

+ 99 - 7
service/tools.class.php

@@ -174,7 +174,9 @@ class tools {
         if ($operate == "subscribe_notification_init") {
             $subscribur_data =array();
             //查询用户对应的Rule
-            $subscribe_rule_sql = "select * from public.notifications_rules where notifications_type = 'Subscribe' and lower(user_login) = '".strtolower(_getLoginName())."' order by id";
+            $subscribe_rule_sql = "select *,TO_CHAR(daily_time, 'HH24:MI') as _daily_time,
+                    TO_CHAR(weekly_time, 'HH24:MI') as _weekly_time
+                from public.notifications_rules where notifications_type = 'Subscribe' and lower(user_login) = '".strtolower(_getLoginName())."' order by id";
             $subscribe_rules = common::excuteListSql($subscribe_rule_sql);
             $all_rules = array("Milestone_Update","Container_Status_Update","Departure/Arrival_Delay","ETD/ETA_Change");
             foreach($all_rules as $rule_name){
@@ -195,7 +197,7 @@ class tools {
             $subscribur_data['addedRules'] = array("tableData"=>$addedRules);
 
             //获取subscribe shipment 当前页数cp,每页ps
-            $subscribeShipmentWithPage =  $this->getSubscribeShipment(1,20);
+            $subscribeShipmentWithPage =  $this->getSubscribeShipment(1,15);
             $subscribur_data['subscribeShipmentWithPage'] = $subscribeShipmentWithPage;
 
             common::echo_json_encode(200,$subscribur_data);
@@ -245,9 +247,9 @@ class tools {
         }
 
         if ($operate == "subscribe_shipment"){
-            $serial_no = common::deCode($_GET['serial_no'], 'D');
+            $serial_no = common::deCode($_POST['serial_no'], 'D');
             $is_subscribe = common::check_input($_POST['is_subscribe']);
-            if($is_subscribe == "yes"){
+            if($is_subscribe == "true"){
                 $exist = common::excuteOneSql("select user_login from public.kln_user_subscribed where lower(user_login) = '".strtolower(_getLoginName())."' and subscribed_serial_no = '$serial_no'");
                 if(!empty($exist)){
                     $data = array("msg" => "Subscribe exist,Please check");
@@ -270,6 +272,14 @@ class tools {
                 exit();
             }
         }
+
+        if ($operate == "subscribe_shipment_search"){
+            $cp = common::check_input($_POST ['cp']); //current_page
+            $ps = common::check_input($_POST ['ps']); //ps
+            $arrTmp = $this->getSubscribeShipment($cp,$ps);
+            common::echo_json_encode(200,$arrTmp);
+            exit();
+        }
     }
 
     public function user_monitoring_setting(){
@@ -343,6 +353,54 @@ class tools {
         }
     }
 
+    public function notifications_rules(){
+        $operate = utils::_get('operate');
+        $operate = strtolower($operate);
+
+        if ($operate == "notifications"){
+            $rules_type = common::check_input($_POST ['rules_type']); 
+            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";
+            }
+            $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"]);
+                    }
+
+                }
+            }
+
+        }
+    }
+
     /**
      * 遍历查找对应的rule。
      */
@@ -352,6 +410,9 @@ class tools {
         foreach($subscribe_rules as $rules){
             if($rules['rules_type'] == $rule_name){
                 $rules["is_display"] = true;
+                $rules["daily_time"] = $rules["_daily_time"];
+                $rules["weekly_time"] = $rules["_weekly_time"];
+                $rules["weekly_week"] = common::getWeek($rules["weekly_week"]);
                 $ret = $rules;
             }
         }
@@ -407,10 +468,15 @@ class tools {
      * cp current_page
      */
     public function getSubscribeShipment($cp,$ps){
+        if (empty($cp)){
+            $cp = 1;
+        }
         if (empty($ps)){
-            $ps = 20;
+            $ps = 15;
         }
-        $sql = "select count(1) from  public.kln_user_subscribed where  lower(user_login) = '".strtolower(_getLoginName())."'";
+        $sql = "select count(1) from  public.kln_user_subscribed u
+                left join public.kln_ocean o on  o.serial_no  = u.subscribed_serial_no 
+            where  lower(user_login) = '".strtolower(_getLoginName())."'";
         $rc = common::excuteOneSql($sql);
         $tp = ceil($rc / $ps);
         if ($rc > 0) {
@@ -433,7 +499,7 @@ class tools {
                                     where a.serial_no=o.serial_no and act_date is not null  order by sn.sno desc limit 1)
                             else '' end as recent_milestone				
                     from  public.kln_user_subscribed u 
-                        left join public.kln_ocean o on  o.serial_no in (SELECT regexp_split_to_table(subscribed_serial_no,';')) 
+                        left join public.kln_ocean o on  o.serial_no  = u.subscribed_serial_no
                     where  lower(user_login) = '".strtolower(_getLoginName())."' order by u.id desc limit " . $ps . " offset " . ($cp - 1) * $ps;
             $subscribeShipment = common::excuteListSql($sql);
             $arrTmp = array('tableData' => $subscribeShipment, 
@@ -754,6 +820,32 @@ class tools {
         return  $event;   
     }
 
+
+    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' 
+                            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";
+        }
+
+    }
 }
 
 ?>

+ 33 - 0
utils/common.class.php

@@ -1979,5 +1979,38 @@ class common {
         }
         return TRUE;
     }
+
+    /**
+     * checked is_subscribe
+    */
+    public static function checkedSubscribe($serial_no) { //creates directory tree recursively
+        $is_subscribe_exist = common::excuteOneSql("select user_login from kln_user_subscribed us  
+            where lower(us.user_login) = '".strtolower(_getLoginName())."' and us.subscribed_serial_no = '".$serial_no."'");
+        if(empty($is_subscribe_exist)){
+            $is_subscribe = false;
+        }else{
+            $is_subscribe = true;
+        }
+        return $is_subscribe;
+    }
+
+    public static  function getWeek($week){
+        if ($week == "0"){
+            $week = "Sunday";
+        } elseif ($week == "1"){
+            $week = "Monday";
+        } elseif ($week == "2"){
+            $week = "Tuesday";
+        } elseif ($week == "3"){
+            $week = "Wednesday";
+        } elseif ($week == "4"){
+            $week = "Thursday";
+        } elseif ($week == "5"){
+            $week = "Friday";
+        } elseif ($week == "6"){
+            $week = "Sunday";
+        }
+        return $week;
+    }
 }
 ?>