ShuanghongS 2 weeks ago
parent
commit
d1e0fc1ff4
3 changed files with 233 additions and 6 deletions
  1. 3 1
      service/column.class.php
  2. 154 1
      service/destination_delivery.class.php
  3. 76 4
      utils/common.class.php

+ 3 - 1
service/column.class.php

@@ -318,7 +318,9 @@ class column {
         if ($type == "destination_delivery_shipment_search"){
             return array("eta" =>array("formatter" =>"date"),
                         "ata" =>array("formatter" =>"date"),
-                        "date_range" =>array("type" =>"recommend"));
+                        "date_range" =>array("type" =>"recommend"),
+                        "packing_list" =>array("type" =>"download"),
+                        "commercial_invoice" =>array("type" =>"download"));
         }
     }
 

+ 154 - 1
service/destination_delivery.class.php

@@ -593,6 +593,9 @@ class destination_delivery {
             //栏位信息
             $column = column::getInstance()->getDisplayColumn('destination_delivery_shipment_search');
             $BookingTableColumns = column::getInstance()->tableColumns('destination_delivery_shipment_search',$column);
+
+            //Packing List 和 Commercial Invoice  顺序处理,以后自定义了可以移除这个函数
+            $BookingTableColumns = common::destination_delivery_shipment_search_sort($BookingTableColumns);
             $data['TrackingTableColumns'] = $BookingTableColumns;
             common::echo_json_encode(200,$data);
             exit();
@@ -1215,6 +1218,13 @@ class destination_delivery {
             common::echo_json_encode(200,$data); 
         }
 
+        /*
+        * download  batch P AND CI document 
+        */
+        if ($operate == "batch_download_ci_p_file") {
+            $this->_batch_download_ci_p_file();
+        }
+
     }
 
     private function getCommunicationNew($serial_no) {
@@ -1283,6 +1293,16 @@ class destination_delivery {
         if (isset($_REQUEST['ata_end']) && !empty($_REQUEST['ata_end']))
             $sqlWhere .= " and ata <= '" . common::usDate2sqlDate($_REQUEST['ata_end']) . " 23:59:59'";
 
+        $recommended_delivery_sql = ' 1=1 ';
+        if (isset($_REQUEST['recommended_delivery_date']) && !empty($_REQUEST['recommended_delivery_date']))
+            $recommended_delivery_sql .= " and ((recommended_delivery_from_date is not null and recommended_delivery_from_date <= '" . common::usDate2sqlDate($_REQUEST['recommended_delivery_date']) . " 00:00:00')
+                                                OR 
+                                                recommended_delivery_from_date is null)";
+        if (isset($_REQUEST['recommended_delivery_date']) && !empty($_REQUEST['recommended_delivery_date']))
+            $recommended_delivery_sql .= " and ((recommended_delivery_to_date is not null and recommended_delivery_to_date >= '" . common::usDate2sqlDate($_REQUEST['recommended_delivery_date']) . " 00:00:00')
+                                                OR 
+                                                recommended_delivery_to_date is null)";
+
         $sql = "with oo as(
                 select  oo.serial_no,
                     oo.h_bol,
@@ -1495,7 +1515,7 @@ class destination_delivery {
                     ) r ON true
                 order by md.eta desc,md.h_bol asc
             )
-            select * from shipment_table";
+            select * from shipment_table where ".$recommended_delivery_sql;
 
         $rs = common::excuteListSql($sql);
         error_log($sql);
@@ -1743,6 +1763,139 @@ class destination_delivery {
         }
         return array("msg"=>"","result"=>$result);
     }
