98 lines
2.1 KiB
PHP
98 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace app\admin\logic\user_ship;
|
|
|
|
|
|
use app\common\model\user_ship\UserShip;
|
|
use app\common\logic\BaseLogic;
|
|
use think\facade\Db;
|
|
|
|
|
|
/**
|
|
* 会员类型逻辑
|
|
* Class UserShipLogic
|
|
* @package app\admin\logic\user_ship
|
|
*/
|
|
class UserShipLogic extends BaseLogic
|
|
{
|
|
|
|
|
|
/**
|
|
* @notes 添加会员类型
|
|
* @param array $params
|
|
* @return bool
|
|
* @author admin
|
|
* @date 2024/06/29 14:18
|
|
*/
|
|
public static function add(array $params): bool
|
|
{
|
|
Db::startTrans();
|
|
try {
|
|
UserShip::create([
|
|
'title' => $params['title'],
|
|
'limit' => $params['limit'],
|
|
'sort' => $params['sort']
|
|
]);
|
|
|
|
Db::commit();
|
|
return true;
|
|
} catch (\Exception $e) {
|
|
Db::rollback();
|
|
self::setError($e->getMessage());
|
|
return false;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
* @notes 编辑会员类型
|
|
* @param array $params
|
|
* @return bool
|
|
* @author admin
|
|
* @date 2024/06/29 14:18
|
|
*/
|
|
public static function edit(array $params): bool
|
|
{
|
|
Db::startTrans();
|
|
try {
|
|
UserShip::where('id', $params['id'])->update([
|
|
'title' => $params['title'],
|
|
'limit' => $params['limit'],
|
|
'sort' => $params['sort']
|
|
]);
|
|
|
|
Db::commit();
|
|
return true;
|
|
} catch (\Exception $e) {
|
|
Db::rollback();
|
|
self::setError($e->getMessage());
|
|
return false;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
* @notes 删除会员类型
|
|
* @param array $params
|
|
* @return bool
|
|
* @author admin
|
|
* @date 2024/06/29 14:18
|
|
*/
|
|
public static function delete(array $params): bool
|
|
{
|
|
return UserShip::destroy($params['id']);
|
|
}
|
|
|
|
|
|
/**
|
|
* @notes 获取会员类型详情
|
|
* @param $params
|
|
* @return array
|
|
* @author admin
|
|
* @date 2024/06/29 14:18
|
|
*/
|
|
public static function detail($params): array
|
|
{
|
|
return UserShip::findOrEmpty($params['id'])->toArray();
|
|
}
|
|
} |