ShuanghongS 8 månader sedan
förälder
incheckning
6cb43e36cd
2 ändrade filer med 89 tillägg och 17 borttagningar
  1. 1 0
      service/ocean_order.class.php
  2. 88 17
      service/tools.class.php

+ 1 - 0
service/ocean_order.class.php

@@ -1014,6 +1014,7 @@ class ocean_order {
                 }else{
                     $rs[$index]['is_subscribe'] = true;
                 }
+                //这个不影响,不会deCode两次,取得是临时变量的__serial_no,加这个是为了订阅
                 $rs[$index]["a"] = common::deCode($val['__serial_no'], 'E');
             }
         

+ 88 - 17
service/tools.class.php

@@ -176,7 +176,7 @@ class tools {
             //查询用户对应的Rule
             $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";
+                from public.notifications_rules where notifications_type = 'Subscribe' and lower(user_login) = '".strtolower(_getLoginName())."' order by id desc";
             $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){
@@ -703,6 +703,17 @@ class tools {
                 $rules["daily_time"] = $rules["_daily_time"];
                 $rules["weekly_time"] = $rules["_weekly_time"];
                 $rules["weekly_week"] = common::getWeek($rules["weekly_week"]);
+
+                //字符串转数字
+                $rules["ocean_atd_sub_etd"] = !empty($rules["ocean_atd_sub_etd"]) ? intval($rules["ocean_atd_sub_etd"]): $rules["ocean_atd_sub_etd"];
+                $rules["ocean_ata_sub_eta"] = !empty($rules["ocean_ata_sub_eta"]) ? intval($rules["ocean_ata_sub_eta"]): $rules["ocean_ata_sub_eta"];
+                $rules["air_atd_sub_etd"] = !empty($rules["air_atd_sub_etd"]) ? intval($rules["air_atd_sub_etd"]): $rules["air_atd_sub_etd"];
+                $rules["air_ata_sub_eta"] = !empty($rules["air_ata_sub_eta"]) ? intval($rules["air_ata_sub_eta"]): $rules["air_ata_sub_eta"];
+
+                $rules["ocean_etd_old_sub_new"] = !empty($rules["ocean_etd_old_sub_new"]) ? intval($rules["ocean_etd_old_sub_new"]): $rules["ocean_etd_old_sub_new"];
+                $rules["ocean_eta_old_sub_new"] = !empty($rules["ocean_eta_old_sub_new"]) ? intval($rules["ocean_eta_old_sub_new"]): $rules["ocean_eta_old_sub_new"];
+                $rules["air_etd_old_sub_new"] = !empty($rules["air_etd_old_sub_new"]) ? intval($rules["air_etd_old_sub_new"]): $rules["air_etd_old_sub_new"];
+                $rules["air_eta_old_sub_new"] = !empty($rules["air_eta_old_sub_new"]) ? intval($rules["air_eta_old_sub_new"]): $rules["air_eta_old_sub_new"];
                 $ret = $rules;
             }
         }
