作者 开飞机的舒克

后台修改

@@ -4,6 +4,9 @@ namespace app\admin\controller; @@ -4,6 +4,9 @@ namespace app\admin\controller;
4 4
5 use app\common\controller\Backend; 5 use app\common\controller\Backend;
6 use app\common\controller\Resource; 6 use app\common\controller\Resource;
  7 +use think\Db;
  8 +use think\exception\PDOException;
  9 +use think\exception\ValidateException;
7 10
8 /** 11 /**
9 * 学生管理 12 * 学生管理
@@ -70,20 +73,6 @@ class Study extends Backend @@ -70,20 +73,6 @@ class Study extends Backend
70 return $this->view->fetch(); 73 return $this->view->fetch();
71 } 74 }
72 75
73 - /**  
74 - * 生成现场二维码  
75 - */  
76 - public function barcode($ids)  
77 - {  
78 - $barcode = $this->model->where('id', $ids)->value('barcode');  
79 - if (!empty($barcode)) {  
80 - $this->error('已生成条形码,无需重复生成');  
81 - }  
82 - $brpath = Resource::StudyBar($ids);  
83 - halt($brpath);  
84 - $this->model->save(['barcode' => $brpath], ['id' => $ids]);  
85 - $this->success('操作成功');  
86 - }  
87 76
88 77
89 //导出数据 78 //导出数据
@@ -159,4 +148,49 @@ class Study extends Backend @@ -159,4 +148,49 @@ class Study extends Backend
159 exit; 148 exit;
160 } 149 }
161 } 150 }
  151 +
  152 + /**
  153 + * 添加
  154 + *
  155 + * @return string
  156 + * @throws \think\Exception
  157 + */
  158 + public function add()
  159 + {
  160 + if (false === $this->request->isPost()) {
  161 + return $this->view->fetch();
  162 + }
  163 + $params = $this->request->post('row/a');
  164 + if (empty($params)) {
  165 + $this->error(__('Parameter %s can not be empty', ''));
  166 + }
  167 + $params = $this->preExcludeFields($params);
  168 +
  169 + if ($this->dataLimit && $this->dataLimitFieldAutoFill) {
  170 + $params[$this->dataLimitField] = $this->auth->id;
  171 + }
  172 + $result = false;
  173 + Db::startTrans();
  174 + try {
  175 + //是否采用模型验证
  176 + if ($this->modelValidate) {
  177 + $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
  178 + $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : $name) : $this->modelValidate;
  179 + $this->model->validateFailException()->validate($validate);
  180 + }
  181 + $result = $this->model->allowField(true)->save($params);
  182 + $id = $this->model->id;
  183 + $brpath = Resource::StudyBar($id);
  184 + $this->model->save(['barcode'=>$brpath],['id'=>$id]);
  185 + Db::commit();
  186 + } catch (ValidateException|PDOException|Exception $e) {
  187 + Db::rollback();
  188 + $this->error($e->getMessage());
  189 + }
  190 + if ($result === false) {
  191 + $this->error(__('No rows were inserted'));
  192 + }
  193 + $this->success();
  194 + }
  195 +
162 } 196 }
@@ -3,10 +3,10 @@ @@ -3,10 +3,10 @@
3 namespace app\api\controller; 3 namespace app\api\controller;
4 4
5 use app\common\controller\Api; 5 use app\common\controller\Api;
  6 +use app\common\controller\Resource;
6 7
7 /** 8 /**
8 * 示例接口 9 * 示例接口
9 - * @ApiInternal  
10 */ 10 */
11 class Demo extends Api 11 class Demo extends Api
12 { 12 {
@@ -16,7 +16,7 @@ class Demo extends Api @@ -16,7 +16,7 @@ class Demo extends Api
16 //如果接口已经设置无需登录,那也就无需鉴权了 16 //如果接口已经设置无需登录,那也就无需鉴权了
17 // 17 //
18 // 无需登录的接口,*表示全部 18 // 无需登录的接口,*表示全部
19 - protected $noNeedLogin = ['test', 'test1']; 19 + protected $noNeedLogin = ['*'];
20 // 无需鉴权的接口,*表示全部 20 // 无需鉴权的接口,*表示全部
21 protected $noNeedRight = ['test2']; 21 protected $noNeedRight = ['test2'];
22 22
@@ -68,7 +68,8 @@ class Demo extends Api @@ -68,7 +68,8 @@ class Demo extends Api
68 */ 68 */
69 public function test3() 69 public function test3()
70 { 70 {
71 - $this->success('返回成功', ['action' => 'test3']); 71 + $ids = Resource::StudyBar(1);
  72 + return $ids;
72 } 73 }
73 74
74 } 75 }
@@ -7,8 +7,8 @@ use tinymeng\code\Generate; @@ -7,8 +7,8 @@ use tinymeng\code\Generate;
7 class Resource 7 class Resource
8 { 8 {
9 public static function StudyBar($id){ 9 public static function StudyBar($id){
10 - $generate = Generate::bar();  
11 - /** 二维码存入本地并输出存储路径 */ 10 + $generate = Generate::qr();
  11 + /** 直接输出图片 */
12 $file_path = $generate->create($id,true); 12 $file_path = $generate->create($id,true);
13 $file_path = substr($file_path,strripos($file_path,"public")+6); 13 $file_path = substr($file_path,strripos($file_path,"public")+6);
14 return $file_path; 14 return $file_path;
此 diff 太大无法显示。
@@ -100,27 +100,6 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin @@ -100,27 +100,6 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
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: 'qrcode',  
106 - title: __('生成条形码'),  
107 - classname: 'btn btn-xs btn-primary btn-ajax',  
108 - icon: 'fa fa-qrcode',  
109 - confirm: '确认生成新的条形码',  
110 - url: function(ids){  
111 - var x = JSON.stringify(ids);  
112 - var s = ids.id;  
113 - return 'study/barcode?ids='+s;  
114 - },  
115 - success: function (data, ret) {  
116 - return true;  
117 - },  
118 - error: function (data, ret) {  
119 - Toastr.error(ret.msg);  
120 - return false;  
121 - }  
122 - }  
123 - ],  
124 formatter: Table.api.formatter.operate} 103 formatter: Table.api.formatter.operate}
125 ] 104 ]
126 ] 105 ]