作者 开飞机的舒克

圖片下載

@@ -16,6 +16,9 @@ use think\db\exception\BindParamException; @@ -16,6 +16,9 @@ use think\db\exception\BindParamException;
16 use think\exception\DbException; 16 use think\exception\DbException;
17 use think\exception\PDOException; 17 use think\exception\PDOException;
18 use think\exception\ValidateException; 18 use think\exception\ValidateException;
  19 +use http\Header;
  20 +use think\Env;
  21 +use app\api\controller\Login;
19 22
20 /** 23 /**
21 * 学生管理 24 * 学生管理
@@ -296,5 +299,61 @@ class Study extends Backend @@ -296,5 +299,61 @@ class Study extends Backend
296 $this->success(); 299 $this->success();
297 } 300 }
298 301
  302 + /**
  303 + * 下载分享码
  304 + *
  305 + * @param $ids
  306 + * @return void
  307 + */
  308 + public function multi($ids = null)
  309 + {
  310 + $ids = $this->request->param('ids');
  311 + $product = new \app\admin\model\Study();
  312 + $ids = explode(',', $ids);
  313 + $arr = $product->whereIn('id' , $ids)->field('barcode')->select();
  314 + foreach ($arr as $v){
  315 + $v['barcode'] = substr($v['barcode'],20);
  316 + $as = ROOT_PATH.'public/'.$v['barcode'];
  317 + $data[]=$as;
  318 + }
  319 + $url = ROOT_PATH.'public/';
  320 + // $data = [
  321 + // ROOT_PATH.'public/uploads/QR/20230301/_18.jpg'
  322 + // ];
  323 + // zip 临时文件
  324 + $tmp_dir = $url . 'temp/';
  325 + // zip名称
  326 + $zip_name = 'quality_'.time().'.zip';
  327 + // 打包
  328 + $zipName = $this->zip_files($data, $tmp_dir.$zip_name);
  329 + //下载
  330 + $down = 'http://campus.shs.broing.cn/temp/'.$zip_name;
  331 + downloads($down);
  332 + }
  333 +
  334 + /**
  335 + * 打包成zip
  336 + * @param $pathArr
  337 + * @param $zipName
  338 + * @return array
  339 + */
  340 + public function zip_files($pathArr,$zipName)
  341 + {
  342 +
  343 + $zip = new \ZipArchive();
  344 + if($zip->open($zipName,\ZipArchive::CREATE|\ZipArchive::OVERWRITE)){
  345 + foreach($pathArr as $file){
  346 + if(!file_exists($file)){
  347 + continue;
  348 + }
  349 + $zip->addFile($file,basename($file)); //向压缩包中添加文件
  350 + }
  351 + $zip->close();
  352 + return $zipName;
  353 + }else{
  354 + return '';
  355 + }
  356 + }
  357 +