@@ -765,7 +776,7 @@ class tools {
         $rc = common::excuteOneSql($sql);
         $tp = ceil($rc / $ps);
         if ($rc > 0) {
-            $sql = "select o.h_bol,
+            $sql = "select o.serial_no,order_from as _schemas,o.h_bol,
                         o.shipper,o.consignee,o.etd,o.eta,
                         case when transport_mode = 'sea'  
                                 then (select  sn.description
@@ -787,18 +798,21 @@ class tools {
                         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);
+            foreach($subscribeShipment as $key => $val){
+                $subscribeShipment[$key]["__serial_no"] = common::deCode($val['serial_no'], 'E');
+            }
             $arrTmp = array('tableData' => $subscribeShipment, 
                 'rc' => intval($rc),
-                'ps' => $ps,
-                'cp' => $cp,
-                'tp' => $tp
+                'ps' => intval($ps),
+                'cp' => intval($cp),
+                'tp' => intval($tp)
             );
         } else {
             $arrTmp = array('tableData' => array(), 
-                'rc' => $rc,
-                'ps' => $ps,
-                'cp' => $cp,
-                'tp' => $tp,
+                'rc' => intval($rc),
+                'ps' => intval($ps),
+                'cp' => intval($cp),
+                'tp' => intval($tp),
             );
         }
         return $arrTmp;
@@ -806,12 +820,12 @@ class tools {
 
     public function getNotificationsRulesUpdateSql($updateOrInsert,$rules_type,$notifications_type,$id){
         $sql = "";
-        //先删后加
-        if($updateOrInsert == "update"){
-            $sql.="delete from public.notifications_rules where rules_type = '$rules_type' 
-                    and notifications_type = '$notifications_type' and  lower(user_login) = '".strtolower(_getLoginName())."'
-                    and id = '$id';";
-        }
+        //先删后加 这个逻辑有移除
+        // if($updateOrInsert == "update"){
+        //     $sql.="delete from public.notifications_rules where rules_type = '$rules_type' 
+        //             and notifications_type = '$notifications_type' and  lower(user_login) = '".strtolower(_getLoginName())."'
+        //             and id = '$id';";
+        // }
         //这个几个参数是所有规则都有的参数
         $frequency_type = common::check_input($_POST['frequency_type']);
         $daily_time  = "null";
@@ -850,6 +864,17 @@ class tools {
             $ocean_milestone = utils::implode(";",$_POST['ocean_milestone']);
             $air_milestone =  utils::implode(";",$_POST['air_milestone']);
 
+            //改为update  不在是删除后添加,为了保留原始顺序
+            if ($updateOrInsert == "update"){ 
+                $sql.="update public.notifications_rules set ocean_milestone = '$ocean_milestone',air_milestone = '$air_milestone',
+                    frequency_type = '$frequency_type',daily_time = $daily_time, daily_time_zone = '$daily_time_zone',
+                    weekly_week = '$weekly_week', weekly_time = $weekly_time, weekly_time_zone = '$weekly_time_zone', method_by_email = '$method_by_email',method_by_message = '$method_by_message',
+                    event_details = '$event_details', frequency_display = '$frequency_display', method_display = '$method_display', shipment_details = '$shipment_detail',
+                    shipment_transport_mode = '$shipment_transport_mode', shipment_etd_limit = '$shipment_etd_limit', shipment_eta_limit = '$shipment_eta_limit' 
+                    where rules_type = '$rules_type' 
+                        and notifications_type = '$notifications_type' and  lower(user_login) = '".strtolower(_getLoginName())."'
+                        and id = '$id';";
+            } else {
             $sql.="INSERT INTO public.notifications_rules(
                     user_login, notifications_type, rules_type, ocean_milestone, 
                     air_milestone, frequency_type, daily_time, daily_time_zone,
@@ -861,11 +886,23 @@ class tools {
                     '$weekly_week', $weekly_time, '$weekly_time_zone', '$method_by_email', '$method_by_message',
                     '$event_details', '$frequency_display', '$method_display','$shipment_detail',
                     '$shipment_transport_mode','$shipment_etd_limit','$shipment_eta_limit');";
+            }
         }
 
         if ($rules_type == "Container_Status_Update"){
             $ocean_ctnr_status = utils::implode(";",$_POST['ocean_ctnr_status']);
 
+            //改为update  不在是删除后添加,为了保留原始顺序
+            if ($updateOrInsert == "update"){ 
+                $sql.="update public.notifications_rules set ocean_ctnr_status = '$ocean_ctnr_status',
+                    frequency_type = '$frequency_type',daily_time = $daily_time, daily_time_zone = '$daily_time_zone',
+                    weekly_week = '$weekly_week', weekly_time = $weekly_time, weekly_time_zone = '$weekly_time_zone', method_by_email = '$method_by_email',method_by_message = '$method_by_message',
+                    event_details = '$event_details', frequency_display = '$frequency_display', method_display = '$method_display', shipment_details = '$shipment_detail',
+                    shipment_transport_mode = '$shipment_transport_mode', shipment_etd_limit = '$shipment_etd_limit', shipment_eta_limit = '$shipment_eta_limit' 
+                    where rules_type = '$rules_type' 
+                        and notifications_type = '$notifications_type' and  lower(user_login) = '".strtolower(_getLoginName())."'
+                        and id = '$id';";
+            }else{
             $sql.="INSERT INTO public.notifications_rules(
                     user_login, notifications_type, rules_type, ocean_ctnr_status, 
                     frequency_type, daily_time, daily_time_zone,
@@ -877,6 +914,7 @@ class tools {
                     '$weekly_week', $weekly_time, '$weekly_time_zone', '$method_by_email', '$method_by_message',
                     '$event_details', '$frequency_display', '$method_display','$shipment_detail',
                     '$shipment_transport_mode','$shipment_etd_limit','$shipment_eta_limit');";
+            }
         }
 
         if ($rules_type == "Departure/Arrival_Delay"){
@@ -901,7 +939,22 @@ class tools {
             if(!empty($air_ata_sub_eta_unit)){
                 $air_ata_sub_eta_unit = $air_ata_sub_eta_unit=="Day(s)" ? "days":"hours";
             }
-            
+
+            //改为update  不在是删除后添加,为了保留原始顺序
+            if ($updateOrInsert == "update"){
+                $sql.="update public.notifications_rules set 
+                    ocean_atd_sub_etd = '$ocean_atd_sub_etd',ocean_atd_sub_etd_unit = '$ocean_atd_sub_etd_unit',
+                    ocean_ata_sub_eta = '$ocean_ata_sub_eta',ocean_ata_sub_eta_unit = '$ocean_ata_sub_eta_unit',
+                    air_atd_sub_etd = '$air_atd_sub_etd',air_atd_sub_etd_unit = '$air_atd_sub_etd_unit',
+                    air_ata_sub_eta = '$air_ata_sub_eta',air_ata_sub_eta_unit = '$air_ata_sub_eta_unit',
+                    frequency_type = '$frequency_type',daily_time = $daily_time, daily_time_zone = '$daily_time_zone',
+                    weekly_week = '$weekly_week', weekly_time = $weekly_time, weekly_time_zone = '$weekly_time_zone', method_by_email = '$method_by_email',method_by_message = '$method_by_message',
+                    event_details = '$event_details', frequency_display = '$frequency_display', method_display = '$method_display', shipment_details = '$shipment_detail',
+                    shipment_transport_mode = '$shipment_transport_mode', shipment_etd_limit = '$shipment_etd_limit', shipment_eta_limit = '$shipment_eta_limit' 
+                    where rules_type = '$rules_type' 
+                        and notifications_type = '$notifications_type' and  lower(user_login) = '".strtolower(_getLoginName())."'
+                        and id = '$id';";
+            }else{
             $sql.="INSERT INTO public.notifications_rules(
                     user_login, notifications_type, rules_type,
                     ocean_atd_sub_etd, ocean_atd_sub_etd_unit,ocean_ata_sub_eta,ocean_ata_sub_eta_unit,
@@ -917,6 +970,7 @@ class tools {
                     '$weekly_week', $weekly_time, '$weekly_time_zone', '$method_by_email', '$method_by_message',
                     '$event_details', '$frequency_display', '$method_display','$shipment_detail',
                     '$shipment_transport_mode','$shipment_etd_limit','$shipment_eta_limit');";
+            }
         }
 
         if ($rules_type == "ETD/ETA_Change"){
@@ -945,7 +999,23 @@ class tools {
             if(!empty($air_eta_old_sub_new_unit)){
                 $air_eta_old_sub_new_unit = $air_eta_old_sub_new_unit=="Day(s)" ? "days":"hours";
             }
-            
+            //改为update  不在是删除后添加,为了保留原始顺序
+            if ($updateOrInsert == "update"){
+                $sql.="update public.notifications_rules set 
+                    ocean_etd_change = '$ocean_etd_change',ocean_etd_old_sub_new = '$ocean_etd_old_sub_new',ocean_etd_old_sub_new_unit = '$ocean_etd_old_sub_new_unit',
+                    ocean_eta_change = '$ocean_eta_change',ocean_eta_old_sub_new = '$ocean_eta_old_sub_new',ocean_eta_old_sub_new_unit = '$ocean_eta_old_sub_new_unit',
+
+                    air_etd_change = '$air_etd_change',air_etd_old_sub_new = '$air_etd_old_sub_new',air_etd_old_sub_new_unit = '$air_etd_old_sub_new_unit',
+                    air_eta_change = '$air_eta_change',air_eta_old_sub_new = '$air_eta_old_sub_new',air_eta_old_sub_new_unit = '$air_eta_old_sub_new_unit',
+
+                    frequency_type = '$frequency_type',daily_time = $daily_time, daily_time_zone = '$daily_time_zone',
+                    weekly_week = '$weekly_week', weekly_time = $weekly_time, weekly_time_zone = '$weekly_time_zone', method_by_email = '$method_by_email',method_by_message = '$method_by_message',
+                    event_details = '$event_details', frequency_display = '$frequency_display', method_display = '$method_display', shipment_details = '$shipment_detail',
+                    shipment_transport_mode = '$shipment_transport_mode', shipment_etd_limit = '$shipment_etd_limit', shipment_eta_limit = '$shipment_eta_limit' 
+                    where rules_type = '$rules_type' 
+                        and notifications_type = '$notifications_type' and  lower(user_login) = '".strtolower(_getLoginName())."'
+                        and id = '$id';";
+            }else{
             $sql.="INSERT INTO public.notifications_rules(
                     user_login, notifications_type, rules_type,
                     ocean_etd_change, ocean_etd_old_sub_new,ocean_etd_old_sub_new_unit,ocean_eta_change,ocean_eta_old_sub_new,ocean_eta_old_sub_new_unit,
@@ -961,6 +1031,7 @@ class tools {
                     '$weekly_week', $weekly_time, '$weekly_time_zone', '$method_by_email', '$method_by_message',
                     '$event_details', '$frequency_display', '$method_display','$shipment_detail',
                     '$shipment_transport_mode','$shipment_etd_limit','$shipment_eta_limit');";
+            }
         }
         return $sql;
     }