作者 开飞机的舒克

后台学生管理功能优化

... ... @@ -291,18 +291,18 @@ class Study extends Backend
}
}
/**
* 下载条形码
*/
public function down()
{
$id = input('id');
$this->success('');
// $res = \app\admin\model\Study::where('id', $id)->update(['down' => 1]);
// if ($res) {
// $this->success('');
// }
}
// /**
// * 下载条形码
// */
// public function down()
// {
// $id = input('id');
// $this->success('');
//// $res = \app\admin\model\Study::where('id', $id)->update(['down' => 1]);
//// if ($res) {
//// $this->success('');
//// }
// }
/**
... ... @@ -398,58 +398,58 @@ class Study extends Backend
$this->success();
}
/**
* 下载分享码
*/
public function multi($ids = null)
{
$ids = $this->request->param('ids');
$study = new \app\admin\model\Study();
$ids = explode(',', $ids);
$arr = $study->whereIn('id' , $ids)->field('barcode')->select();
foreach ($arr as $v){
//$v['barcode'] = substr($v['barcode'],20);
$as = ROOT_PATH.'public/'.$v['barcode'];
$data[]=$as;
}
$url = ROOT_PATH.'public/';
// $data = [
// ROOT_PATH.'public/uploads/QR/20230301/_18.jpg'
// ];
// zip 临时文件
$tmp_dir = $url . 'temp/';
// zip名称
$zip_name = 'images'.'.zip';
// 打包
$zipName = $this->zip_files($data, $tmp_dir.$zip_name);
//下载
$down = 'http://campus.shs.broing.cn/temp/'.$zip_name;
downloads($down);
}
/**
* 打包成zip
* @param $pathArr
* @param $zipName
* @return array
*/
public function zip_files($pathArr,$zipName)
{
$zip = new \ZipArchive();
if($zip->open($zipName,\ZipArchive::CREATE|\ZipArchive::OVERWRITE)){
foreach($pathArr as $file){
if(!file_exists($file)){
continue;
}
$zip->addFile($file,basename($file)); //向压缩包中添加文件
}
$zip->close();
return $zipName;
}else{
return '';
}
}
// /**
// * 下载分享码
// */
// public function multi($ids = null)
// {
// $ids = $this->request->param('ids');
// $study = new \app\admin\model\Study();
// $ids = explode(',', $ids);
// $arr = $study->whereIn('id' , $ids)->field('barcode')->select();
// foreach ($arr as $v){
// //$v['barcode'] = substr($v['barcode'],20);
// $as = ROOT_PATH.'public/'.$v['barcode'];
// $data[]=$as;
// }
// $url = ROOT_PATH.'public/';
// // $data = [
// // ROOT_PATH.'public/uploads/QR/20230301/_18.jpg'
// // ];
// // zip 临时文件
// $tmp_dir = $url . 'temp/';
// // zip名称
// $zip_name = 'images'.'.zip';
// // 打包
// $zipName = $this->zip_files($data, $tmp_dir.$zip_name);
// //下载
// $down = 'http://campus.shs.broing.cn/temp/'.$zip_name;
// downloads($down);
// }
//
// /**
// * 打包成zip
// * @param $pathArr
// * @param $zipName
// * @return array
// */
// public function zip_files($pathArr,$zipName)
// {
//
// $zip = new \ZipArchive();
// if($zip->open($zipName,\ZipArchive::CREATE|\ZipArchive::OVERWRITE)){
// foreach($pathArr as $file){
// if(!file_exists($file)){
// continue;
// }
// $zip->addFile($file,basename($file)); //向压缩包中添加文件
// }
// $zip->close();
// return $zipName;
// }else{
// return '';
// }
// }
}
... ...
... ... @@ -9,9 +9,9 @@
<a href="javascript:;" class="btn btn-primary btn-refresh" title="{:__('Refresh')}" ><i class="fa fa-refresh"></i> </a>
<a href="javascript:;" class="btn btn-success btn-add {:$auth->check('study/add')?'':'hide'}" title="{:__('Add')}" ><i class="fa fa-plus"></i> {:__('Add')}</a>
<!-- <a href="javascript:;" class="btn btn-success btn-import {:$auth->check('study/import')?'':'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>-->
<a href="javascript:;" class="btn btn-danger 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>
<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>
<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>
<a href="#" title="下载分享码" class="btn btn-success btn-disabled download {:$auth->check('study/multi')?'':'hide'} ">下载条形码</a>
<!-- <a href="#" title="下载分享码" class="btn btn-success btn-disabled download {:$auth->check('study/multi')?'':'hide'} ">下载条形码</a>-->
<div class="dropdown btn-group {:$auth->check('study/multi')?'':'hide'}">
<ul class="dropdown-menu text-left" role="menu">
... ...
... ... @@ -20,26 +20,26 @@ class Crontab extends Api
/**
* @ApiTitle (定时任务)
*/
public function index()
{
//查询未生成的条形码
$id = db('study')->where('generate', 0)->limit(10)->column('id');
if (empty($id)) {
$this->error('不执行', ['status' => 0]);
}
foreach ($id as $k => $v) {
$res = str_pad($v, 8, "0", STR_PAD_LEFT);
$barpath = Resource::StudyBar($res);
db('study')
->where('id', $v)
->update([
'barcode' => $barpath,
'unique' => $res,
'generate' => 1
]);
}
$this->success('执行成功', ['status' => 1]);
}
// public function index()
// {
// //查询未生成的条形码
// $id = db('study')->where('generate', 0)->limit(10)->column('id');
// if (empty($id)) {
// $this->error('不执行', ['status' => 0]);
// }
// foreach ($id as $k => $v) {
// $res = str_pad($v, 8, "0", STR_PAD_LEFT);
// $barpath = Resource::StudyBar($res);
// db('study')
// ->where('id', $v)
// ->update([
// 'barcode' => $barpath,
// 'unique' => $res,
// 'generate' => 1
// ]);
//
// }
// $this->success('执行成功', ['status' => 1]);
//
// }
}
\ No newline at end of file
... ...
... ... @@ -9,10 +9,10 @@ class Resource
/**
* 生成条形码
*/
public static function StudyBar($res){
$generate = Generate::bar();
$file_path = $generate->create($res,true,true);
$file_path = substr($file_path,strripos($file_path,"public")+6);
return $file_path;
}
// public static function StudyBar($res){
// $generate = Generate::bar();
// $file_path = $generate->create($res,true,true);
// $file_path = substr($file_path,strripos($file_path,"public")+6);
// return $file_path;
// }
}
\ No newline at end of file
... ...
... ... @@ -101,41 +101,41 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
// {field: 'team_id', title: __('Team_id')},
{field: 'earn_score', title: __('Earn_score'),operate:false},
{field: 'unique', title: __('Unique'), operate:false},
{field: 'barcode_images', title: __('Barcode'),events: Table.api.events.image, formatter: Table.api.formatter.image, operate:false},
//{field: 'barcode_images', title: __('Barcode'),events: Table.api.events.image, formatter: Table.api.formatter.image, operate:false},
{field: 'rank', title: __('Rank'),operate: false},
// {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
// {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate,
buttons: [
{
name: 'click',
title: __('下载'),
text: __('下载'),
classname: 'btn btn-xs btn-info btn-click',
icon: 'fa fa-leaf',
// dropdown: '更多',//如果包含dropdown,将会以下拉列表的形式展示
click: function (e, data) {
$.ajax({
type: 'get',
url: 'study/down',
data: {id: data.id},
success: function (res) {
if (res.code === 1) {
var domain = window.location.href.split(':')[0] + '://' + document.domain;
var url = domain + data.barcode;
var link = document.createElement('a');
link.setAttribute("download", data.name);
link.href = url;
link.click();
$(".btn-refresh").trigger("click");
}
}
});
}
},
],
// buttons: [
// {
// name: 'click',
// title: __('下载'),
// text: __('下载'),
// classname: 'btn btn-xs btn-info btn-click',
// icon: 'fa fa-leaf',
// // dropdown: '更多',//如果包含dropdown,将会以下拉列表的形式展示
// click: function (e, data) {
//
// $.ajax({
// type: 'get',
// url: 'study/down',
// data: {id: data.id},
// success: function (res) {
// if (res.code === 1) {
// var domain = window.location.href.split(':')[0] + '://' + document.domain;
// var url = domain + data.barcode;
// var link = document.createElement('a');
// link.setAttribute("download", data.name);
// link.href = url;
// link.click();
// $(".btn-refresh").trigger("click");
// }
// }
// });
//
// }
// },
// ],
formatter: Table.api.formatter.operate}
]
]
... ...