mirror of https://github.com/1099438829/apeblog
完善邀请码生成
This commit is contained in:
parent
8765f122b6
commit
b10e3dc5c1
|
|
@ -14,6 +14,15 @@ use app\admin\services\UtilService as Util;
|
|||
*/
|
||||
class Invitation extends AuthController
|
||||
{
|
||||
/**
|
||||
* 构造方法 初始化一些参数
|
||||
*/
|
||||
public function initialize()
|
||||
{
|
||||
parent::initialize(); // TODO: Change the autogenerated stub
|
||||
//修正因为修改model名称和原来不能对应导致的model功能异常
|
||||
$this->model = new aModel();
|
||||
}
|
||||
/**
|
||||
* 活动列表
|
||||
* @return string
|
||||
|
|
@ -45,4 +54,70 @@ class Invitation extends AuthController
|
|||
]);
|
||||
return app("json")->layui(aModel::systemPage($where));
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存修改
|
||||
* @param string $id
|
||||
* @return mixed
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author 李玉坤
|
||||
* @date 2021-02-20 14:32
|
||||
*/
|
||||
public function save($id="")
|
||||
{
|
||||
$data = Util::postMore([
|
||||
['code',''],
|
||||
['status',0],
|
||||
]);
|
||||
if ($data['code'] == "") return app("json")->fail("邀请码不能为空");
|
||||
if ($id=="") {
|
||||
//判断下用户是否存在
|
||||
$info = aModel::where('code',$data['code'])->find();
|
||||
if ($info){
|
||||
return app("json")->fail("邀请码已存在");
|
||||
}
|
||||
$data['user'] = $this->adminId;
|
||||
$res = aModel::create($data);
|
||||
}else {
|
||||
$data['user'] = $this->adminId;
|
||||
$res = aModel::update($data,['id'=>$id]);
|
||||
}
|
||||
return $res ? app("json")->success("操作成功",'code') : app("json")->fail("操作失败");
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量添加
|
||||
* @param string $id
|
||||
* @return mixed
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author 李玉坤
|
||||
* @date 2021-02-20 14:35
|
||||
*/
|
||||
public function addMultiple($id="")
|
||||
{
|
||||
$data = Util::postMore([
|
||||
['name',''],
|
||||
['number',1],
|
||||
]);
|
||||
if ($data['name'] == "") return app("json")->fail("邀请码前缀不能为空");
|
||||
if ($data['number'] == "") return app("json")->fail("数量不是数字或者小于1");
|
||||
$count =intval($data['number']);
|
||||
for ($i=0; $i <$count; $i++) {
|
||||
$code['code'] = ($data['name'].substr(time(),-6).rand(0,9999));
|
||||
$code['status'] = 0;
|
||||
$code['user'] = $this->adminId;
|
||||
$check = aModel::where('code')->find();
|
||||
if($check ==null || $check ==false){
|
||||
$res = aModel::create($code);
|
||||
}else{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
return $res ? app("json")->success("操作成功",'code') : app("json")->fail("操作失败");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -26,7 +26,6 @@ trait TemplateTrait
|
|||
$ids = $request->param("id",0);
|
||||
if (empty($ids) || !$ids) return app("json")->fail("参数有误,Id为空!");
|
||||
if (!is_array($ids)) $ids = explode(",",$ids);
|
||||
if (in_array(1,$ids)) return app("json")->fail("参数有误,初始ID不允许操作!");
|
||||
return $this->model->where($this->model->getPk(),"in",$ids)->delete() ? app("json")->success("操作成功") : app("json")->fail("操作失败");
|
||||
}
|
||||
|
||||
|
|
@ -40,7 +39,6 @@ trait TemplateTrait
|
|||
$ids = $request->param("id",0);
|
||||
if (empty($ids) || !$ids) return app("json")->fail("参数有误,Id为空!");
|
||||
if (!is_array($ids)) $ids = explode(",",$ids);
|
||||
if (in_array(1,$ids)) return app("json")->fail("参数有误,初始ID不允许操作!");
|
||||
return $this->model->where($this->model->getPk(),"in",$ids)->update(['status'=>1]) ? app("json")->success("操作成功") : app("json")->fail("操作失败");
|
||||
}
|
||||
|
||||
|
|
@ -54,7 +52,6 @@ trait TemplateTrait
|
|||
$ids = $request->param("id",0);
|
||||
if (empty($ids) || !$ids) return app("json")->fail("参数有误,Id为空!");
|
||||
if (!is_array($ids)) $ids = explode(",",$ids);
|
||||
if (in_array(1,$ids)) return app("json")->fail("参数有误,初始ID不允许操作!");
|
||||
return $this->model->where($this->model->getPk(),"in",$ids)->update(['status'=>0]) ? app("json")->success("操作成功") : app("json")->fail("操作失败");
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -37,9 +37,12 @@
|
|||
<div class="card">
|
||||
<div class="card-toolbar clearfix">
|
||||
<div class="toolbar-btn-action">
|
||||
<button id="btn_add" type="button" class="btn btn-primary m-r-5" onclick="iframe.createIframe('添加用户','/admin/admin/add')">
|
||||
<button id="btn_add" type="button" class="btn btn-primary m-r-5">
|
||||
<span class="mdi mdi-plus" aria-hidden="true"></span>新增
|
||||
</button>
|
||||
<button id="btn_add_multiple" type="button" class="btn btn-primary m-r-5">
|
||||
<span class="mdi mdi-plus" aria-hidden="true"></span>批量新增
|
||||
</button>
|
||||
<a class="btn btn-warning" href="#!" onclick="delSelect()"><i class="mdi mdi-window-close"></i> 删除</a>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -124,6 +127,103 @@
|
|||
$("#tb_departments").bootstrapTable('refresh',{query:{page:1},pageNumber:1});
|
||||
});
|
||||
|
||||
|
||||
//新增邀请码
|
||||
$('body').on('click','#btn_add',function(){
|
||||
$.confirm({
|
||||
title: '新增邀请码',
|
||||
content: '' +
|
||||
'<form action="" class="formName">' +
|
||||
'<div class="form-group">' +
|
||||
'<input type="text" placeholder="请输入邀请码" name="code" class="name form-control" required />' +
|
||||
'</div>' +
|
||||
'</form>',
|
||||
buttons: {
|
||||
formSubmit: {
|
||||
text: '提交',
|
||||
btnClass: 'btn-primary',
|
||||
action: function () {
|
||||
var name = this.$content.find('.name').val();
|
||||
if(!name){
|
||||
$.alert('请输入邀请码');
|
||||
return false;
|
||||
}
|
||||
$.post(url="/admin/invitation/save",this.$content.find('form').serialize(),function (res) {
|
||||
if (res.code == 200 || res.status == 200) {
|
||||
parent.lightyear.notify('操作成功', 'success', 3000, 'mdi mdi-emoticon-happy', 'top', 'center');
|
||||
$("#tb_departments").bootstrapTable('refresh',{query:{page:1},pageNumber:1});
|
||||
} else{
|
||||
parent.lightyear.notify(res.msg, 'danger', 3000, 'mdi mdi-emoticon-happy', 'top', 'center');
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
cancel: {
|
||||
text: '取消'
|
||||
},
|
||||
},
|
||||
onContentReady: function () {
|
||||
var jc = this;
|
||||
this.$content.find('form').on('submit', function (e) {
|
||||
e.preventDefault();
|
||||
jc.$$formSubmit.trigger('click');
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
//批量新增邀请码
|
||||
$('body').on('click','#btn_add_multiple',function(){
|
||||
$.confirm({
|
||||
title: '新增邀请码',
|
||||
content: '' +
|
||||
'<form action="" class="searchForm">' +
|
||||
' <div class="form-group">\n' +
|
||||
' <label>邀请码前缀</label>\n' +
|
||||
' <input class="form-control" type="text"name="name" placeholder="请输入邀请码前缀">\n' +
|
||||
' </div>\n' +
|
||||
' <div class="form-group">\n' +
|
||||
' <label>生成个数</label>\n' +
|
||||
' <input type="text" class="form-control" name="number" placeholder="请输入要生成的个数" />\n' +
|
||||
' </div>\n' +
|
||||
'</form>',
|
||||
buttons: {
|
||||
formSubmit: {
|
||||
text: '提交',
|
||||
btnClass: 'btn-primary',
|
||||
action: function () {
|
||||
let field = this.$content.find('form').serializeArray();
|
||||
for(j = 0;j < field.length; j++) {
|
||||
if(!field[j].value){
|
||||
$.alert('请检查填写!');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
$.post(url="/admin/invitation/addMultiple",this.$content.find('form').serialize(),function (res) {
|
||||
if (res.code == 200 || res.status == 200) {
|
||||
parent.lightyear.notify('操作成功', 'success', 3000, 'mdi mdi-emoticon-happy', 'top', 'center');
|
||||
$("#tb_departments").bootstrapTable('refresh',{query:{page:1},pageNumber:1});
|
||||
} else{
|
||||
parent.lightyear.notify(res.msg, 'danger', 3000, 'mdi mdi-emoticon-happy', 'top', 'center');
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
cancel: {
|
||||
text: '取消'
|
||||
},
|
||||
},
|
||||
onContentReady: function () {
|
||||
var jc = this;
|
||||
this.$content.find('form').on('submit', function (e) {
|
||||
e.preventDefault();
|
||||
jc.$$formSubmit.trigger('click');
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
function delOne(id) {
|
||||
$.confirm({
|
||||
title: '重要提醒!',
|
||||
|
|
@ -134,7 +234,7 @@
|
|||
text: '确认',
|
||||
btnClass: 'btn-danger',
|
||||
action: function () {
|
||||
$.post("/admin/admin_log/del",data={id:id},function (res) {
|
||||
$.post("/admin/invitation/del",data={id:id},function (res) {
|
||||
if (res.status == 200 || res.code == 200) lightyear.notify(res.msg, 'success', 3000, 'mdi mdi-emoticon-happy', 'top', 'center');
|
||||
else lightyear.notify(res.msg, 'danger', 3000, 'mdi mdi-emoticon-neutral', 'top', 'center');
|
||||
location.reload();
|
||||
|
|
@ -167,7 +267,7 @@
|
|||
text: '确认',
|
||||
btnClass: 'btn-danger',
|
||||
action: function () {
|
||||
$.post("/admin/admin_log/del",data={id:checkID},function (res) {
|
||||
$.post("/admin/invitation/del",data={id:checkID},function (res) {
|
||||
if (res.status == 200 || res.code == 200) { lightyear.notify(res.msg, 'success', 3000, 'mdi mdi-emoticon-happy', 'top', 'center');location.reload();}
|
||||
else lightyear.notify(res.msg, 'danger', 3000, 'mdi mdi-emoticon-neutral', 'top', 'center');
|
||||
})
|
||||
|
|
|
|||
Loading…
Reference in New Issue