first commit
This commit is contained in:
209
app/adminapi/logic/member/UserMemberLogic.php
Normal file
209
app/adminapi/logic/member/UserMemberLogic.php
Normal file
@@ -0,0 +1,209 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeadmin快速开发前后端分离管理后台(PHP版)
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
|
||||
// | github下载:https://github.com/likeshop-github/likeadmin
|
||||
// | 访问官网:https://www.likeadmin.cn
|
||||
// | likeadmin团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeadminTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\adminapi\logic\member;
|
||||
|
||||
|
||||
use app\common\model\member\{UserMember,UserMemberRecord};
|
||||
use app\common\logic\BaseLogic;
|
||||
use think\facade\Db;
|
||||
use app\common\service\FileService;
|
||||
use app\common\model\user\{User};
|
||||
|
||||
|
||||
/**
|
||||
* 会员等级逻辑
|
||||
* Class UserMemberLogic
|
||||
* @package app\adminapi\logic\member
|
||||
*/
|
||||
class UserMemberLogic extends BaseLogic
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @notes 添加会员等级
|
||||
* @param array $params
|
||||
* @return bool
|
||||
* @author BD
|
||||
* @date 2024/03/14 00:28
|
||||
*/
|
||||
public static function add(array $params): bool
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
UserMember::create([
|
||||
'name' => $params['name'],
|
||||
'logo' => $params['logo'] ? FileService::setFileUrl($params['logo']) : '',
|
||||
'bg_img' => $params['bg_img'] ? FileService::setFileUrl($params['bg_img']) : '',
|
||||
'text_color' => $params['text_color'],
|
||||
'money' => $params['money'],
|
||||
'level1_num' => $params['level1_num'],
|
||||
'level1_vip_id' => $params['level1_vip_id'],
|
||||
'lh_min' => $params['lh_min'],
|
||||
'lh_max' => $params['lh_max'],
|
||||
'rate_min' => $params['rate_min'],
|
||||
'rate_max' => $params['rate_max'],
|
||||
'item_add_rate' => $params['item_add_rate'],
|
||||
'lh_num' => $params['lh_num'],
|
||||
'item_num' => $params['item_num'],
|
||||
'is_show' => $params['is_show'],
|
||||
]);
|
||||
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 编辑会员等级
|
||||
* @param array $params
|
||||
* @return bool
|
||||
* @author BD
|
||||
* @date 2024/03/14 00:28
|
||||
*/
|
||||
public static function edit(array $params): bool
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
//会员次数
|
||||
if($params['is_show'] == 0){
|
||||
$count = UserMemberRecord::where(['member_id' => $params['id']])->count();
|
||||
if($count > 0){
|
||||
throw new \Exception('该会员等级下存在用户,不可隐藏');
|
||||
}
|
||||
}
|
||||
|
||||
UserMember::where('id', $params['id'])->update([
|
||||
'name' => $params['name'],
|
||||
'logo' => $params['logo'] ? FileService::setFileUrl($params['logo']) : '',
|
||||
'bg_img' => $params['bg_img'] ? FileService::setFileUrl($params['bg_img']) : '',
|
||||
'text_color' => $params['text_color'],
|
||||
'money' => $params['money'],
|
||||
'level1_num' => $params['level1_num'],
|
||||
'level1_vip_id' => $params['level1_vip_id'],
|
||||
'lh_min' => $params['lh_min'],
|
||||
'lh_max' => $params['lh_max'],
|
||||
'rate_min' => $params['rate_min'],
|
||||
'rate_max' => $params['rate_max'],
|
||||
'item_add_rate' => $params['item_add_rate'],
|
||||
'lh_num' => $params['lh_num'],
|
||||
'item_num' => $params['item_num'],
|
||||
'is_show' => $params['is_show'],
|
||||
]);
|
||||
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 删除会员等级
|
||||
* @param array $params
|
||||
* @return bool
|
||||
* @author BD
|
||||
* @date 2024/03/14 00:28
|
||||
*/
|
||||
public static function delete(array $params): bool
|
||||
{
|
||||
return UserMember::destroy($params['id']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取会员等级详情
|
||||
* @param $params
|
||||
* @return array
|
||||
* @author BD
|
||||
* @date 2024/03/14 00:28
|
||||
*/
|
||||
public static function detail($params): array
|
||||
{
|
||||
return UserMember::findOrEmpty($params['id'])->toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 设置用户会员等级
|
||||
* @param array $params
|
||||
* @return bool
|
||||
* @author BD
|
||||
* @date 2024/03/19 02:29
|
||||
*/
|
||||
public static function setUserMember(array $params): bool
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
$user = User::where(['id' => $params['user_id']])->findOrEmpty();
|
||||
|
||||
if ($user->isEmpty()) {
|
||||
throw new \Exception('用户不存在');
|
||||
}
|
||||
$member = UserMember::where(['id' => $params['member_id']])->findOrEmpty();
|
||||
if ($member->isEmpty()) {
|
||||
throw new \Exception('会员等级不存在');
|
||||
}
|
||||
$data = [
|
||||
'user_id' => $params['user_id'],
|
||||
'member_id' => $params['member_id'],
|
||||
];
|
||||
|
||||
//查询用户会员等级
|
||||
$record = UserMemberRecord::where(['user_id' => $params['user_id']])->findOrEmpty();
|
||||
|
||||
if ($record->isEmpty()) {
|
||||
UserMemberRecord::create($data);
|
||||
}else{
|
||||
$data['id'] = $record['id'];
|
||||
UserMemberRecord::update($data);
|
||||
}
|
||||
|
||||
User::where('id',$params['user_id'])->update(['auto_member' => 0]);
|
||||
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 会员等级数据
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author BD
|
||||
* @date 2024/03/11 01:58
|
||||
*/
|
||||
public static function getAllData()
|
||||
{
|
||||
return UserMember::field(['id', 'name', 'logo', 'bg_img', 'text_color', 'money', 'level1_num', 'level1_vip_id', 'item_num', 'item_add_rate'])
|
||||
->append(['vip_name'])
|
||||
->where(['is_show' => 1])
|
||||
->order(['money' => 'desc','id' => 'desc'])
|
||||
->select()
|
||||
->toArray();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user