pricing.go 986 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package controller
  2. import (
  3. "github.com/gin-gonic/gin"
  4. "one-api/common"
  5. "one-api/model"
  6. )
  7. func GetPricing(c *gin.Context) {
  8. userId := c.GetInt("id")
  9. // if no login, get default group ratio
  10. groupRatio := common.GetGroupRatio("default")
  11. group, err := model.CacheGetUserGroup(userId)
  12. if err == nil {
  13. groupRatio = common.GetGroupRatio(group)
  14. }
  15. pricing := model.GetPricing(group)
  16. c.JSON(200, gin.H{
  17. "success": true,
  18. "data": pricing,
  19. "group_ratio": groupRatio,
  20. })
  21. }
  22. func ResetModelRatio(c *gin.Context) {
  23. defaultStr := common.DefaultModelRatio2JSONString()
  24. err := model.UpdateOption("ModelRatio", defaultStr)
  25. if err != nil {
  26. c.JSON(200, gin.H{
  27. "success": false,
  28. "message": err.Error(),
  29. })
  30. return
  31. }
  32. err = common.UpdateModelRatioByJSONString(defaultStr)
  33. if err != nil {
  34. c.JSON(200, gin.H{
  35. "success": false,
  36. "message": err.Error(),
  37. })
  38. return
  39. }
  40. c.JSON(200, gin.H{
  41. "success": true,
  42. "message": "重置模型倍率成功",
  43. })
  44. }