fix(pay): 增加订单金额一致性校验并改进链路追踪
- 在支付服务中加入订单金额与提交金额不一致的错误校验 - 修改扫描控制器中链路追踪的创建方式,统一使用otelTrace.Span方法 - 在创建订单接口中添加请求参数日志记录 - 删除创建订单接口内多余空行,优化代码格式
This commit is contained in:
@@ -89,7 +89,7 @@ type ScanController struct {
|
||||
|
||||
// Scan 处理扫码的请求
|
||||
func (c *ScanController) Scan() {
|
||||
ctx, span := otelTrace.CreateLinkContext(c.Ctx.Request.Context(), "ScanController")
|
||||
ctx, span := otelTrace.Span(c.Ctx.Request.Context(), "ScanController", "ScanController.Scan")
|
||||
defer span.End()
|
||||
// 获取所有请求参数
|
||||
p := service.GetMerchantInfo(ctx, map[string]any{
|
||||
@@ -349,7 +349,7 @@ func (c *ScanController) SolveFailJSON(p *response.PayBaseResp) {
|
||||
}
|
||||
|
||||
func (c *ScanController) GetAllowedMM() {
|
||||
ctx, span := otelTrace.CreateLinkContext(c.Ctx.Request.Context(), "GetAllowedMM")
|
||||
ctx, span := otelTrace.Span(c.Ctx.Request.Context(), "ScanController", "GetAllowedMM")
|
||||
defer span.End()
|
||||
payKey := strings.TrimSpace(c.GetString("payKey"))
|
||||
showMMValue, err := c.GetFloat("showMMValue")
|
||||
@@ -416,9 +416,8 @@ func (c *ScanController) GetAllowedMM() {
|
||||
|
||||
// CreateOrder 创建订单
|
||||
func (c *ScanController) CreateOrder() {
|
||||
ctx, span := otelTrace.CreateLinkContext(c.Ctx.Request.Context(), "CreateOrder")
|
||||
ctx, span := otelTrace.Span(c.Ctx.Request.Context(), "ScanController", "ScanController.CreateOrder")
|
||||
defer span.End()
|
||||
|
||||
createdOrder := request.CreatedOrder{}
|
||||
_ = c.Bind(&createdOrder)
|
||||
valid := validation.Validation{}
|
||||
@@ -448,6 +447,7 @@ func (c *ScanController) CreateOrder() {
|
||||
_ = c.ServeJSON()
|
||||
return
|
||||
}
|
||||
otelTrace.Logger.WithContext(ctx).Info("请求参数", zap.Any("createdOrder", createdOrder))
|
||||
|
||||
orderInfo := order.GetOrderByMerchantOrderId(ctx, createdOrder.OrderNo)
|
||||
roadInfo := road.GetRoadInfoByProductCode(ctx, createdOrder.ProductCode)
|
||||
@@ -496,7 +496,6 @@ func (c *ScanController) CreateOrder() {
|
||||
|
||||
payUrl := ""
|
||||
bankTransId := ""
|
||||
//TODO: 区分自有渠道和三方渠道
|
||||
if supplierByCode.HasDependencyHTML() {
|
||||
scanData := supplierByCode.Scan(ctx, orderInfo, roadInfo, merchantInfo)
|
||||
payUrl = scanData.PayUrl
|
||||
|
||||
@@ -364,6 +364,11 @@ func GenerateRecord(ctx context.Context, c *response.PayBaseResp) (order.OrderIn
|
||||
return orderInfo, orderProfitInfo, err
|
||||
}
|
||||
|
||||
if orderInfo.OrderAmount != c.OrderAmount {
|
||||
err = errors.New("订单金额与提交金额不一致")
|
||||
return orderInfo, orderProfitInfo, err
|
||||
}
|
||||
|
||||
if !order.InsertOrderExValue(ctx, convertor.ToString(c.Params["orderNo"]), convertor.ToString(c.Params["exValue"])) {
|
||||
err = errors.New("订单数据插入失败")
|
||||
return orderInfo, orderProfitInfo, err
|
||||
|
||||
Reference in New Issue
Block a user