+
+    /**
+     * 批量选着文件下载 CI & P
+     */
+    private function _batch_download_ci_p_file(){
+        //ocean的相关配置参数    
+        $OutFileURL = common::excuteOneSql("select item_value from config where item='OutFileURL'");
+        $ocean_can_view_file = common::excuteOneSql("select ocean_can_view_file from ra_online_user where user_login='".$_SESSION['ONLINE_USER']['user_login']."'");
+        //$ocean_can_view_file = '{"HBL":[{"type":"TELEX","value":""}],"MBL":[{"type":"TELEX","value":""}]}';
+        $tar = json_decode($ocean_can_view_file,true);
+        $sqlFiterWhere = "1<>1 ";
+        foreach($tar as $_tar){
+            foreach($_tar as $dkey => $dvalue){
+                $sqlFiterWhere.= " or (lower(format_serailno) in ('".strtolower(str_replace(";","','",$dvalue['value']))."')  
+                    and upper((string_to_array((string_to_array(file_name,'.'))[1], '_'))[2]) = '".$dvalue['type']."')";
+            }
+        }
+
+        //air的相关配置参数  
+        $air_can_view_file = common::excuteOneSql("select air_can_view_file from ra_online_user where lower(user_login)='".strtolower($_SESSION['ONLINE_USER']['user_login'])."'");
+        $air_tar = json_decode($air_can_view_file,true);
+        $air_sqlFiterWhere = "1<>1 ";
+        foreach($air_tar as $_air_tar){
+            foreach($_air_tar as $air_dkey => $air_dvalue){
+                $air_sqlFiterWhere.= " or (lower(format_serailno) in ('".strtolower(str_replace(";","','",$air_dvalue['value']))."')  
+                    and upper((string_to_array((string_to_array(file_name,'.'))[1], '_'))[2]) = '".$air_dvalue['type']."')";
+            }
+        }
+
+        $serial_no_arr = array($_POST['serial_no']);
+        $file_type = $_POST['file_type'];
+        
+        $file_arr = array();
+        foreach($serial_no_arr as $key =>$serial_no){
+            $ocean = common::excuteObjectSql("select m_bol as _m_bol,
+                h_bol as _h_bol,
+                transport_mode,
+                order_from,
+                case when transport_mode = 'sea' and order_from = 'public' then (select job_no from public.ocean o  where  o.serial_no = oo.serial_no)
+                    when transport_mode = 'sea' and order_from = 'sfs' then (select job_no from sfs.ocean o  where  o.serial_no = oo.serial_no)
+                else ''::text end as _job_bol
+            from public.kln_ocean oo where oo.serial_no = '$serial_no'");
+
+            $_schemas = $ocean["order_from"];
+            if ($ocean["transport_mode"] == 'sea'){
+                //ocean 能看的文件类型
+                $document = _getViewDocType($_schemas);
+                $file_serial_nos = array();
+                foreach ($document as $v) {
+                    $types = $v['serial_no'];
+                    $types = strtolower($types);
+                    $types = explode(";", $types);
+                    foreach ($types as $k => $type) {
+                        $file_serial_nos[] = $type;
+                    }
+                }
+                $file_serial_nos = utils::implode(';',$file_serial_nos);
+                $formatSerailnoWhere = "";
+                if($file_type == 'Packing List'){
+                    $formatSerailnoWhere = " and lower(format_serailno) = '".strtolower('abfee0ffac630983976b336b37624c73')."'";
+                } else if ($file_type == 'C/I'){
+                    $formatSerailnoWhere = " and lower(format_serailno) = '".strtolower('4f0a5400c6829')."'";
+                }
+
+                $filefilter = " ('TELEX') ";
+                $fileSql = "SELECT file_path, file_name from $_schemas.ra_online_doc_upload doc
+                            left join $_schemas.ra_online_file_format ff on ff.serial_no = doc.format_serailno
+                    where (lower(bol) = '" . strtolower($ocean['_m_bol']) . "' or lower(bol) = '" . strtolower($ocean['_h_bol']) . "' or lower(bol) = '".strtolower($ocean['_job_bol'])."' )
+                        and (
+                            (upper(coalesce((string_to_array((string_to_array(file_name,'.'))[1], '_'))[2],'')) not in ".$filefilter.") 
+                            or  ".$sqlFiterWhere."
+                        ) and lower(format_serailno) " . common::getInNotInSql($file_serial_nos) . " ". $formatSerailnoWhere."  order by ff.format_name ASC,doc.id desc"; 
+
+                $rss = common::excuteListSql($fileSql);
+                foreach ($rss as $rs) {
+                    if ($rs['from_system']=="TOPOCEAN"||$rs['from_system']=="KSMART") {
+                        //这种类型现在没有了
+                    }else {
+                        $file_arr[] = $rs['file_path'] . DS . $rs['file_name'];
+                    }
+                } 
+               
+            }
+            if ($ocean["transport_mode"] == 'air'){
+                //air能看的文件类型
+                $document = _getAirViewDocType($_schemas);
+                $file_serial_nos = array();
+                foreach ($document as $v) {
+                    $types = $v['serial_no'];
+                    $types = strtolower($types);
+                    $types = explode(";", $types);
+                    foreach ($types as $k => $type) {
+                        $file_serial_nos[] = $type;
+                    }
+                }
+                $file_serial_nos = utils::implode(';',$file_serial_nos);
+
+                $formatSerailnoWhere = "";
+                if($file_type == 'Packing List'){
+                    $formatSerailnoWhere = " and lower(format_serailno) = '".strtolower('abfee0ffac630983976b336b37624c73')."'";
+                } else if ($file_type == 'C/I'){
+                    $formatSerailnoWhere = " and lower(format_serailno) = '".strtolower('4f0a5400c6829')."'";
+                }
+
+                $filefilter = " ('TELEX') ";
+                $fileSql = "SELECT file_path, file_name from $_schemas.air_doc_upload 
+                            left join $_schemas.air_file_format ff on ff.serial_no = air_doc_upload.format_serailno
+                    where (lower(bol) = '" . strtolower($ocean['_m_bol']) . "' or lower(bol) = '" . strtolower($ocean['_h_bol']) . "')
+                        and (
+                            (upper(coalesce((string_to_array((string_to_array(file_name,'.'))[1], '_'))[2],'')) not in ".$filefilter.") 
+                            or  ".$sqlFiterWhere."
+                        ) and lower(format_serailno) " . common::getInNotInSql($file_serial_nos) . "  order by ff.format_name ASC,air_doc_upload.id desc"; 
+
+                $rss = common::excuteListSql($fileSql);
+                foreach ($rss as $rs) {
+                    $file_arr[] = $rs['file_path'] . DS . $rs['file_name'];
+                } 
+            }
+        }
+
+        if($file_type == 'Packing List'){
+            $zipName = "Packing_List";
+        } else if ($file_type == 'C/I'){
+            $zipName = "C/I";     
+        }
+
+        if(empty($file_arr)){
+            $data = array('msg' => 'No file to download','data' => '');
+            common::echo_json_encode(500, $data);
+            exit();
+        }
+        common::downloadFilesAsSimapleZip($file_arr,$zipName);
+    }
 }
 
 ?>

