Browse Source

修复mj计费问题

CaIon 2 years ago
parent
commit
b3fc335908
1 changed files with 19 additions and 2 deletions
  1. 19 2
      controller/relay-mj.go

+ 19 - 2
controller/relay-mj.go

@@ -55,6 +55,15 @@ type MidjourneyWithoutStatus struct {
 	ChannelId   int    `json:"channel_id"`
 }
 
+var DefaultModelPrice = map[string]float64{
+	"mj_imagine":   0.1,
+	"mj_variation": 0.1,
+	"mj_reroll":    0.1,
+	"mj_blend":     0.1,
+	"mj_describe":  0.05,
+	"mj_upscale":   0.05,
+}
+
 func RelayMidjourneyImage(c *gin.Context) {
 	taskId := c.Param("id")
 	midjourneyTask := model.GetByOnlyMJId(taskId)
@@ -382,8 +391,16 @@ func relayMidjourneySubmit(c *gin.Context, relayMode int) *MidjourneyResponse {
 	} else {
 		requestBody = c.Request.Body
 	}
-
-	modelPrice := common.GetModelPrice("mj_" + strings.ToLower(action))
+	mjAction := "mj_" + strings.ToLower(action)
+	modelPrice := common.GetModelPrice(mjAction)
+	if modelPrice == -1 {
+		defaultPrice, ok := DefaultModelPrice[mjAction]
+		if !ok {
+			modelPrice = 0.1
+		} else {
+			modelPrice = defaultPrice
+		}
+	}
 	groupRatio := common.GetGroupRatio(group)
 	ratio := modelPrice * groupRatio
 	userQuota, err := model.CacheGetUserQuota(userId)