作者 开飞机的舒克

后台修改

... ... @@ -4,6 +4,9 @@ namespace app\admin\controller;
use app\common\controller\Backend;
use app\common\controller\Resource;
use think\Db;
use think\exception\PDOException;
use think\exception\ValidateException;
/**
* 学生管理
... ... @@ -70,20 +73,6 @@ class Study extends Backend
return $this->view->fetch();
}
/**
* 生成现场二维码
*/
public function barcode($ids)
{
$barcode = $this->model->where('id', $ids)->value('barcode');
if (!empty($barcode)) {
$this->error('已生成条形码,无需重复生成');
}
$brpath = Resource::StudyBar($ids);
halt($brpath);
$this->model->save(['barcode' => $brpath], ['id' => $ids]);
$this->success('操作成功');
}
//导出数据
... ... @@ -159,4 +148,49 @@ class Study extends Backend
exit;
}
}
/**
* 添加
*
* @return string
* @throws \think\Exception
*/
public function add()
{
if (false === $this->request->isPost()) {
return $this->view->fetch();
}
$params = $this->request->post('row/a');
if (empty($params)) {
$this->error(__('Parameter %s can not be empty', ''));
}
$params = $this->preExcludeFields($params);
if ($this->dataLimit && $this->dataLimitFieldAutoFill) {
$params[$this->dataLimitField] = $this->auth->id;
}
$result = false;
Db::startTrans();
try {
//是否采用模型验证
if ($this->modelValidate) {
$name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
$validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : $name) : $this->modelValidate;
$this->model->validateFailException()->validate($validate);
}
$result = $this->model->allowField(true)->save($params);
$id = $this->model->id;
$brpath = Resource::StudyBar($id);
$this->model->save(['barcode'=>$brpath],['id'=>$id]);
Db::commit();
} catch (ValidateException|PDOException|Exception $e) {
Db::rollback();
$this->error($e->getMessage());
}
if ($result === false) {
$this->error(__('No rows were inserted'));
}
$this->success();
}
}
... ...
... ... @@ -3,10 +3,10 @@
namespace app\api\controller;
use app\common\controller\Api;
use app\common\controller\Resource;
/**
* 示例接口
* @ApiInternal
*/
class Demo extends Api
{
... ... @@ -16,7 +16,7 @@ class Demo extends Api
//如果接口已经设置无需登录,那也就无需鉴权了
//
// 无需登录的接口,*表示全部
protected $noNeedLogin = ['test', 'test1'];
protected $noNeedLogin = ['*'];
// 无需鉴权的接口,*表示全部
protected $noNeedRight = ['test2'];
... ... @@ -68,7 +68,8 @@ class Demo extends Api
*/
public function test3()
{
$this->success('返回成功', ['action' => 'test3']);
$ids = Resource::StudyBar(1);
return $ids;
}
}
... ...
... ... @@ -7,8 +7,8 @@ use tinymeng\code\Generate;
class Resource
{
public static function StudyBar($id){
$generate = Generate::bar();
/** 二维码存入本地并输出存储路径 */
$generate = Generate::qr();
/** 直接输出图片 */
$file_path = $generate->create($id,true);
$file_path = substr($file_path,strripos($file_path,"public")+6);
return $file_path;
... ...
此 diff 太大无法显示。
... ... @@ -100,27 +100,6 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
// {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: 'qrcode',
title: __('生成条形码'),
classname: 'btn btn-xs btn-primary btn-ajax',
icon: 'fa fa-qrcode',
confirm: '确认生成新的条形码',
url: function(ids){
var x = JSON.stringify(ids);
var s = ids.id;
return 'study/barcode?ids='+s;
},
success: function (data, ret) {
return true;
},
error: function (data, ret) {
Toastr.error(ret.msg);
return false;
}
}
],
formatter: Table.api.formatter.operate}
]
]
... ...