启用微信支付逻辑;调整支付金额处理方式以支持调试模式

This commit is contained in:
2025-05-09 16:37:53 +08:00
parent 189f523693
commit d5a242d6b4
7 changed files with 21 additions and 23 deletions

View File

@@ -49,7 +49,7 @@ type ResourceInfo struct {
// region RemoveChannel
func (s *channelService) RemoveChannels(ctx context.Context, authCtx *auth.Context, id ...int32) error {
var step = time.Now()
var now = time.Now()
var rid = ctx.Value(requestid.ConfigDefault.ContextKey).(string)
err := q.Q.Transaction(func(tx *q.Query) error {
@@ -62,8 +62,6 @@ func (s *channelService) RemoveChannels(ctx context.Context, authCtx *auth.Conte
return err
}
slog.Debug("查找通道", "rid", rid, "step", time.Since(step))
// 检查权限,如果为用户操作的话,则只能删除自己的通道
for _, channel := range channels {
if authCtx.Payload.Type == auth.PayloadUser && authCtx.Payload.Id != channel.UserID {
@@ -72,8 +70,6 @@ func (s *channelService) RemoveChannels(ctx context.Context, authCtx *auth.Conte
}
// 查找代理
step = time.Now()
proxySet := make(map[int32]struct{})
proxyIds := make([]int32, 0)
for _, channel := range channels {
@@ -89,12 +85,10 @@ func (s *channelService) RemoveChannels(ctx context.Context, authCtx *auth.Conte
return err
}
slog.Debug("查找代理", "rid", rid, "step", time.Since(step))
// 删除指定的通道
result, err := tx.Channel.
result, err := tx.Channel.Debug().
Where(q.Channel.ID.In(id...)).
Update(q.Channel.DeletedAt, time.Now())
Update(q.Channel.DeletedAt, now)
if err != nil {
return err
}
@@ -102,19 +96,15 @@ func (s *channelService) RemoveChannels(ctx context.Context, authCtx *auth.Conte
return ChannelServiceErr("删除通道失败")
}
// 删除缓存,异步任务直接在消费端处理删除
step = time.Now()
// 删除缓存
err = deleteCache(ctx, channels)
if err != nil {
return err
}
slog.Debug("删除缓存", "rid", rid, "step", time.Since(step))
// 禁用代理端口并下线用过的节点
if env.DebugExternalChange {
step = time.Now()
var step = time.Now()
// 组织数据
var configMap = make(map[int32][]g.PortConfigsReq, len(proxies))

View File

@@ -31,6 +31,14 @@ func (s *transactionService) PrepareTransaction(ctx context.Context, q *q.Query,
var tType = data.Type
var method = data.Method
var amount = data.Amount
// 实际支付金额,只在创建真实订单时使用
var amountReal = data.Amount
if env.RunMode == "debug" {
amountReal = 0.01
}
// 附加优惠券
if data.CouponCode != "" {
coupon, err := q.Coupon.WithContext(ctx).
Where(
@@ -101,7 +109,7 @@ func (s *transactionService) PrepareTransaction(ctx context.Context, q *q.Query,
ProductCode: "FAST_INSTANT_TRADE_PAY",
OutTradeNo: tradeNo,
Subject: subject,
TotalAmount: strconv.FormatFloat(amount, 'f', 2, 64),
TotalAmount: strconv.FormatFloat(amountReal, 'f', 2, 64),
TimeExpire: expire.Format("2006-01-02 15:04:05"),
},
})
@@ -120,7 +128,7 @@ func (s *transactionService) PrepareTransaction(ctx context.Context, q *q.Query,
TimeExpire: &expire,
NotifyUrl: &env.WechatPayCallbackUrl,
Amount: &native.Amount{
Total: u.P(int64(amount * 100)),
Total: u.P(int64(amountReal * 100)),
},
})
if err != nil {
@@ -152,7 +160,6 @@ func (s *transactionService) PrepareTransaction(ctx context.Context, q *q.Query,
Method: int32(method),
Type: int32(tradeType),
Amount: amount,
Status: 0, // 0-待支付
PayURL: payUrl,
}
err = q.Trade.Create(&trade)