299 358
300 } 359 }
@@ -11,7 +11,7 @@ @@ -11,7 +11,7 @@
11 <a href="javascript:;" class="btn btn-success btn-import {:$auth->check('你的权限规则')?'':'hide'}" title="导入" id="btn-import-file" data-url="ajax/upload" data-mimetype="csv,xls,xlsx" data-multiple="false"><i class="fa fa-upload"></i> 导入</a> 11 <a href="javascript:;" class="btn btn-success btn-import {:$auth->check('你的权限规则')?'':'hide'}" title="导入" id="btn-import-file" data-url="ajax/upload" data-mimetype="csv,xls,xlsx" data-multiple="false"><i class="fa fa-upload"></i> 导入</a>
12 <a href="javascript:;" class="btn btn-danger btn-export {:$auth->check('study/export')?'':'hide'}" title="{:__('Export')}" id="btn-export-file"><i class="fa fa-download"></i> {:__('Export')}</a> 12 <a href="javascript:;" class="btn btn-danger btn-export {:$auth->check('study/export')?'':'hide'}" title="{:__('Export')}" id="btn-export-file"><i class="fa fa-download"></i> {:__('Export')}</a>
13 <a class="btn btn-info btn-disabled disabled btn-selected" href="javascript:;"><i class="fa fa-leaf"></i> 批量下载</a> 13 <a class="btn btn-info btn-disabled disabled btn-selected" href="javascript:;"><i class="fa fa-leaf"></i> 批量下载</a>
14 - 14 + <a href="#" title="下载分享码" class="btn btn-success btn-disabled download {:$auth->check('study/multi')?'':'hide'} ">下载分享码</a>
15 15
16 <div class="dropdown btn-group {:$auth->check('study/multi')?'':'hide'}"> 16 <div class="dropdown btn-group {:$auth->check('study/multi')?'':'hide'}">
17 <ul class="dropdown-menu text-left" role="menu"> 17 <ul class="dropdown-menu text-left" role="menu">
@@ -548,12 +548,12 @@ EOT; @@ -548,12 +548,12 @@ EOT;
548 if (file_exists($filename)) { 548 if (file_exists($filename)) {
549 unlink($filename); 549 unlink($filename);
550 } 550 }
551 -//重新生成文件 551 + //重新生成文件
552 $zip = new ZipArchive(); 552 $zip = new ZipArchive();
553 if ($zip->open($filename, ZIPARCHIVE::CREATE) !== TRUE) { 553 if ($zip->open($filename, ZIPARCHIVE::CREATE) !== TRUE) {
554 exit('无法打开文件,或者文件创建失败'); 554 exit('无法打开文件,或者文件创建失败');
555 } 555 }
556 -// $datalist=array('try.php','zip_class.php'); 556 + // $datalist=array('try.php','zip_class.php');
557 foreach ($datalist as $val) { 557 foreach ($datalist as $val) {
558 if (file_exists($val)) { 558 if (file_exists($val)) {
559 $path_parts = pathinfo($val); 559 $path_parts = pathinfo($val);
@@ -572,4 +572,31 @@ EOT; @@ -572,4 +572,31 @@ EOT;
572 $upload_path = str_replace('\\', '/', ROOT_PATH); 572 $upload_path = str_replace('\\', '/', ROOT_PATH);
573 return $upload_path . 'public' . $path; 573 return $upload_path . 'public' . $path;
574 } 574 }
  575 +
  576 + /**
  577 + *下载小程序码到浏览器
  578 + *
  579 + * @param string $pic_url 下载路径
  580 + */
  581 + function downloads($file)
  582 + {
  583 + $fileTmp = pathinfo($file);
  584 + $fileExt = $fileTmp['extension']; //图片后缀名
  585 + $filename =($fileTmp['filename']); //图片名称,可以任务设置图片名称
  586 + $saveFileName = ($filename.'.'.$fileExt);
  587 + $fp=fopen($file,"r");
  588 + //下载文件需要用到的头
  589 + Header("Content-type: video/quicktime");
  590 + Header("Accept-Ranges: bytes");
  591 + Header("Content-Disposition: attachment; filename=".$saveFileName);
  592 + $buffer=1024;
  593 + $file_count=0;
  594 + //向浏览器返回数据
  595 + while(!feof($fp)){
  596 + $file_con=fread($fp,$buffer);
  597 + $file_count+=$buffer;
  598 + echo $file_con;
  599 + }
  600 + fclose($fp);
  601 + }
575 } 602 }
1 define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) { 1 define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
2 2
  3 + $('.download').click(function () {
  4 + var ids = Table.api.selectedids($("#table"));
  5 + window.location.href = '/back.php/study/multi?ids='+ids;
  6 + });
  7 +
3 var Controller = { 8 var Controller = {
4 index: function () { 9 index: function () {
5 // 初始化表格参数配置 10 // 初始化表格参数配置
@@ -26,10 +31,8 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin @@ -26,10 +31,8 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
26 if (res.code === 1) { 31 if (res.code === 1) {
27 var domain = window.location.href.split(':')[0] + '://' + document.domain; 32 var domain = window.location.href.split(':')[0] + '://' + document.domain;
28 var url = domain + '/back.php/study/down_file'; 33 var url = domain + '/back.php/study/down_file';
29 - var link = document.createElement('a');  
30 - link.setAttribute("download", "");  
31 - link.href = url;  
32 - link.click(); 34 + window.location.href = url;
  35 + location.reload();
33 $(".btn-refresh").trigger("click"); 36 $(".btn-refresh").trigger("click");
34 } 37 }
35 } 38 }