TaoLer/app/admin/controller/user/Vip.php

104 lines
2.3 KiB
PHP
Raw Normal View History

2023-03-16 22:40:15 +08:00
<?php
2023-03-16 22:42:05 +08:00
/**
* @Program: TaoLer 2023/3/14
* @FilePath: app\admin\controller\user\Vip.php
* @Description: Vip
* @LastEditTime: 2023-03-14 16:48:31
* @Author: Taoker <317927823@qq.com>
* @Copyright (c) 2020~2023 https://www.aieok.com All rights reserved.
*/
2023-03-16 22:40:15 +08:00
namespace app\admin\controller\user;
use app\common\controller\AdminController;
use think\facade\View;
use think\facade\Request;
use think\facade\Db;
use app\common\model\UserViprule;
class Vip extends AdminController
{
public function index()
{
return View::fetch();
}
2023-03-16 22:42:05 +08:00
// VIP列表
2023-03-16 22:40:15 +08:00
public function list()
{
$keys = UserViprule::select();
$count = $keys->count();
2024-04-01 10:17:53 +08:00
$data = [];
2023-03-16 22:40:15 +08:00
if($count){
foreach($keys as $k=>$v){
2024-04-01 10:17:53 +08:00
$data[] = [
'id'=>$v['id'],
'vip'=>$v['vip'],
'score'=>$v['score'],
'nick'=>$v['nick'],
'postnum'=>$v['postnum'],
'postpoint'=>$v['postpoint'],
'refreshnum'=>$v['refreshnum'],
'refreshpoint'=>$v['refreshpoint'],
'ctime'=>$v['create_time']
];
}
return json(['code'=>0,'msg'=>'ok','count'=>$count, 'data' => $data]);
}
return json(['code'=>-1,'msg'=>'还没有任何vip等级设置']);
2023-03-16 22:40:15 +08:00
}
//添加VIP积分规则
public function add()
{
2024-04-01 10:17:53 +08:00
$data = Request::only(['score','vip','nick','postnum','refreshnum']);
2023-03-16 22:40:15 +08:00
$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);
}
//编辑VIP积分规则
public function edit($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();
}
//删除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'=>'删除失败']);
}
}
}
}