hsby.go 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387
  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. // QueryHsbyTopGoodsesReq 查询热门商品列表请求参数
  12. type QueryHsbyTopGoodsesReq struct {
  13. app.PageInfo
  14. MarketIDs string `form:"marketIDs" binding:"required"`
  15. DescProvinceID int `form:"descProvinceID"`
  16. DescCityID int `form:"descCityID"`
  17. }
  18. // QueryHsbyTopGoodses 查询热卖商品列表(二级市场挂牌点选)
  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 marketIDs query string true "市场ID列表,格式:1,2,3"
  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/QueryHsbyTopGoodses [get]
  31. // @Tags 定制【海商报业】
  32. func QueryHsbyTopGoodses(c *gin.Context) {
  33. appG := app.Gin{C: c}
  34. // 获取请求参数
  35. var req QueryHsbyTopGoodsesReq
  36. if err := appG.C.ShouldBindQuery(&req); err != nil {
  37. logger.GetLogger().Errorf("QueryHsbyTopGoodses failed: %s", err.Error())
  38. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  39. return
  40. }
  41. // 获取数据
  42. topGoodses, err := models.GetHsbyTopGoodses(req.MarketIDs, req.DescProvinceID, req.DescCityID)
  43. if err != nil {
  44. // 查询失败
  45. logger.GetLogger().Errorf("QueryHsbyTopGoodses 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("QueryHsbyTopGoodses 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("QueryHsbyTopGoodses 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. BuyOrSell int `form:"buyOrSell"`
  119. Price float64 `form:"price"`
  120. Speed int `form:"speed"`
  121. }
  122. // QueryHsbyGoodsOrderDetails 查询二级市场(挂牌点选)商品对应的挂牌委托单信息
  123. // @Summary 查询二级市场(挂牌点选)商品对应的挂牌委托单信息
  124. // @Description 说明:查询结果已按委托价格和委托时间排序; sellOrderDetails - 转让(卖出)单,buyOrderDetails - 求购(买入)单
  125. // @Produce json
  126. // @Security ApiKeyAuth
  127. // @Param goodsID query int true "商品ID"
  128. // @Param buyOrSell query int false "委托单方向。0:买 1:卖。不传则默认为买"
  129. // @Param price query number false " 参考价格。买方向委托单则价格大于等于(站在摘牌人的角度);卖方向委托单则价格小于等于"
  130. // @Param speed query int false "档位,不传则默认为3档"
  131. // @Success 200 {object} models.HsbyGoodsOrderDetail
  132. // @Failure 500 {object} app.Response
  133. // @Router /HSBY/QueryHsbyGoodsOrderDetails [get]
  134. // @Tags 定制【海商报业】
  135. func QueryHsbyGoodsOrderDetails(c *gin.Context) {
  136. appG := app.Gin{C: c}
  137. // 获取请求参数
  138. var req QueryHsbyGoodsOrderDetailsReq
  139. if err := appG.C.ShouldBindQuery(&req); err != nil {
  140. logger.GetLogger().Errorf("QueryHsbyGoodsOrderDetails failed: %s", err.Error())
  141. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  142. return
  143. }
  144. // 获取数据
  145. orderDetails, err := models.GetHsbyGoodsOrderDetails(req.GoodsID, req.BuyOrSell, req.Price)
  146. if err != nil {
  147. // 查询失败
  148. logger.GetLogger().Errorf("QueryHsbyGoodsOrderDetails failed: %s", err.Error())
  149. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  150. return
  151. }
  152. // 按时间和价格排序
  153. if req.BuyOrSell == 0 {
  154. // 买方向
  155. sort.Slice(orderDetails, func(i int, j int) bool {
  156. // 委托价格一样则按时间顺序排
  157. if orderDetails[i].Orderprice == orderDetails[j].Orderprice {
  158. return orderDetails[i].Ordertime.Before(orderDetails[j].Ordertime)
  159. }
  160. // 站在摘牌者的角度,买方向的委托单价格高的在前面
  161. return orderDetails[i].Orderprice > orderDetails[j].Orderprice
  162. })
  163. } else {
  164. // 卖方向
  165. sort.Slice(orderDetails, func(i int, j int) bool {
  166. // 委托价格一样则按时间顺序排
  167. if orderDetails[i].Orderprice == orderDetails[j].Orderprice {
  168. return orderDetails[i].Ordertime.Before(orderDetails[j].Ordertime)
  169. }
  170. return orderDetails[i].Orderprice < orderDetails[j].Orderprice
  171. })
  172. }
  173. // 取N档,默认3档
  174. if req.Speed == 0 {
  175. req.Speed = 3
  176. }
  177. // 判断结束下标是否越界
  178. end := req.Speed
  179. if req.Speed > len(orderDetails) {
  180. end = len(orderDetails)
  181. }
  182. orderDetails = orderDetails[0:end]
  183. // 查询成功返回
  184. logger.GetLogger().Debugln("QueryHsbyGoodsOrderDetails successed: %v", orderDetails)
  185. appG.Response(http.StatusOK, e.SUCCESS, orderDetails)
  186. }
  187. // QueryHsbyMyBuyOrderDetailsReq 查询“我的订单”信息请求参数
  188. type QueryHsbyMyBuyOrderDetailsReq struct {
  189. AccountIDs string `form:"accountIDs" binding:"required"`
  190. MyBuyStatus int `form:"myBuyStatus"`
  191. }
  192. // QueryHsbyMyBuyOrderDetails 查询“我的订单”信息
  193. // @Summary 查询“我的订单”信息
  194. // @Description 说明: 全部:一二级市场买委托;抢购中:一级市场买摘; 求购中:二级市场买挂; 3:已完成:一二级市场已完成买委托;
  195. // @Produce json
  196. // @Security ApiKeyAuth
  197. // @Param accountIDs query string true "资金账户列表,格式:1,2,3"
  198. // @Param myBuyStatus query int false "'我的订单'状态, 1:抢购中 2:求购中 3:已完成;不传则为'全部'"
  199. // @Success 200 {object} models.HybsMyBuyOrderDetail
  200. // @Failure 500 {object} app.Response
  201. // @Router /HSBY/QueryHsbyMyBuyOrderDetails [get]
  202. // @Tags 定制【海商报业】
  203. func QueryHsbyMyBuyOrderDetails(c *gin.Context) {
  204. appG := app.Gin{C: c}
  205. // 获取请求参数
  206. var req QueryHsbyMyBuyOrderDetailsReq
  207. if err := appG.C.ShouldBindQuery(&req); err != nil {
  208. logger.GetLogger().Errorf("QueryHsbyMyBuyOrderDetails failed: %s", err.Error())
  209. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  210. return
  211. }
  212. // 获取数据
  213. myOrderDetails, err := models.GetHsbyBuyMyOrderDetails(req.AccountIDs, req.MyBuyStatus)
  214. if err != nil {
  215. // 查询失败
  216. logger.GetLogger().Errorf("QueryHsbyMyBuyOrderDetails failed: %s", err.Error())
  217. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  218. return
  219. }
  220. // 按时间排序
  221. sort.Slice(myOrderDetails, func(i int, j int) bool {
  222. return myOrderDetails[i].Ordertime.After(myOrderDetails[j].Ordertime)
  223. })
  224. // 查询成功返回
  225. logger.GetLogger().Debugln("QueryHsbyMyBuyOrderDetails successed: %v", myOrderDetails)
  226. appG.Response(http.StatusOK, e.SUCCESS, myOrderDetails)
  227. }
  228. // QueryHsbyMyGoodsReq 查询“我的商品”请求参数
  229. type QueryHsbyMyGoodsReq struct {
  230. AccountIDs string `form:"accountIDs" binding:"required"`
  231. }
  232. // QueryHsbyMyGoods 查询“我的商品”信息
  233. // @Summary 查询“我的商品”信息
  234. // @Produce json
  235. // @Security ApiKeyAuth
  236. // @Param accountIDs query string true "资金账户列表,格式:1,2,3"
  237. // @Success 200 {object} models.HsbyMyGoods
  238. // @Failure 500 {object} app.Response
  239. // @Router /HSBY/QueryHsbyMyGoods [get]
  240. // @Tags 定制【海商报业】
  241. func QueryHsbyMyGoods(c *gin.Context) {
  242. appG := app.Gin{C: c}
  243. // 获取请求参数
  244. var req QueryHsbyMyGoodsReq
  245. if err := appG.C.ShouldBindQuery(&req); err != nil {
  246. logger.GetLogger().Errorf("QueryHsbyMyGoods failed: %s", err.Error())
  247. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  248. return
  249. }
  250. // 获取数据
  251. myGoodses, err := models.GetHsbyMyGoods(req.AccountIDs)
  252. if err != nil {
  253. // 查询失败
  254. logger.GetLogger().Errorf("QueryHsbyMyGoods failed: %s", err.Error())
  255. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  256. return
  257. }
  258. // 查询成功返回
  259. logger.GetLogger().Debugln("QueryHsbyMyGoods successed: %v", myGoodses)
  260. appG.Response(http.StatusOK, e.SUCCESS, myGoodses)
  261. }
  262. // QueryHsbyPreGoodsesReq 查询新品上市商品列表请求参数
  263. type QueryHsbyPreGoodsesReq struct {
  264. app.PageInfo
  265. MarketIDs string `form:"marketIDs" binding:"required"`
  266. DescProvinceID int `form:"descProvinceID"`
  267. DescCityID int `form:"descCityID"`
  268. }
  269. // QueryHsbyPreGoodses 查询新品上市商品列表(一级市场产能预售)
  270. // @Summary 查询新品上市商品列表(一级市场产能预售)
  271. // @Description 说明:结果已先显示已开始商品(按结束时间顺序排),再显示未开始商品(按开始时间顺序排)
  272. // @Produce json
  273. // @Security ApiKeyAuth
  274. // @Param page query int false "页码"
  275. // @Param pagesize query int false "每页条数"
  276. // @Param marketIDs query string true "市场ID列表,格式:1,2,3"
  277. // @Param DescProvinceID query int false "目的地(省)ID"
  278. // @Param DescCityID query int false "目的地(市)ID"
  279. // @Success 200 {object} models.HsbyPreGoods
  280. // @Failure 500 {object} app.Response
  281. // @Router /HSBY/QueryHsbyPreGoodses [get]
  282. // @Tags 定制【海商报业】
  283. func QueryHsbyPreGoodses(c *gin.Context) {
  284. appG := app.Gin{C: c}
  285. // 获取请求参数
  286. var req QueryHsbyPreGoodsesReq
  287. if err := appG.C.ShouldBindQuery(&req); err != nil {
  288. logger.GetLogger().Errorf("QueryHsbyPreGoodses failed: %s", err.Error())
  289. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  290. return
  291. }
  292. // 获取数据
  293. preGoodses, err := models.GetHsbyPreGoodses(req.MarketIDs, req.DescProvinceID, req.DescCityID)
  294. if err != nil {
  295. // 查询失败
  296. logger.GetLogger().Errorf("QueryHsbyPreGoodses failed: %s", err.Error())
  297. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  298. return
  299. }
  300. // 排序,先显示已开始商品(按结束时间顺序排),再显示未开始商品(按开始时间顺序排)
  301. sort.Slice(preGoodses, func(i int, j int) bool {
  302. if preGoodses[i].Goodsstatus == 3 && preGoodses[j].Goodsstatus == 2 {
  303. // 先显示已开始商品
  304. return true
  305. } else if preGoodses[i].Goodsstatus == 3 && preGoodses[j].Goodsstatus == 3 {
  306. // 已开始商品按结束时间顺序排
  307. return preGoodses[i].Endtime.After(preGoodses[j].Endtime)
  308. } else if preGoodses[i].Goodsstatus == 3 && preGoodses[j].Goodsstatus == 3 {
  309. // 未开始商品按开始时间顺序排
  310. return preGoodses[i].Starttime.After(preGoodses[j].Starttime)
  311. }
  312. return false
  313. })
  314. // 分页
  315. total := len(preGoodses)
  316. if req.PageSize > 0 {
  317. rstByPage := make([]models.HsbyPreGoods, 0)
  318. // 开始上标
  319. start := req.Page * req.PageSize
  320. // 结束下标
  321. end := start + req.PageSize
  322. if start <= len(preGoodses) {
  323. // 判断结束下标是否越界
  324. if end > len(preGoodses) {
  325. end = len(preGoodses)
  326. }
  327. rstByPage = preGoodses[start:end]
  328. } else {
  329. rstByPage = preGoodses[0:0]
  330. }
  331. preGoodses = rstByPage
  332. }
  333. // 查询成功返回
  334. if req.PageSize > 0 {
  335. logger.GetLogger().Debugln("QueryHsbyPreGoodses successed: %v", preGoodses)
  336. appG.ResponseByPage(http.StatusOK, e.SUCCESS, preGoodses, app.PageInfo{Page: req.Page, PageSize: req.PageSize, Total: total})
  337. } else {
  338. logger.GetLogger().Debugln("QueryHsbyPreGoodses successed: %v", preGoodses)
  339. appG.Response(http.StatusOK, e.SUCCESS, preGoodses)
  340. }
  341. }