+ 76 - 4
utils/common.class.php

@@ -962,10 +962,7 @@ class common {
         $filename = str_replace("/", DIRECTORY_SEPARATOR, $filename);
         $filename = str_replace("\\", DIRECTORY_SEPARATOR, $filename);
         if (!file_exists($filename)){
-            $data = array(
-                'msg' =>"File Not Exist"
-            );
-            common::echo_json_encode(500, $data);
+            exit("File Not Exist");
         }
         if (empty($display_name))
             $display_name = basename($filename);
@@ -1090,6 +1087,54 @@ class common {
         common::download_file($f, null, TRUE, null);
     }
 
+    /**
+     * 生成嵌套 ZIP 文件 
+     *
+     * @param array $files 文件列表
+     */
+    public static  function downloadFilesAsSimapleZip($files,$zipName)
+    {
+        // 清除缓冲区,防止输出干扰 ZIP 文件
+        if (ob_get_level()) {
+            ob_end_clean();
+        }
+
+        $f = ONLINE_ROOT . DS . "upload" . DS . $zipName."_" . date('Y-m-dH\hi\ms\s', time()) . ".zip";
+        $zip = new ZipArchive();
+
+        if ($zip->open($f, ZipArchive::OVERWRITE) === TRUE ||
+            $zip->open($f, ZipArchive::CREATE) === TRUE) {
+            
+        } else {
+            die("create ZIP faild。");
+        }
+        foreach ($files as $file) {
+            if (file_exists($file) && is_file($file)) {
+                $zip->addFile($file, basename($file));
+            }
+        }
+        $zip->close();
+        // 读取 ZIP 文件内容并 Base64 编码
+        if (!file_exists($f)) {
+            $data = array('msg' => 'ZIP file was not created.','data' => '');
+            common::echo_json_encode(500, $data);
+            exit();
+        }
+        $zipContent = file_get_contents($f);
+        if ($zipContent === false) {
+            $data = array('msg' => 'Failed to read ZIP file.','data' => '');
+            common::echo_json_encode(500, $data);
+            exit();
+        }
+        $base64Zip = base64_encode($zipContent);
+        //删除临时 ZIP 文件
+        unlink($f);
+        
+        $data = array("msg"=>"success","filename" =>basename($f),"data"=>$base64Zip);
+        common::echo_json_encode(200, $data);
+        exit();
+    }
+
 
     /*
      * Get the file extension
@@ -4295,5 +4340,32 @@ class common {
 
         return $safeName;
     }
+    /**
+     * Packing List 和 Commercial Invoice  顺序处理,以后自定义了可以移除这个函数
+    */
+    public static function destination_delivery_shipment_search_sort($columns){
+        // 找出目标元素的位置和需要移动的元素
+        $moveItems = [];
+        $targetIndex = null;
+
+        foreach ($columns as $index => $item) {
+            if ($item['field'] === 'package_type') {
+                $targetIndex = $index;
+            } elseif (in_array($item['title'], ['Packing List', 'Commercial Invoice'])) {
+                $moveItems[] = $item;
+                unset($columns[$index]); // 移除这些元素
+            }
+        }
+
+        // 如果找到了目标位置并且有需要移动的元素
+        if ($targetIndex !== null && count($moveItems) > 0) {
+            // 在目标位置后插入需要移动的元素
+            array_splice($columns, $targetIndex + 1, 0, $moveItems);
+            
+            // 重置数组索引
+            $columns = array_values($columns);
+        }
+        return $columns;
+    }
 }
 ?>