goods.go 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. package sbyj
  2. import (
  3. "mtp2_if/global/app"
  4. "mtp2_if/global/e"
  5. "mtp2_if/logger"
  6. "mtp2_if/models"
  7. "net/http"
  8. "strconv"
  9. "strings"
  10. "github.com/gin-gonic/gin"
  11. )
  12. type GetTouristGoodsReq struct {
  13. TradeModes string `form:"trademodes"` // 交易模式筛选, 逗号隔开, 默认为 52,97,99
  14. MarketIds string `form:"marketids"` // 市场ID筛选, 逗号隔开
  15. }
  16. // GetTouristGoods 获取订单系统游客商品列表
  17. // @Summary 获取订单系统游客商品列表
  18. // @Produce json
  19. // @Param trademodes query string false "交易模式筛选, 逗号隔开, 默认为 52,97,99"
  20. // @Param marketids query string false "市场ID筛选, 逗号隔开"
  21. // @Success 200 {array} models.TouristGoods
  22. // @Failure 500 {object} app.Response
  23. // @Router /sbyj/GetTouristGoods [get]
  24. // @Tags 订单系统
  25. func GetTouristGoods(c *gin.Context) {
  26. appG := app.Gin{C: c}
  27. // 获取请求参数
  28. var req GetTouristGoodsReq
  29. if err := appG.C.ShouldBindQuery(&req); err != nil {
  30. logger.GetLogger().Errorf("GetTouristGoods failed: %s", err.Error())
  31. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  32. return
  33. }
  34. // 获取数据
  35. var tradeModes []int
  36. if req.TradeModes != "" {
  37. arr := strings.Split(req.TradeModes, ",")
  38. for _, item := range arr {
  39. a, _ := strconv.Atoi(item)
  40. tradeModes = append(tradeModes, a)
  41. }
  42. } else {
  43. // 接外部行情的市场: 52-订单系统,10,53-交易系统 97,99-参考行情
  44. tradeModes = []int{10, 53, 52, 97, 99}
  45. }
  46. marketIds := make([]int, 0)
  47. if req.MarketIds != "" {
  48. arr := strings.Split(req.MarketIds, ",")
  49. for _, item := range arr {
  50. a, _ := strconv.Atoi(item)
  51. marketIds = append(marketIds, a)
  52. }
  53. }
  54. goodses, err := models.GetTouristGoods(tradeModes, marketIds)
  55. if err != nil {
  56. // 查询失败
  57. logger.GetLogger().Errorf("GetTouristGoods failed: %s", err.Error())
  58. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  59. return
  60. }
  61. // 查询成功返回
  62. appG.Response(http.StatusOK, e.SUCCESS, goodses)
  63. }
  64. type GetMyOrdersReq struct {
  65. GoodsId int `form:"goodsId"` // 商品ID
  66. UserId int `form:"userId" binding:"required"` // 用户ID
  67. AccountId string `form:"accountId"` // 资金账户Id
  68. }