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