You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
112 lines
3.5 KiB
112 lines
3.5 KiB
<?php
|
|
namespace app\admin\logic\user;
|
|
|
|
use app\common\basics\Logic;
|
|
use app\common\model\user\User;
|
|
use app\common\model\user\UserLevel;
|
|
use app\common\model\user\UserRight;
|
|
use app\common\model\user\UserShip;
|
|
use app\common\model\user\UserSvipRight;
|
|
use app\common\server\UrlServer;
|
|
use think\facade\Db;
|
|
|
|
class SvipRightLogic extends Logic
|
|
{
|
|
public static function lists($get)
|
|
{
|
|
$count = UserSvipRight::where(['del'=>0])->count();
|
|
$lists = UserSvipRight::where(['del'=>0])->order('sort', 'desc')->page($get['page'], $get['limit'])->select()->toArray();
|
|
|
|
foreach ($lists as &$item){
|
|
$item['image'] = UrlServer::getFileUrl($item['image']);
|
|
}
|
|
return ['count' => $count, 'lists' => $lists];
|
|
}
|
|
|
|
public static function add($post)
|
|
{
|
|
try{
|
|
$userLevel = UserSvipRight::where(['title'=>trim($post['title']), 'del'=>0])->findOrEmpty();
|
|
if(!$userLevel->isEmpty()) {
|
|
throw new \think\Exception('权益名称已被使用,请更换后重试');
|
|
}
|
|
$time = time();
|
|
$data = [
|
|
'title' => trim($post['title']),
|
|
'show_title' => trim($post['show_title']),
|
|
'image' => clearDomain($post['image']),
|
|
'explain' => trim($post['explain']),
|
|
// 'number' => trim($post['number']),
|
|
'sort' => $post['sort'],
|
|
'create_time' => $time,
|
|
'update_time' => $time,
|
|
'del' => 0
|
|
];
|
|
UserSvipRight::create($data);
|
|
return true;
|
|
}catch(\Exception $e) {
|
|
self::$error = $e->getMessage();
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public static function detail($id)
|
|
{
|
|
$detail = UserSvipRight::where(['id'=>$id])->findOrEmpty();
|
|
if($detail->isEmpty()) {
|
|
return [];
|
|
}
|
|
$detail = $detail->toArray();
|
|
$detail['image'] = UrlServer::getFileUrl($detail['image']);
|
|
return $detail;
|
|
}
|
|
|
|
public static function edit($post)
|
|
{
|
|
try{
|
|
$userLevel = UserSvipRight::where([
|
|
['title', '=', trim($post['title'])],
|
|
['del', '=', 0],
|
|
['id', '<>', $post['id']]
|
|
])->findOrEmpty();
|
|
if(!$userLevel->isEmpty()) {
|
|
throw new \think\Exception('权益名称已被使用,请更换后重试');
|
|
}
|
|
$time = time();
|
|
$data = [
|
|
'id' => $post['id'],
|
|
'title' => trim($post['title']),
|
|
'show_title' => trim($post['show_title']),
|
|
'image' => clearDomain($post['image']),
|
|
'explain' => trim($post['explain']),
|
|
// 'number' => trim($post['number']),
|
|
'sort' => $post['sort'],
|
|
'create_time' => $time,
|
|
'update_time' => $time,
|
|
'del' => 0
|
|
];
|
|
UserSvipRight::update($data);
|
|
return true;
|
|
}catch(\Exception $e) {
|
|
self::$error = $e->getMessage();
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public static function del($id)
|
|
{
|
|
try{
|
|
$data = [
|
|
'id' => $id,
|
|
'del' => 1,
|
|
'update_time' => time()
|
|
];
|
|
UserSvipRight::update($data);
|
|
return true;
|
|
}catch(\Exception $e) {
|
|
self::$error = $e->getMessage();
|
|
return false;
|
|
}
|
|
}
|
|
|
|
}
|
|
|