TaoLer/app/admin/controller/Vip.php

81 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\UserViprule;
2021-08-03 17:33:48 +08:00
class Vip extends AdminController
2020-03-29 19:57:18 +08:00
{
2020-03-30 21:11:12 +08:00
//添加VIP积分规则
2020-03-29 19:57:18 +08:00
public function add()
{
$data = Request::only(['score','vip']);
$vip = UserViprule::where('vip',$data['vip'])->find();
if($vip){
$res = ['code'=>-1,'msg'=>'vip等级不能重复设置'];
} else {
$result = UserViprule::create($data);
if($result){
$res = ['code'=>0,'msg'=>'设置vip等级成功'];
} else {
$res = ['code'=>-1,'msg'=>'vip保存失败'];
}
}
return json($res);
}
2020-03-30 21:11:12 +08:00
//删除VIP积分规则
public function delete($id)
{
if(Request::isAjax()){
$user =UserViprule::find($id);
$result = $user->delete();
if($result){
return json(['code'=>0,'msg'=>'删除成功']);
}else{
return json(['code'=>-1,'msg'=>'删除失败']);
}
}
}
//编辑VIP积分规则
public function vipEdit($id)
{
if(Request::isAjax()){
$data = Request::param();
$result = UserViprule::update($data);
if($result){
$res = ['code'=>0,'msg'=>'编辑成功'];
}else{
$res = ['code'=>-1,'msg'=>'编辑失败'];
}
return json($res);
}
$vip = Db::name('user_viprule')->find($id);
$level = UserViprule::column('vip');
View::assign(['vip'=>$vip,'level'=>$level]);
return View::fetch('set/system/vipedit');
}
//显示VIP规则
2020-03-29 19:57:18 +08:00
public function vipRule()
{
$keys = UserViprule::select();
$count = $keys->count();
$res = [];
if($count){
$res = ['code'=>0,'msg'=>'','count'=>$count];
foreach($keys as $k=>$v){
2020-03-30 21:11:12 +08:00
$res['data'][] = ['id'=>$v['id'],'score'=>$v['score'],'nick'=>$v['nick'],'vip'=>$v['vip'],'ctime'=>$v['create_time']];
2020-03-29 19:57:18 +08:00
}
} else {
$res = ['code'=>-1,'msg'=>'还没有任何vip等级设置'];
}
return json($res);
}
}