TaoLer/app/admin/controller/Sign.php

83 lines
1.9 KiB
PHP
Raw Normal View History

2020-03-29 19:57:18 +08:00
<?php
namespace app\admin\controller;
2021-08-03 17:33:48 +08:00
use app\common\controller\AdminController;
2020-03-29 19:57:18 +08:00
use think\facade\View;
use think\facade\Request;
use think\facade\Db;
use app\common\model\UserSignrule;
2021-08-03 17:33:48 +08:00
class Sign extends AdminController
2020-03-29 19:57:18 +08:00
{
2020-03-30 21:11:12 +08:00
//添加签到积分规则
2020-03-29 19:57:18 +08:00
public function add()
{
2021-10-12 16:50:02 +08:00
if(Request::isPost()){
$data = Request::only(['days','score']);
$day = UserSignrule::where('days',(int)$data['days'])->find();
//$day = Db::name('user_signrule')->where('days',$data['days'])->find();
if(!is_null($day)){
$res = ['code'=>-1,'msg'=>'不能重复设置'];
2020-03-29 19:57:18 +08:00
} else {
2021-10-12 16:50:02 +08:00
$result = UserSignrule::create($data);
if($result){
$res = ['code'=>0,'msg'=>'设置积分成功'];
} else {
$res = ['code'=>-1,'msg'=>'保存失败'];
}
2020-03-29 19:57:18 +08:00
}
2021-10-12 16:50:02 +08:00
return json($res);
2020-03-29 19:57:18 +08:00
}
}
2020-03-30 21:11:12 +08:00
//删除签到积分规则
public function delete($id)
{
if(Request::isAjax()){
$user =UserSignrule::find($id);
$result = $user->delete();
if($result){
return json(['code'=>0,'msg'=>'删除成功']);
}else{
return json(['code'=>-1,'msg'=>'删除失败']);
}
}
}
//编辑签到积分规则
public function signEdit()
{
if(Request::isAjax()){
$data = Request::param();
$result = UserSignrule::update($data);
if($result){
$res = ['code'=>0,'msg'=>'编辑成功'];
}else{
$res = ['code'=>-1,'msg'=>'编辑失败'];
}
return json($res);
}
$sign = Db::name('user_signrule')->find(input('id'));
View::assign('sign',$sign);
return View::fetch('set/system/signedit');
}
//显示签到积分规则
2020-03-29 19:57:18 +08:00
public function signRule()
{
$keys = UserSignrule::select();
$count = $keys->count();
$res = [];
if($count){
$res = ['code'=>0,'msg'=>'','count'=>$count];
foreach($keys as $k=>$v){
$res['data'][] = ['id'=>$v['id'],'days'=>$v['days'],'score'=>$v['score'],'ctime'=>$v['create_time']];
}
} else {
$res = ['code'=>-1,'msg'=>'还没有任何积分设置!'];
}
return json($res);
}
}