fix promotion
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
"tyc-server/app/main/api/internal/service"
|
||||
"tyc-server/app/main/api/internal/svc"
|
||||
"tyc-server/app/main/api/internal/types"
|
||||
"tyc-server/app/main/model"
|
||||
"tyc-server/common/ctxdata"
|
||||
"tyc-server/common/xerr"
|
||||
|
||||
@@ -70,6 +71,26 @@ func (l *PaymentLogic) Payment(req *types.PaymentReq) (resp *types.PaymentResp,
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "生成订单失败: %+v", err)
|
||||
}
|
||||
|
||||
promoteKey, ok := l.ctx.Value("promoteKey").(string)
|
||||
if ok && promoteKey != "" {
|
||||
url := fmt.Sprintf("%s/%s", l.svcCtx.Config.AdminPromotion.URLDomain, promoteKey)
|
||||
promoteLink, err := l.svcCtx.AdminPromotionLinkModel.FindOneByUrl(l.ctx, url)
|
||||
if err != nil && !errors.Is(err, model.ErrNotFound) {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "生成订单, 查找推广链接失败: %+v", err)
|
||||
}
|
||||
if promoteLink != nil {
|
||||
promoteOrder := &model.AdminPromotionOrder{
|
||||
OrderId: orderResp.OrderID,
|
||||
LinkId: promoteLink.Id,
|
||||
UserId: userID,
|
||||
AdminUserId: promoteLink.AdminUserId,
|
||||
}
|
||||
_, insertPromoteOrderErr := l.svcCtx.AdminPromotionOrderModel.Insert(l.ctx, nil, promoteOrder)
|
||||
if insertPromoteOrderErr != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "生成订单, 保存推广订单失败: %+v", insertPromoteOrderErr)
|
||||
}
|
||||
}
|
||||
}
|
||||
return &types.PaymentResp{
|
||||
PrepayData: orderResp.PayData,
|
||||
PrepayId: orderResp.OrderNo,
|
||||
|
||||
@@ -366,7 +366,7 @@ func (p *PayService) Refund(ctx context.Context, req *RefundRequest) (*RefundRes
|
||||
refundAmount: resp.RefundAmount,
|
||||
platformRefundId: sql.NullString{String: resp.RefundID, Valid: true},
|
||||
}
|
||||
order.Status = model.OrderRefundStatusSuccess
|
||||
order.Status = model.OrderStatusRefund
|
||||
default:
|
||||
return fmt.Errorf("不支持的支付平台退款: %s", order.PaymentPlatform)
|
||||
}
|
||||
@@ -389,7 +389,7 @@ func (p *PayService) Refund(ctx context.Context, req *RefundRequest) (*RefundRes
|
||||
}
|
||||
|
||||
// 更新订单状态
|
||||
order.Status = model.OrderStatusRefunding
|
||||
order.Status = model.OrderStatusRefund
|
||||
order.RefundTime = sql.NullTime{Time: result.refundTime, Valid: !result.refundTime.IsZero()}
|
||||
if _, err := p.orderModel.Update(ctx, session, order); err != nil {
|
||||
return fmt.Errorf("更新订单状态失败: %v", err)
|
||||
|
||||
Reference in New Issue
Block a user