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" ) // QueryHsbyTopGoodsesReq 查询热门商品列表请求参数 type QueryHsbyTopGoodsesReq struct { app.PageInfo MarketIDs string `form:"marketIDs" binding:"required"` DescProvinceID int `form:"descProvinceID"` DescCityID int `form:"descCityID"` } // QueryHsbyTopGoodses 查询热卖商品列表(二级市场挂牌点选) // @Summary 查询热卖商品列表(二级市场挂牌点选) // @Description 说明:查询结果已按Hotindex(景点热度)从大到小排序 // @Produce json // @Security ApiKeyAuth // @Param page query int false "页码" // @Param pagesize query int false "每页条数" // @Param marketIDs query string true "市场ID列表,格式:1,2,3" // @Param DescProvinceID query int false "目的地(省)ID" // @Param DescCityID query int false "目的地(市)ID" // @Success 200 {object} models.HsbyTopGoods // @Failure 500 {object} app.Response // @Router /HSBY/QueryHsbyTopGoodses [get] // @Tags 定制【海商报业】 func QueryHsbyTopGoodses(c *gin.Context) { appG := app.Gin{C: c} // 获取请求参数 var req QueryHsbyTopGoodsesReq if err := appG.C.ShouldBindQuery(&req); err != nil { logger.GetLogger().Errorf("QueryHsbyTopGoodses failed: %s", err.Error()) appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil) return } // 获取数据 topGoodses, err := models.GetHsbyTopGoodses(req.MarketIDs, req.DescProvinceID, req.DescCityID) if err != nil { // 查询失败 logger.GetLogger().Errorf("QueryHsbyTopGoodses 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("QueryHsbyTopGoodses successed: %v", topGoodses) appG.ResponseByPage(http.StatusOK, e.SUCCESS, topGoodses, app.PageInfo{Page: req.Page, PageSize: req.PageSize, Total: total}) } else { logger.GetLogger().Debugln("QueryHsbyTopGoodses 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"` BuyOrSell int `form:"buyOrSell"` Price float64 `form:"price"` Speed int `form:"speed"` } // QueryHsbyGoodsOrderDetails 查询二级市场(挂牌点选)商品对应的挂牌委托单信息 // @Summary 查询二级市场(挂牌点选)商品对应的挂牌委托单信息 // @Description 说明:查询结果已按委托价格和委托时间排序; sellOrderDetails - 转让(卖出)单,buyOrderDetails - 求购(买入)单 // @Produce json // @Security ApiKeyAuth // @Param goodsID query int true "商品ID" // @Param buyOrSell query int false "委托单方向。0:买 1:卖。不传则默认为买" // @Param price query number false " 参考价格。买方向委托单则价格大于等于(站在摘牌人的角度);卖方向委托单则价格小于等于" // @Param speed 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 } // 获取数据 orderDetails, err := models.GetHsbyGoodsOrderDetails(req.GoodsID, req.BuyOrSell, req.Price) if err != nil { // 查询失败 logger.GetLogger().Errorf("QueryHsbyGoodsOrderDetails failed: %s", err.Error()) appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil) return } // 按时间和价格排序 if req.BuyOrSell == 0 { // 买方向 sort.Slice(orderDetails, func(i int, j int) bool { // 委托价格一样则按时间顺序排 if orderDetails[i].Orderprice == orderDetails[j].Orderprice { return orderDetails[i].Ordertime.Before(orderDetails[j].Ordertime) } // 站在摘牌者的角度,买方向的委托单价格高的在前面 return orderDetails[i].Orderprice > orderDetails[j].Orderprice }) } else { // 卖方向 sort.Slice(orderDetails, func(i int, j int) bool { // 委托价格一样则按时间顺序排 if orderDetails[i].Orderprice == orderDetails[j].Orderprice { return orderDetails[i].Ordertime.Before(orderDetails[j].Ordertime) } return orderDetails[i].Orderprice < orderDetails[j].Orderprice }) } // 取N档,默认3档 if req.Speed == 0 { req.Speed = 3 } // 判断结束下标是否越界 end := req.Speed if req.Speed > len(orderDetails) { end = len(orderDetails) } orderDetails = orderDetails[0:end] // 查询成功返回 logger.GetLogger().Debugln("QueryHsbyGoodsOrderDetails successed: %v", orderDetails) appG.Response(http.StatusOK, e.SUCCESS, orderDetails) } // QueryHsbyMyBuyOrderDetailsReq 查询“我的订单”信息请求参数 type QueryHsbyMyBuyOrderDetailsReq struct { AccountIDs string `form:"accountIDs" binding:"required"` MyBuyStatus int `form:"myBuyStatus"` } // QueryHsbyMyBuyOrderDetails 查询“我的订单”信息 // @Summary 查询“我的订单”信息 // @Description 说明: 全部:一二级市场买委托;抢购中:一级市场买摘; 求购中:二级市场买挂; 3:已完成:一二级市场已完成买委托; // @Produce json // @Security ApiKeyAuth // @Param accountIDs query string true "资金账户列表,格式:1,2,3" // @Param myBuyStatus query int false "'我的订单'状态, 1:抢购中 2:求购中 3:已完成;不传则为'全部'" // @Success 200 {object} models.HybsMyBuyOrderDetail // @Failure 500 {object} app.Response // @Router /HSBY/QueryHsbyMyBuyOrderDetails [get] // @Tags 定制【海商报业】 func QueryHsbyMyBuyOrderDetails(c *gin.Context) { appG := app.Gin{C: c} // 获取请求参数 var req QueryHsbyMyBuyOrderDetailsReq if err := appG.C.ShouldBindQuery(&req); err != nil { logger.GetLogger().Errorf("QueryHsbyMyBuyOrderDetails failed: %s", err.Error()) appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil) return } // 获取数据 myOrderDetails, err := models.GetHsbyBuyMyOrderDetails(req.AccountIDs, req.MyBuyStatus) if err != nil { // 查询失败 logger.GetLogger().Errorf("QueryHsbyMyBuyOrderDetails failed: %s", err.Error()) appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil) return } // 按时间排序 sort.Slice(myOrderDetails, func(i int, j int) bool { return myOrderDetails[i].Ordertime.After(myOrderDetails[j].Ordertime) }) // 查询成功返回 logger.GetLogger().Debugln("QueryHsbyMyBuyOrderDetails successed: %v", myOrderDetails) appG.Response(http.StatusOK, e.SUCCESS, myOrderDetails) } // QueryHsbyMyGoodsReq 查询“我的商品”请求参数 type QueryHsbyMyGoodsReq struct { AccountIDs string `form:"accountIDs" binding:"required"` } // QueryHsbyMyGoods 查询“我的商品”信息 // @Summary 查询“我的商品”信息 // @Produce json // @Security ApiKeyAuth // @Param accountIDs query string true "资金账户列表,格式:1,2,3" // @Success 200 {object} models.HsbyMyGoods // @Failure 500 {object} app.Response // @Router /HSBY/QueryHsbyMyGoods [get] // @Tags 定制【海商报业】 func QueryHsbyMyGoods(c *gin.Context) { appG := app.Gin{C: c} // 获取请求参数 var req QueryHsbyMyGoodsReq if err := appG.C.ShouldBindQuery(&req); err != nil { logger.GetLogger().Errorf("QueryHsbyMyGoods failed: %s", err.Error()) appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil) return } // 获取数据 myGoodses, err := models.GetHsbyMyGoods(req.AccountIDs) if err != nil { // 查询失败 logger.GetLogger().Errorf("QueryHsbyMyGoods failed: %s", err.Error()) appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil) return } // 查询成功返回 logger.GetLogger().Debugln("QueryHsbyMyGoods successed: %v", myGoodses) appG.Response(http.StatusOK, e.SUCCESS, myGoodses) } // QueryHsbyPreGoodsesReq 查询新品上市商品列表请求参数 type QueryHsbyPreGoodsesReq struct { app.PageInfo MarketIDs string `form:"marketIDs" binding:"required"` DescProvinceID int `form:"descProvinceID"` DescCityID int `form:"descCityID"` } // QueryHsbyPreGoodses 查询新品上市商品列表(一级市场产能预售) // @Summary 查询新品上市商品列表(一级市场产能预售) // @Description 说明:结果已先显示已开始商品(按结束时间顺序排),再显示未开始商品(按开始时间顺序排) // @Produce json // @Security ApiKeyAuth // @Param page query int false "页码" // @Param pagesize query int false "每页条数" // @Param marketIDs query string true "市场ID列表,格式:1,2,3" // @Param DescProvinceID query int false "目的地(省)ID" // @Param DescCityID query int false "目的地(市)ID" // @Success 200 {object} models.HsbyPreGoods // @Failure 500 {object} app.Response // @Router /HSBY/QueryHsbyPreGoodses [get] // @Tags 定制【海商报业】 func QueryHsbyPreGoodses(c *gin.Context) { appG := app.Gin{C: c} // 获取请求参数 var req QueryHsbyPreGoodsesReq if err := appG.C.ShouldBindQuery(&req); err != nil { logger.GetLogger().Errorf("QueryHsbyPreGoodses failed: %s", err.Error()) appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil) return } // 获取数据 preGoodses, err := models.GetHsbyPreGoodses(req.MarketIDs, req.DescProvinceID, req.DescCityID) if err != nil { // 查询失败 logger.GetLogger().Errorf("QueryHsbyPreGoodses failed: %s", err.Error()) appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil) return } // 排序,先显示已开始商品(按结束时间顺序排),再显示未开始商品(按开始时间顺序排) sort.Slice(preGoodses, func(i int, j int) bool { if preGoodses[i].Goodsstatus == 3 && preGoodses[j].Goodsstatus == 2 { // 先显示已开始商品 return true } else if preGoodses[i].Goodsstatus == 3 && preGoodses[j].Goodsstatus == 3 { // 已开始商品按结束时间顺序排 return preGoodses[i].Endtime.After(preGoodses[j].Endtime) } else if preGoodses[i].Goodsstatus == 3 && preGoodses[j].Goodsstatus == 3 { // 未开始商品按开始时间顺序排 return preGoodses[i].Starttime.After(preGoodses[j].Starttime) } return false }) // 分页 total := len(preGoodses) if req.PageSize > 0 { rstByPage := make([]models.HsbyPreGoods, 0) // 开始上标 start := req.Page * req.PageSize // 结束下标 end := start + req.PageSize if start <= len(preGoodses) { // 判断结束下标是否越界 if end > len(preGoodses) { end = len(preGoodses) } rstByPage = preGoodses[start:end] } else { rstByPage = preGoodses[0:0] } preGoodses = rstByPage } // 查询成功返回 if req.PageSize > 0 { logger.GetLogger().Debugln("QueryHsbyPreGoodses successed: %v", preGoodses) appG.ResponseByPage(http.StatusOK, e.SUCCESS, preGoodses, app.PageInfo{Page: req.Page, PageSize: req.PageSize, Total: total}) } else { logger.GetLogger().Debugln("QueryHsbyPreGoodses successed: %v", preGoodses) appG.Response(http.StatusOK, e.SUCCESS, preGoodses) } }