fix promotion
This commit is contained in:
parent
c062908aae
commit
9aa6913883
@ -143,7 +143,26 @@ func (l *PaymentLogic) QueryOrderPayment(req *types.PaymentReq, session sqlx.Ses
|
|||||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "生成订单, 获取保存订单ID失败: %+v", lastInsertIdErr)
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "生成订单, 获取保存订单ID失败: %+v", lastInsertIdErr)
|
||||||
}
|
}
|
||||||
orderID = insertedOrderID
|
orderID = insertedOrderID
|
||||||
|
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: 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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
if data.AgentIdentifier != "" {
|
if data.AgentIdentifier != "" {
|
||||||
agent, parsingErr := l.agentParsing(data.AgentIdentifier)
|
agent, parsingErr := l.agentParsing(data.AgentIdentifier)
|
||||||
if parsingErr != nil {
|
if parsingErr != nil {
|
||||||
|
@ -7,19 +7,22 @@ import (
|
|||||||
|
|
||||||
const (
|
const (
|
||||||
PlatformKey = "X-Platform"
|
PlatformKey = "X-Platform"
|
||||||
|
PromoteKey = "X-Promote-Key"
|
||||||
)
|
)
|
||||||
|
|
||||||
func GlobalSourceInterceptor(next http.HandlerFunc) http.HandlerFunc {
|
func GlobalSourceInterceptor(next http.HandlerFunc) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
// 获取请求头 X-Platform 的值
|
// 获取请求头 X-Platform 的值
|
||||||
platform := r.Header.Get(PlatformKey)
|
platform := r.Header.Get(PlatformKey)
|
||||||
|
promoteValue := r.Header.Get(PromoteKey)
|
||||||
// 将值放入新的 context 中
|
// 将值放入新的 context 中
|
||||||
ctx := r.Context()
|
ctx := r.Context()
|
||||||
if platform != "" {
|
if platform != "" {
|
||||||
ctx = context.WithValue(ctx, "platform", platform)
|
ctx = context.WithValue(ctx, "platform", platform)
|
||||||
}
|
}
|
||||||
|
if promoteValue != "" {
|
||||||
|
ctx = context.WithValue(ctx, "promoteKey", promoteValue)
|
||||||
|
}
|
||||||
// 通过 r.WithContext 将更新后的 ctx 传递给后续的处理函数
|
// 通过 r.WithContext 将更新后的 ctx 传递给后续的处理函数
|
||||||
r = r.WithContext(ctx)
|
r = r.WithContext(ctx)
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@ import (
|
|||||||
"database/sql"
|
"database/sql"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"regexp"
|
"regexp"
|
||||||
@ -139,7 +140,10 @@ func (l *PaySuccessNotifyUserHandler) ProcessTask(ctx context.Context, t *asynq.
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return l.handleError(ctx, err, order, query)
|
return l.handleError(ctx, err, order, query)
|
||||||
}
|
}
|
||||||
|
err = l.promotionOrderStats(ctx, order)
|
||||||
|
if err != nil {
|
||||||
|
logx.Errorf("处理推广订单统计失败,订单ID: %d, 错误: %v", order.Id, err)
|
||||||
|
}
|
||||||
_, delErr := l.svcCtx.Redis.DelCtx(ctx, redisKey)
|
_, delErr := l.svcCtx.Redis.DelCtx(ctx, redisKey)
|
||||||
if delErr != nil {
|
if delErr != nil {
|
||||||
logx.Errorf("删除Redis缓存失败,但任务已成功处理,订单ID: %d, 错误: %v", order.Id, delErr)
|
logx.Errorf("删除Redis缓存失败,但任务已成功处理,订单ID: %d, 错误: %v", order.Id, delErr)
|
||||||
@ -296,6 +300,21 @@ func (l *PaySuccessNotifyUserHandler) createNullString(value string) sql.NullStr
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 处理推广订单统计
|
||||||
|
func (l *PaySuccessNotifyUserHandler) promotionOrderStats(ctx context.Context, order *model.Order) error {
|
||||||
|
promotionOrder, err := l.svcCtx.AdminPromotionOrderModel.FindOneByOrderId(ctx, order.Id)
|
||||||
|
if err != nil && !errors.Is(err, model.ErrNotFound) {
|
||||||
|
return fmt.Errorf("获取推广订单失败: %+v", err)
|
||||||
|
}
|
||||||
|
if promotionOrder != nil {
|
||||||
|
err = l.svcCtx.AdminPromotionLinkStatsService.UpdatePaymentStats(ctx, promotionOrder.LinkId, float64(order.Amount))
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("更新推广链接支付统计失败: %+v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// desensitizeParams 对敏感数据进行脱敏处理
|
// desensitizeParams 对敏感数据进行脱敏处理
|
||||||
func (l *PaySuccessNotifyUserHandler) desensitizeParams(data []byte) ([]byte, error) {
|
func (l *PaySuccessNotifyUserHandler) desensitizeParams(data []byte) ([]byte, error) {
|
||||||
// 解析JSON数据到map
|
// 解析JSON数据到map
|
||||||
|
Loading…
Reference in New Issue
Block a user