package hsby import ( "mtp2_if/global/app" "mtp2_if/global/e" "mtp2_if/logger" "mtp2_if/models" "net/http" "sort" "github.com/gin-gonic/gin" ) // QueryTopGoodsReq 查询热门商品列表请求参数 type QueryTopGoodsReq struct { app.PageInfo MarketID int `form:"marketID" binding:"required"` DescProvinceID int `form:"descProvinceID"` DescCityID int `form:"descCityID"` } // QueryTopGoods 查询热门商品列表(二级市场,挂牌点选) // @Summary 查询热门商品列表(二级市场,挂牌点选) // @Description 说明:查询结果已按Hotindex(景点热度)从大到小排序 // @Produce json // @Security ApiKeyAuth // @Param page query int false "页码" // @Param pagesize query int false "每页条数" // @Param marketID query int true "市场ID" // @Param DescProvinceID query int false "目的地(省)ID" // @Param DescCityID query int false "目的地(市)ID" // @Success 200 {object} models.HsbyTopGoods // @Failure 500 {object} app.Response // @Router /HSBY/QueryTopGoods [get] // @Tags 定制【海商报业】 func QueryTopGoods(c *gin.Context) { appG := app.Gin{C: c} // 获取请求参数 var req QueryTopGoodsReq if err := appG.C.ShouldBindQuery(&req); err != nil { logger.GetLogger().Errorf("QueryTopGoods failed: %s", err.Error()) appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil) return } // 获取数据 topGoodses, err := models.GetHsbyTopGoods(req.MarketID, req.DescProvinceID, req.DescCityID) if err != nil { // 查询失败 logger.GetLogger().Errorf("QueryTopGoods failed: %s", err.Error()) appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil) return } // 排序 sort.Slice(topGoodses, func(i int, j int) bool { return topGoodses[i].Hotindex > topGoodses[j].Hotindex }) // 分页 total := len(topGoodses) if req.PageSize > 0 { rstByPage := make([]models.HsbyTopGoods, 0) // 开始上标 start := req.Page * req.PageSize // 结束下标 end := start + req.PageSize if start <= len(topGoodses) { // 判断结束下标是否越界 if end > len(topGoodses) { end = len(topGoodses) } rstByPage = topGoodses[start:end] } else { rstByPage = topGoodses[0:0] } topGoodses = rstByPage } // 查询成功返回 if req.PageSize > 0 { logger.GetLogger().Debugln("QueryTopGoods successed: %v", topGoodses) appG.ResponseByPage(http.StatusOK, e.SUCCESS, topGoodses, app.PageInfo{Page: req.Page, PageSize: req.PageSize, Total: total}) } else { logger.GetLogger().Debugln("QueryTopGoods successed: %v", topGoodses) appG.Response(http.StatusOK, e.SUCCESS, topGoodses) } } // QueryHsbyListingGoodsDetailReq 查询二级市场(挂牌点选)商品信息详情请求参数 type QueryHsbyListingGoodsDetailReq struct { GoodsID int `form:"goodsID" binding:"required"` } // QueryHsbyListingGoodsDetail 查询二级市场(挂牌点选)商品信息详情 // @Summary 查询二级市场(挂牌点选)商品信息详情 // @Produce json // @Security ApiKeyAuth // @Param goodsID query int true "商品ID" // @Success 200 {object} models.HsbyListingGoodsDetail // @Failure 500 {object} app.Response // @Router /HSBY/QueryHsbyListingGoodsDetail [get] // @Tags 定制【海商报业】 func QueryHsbyListingGoodsDetail(c *gin.Context) { appG := app.Gin{C: c} // 获取请求参数 var req QueryHsbyListingGoodsDetailReq if err := appG.C.ShouldBindQuery(&req); err != nil { logger.GetLogger().Errorf("QueryHsbyListingGoodsDetail failed: %s", err.Error()) appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil) return } // 获取数据 goodsInfo, err := models.GetHsbyListingGoodsDetail(req.GoodsID) if err != nil { // 查询失败 logger.GetLogger().Errorf("QueryHsbyListingGoodsDetail failed: %s", err.Error()) appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil) return } // 查询成功返回 logger.GetLogger().Debugln("QueryHsbyListingGoodsDetail successed: %v", goodsInfo) appG.Response(http.StatusOK, e.SUCCESS, goodsInfo) } // QueryHsbyGoodsOrderDetailsReq 查询二级市场(挂牌点选)商品对应的挂牌委托单信息请求参数 type QueryHsbyGoodsOrderDetailsReq struct { GoodsID int `form:"goodsID" binding:"required"` Number int `form:"number"` } // QueryHsbyGoodsOrderDetails 查询二级市场(挂牌点选)商品对应的挂牌委托单信息 // @Summary 查询二级市场(挂牌点选)商品对应的挂牌委托单信息 // @Description 说明:查询结果已按委托价格和委托时间排序 // @Produce json // @Security ApiKeyAuth // @Param goodsID query int true "商品ID" // @Param Number query int false "档位,不传则默认为3档" // @Success 200 {object} models.HsbyGoodsOrderDetail // @Failure 500 {object} app.Response // @Router /HSBY/QueryHsbyGoodsOrderDetails [get] // @Tags 定制【海商报业】 func QueryHsbyGoodsOrderDetails(c *gin.Context) { appG := app.Gin{C: c} // 获取请求参数 var req QueryHsbyGoodsOrderDetailsReq if err := appG.C.ShouldBindQuery(&req); err != nil { logger.GetLogger().Errorf("QueryHsbyGoodsOrderDetails failed: %s", err.Error()) appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil) return } // 获取数据 sellOrderDetails, buyOrderDetails, err := models.GetHsbyGoodsOrderDetails(req.GoodsID) if err != nil { // 查询失败 logger.GetLogger().Errorf("QueryHsbyGoodsOrderDetails failed: %s", err.Error()) appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil) return } // 按时间和价格排序 sort.Slice(sellOrderDetails, func(i int, j int) bool { // 时间价格一样则按时间顺序排 if sellOrderDetails[i].Orderprice == sellOrderDetails[j].Orderprice { return sellOrderDetails[i].Ordertime.Before(sellOrderDetails[j].Ordertime) } return sellOrderDetails[i].Orderprice < sellOrderDetails[j].Orderprice }) sort.Slice(buyOrderDetails, func(i int, j int) bool { // 时间价格一样则按时间顺序排 if buyOrderDetails[i].Orderprice == buyOrderDetails[j].Orderprice { return buyOrderDetails[i].Ordertime.Before(buyOrderDetails[j].Ordertime) } return buyOrderDetails[i].Orderprice > buyOrderDetails[j].Orderprice }) // 取N档,默认3档 if req.Number == 0 { req.Number = 3 } // 判断结束下标是否越界 sellEnd := req.Number if req.Number > len(sellOrderDetails) { sellEnd = len(sellOrderDetails) } sellOrderDetails = sellOrderDetails[0:sellEnd] buyEnd := req.Number if req.Number > len(buyOrderDetails) { buyEnd = len(buyOrderDetails) } buyOrderDetails = buyOrderDetails[0:buyEnd] // 结果集 rst := make(map[string]interface{}) rst["sellOrderDetails"] = sellOrderDetails rst["buyOrderDetails"] = buyOrderDetails // 查询成功返回 logger.GetLogger().Debugln("QueryHsbyGoodsOrderDetails successed: %v", rst) appG.Response(http.StatusOK, e.SUCCESS, rst) }