hsby.go 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928
  1. package hsby
  2. import (
  3. "mtp2_if/global/app"
  4. "mtp2_if/global/e"
  5. "mtp2_if/logger"
  6. "mtp2_if/models"
  7. "mtp2_if/pb"
  8. "net/http"
  9. "sort"
  10. "github.com/gin-gonic/gin"
  11. "github.com/golang/protobuf/proto"
  12. )
  13. // QueryHsbyTopGoodsesReq 查询热门商品列表请求参数
  14. type QueryHsbyTopGoodsesReq struct {
  15. app.PageInfo
  16. MarketIDs string `form:"marketIDs" binding:"required"`
  17. DescProvinceID int `form:"descProvinceID"`
  18. DescCityID int `form:"descCityID"`
  19. }
  20. // QueryHsbyTopGoodses 查询热卖商品列表(二级市场挂牌点选)
  21. // @Summary 查询热卖商品列表(二级市场挂牌点选)
  22. // @Description 说明:查询结果已按Hotindex(景点热度)从大到小排序
  23. // @Produce json
  24. // @Security ApiKeyAuth
  25. // @Param page query int false "页码"
  26. // @Param pagesize query int false "每页条数"
  27. // @Param marketIDs query string true "市场ID列表,格式:1,2,3"
  28. // @Param descProvinceID query int false "目的地(省)ID"
  29. // @Param descCityID query int false "目的地(市)ID"
  30. // @Success 200 {object} models.HsbyTopGoods
  31. // @Failure 500 {object} app.Response
  32. // @Router /HSBY/QueryHsbyTopGoodses [get]
  33. // @Tags 定制【海商报业】
  34. func QueryHsbyTopGoodses(c *gin.Context) {
  35. appG := app.Gin{C: c}
  36. // 获取请求参数
  37. var req QueryHsbyTopGoodsesReq
  38. if err := appG.C.ShouldBindQuery(&req); err != nil {
  39. logger.GetLogger().Errorf("QueryHsbyTopGoodses failed: %s", err.Error())
  40. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  41. return
  42. }
  43. // 获取数据
  44. topGoodses, err := models.GetHsbyTopGoodses(req.MarketIDs, req.DescProvinceID, req.DescCityID)
  45. if err != nil {
  46. // 查询失败
  47. logger.GetLogger().Errorf("QueryHsbyTopGoodses failed: %s", err.Error())
  48. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  49. return
  50. }
  51. // 排序
  52. sort.Slice(topGoodses, func(i int, j int) bool {
  53. return topGoodses[i].Hotindex > topGoodses[j].Hotindex
  54. })
  55. // 分页
  56. total := len(topGoodses)
  57. if req.PageSize > 0 {
  58. rstByPage := make([]models.HsbyTopGoods, 0)
  59. // 开始上标
  60. start := req.Page * req.PageSize
  61. // 结束下标
  62. end := start + req.PageSize
  63. if start <= len(topGoodses) {
  64. // 判断结束下标是否越界
  65. if end > len(topGoodses) {
  66. end = len(topGoodses)
  67. }
  68. rstByPage = topGoodses[start:end]
  69. } else {
  70. rstByPage = topGoodses[0:0]
  71. }
  72. topGoodses = rstByPage
  73. }
  74. // 查询成功返回
  75. if req.PageSize > 0 {
  76. logger.GetLogger().Debugln("QueryHsbyTopGoodses successed: %v", topGoodses)
  77. appG.ResponseByPage(http.StatusOK, e.SUCCESS, topGoodses, app.PageInfo{Page: req.Page, PageSize: req.PageSize, Total: total})
  78. } else {
  79. logger.GetLogger().Debugln("QueryHsbyTopGoodses successed: %v", topGoodses)
  80. appG.Response(http.StatusOK, e.SUCCESS, topGoodses)
  81. }
  82. }
  83. // QueryHsbyListingGoodsDetailReq 查询二级市场(挂牌点选)商品信息详情请求参数
  84. type QueryHsbyListingGoodsDetailReq struct {
  85. GoodsID int `form:"goodsID" binding:"required"`
  86. AccountID int `form:"accountID"`
  87. }
  88. // QueryHsbyListingGoodsDetail 查询二级市场(挂牌点选)商品信息详情
  89. // @Summary 查询二级市场(挂牌点选)商品信息详情
  90. // @Produce json
  91. // @Security ApiKeyAuth
  92. // @Param goodsID query int true "商品ID"
  93. // @Param AccountID query int false "资金账户,主要用于获取交易规则。不传则获取通用规则。"
  94. // @Success 200 {object} models.HsbyListingGoodsDetail
  95. // @Failure 500 {object} app.Response
  96. // @Router /HSBY/QueryHsbyListingGoodsDetail [get]
  97. // @Tags 定制【海商报业】
  98. func QueryHsbyListingGoodsDetail(c *gin.Context) {
  99. appG := app.Gin{C: c}
  100. // 获取请求参数
  101. var req QueryHsbyListingGoodsDetailReq
  102. if err := appG.C.ShouldBindQuery(&req); err != nil {
  103. logger.GetLogger().Errorf("QueryHsbyListingGoodsDetail failed: %s", err.Error())
  104. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  105. return
  106. }
  107. // 获取数据
  108. goodsInfo, err := models.GetHsbyListingGoodsDetail(req.GoodsID)
  109. if err != nil {
  110. // 查询失败
  111. logger.GetLogger().Errorf("QueryHsbyListingGoodsDetail failed: %s", err.Error())
  112. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  113. return
  114. }
  115. // 获取交易规则
  116. rule, err := models.GetTodayAccountTradeRule(req.AccountID, req.GoodsID)
  117. if err != nil {
  118. // 查询失败
  119. logger.GetLogger().Errorf("QueryHsbyListingGoodsDetail failed: %s", err.Error())
  120. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  121. return
  122. }
  123. tradeRuleInfoStruct := &pb.TradeRuleInfoStruct{}
  124. if err := proto.Unmarshal([]byte(rule.Infocontent), tradeRuleInfoStruct); err != nil {
  125. // 查询失败
  126. logger.GetLogger().Errorf("QueryHsbyListingGoodsDetail failed: %s", err.Error())
  127. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  128. return
  129. }
  130. // INSERT INTO TRADERULEDESCRIPTION (RULEID, RULENAME, REGEXPRESS, DEFAULTVALUE, REMARK) VALUES (103, '单笔最小交易量', '^[1-9]\d*$', 1, '请输入正整数!');
  131. for _, v := range tradeRuleInfoStruct.TradeRules {
  132. if int(*v.RuleID) == 103 {
  133. goodsInfo.LotSize = int(*v.ParamValue)
  134. break
  135. }
  136. }
  137. // 查询成功返回
  138. logger.GetLogger().Debugln("QueryHsbyListingGoodsDetail successed: %v", goodsInfo)
  139. appG.Response(http.StatusOK, e.SUCCESS, goodsInfo)
  140. }
  141. // QueryHsbyGoodsOrderDetailsReq 查询二级市场(挂牌点选)商品对应的挂牌委托单信息请求参数
  142. type QueryHsbyGoodsOrderDetailsReq struct {
  143. GoodsID int `form:"goodsID" binding:"required"`
  144. AccountIDs string `form:"accountIDs" binding:"required"`
  145. BuyOrSell int `form:"buyOrSell"`
  146. Price float64 `form:"price"`
  147. Speed int `form:"speed"`
  148. }
  149. // QueryHsbyGoodsOrderDetails 查询二级市场(挂牌点选)商品对应的挂牌委托单信息
  150. // @Summary 查询二级市场(挂牌点选)商品对应的挂牌委托单信息
  151. // @Description 说明:查询结果已按委托价格和委托时间排序
  152. // @Produce json
  153. // @Security ApiKeyAuth
  154. // @Param goodsID query int true "商品ID"
  155. // @Param accountIDs query string true "摘牌方资金账户列表,格式:1,2,3。主要用于过滤自己的挂牌单"
  156. // @Param buyOrSell query int false "挂牌委托单方向(对手单方向),0:买 1:卖"
  157. // @Param price query number false " 参考价格。对手单买方向委托单则价格大于等于(站在摘牌人的角度,摘牌方面是卖,我的闲置下单);对手单卖方向委托单则价格小于等于(站在摘牌人的角度,摘牌方面是买,热门商品下单)"
  158. // @Param speed query int false "档位,不传则默认为3档"
  159. // @Success 200 {object} models.HsbyGoodsOrderDetail
  160. // @Failure 500 {object} app.Response
  161. // @Router /HSBY/QueryHsbyGoodsOrderDetails [get]
  162. // @Tags 定制【海商报业】
  163. func QueryHsbyGoodsOrderDetails(c *gin.Context) {
  164. appG := app.Gin{C: c}
  165. // 获取请求参数
  166. var req QueryHsbyGoodsOrderDetailsReq
  167. if err := appG.C.ShouldBindQuery(&req); err != nil {
  168. logger.GetLogger().Errorf("QueryHsbyGoodsOrderDetails failed: %s", err.Error())
  169. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  170. return
  171. }
  172. // 获取数据
  173. orderDetails, err := models.GetHsbyGoodsOrderDetails(req.GoodsID, req.BuyOrSell, req.Price, req.AccountIDs)
  174. if err != nil {
  175. // 查询失败
  176. logger.GetLogger().Errorf("QueryHsbyGoodsOrderDetails failed: %s", err.Error())
  177. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  178. return
  179. }
  180. // 按时间和价格排序
  181. if req.BuyOrSell == 0 {
  182. // 买方向
  183. sort.Slice(orderDetails, func(i int, j int) bool {
  184. // 委托价格一样则按时间顺序排
  185. if orderDetails[i].Orderprice == orderDetails[j].Orderprice {
  186. return orderDetails[i].Ordertime.Before(orderDetails[j].Ordertime)
  187. }
  188. // 站在摘牌者的角度,买方向的委托单价格高的在前面
  189. return orderDetails[i].Orderprice > orderDetails[j].Orderprice
  190. })
  191. } else {
  192. // 卖方向
  193. sort.Slice(orderDetails, func(i int, j int) bool {
  194. // 委托价格一样则按时间顺序排
  195. if orderDetails[i].Orderprice == orderDetails[j].Orderprice {
  196. return orderDetails[i].Ordertime.Before(orderDetails[j].Ordertime)
  197. }
  198. return orderDetails[i].Orderprice < orderDetails[j].Orderprice
  199. })
  200. }
  201. // 取N档,默认3档
  202. if req.Speed == 0 {
  203. req.Speed = 3
  204. }
  205. // 判断结束下标是否越界
  206. end := req.Speed
  207. if req.Speed > len(orderDetails) {
  208. end = len(orderDetails)
  209. }
  210. orderDetails = orderDetails[0:end]
  211. // 查询成功返回
  212. logger.GetLogger().Debugln("QueryHsbyGoodsOrderDetails successed: %v", orderDetails)
  213. appG.Response(http.StatusOK, e.SUCCESS, orderDetails)
  214. }
  215. // QueryHsbyMyBuyOrderDetailsReq 查询“我的订单”信息请求参数
  216. type QueryHsbyMyBuyOrderDetailsReq struct {
  217. AccountIDs string `form:"accountIDs" binding:"required"`
  218. MyBuyStatus int `form:"myBuyStatus"`
  219. }
  220. // QueryHsbyMyBuyOrderDetails 查询“我的订单”信息
  221. // @Summary 查询“我的订单”信息
  222. // @Description 说明: 全部:一二级市场买委托;抢购中:一级市场买摘; 求购中:二级市场买挂; 3:已完成:一二级市场已完成买委托;
  223. // @Produce json
  224. // @Security ApiKeyAuth
  225. // @Param accountIDs query string true "资金账户列表,格式:1,2,3"
  226. // @Param myBuyStatus query int false "'我的订单'状态, 1:抢购中 2:求购中 3:已完成;不传则为'全部'"
  227. // @Success 200 {object} models.HybsMyBuyOrderDetail
  228. // @Failure 500 {object} app.Response
  229. // @Router /HSBY/QueryHsbyMyBuyOrderDetails [get]
  230. // @Tags 定制【海商报业】
  231. func QueryHsbyMyBuyOrderDetails(c *gin.Context) {
  232. appG := app.Gin{C: c}
  233. // 获取请求参数
  234. var req QueryHsbyMyBuyOrderDetailsReq
  235. if err := appG.C.ShouldBindQuery(&req); err != nil {
  236. logger.GetLogger().Errorf("QueryHsbyMyBuyOrderDetails failed: %s", err.Error())
  237. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  238. return
  239. }
  240. // 获取数据
  241. myOrderDetails, err := models.GetHsbyBuyMyOrderDetails(req.AccountIDs, req.MyBuyStatus)
  242. if err != nil {
  243. // 查询失败
  244. logger.GetLogger().Errorf("QueryHsbyMyBuyOrderDetails failed: %s", err.Error())
  245. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  246. return
  247. }
  248. // 按时间排序
  249. sort.Slice(myOrderDetails, func(i int, j int) bool {
  250. return myOrderDetails[i].Ordertime.After(myOrderDetails[j].Ordertime)
  251. })
  252. // 查询成功返回
  253. logger.GetLogger().Debugln("QueryHsbyMyBuyOrderDetails successed: %v", myOrderDetails)
  254. appG.Response(http.StatusOK, e.SUCCESS, myOrderDetails)
  255. }
  256. // QueryHsbyMyGoodsReq 查询“我的商品”请求参数
  257. type QueryHsbyMyGoodsReq struct {
  258. AccountIDs string `form:"accountIDs" binding:"required"`
  259. }
  260. // QueryHsbyMyGoods 查询“我的商品”信息
  261. // @Summary 查询“我的商品”信息
  262. // @Produce json
  263. // @Security ApiKeyAuth
  264. // @Param accountIDs query string true "资金账户列表,格式:1,2,3"
  265. // @Success 200 {object} models.HsbyMyGoods
  266. // @Failure 500 {object} app.Response
  267. // @Router /HSBY/QueryHsbyMyGoods [get]
  268. // @Tags 定制【海商报业】
  269. func QueryHsbyMyGoods(c *gin.Context) {
  270. appG := app.Gin{C: c}
  271. // 获取请求参数
  272. var req QueryHsbyMyGoodsReq
  273. if err := appG.C.ShouldBindQuery(&req); err != nil {
  274. logger.GetLogger().Errorf("QueryHsbyMyGoods failed: %s", err.Error())
  275. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  276. return
  277. }
  278. // 获取数据
  279. myGoodses, err := models.GetHsbyMyGoods(req.AccountIDs)
  280. if err != nil {
  281. // 查询失败
  282. logger.GetLogger().Errorf("QueryHsbyMyGoods failed: %s", err.Error())
  283. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  284. return
  285. }
  286. // 查询成功返回
  287. logger.GetLogger().Debugln("QueryHsbyMyGoods successed: %v", myGoodses)
  288. appG.Response(http.StatusOK, e.SUCCESS, myGoodses)
  289. }
  290. // QueryHsbyPreGoodsesReq 查询新品上市商品列表请求参数
  291. type QueryHsbyPreGoodsesReq struct {
  292. app.PageInfo
  293. MarketIDs string `form:"marketIDs" binding:"required"`
  294. DescProvinceID int `form:"descProvinceID"`
  295. DescCityID int `form:"descCityID"`
  296. }
  297. // QueryHsbyPreGoodses 查询新品上市商品列表(一级市场产能预售)
  298. // @Summary 查询新品上市商品列表(一级市场产能预售)
  299. // @Description 说明:结果已先显示已开始商品(按结束时间顺序排),再显示未开始商品(按开始时间顺序排)
  300. // @Produce json
  301. // @Security ApiKeyAuth
  302. // @Param page query int false "页码"
  303. // @Param pagesize query int false "每页条数"
  304. // @Param marketIDs query string true "市场ID列表,格式:1,2,3"
  305. // @Param descProvinceID query int false "目的地(省)ID"
  306. // @Param descCityID query int false "目的地(市)ID"
  307. // @Success 200 {object} models.HsbyPreGoods
  308. // @Failure 500 {object} app.Response
  309. // @Router /HSBY/QueryHsbyPreGoodses [get]
  310. // @Tags 定制【海商报业】
  311. func QueryHsbyPreGoodses(c *gin.Context) {
  312. appG := app.Gin{C: c}
  313. // 获取请求参数
  314. var req QueryHsbyPreGoodsesReq
  315. if err := appG.C.ShouldBindQuery(&req); err != nil {
  316. logger.GetLogger().Errorf("QueryHsbyPreGoodses failed: %s", err.Error())
  317. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  318. return
  319. }
  320. // 获取数据
  321. preGoodses, err := models.GetHsbyPreGoodses(req.MarketIDs, req.DescProvinceID, req.DescCityID)
  322. if err != nil {
  323. // 查询失败
  324. logger.GetLogger().Errorf("QueryHsbyPreGoodses failed: %s", err.Error())
  325. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  326. return
  327. }
  328. // 排序,先显示已开始商品(按结束时间顺序排),再显示未开始商品(按开始时间顺序排)
  329. sort.Slice(preGoodses, func(i int, j int) bool {
  330. if preGoodses[i].Goodsstatus == 3 && preGoodses[j].Goodsstatus == 2 {
  331. // 先显示已开始商品
  332. return true
  333. } else if preGoodses[i].Goodsstatus == 3 && preGoodses[j].Goodsstatus == 3 {
  334. // 已开始商品按结束时间顺序排
  335. return preGoodses[i].Lasttradedate.Before(preGoodses[j].Lasttradedate)
  336. } else if preGoodses[i].Goodsstatus == 2 && preGoodses[j].Goodsstatus == 2 {
  337. // 未开始商品按开始时间顺序排
  338. return preGoodses[i].Listingdate.Before(preGoodses[j].Listingdate)
  339. }
  340. return false
  341. })
  342. // 分页
  343. total := len(preGoodses)
  344. if req.PageSize > 0 {
  345. rstByPage := make([]models.HsbyPreGoods, 0)
  346. // 开始上标
  347. start := req.Page * req.PageSize
  348. // 结束下标
  349. end := start + req.PageSize
  350. if start <= len(preGoodses) {
  351. // 判断结束下标是否越界
  352. if end > len(preGoodses) {
  353. end = len(preGoodses)
  354. }
  355. rstByPage = preGoodses[start:end]
  356. } else {
  357. rstByPage = preGoodses[0:0]
  358. }
  359. preGoodses = rstByPage
  360. }
  361. // 查询成功返回
  362. if req.PageSize > 0 {
  363. logger.GetLogger().Debugln("QueryHsbyPreGoodses successed: %v", preGoodses)
  364. appG.ResponseByPage(http.StatusOK, e.SUCCESS, preGoodses, app.PageInfo{Page: req.Page, PageSize: req.PageSize, Total: total})
  365. } else {
  366. logger.GetLogger().Debugln("QueryHsbyPreGoodses successed: %v", preGoodses)
  367. appG.Response(http.StatusOK, e.SUCCESS, preGoodses)
  368. }
  369. }
  370. // QueryHsbyPreGoodsDetailReq 查询一级市场(产能预售)商品信息详情请求参数
  371. type QueryHsbyPreGoodsDetailReq struct {
  372. GoodsID int `form:"goodsID" binding:"required"`
  373. AccountID int `form:"accountID" binding:"required"`
  374. }
  375. // QueryHsbyPreGoodsDetail 查询一级市场(产能预售)商品信息详情
  376. // @Summary 查询一级市场(产能预售)商品信息详情
  377. // @Produce json
  378. // @Security ApiKeyAuth
  379. // @Param goodsID query int true "商品ID"
  380. // @Param accountID query int true "资金账户,主要用于获取预售商品购买上限"
  381. // @Success 200 {object} models.HsbyPreGoodsDetail
  382. // @Failure 500 {object} app.Response
  383. // @Router /HSBY/QueryHsbyPreGoodsDetail [get]
  384. // @Tags 定制【海商报业】
  385. func QueryHsbyPreGoodsDetail(c *gin.Context) {
  386. appG := app.Gin{C: c}
  387. // 获取请求参数
  388. var req QueryHsbyPreGoodsDetailReq
  389. if err := appG.C.ShouldBindQuery(&req); err != nil {
  390. logger.GetLogger().Errorf("QueryHsbyPreGoodsDetail failed: %s", err.Error())
  391. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  392. return
  393. }
  394. // 获取数据
  395. goodsInfo, err := models.GetHsbyPreGoodsDetail(req.GoodsID, req.AccountID)
  396. if err != nil {
  397. // 查询失败
  398. logger.GetLogger().Errorf("QueryHsbyPreGoodsDetail failed: %s", err.Error())
  399. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  400. return
  401. }
  402. // 查询成功返回
  403. logger.GetLogger().Debugln("QueryHsbyPreGoodsDetail successed: %v", goodsInfo)
  404. appG.Response(http.StatusOK, e.SUCCESS, goodsInfo)
  405. }
  406. // QueryHsbySellMyDetailReq 查询"我的闲置"单据信息请求参数
  407. type QueryHsbySellMyDetailReq struct {
  408. app.PageInfo
  409. AccountIDs string `form:"accountIDs" binding:"required"`
  410. OrderType int `form:"orderType"`
  411. }
  412. // QueryHsbySellMyDetails 查询"我的闲置"单据信息
  413. // @Summary 查询"我的闲置"单据信息
  414. // @Description 说明:已发布 - 二级市场卖挂,3:委托成功、7:部分成交; 已完成 - 二级市场成交单,包括历史数据。查询结果已按时间从近到远排序
  415. // @Produce json
  416. // @Security ApiKeyAuth
  417. // @Param page query int false "页码"
  418. // @Param pagesize query int false "每页条数"
  419. // @Param accountIDs query string true "资金账户列表,格式:1,2,3"
  420. // @Param orderType query int false "单据类型:0 - 已发布(默认), 1 - 已完成"
  421. // @Success 200 {object} models.HsbySellMyDetail
  422. // @Failure 500 {object} app.Response
  423. // @Router /HSBY/QueryHsbySellMyDetails [get]
  424. // @Tags 定制【海商报业】
  425. func QueryHsbySellMyDetails(c *gin.Context) {
  426. appG := app.Gin{C: c}
  427. // 获取请求参数
  428. var req QueryHsbySellMyDetailReq
  429. if err := appG.C.ShouldBindQuery(&req); err != nil {
  430. logger.GetLogger().Errorf("QueryHsbySellMyDetails failed: %s", err.Error())
  431. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  432. return
  433. }
  434. // 获取数据
  435. var orders []models.HsbySellMyDetail
  436. if req.OrderType == 0 {
  437. // 已发布
  438. var err error
  439. orders, err = models.GetHsbySellMyOrderDetails(req.AccountIDs)
  440. if err != nil {
  441. // 查询失败
  442. logger.GetLogger().Errorf("QueryHsbySellMyDetails failed: %s", err.Error())
  443. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  444. return
  445. }
  446. } else {
  447. // 已完成
  448. var err error
  449. orders, err = models.GetHsbySellMyTradeDetails(req.AccountIDs)
  450. if err != nil {
  451. // 查询失败
  452. logger.GetLogger().Errorf("QueryHsbySellMyDetails failed: %s", err.Error())
  453. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  454. return
  455. }
  456. }
  457. // 排序
  458. sort.Slice(orders, func(i int, j int) bool {
  459. return orders[i].Time.After(orders[j].Time)
  460. })
  461. // 分页
  462. total := len(orders)
  463. if req.PageSize > 0 {
  464. rstByPage := make([]models.HsbySellMyDetail, 0)
  465. // 开始上标
  466. start := req.Page * req.PageSize
  467. // 结束下标
  468. end := start + req.PageSize
  469. if start <= len(orders) {
  470. // 判断结束下标是否越界
  471. if end > len(orders) {
  472. end = len(orders)
  473. }
  474. rstByPage = orders[start:end]
  475. } else {
  476. rstByPage = orders[0:0]
  477. }
  478. orders = rstByPage
  479. }
  480. // 查询成功返回
  481. if req.PageSize > 0 {
  482. logger.GetLogger().Debugln("QueryHsbySellMyDetails successed: %v", orders)
  483. appG.ResponseByPage(http.StatusOK, e.SUCCESS, orders, app.PageInfo{Page: req.Page, PageSize: req.PageSize, Total: total})
  484. } else {
  485. logger.GetLogger().Debugln("QueryHsbySellMyDetails successed: %v", orders)
  486. appG.Response(http.StatusOK, e.SUCCESS, orders)
  487. }
  488. }
  489. // QueryHsbyMyPackagesReq 查询我的包裹信息请求参数
  490. type QueryHsbyMyPackagesReq struct {
  491. AccountIDs string `form:"accountIDs" binding:"required"`
  492. TakeOrderStatus int `form:"takeOrderStatus"`
  493. }
  494. // QueryHsbyMyPackages 查询我的包裹信息
  495. // @Summary 查询我的包裹信息
  496. // @Produce json
  497. // @Security ApiKeyAuth
  498. // @Param accountIDs query string true "资金账户列表,格式:1,2,3"
  499. // @Param takeOrderStatus query int false "提货状态 - 1:待发货 2:已发货 3:已收货"
  500. // @Success 200 {object} models.HsbyMyPackage
  501. // @Failure 500 {object} app.Response
  502. // @Router /HSBY/QueryHsbyMyPackages [get]
  503. // @Tags 定制【海商报业】
  504. func QueryHsbyMyPackages(c *gin.Context) {
  505. appG := app.Gin{C: c}
  506. // 获取请求参数
  507. var req QueryHsbyMyPackagesReq
  508. if err := appG.C.ShouldBindQuery(&req); err != nil {
  509. logger.GetLogger().Errorf("QueryHsbyMyPackages failed: %s", err.Error())
  510. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  511. return
  512. }
  513. // 获取数据
  514. goodsInfo, err := models.GetHsbyMyPackages(req.AccountIDs, req.TakeOrderStatus)
  515. if err != nil {
  516. // 查询失败
  517. logger.GetLogger().Errorf("QueryHsbyMyPackages failed: %s", err.Error())
  518. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  519. return
  520. }
  521. // 查询成功返回
  522. logger.GetLogger().Debugln("QueryHsbyMyPackages successed: %v", goodsInfo)
  523. appG.Response(http.StatusOK, e.SUCCESS, goodsInfo)
  524. }
  525. // SetHsbyMyPackagesStatusReq 设置我的包裹已收货状态
  526. type SetHsbyMyPackagesStatusReq struct {
  527. TakeOrderID string `form:"takeOrderID" binding:"required"`
  528. AccountID int `form:"accountID" binding:"required"`
  529. }
  530. // SetHsbyMyPackagesStatus 设置我的包裹已收货状态
  531. // @Summary 设置我的包裹已收货状态
  532. // @Produce json
  533. // @Security ApiKeyAuth
  534. // @Param takeOrderID query string true "提货单号"
  535. // @Param accountID query int true "资金账号"
  536. // @Success 200 {object} app.Response
  537. // @Failure 500 {object} app.Response
  538. // @Router /HSBY/SetHsbyMyPackagesStatus [post]
  539. // @Tags 定制【海商报业】
  540. func SetHsbyMyPackagesStatus(c *gin.Context) {
  541. appG := app.Gin{C: c}
  542. // 获取请求参数
  543. var req SetHsbyMyPackagesStatusReq
  544. if err := appG.C.ShouldBind(&req); err != nil {
  545. logger.GetLogger().Errorf("SetHsbyMyPackagesStatus failed: %s", err.Error())
  546. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  547. return
  548. }
  549. // 3 - 已收货
  550. if err := models.SetHsbyMyPackagesStatus(req.TakeOrderID, req.AccountID, 3); err != nil {
  551. // 执行失败
  552. logger.GetLogger().Errorf("SetHsbyMyPackagesStatus failed: %s", err.Error())
  553. appG.Response(http.StatusBadRequest, e.ERROR_OPERATION_FAILED, nil)
  554. return
  555. }
  556. // 执行成功
  557. logger.GetLogger().Debugln("SetHsbyMyPackagesStatus successed: %v", "ok")
  558. appG.Response(http.StatusOK, e.SUCCESS, "")
  559. }
  560. // QueryProvincesAndCitiesReq 查询省市信息请求参数
  561. type QueryProvincesAndCitiesReq struct {
  562. ProvinceID int `form:"provinceID"` // 省ID
  563. }
  564. // QueryProvincesAndCitiesRsp 查询省市信息返回模型
  565. type QueryProvincesAndCitiesRsp struct {
  566. Province models.Division // 省
  567. Cities []models.Division // 市
  568. }
  569. // QueryProvincesAndCities 查询省市信息(不包括区)
  570. // @Summary 查询省市信息(不包括区)
  571. // @Description 查询结果只包括二级市场商品已关连的省市信息。
  572. // @Produce json
  573. // @Security ApiKeyAuth
  574. // @Param provinceID query int false "省ID"
  575. // @Success 200 {object} QueryProvincesAndCitiesRsp
  576. // @Failure 500 {object} app.Response
  577. // @Router /HSBY/QueryProvincesAndCities [get]
  578. // @Tags 定制【海商报业】
  579. func QueryProvincesAndCities(c *gin.Context) {
  580. appG := app.Gin{C: c}
  581. // 获取请求参数
  582. var req QueryProvincesAndCitiesReq
  583. if err := appG.C.ShouldBindQuery(&req); err != nil {
  584. logger.GetLogger().Errorf("QueryProvincesAndCities failed: %s", err.Error())
  585. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  586. return
  587. }
  588. // 获取省市信息
  589. provinces, err := models.GetHsbyProvincesAndCities(req.ProvinceID)
  590. if err != nil {
  591. // 查询失败
  592. logger.GetLogger().Errorf("QueryProvincesAndCities failed: %s", err.Error())
  593. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  594. return
  595. }
  596. // 分解省市数据
  597. // Golang Map元素取址问题: cannot assign to struct field XXXX in map
  598. // https://blog.csdn.net/makenothing/article/details/105037977
  599. pMap := make(map[string]*QueryProvincesAndCitiesRsp)
  600. // 构建省节点
  601. for _, v := range provinces {
  602. if v.Divisionlevel == "province" {
  603. pMap[v.Divisioncode] = &QueryProvincesAndCitiesRsp{Province: v, Cities: make([]models.Division, 0)}
  604. }
  605. }
  606. // 为省节点增加市信息
  607. for _, v := range provinces {
  608. if v.Divisionlevel == "city" {
  609. pMap[v.Parentcode].Cities = append(pMap[v.Parentcode].Cities, v)
  610. }
  611. }
  612. // map to slice
  613. rst := make([]QueryProvincesAndCitiesRsp, 0)
  614. for _, v := range pMap {
  615. rst = append(rst, *v)
  616. }
  617. // 查询成功
  618. logger.GetLogger().Debugln("QueryProvincesAndCities successed: %v", rst)
  619. appG.Response(http.StatusOK, e.SUCCESS, rst)
  620. }
  621. // QueryHsbyBuyMyTradeDetailReq 查询"我的订单 - 已完成"单据信息请求参数
  622. type QueryHsbyBuyMyTradeDetailReq struct {
  623. app.PageInfo
  624. AccountIDs string `form:"accountIDs" binding:"required"`
  625. }
  626. // QueryHsbyBuyMyTradeDetail 查询"我的订单 - 已完成"单据信息
  627. // @Summary 查询"我的订单 - 已完成"单据信息
  628. // @Produce json
  629. // @Security ApiKeyAuth
  630. // @Param page query int false "页码"
  631. // @Param pagesize query int false "每页条数"
  632. // @Param accountIDs query string true "资金账户列表,格式:1,2,3"
  633. // @Success 200 {object} models.HsbyBuyMyTradeDetail
  634. // @Failure 500 {object} app.Response
  635. // @Router /HSBY/QueryHsbyBuyMyTradeDetail [get]
  636. // @Tags 定制【海商报业】
  637. func QueryHsbyBuyMyTradeDetail(c *gin.Context) {
  638. appG := app.Gin{C: c}
  639. // 获取请求参数
  640. var req QueryHsbyBuyMyTradeDetailReq
  641. if err := appG.C.ShouldBindQuery(&req); err != nil {
  642. logger.GetLogger().Errorf("QueryHsbyBuyMyTradeDetail failed: %s", err.Error())
  643. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  644. return
  645. }
  646. // 获取数据
  647. var orders []models.HsbyBuyMyTradeDetail
  648. var err error
  649. orders, err = models.GetHsbyBuyMyTradeDetails(req.AccountIDs)
  650. if err != nil {
  651. // 查询失败
  652. logger.GetLogger().Errorf("QueryHsbyBuyMyTradeDetail failed: %s", err.Error())
  653. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  654. return
  655. }
  656. // 排序
  657. sort.Slice(orders, func(i int, j int) bool {
  658. return orders[i].Time.After(orders[j].Time)
  659. })
  660. // 分页
  661. total := len(orders)
  662. if req.PageSize > 0 {
  663. rstByPage := make([]models.HsbyBuyMyTradeDetail, 0)
  664. // 开始上标
  665. start := req.Page * req.PageSize
  666. // 结束下标
  667. end := start + req.PageSize
  668. if start <= len(orders) {
  669. // 判断结束下标是否越界
  670. if end > len(orders) {
  671. end = len(orders)
  672. }
  673. rstByPage = orders[start:end]
  674. } else {
  675. rstByPage = orders[0:0]
  676. }
  677. orders = rstByPage
  678. }
  679. // 查询成功返回
  680. if req.PageSize > 0 {
  681. logger.GetLogger().Debugln("QueryHsbyBuyMyTradeDetail successed: %v", orders)
  682. appG.ResponseByPage(http.StatusOK, e.SUCCESS, orders, app.PageInfo{Page: req.Page, PageSize: req.PageSize, Total: total})
  683. } else {
  684. logger.GetLogger().Debugln("QueryHsbyBuyMyTradeDetail successed: %v", orders)
  685. appG.Response(http.StatusOK, e.SUCCESS, orders)
  686. }
  687. }
  688. // GetHsbyMyCountReq 获取我的订单与包裹数量请求参数模型
  689. type GetHsbyMyCountReq struct {
  690. AccountIDs string `form:"accountIDs" binding:"required"`
  691. }
  692. // GetHsbyMyCountRsp 获取我的订单与包裹数量返回模型
  693. type GetHsbyMyCountRsp struct {
  694. MyOrderDetailPreCount int `json:"myOrderDetailPreCount"` // 我的订单抢购中数量
  695. MyOrderDetailListingCount int `json:"myOrderDetailListingCount"` // 我的订单求购中数量
  696. MyPackageUnSendCount int `json:"myPackageUnSendCount"` // 我的包裹待发货数量
  697. MyPackageUnReceiveCount int `json:"myPackageUnReceiveCount"` // 我的包裹待收货数量
  698. }
  699. // GetHsbyMyCount 获取我的订单与包裹数量
  700. // @Summary 获取我的订单与包裹数量
  701. // @Description 说明: 不包括已完成的数量。
  702. // @Produce json
  703. // @Security ApiKeyAuth
  704. // @Param accountIDs query string true "资金账户列表,格式:1,2,3"
  705. // @Success 200 {object} GetHsbyMyCountRsp
  706. // @Failure 500 {object} app.Response
  707. // @Router /HSBY/GetHsbyMyCount [get]
  708. // @Tags 定制【海商报业】
  709. func GetHsbyMyCount(c *gin.Context) {
  710. appG := app.Gin{C: c}
  711. // 获取请求参数
  712. var req GetHsbyMyCountReq
  713. if err := appG.C.ShouldBindQuery(&req); err != nil {
  714. logger.GetLogger().Errorf("GetHsbyMyCount failed: %s", err.Error())
  715. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  716. return
  717. }
  718. // 获取我的订单数据
  719. myOrderDetails, err := models.GetHsbyBuyMyOrderDetails(req.AccountIDs, 0)
  720. if err != nil {
  721. // 查询失败
  722. logger.GetLogger().Errorf("GetHsbyMyCount failed: %s", err.Error())
  723. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  724. return
  725. }
  726. // 获取数据
  727. myPackages, err := models.GetHsbyMyPackages(req.AccountIDs, 0)
  728. if err != nil {
  729. // 查询失败
  730. logger.GetLogger().Errorf("GetHsbyMyCount failed: %s", err.Error())
  731. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  732. return
  733. }
  734. // 统计数量
  735. rsp := GetHsbyMyCountRsp{}
  736. for _, v := range myOrderDetails {
  737. if v.MyBuyStatus == 1 {
  738. // 抢购中
  739. rsp.MyOrderDetailPreCount++
  740. } else if v.MyBuyStatus == 2 {
  741. // 求购中
  742. rsp.MyOrderDetailListingCount++
  743. }
  744. }
  745. for _, v := range myPackages {
  746. if v.Takeorderstatus == 1 {
  747. // 待发货
  748. rsp.MyPackageUnSendCount++
  749. } else if v.Takeorderstatus == 2 {
  750. // 待收货
  751. rsp.MyPackageUnReceiveCount++
  752. }
  753. }
  754. // 查询成功返回
  755. logger.GetLogger().Debugln("GetHsbyMyCount successed: %v", rsp)
  756. appG.Response(http.StatusOK, e.SUCCESS, rsp)
  757. }
  758. // QueryTradePayOrdersReq 待付款信息查询请求参数
  759. type QueryTradePayOrdersReq struct {
  760. app.PageInfo
  761. AccountIDs string `form:"accountIDs" binding:"required"`
  762. }
  763. // QueryTradePayOrders 获取待付款信息
  764. // @Summary 获取待付款信息
  765. // @Produce json
  766. // @Security ApiKeyAuth
  767. // @Param page query int false "页码"
  768. // @Param pagesize query int false "每页条数"
  769. // @Param accountIDs query string true "资金账户列表,格式:1,2,3"
  770. // @Param buyOrderID query int false "买方委托单号"
  771. // @Success 200 {object} models.HsbyBuyMyPayOrder
  772. // @Failure 500 {object} app.Response
  773. // @Router /HSBY/QueryTradePayOrders [get]
  774. // @Tags 定制【海商报业】
  775. func QueryTradePayOrders(c *gin.Context) {
  776. appG := app.Gin{C: c}
  777. // 获取请求参数
  778. var req QueryTradePayOrdersReq
  779. if err := appG.C.ShouldBindQuery(&req); err != nil {
  780. logger.GetLogger().Errorf("QueryTradePayOrders failed: %s", err.Error())
  781. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  782. return
  783. }
  784. // 获取数据
  785. orders, err := models.GetHsbyBuyMyPayOrders(req.AccountIDs)
  786. if err != nil {
  787. // 查询失败
  788. logger.GetLogger().Errorf("QueryTradePayOrders failed: %s", err.Error())
  789. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  790. return
  791. }
  792. // 排序
  793. sort.Slice(orders, func(i int, j int) bool {
  794. return orders[i].Createtime.Before(orders[j].Createtime)
  795. })
  796. // 分页
  797. total := len(orders)
  798. if req.PageSize > 0 {
  799. rstByPage := make([]models.HsbyBuyMyPayOrder, 0)
  800. // 开始上标
  801. start := req.Page * req.PageSize
  802. // 结束下标
  803. end := start + req.PageSize
  804. if start <= len(orders) {
  805. // 判断结束下标是否越界
  806. if end > len(orders) {
  807. end = len(orders)
  808. }
  809. rstByPage = orders[start:end]
  810. } else {
  811. rstByPage = orders[0:0]
  812. }
  813. orders = rstByPage
  814. }
  815. // 查询成功返回
  816. if req.PageSize > 0 {
  817. logger.GetLogger().Debugln("QueryTradePayOrders successed: %v", orders)
  818. appG.ResponseByPage(http.StatusOK, e.SUCCESS, orders, app.PageInfo{Page: req.Page, PageSize: req.PageSize, Total: total})
  819. } else {
  820. logger.GetLogger().Debugln("QueryTradePayOrders successed: %v", orders)
  821. appG.Response(http.StatusOK, e.SUCCESS, orders)
  822. }
  823. }