From 71f7be5716a6a97e92642b0b9f5ab66affbf6813 Mon Sep 17 00:00:00 2001 From: zhoujunyao Date: Wed, 7 Jan 2026 10:50:51 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=94=AF=E4=BB=98=E5=9B=9E=E8=B0=83?= =?UTF-8?q?=EF=BC=8C=E6=9B=B4=E6=96=B0=E6=89=8B=E7=BB=AD=E8=B4=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/dao/orderRecordsDao.go | 34 +++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/internal/dao/orderRecordsDao.go b/internal/dao/orderRecordsDao.go index 72f972f..eaf629a 100644 --- a/internal/dao/orderRecordsDao.go +++ b/internal/dao/orderRecordsDao.go @@ -4,6 +4,7 @@ import ( "encoding/json" "errors" "fmt" + "github.com/shopspring/decimal" "micro-bundle/internal/model" "micro-bundle/pb/bundle" "micro-bundle/pkg/app" @@ -127,6 +128,26 @@ func UpdateOrderRecordByOrderNO(orderRecord *model.BundleOrderRecords) (res *bun } } } + + tempRecord := new(model.BundleOrderRecords) + if err := app.ModuleClients.BundleDB.Where("deleted_at is null and order_no = ?", orderRecord.OrderNo).First(&tempRecord).Error; err != nil { + if errors.Is(err, gorm.ErrRecordNotFound) { + return nil, errors.New("订单记录不存在") + } + return nil, fmt.Errorf("查询订单失败: %v", err) + } + if orderRecord.Status == 2 && tempRecord.AmountType == 2 && tempRecord.TotalAmount > 0 { + // 当回调支付成功,币种是美元,且订单金额大于0,计算美元手续费:订单金额*0.019(四舍五入保留两位小数字)+0.1 + amount := decimal.NewFromFloat32(tempRecord.TotalAmount) + rate, _ := decimal.NewFromString("0.019") + fee := amount.Mul(rate) + // 4. 四舍五入保留两位小数 + feeRounded := fee.Round(2) + addition, _ := decimal.NewFromString("0.1") + result := feeRounded.Add(addition) + valueAdd.HandlingFee = result.String() + } + } err = app.ModuleClients.BundleDB.Model(&model.BundleOrderValueAdd{}). @@ -807,6 +828,19 @@ func UpdateReconciliationStatusBySerialNumber(req *bundle.UpdateStatusAndPayTime PayStatus: int(req.PaymentStatus), SerialNumber: req.SerialNumber, } + + if req.PaymentStatus == 2 && existing.CurrencyType == 2 && existing.PayAmount > 0 { + // 当回调支付成功,币种是美元,且订单金额大于0,计算美元手续费:订单金额*0.019(四舍五入保留两位小数字)+0.1 + amount := decimal.NewFromFloat32(existing.PayAmount) + rate, _ := decimal.NewFromString("0.019") + fee := amount.Mul(rate) + // 4. 四舍五入保留两位小数 + feeRounded := fee.Round(2) + addition, _ := decimal.NewFromString("0.1") + result := feeRounded.Add(addition) + updates.HandlingFee = result.String() + } + if err := app.ModuleClients.BundleDB.Model(&existing).Updates(updates).Error; err != nil { return nil, fmt.Errorf("更新对账单失败: %v", err) }