|
@@ -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;
|