ShuanghongS 1 ヶ月 前
コミット
dd75ede69f
3 ファイル変更80 行追加99 行削除
  1. 23 19
      service/destination_delivery.class.php
  2. 49 80
      utils/common.class.php
  3. 8 0
      utils/utils.class.php

+ 23 - 19
service/destination_delivery.class.php

@@ -174,7 +174,7 @@ class destination_delivery {
 
             $delivery_serial_no = common::deCode($_REQUEST['delivery_serial_no'], 'D');
             //contact_person,contact_number,  现在系统还没有把这两个字段接入
-            if(!empty($delivery_serial_no)){
+            //if(!empty($delivery_serial_no)){
                 $sql = "SELECT addr1,addr2,addr3,addr4,
                             ctry_code,city_code,postal_code,
                             '' as contact_person,'' as contact_number,
@@ -185,7 +185,7 @@ class destination_delivery {
                             WHERE addr_type = 'D' 
                                 and lower(ca.contact_id) in (".$more_param.") 
                                 and ca.from_station in (select code from public.kerry_system_code where lower(category) in (".$more_param_country.")) 
-                                and ca.sync_key not in (select sync_key from public.contacts_address_online where delivery_serial_no = '".$delivery_serial_no."')
+                                and ca.sync_key not in (select sync_key from public.contacts_address_online where lower(contact_id) in (".$more_param."))
                         union all
                         SELECT addr1,addr2,addr3,addr4,
                                 ctry_code,city_code,postal_code,
@@ -194,19 +194,20 @@ class destination_delivery {
                                 from_station,
                                 action as op_action
                         FROM public.contacts_address_online 
-                            where delivery_serial_no = '$delivery_serial_no'";
-            }else{
-                $sql = "SELECT addr1,addr2,addr3,addr4,
-                            ctry_code,city_code,postal_code,
-                            '' as contact_person,'' as contact_number,
-                            create_user,contact_id,sync_key,
-                            from_station,
-                            'from Ksmart' as op_action
-                        FROM public.contacts_address ca 
-                        WHERE addr_type = 'D' 
-                            and lower(ca.contact_id) in (".$more_param.") 
-                            and ca.from_station in (select code from public.kerry_system_code where lower(category) in (".$more_param_country."))";
-            }
+                            where is_delete = false  
+                                and lower(contact_id) in (".$more_param.")";
+            // }else{
+            //     $sql = "SELECT addr1,addr2,addr3,addr4,
+            //                 ctry_code,city_code,postal_code,
+            //                 '' as contact_person,'' as contact_number,
+            //                 create_user,contact_id,sync_key,
+            //                 from_station,
+            //                 'from Ksmart' as op_action
+            //             FROM public.contacts_address ca 
+            //             WHERE addr_type = 'D' 
+            //                 and lower(ca.contact_id) in (".$more_param.") 
+            //                 and ca.from_station in (select code from public.kerry_system_code where lower(category) in (".$more_param_country."))";
+            // }
 
             $data = common::excuteListSql($sql);
             error_log($sql);
@@ -1019,11 +1020,14 @@ class destination_delivery {
                         array_to_json(h_serial_no) as h_serial_no_json,
                         TO_CHAR( delivery_date, 'HH24:MI') AS _delivery_time,
                         delivery_date::date AS _delivery_date
-                        from public.kln_destination_delivery where serial_no = '$serial_no'");
+                        from public.kln_destination_delivery where serial_no = '$serial_no'"); 
 
-                    $onine_address = common::excuteListSql("select * from public.contacts_address_online where delivery_serial_no = '$serial_no'");
-                    $sql .= "delete from public.contacts_address_online where delivery_serial_no = '$serial_no';";
-                    $sql .=common::returnDAddressRecord($delivery_booking["address_country"],$onine_address);
+                    $delivery_address_detail = json_decode($delivery_booking["delivery_address_detail"],true);
+                    $onine_address = common::excuteListSql("select * from public.contacts_address_online 
+                        where (delivery_serial_no = '$serial_no' or sync_key = '".$delivery_address_detail['sync_key']."')");
+
+                    //$sql .= "delete from public.contacts_address_online where delivery_serial_no = '$serial_no';";
+                    $sql .=common::returnDAddressRecord($delivery_booking["address_country"],$onine_address,$delivery_address_detail);
 
                     //Booking自動同步到Ksmart WO 的逻辑   保存在do_header和do_details表里
                     common::saveWorkOrder($delivery_booking);

+ 49 - 80
utils/common.class.php

@@ -3837,7 +3837,8 @@ class common {
             $_contact_type = common::check_input($_POST['contact_type'][$key]);
             $_create_user = common::check_input($_POST['create_user'][$key]);
 
-            if ($_contact_type ==  "Add"){
+            //为空的代表新加  _contact_type在非Unedit 和  Delete时,判断新加前端有bug,  先添加,立即修改。状态会从add  变成 moidfy,这个是有问题。
+            if (empty($_sync_key)){
                 $uniqueAC =array();
                 foreach($consignee_id as $ck => $_consignee_id){
                     $_add_create_user = "Online_D_Address";
@@ -3865,63 +3866,54 @@ class common {
                 if(!empty($_sync_key)){
                     $_add_create_user = "Online_D_Address";
                     if($_contact_type == "Unedit"){
-                        $_add_create_user = $_create_user;
+                        continue;
+                    }
+                    $_is_delete = 'f';
+                    if ($_contact_type ==  "Delete"){
+                        $_is_delete = 't';
                     }
-                    $exist = common::excuteObjectSql("select sync_key,action from public.contacts_address_online where sync_key = '$_sync_key' and delivery_serial_no = '$delivery_serial_no'");
+
+                    $exist = common::excuteObjectSql("select sync_key,action from public.contacts_address_online where sync_key = '$_sync_key'");
                     if(empty($exist)){
                         $addressSql .= "INSERT INTO public.contacts_address_online(
                                 delivery_serial_no,action,
                                 addr_type,contact_id, addr1, addr2,addr3, addr4, 
                                 ctry_code, city_code, postal_code,  
                                 create_user, create_date, modify_user, modify_date,
-                                is_sync_country, sync_key, from_station,contact_person,contact_number)
+                                is_sync_country, sync_key, from_station,contact_person,contact_number,is_delete)
                         VALUES ('$delivery_serial_no','$_contact_type',
                                 'D','$_contact_id','$_address_1','$_address_2','$_address_3','$_address_4',
                                 '$_country','$_city','$_postal_code',
                                 '$_add_create_user',now(),'$_add_create_user',now(),
-                                true,'$_sync_key','$_from_station','$_contact_person','$_contact_number');";
+                                true,'$_sync_key','$_from_station','$_contact_person','$_contact_number','$_is_delete');";
                     } else {
-                        if ($_contact_type ==  "Delete" && $exist['action'] == "Add"){
-                            //代表未审核新加的,这次提交为删除
-                            $addressSql .= "delete from public.contacts_address_online where sync_key = '$_sync_key' and delivery_serial_no = '$delivery_serial_no';";
-                        } 
-                        // elseif ($_contact_type ==  "Delete" && ($exist['action'] == "Modify" || $exist['action'] == "Unedit")){
-                        //     //代表未审核编辑的,这次提交为删除,修改action固定为Detele
-                        //     $addressSql .="UPDATE public.contacts_address_online
-                        //             SET addr1='$_address_1', addr2='$_address_2', addr3='$_address_3', addr4='$_address_4',
-                        //                 ctry_code='$_country', city_code='$_city', postal_code='$_postal_code', 
-                        //                 modify_user='$_add_create_user', modify_date=now(),
-                        //                 contact_person='$_contact_person', contact_number='$_contact_number',
-                        //                 action='Delete'
-                        //             WHERE sync_key = '$_sync_key' and delivery_serial_no = '$delivery_serial_no';"; 
-                        // } 
-                        else {
-                            //Modify  Unedit :如果是用户完全新加的,这里不做action的修改,保留记录的Add
-                            $temp_action = $_contact_type;
-                            if ($exist['action'] == "Add"){
-                                $temp_action = "Add";
-                            }
-                            $addressSql .="UPDATE public.contacts_address_online
-                                SET addr1='$_address_1', addr2='$_address_2', addr3='$_address_3', addr4='$_address_4',
-                                    ctry_code='$_country', city_code='$_city', postal_code='$_postal_code', 
-                                    modify_user='$_add_create_user', modify_date=now(),
-                                    contact_person='$_contact_person', contact_number='$_contact_number',
-                                    action='$temp_action'
-                                WHERE sync_key = '$_sync_key' and delivery_serial_no = '$delivery_serial_no';";
-                            
+                        //Modify  Unedit :如果是用户完全新加的,这里不做action的修改,保留记录的Add
+                        $temp_action = $_contact_type;
+                        if ($exist['action'] == "Add"){
+                            $temp_action = "Add";
                         }
+
+                        $addressSql .="UPDATE public.contacts_address_online
+                            SET delivery_serial_no = '$delivery_serial_no',addr1='$_address_1', addr2='$_address_2', addr3='$_address_3', addr4='$_address_4',
+                                ctry_code='$_country', city_code='$_city', postal_code='$_postal_code', 
+                                modify_user='$_add_create_user', modify_date=now(),
+                                contact_person='$_contact_person', contact_number='$_contact_number',
+                                action='$temp_action', is_delete = '$_is_delete'
+                            WHERE sync_key = '$_sync_key';";
                     }
                 }
             }
         }
-        common::excuteUpdateSql($addressSql);
+        if(!empty($addressSql)){
+            common::excuteUpdateSql($addressSql);
+        }
         return $_sync_key_add;
     }
 
     /**
      * 审核通过时,才取下放当时应用修改的地址
      */
-    public static function returnDAddressRecord($address_country,$onine_address){
+    public static function returnDAddressRecord($address_country,$onine_address,$delivery_address_detail){
         //deliver address is new
         $addressSql = "";
         $address_country = json_decode($address_country,true);
@@ -3931,8 +3923,8 @@ class common {
             $_address_2 = common::check_input($_onine_address['addr2']);
             $_address_3 = common::check_input($_onine_address['addr3']);
             $_address_4 = common::check_input($_onine_address['addr4']); 
-            $_country = common::check_input($_onine_address['ctry_code']); 
-            $_city = common::check_input($_onine_address['city_code']); 
+            $_ctry_code = common::check_input($_onine_address['ctry_code']); 
+            $_city_code = common::check_input($_onine_address['city_code']); 
             $_postal_code = common::check_input($_onine_address['postal_code']); 
             $_contact_person = common::check_input($_onine_address['contact_person']); 
             $_contact_number = common::check_input($_onine_address['contact_number']); 
@@ -3941,12 +3933,9 @@ class common {
             $_sync_key = common::check_input($_onine_address['sync_key']);
             $_from_station = strtoupper(common::check_input($_onine_address['from_station']));
             $_contact_type = common::check_input($_onine_address['action']);
+            $_is_delete = common::check_input($_onine_address['is_delete']);
 
-            //适应前端逻辑,如果遇到Unedit 代表该地址未变动,移除变动记录里
-            if ($_contact_type == "Unedit"){
-                continue;
-            }
-
+            $addressSql .=  "delete from public.contacts_address_online WHERE sync_key = '$_sync_key';";
             $uniqueAC =array();
             foreach($address_country as $ck => $_country){
                 if(utils::in_array($_country,$uniqueAC)){
@@ -3954,57 +3943,36 @@ class common {
                 }
                 $uniqueAC[] = $_country;
 
-                //如果需要新加的时候 用户固定名称,用作标记   //contact_person,contact_number  '$_contact_person','$_contact_number'
                 $_add_create_user = "Online_D_Address";
-                if ($_contact_type == "Add"){
-                    if(empty($_sync_key)){
-                        continue;
-                    }
-                    $from_station = "ONLINE_".strtoupper($_country);
-                    $addressSql .= "INSERT INTO public.contacts_address(
-                            addr_type,contact_id, addr1, addr2,addr3, addr4, 
-                            ctry_code, city_code, postal_code,  
-                            create_user, create_date, modify_user, modify_date,
-                            is_sync_country, sync_key, from_station)
-                    VALUES ('D','$_contact_id','$_address_1','$_address_2','$_address_3','$_address_4',
-                            '$_country','$_city','$_postal_code',
-                            '$_add_create_user',now(),'$_add_create_user',now(),
-                            true,'$_sync_key','$from_station');";
+                $from_station = "ONLINE_".strtoupper($_country);
+
+                $_sync_key_new = $_sync_key;
+                if($ck > 0){
+                    $_sync_key_new = common::uuid();
                 }
-                if ($_contact_type == "Modify"){
-                    //代表在一个国家内的编辑 //contact_person='$_contact_person', contact_number='$_contact_number'  
-                    $from_station_country = "";
-                    if (strpos($_from_station, "ONLINE_") === 0) { // 确保字符串以 ONLINE_ 开头
-                        $from_station_country = substr($_from_station, strlen("ONLINE_"));
-                    }
-                    if($from_station_country == $_country){
+
+                $existData = common::excuteObjectSql("select sync_key FROM public.contacts_address WHERE sync_key = '$_sync_key' and from_station = '$from_station'");
+                if ($delivery_address_detail['sync_key'] == $_sync_key) {
+                    if(!empty($existData) && !empty($existData['sync_key'])){
                         $addressSql .= "UPDATE public.contacts_address
                             SET addr1='$_address_1', addr2='$_address_2', 
-                                ctry_code='$_country', city_code='$_city', postal_code='$_postal_code',  
+                                ctry_code='$_ctry_code', city_code='$_city_code', postal_code='$_postal_code',  
                                 modify_user='"._getLoginName()."', modify_date=now()
                             WHERE sync_key = '$_sync_key';";
                     } else {
-                        if(empty($_sync_key)){
-                            continue;
-                        }
-                        $from_station = "ONLINE_".strtoupper($_country);
                         $addressSql .= "INSERT INTO public.contacts_address(
                                 addr_type,contact_id, addr1, addr2,addr3, addr4, 
                                 ctry_code, city_code, postal_code,  
                                 create_user, create_date, modify_user, modify_date,
                                 is_sync_country, sync_key, from_station)
                         VALUES ('D','$_contact_id','$_address_1','$_address_2','$_address_3','$_address_4',
-                                '$_country','$_city','$_postal_code',
+                                '$_ctry_code','$_city_code','$_postal_code',
                                 '$_add_create_user',now(),'$_add_create_user',now(),
-                                true,'$_sync_key','$from_station');";
+                                true,'$_sync_key_new','$from_station');";
                     }
-                }
-                if ($_contact_type == "Delete"){
-                    $from_station_country = "";
-                    if (strpos($_from_station, "ONLINE_") === 0) { // 确保字符串以 ONLINE_ 开头
-                        $from_station_country = substr($_from_station, strlen("ONLINE_"));
-                    }
-                    if($from_station_country == $_country){
+                } else {
+                    //除开当前编辑的提交的,就只有用户自己删除要处理,其他的修改最后未选的情况留在本地管理
+                    if ($_is_delete  == 't' && !empty($existData) && !empty($existData['sync_key'])){
                         $addressSql .=  "DELETE FROM public.contacts_address WHERE sync_key = '$_sync_key';";
                     }
                 }
@@ -4041,7 +4009,8 @@ class common {
             $_from_station = $_POST['from_station'][$key];
             $_contact_type = $_POST['contact_type'][$key];
 
-            if($_contact_type == "Add"){
+            //if($_contact_type == "Add"){
+            if(!empty($_sync_key_add)){
                 //add 这么生成的唯一key
                 $_sync_key = $_sync_key_add;
             }
@@ -4132,7 +4101,7 @@ class common {
                 est_delivery_date, est_delivery_time,instructions,
                 create_user, create_time,delivery_vehicle_type,delivery_fuel_type,
                 consignee, consignee_name, consignee_exp,delivery_to_address_sync_key,
-                delivery_reference)
+                refno)
             VALUES ('".$do_serial_no."','".$detail_row_count."','Ocean', '".$oceanInfo['agent']."','".$biztype."','Awaiting Confirmation','".$mode_type."',
                 '".$serial_no."','".$oceanInfo['m_bol']."','".$oceanInfo['h_bol']."','".$oceanInfo['job_no']."',now(),
                 ".$total_pcs.",'".$total_pcs_unit."',".$total_weight.",'".$total_weight_unit."',".$total_volume.",'".$total_volume_unit."',

+ 8 - 0
utils/utils.class.php

@@ -273,6 +273,14 @@ class utils {
                 }
             }
         }
+        //邮件处理,去重
+        $array = array_filter(
+            array_map('trim', explode(';', $email["email"])),
+            'strlen'
+        );
+        $array = array_unique($array);
+        $email["email"] = utils::implode(';',$array);
+        
         $email["h_bol"] = $ocean["h_bol"];
         $email["consignee"] = $ocean["consignee"];
         return $email;