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

141 lines
3.7 KiB

<?php
namespace app\admin\logic\shop;
use app\common\basics\Logic;
use app\common\model\shop\ShopLevel;
use app\common\model\shop\ShopVip;
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 ShopVipLogic extends Logic
{
public static function lists($get)
{
$count = ShopVip::where(['del'=>0])->count();
$lists = ShopVip::where(['del'=>0])->order('id', 'desc')->page($get['page'], $get['limit'])->select()->toArray();
return ['count' => $count, 'lists' => $lists];
}
public static function add($post)
{
try{
$userLevel = ShopVip::where(['name'=>trim($post['name']), 'del'=>0])->findOrEmpty();
if(!$userLevel->isEmpty()) {
throw new \think\Exception('等级名称已被使用,请更换后重试');
}
$time = time();
$data = [
'name' => trim($post['name']),
'create_time' => $time,
'update_time' => $time,
'del' => 0
];
ShopVip::create($data);
return true;
}catch(\Exception $e) {
self::$error = $e->getMessage();
return false;
}
}
public static function detail($id)
{
$detail = ShopVip::where(['id'=>$id])->findOrEmpty();
if($detail->isEmpty()) {
return [];
}
$detail = $detail->toArray();
return $detail;
}
public static function edit($post)
{
try{
$userLevel = ShopVip::where([
['name', '=', trim($post['name'])],
['del', '=', 0],
['id', '<>', $post['id']]
])->findOrEmpty();
if(!$userLevel->isEmpty()) {
throw new \think\Exception('名称已被使用,请更换后重试');
}
$time = time();
$data = [
'name' => trim($post['name']),
'update_time' => $time,
'del' => 0
];
ShopLevel::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()
];
ShopVip::update($data);
return true;
}catch(\Exception $e) {
self::$error = $e->getMessage();
return false;
}
}
/**
* @Notes: 隐藏
* @Author: 张无忌
* @param $id
* @return bool
*/
public static function hide($id)
{
try {
$model = new ShopVip();
$category = $model->findOrEmpty($id)->toArray();
ShopVip::update([
'is_show' => !$category['is_show'],
'update_time' => time()
], ['id'=>$id]);
return true;
} catch (\Exception $e) {
static::$error = $e->getMessage();
return false;
}
}
/**
* NOTE: 获取主营类目
* @author: 张无忌
* @return array
*/
public static function getCategory()
{
try {
$model = new ShopVip();
return $model->field(true)
->where('del', 0)
->order('id', 'desc')
->select()->toArray();
} catch (\Exception $e) {
return [];
}
}
}