Bladeren bron

津补贴通用附件下载

sugangqiang 11 maanden geleden
bovenliggende
commit
9aa878b168

+ 6 - 1
app/admin/view/talent_allowance/index.html

@@ -335,7 +335,12 @@
                             {/if}
                             {if condition="chkCommission('','/admin/talentAllowance/firstDownload')"}
                             <button type="button" class="btn btn-sm btn-primary " onclick="TalentAllowanceInfo.download()" id="">
-                                <i class="fa fa-download"></i>&nbsp;下载
+                                <i class="fa fa-download"></i>&nbsp;下载常规附件
+                            </button>
+                            {/if}
+                            {if condition="chkCommission('','/admin/talentAllowance/firstDownload')"}
+                            <button type="button" class="btn btn-sm btn-primary " onclick="TalentAllowanceInfo.downloadCommonFile()" id="">
+                                <i class="fa fa-download"></i>&nbsp;下载通用附件
                             </button>
                             {/if}
                             {/eq}

+ 57 - 0
app/common/controller/Api.php

@@ -857,6 +857,63 @@ class Api extends BaseController {
         @unlink($tmp_file_path);
     }
 
+    /**
+     * 打包下载人才申请附件
+     */
+    public function downloadCommonZip() {
+        $table = "un_talent_allowance_common_file";
+        $param = $this->request->param();
+        $id = $param["id"];
+        $year = $param["year"];
+
+        $info = \app\common\model\TalentAllowance::findOrEmpty($id);
+        $enterprise_info = \app\common\model\Enterprise::findOrEmpty($info["enterpriseId"]);
+        $zip_filename = sprintf("%s(%s)津补贴申报通用材料.zip", $info["talentName"], $enterprise_info["name"]);
+
+        $where = [];
+        $where[] = ["enterpriseId", "=", $info["enterpriseId"]];
+        $where[] = ["batch", "=", $year];
+        $files = Db::table($table)->where($where)->select()->toArray();
+        if (!$files) {
+            //die("没有附件不能打包下载");
+            echo "<script>parent.layer.alert('没有附件不能打包下载');window.history.go(-1);</script>";
+        }
+
+        $tmp_path = "storage/temp/";
+        $tmp_file_path = $tmp_path . $zip_filename;
+        if (!file_exists($tmp_path)) {
+            mkdir($tmp_path);
+        }
+        $zip = new \ZipArchive();
+        if (!$zip->open($tmp_file_path, \ZipArchive::CREATE | \ZipArchive::OVERWRITE)) {
+            header('HTTP/1.1 404 NOT FOUND');
+        }
+        foreach ($files as $file) {
+            if (is_array($file)) {
+                $filepath = "storage/" . $file["url"];
+                $fileTypeInfo = Db::table("new_common_filetype")->where("id", $file["fileTypeId"])->find();
+                $filename = $fileTypeInfo["name"] . "/" . $file["originalName"];
+                $zip->addFile($filepath, $filename);
+            } else {
+                $filepath = "storage/" . $file;
+                $filename = basename($filepath);
+                $zip->addFile($filepath, $filename);
+            }
+        }
+        $zip->close();
+        if (file_exists($tmp_file_path)) {
+            header("Cache-Control: public");
+            header("Content-Description: File Transfer");
+            header('Content-disposition: attachment; filename=' . $zip_filename); //文件名
+            header("Content-Type: application/octet-stream;charset=utf-8"); //zip格式的
+            header("Content-Transfer-Encoding: binary"); //告诉浏览器,这是二进制文件
+            header('Content-Length: ' . filesize($tmp_file_path)); //告诉浏览器,文件大小
+            @readfile($tmp_file_path);
+        }
+        //删除临时文件
+        @unlink($tmp_file_path);
+    }
+
     private function chkIsFileOwner($mainId, $type) {
         if (!$mainId)
             return true;

+ 8 - 0
public/static/modular/talentAllowance/talentAllowanceInfo.js

@@ -848,6 +848,14 @@ TalentAllowanceInfo.download = function () {
     }
 }
 
+/**
+ * 下载通用附件
+ */
+TalentAllowanceInfo.downloadCommonFile = function () {
+    if (this.check()) {
+        window.location.href = encodeURI(encodeURI(Feng.ctxPath + "/common/api/downloadCommonZip?id=" + TalentAllowanceInfo.seItem.id + "&year=" + TalentAllowanceInfo.seItem.year));
+    }
+}
 
 $(function () {
     var process = $("#process").val();