| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258 |
- 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 说明:查询结果已按委托价格和委托时间排序; sellOrderDetails - 转让(卖出)单,buyOrderDetails - 求购(买入)单
- // @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)
- }
- // QueryHsbyMyBuyOrderDetailsReq 查询“我的订单”信息请求参数
- type QueryHsbyMyBuyOrderDetailsReq struct {
- AccountID int `form:"accountID" binding:"required"`
- MyBuyStatus int `form:"myBuyStatus"`
- }
- // QueryHsbyMyBuyOrderDetails 查询“我的订单”信息
- // @Summary 查询“我的订单”信息
- // @Description 说明: 全部:一二级市场买委托;抢购中:一级市场买摘; 求购中:二级市场买挂; 3:已完成:一二级市场已完成买委托;
- // @Produce json
- // @Security ApiKeyAuth
- // @Param accountID query int true "资金账户"
- // @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.AccountID, 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)
- }
|