Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 

56 righe
1.1 KiB

  1. package controller
  2. import (
  3. "github.com/QuantumNous/new-api/common"
  4. "github.com/QuantumNous/new-api/model"
  5. "github.com/gin-gonic/gin"
  6. )
  7. // ReorderVendors 批量更新供应商排序
  8. func ReorderVendors(c *gin.Context) {
  9. var req struct {
  10. Items []struct {
  11. Id int `json:"id"`
  12. SortOrder int `json:"sort_order"`
  13. } `json:"items"`
  14. }
  15. if err := c.ShouldBindJSON(&req); err != nil {
  16. common.ApiError(c, err)
  17. return
  18. }
  19. if len(req.Items) == 0 {
  20. common.ApiErrorMsg(c, "items 不能为空")
  21. return
  22. }
  23. if err := model.ReorderVendors(req.Items); err != nil {
  24. common.ApiError(c, err)
  25. return
  26. }
  27. common.ApiSuccess(c, nil)
  28. }
  29. // ReorderModels 批量更新模型排序
  30. func ReorderModels(c *gin.Context) {
  31. var req struct {
  32. Items []struct {
  33. Id int `json:"id"`
  34. SortOrder int `json:"sort_order"`
  35. } `json:"items"`
  36. }
  37. if err := c.ShouldBindJSON(&req); err != nil {
  38. common.ApiError(c, err)
  39. return
  40. }
  41. if len(req.Items) == 0 {
  42. common.ApiErrorMsg(c, "items 不能为空")
  43. return
  44. }
  45. if err := model.ReorderModels(req.Items); err != nil {
  46. common.ApiError(c, err)
  47. return
  48. }
  49. model.RefreshPricing()
  50. common.ApiSuccess(c, nil)
  51. }