From 0c725e99a42527bc00b8abe56030c78ad6bc1b00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E6=B6=9B?= Date: Thu, 8 Jun 2023 21:47:04 +0800 Subject: [PATCH] =?UTF-8?q?fix(charge):=E4=BF=AE=E5=A4=8D=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E5=85=85=E5=80=BC=E8=AE=B0=E5=BD=95=E5=88=9B=E5=BB=BA?= =?UTF-8?q?=E7=9A=84=E6=97=B6=E5=80=99=E5=AF=B9=E4=BA=8E=E6=95=B0=E5=80=BC?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B=E5=86=85=E5=AE=B9=E8=A7=A3=E6=9E=90=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controller/charge.go | 9 ++++++--- model/charge.go | 12 +++++++----- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/controller/charge.go b/controller/charge.go index 86b83cb..2d057b1 100644 --- a/controller/charge.go +++ b/controller/charge.go @@ -50,11 +50,14 @@ func createNewUserChargeRecord(c *fiber.Ctx) error { chargeLog.Error("无法解析创建充值记录的请求数据。", zap.Error(err)) return result.Error(http.StatusBadRequest, err.Error()) } + fee, _ := createionForm.Fee.Float64() + discount, _ := createionForm.Discount.Float64() + amount, _ := createionForm.Amount.Float64() ok, err := service.ChargeService.RecordUserCharge( createionForm.UserId, - createionForm.Fee, - createionForm.Discount, - createionForm.Amount, + &fee, + &discount, + &amount, createionForm.ChargeTo, true, ) diff --git a/model/charge.go b/model/charge.go index d09783c..b8357b4 100644 --- a/model/charge.go +++ b/model/charge.go @@ -2,6 +2,8 @@ package model import ( "electricity_bill_calc/types" + + "github.com/shopspring/decimal" ) type UserChargeDetail struct { @@ -22,9 +24,9 @@ type UserChargeDetail struct { } type ChargeRecordCreationForm struct { - UserId string `json:"userId"` - Fee *float64 `json:"fee"` - Discount *float64 `json:"discount"` - Amount *float64 `json:"amount"` - ChargeTo types.Date `json:"chargeTo"` + UserId string `json:"userId"` + Fee *decimal.Decimal `json:"fee"` + Discount *decimal.Decimal `json:"discount"` + Amount *decimal.Decimal `json:"amount"` + ChargeTo types.Date `json:"chargeTo"` }