作者 开飞机的舒克

后台优化

... ... @@ -6,6 +6,7 @@ use app\admin\library\Auth;
use app\common\controller\Backend;
use app\common\controller\Resource;
use Exception;
use GuzzleHttp\Client;
use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
use PhpOffice\PhpSpreadsheet\Reader\Csv;
use PhpOffice\PhpSpreadsheet\Reader\Xls;
... ... @@ -170,6 +171,46 @@ class Study extends Backend
}
}
public function qiniu($filePath = '', $fileName = '')
{
// $filePath=ROOT_PATH.'public'.DS.'uploads'.DS.'20200224'.DS.'img1.jpg';//文件路径
// $fileName='public'.DS.'uploads'.DS.'20200224'.DS.'img1.jpg'; //七牛云上的名字
// $filePath = ROOT_PATH . 'public' . DS . 'uploads' . DS . '20200224' . DS . 'img2.jpg';//文件路径
// $fileName = 'public' . DS . 'uploads' . DS . '20200224' . DS . 'img2.jpg'; //七牛云上的名字,头部不带杠
$config = get_addon_config('qiniu');
$policy = array(
'saveKey' => $fileName,
);
$auth = new \Qiniu\Auth($config['accessKey'], $config['secretKey']);
$token = $auth->uploadToken($config['bucket'], null, $config['expire'], $policy);
$multipart = [
['name' => 'token', 'contents' => $token],
[
'name' => 'file',
'contents' => fopen($filePath, 'r'),
'filename' => $fileName,
]
];
try {
$client = new Client();
$res = $client->request('POST', $config['uploadurl'], [
'multipart' => $multipart
]);
$code = $res->getStatusCode();
//成功不做任何操作
} catch (\GuzzleHttp\Exception\ClientException $e) {
// unlink($filePath);
$this->error("上传失败");
}
// dump($code);
// $url = '/';
//上传成功后将存储变更为qiniu
// $this->success("上传成功", ['url' => cdnurl($url), 'save_path' => $url]);
}
/**
* 添加
*
... ...
... ... @@ -26,7 +26,8 @@ class Study extends Model
// 追加属性
protected $append = [
'gender_text',
'team_rank'
'team_rank',
'barcode_images'
];
... ... @@ -56,6 +57,12 @@ class Study extends Model
return $order;
}
public function getBarcodeImagesAttr($value,$data){
$list = $this->where('id',$data['id'])->value('barcode');
$order = 'http://campus.cn'.$list;
return $order;
}
public function grade()
{
... ...
... ... @@ -10,7 +10,6 @@
<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('你的权限规则')?'':'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>
<div class="dropdown btn-group {:$auth->check('study/multi')?'':'hide'}">
<ul class="dropdown-menu text-left" role="menu">
<li><a class="btn btn-link btn-multi btn-disabled disabled" href="javascript:;" data-params="status=normal"><i class="fa fa-eye"></i> {:__('Set to normal')}</a></li>
... ...
... ... @@ -96,10 +96,38 @@ 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', 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: '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',
data: {id: data.id},
success: function (res) {
if (res.code === 1) {
var domain = 'http://campus.cn/';
var url = domain + data.barcode_images;
var link = document.createElement('a');
link.setAttribute("download", "");
link.href = url;
link.click();
$(".btn-refresh").trigger("click");
}
}
});
}
},
],
formatter: Table.api.formatter.operate}
]
]
... ...