This commit is contained in:
2026-05-13 14:43:10 +08:00
parent 2312f54e1e
commit 3399de0dc5
49 changed files with 1637 additions and 287 deletions

View File

@@ -15,6 +15,7 @@ import (
"qnc-server/common/tool"
"qnc-server/common/xerr"
"qnc-server/pkg/lzkit/crypto"
"qnc-server/pkg/lzkit/lzUtils"
"github.com/Masterminds/squirrel"
"github.com/pkg/errors"
@@ -41,6 +42,12 @@ func NewGeneratingLinkLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Ge
}
func (l *GeneratingLinkLogic) GeneratingLink(req *types.AgentGeneratingLinkReq) (resp *types.AgentGeneratingLinkResp, err error) {
// 将 set_price 从 string 转为 float64
setPrice, err := strconv.ParseFloat(req.SetPrice, 64)
if err != nil {
return nil, errors.Wrapf(xerr.NewErrMsg("设定价格格式不正确"), "")
}
userID, err := ctxdata.GetUidFromCtx(l.ctx)
if err != nil {
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "生成推广链接失败, %v", err)
@@ -71,14 +78,14 @@ func (l *GeneratingLinkLogic) GeneratingLink(req *types.AgentGeneratingLinkReq)
}
basePrice := productConfig.BasePrice
actualBasePrice := basePrice + float64(levelBonus)
actualBasePrice := lzUtils.RoundMoney(basePrice + float64(levelBonus))
systemMaxPrice := productConfig.SystemMaxPrice
upliftAmount, err := l.getLevelMaxUpliftAmount(agentModel.Level)
if err != nil {
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "获取等级上调金额失败, %v", err)
}
levelMaxPrice := systemMaxPrice + upliftAmount
if req.SetPrice < actualBasePrice || req.SetPrice > levelMaxPrice {
levelMaxPrice := lzUtils.RoundMoney(systemMaxPrice + upliftAmount)
if setPrice < actualBasePrice || setPrice > levelMaxPrice {
return nil, errors.Wrapf(xerr.NewErrMsg("设定价格必须在 %.2f 到 %.2f 之间"), "设定价格必须在 %.2f 到 %.2f 之间", actualBasePrice, levelMaxPrice)
}
@@ -86,7 +93,7 @@ func (l *GeneratingLinkLogic) GeneratingLink(req *types.AgentGeneratingLinkReq)
builder := l.svcCtx.AgentLinkModel.SelectBuilder().Where(squirrel.And{
squirrel.Eq{"agent_id": agentModel.Id},
squirrel.Eq{"product_id": req.ProductId},
squirrel.Eq{"set_price": req.SetPrice},
squirrel.Eq{"set_price": setPrice},
squirrel.Eq{"del_state": globalkey.DelStateNo},
})
@@ -115,7 +122,7 @@ func (l *GeneratingLinkLogic) GeneratingLink(req *types.AgentGeneratingLinkReq)
var agentIdentifier types.AgentIdentifier
agentIdentifier.AgentID = agentModel.Id
agentIdentifier.ProductID = req.ProductId
agentIdentifier.SetPrice = req.SetPrice
agentIdentifier.SetPrice = setPrice
agentIdentifierByte, err := json.Marshal(agentIdentifier)
if err != nil {
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "序列化标识失败, %v", err)
@@ -140,7 +147,7 @@ func (l *GeneratingLinkLogic) GeneratingLink(req *types.AgentGeneratingLinkReq)
UserId: userID,
ProductId: req.ProductId,
LinkIdentifier: encrypted,
SetPrice: req.SetPrice,
SetPrice: setPrice,
ActualBasePrice: actualBasePrice,
}