Files
zzp-server/app/api/logic/UserMemberLogic.php
2026-01-19 14:19:22 +08:00

137 lines
4.4 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?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\api\logic;
use app\common\logic\BaseLogic;
use app\common\model\member\{UserMember,UserMemberRecord};
use app\common\model\user\{User,UserRelation};
use app\common\model\item\{ItemRecord};
use app\common\service\{ConfigService,UtilsService};
use think\facade\{Db};
/**
* 会员逻辑
* Class UserMemberLogic
* @package app\api\logic
*/
class UserMemberLogic extends BaseLogic
{
/**
* @notes 首页数据
* @param $params
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author BD
* @date 2023/9/21 19:15
*/
public static function getIndexData(array $params)
{
$user['total_invest'] = ItemRecord::where(['user_id' => $params['user_id']])->sum('money');
$user['invite_count'] = UserRelation::where(['parent_id' => $params['user_id'],'level' => 1])->count();
//查询会员等级
$member_id = UtilsService::get_user_member_id($params['user_id']);
$userMember = UserMember::field('id,name')
->where(['id' => $member_id])
->where(['is_show' => 1])
->findOrEmpty();
return [
'user' => $user,
'member' => $userMember,
];
}
/**
* @notes 会员列表
* @param $params
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author BD
* @date 2024/02/22 10:54
*/
public static function getAllData(array $params)
{
$field = ['id, name as text, logo, bg_img as image, text_color, money, level1_num,level1_vip_id, item_num, item_add_rate,mine_speed'];
$members = UserMember::field($field)
->append(['vip_name'])
->where(['is_show' => 1])
->order(['money' => 'asc', 'id' => 'desc'])
->select()
->toArray();
$config_mine = ConfigService::get('website', 'mine');
foreach ($members as &$member) {
$member['mine_speed'] = $member['mine_speed'].' '.$config_mine['symbol'].' / H';
}
return $members;
}
/**
* @notes 加入会员
* @param $params
* @return array|false
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author BD
* @date 2024/02/22 10:54
*/
public static function join(array $params)
{
Db::startTrans();
try {
//判断会员等级是否存在
$member = UserMember::where(['id' => $params['id']])->findOrEmpty();
$data = [
'user_id' => $params['user_id'],
'member_id' => $member['id'],
];
$record = UserMemberRecord::create($data);
//记录日志
UtilsService::user_finance_add(
$data['user_id'],
10,
2,
$member['price'],
''
);
//用户资金修改
UtilsService::user_money_change($data['user_id'], 2, $member['price'],'user_money');
Db::commit();
return [
'order_id' => $record['id'],
];
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
}