Kaynağa Gözat

chore: epay

CalciumIon 1 yıl önce
ebeveyn
işleme
a0a3807bd4
1 değiştirilmiş dosya ile 14 ekleme ve 6 silme
  1. 14 6
      controller/topup.go

+ 14 - 6
controller/topup.go

@@ -41,12 +41,12 @@ func GetEpayClient() *epay.Client {
 	return withUrl
 	return withUrl
 }
 }
 
 
-func getPayMoney(amount float64, user model.User) float64 {
+func getPayMoney(amount float64, group string) float64 {
 	if !common.DisplayInCurrencyEnabled {
 	if !common.DisplayInCurrencyEnabled {
 		amount = amount / common.QuotaPerUnit
 		amount = amount / common.QuotaPerUnit
 	}
 	}
 	// 别问为什么用float64,问就是这么点钱没必要
 	// 别问为什么用float64,问就是这么点钱没必要
-	topupGroupRatio := common.GetTopupGroupRatio(user.Group)
+	topupGroupRatio := common.GetTopupGroupRatio(group)
 	if topupGroupRatio == 0 {
 	if topupGroupRatio == 0 {
 		topupGroupRatio = 1
 		topupGroupRatio = 1
 	}
 	}
@@ -75,8 +75,12 @@ func RequestEpay(c *gin.Context) {
 	}
 	}
 
 
 	id := c.GetInt("id")
 	id := c.GetInt("id")
-	user, _ := model.GetUserById(id, false)
-	payMoney := getPayMoney(float64(req.Amount), *user)
+	group, err := model.CacheGetUserGroup(id)
+	if err != nil {
+		c.JSON(200, gin.H{"message": "error", "data": "获取用户分组失败"})
+		return
+	}
+	payMoney := getPayMoney(float64(req.Amount), group)
 	if payMoney < 0.01 {
 	if payMoney < 0.01 {
 		c.JSON(200, gin.H{"message": "error", "data": "充值金额过低"})
 		c.JSON(200, gin.H{"message": "error", "data": "充值金额过低"})
 		return
 		return
@@ -233,8 +237,12 @@ func RequestAmount(c *gin.Context) {
 		return
 		return
 	}
 	}
 	id := c.GetInt("id")
 	id := c.GetInt("id")
-	user, _ := model.GetUserById(id, false)
-	payMoney := getPayMoney(float64(req.Amount), *user)
+	group, err := model.CacheGetUserGroup(id)
+	if err != nil {
+		c.JSON(200, gin.H{"message": "error", "data": "获取用户分组失败"})
+		return
+	}
+	payMoney := getPayMoney(float64(req.Amount), group)
 	if payMoney <= 0.01 {
 	if payMoney <= 0.01 {
 		c.JSON(200, gin.H{"message": "error", "data": "充值金额过低"})
 		c.JSON(200, gin.H{"message": "error", "data": "充值金额过低"})
 		return
 		return