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.
108 lines
3.2 KiB
108 lines
3.2 KiB
<?php
|
|
namespace app\admin\logic\user;
|
|
|
|
use app\common\basics\Logic;
|
|
use app\common\model\user\UserShip;
|
|
use app\common\model\user\UserTag;
|
|
use app\common\model\user\User;
|
|
|
|
class ShipLogic extends Logic
|
|
{
|
|
public static function lists($get)
|
|
{
|
|
$lists = UserShip::where(['del'=>0])->page($get['page'], $get['limit'])->select()->toArray();
|
|
$count = UserShip::where(['del'=>0])->count();
|
|
return [
|
|
'lists' => $lists,
|
|
'count' => $count
|
|
];
|
|
}
|
|
|
|
public static function add($post)
|
|
{
|
|
try{
|
|
// 判断新标签名称是否已被占用
|
|
$userShip = UserShip::where(['type'=>$post['type'], 'del'=>0])->findOrEmpty();
|
|
if(!$userShip->isEmpty()) {
|
|
throw new \think\Exception('该周期类型已经使用!!');
|
|
}
|
|
$time = time();
|
|
$data = [
|
|
'type' => $post['type'],
|
|
'title' => trim($post['title']),
|
|
'vip_day' => $post['vip_day'],
|
|
'price' => $post['price'],
|
|
'pre_price' => $post['pre_price'],
|
|
'sort' => $post['sort'],
|
|
'create_time' => $time,
|
|
'update_time' => $time,
|
|
'del' => 0
|
|
];
|
|
UserShip::create($data);
|
|
return true;
|
|
}catch(\Exception $e) {
|
|
self::$error = $e->getMessage();
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public static function detail($id)
|
|
{
|
|
$userShip = UserShip::where(['id'=>$id])->findOrEmpty();
|
|
if($userShip->isEmpty()) {
|
|
return [];
|
|
}
|
|
return $userShip->toArray();
|
|
}
|
|
|
|
public static function edit($post)
|
|
{
|
|
try{
|
|
$userShip = UserShip::where([
|
|
['type', '=', trim($post['type'])],
|
|
['id', '<>', trim($post['id'])],
|
|
])->findOrEmpty();
|
|
if(!$userShip->isEmpty()){
|
|
throw new \think\Exception('该周期类型已经使用!!');
|
|
}
|
|
$data = [
|
|
'id' => $post['id'],
|
|
'type' => $post['type'],
|
|
'title' => trim($post['title']),
|
|
'vip_day' => $post['vip_day'],
|
|
'price' => $post['price'],
|
|
'pre_price' => $post['pre_price'],
|
|
'sort' => $post['sort'],
|
|
'update_time' => time(),
|
|
'del' => 0
|
|
];
|
|
UserShip::update($data);
|
|
return true;
|
|
}catch(\Exception $e) {
|
|
self::$error = $e->getMessage();
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public static function del($id)
|
|
{
|
|
try{
|
|
// 查看是否有会员是该类型的付费会员,若有则不允许删除
|
|
$users = User::whereFindInSet('ship_id',$id)->where('del',0)->count();
|
|
if($users) {
|
|
throw new \think\Exception('有用户是该类型会员,无法删除');
|
|
}
|
|
$data = [
|
|
'id' => $id,
|
|
'update_time' => time(),
|
|
'del' => 1
|
|
];
|
|
UserShip::update($data);
|
|
return true;
|
|
}catch(\Exception $e){
|
|
self::$error = $e->getMessage();
|
|
return false;
|
|
}
|
|
}
|
|
|
|
}
|