f
This commit is contained in:
@@ -76,6 +76,12 @@ func (l *PaymentLogic) Payment(req *types.PaymentReq) (resp *types.PaymentResp,
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
case "whitelist":
|
||||
paymentTypeResp, err = l.WhitelistOrderPayment(req, session)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// 开发环境测试支付模式:跳过实际支付流程
|
||||
@@ -462,6 +468,67 @@ func (l *PaymentLogic) AgentUpgradeOrderPayment(req *types.PaymentReq, session s
|
||||
}, nil
|
||||
}
|
||||
|
||||
// WhitelistOrderPayment 白名单下架订单支付(id 格式:id_card|feature_api_id)
|
||||
func (l *PaymentLogic) WhitelistOrderPayment(req *types.PaymentReq, session sqlx.Session) (resp *PaymentTypeResp, err error) {
|
||||
userID, err := ctxdata.GetUidFromCtx(l.ctx)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "获取用户信息失败, %v", err)
|
||||
}
|
||||
parts := strings.SplitN(req.Id, "|", 2)
|
||||
if len(parts) != 2 || parts[0] == "" || parts[1] == "" {
|
||||
return nil, errors.Wrapf(xerr.NewErrMsg("白名单支付参数无效,id 格式应为 id_card|feature_api_id"), "")
|
||||
}
|
||||
idCard := parts[0]
|
||||
featureApiId := parts[1]
|
||||
feature, err := l.svcCtx.FeatureModel.FindOneByApiId(l.ctx, featureApiId)
|
||||
if err != nil {
|
||||
if errors.Is(err, model.ErrNotFound) {
|
||||
return nil, errors.Wrapf(xerr.NewErrMsg("模块不存在"), "")
|
||||
}
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "查询模块失败: %v", err)
|
||||
}
|
||||
if feature.WhitelistPrice <= 0 {
|
||||
return nil, errors.Wrapf(xerr.NewErrMsg("该模块不支持付费下架"), "")
|
||||
}
|
||||
base := l.svcCtx.AlipayService.GenerateOutTradeNo()
|
||||
outTradeNo := "W_" + base
|
||||
if len(outTradeNo) > 32 {
|
||||
outTradeNo = outTradeNo[:32]
|
||||
}
|
||||
amount := feature.WhitelistPrice
|
||||
wo := &model.WhitelistOrder{
|
||||
Id: uuid.NewString(),
|
||||
OrderNo: outTradeNo,
|
||||
UserId: userID,
|
||||
IdCard: idCard,
|
||||
TotalAmount: amount,
|
||||
Status: 1,
|
||||
}
|
||||
_, err = l.svcCtx.WhitelistOrderModel.Insert(l.ctx, session, wo)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "创建白名单订单失败: %v", err)
|
||||
}
|
||||
item := &model.WhitelistOrderItem{
|
||||
Id: uuid.NewString(),
|
||||
OrderId: wo.Id,
|
||||
FeatureId: feature.Id,
|
||||
FeatureApiId: feature.ApiId,
|
||||
FeatureName: feature.Name,
|
||||
Price: amount,
|
||||
}
|
||||
_, err = l.svcCtx.WhitelistOrderItemModel.Insert(l.ctx, session, item)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "创建白名单订单明细失败: %v", err)
|
||||
}
|
||||
description := fmt.Sprintf("%s 模块下架", feature.Name)
|
||||
return &PaymentTypeResp{
|
||||
amount: amount,
|
||||
outTradeNo: outTradeNo,
|
||||
description: description,
|
||||
orderID: wo.Id,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// getLevelBonus 获取等级加成(从配置表读取)
|
||||
func (l *PaymentLogic) getLevelBonus(level int64) (int64, error) {
|
||||
var configKey string
|
||||
|
||||
Reference in New Issue
Block a user