作者 开飞机的舒克

后台优化

@@ -6,6 +6,7 @@ use app\admin\library\Auth; @@ -6,6 +6,7 @@ use app\admin\library\Auth;
6 use app\common\controller\Backend; 6 use app\common\controller\Backend;
7 use app\common\controller\Resource; 7 use app\common\controller\Resource;
8 use Exception; 8 use Exception;
  9 +use GuzzleHttp\Client;
9 use PhpOffice\PhpSpreadsheet\Cell\Coordinate; 10 use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
10 use PhpOffice\PhpSpreadsheet\Reader\Csv; 11 use PhpOffice\PhpSpreadsheet\Reader\Csv;
11 use PhpOffice\PhpSpreadsheet\Reader\Xls; 12 use PhpOffice\PhpSpreadsheet\Reader\Xls;
@@ -170,6 +171,46 @@ class Study extends Backend @@ -170,6 +171,46 @@ class Study extends Backend
170 } 171 }
171 } 172 }
172 173
  174 + public function qiniu($filePath = '', $fileName = '')
  175 + {
  176 +// $filePath=ROOT_PATH.'public'.DS.'uploads'.DS.'20200224'.DS.'img1.jpg';//文件路径
  177 +// $fileName='public'.DS.'uploads'.DS.'20200224'.DS.'img1.jpg'; //七牛云上的名字
  178 +// $filePath = ROOT_PATH . 'public' . DS . 'uploads' . DS . '20200224' . DS . 'img2.jpg';//文件路径
  179 +// $fileName = 'public' . DS . 'uploads' . DS . '20200224' . DS . 'img2.jpg'; //七牛云上的名字,头部不带杠
  180 +
  181 + $config = get_addon_config('qiniu');
  182 + $policy = array(
  183 + 'saveKey' => $fileName,
  184 + );
  185 + $auth = new \Qiniu\Auth($config['accessKey'], $config['secretKey']);
  186 + $token = $auth->uploadToken($config['bucket'], null, $config['expire'], $policy);
  187 + $multipart = [
  188 + ['name' => 'token', 'contents' => $token],
  189 + [
  190 + 'name' => 'file',
  191 + 'contents' => fopen($filePath, 'r'),
  192 + 'filename' => $fileName,
  193 + ]
  194 + ];
  195 +
  196 + try {
  197 + $client = new Client();
  198 + $res = $client->request('POST', $config['uploadurl'], [
  199 + 'multipart' => $multipart
  200 + ]);
  201 + $code = $res->getStatusCode();
  202 + //成功不做任何操作
  203 + } catch (\GuzzleHttp\Exception\ClientException $e) {
  204 + // unlink($filePath);
  205 + $this->error("上传失败");
  206 + }
  207 +// dump($code);
  208 +// $url = '/';
  209 +
  210 + //上传成功后将存储变更为qiniu
  211 +// $this->success("上传成功", ['url' => cdnurl($url), 'save_path' => $url]);
  212 + }
  213 +
173 /** 214 /**
174 * 添加 215 * 添加
175 * 216 *
@@ -26,7 +26,8 @@ class Study extends Model @@ -26,7 +26,8 @@ class Study extends Model
26 // 追加属性 26 // 追加属性
27 protected $append = [ 27 protected $append = [
28 'gender_text', 28 'gender_text',
29 - 'team_rank' 29 + 'team_rank',
  30 + 'barcode_images'
30 ]; 31 ];
31 32
32 33
@@ -56,6 +57,12 @@ class Study extends Model @@ -56,6 +57,12 @@ class Study extends Model
56 return $order; 57 return $order;
57 } 58 }
58 59
  60 + public function getBarcodeImagesAttr($value,$data){
  61 + $list = $this->where('id',$data['id'])->value('barcode');
  62 + $order = 'http://campus.cn'.$list;
  63 + return $order;
  64 + }
  65 +
59 66
60 public function grade() 67 public function grade()
61 { 68 {
@@ -10,7 +10,6 @@ @@ -10,7 +10,6 @@
10 <a href="javascript:;" class="btn btn-success btn-add {:$auth->check('study/add')?'':'hide'}" title="{:__('Add')}" ><i class="fa fa-plus"></i> {:__('Add')}</a> 10 <a href="javascript:;" class="btn btn-success btn-add {:$auth->check('study/add')?'':'hide'}" title="{:__('Add')}" ><i class="fa fa-plus"></i> {:__('Add')}</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> 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 -  
14 <div class="dropdown btn-group {:$auth->check('study/multi')?'':'hide'}"> 13 <div class="dropdown btn-group {:$auth->check('study/multi')?'':'hide'}">
15 <ul class="dropdown-menu text-left" role="menu"> 14 <ul class="dropdown-menu text-left" role="menu">
16 <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> 15 <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 @@ -96,10 +96,38 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
96 // {field: 'team_id', title: __('Team_id')}, 96 // {field: 'team_id', title: __('Team_id')},
97 {field: 'earn_score', title: __('Earn_score'),operate:false}, 97 {field: 'earn_score', title: __('Earn_score'),operate:false},
98 {field: 'unique', title: __('Unique'), operate:false}, 98 {field: 'unique', title: __('Unique'), operate:false},
99 - {field: 'barcode', title: __('Barcode'),events: Table.api.events.image, formatter: Table.api.formatter.image, operate:false}, 99 + {field: 'barcode_images', title: __('Barcode'),events: Table.api.events.image, formatter: Table.api.formatter.image, operate:false},
100 // {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime}, 100 // {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
101 // {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime}, 101 // {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
102 {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, 102 {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate,
  103 + buttons: [
  104 + {
  105 + name: 'click',
  106 + title: __('下载'),
  107 + text: __('下载'),
  108 + classname: 'btn btn-xs btn-info btn-click',
  109 + icon: 'fa fa-leaf',
  110 + // dropdown: '更多',//如果包含dropdown,将会以下拉列表的形式展示
  111 + click: function (e, data) {
  112 + $.ajax({
  113 + type: 'get',
  114 + data: {id: data.id},
  115 + success: function (res) {
  116 + if (res.code === 1) {
  117 + var domain = 'http://campus.cn/';
  118 + var url = domain + data.barcode_images;
  119 + var link = document.createElement('a');
  120 + link.setAttribute("download", "");
  121 + link.href = url;
  122 + link.click();
  123 + $(".btn-refresh").trigger("click");
  124 + }
  125 + }
  126 + });
  127 +
  128 + }
  129 + },
  130 + ],
103 formatter: Table.api.formatter.operate} 131 formatter: Table.api.formatter.operate}
104 ] 132 ]
105 ] 133 ]