46 lines
1.0 KiB
PHP
46 lines
1.0 KiB
PHP
|
<?php
|
|||
|
namespace app\admin\controller;
|
|||
|
|
|||
|
use app\common\controller\BaseController;
|
|||
|
use think\facade\View;
|
|||
|
use think\facade\Request;
|
|||
|
use think\facade\Db;
|
|||
|
use app\common\model\UserViprule;
|
|||
|
|
|||
|
class Vip extends BaseController
|
|||
|
{
|
|||
|
|
|||
|
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);
|
|||
|
}
|
|||
|
|
|||
|
public function vipRule()
|
|||
|
{
|
|||
|
$keys = UserViprule::select();
|
|||
|
$count = $keys->count();
|
|||
|
$res = [];
|
|||
|
if($count){
|
|||
|
$res = ['code'=>0,'msg'=>'','count'=>$count];
|
|||
|
foreach($keys as $k=>$v){
|
|||
|
$res['data'][] = ['id'=>$v['id'],'score'=>$v['score'],'vip'=>$v['vip'],'ctime'=>$v['create_time']];
|
|||
|
}
|
|||
|
} else {
|
|||
|
$res = ['code'=>-1,'msg'=>'还没有任何vip等级设置!'];
|
|||
|
}
|
|||
|
return json($res);
|
|||
|
}
|
|||
|
|
|||
|
}
|