hsby.go 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. package hsby
  2. import (
  3. "mtp2_if/global/app"
  4. "mtp2_if/global/e"
  5. "mtp2_if/logger"
  6. "mtp2_if/models"
  7. "net/http"
  8. "sort"
  9. "github.com/gin-gonic/gin"
  10. )
  11. // QueryTopGoodsReq 查询热门商品列表请求参数
  12. type QueryTopGoodsReq struct {
  13. app.PageInfo
  14. MarketID int `form:"marketID" binding:"required"`
  15. DescProvinceID int `form:"descProvinceID"`
  16. DescCityID int `form:"descCityID"`
  17. }
  18. // QueryTopGoods 查询热门商品列表(二级市场,挂牌点选)
  19. // @Summary 查询热门商品列表(二级市场,挂牌点选)
  20. // @Description 说明:查询结果已按Hotindex(景点热度)从大到小排序
  21. // @Produce json
  22. // @Security ApiKeyAuth
  23. // @Param page query int false "页码"
  24. // @Param pagesize query int false "每页条数"
  25. // @Param marketID query int true "市场ID"
  26. // @Param DescProvinceID query int false "目的地(省)ID"
  27. // @Param DescCityID query int false "目的地(市)ID"
  28. // @Success 200 {object} models.HsbyTopGoods
  29. // @Failure 500 {object} app.Response
  30. // @Router /HSBY/QueryTopGoods [get]
  31. // @Tags 定制【海商报业】
  32. func QueryTopGoods(c *gin.Context) {
  33. appG := app.Gin{C: c}
  34. // 获取请求参数
  35. var req QueryTopGoodsReq
  36. if err := appG.C.ShouldBindQuery(&req); err != nil {
  37. logger.GetLogger().Errorf("QueryTopGoods failed: %s", err.Error())
  38. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  39. return
  40. }
  41. // 获取数据
  42. topGoodses, err := models.GetHsbyTopGoods(req.MarketID, req.DescProvinceID, req.DescCityID)
  43. if err != nil {
  44. // 查询失败
  45. logger.GetLogger().Errorf("QueryTopGoods failed: %s", err.Error())
  46. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  47. return
  48. }
  49. // 排序
  50. sort.Slice(topGoodses, func(i int, j int) bool {
  51. return topGoodses[i].Hotindex > topGoodses[j].Hotindex
  52. })
  53. // 分页
  54. total := len(topGoodses)
  55. if req.PageSize > 0 {
  56. rstByPage := make([]models.HsbyTopGoods, 0)
  57. // 开始上标
  58. start := req.Page * req.PageSize
  59. // 结束下标
  60. end := start + req.PageSize
  61. if start <= len(topGoodses) {
  62. // 判断结束下标是否越界
  63. if end > len(topGoodses) {
  64. end = len(topGoodses)
  65. }
  66. rstByPage = topGoodses[start:end]
  67. } else {
  68. rstByPage = topGoodses[0:0]
  69. }
  70. topGoodses = rstByPage
  71. }
  72. // 查询成功返回
  73. if req.PageSize > 0 {
  74. logger.GetLogger().Debugln("QueryTopGoods successed: %v", topGoodses)
  75. appG.ResponseByPage(http.StatusOK, e.SUCCESS, topGoodses, app.PageInfo{Page: req.Page, PageSize: req.PageSize, Total: total})
  76. } else {
  77. logger.GetLogger().Debugln("QueryTopGoods successed: %v", topGoodses)
  78. appG.Response(http.StatusOK, e.SUCCESS, topGoodses)
  79. }
  80. }
  81. // QueryHsbyListingGoodsDetailReq 查询二级市场(挂牌点选)商品信息详情请求参数
  82. type QueryHsbyListingGoodsDetailReq struct {
  83. GoodsID int `form:"goodsID" binding:"required"`
  84. }
  85. // QueryHsbyListingGoodsDetail 查询二级市场(挂牌点选)商品信息详情
  86. // @Summary 查询二级市场(挂牌点选)商品信息详情
  87. // @Produce json
  88. // @Security ApiKeyAuth
  89. // @Param goodsID query int true "商品ID"
  90. // @Success 200 {object} models.HsbyListingGoodsDetail
  91. // @Failure 500 {object} app.Response
  92. // @Router /HSBY/QueryHsbyListingGoodsDetail [get]
  93. // @Tags 定制【海商报业】
  94. func QueryHsbyListingGoodsDetail(c *gin.Context) {
  95. appG := app.Gin{C: c}
  96. // 获取请求参数
  97. var req QueryHsbyListingGoodsDetailReq
  98. if err := appG.C.ShouldBindQuery(&req); err != nil {
  99. logger.GetLogger().Errorf("QueryHsbyListingGoodsDetail failed: %s", err.Error())
  100. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  101. return
  102. }
  103. // 获取数据
  104. goodsInfo, err := models.GetHsbyListingGoodsDetail(req.GoodsID)
  105. if err != nil {
  106. // 查询失败
  107. logger.GetLogger().Errorf("QueryHsbyListingGoodsDetail failed: %s", err.Error())
  108. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  109. return
  110. }
  111. // 查询成功返回
  112. logger.GetLogger().Debugln("QueryHsbyListingGoodsDetail successed: %v", goodsInfo)
  113. appG.Response(http.StatusOK, e.SUCCESS, goodsInfo)
  114. }
  115. // QueryHsbyGoodsOrderDetailsReq 查询二级市场(挂牌点选)商品对应的挂牌委托单信息请求参数
  116. type QueryHsbyGoodsOrderDetailsReq struct {
  117. GoodsID int `form:"goodsID" binding:"required"`
  118. Number int `form:"number"`
  119. }
  120. // QueryHsbyGoodsOrderDetails 查询二级市场(挂牌点选)商品对应的挂牌委托单信息
  121. // @Summary 查询二级市场(挂牌点选)商品对应的挂牌委托单信息
  122. // @Description 说明:查询结果已按委托价格和委托时间排序; sellOrderDetails - 转让(卖出)单,buyOrderDetails - 求购(买入)单
  123. // @Produce json
  124. // @Security ApiKeyAuth
  125. // @Param goodsID query int true "商品ID"
  126. // @Param Number query int false "档位,不传则默认为3档"
  127. // @Success 200 {object} models.HsbyGoodsOrderDetail
  128. // @Failure 500 {object} app.Response
  129. // @Router /HSBY/QueryHsbyGoodsOrderDetails [get]
  130. // @Tags 定制【海商报业】
  131. func QueryHsbyGoodsOrderDetails(c *gin.Context) {
  132. appG := app.Gin{C: c}
  133. // 获取请求参数
  134. var req QueryHsbyGoodsOrderDetailsReq
  135. if err := appG.C.ShouldBindQuery(&req); err != nil {
  136. logger.GetLogger().Errorf("QueryHsbyGoodsOrderDetails failed: %s", err.Error())
  137. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  138. return
  139. }
  140. // 获取数据
  141. sellOrderDetails, buyOrderDetails, err := models.GetHsbyGoodsOrderDetails(req.GoodsID)
  142. if err != nil {
  143. // 查询失败
  144. logger.GetLogger().Errorf("QueryHsbyGoodsOrderDetails failed: %s", err.Error())
  145. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  146. return
  147. }
  148. // 按时间和价格排序
  149. sort.Slice(sellOrderDetails, func(i int, j int) bool {
  150. // 时间价格一样则按时间顺序排
  151. if sellOrderDetails[i].Orderprice == sellOrderDetails[j].Orderprice {
  152. return sellOrderDetails[i].Ordertime.Before(sellOrderDetails[j].Ordertime)
  153. }
  154. return sellOrderDetails[i].Orderprice < sellOrderDetails[j].Orderprice
  155. })
  156. sort.Slice(buyOrderDetails, func(i int, j int) bool {
  157. // 时间价格一样则按时间顺序排
  158. if buyOrderDetails[i].Orderprice == buyOrderDetails[j].Orderprice {
  159. return buyOrderDetails[i].Ordertime.Before(buyOrderDetails[j].Ordertime)
  160. }
  161. return buyOrderDetails[i].Orderprice > buyOrderDetails[j].Orderprice
  162. })
  163. // 取N档,默认3档
  164. if req.Number == 0 {
  165. req.Number = 3
  166. }
  167. // 判断结束下标是否越界
  168. sellEnd := req.Number
  169. if req.Number > len(sellOrderDetails) {
  170. sellEnd = len(sellOrderDetails)
  171. }
  172. sellOrderDetails = sellOrderDetails[0:sellEnd]
  173. buyEnd := req.Number
  174. if req.Number > len(buyOrderDetails) {
  175. buyEnd = len(buyOrderDetails)
  176. }
  177. buyOrderDetails = buyOrderDetails[0:buyEnd]
  178. // 结果集
  179. rst := make(map[string]interface{})
  180. rst["sellOrderDetails"] = sellOrderDetails
  181. rst["buyOrderDetails"] = buyOrderDetails
  182. // 查询成功返回
  183. logger.GetLogger().Debugln("QueryHsbyGoodsOrderDetails successed: %v", rst)
  184. appG.Response(http.StatusOK, e.SUCCESS, rst)
  185. }
  186. // QueryHsbyMyBuyOrderDetailsReq 查询“我的订单”信息请求参数
  187. type QueryHsbyMyBuyOrderDetailsReq struct {
  188. AccountID int `form:"accountID" binding:"required"`
  189. MyBuyStatus int `form:"myBuyStatus"`
  190. }
  191. // QueryHsbyMyBuyOrderDetails 查询“我的订单”信息
  192. // @Summary 查询“我的订单”信息
  193. // @Description 说明: 全部:一二级市场买委托;抢购中:一级市场买摘; 求购中:二级市场买挂; 3:已完成:一二级市场已完成买委托;
  194. // @Produce json
  195. // @Security ApiKeyAuth
  196. // @Param accountID query int true "资金账户"
  197. // @Param myBuyStatus query int false "'我的订单'状态, 1:抢购中 2:求购中 3:已完成;不传则为'全部'"
  198. // @Success 200 {object} models.HybsMyBuyOrderDetail
  199. // @Failure 500 {object} app.Response
  200. // @Router /HSBY/QueryHsbyMyBuyOrderDetails [get]
  201. // @Tags 定制【海商报业】
  202. func QueryHsbyMyBuyOrderDetails(c *gin.Context) {
  203. appG := app.Gin{C: c}
  204. // 获取请求参数
  205. var req QueryHsbyMyBuyOrderDetailsReq
  206. if err := appG.C.ShouldBindQuery(&req); err != nil {
  207. logger.GetLogger().Errorf("QueryHsbyMyBuyOrderDetails failed: %s", err.Error())
  208. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  209. return
  210. }
  211. // 获取数据
  212. myOrderDetails, err := models.GetHsbyBuyMyOrderDetails(req.AccountID, req.MyBuyStatus)
  213. if err != nil {
  214. // 查询失败
  215. logger.GetLogger().Errorf("QueryHsbyMyBuyOrderDetails failed: %s", err.Error())
  216. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  217. return
  218. }
  219. // 按时间排序
  220. sort.Slice(myOrderDetails, func(i int, j int) bool {
  221. return myOrderDetails[i].Ordertime.After(myOrderDetails[j].Ordertime)
  222. })
  223. // 查询成功返回
  224. logger.GetLogger().Debugln("QueryHsbyMyBuyOrderDetails successed: %v", myOrderDetails)
  225. appG.Response(http.StatusOK, e.SUCCESS, myOrderDetails)
  226. }