- 在DeviceManager中添加GetOnlineDeviceCount方法用于获取在线设备数 - 在统计接口中增加在线设备数返回 - 优化订阅查询逻辑,增加服务组关联节点数量计算 - 添加AnyTLS协议支持及相关URI生成功能 - 重构邀请佣金计算逻辑,支持首购/年付/非首购不同比例 - 修复用户基本信息更新中IsAdmin和Enable字段类型不匹配问题 - 更新数据库迁移脚本和配置文件中邀请相关配置项
66 lines
2.1 KiB
Go
66 lines
2.1 KiB
Go
package user
|
||
|
||
import (
|
||
"context"
|
||
"os"
|
||
"strings"
|
||
|
||
"github.com/perfect-panel/server/internal/svc"
|
||
"github.com/perfect-panel/server/internal/types"
|
||
"github.com/perfect-panel/server/pkg/logger"
|
||
"github.com/perfect-panel/server/pkg/tool"
|
||
"github.com/perfect-panel/server/pkg/xerr"
|
||
"github.com/pkg/errors"
|
||
)
|
||
|
||
type UpdateUserBasicInfoLogic struct {
|
||
logger.Logger
|
||
ctx context.Context
|
||
svcCtx *svc.ServiceContext
|
||
}
|
||
|
||
// NewUpdateUserBasicInfoLogic Update user basic info
|
||
func NewUpdateUserBasicInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateUserBasicInfoLogic {
|
||
return &UpdateUserBasicInfoLogic{
|
||
Logger: logger.WithContext(ctx),
|
||
ctx: ctx,
|
||
svcCtx: svcCtx,
|
||
}
|
||
}
|
||
|
||
func (l *UpdateUserBasicInfoLogic) UpdateUserBasicInfo(req *types.UpdateUserBasiceInfoRequest) error {
|
||
userInfo, err := l.svcCtx.UserModel.FindOne(l.ctx, req.UserId)
|
||
if err != nil {
|
||
l.Errorw("[UpdateUserBasicInfoLogic] Find User Error:", logger.Field("err", err.Error()), logger.Field("userId", req.UserId))
|
||
return errors.Wrapf(xerr.NewErrCode(xerr.DatabaseQueryError), "Find User Error")
|
||
}
|
||
|
||
isDemo := strings.ToLower(os.Getenv("PPANEL_MODE")) == "demo"
|
||
|
||
tool.DeepCopy(userInfo, req)
|
||
if req.Avatar != "" && !tool.IsValidImageSize(req.Avatar, 1024) {
|
||
return errors.Wrapf(xerr.NewErrCode(xerr.ERROR), "Invalid Image Size")
|
||
}
|
||
userInfo.Balance = req.Balance
|
||
userInfo.GiftAmount = req.GiftAmount
|
||
userInfo.Commission = req.Commission
|
||
// 手动设置 IsAdmin 字段,因为类型不匹配(*bool vs bool)
|
||
userInfo.IsAdmin = &req.IsAdmin
|
||
userInfo.Enable = &req.Enable
|
||
|
||
if req.Password != "" {
|
||
if userInfo.Id == 2 && isDemo {
|
||
return errors.Wrapf(xerr.NewErrCodeMsg(503, "Demo mode does not allow modification of the admin user password"), "UpdateUserBasicInfo failed: cannot update admin user password in demo mode")
|
||
}
|
||
userInfo.Password = tool.EncodePassWord(req.Password)
|
||
}
|
||
|
||
err = l.svcCtx.UserModel.Update(l.ctx, userInfo)
|
||
if err != nil {
|
||
l.Errorw("[UpdateUserBasicInfoLogic] Update User Error:", logger.Field("err", err.Error()), logger.Field("userId", req.UserId))
|
||
return errors.Wrapf(xerr.NewErrCode(xerr.DatabaseUpdateError), "Update User Error")
|
||
}
|
||
|
||
return nil
|
||
}
|