ShuanghongS hai 4 meses
pai
achega
70f4a4597b
Modificáronse 3 ficheiros con 254 adicións e 144 borrados
  1. 244 138
      service/destination_delivery.class.php
  2. 9 5
      service/tools.class.php
  3. 1 1
      utils/utils.class.php

+ 244 - 138
service/destination_delivery.class.php

@@ -32,65 +32,44 @@ class destination_delivery {
          * select country
          */
         if ($operate == "country") {
-            $$cp = common::check_input($_POST ['cp']); //current_page
-            $ps = common::check_input($_POST ['ps']); //ps
-            if (empty($ps))
-                $ps = 20;
             $term = $_POST['term'];
             $term = trim($term);
-
-            $rc = $_POST ['rc'];
-            if ($rc == - 1) {
-                $sql = "select COUNT(DISTINCT SUBSTRING(c.country FROM 1 FOR 2)) AS total_count
-                        from public.contract_region_mapping crm
-	                        left join ocean.contacts c on  c.contact_id = crm.overeas and crm.ksmart_station_new ilike 'ksmart%'
-                        where coalesce(c.country,'')<> '' 
-                            and  SUBSTRING(c.country FROM 1 FOR 2) ilike '" . common::check_input($term) . "%'";
-                $rc = common::excuteOneSql($sql);
-            }
-            $tp = ceil($rc / $ps);
-            if ($rc > 0) {
-                $sql = "select DISTINCT SUBSTRING(c.country FROM 1 FOR 2) AS country_code 
+            $sql = "select DISTINCT SUBSTRING(c.country FROM 1 FOR 2) AS country_code 
                         from public.contract_region_mapping crm
 	                        left join ocean.contacts c on  c.contact_id = crm.overeas and crm.ksmart_station_new ilike 'ksmart%'
                         where coalesce(c.country,'')<> '' 
                             and  SUBSTRING(c.country FROM 1 FOR 2) ilike '" . common::check_input($term) . "%'";
-                $sql .= " order by country_code limit " . $ps . " offset " . ($cp - 1) * $ps;
-
-                $rs = common::excuteListSql($sql);
-                //前端要加上id 从1开始
-                $retData = array();
-                foreach($rs as $key => $val){
-                    if(!empty($val['country_code'])){
-                        $val["id"] = $key +1;
-                        $retData[] = $val;
-                    }
+            $sql .= " order by country_code";
+
+            $rs = common::excuteListSql($sql);
+            //前端要加上id 从1开始
+            $retData = array();
+            foreach($rs as $key => $val){
+                if(!empty($val['country_code'])){
+                    $retData[] = array("value" =>$val['country_code'] ,"label"=>$val['country_code']);
                 }
-                $arrTmp = array('searchData' => $retData, 
-                        'rc' => $rc,
-                        'ps' => $ps,
-                        'cp' => $cp,
-                        'tp' => $tp);
-                common::echo_json_encode(200,$arrTmp);
-                exit();
-            }else{
-                $arrTmp = array('searchData' => array());
-                common::echo_json_encode(200, $arrTmp);
-                exit();
             }
+            common::echo_json_encode(200,$retData);
+            exit();
+
         }
 
         /**
          * select station  选择国家后再展示 station list数据
-         */
+        */
         if ($operate == "station") {
             $country = common::check_input($_REQUEST['country']);
             $sql  = "select crm.overeas from public.contract_region_mapping crm
                             left join ocean.contacts c on  c.contact_id = crm.overeas and crm.ksmart_station_new ilike 'ksmart%'
                     where SUBSTRING(c.country FROM 1 FOR 2) = '".$country."'";
-            $data = common::excuteListSql($sql);
+            $rs = common::excuteListSql($sql);
 
-            common::echo_json_encode(200,$data);
+            foreach($rs as $key => $val){
+                if(!empty($val['overeas'])){
+                    $retData[] = array("value" =>$val['overeas'] ,"label"=>$val['overeas']);
+                }
+            }
+            common::echo_json_encode(200,$retData);
             exit();
         }
 
@@ -98,13 +77,19 @@ class destination_delivery {
          * select KLN PIC   下拉可供选择的employee帐号,且帐号权限站点包含选中的station
          */
         if ($operate == "employee_account") {
+            $term = $_POST['term'];
+            $term = trim($term);
             $station = $_REQUEST['station'];
             $more_param = common::getInNotInSqlForSearch(utils::implode(';',$station));
 
-            $sql  = "select email from  employee where contact_id in ($more_param) ";
-            $data = common::excuteListSql($sql);
-
-            common::echo_json_encode(200,$data);
+            $sql  = "select email from  employee where contact_id in ($more_param) and email ilike '" . common::check_input($term) . "%' limit 20";
+            $rs = common::excuteListSql($sql);
+            foreach($rs as $key => $val){
+                if(!empty($val['email'])){
+                    $retData[] = array("value" =>$val['email'] ,"label"=>$val['email']);
+                }
+            }
+            common::echo_json_encode(200,$retData);
             exit();
         }
 
@@ -112,107 +97,92 @@ class destination_delivery {
          * 下拉可供选择的ports
          */
         if ($operate == "ports") {
-            $mode = $_REQUEST['mode'];
-            if ($mode == 'sea'){
-                $sql  = "select DISTINCT uncode from public.ports where  coalesce(uncode,'')<> ''  order by uncode";
-            } else {
-                $sql = "select DISTINCT coalesce(airport.country_abb,'')||airport.airport_code as uncode from sfs.airport 
-                            where  coalesce(country_abb,'')<>'' order by uncode";
-            }
-            $data = common::excuteListSql($sql);
-            common::echo_json_encode(200,$data);
-            exit();
-
-            $cp = common::check_input($_POST ['cp']); //current_page
-            $ps = common::check_input($_POST ['ps']); //ps
-            if (empty($ps))
-                $ps = 20;
             
             $mode = $_POST['mode'];
             $term = $_POST['term'];
             $term = trim($term);
 
-            $rc = $_POST ['rc'];
-            if ($rc == - 1) {
-               if ($mode == 'sea'){
-                    $sql  = "select COUNT(DISTINCT uncode) from public.ports 
-                        where  coalesce(uncode,'')<>'' and  uncode ilike '" . common::check_input($term) . "%'";
-                } else {
-                    $sql = "select COUNT(DISTINCT coalesce(airport.country_abb,'')||airport.airport_code) from sfs.airport 
-                            where  coalesce(country_abb,'')<>'' 
-                                and  coalesce(airport.country_abb,'')||airport.airport_code ilike '" . common::check_input($term) . "%'";
-                }
-                $rc = common::excuteOneSql($sql);
-            }
-            $tp = ceil($rc / $ps);
-            if ($rc > 0) {
-                if ($mode == 'sea'){
+            if ($mode == 'sea'){
                 $sql  = "select DISTINCT uncode from public.ports 
                     where  coalesce(uncode,'')<> '' and  uncode ilike '" . common::check_input($term) . "%'";
-                } else {
+            } else {
                     $sql = "select DISTINCT coalesce(airport.country_abb,'')||airport.airport_code as uncode from sfs.airport 
                             where  coalesce(country_abb,'')<>'' 
                                 and  coalesce(airport.country_abb,'')||airport.airport_code ilike '" . common::check_input($term) . "%'";
+            }
+            $sql .= " order by uncode limit 20";
+
+            $rs = common::excuteListSql($sql);
+            //前端要加上id 从1开始
+            $retData = array();
+            foreach($rs as $key => $val){
+                if(!empty($val['uncode'])){
+                    $retData[] = array("value" =>$val['uncode'] ,"label"=>$val['uncode']);
                 }
-                $sql .= " order by uncode limit " . $ps . " offset " . ($cp - 1) * $ps;
-
-                $rs = common::excuteListSql($sql);
-                //前端要加上id 从1开始
-                $retData = array();
-                foreach($rs as $key => $val){
-                    if(!empty($val['uncode'])){
-                        $val["id"] = $key +1;
-                        $retData[] = $val;
-                    }
-                }
-                $arrTmp = array('searchData' => $retData, 
-                        'rc' => $rc,
-                        'ps' => $ps,
-                        'cp' => $cp,
-                        'tp' => $tp);
-                common::echo_json_encode(200,$arrTmp);
-                exit();
-            }else{
-                $arrTmp = array('searchData' => array());
-                common::echo_json_encode(200, $arrTmp);
-                exit();
             }
+            common::echo_json_encode(200,$retData);
+            exit();
+            
         }
 
         /**
          * 下拉可供选择的carrier
          */
         if ($operate == "carrier") {
+            $term = $_POST['term'];
+            $term = trim($term);
+
+            $sql = "select DISTINCT scac from public.vessel_company
+                            where coalesce(scac,'')<> '' and  scac ilike '" . common::check_input($term) . "%'";
+            $sql .= " order by scac limit 20";
+
+            $rs = common::excuteListSql($sql);
+            //前端要加上id 从1开始
+            $retData = array();
+            foreach($rs as $key => $val){
+                if(!empty($val['scac'])){
+                    $retData[] = array("value" =>$val['scac'] ,"label"=>$val['scac']);
+                }
+            }
+            common::echo_json_encode(200,$retData);
+            exit();
+        }
+    }
+
+    /**
+     * destination_delivery 配置
+    */
+    public function destination_delivery_config(){
+        $operate = utils::_get('operate');
+        $operate = strtolower($operate);
+
+        /**
+         * 这个是嵌套在destination_delivery的配置查询,
+         */
+        if ($operate == "search"){
             $cp = common::check_input($_POST ['cp']); //current_page
             $ps = common::check_input($_POST ['ps']); //ps
             if (empty($ps))
-                $ps = 20;
-
-            $term = $_POST['term'];
-            $term = trim($term);
+                $ps = 100;
+            if (empty($cp))
+                $cp = 1;
 
             $rc = $_POST ['rc'];
             if ($rc == - 1) {
-                $sql = "select COUNT(DISTINCT scac) from public.vessel_company 
-                            where coalesce(scac,'')<> '' and  scac ilike '" . common::check_input($term) . "%'";
+                $sql = "select count(*) from public.kln_destination_delivery_config";
                 $rc = common::excuteOneSql($sql);
             }
             $tp = ceil($rc / $ps);
             if ($rc > 0) {
-                $sql = "select DISTINCT scac from public.vessel_company
-                            where coalesce(scac,'')<> '' and  scac ilike '" . common::check_input($term) . "%'";
-                $sql .= " order by scac limit " . $ps . " offset " . ($cp - 1) * $ps;
+                $sql = "select * from public.kln_destination_delivery_config";
+                $sql .= " order by id desc limit " . $ps . " offset " . ($cp - 1) * $ps;
 
                 $rs = common::excuteListSql($sql);
-                //前端要加上id 从1开始
-                $retData = array();
+
                 foreach($rs as $key => $val){
-                    if(!empty($val['scac'])){
-                        $val["id"] = $key +1;
-                        $retData[] = $val;
-                    }
+                    $rs[$key]["_serial_no"] = common::deCode($val['serial_no'], 'E');
                 }
-                $arrTmp = array('searchData' => $retData, 
+                $arrTmp = array('searchData' => $rs, 
                         'rc' => $rc,
                         'ps' => $ps,
                         'cp' => $cp,
@@ -225,48 +195,184 @@ class destination_delivery {
                 exit();
             }
         }
-    }
 
-    /**
-     * destination_delivery 配置
-    */
-    public function destination_delivery_config(){
-        $operate = utils::_get('operate');
-        $operate = strtolower($operate);
+        if ($operate == "add"){
+            $serial_no = common::deCode($_GET['a'], 'D');
+            $data = array();
+            $rule = array();
 
-        /**
-         * 这个是嵌套在destination_delivery的配置查询,
-         */
-        if ($operate == "search"){
-            $sql = "select * from public.kln_destination_delivery_config";
-            $data = common::excuteListSql($sql);
-            common::echo_json_encode(200,$data);                
-            exit(); 
-        }
+            if (!empty($serial_no)){
+                $sql = "select * from public.kln_destination_delivery_config where serial_no = '$serial_no'";
+                $data = common::excuteObjectSql($sql);
 
-        if ($operate == "add"){
-            $id = common::deCode($_GET['a'], 'D');
-            if (!empty($id)){
+                if ($data['recommended_delivery'] == 'delivery_eta_ata') {
+                    $sql = "select * from public.kln_destination_delivery_rule where recommended_delivery_serial_no = '$serial_no'";
+                    $rule = common::excuteObjectSql($sql);
+                }
+            } 
+
+            //处理组装返回格式
+            //RcommendDeliveryDate
+            $RecommendCheckedAirList = array();
+            $RecommendCheckedSeaList = array();
+            $RecommendCheckedList = array();
+            foreach($rule as $item){
+                if ($item['mode_type'] == 'sea'){
+                    $RecommendCheckedSeaList[] = array("Priority"=>$item['priority'],"RuleType"=>$item['rule_type'],
+                        "Port"=>explode(";", $item['ports']),
+                        "Carrier"=>explode(";", $item['carrier']),
+                        "FromDate"=>$item['recommended_delivery_from'],
+                        "ToDate"=>$item['recommended_delivery_to']);
+                }
+                if ($item['mode_type'] == 'air'){
+                    $RecommendCheckedAirList[] = array("Priority"=>$item['priority'],"RuleType"=>$item['rule_type'],
+                        "Port"=>explode(";", $item['ports']),
+                        "Carrier"=>explode(";", $item['carrier']),
+                        "FromDate"=>$item['recommended_delivery_from'],
+                        "ToDate"=>$item['recommended_delivery_to']);
+                }
+                if (!utils::in_array($item['mode_type'], $RecommendCheckedList)) {
+                    $RecommendCheckedList[] = $item['mode_type'];
+                }
+            }
 
+            $returnData = $data;
+            if (!empty($data['booking_window'])) {
+                $returnData["SetBookingWindow"] = array("windowradio" =>$data['booking_window'],
+                    "windowBeforeDays"=>$data['booking_window'], 
+                    "windowAfterDays"=>$data['booking_window']);
             } else {
+                $returnData["SetBookingWindow"] = array();
+            }
 
+            if ($data['recommended_delivery'] == 'Delivery_ETA_ATA') {
+                $returnData["RcommendDeliveryDate"] = array("Recommendradio" =>$data['recommended_delivery'],
+                    "RecommendCheckedList"=>$RecommendCheckedList, 
+                    "RecommendCheckedAirList"=>$RecommendCheckedAirList,
+                    "RecommendCheckedSeaList"=>$RecommendCheckedSeaList);
+            } else {
+                $returnData["RcommendDeliveryDate"] = array();
             }
 
+            $returnData["KLNPLCvalue"] = explode(";", $data['kln_pic']);
+
             global $_COPYRIGHT;
             $data = array('copyright' =>$_COPYRIGHT,
-                'website' =>"");
+                'returnData' =>$returnData);
             common::echo_json_encode(200,$data);                
             exit(); 
         }
 
         if ($operate == "save"){
-            $id = common::deCode($_GET['a'], 'D');
-            if (!empty($id)){
-
+            $serial_no = common::deCode($_POST['a'], 'D');
+
+            $country = common::check_input($_POST['country']);
+            $station = empty($_POST['station']) ? "" :explode(";", $_POST['station']);
+            $booking_window = common::check_input($_POST['booking_window']);
+            $booking_window_date_start = common::check_input($_POST['booking_window_date_start']);
+            $booking_window_date_end = common::check_input($_POST['booking_window_date_end']);
+            $recommended_delivery = common::check_input($_POST['recommended_delivery']);
+            $kln_pic = empty($_POST['kln_pic']) ? "" :explode(";", $_POST['kln_pic']);
+
+            //rule
+            $_mode_type = $_POST['mode_type'];
+            $_priority = $_POST['priority'];
+            $_rule_type = $_POST['rule_type'];
+            $_ports = $_POST['ports'];
+            $_carrier = $_POST['carrier'];
+            $_recommended_delivery_from = $_POST['recommended_delivery_from'];
+            $_recommended_delivery_to = $_POST['recommended_delivery_to'];
+
+            $errmsg = "";
+            $sql = "";
+            if (!empty($serial_no)){
+                $updateSqlSet = " modify_by = '"._getLoginName()."',update_time = now()";
+                if (!empty($country)) {
+                    $updateSqlSet.= ", country = '$country' ";
+                }
+                if (!empty($station)) {
+                    $updateSqlSet.= ", station = '$station' ";
+                }
+                if (!empty($booking_window)) {
+                    $updateSqlSet.= ", booking_window = '$booking_window' ";
+                }
+                if (!empty($booking_window_date_start)) {
+                    $updateSqlSet.= ", booking_window_date_start = '$booking_window_date_start' ";
+                }
+                if (!empty($booking_window_date_end)) {
+                    $updateSqlSet.= ", booking_window_date_end = '$booking_window_date_end' ";
+                }
+                if (!empty($recommended_delivery)) {
+                    $updateSqlSet.= ", recommended_delivery = '$recommended_delivery' ";
+                }
+                if (!empty($kln_pic)) {
+                    $updateSqlSet.= ", kln_pic = '$kln_pic' ";
+                }
+                //代表update 
+                $sql .= "update public.kln_destination_delivery_config set ".$updateSqlSet."
+                    where serial_no = '$serial_no';";
             } else {
+                //代表更新
+                $serial_no = common::uuid();
+                $sql .="INSERT INTO public.kln_destination_delivery_config(
+                        serial_no, country, station, booking_window, booking_window_date_start, 
+                        booking_window_date_end, recommended_delivery, kln_pic, create_by, 
+                        created_time, modify_by, update_time)
+                VALUES ('$serial_no', '$country', '$station', '$booking_window', '$booking_window_date_start', 
+                        '$booking_window_date_end', '$recommended_delivery', '$kln_pic',
+                        '"._getLoginName()."', now(), '"._getLoginName()."', now());";
+            }
 
+            if ($recommended_delivery == "delivery_eta_ata"){
+                // 用于统计每种类型是否存在,以及是否满足 rule_type = 'all'
+                $typeExists = ['air' => false, 'sea' => false];
+                $typeHasAllRule = ['air' => false, 'sea' => false];
+
+                foreach($_mode_type as $key => $v){
+                    $mode_type = $v;
+                    $priority = $_priority[$key];
+                    $rule_type = $_rule_type[$key];
+                    $ports = empty($_ports[$key]) ? "" :explode(";", $_ports[$key]);
+                    $carrier = empty($_carrier[$key]) ? "" :explode(";", $_carrier[$key]);
+                    $recommended_delivery_from = $_recommended_delivery_from[$key];
+                    $recommended_delivery_to = $_recommended_delivery_to[$key];
+
+                    // 只处理 air 和 sea
+                    if ($mode_type == 'air' || $mode_type == 'sea') {
+                        $typeExists[$mode_type] = true;
+                        if ($rule_type == 'all') {
+                            $typeHasAllRule[$mode_type] = true;
+                        }
+                    }
+
+                    //先删除,后添加
+                    $sql .= "delete from  public.kln_destination_delivery_rule where recommended_delivery_serial_no = '$serial_no';";
+                    $sql .= "INSERT INTO public.kln_destination_delivery_rule(
+                            serial_no, recommended_delivery_serial_no, mode_type, priority, 
+                            rule_type, ports, carrier, recommended_delivery_from, recommended_delivery_to, 
+                            create_by, created_time, modify_by, update_time)
+                    VALUES ('$serial_no', '$mode_type', '$priority', 
+                            '$rule_type', '$ports', '$carrier', '$recommended_delivery_from', '$recommended_delivery_to', 
+                            '"._getLoginName()."', now(), '"._getLoginName()."', now());";
+                }
+                // 检查缺失的 rule_type = 'all'
+                $missingTypes = [];
+                foreach (['air', 'sea'] as $type) {
+                    if ($typeExists[$type] && !$typeHasAllRule[$type]) {
+                        $missingTypes[] = $type;
+                    }
+                }
+                if (!empty($missingTypes)) {
+                    $errmsg =  "The Default Rule must exist.";
+                }
             }
-            $data = "";
+
+            if (empty($errmsg) && !empty($sql)){
+                common::excuteUpdateSql($sql);
+                $data = array("msg" =>"success");
+            } else {
+                $data = array("msg" =>$errmsg);
+            }  
             common::echo_json_encode(200,$data);                
             exit(); 
         }

+ 9 - 5
service/tools.class.php

@@ -710,7 +710,7 @@ class tools {
             $id = $_POST["id"];
             //代表改用户下的所有信息全部标记为已读
             if ($read_type == "true"){
-                $rs = common::excuteUpdateSql("update public.kln_notifiation_info set is_send_message = now(),readed_date = now() where lower(user_login) = '".strtolower(_getLoginName())."'");
+                $rs = common::excuteUpdateSql("update public.kln_notifiation_info set is_send_message = now(),readed_date = now() where lower(user_login) in ('".strtolower(_getLoginName())."','all_user')");
             }else{
                 //处理一下前端提交的不正确参数
                 $param_id = array();
@@ -1099,7 +1099,7 @@ class tools {
             $ps = 15;
         }
         $sql = "select count(1) from  public.kln_user_subscribed u
-                left join public.kln_ocean o on  o.serial_no  = u.subscribed_serial_no 
+                inner 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);
@@ -1123,7 +1123,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  = u.subscribed_serial_no
+                        inner 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){
@@ -2370,6 +2370,10 @@ class tools {
             if($title == "Password Notifications" and $mInfo["other_pnum"] <= 3){
                 $isExpiration = true;
             }
+            $path = $mInfo["id"];
+            if(!empty($mInfo["serial_no"])){
+                $path =$mInfo["serial_no"];
+            }
             $eventCard = array(
                 "title" => $title,
                 "id"=> $mInfo["id"],
@@ -2378,8 +2382,8 @@ class tools {
                 "isRead"=>!empty($mInfo["is_send_message"]) ? true : false,
                 "isExpiration"=> $isExpiration,
                 "rules_type"=>$mInfo["notifiation_type"],
-                "imgSrc"=>SERVER_PAHT.FILE_UPLOAD_PAHT."feature_update_".$mInfo["id"].".jpg",
-                "view_more_link" =>"main_new_version.php?action=feature_update&id=".$mInfo["id"]
+                "imgSrc"=>SERVER_PAHT.FILE_UPLOAD_PAHT."feature_update_".$path.".png",
+                "view_more_link" =>"main_new_version.php?action=feature_update&id=".$path
             );
         }
         return $eventCard;

+ 1 - 1
utils/utils.class.php

@@ -1087,7 +1087,7 @@ class utils {
 
             // 检查每个变量是否都在 SQL 字段中
             foreach ($templateVars as $var) {
-                if (!in_array(strtolower($var), array_map('strtolower', $sqlFields))) {
+                if (!utils::in_array(strtolower($var), array_map('strtolower', $sqlFields))) {
                     continue; // 跳出当前循环,继续检查下一行
                 }
             }