hsby.go 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670
  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. AccountIDs string `form:"accountIDs" binding:"required"`
  119. BuyOrSell int `form:"buyOrSell"`
  120. Price float64 `form:"price"`
  121. Speed int `form:"speed"`
  122. }
  123. // QueryHsbyGoodsOrderDetails 查询二级市场(挂牌点选)商品对应的挂牌委托单信息
  124. // @Summary 查询二级市场(挂牌点选)商品对应的挂牌委托单信息
  125. // @Description 说明:查询结果已按委托价格和委托时间排序
  126. // @Produce json
  127. // @Security ApiKeyAuth
  128. // @Param goodsID query int true "商品ID"
  129. // @Param accountIDs query string true "摘牌方资金账户列表,格式:1,2,3。主要用于过滤自己的挂牌单"
  130. // @Param buyOrSell query int false "委托单方向。0:买 1:卖。不传则默认为买"
  131. // @Param price query number false " 参考价格。买方向委托单则价格小于等于(站在摘牌人的角度);卖方向委托单则价格大于等于"
  132. // @Param speed query int false "档位,不传则默认为3档"
  133. // @Success 200 {object} models.HsbyGoodsOrderDetail
  134. // @Failure 500 {object} app.Response
  135. // @Router /HSBY/QueryHsbyGoodsOrderDetails [get]
  136. // @Tags 定制【海商报业】
  137. func QueryHsbyGoodsOrderDetails(c *gin.Context) {
  138. appG := app.Gin{C: c}
  139. // 获取请求参数
  140. var req QueryHsbyGoodsOrderDetailsReq
  141. if err := appG.C.ShouldBindQuery(&req); err != nil {
  142. logger.GetLogger().Errorf("QueryHsbyGoodsOrderDetails failed: %s", err.Error())
  143. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  144. return
  145. }
  146. // 获取数据
  147. orderDetails, err := models.GetHsbyGoodsOrderDetails(req.GoodsID, req.BuyOrSell, req.Price, req.AccountIDs)
  148. if err != nil {
  149. // 查询失败
  150. logger.GetLogger().Errorf("QueryHsbyGoodsOrderDetails failed: %s", err.Error())
  151. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  152. return
  153. }
  154. // 按时间和价格排序
  155. if req.BuyOrSell == 0 {
  156. // 买方向
  157. sort.Slice(orderDetails, func(i int, j int) bool {
  158. // 委托价格一样则按时间顺序排
  159. if orderDetails[i].Orderprice == orderDetails[j].Orderprice {
  160. return orderDetails[i].Ordertime.Before(orderDetails[j].Ordertime)
  161. }
  162. // 站在摘牌者的角度,买方向的委托单价格高的在前面
  163. return orderDetails[i].Orderprice > orderDetails[j].Orderprice
  164. })
  165. } else {
  166. // 卖方向
  167. sort.Slice(orderDetails, func(i int, j int) bool {
  168. // 委托价格一样则按时间顺序排
  169. if orderDetails[i].Orderprice == orderDetails[j].Orderprice {
  170. return orderDetails[i].Ordertime.Before(orderDetails[j].Ordertime)
  171. }
  172. return orderDetails[i].Orderprice < orderDetails[j].Orderprice
  173. })
  174. }
  175. // 取N档,默认3档
  176. if req.Speed == 0 {
  177. req.Speed = 3
  178. }
  179. // 判断结束下标是否越界
  180. end := req.Speed
  181. if req.Speed > len(orderDetails) {
  182. end = len(orderDetails)
  183. }
  184. orderDetails = orderDetails[0:end]
  185. // 查询成功返回
  186. logger.GetLogger().Debugln("QueryHsbyGoodsOrderDetails successed: %v", orderDetails)
  187. appG.Response(http.StatusOK, e.SUCCESS, orderDetails)
  188. }
  189. // QueryHsbyMyBuyOrderDetailsReq 查询“我的订单”信息请求参数
  190. type QueryHsbyMyBuyOrderDetailsReq struct {
  191. AccountIDs string `form:"accountIDs" binding:"required"`
  192. MyBuyStatus int `form:"myBuyStatus"`
  193. }
  194. // QueryHsbyMyBuyOrderDetails 查询“我的订单”信息
  195. // @Summary 查询“我的订单”信息
  196. // @Description 说明: 全部:一二级市场买委托;抢购中:一级市场买摘; 求购中:二级市场买挂; 3:已完成:一二级市场已完成买委托;
  197. // @Produce json
  198. // @Security ApiKeyAuth
  199. // @Param accountIDs query string true "资金账户列表,格式:1,2,3"
  200. // @Param myBuyStatus query int false "'我的订单'状态, 1:抢购中 2:求购中 3:已完成;不传则为'全部'"
  201. // @Success 200 {object} models.HybsMyBuyOrderDetail
  202. // @Failure 500 {object} app.Response
  203. // @Router /HSBY/QueryHsbyMyBuyOrderDetails [get]
  204. // @Tags 定制【海商报业】
  205. func QueryHsbyMyBuyOrderDetails(c *gin.Context) {
  206. appG := app.Gin{C: c}
  207. // 获取请求参数
  208. var req QueryHsbyMyBuyOrderDetailsReq
  209. if err := appG.C.ShouldBindQuery(&req); err != nil {
  210. logger.GetLogger().Errorf("QueryHsbyMyBuyOrderDetails failed: %s", err.Error())
  211. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  212. return
  213. }
  214. // 获取数据
  215. myOrderDetails, err := models.GetHsbyBuyMyOrderDetails(req.AccountIDs, req.MyBuyStatus)
  216. if err != nil {
  217. // 查询失败
  218. logger.GetLogger().Errorf("QueryHsbyMyBuyOrderDetails failed: %s", err.Error())
  219. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  220. return
  221. }
  222. // 按时间排序
  223. sort.Slice(myOrderDetails, func(i int, j int) bool {
  224. return myOrderDetails[i].Ordertime.After(myOrderDetails[j].Ordertime)
  225. })
  226. // 查询成功返回
  227. logger.GetLogger().Debugln("QueryHsbyMyBuyOrderDetails successed: %v", myOrderDetails)
  228. appG.Response(http.StatusOK, e.SUCCESS, myOrderDetails)
  229. }
  230. // QueryHsbyMyGoodsReq 查询“我的商品”请求参数
  231. type QueryHsbyMyGoodsReq struct {
  232. AccountIDs string `form:"accountIDs" binding:"required"`
  233. }
  234. // QueryHsbyMyGoods 查询“我的商品”信息
  235. // @Summary 查询“我的商品”信息
  236. // @Produce json
  237. // @Security ApiKeyAuth
  238. // @Param accountIDs query string true "资金账户列表,格式:1,2,3"
  239. // @Success 200 {object} models.HsbyMyGoods
  240. // @Failure 500 {object} app.Response
  241. // @Router /HSBY/QueryHsbyMyGoods [get]
  242. // @Tags 定制【海商报业】
  243. func QueryHsbyMyGoods(c *gin.Context) {
  244. appG := app.Gin{C: c}
  245. // 获取请求参数
  246. var req QueryHsbyMyGoodsReq
  247. if err := appG.C.ShouldBindQuery(&req); err != nil {
  248. logger.GetLogger().Errorf("QueryHsbyMyGoods failed: %s", err.Error())
  249. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  250. return
  251. }
  252. // 获取数据
  253. myGoodses, err := models.GetHsbyMyGoods(req.AccountIDs)
  254. if err != nil {
  255. // 查询失败
  256. logger.GetLogger().Errorf("QueryHsbyMyGoods failed: %s", err.Error())
  257. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  258. return
  259. }
  260. // 查询成功返回
  261. logger.GetLogger().Debugln("QueryHsbyMyGoods successed: %v", myGoodses)
  262. appG.Response(http.StatusOK, e.SUCCESS, myGoodses)
  263. }
  264. // QueryHsbyPreGoodsesReq 查询新品上市商品列表请求参数
  265. type QueryHsbyPreGoodsesReq struct {
  266. app.PageInfo
  267. MarketIDs string `form:"marketIDs" binding:"required"`
  268. DescProvinceID int `form:"descProvinceID"`
  269. DescCityID int `form:"descCityID"`
  270. }
  271. // QueryHsbyPreGoodses 查询新品上市商品列表(一级市场产能预售)
  272. // @Summary 查询新品上市商品列表(一级市场产能预售)
  273. // @Description 说明:结果已先显示已开始商品(按结束时间顺序排),再显示未开始商品(按开始时间顺序排)
  274. // @Produce json
  275. // @Security ApiKeyAuth
  276. // @Param page query int false "页码"
  277. // @Param pagesize query int false "每页条数"
  278. // @Param marketIDs query string true "市场ID列表,格式:1,2,3"
  279. // @Param DescProvinceID query int false "目的地(省)ID"
  280. // @Param DescCityID query int false "目的地(市)ID"
  281. // @Success 200 {object} models.HsbyPreGoods
  282. // @Failure 500 {object} app.Response
  283. // @Router /HSBY/QueryHsbyPreGoodses [get]
  284. // @Tags 定制【海商报业】
  285. func QueryHsbyPreGoodses(c *gin.Context) {
  286. appG := app.Gin{C: c}
  287. // 获取请求参数
  288. var req QueryHsbyPreGoodsesReq
  289. if err := appG.C.ShouldBindQuery(&req); err != nil {
  290. logger.GetLogger().Errorf("QueryHsbyPreGoodses failed: %s", err.Error())
  291. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  292. return
  293. }
  294. // 获取数据
  295. preGoodses, err := models.GetHsbyPreGoodses(req.MarketIDs, req.DescProvinceID, req.DescCityID)
  296. if err != nil {
  297. // 查询失败
  298. logger.GetLogger().Errorf("QueryHsbyPreGoodses failed: %s", err.Error())
  299. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  300. return
  301. }
  302. // 排序,先显示已开始商品(按结束时间顺序排),再显示未开始商品(按开始时间顺序排)
  303. sort.Slice(preGoodses, func(i int, j int) bool {
  304. if preGoodses[i].Goodsstatus == 3 && preGoodses[j].Goodsstatus == 2 {
  305. // 先显示已开始商品
  306. return true
  307. } else if preGoodses[i].Goodsstatus == 3 && preGoodses[j].Goodsstatus == 3 {
  308. // 已开始商品按结束时间顺序排
  309. return preGoodses[i].Endtime.Before(preGoodses[j].Endtime)
  310. } else if preGoodses[i].Goodsstatus == 2 && preGoodses[j].Goodsstatus == 2 {
  311. // 未开始商品按开始时间顺序排
  312. return preGoodses[i].Starttime.Before(preGoodses[j].Starttime)
  313. }
  314. return false
  315. })
  316. // 分页
  317. total := len(preGoodses)
  318. if req.PageSize > 0 {
  319. rstByPage := make([]models.HsbyPreGoods, 0)
  320. // 开始上标
  321. start := req.Page * req.PageSize
  322. // 结束下标
  323. end := start + req.PageSize
  324. if start <= len(preGoodses) {
  325. // 判断结束下标是否越界
  326. if end > len(preGoodses) {
  327. end = len(preGoodses)
  328. }
  329. rstByPage = preGoodses[start:end]
  330. } else {
  331. rstByPage = preGoodses[0:0]
  332. }
  333. preGoodses = rstByPage
  334. }
  335. // 查询成功返回
  336. if req.PageSize > 0 {
  337. logger.GetLogger().Debugln("QueryHsbyPreGoodses successed: %v", preGoodses)
  338. appG.ResponseByPage(http.StatusOK, e.SUCCESS, preGoodses, app.PageInfo{Page: req.Page, PageSize: req.PageSize, Total: total})
  339. } else {
  340. logger.GetLogger().Debugln("QueryHsbyPreGoodses successed: %v", preGoodses)
  341. appG.Response(http.StatusOK, e.SUCCESS, preGoodses)
  342. }
  343. }
  344. // QueryHsbyPreGoodsDetailReq 查询一级市场(产能预售)商品信息详情请求参数
  345. type QueryHsbyPreGoodsDetailReq struct {
  346. GoodsID int `form:"goodsID" binding:"required"`
  347. }
  348. // QueryHsbyPreGoodsDetail 查询一级市场(产能预售)商品信息详情
  349. // @Summary 查询一级市场(产能预售)商品信息详情
  350. // @Produce json
  351. // @Security ApiKeyAuth
  352. // @Param goodsID query int true "商品ID"
  353. // @Success 200 {object} models.HsbyPreGoodsDetail
  354. // @Failure 500 {object} app.Response
  355. // @Router /HSBY/QueryHsbyPreGoodsDetail [get]
  356. // @Tags 定制【海商报业】
  357. func QueryHsbyPreGoodsDetail(c *gin.Context) {
  358. appG := app.Gin{C: c}
  359. // 获取请求参数
  360. var req QueryHsbyPreGoodsDetailReq
  361. if err := appG.C.ShouldBindQuery(&req); err != nil {
  362. logger.GetLogger().Errorf("QueryHsbyPreGoodsDetail failed: %s", err.Error())
  363. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  364. return
  365. }
  366. // 获取数据
  367. goodsInfo, err := models.GetHsbyPreGoodsDetail(req.GoodsID)
  368. if err != nil {
  369. // 查询失败
  370. logger.GetLogger().Errorf("QueryHsbyPreGoodsDetail failed: %s", err.Error())
  371. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  372. return
  373. }
  374. // 查询成功返回
  375. logger.GetLogger().Debugln("QueryHsbyPreGoodsDetail successed: %v", goodsInfo)
  376. appG.Response(http.StatusOK, e.SUCCESS, goodsInfo)
  377. }
  378. // QueryHsbySellMyDetailReq 查询"我的闲置"单据信息请求参数
  379. type QueryHsbySellMyDetailReq struct {
  380. app.PageInfo
  381. AccountIDs string `form:"accountIDs" binding:"required"`
  382. OrderType int `form:"orderType"`
  383. }
  384. // QueryHsbySellMyDetails 查询"我的闲置"单据信息
  385. // @Summary 查询"我的闲置"单据信息
  386. // @Description 说明:已发布 - 二级市场卖挂,3:委托成功、7:部分成交; 已完成 - 二级市场成交单,包括历史数据。查询结果已按时间从近到远排序
  387. // @Produce json
  388. // @Security ApiKeyAuth
  389. // @Param page query int false "页码"
  390. // @Param pagesize query int false "每页条数"
  391. // @Param accountIDs query string true "资金账户列表,格式:1,2,3"
  392. // @Param orderType query int false "单据类型:0 - 已发布(默认), 1 - 已完成"
  393. // @Success 200 {object} models.HsbySellMyDetail
  394. // @Failure 500 {object} app.Response
  395. // @Router /HSBY/QueryHsbySellMyDetails [get]
  396. // @Tags 定制【海商报业】
  397. func QueryHsbySellMyDetails(c *gin.Context) {
  398. appG := app.Gin{C: c}
  399. // 获取请求参数
  400. var req QueryHsbySellMyDetailReq
  401. if err := appG.C.ShouldBindQuery(&req); err != nil {
  402. logger.GetLogger().Errorf("QueryHsbySellMyDetails failed: %s", err.Error())
  403. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  404. return
  405. }
  406. // 获取数据
  407. var orders []models.HsbySellMyDetail
  408. if req.OrderType == 0 {
  409. // 已发布
  410. var err error
  411. orders, err = models.GetHsbySellMyOrderDetails(req.AccountIDs)
  412. if err != nil {
  413. // 查询失败
  414. logger.GetLogger().Errorf("QueryHsbySellMyDetails failed: %s", err.Error())
  415. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  416. return
  417. }
  418. } else {
  419. // 已完成
  420. var err error
  421. orders, err = models.GetHsbySellMyTradeDetails(req.AccountIDs)
  422. if err != nil {
  423. // 查询失败
  424. logger.GetLogger().Errorf("QueryHsbySellMyDetails failed: %s", err.Error())
  425. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  426. return
  427. }
  428. }
  429. // 排序
  430. sort.Slice(orders, func(i int, j int) bool {
  431. return orders[i].Time.After(orders[j].Time)
  432. })
  433. // 分页
  434. total := len(orders)
  435. if req.PageSize > 0 {
  436. rstByPage := make([]models.HsbySellMyDetail, 0)
  437. // 开始上标
  438. start := req.Page * req.PageSize
  439. // 结束下标
  440. end := start + req.PageSize
  441. if start <= len(orders) {
  442. // 判断结束下标是否越界
  443. if end > len(orders) {
  444. end = len(orders)
  445. }
  446. rstByPage = orders[start:end]
  447. } else {
  448. rstByPage = orders[0:0]
  449. }
  450. orders = rstByPage
  451. }
  452. // 查询成功返回
  453. if req.PageSize > 0 {
  454. logger.GetLogger().Debugln("QueryHsbySellMyDetails successed: %v", orders)
  455. appG.ResponseByPage(http.StatusOK, e.SUCCESS, orders, app.PageInfo{Page: req.Page, PageSize: req.PageSize, Total: total})
  456. } else {
  457. logger.GetLogger().Debugln("QueryHsbySellMyDetails successed: %v", orders)
  458. appG.Response(http.StatusOK, e.SUCCESS, orders)
  459. }
  460. }
  461. // QueryHsbyMyPackagesReq 查询我的包裹信息请求参数
  462. type QueryHsbyMyPackagesReq struct {
  463. AccountIDs string `form:"accountIDs" binding:"required"`
  464. TakeOrderStatus int `form:"takeOrderStatus"`
  465. }
  466. // QueryHsbyMyPackages 查询我的包裹信息
  467. // @Summary 查询我的包裹信息
  468. // @Produce json
  469. // @Security ApiKeyAuth
  470. // @Param accountIDs query string true "资金账户列表,格式:1,2,3"
  471. // @Param takeOrderStatus query int false "提货状态 - 1:待发货 2:已发货 3:已收货"
  472. // @Success 200 {object} models.HsbyMyPackage
  473. // @Failure 500 {object} app.Response
  474. // @Router /HSBY/QueryHsbyMyPackages [get]
  475. // @Tags 定制【海商报业】
  476. func QueryHsbyMyPackages(c *gin.Context) {
  477. appG := app.Gin{C: c}
  478. // 获取请求参数
  479. var req QueryHsbyMyPackagesReq
  480. if err := appG.C.ShouldBindQuery(&req); err != nil {
  481. logger.GetLogger().Errorf("QueryHsbyMyPackages failed: %s", err.Error())
  482. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  483. return
  484. }
  485. // 获取数据
  486. goodsInfo, err := models.GetHsbyMyPackages(req.AccountIDs, req.TakeOrderStatus)
  487. if err != nil {
  488. // 查询失败
  489. logger.GetLogger().Errorf("QueryHsbyMyPackages failed: %s", err.Error())
  490. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  491. return
  492. }
  493. // 查询成功返回
  494. logger.GetLogger().Debugln("QueryHsbyMyPackages successed: %v", goodsInfo)
  495. appG.Response(http.StatusOK, e.SUCCESS, goodsInfo)
  496. }
  497. // SetHsbyMyPackagesStatusReq 设置我的包裹已收货状态
  498. type SetHsbyMyPackagesStatusReq struct {
  499. TakeOrderID string `form:"takeOrderID" binding:"required"`
  500. AccountID int `form:"accountID" binding:"required"`
  501. }
  502. // SetHsbyMyPackagesStatus 设置我的包裹已收货状态
  503. // @Summary 设置我的包裹已收货状态
  504. // @Produce json
  505. // @Security ApiKeyAuth
  506. // @Param takeOrderID query string true "提货单号"
  507. // @Param accountID query int true "资金账号"
  508. // @Success 200 {object} app.Response
  509. // @Failure 500 {object} app.Response
  510. // @Router /HSBY/SetHsbyMyPackagesStatus [post]
  511. // @Tags 定制【海商报业】
  512. func SetHsbyMyPackagesStatus(c *gin.Context) {
  513. appG := app.Gin{C: c}
  514. // 获取请求参数
  515. var req SetHsbyMyPackagesStatusReq
  516. if err := appG.C.ShouldBind(&req); err != nil {
  517. logger.GetLogger().Errorf("SetHsbyMyPackagesStatus failed: %s", err.Error())
  518. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  519. return
  520. }
  521. // 3 - 已收货
  522. if err := models.SetHsbyMyPackagesStatus(req.TakeOrderID, req.AccountID, 3); err != nil {
  523. // 执行失败
  524. logger.GetLogger().Errorf("SetHsbyMyPackagesStatus failed: %s", err.Error())
  525. appG.Response(http.StatusBadRequest, e.ERROR_OPERATION_FAILED, nil)
  526. return
  527. }
  528. // 执行成功
  529. logger.GetLogger().Debugln("SetHsbyMyPackagesStatus successed: %v", "ok")
  530. appG.Response(http.StatusOK, e.SUCCESS, "")
  531. }
  532. // QueryProvincesAndCitiesReq 查询省市信息请求参数
  533. type QueryProvincesAndCitiesReq struct {
  534. ProvinceID int `form:"provinceID"` // 省ID
  535. }
  536. // QueryProvincesAndCitiesRsp 查询省市信息返回模型
  537. type QueryProvincesAndCitiesRsp struct {
  538. Province models.Division // 省
  539. Cities []models.Division // 市
  540. }
  541. // QueryProvincesAndCities 查询省市信息(不包括区)
  542. // @Summary 查询省市信息(不包括区)
  543. // @Description 查询结果只包括二级市场商品已关连的省市信息。
  544. // @Produce json
  545. // @Security ApiKeyAuth
  546. // @Param provinceID query int false "省ID"
  547. // @Success 200 {object} QueryProvincesAndCitiesRsp
  548. // @Failure 500 {object} app.Response
  549. // @Router /HSBY/QueryProvincesAndCities [get]
  550. // @Tags 定制【海商报业】
  551. func QueryProvincesAndCities(c *gin.Context) {
  552. appG := app.Gin{C: c}
  553. // 获取请求参数
  554. var req QueryProvincesAndCitiesReq
  555. if err := appG.C.ShouldBindQuery(&req); err != nil {
  556. logger.GetLogger().Errorf("QueryProvincesAndCities failed: %s", err.Error())
  557. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  558. return
  559. }
  560. // 获取省市信息
  561. provinces, err := models.GetHsbyProvincesAndCities(req.ProvinceID)
  562. if err != nil {
  563. // 查询失败
  564. logger.GetLogger().Errorf("QueryProvincesAndCities failed: %s", err.Error())
  565. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  566. return
  567. }
  568. // 分解省市数据
  569. // Golang Map元素取址问题: cannot assign to struct field XXXX in map
  570. // https://blog.csdn.net/makenothing/article/details/105037977
  571. pMap := make(map[string]*QueryProvincesAndCitiesRsp)
  572. // 构建省节点
  573. for _, v := range provinces {
  574. if v.Divisionlevel == "province" {
  575. pMap[v.Divisioncode] = &QueryProvincesAndCitiesRsp{Province: v, Cities: make([]models.Division, 0)}
  576. }
  577. }
  578. // 为省节点增加市信息
  579. for _, v := range provinces {
  580. if v.Divisionlevel == "city" {
  581. pMap[v.Parentcode].Cities = append(pMap[v.Parentcode].Cities, v)
  582. }
  583. }
  584. // map to slice
  585. rst := make([]QueryProvincesAndCitiesRsp, 0)
  586. for _, v := range pMap {
  587. rst = append(rst, *v)
  588. }
  589. // 查询成功
  590. logger.GetLogger().Debugln("QueryProvincesAndCities successed: %v", rst)
  591. appG.Response(http.StatusOK, e.SUCCESS, rst)
  592. }