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"` }