安徽博创起重服务端程序
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.
 
 
 
 
 

111 lines
3.4 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\server\UrlServer;
use think\facade\Db;
class RightLogic extends Logic
{
public static function lists($get)
{
$count = UserRight::where(['del'=>0])->count();
$lists = UserRight::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 = UserRight::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
];
UserRight::create($data);
return true;
}catch(\Exception $e) {
self::$error = $e->getMessage();
return false;
}
}
public static function detail($id)
{
$detail = UserRight::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 = UserRight::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
];
UserRight::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()
];
UserRight::update($data);
return true;
}catch(\Exception $e) {
self::$error = $e->getMessage();
return false;
}
}
}