hsby.go 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245
  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. // @Description 说明:“我的商品”详情中,二级(挂牌点选)和三级(商城)的商品详情都使用此接口
  91. // @Produce json
  92. // @Security ApiKeyAuth
  93. // @Param goodsID query int true "商品ID"
  94. // @Param AccountID query int false "资金账户,主要用于获取交易规则。不传则获取通用规则。"
  95. // @Success 200 {object} models.HsbyListingGoodsDetail
  96. // @Failure 500 {object} app.Response
  97. // @Router /HSBY/QueryHsbyListingGoodsDetail [get]
  98. // @Tags 定制【海商报业】
  99. func QueryHsbyListingGoodsDetail(c *gin.Context) {
  100. appG := app.Gin{C: c}
  101. // 获取请求参数
  102. var req QueryHsbyListingGoodsDetailReq
  103. if err := appG.C.ShouldBindQuery(&req); err != nil {
  104. logger.GetLogger().Errorf("QueryHsbyListingGoodsDetail failed: %s", err.Error())
  105. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  106. return
  107. }
  108. // 获取数据
  109. goodsInfo, err := models.GetHsbyListingGoodsDetail(req.GoodsID)
  110. if err != nil {
  111. // 查询失败
  112. logger.GetLogger().Errorf("QueryHsbyListingGoodsDetail failed: %s", err.Error())
  113. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  114. return
  115. }
  116. // 获取交易规则
  117. rule, err := models.GetTodayAccountTradeRule(req.AccountID, req.GoodsID)
  118. if err != nil {
  119. // 查询失败
  120. logger.GetLogger().Errorf("QueryHsbyListingGoodsDetail failed: %s", err.Error())
  121. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  122. return
  123. }
  124. if rule != nil {
  125. tradeRuleInfoStruct := &pb.TradeRuleInfoStruct{}
  126. if err := proto.Unmarshal([]byte(rule.Infocontent), tradeRuleInfoStruct); err != nil {
  127. // 查询失败
  128. logger.GetLogger().Errorf("QueryHsbyListingGoodsDetail failed: %s", err.Error())
  129. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  130. return
  131. }
  132. // INSERT INTO TRADERULEDESCRIPTION (RULEID, RULENAME, REGEXPRESS, DEFAULTVALUE, REMARK) VALUES (103, '单笔最小交易量', '^[1-9]\d*$', 1, '请输入正整数!');
  133. for _, v := range tradeRuleInfoStruct.TradeRules {
  134. if int(*v.RuleID) == 103 {
  135. goodsInfo.LotSize = int(*v.ParamValue)
  136. break
  137. }
  138. }
  139. }
  140. // 查询成功返回
  141. logger.GetLogger().Debugln("QueryHsbyListingGoodsDetail successed: %v", goodsInfo)
  142. appG.Response(http.StatusOK, e.SUCCESS, goodsInfo)
  143. }
  144. // QueryHsbyGoodsOrderDetailsReq 查询二级市场(挂牌点选)商品对应的挂牌委托单信息请求参数
  145. type QueryHsbyGoodsOrderDetailsReq struct {
  146. GoodsID int `form:"goodsID" binding:"required"`
  147. AccountIDs string `form:"accountIDs"`
  148. BuyOrSell int `form:"buyOrSell"`
  149. Price float64 `form:"price"`
  150. Speed int `form:"speed"`
  151. }
  152. // QueryHsbyGoodsOrderDetails 查询二级市场(挂牌点选)商品对应的挂牌委托单信息
  153. // @Summary 查询二级市场(挂牌点选)商品对应的挂牌委托单信息
  154. // @Description 说明:查询结果已按委托价格和委托时间排序
  155. // @Produce json
  156. // @Security ApiKeyAuth
  157. // @Param goodsID query int true "商品ID"
  158. // @Param accountIDs query string false "摘牌方资金账户列表,格式:1,2,3。主要用于过滤自己的挂牌单"
  159. // @Param buyOrSell query int false "挂牌委托单方向(对手单方向),0:买 1:卖"
  160. // @Param price query number false " 参考价格。对手单买方向委托单则价格大于等于(站在摘牌人的角度,摘牌方面是卖,我的闲置下单);对手单卖方向委托单则价格小于等于(站在摘牌人的角度,摘牌方面是买,热门商品下单)"
  161. // @Param speed query int false "档位,不传则默认为3档"
  162. // @Success 200 {object} models.HsbyGoodsOrderDetail
  163. // @Failure 500 {object} app.Response
  164. // @Router /HSBY/QueryHsbyGoodsOrderDetails [get]
  165. // @Tags 定制【海商报业】
  166. func QueryHsbyGoodsOrderDetails(c *gin.Context) {
  167. appG := app.Gin{C: c}
  168. // 获取请求参数
  169. var req QueryHsbyGoodsOrderDetailsReq
  170. if err := appG.C.ShouldBindQuery(&req); err != nil {
  171. logger.GetLogger().Errorf("QueryHsbyGoodsOrderDetails failed: %s", err.Error())
  172. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  173. return
  174. }
  175. // 获取数据
  176. orderDetails, err := models.GetHsbyGoodsOrderDetails(req.GoodsID, req.BuyOrSell, req.Price, req.AccountIDs)
  177. if err != nil {
  178. // 查询失败
  179. logger.GetLogger().Errorf("QueryHsbyGoodsOrderDetails failed: %s", err.Error())
  180. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  181. return
  182. }
  183. // 按时间和价格排序
  184. if req.BuyOrSell == 0 {
  185. // 买方向
  186. sort.Slice(orderDetails, func(i int, j int) bool {
  187. // 委托价格一样则按时间顺序排
  188. if orderDetails[i].Orderprice == orderDetails[j].Orderprice {
  189. return orderDetails[i].Ordertime.Before(orderDetails[j].Ordertime)
  190. }
  191. // 站在摘牌者的角度,买方向的委托单价格高的在前面
  192. return orderDetails[i].Orderprice > orderDetails[j].Orderprice
  193. })
  194. } else {
  195. // 卖方向
  196. sort.Slice(orderDetails, func(i int, j int) bool {
  197. // 委托价格一样则按时间顺序排
  198. if orderDetails[i].Orderprice == orderDetails[j].Orderprice {
  199. return orderDetails[i].Ordertime.Before(orderDetails[j].Ordertime)
  200. }
  201. return orderDetails[i].Orderprice < orderDetails[j].Orderprice
  202. })
  203. }
  204. // 取N档,默认3档
  205. if req.Speed == 0 {
  206. req.Speed = 3
  207. }
  208. // 判断结束下标是否越界
  209. end := req.Speed
  210. if req.Speed > len(orderDetails) {
  211. end = len(orderDetails)
  212. }
  213. orderDetails = orderDetails[0:end]
  214. // 查询成功返回
  215. logger.GetLogger().Debugln("QueryHsbyGoodsOrderDetails successed: %v", orderDetails)
  216. appG.Response(http.StatusOK, e.SUCCESS, orderDetails)
  217. }
  218. // QueryHsbyMyBuyOrderDetailsReq 查询“我的订单”信息请求参数
  219. type QueryHsbyMyBuyOrderDetailsReq struct {
  220. AccountIDs string `form:"accountIDs" binding:"required"`
  221. MyBuyStatus int `form:"myBuyStatus"`
  222. }
  223. // QueryHsbyMyBuyOrderDetails 查询“我的订单”信息
  224. // @Summary 查询“我的订单”信息
  225. // @Description 说明: 全部:一二级市场买委托;抢购中:一级市场买摘; 求购中:二级市场买挂; 3:已完成:一二级市场已完成买委托;
  226. // @Produce json
  227. // @Security ApiKeyAuth
  228. // @Param accountIDs query string true "资金账户列表,格式:1,2,3"
  229. // @Param myBuyStatus query int false "'我的订单'状态, 1:抢购中 2:求购中 3:已完成;不传则为'全部'"
  230. // @Success 200 {object} models.HybsMyBuyOrderDetail
  231. // @Failure 500 {object} app.Response
  232. // @Router /HSBY/QueryHsbyMyBuyOrderDetails [get]
  233. // @Tags 定制【海商报业】
  234. func QueryHsbyMyBuyOrderDetails(c *gin.Context) {
  235. appG := app.Gin{C: c}
  236. // 获取请求参数
  237. var req QueryHsbyMyBuyOrderDetailsReq
  238. if err := appG.C.ShouldBindQuery(&req); err != nil {
  239. logger.GetLogger().Errorf("QueryHsbyMyBuyOrderDetails failed: %s", err.Error())
  240. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  241. return
  242. }
  243. // 获取数据
  244. myOrderDetails, err := models.GetHsbyBuyMyOrderDetails(req.AccountIDs, req.MyBuyStatus)
  245. if err != nil {
  246. // 查询失败
  247. logger.GetLogger().Errorf("QueryHsbyMyBuyOrderDetails failed: %s", err.Error())
  248. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  249. return
  250. }
  251. // 按时间排序
  252. sort.Slice(myOrderDetails, func(i int, j int) bool {
  253. return myOrderDetails[i].Ordertime.After(myOrderDetails[j].Ordertime)
  254. })
  255. // 查询成功返回
  256. logger.GetLogger().Debugln("QueryHsbyMyBuyOrderDetails successed: %v", myOrderDetails)
  257. appG.Response(http.StatusOK, e.SUCCESS, myOrderDetails)
  258. }
  259. // QueryHsbyMyGoodsReq 查询“我的商品”请求参数
  260. type QueryHsbyMyGoodsReq struct {
  261. AccountIDs string `form:"accountIDs" binding:"required"`
  262. }
  263. // QueryHsbyMyGoods 查询“我的商品”信息
  264. // @Summary 查询“我的商品”信息
  265. // @Produce json
  266. // @Security ApiKeyAuth
  267. // @Param accountIDs query string true "资金账户列表,格式:1,2,3"
  268. // @Success 200 {object} models.HsbyMyGoods
  269. // @Failure 500 {object} app.Response
  270. // @Router /HSBY/QueryHsbyMyGoods [get]
  271. // @Tags 定制【海商报业】
  272. func QueryHsbyMyGoods(c *gin.Context) {
  273. appG := app.Gin{C: c}
  274. // 获取请求参数
  275. var req QueryHsbyMyGoodsReq
  276. if err := appG.C.ShouldBindQuery(&req); err != nil {
  277. logger.GetLogger().Errorf("QueryHsbyMyGoods failed: %s", err.Error())
  278. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  279. return
  280. }
  281. // 获取数据
  282. myGoodses, err := models.GetHsbyMyGoods(req.AccountIDs)
  283. if err != nil {
  284. // 查询失败
  285. logger.GetLogger().Errorf("QueryHsbyMyGoods failed: %s", err.Error())
  286. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  287. return
  288. }
  289. // 查询成功返回
  290. logger.GetLogger().Debugln("QueryHsbyMyGoods successed: %v", myGoodses)
  291. appG.Response(http.StatusOK, e.SUCCESS, myGoodses)
  292. }
  293. // QueryHsbyPreGoodsesReq 查询新品上市商品列表请求参数
  294. type QueryHsbyPreGoodsesReq struct {
  295. app.PageInfo
  296. MarketIDs string `form:"marketIDs" binding:"required"`
  297. DescProvinceID int `form:"descProvinceID"`
  298. DescCityID int `form:"descCityID"`
  299. }
  300. // QueryHsbyPreGoodses 查询新品上市商品列表(一级市场预售)
  301. // @Summary 查询新品上市商品列表(一级市场预售)
  302. // @Description 说明:结果已先显示已开始商品(按结束时间顺序排),再显示未开始商品(按开始时间顺序排)
  303. // @Produce json
  304. // @Security ApiKeyAuth
  305. // @Param page query int false "页码"
  306. // @Param pagesize query int false "每页条数"
  307. // @Param marketIDs query string true "市场ID列表,格式:1,2,3"
  308. // @Param descProvinceID query int false "目的地(省)ID"
  309. // @Param descCityID query int false "目的地(市)ID"
  310. // @Success 200 {object} models.HsbyPreGoods
  311. // @Failure 500 {object} app.Response
  312. // @Router /HSBY/QueryHsbyPreGoodses [get]
  313. // @Tags 定制【海商报业】
  314. func QueryHsbyPreGoodses(c *gin.Context) {
  315. appG := app.Gin{C: c}
  316. // 获取请求参数
  317. var req QueryHsbyPreGoodsesReq
  318. if err := appG.C.ShouldBindQuery(&req); err != nil {
  319. logger.GetLogger().Errorf("QueryHsbyPreGoodses failed: %s", err.Error())
  320. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  321. return
  322. }
  323. // 获取数据
  324. preGoodses, err := models.GetHsbyPreGoodses(req.MarketIDs, req.DescProvinceID, req.DescCityID)
  325. if err != nil {
  326. // 查询失败
  327. logger.GetLogger().Errorf("QueryHsbyPreGoodses failed: %s", err.Error())
  328. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  329. return
  330. }
  331. // 排序,先显示已开始商品(按结束时间顺序排),再显示未开始商品(按开始时间顺序排)
  332. sort.Slice(preGoodses, func(i int, j int) bool {
  333. if preGoodses[i].Goodsstatus == 3 && preGoodses[j].Goodsstatus == 2 {
  334. // 先显示已开始商品
  335. return true
  336. } else if preGoodses[i].Goodsstatus == 3 && preGoodses[j].Goodsstatus == 3 {
  337. // 已开始商品按结束时间顺序排
  338. return preGoodses[i].Lasttradedate.Before(preGoodses[j].Lasttradedate)
  339. } else if preGoodses[i].Goodsstatus == 2 && preGoodses[j].Goodsstatus == 2 {
  340. // 未开始商品按开始时间顺序排
  341. return preGoodses[i].Listingdate.Before(preGoodses[j].Listingdate)
  342. }
  343. return false
  344. })
  345. // 分页
  346. total := len(preGoodses)
  347. if req.PageSize > 0 {
  348. rstByPage := make([]models.HsbyPreGoods, 0)
  349. // 开始上标
  350. start := req.Page * req.PageSize
  351. // 结束下标
  352. end := start + req.PageSize
  353. if start <= len(preGoodses) {
  354. // 判断结束下标是否越界
  355. if end > len(preGoodses) {
  356. end = len(preGoodses)
  357. }
  358. rstByPage = preGoodses[start:end]
  359. } else {
  360. rstByPage = preGoodses[0:0]
  361. }
  362. preGoodses = rstByPage
  363. }
  364. // 查询成功返回
  365. if req.PageSize > 0 {
  366. logger.GetLogger().Debugln("QueryHsbyPreGoodses successed: %v", preGoodses)
  367. appG.ResponseByPage(http.StatusOK, e.SUCCESS, preGoodses, app.PageInfo{Page: req.Page, PageSize: req.PageSize, Total: total})
  368. } else {
  369. logger.GetLogger().Debugln("QueryHsbyPreGoodses successed: %v", preGoodses)
  370. appG.Response(http.StatusOK, e.SUCCESS, preGoodses)
  371. }
  372. }
  373. // QueryHsbyPreGoodsDetailReq 查询一级市场(预售)商品信息详情请求参数
  374. type QueryHsbyPreGoodsDetailReq struct {
  375. GoodsID int `form:"goodsID" binding:"required"`
  376. AccountID int `form:"accountID"`
  377. }
  378. // QueryHsbyPreGoodsDetail 查询一级市场(预售)商品信息详情
  379. // @Summary 查询一级市场(预售)商品信息详情
  380. // @Produce json
  381. // @Security ApiKeyAuth
  382. // @Param goodsID query int true "商品ID"
  383. // @Param accountID query int false "资金账户,主要用于获取预售商品购买上限"
  384. // @Success 200 {object} models.HsbyPreGoodsDetail
  385. // @Failure 500 {object} app.Response
  386. // @Router /HSBY/QueryHsbyPreGoodsDetail [get]
  387. // @Tags 定制【海商报业】
  388. func QueryHsbyPreGoodsDetail(c *gin.Context) {
  389. appG := app.Gin{C: c}
  390. // 获取请求参数
  391. var req QueryHsbyPreGoodsDetailReq
  392. if err := appG.C.ShouldBindQuery(&req); err != nil {
  393. logger.GetLogger().Errorf("QueryHsbyPreGoodsDetail failed: %s", err.Error())
  394. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  395. return
  396. }
  397. // 获取数据
  398. goodsInfo, err := models.GetHsbyPreGoodsDetail(req.GoodsID, req.AccountID)
  399. if err != nil {
  400. // 查询失败
  401. logger.GetLogger().Errorf("QueryHsbyPreGoodsDetail failed: %s", err.Error())
  402. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  403. return
  404. }
  405. // 查询成功返回
  406. logger.GetLogger().Debugln("QueryHsbyPreGoodsDetail successed: %v", goodsInfo)
  407. appG.Response(http.StatusOK, e.SUCCESS, goodsInfo)
  408. }
  409. // QueryHsbySellMyDetailReq 查询"我的闲置"单据信息请求参数
  410. type QueryHsbySellMyDetailReq struct {
  411. app.PageInfo
  412. AccountIDs string `form:"accountIDs" binding:"required"`
  413. OrderType int `form:"orderType"`
  414. }
  415. // QueryHsbySellMyDetails 查询"我的闲置"单据信息
  416. // @Summary 查询"我的闲置"单据信息
  417. // @Description 说明:发布中 - 二级市场卖挂,3:委托成功、7:部分成交; 已完成 - 二级市场成交单,包括历史数据。查询结果已按时间从近到远排序
  418. // @Produce json
  419. // @Security ApiKeyAuth
  420. // @Param page query int false "页码"
  421. // @Param pagesize query int false "每页条数"
  422. // @Param accountIDs query string true "资金账户列表,格式:1,2,3"
  423. // @Param orderType query int false "单据类型:0 - 发布中(默认), 1 - 已完成"
  424. // @Success 200 {object} models.HsbySellMyDetail
  425. // @Failure 500 {object} app.Response
  426. // @Router /HSBY/QueryHsbySellMyDetails [get]
  427. // @Tags 定制【海商报业】
  428. func QueryHsbySellMyDetails(c *gin.Context) {
  429. appG := app.Gin{C: c}
  430. // 获取请求参数
  431. var req QueryHsbySellMyDetailReq
  432. if err := appG.C.ShouldBindQuery(&req); err != nil {
  433. logger.GetLogger().Errorf("QueryHsbySellMyDetails failed: %s", err.Error())
  434. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  435. return
  436. }
  437. // 获取数据
  438. var orders []models.HsbySellMyDetail
  439. if req.OrderType == 0 {
  440. // 发布中
  441. var err error
  442. orders, err = models.GetHsbySellMyOrderDetails(req.AccountIDs)
  443. if err != nil {
  444. // 查询失败
  445. logger.GetLogger().Errorf("QueryHsbySellMyDetails failed: %s", err.Error())
  446. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  447. return
  448. }
  449. } else {
  450. // 已完成
  451. var err error
  452. orders, err = models.GetHsbySellMyTradeDetails(req.AccountIDs)
  453. if err != nil {
  454. // 查询失败
  455. logger.GetLogger().Errorf("QueryHsbySellMyDetails failed: %s", err.Error())
  456. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  457. return
  458. }
  459. }
  460. // 排序
  461. sort.Slice(orders, func(i int, j int) bool {
  462. return orders[i].Time.After(orders[j].Time)
  463. })
  464. // 分页
  465. total := len(orders)
  466. if req.PageSize > 0 {
  467. rstByPage := make([]models.HsbySellMyDetail, 0)
  468. // 开始上标
  469. start := req.Page * req.PageSize
  470. // 结束下标
  471. end := start + req.PageSize
  472. if start <= len(orders) {
  473. // 判断结束下标是否越界
  474. if end > len(orders) {
  475. end = len(orders)
  476. }
  477. rstByPage = orders[start:end]
  478. } else {
  479. rstByPage = orders[0:0]
  480. }
  481. orders = rstByPage
  482. }
  483. // 查询成功返回
  484. if req.PageSize > 0 {
  485. logger.GetLogger().Debugln("QueryHsbySellMyDetails successed: %v", orders)
  486. appG.ResponseByPage(http.StatusOK, e.SUCCESS, orders, app.PageInfo{Page: req.Page, PageSize: req.PageSize, Total: total})
  487. } else {
  488. logger.GetLogger().Debugln("QueryHsbySellMyDetails successed: %v", orders)
  489. appG.Response(http.StatusOK, e.SUCCESS, orders)
  490. }
  491. }
  492. // QueryHsbyMyPackagesReq 查询我的包裹信息请求参数
  493. type QueryHsbyMyPackagesReq struct {
  494. AccountIDs string `form:"accountIDs" binding:"required"`
  495. TakeOrderStatus int `form:"takeOrderStatus"`
  496. }
  497. // QueryHsbyMyPackages 查询我的包裹信息
  498. // @Summary 查询我的包裹信息
  499. // @Produce json
  500. // @Security ApiKeyAuth
  501. // @Param accountIDs query string true "资金账户列表,格式:1,2,3"
  502. // @Param takeOrderStatus query int false "提货状态 - 1:待发货 2:已发货 3:已收货"
  503. // @Success 200 {object} models.HsbyMyPackage
  504. // @Failure 500 {object} app.Response
  505. // @Router /HSBY/QueryHsbyMyPackages [get]
  506. // @Tags 定制【海商报业】
  507. func QueryHsbyMyPackages(c *gin.Context) {
  508. appG := app.Gin{C: c}
  509. // 获取请求参数
  510. var req QueryHsbyMyPackagesReq
  511. if err := appG.C.ShouldBindQuery(&req); err != nil {
  512. logger.GetLogger().Errorf("QueryHsbyMyPackages failed: %s", err.Error())
  513. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  514. return
  515. }
  516. // 获取数据
  517. goodsInfo, err := models.GetHsbyMyPackages(req.AccountIDs, req.TakeOrderStatus)
  518. if err != nil {
  519. // 查询失败
  520. logger.GetLogger().Errorf("QueryHsbyMyPackages failed: %s", err.Error())
  521. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  522. return
  523. }
  524. // 查询成功返回
  525. logger.GetLogger().Debugln("QueryHsbyMyPackages successed: %v", goodsInfo)
  526. appG.Response(http.StatusOK, e.SUCCESS, goodsInfo)
  527. }
  528. // SetHsbyMyPackagesStatusReq 设置我的包裹已收货状态
  529. type SetHsbyMyPackagesStatusReq struct {
  530. TakeOrderID string `form:"takeOrderID" binding:"required"`
  531. AccountID int `form:"accountID" binding:"required"`
  532. }
  533. // SetHsbyMyPackagesStatus 设置我的包裹已收货状态
  534. // @Summary 设置我的包裹已收货状态
  535. // @Produce json
  536. // @Security ApiKeyAuth
  537. // @Param takeOrderID query string true "提货单号"
  538. // @Param accountID query int true "资金账号"
  539. // @Success 200 {object} app.Response
  540. // @Failure 500 {object} app.Response
  541. // @Router /HSBY/SetHsbyMyPackagesStatus [post]
  542. // @Tags 定制【海商报业】
  543. func SetHsbyMyPackagesStatus(c *gin.Context) {
  544. appG := app.Gin{C: c}
  545. // 获取请求参数
  546. var req SetHsbyMyPackagesStatusReq
  547. if err := appG.C.ShouldBind(&req); err != nil {
  548. logger.GetLogger().Errorf("SetHsbyMyPackagesStatus failed: %s", err.Error())
  549. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  550. return
  551. }
  552. // 3 - 已收货
  553. if err := models.SetHsbyMyPackagesStatus(req.TakeOrderID, req.AccountID, 3); err != nil {
  554. // 执行失败
  555. logger.GetLogger().Errorf("SetHsbyMyPackagesStatus failed: %s", err.Error())
  556. appG.Response(http.StatusBadRequest, e.ERROR_OPERATION_FAILED, nil)
  557. return
  558. }
  559. // 执行成功
  560. logger.GetLogger().Debugln("SetHsbyMyPackagesStatus successed: %v", "ok")
  561. appG.Response(http.StatusOK, e.SUCCESS, "")
  562. }
  563. // QueryProvincesAndCitiesReq 查询省市信息请求参数
  564. type QueryProvincesAndCitiesReq struct {
  565. ProvinceID int `form:"provinceID"` // 省ID
  566. }
  567. // QueryProvincesAndCitiesRsp 查询省市信息返回模型
  568. type QueryProvincesAndCitiesRsp struct {
  569. Province models.Division // 省
  570. Cities []models.Division // 市
  571. }
  572. // QueryProvincesAndCities 查询省市信息(不包括区)
  573. // @Summary 查询省市信息(不包括区)
  574. // @Description 查询结果只包括二级市场商品已关连的省市信息。
  575. // @Produce json
  576. // @Security ApiKeyAuth
  577. // @Param provinceID query int false "省ID"
  578. // @Success 200 {object} QueryProvincesAndCitiesRsp
  579. // @Failure 500 {object} app.Response
  580. // @Router /HSBY/QueryProvincesAndCities [get]
  581. // @Tags 定制【海商报业】
  582. func QueryProvincesAndCities(c *gin.Context) {
  583. appG := app.Gin{C: c}
  584. // 获取请求参数
  585. var req QueryProvincesAndCitiesReq
  586. if err := appG.C.ShouldBindQuery(&req); err != nil {
  587. logger.GetLogger().Errorf("QueryProvincesAndCities failed: %s", err.Error())
  588. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  589. return
  590. }
  591. // 获取省市信息
  592. provinces, err := models.GetHsbyProvincesAndCities(req.ProvinceID)
  593. if err != nil {
  594. // 查询失败
  595. logger.GetLogger().Errorf("QueryProvincesAndCities failed: %s", err.Error())
  596. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  597. return
  598. }
  599. // 分解省市数据
  600. // Golang Map元素取址问题: cannot assign to struct field XXXX in map
  601. // https://blog.csdn.net/makenothing/article/details/105037977
  602. pMap := make(map[string]*QueryProvincesAndCitiesRsp)
  603. // 构建省节点
  604. for _, v := range provinces {
  605. if v.Divisionlevel == "province" {
  606. pMap[v.Divisioncode] = &QueryProvincesAndCitiesRsp{Province: v, Cities: make([]models.Division, 0)}
  607. }
  608. }
  609. // 为省节点增加市信息
  610. for _, v := range provinces {
  611. if v.Divisionlevel == "city" {
  612. pMap[v.Parentcode].Cities = append(pMap[v.Parentcode].Cities, v)
  613. }
  614. }
  615. // map to slice
  616. rst := make([]QueryProvincesAndCitiesRsp, 0)
  617. for _, v := range pMap {
  618. rst = append(rst, *v)
  619. }
  620. // 查询成功
  621. logger.GetLogger().Debugln("QueryProvincesAndCities successed: %v", rst)
  622. appG.Response(http.StatusOK, e.SUCCESS, rst)
  623. }
  624. // QueryHsbyBuyMyTradeDetailReq 查询"我的订单 - 已完成"单据信息请求参数
  625. type QueryHsbyBuyMyTradeDetailReq struct {
  626. app.PageInfo
  627. AccountIDs string `form:"accountIDs" binding:"required"`
  628. }
  629. // QueryHsbyBuyMyTradeDetail 查询"我的订单 - 已完成"单据信息
  630. // @Summary 查询"我的订单 - 已完成"单据信息
  631. // @Produce json
  632. // @Security ApiKeyAuth
  633. // @Param page query int false "页码"
  634. // @Param pagesize query int false "每页条数"
  635. // @Param accountIDs query string true "资金账户列表,格式:1,2,3"
  636. // @Success 200 {object} models.HsbyBuyMyTradeDetail
  637. // @Failure 500 {object} app.Response
  638. // @Router /HSBY/QueryHsbyBuyMyTradeDetail [get]
  639. // @Tags 定制【海商报业】
  640. func QueryHsbyBuyMyTradeDetail(c *gin.Context) {
  641. appG := app.Gin{C: c}
  642. // 获取请求参数
  643. var req QueryHsbyBuyMyTradeDetailReq
  644. if err := appG.C.ShouldBindQuery(&req); err != nil {
  645. logger.GetLogger().Errorf("QueryHsbyBuyMyTradeDetail failed: %s", err.Error())
  646. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  647. return
  648. }
  649. // 获取数据
  650. var orders []models.HsbyBuyMyTradeDetail
  651. var err error
  652. orders, err = models.GetHsbyBuyMyTradeDetails(req.AccountIDs)
  653. if err != nil {
  654. // 查询失败
  655. logger.GetLogger().Errorf("QueryHsbyBuyMyTradeDetail failed: %s", err.Error())
  656. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  657. return
  658. }
  659. // 排序
  660. sort.Slice(orders, func(i int, j int) bool {
  661. return orders[i].Time.After(orders[j].Time)
  662. })
  663. // 分页
  664. total := len(orders)
  665. if req.PageSize > 0 {
  666. rstByPage := make([]models.HsbyBuyMyTradeDetail, 0)
  667. // 开始上标
  668. start := req.Page * req.PageSize
  669. // 结束下标
  670. end := start + req.PageSize
  671. if start <= len(orders) {
  672. // 判断结束下标是否越界
  673. if end > len(orders) {
  674. end = len(orders)
  675. }
  676. rstByPage = orders[start:end]
  677. } else {
  678. rstByPage = orders[0:0]
  679. }
  680. orders = rstByPage
  681. }
  682. // 查询成功返回
  683. if req.PageSize > 0 {
  684. logger.GetLogger().Debugln("QueryHsbyBuyMyTradeDetail successed: %v", orders)
  685. appG.ResponseByPage(http.StatusOK, e.SUCCESS, orders, app.PageInfo{Page: req.Page, PageSize: req.PageSize, Total: total})
  686. } else {
  687. logger.GetLogger().Debugln("QueryHsbyBuyMyTradeDetail successed: %v", orders)
  688. appG.Response(http.StatusOK, e.SUCCESS, orders)
  689. }
  690. }
  691. // GetHsbyMyCountReq 获取我的订单与包裹数量请求参数模型
  692. type GetHsbyMyCountReq struct {
  693. AccountIDs string `form:"accountIDs" binding:"required"`
  694. }
  695. // GetHsbyMyCountRsp 获取我的订单与包裹数量返回模型
  696. type GetHsbyMyCountRsp struct {
  697. MyOrderDetailPreCount int `json:"myOrderDetailPreCount"` // 我的订单抢购中数量
  698. MyOrderDetailListingCount int `json:"myOrderDetailListingCount"` // 我的订单求购中数量
  699. MyPackageUnSendCount int `json:"myPackageUnSendCount"` // 我的包裹待发货数量
  700. MyPackageUnReceiveCount int `json:"myPackageUnReceiveCount"` // 我的包裹待收货数量
  701. MyPayOrderCount int `json:"myPayOrderCount"` // 我的订单待付款数量
  702. }
  703. // GetHsbyMyCount 获取我的订单与包裹数量
  704. // @Summary 获取我的订单与包裹数量
  705. // @Description 说明: 不包括已完成的数量。
  706. // @Produce json
  707. // @Security ApiKeyAuth
  708. // @Param accountIDs query string true "资金账户列表,格式:1,2,3"
  709. // @Success 200 {object} GetHsbyMyCountRsp
  710. // @Failure 500 {object} app.Response
  711. // @Router /HSBY/GetHsbyMyCount [get]
  712. // @Tags 定制【海商报业】
  713. func GetHsbyMyCount(c *gin.Context) {
  714. appG := app.Gin{C: c}
  715. // 获取请求参数
  716. var req GetHsbyMyCountReq
  717. if err := appG.C.ShouldBindQuery(&req); err != nil {
  718. logger.GetLogger().Errorf("GetHsbyMyCount failed: %s", err.Error())
  719. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  720. return
  721. }
  722. // 获取我的订单数据
  723. myOrderDetails, err := models.GetHsbyBuyMyOrderDetails(req.AccountIDs, 0)
  724. if err != nil {
  725. // 查询失败
  726. logger.GetLogger().Errorf("GetHsbyMyCount failed: %s", err.Error())
  727. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  728. return
  729. }
  730. // 获取我的包裹数据
  731. myPackages, err := models.GetHsbyMyPackages(req.AccountIDs, 0)
  732. if err != nil {
  733. // 查询失败
  734. logger.GetLogger().Errorf("GetHsbyMyCount failed: %s", err.Error())
  735. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  736. return
  737. }
  738. // 获取我的订单待付款数量
  739. myPayOrders, err := models.GetHsbyBuyMyPayOrders(req.AccountIDs, 0, 0)
  740. if err != nil {
  741. // 查询失败
  742. logger.GetLogger().Errorf("GetHsbyMyCount failed: %s", err.Error())
  743. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  744. return
  745. }
  746. // 统计数量
  747. rsp := GetHsbyMyCountRsp{}
  748. for _, v := range myOrderDetails {
  749. if v.MyBuyStatus == 1 {
  750. // 抢购中
  751. rsp.MyOrderDetailPreCount++
  752. } else if v.MyBuyStatus == 2 {
  753. // 求购中
  754. rsp.MyOrderDetailListingCount++
  755. }
  756. }
  757. for _, v := range myPackages {
  758. if v.Takeorderstatus == 1 {
  759. // 待发货
  760. rsp.MyPackageUnSendCount++
  761. } else if v.Takeorderstatus == 2 {
  762. // 待收货
  763. rsp.MyPackageUnReceiveCount++
  764. }
  765. }
  766. rsp.MyPayOrderCount = len(myPayOrders)
  767. // 查询成功返回
  768. logger.GetLogger().Debugln("GetHsbyMyCount successed: %v", rsp)
  769. appG.Response(http.StatusOK, e.SUCCESS, rsp)
  770. }
  771. // QueryMyPayOrdersReq 我的订单中待付款信息查询请求参数
  772. type QueryMyPayOrdersReq struct {
  773. app.PageInfo
  774. AccountIDs string `form:"accountIDs" binding:"required"`
  775. BuyOrderID int `form:"buyOrderID"`
  776. SellOrderID int `form:"sellOrderID"`
  777. }
  778. // QueryMyPayOrders 获取我的订单中待付款信息
  779. // @Summary 获取我的订单中待付款信息
  780. // @Produce json
  781. // @Security ApiKeyAuth
  782. // @Param page query int false "页码"
  783. // @Param pagesize query int false "每页条数"
  784. // @Param accountIDs query string true "资金账户列表,格式:1,2,3"
  785. // @Param buyOrderID query int false "买方委托单号"
  786. // @Param sellOrderID query int false "卖方委托单号"
  787. // @Success 200 {object} models.HsbyBuyMyPayOrder
  788. // @Failure 500 {object} app.Response
  789. // @Router /HSBY/QueryMyPayOrders [get]
  790. // @Tags 定制【海商报业】
  791. func QueryMyPayOrders(c *gin.Context) {
  792. appG := app.Gin{C: c}
  793. // 获取请求参数
  794. var req QueryMyPayOrdersReq
  795. if err := appG.C.ShouldBindQuery(&req); err != nil {
  796. logger.GetLogger().Errorf("QueryMyPayOrders failed: %s", err.Error())
  797. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  798. return
  799. }
  800. // 获取数据
  801. orders, err := models.GetHsbyBuyMyPayOrders(req.AccountIDs, req.BuyOrderID, req.SellOrderID)
  802. if err != nil {
  803. // 查询失败
  804. logger.GetLogger().Errorf("QueryMyPayOrders failed: %s", err.Error())
  805. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  806. return
  807. }
  808. // 排序
  809. sort.Slice(orders, func(i int, j int) bool {
  810. return orders[i].Createtime.After(orders[j].Createtime)
  811. })
  812. // 分页
  813. total := len(orders)
  814. if req.PageSize > 0 {
  815. rstByPage := make([]models.HsbyBuyMyPayOrder, 0)
  816. // 开始上标
  817. start := req.Page * req.PageSize
  818. // 结束下标
  819. end := start + req.PageSize
  820. if start <= len(orders) {
  821. // 判断结束下标是否越界
  822. if end > len(orders) {
  823. end = len(orders)
  824. }
  825. rstByPage = orders[start:end]
  826. } else {
  827. rstByPage = orders[0:0]
  828. }
  829. orders = rstByPage
  830. }
  831. // 查询成功返回
  832. if req.PageSize > 0 {
  833. logger.GetLogger().Debugln("QueryMyPayOrders successed: %v", orders)
  834. appG.ResponseByPage(http.StatusOK, e.SUCCESS, orders, app.PageInfo{Page: req.Page, PageSize: req.PageSize, Total: total})
  835. } else {
  836. logger.GetLogger().Debugln("QueryMyPayOrders successed: %v", orders)
  837. appG.Response(http.StatusOK, e.SUCCESS, orders)
  838. }
  839. }
  840. // QueryMyCollectionOrdersReq 我的闲置中收款信息查询请求参数
  841. type QueryMyCollectionOrdersReq struct {
  842. app.PageInfo
  843. AccountIDs string `form:"accountIDs" binding:"required"`
  844. }
  845. // QueryMyCollectionOrders 我的闲置中收款信息查询
  846. // @Summary 我的闲置中收款信息查询
  847. // @Produce json
  848. // @Security ApiKeyAuth
  849. // @Param page query int false "页码"
  850. // @Param pagesize query int false "每页条数"
  851. // @Param accountIDs query string true "资金账户,格式:1,2,3"
  852. // @Success 200 {object} models.HsbySellCollectionOrder
  853. // @Failure 500 {object} app.Response
  854. // @Router /HSBY/QueryMyCollectionOrders [get]
  855. // @Tags 定制【海商报业】
  856. func QueryMyCollectionOrders(c *gin.Context) {
  857. appG := app.Gin{C: c}
  858. // 获取请求参数
  859. var req QueryMyCollectionOrdersReq
  860. if err := appG.C.ShouldBindQuery(&req); err != nil {
  861. logger.GetLogger().Errorf("QueryMyCollectionOrders failed: %s", err.Error())
  862. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  863. return
  864. }
  865. // 获取数据
  866. orders, err := models.GetHsbySellCollectionOrders(req.AccountIDs)
  867. if err != nil {
  868. // 查询失败
  869. logger.GetLogger().Errorf("QueryMyCollectionOrders failed: %s", err.Error())
  870. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  871. return
  872. }
  873. // 排序
  874. sort.Slice(orders, func(i int, j int) bool {
  875. return orders[i].Createtime.After(orders[j].Createtime)
  876. })
  877. // 分页
  878. total := len(orders)
  879. if req.PageSize > 0 {
  880. rstByPage := make([]models.HsbySellCollectionOrder, 0)
  881. // 开始上标
  882. start := req.Page * req.PageSize
  883. // 结束下标
  884. end := start + req.PageSize
  885. if start <= len(orders) {
  886. // 判断结束下标是否越界
  887. if end > len(orders) {
  888. end = len(orders)
  889. }
  890. rstByPage = orders[start:end]
  891. } else {
  892. rstByPage = orders[0:0]
  893. }
  894. orders = rstByPage
  895. }
  896. // 查询成功返回
  897. if req.PageSize > 0 {
  898. logger.GetLogger().Debugln("QueryMyCollectionOrders successed: %v", orders)
  899. appG.ResponseByPage(http.StatusOK, e.SUCCESS, orders, app.PageInfo{Page: req.Page, PageSize: req.PageSize, Total: total})
  900. } else {
  901. logger.GetLogger().Debugln("QueryMyCollectionOrders successed: %v", orders)
  902. appG.Response(http.StatusOK, e.SUCCESS, orders)
  903. }
  904. }
  905. // QueryHsbyMarkets 查询海商报业相关市场信息
  906. // @Summary 查询海商报业相关市场信息
  907. // @Produce json
  908. // @Security ApiKeyAuth
  909. // @Success 200 {object} models.HsbyMarketInfo
  910. // @Failure 500 {object} app.Response
  911. // @Router /HSBY/QueryHsbyMarkets [get]
  912. // @Tags 定制【海商报业】
  913. func QueryHsbyMarkets(c *gin.Context) {
  914. appG := app.Gin{C: c}
  915. // 获取数据
  916. markets, err := models.GetHsbyMarketInfos()
  917. if err != nil {
  918. // 查询失败
  919. logger.GetLogger().Errorf("QueryHsbyMarkets failed: %s", err.Error())
  920. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  921. return
  922. }
  923. // 查询成功返回
  924. logger.GetLogger().Debugln("QueryHsbyMarkets successed: %v", markets)
  925. appG.Response(http.StatusOK, e.SUCCESS, markets)
  926. }
  927. // QueryHsbyMarketGoodsesReq 查询特卖商品列表(三级商城)列表请求参数
  928. type QueryHsbyMarketGoodsesReq struct {
  929. app.PageInfo
  930. MarketIDs string `form:"marketIDs" binding:"required"`
  931. AccountID int `form:"accountID"`
  932. CategoryID int `form:"categoryID"`
  933. GoodsID int `form:"goodsID"`
  934. }
  935. // QueryHsbyMarketGoodses 查询特卖商品列表(三级商城)
  936. // @Summary 查询特卖商品列表(三级商城)
  937. // @Produce json
  938. // @Security ApiKeyAuth
  939. // @Param page query int false "页码"
  940. // @Param pagesize query int false "每页条数"
  941. // @Param marketIDs query string true "市场ID列表,格式:1,2,3"
  942. // @Param accountID query int false "资金账户,主要用于判断商品是否有可用的优惠卷;如未登录可不传。"
  943. // @Param categoryID query int false "类别ID"
  944. // @Param goodsID query int false "商品ID"
  945. // @Success 200 {object} models.HsbyMarketGoods
  946. // @Failure 500 {object} app.Response
  947. // @Router /HSBY/QueryHsbyMarketGoodses [get]
  948. // @Tags 定制【海商报业】
  949. func QueryHsbyMarketGoodses(c *gin.Context) {
  950. appG := app.Gin{C: c}
  951. // 获取请求参数
  952. var req QueryHsbyMarketGoodsesReq
  953. if err := appG.C.ShouldBindQuery(&req); err != nil {
  954. logger.GetLogger().Errorf("QueryHsbyMarketGoodses failed: %s", err.Error())
  955. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  956. return
  957. }
  958. // 获取数据
  959. goodses, err := models.GetHsbyMarketGoodses(req.MarketIDs, req.AccountID, req.CategoryID, req.GoodsID)
  960. if err != nil {
  961. // 查询失败
  962. logger.GetLogger().Errorf("QueryHsbyMarketGoodses failed: %s", err.Error())
  963. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  964. return
  965. }
  966. // 排序
  967. sort.Slice(goodses, func(i int, j int) bool {
  968. return goodses[i].Hotindex > goodses[j].Hotindex
  969. })
  970. // 分页
  971. total := len(goodses)
  972. if req.PageSize > 0 {
  973. rstByPage := make([]models.HsbyMarketGoods, 0)
  974. // 开始上标
  975. start := req.Page * req.PageSize
  976. // 结束下标
  977. end := start + req.PageSize
  978. if start <= len(goodses) {
  979. // 判断结束下标是否越界
  980. if end > len(goodses) {
  981. end = len(goodses)
  982. }
  983. rstByPage = goodses[start:end]
  984. } else {
  985. rstByPage = goodses[0:0]
  986. }
  987. goodses = rstByPage
  988. }
  989. // 查询成功返回
  990. if req.PageSize > 0 {
  991. logger.GetLogger().Debugln("QueryHsbyMarketGoodses successed: %v", goodses)
  992. appG.ResponseByPage(http.StatusOK, e.SUCCESS, goodses, app.PageInfo{Page: req.Page, PageSize: req.PageSize, Total: total})
  993. } else {
  994. logger.GetLogger().Debugln("QueryHsbyMarketGoodses successed: %v", goodses)
  995. appG.Response(http.StatusOK, e.SUCCESS, goodses)
  996. }
  997. }
  998. // QueryHsbyMarketGoodsDetailReq 查询三级市场(商城)商品信息详情请求参数
  999. type QueryHsbyMarketGoodsDetailReq struct {
  1000. OrderID int `form:"orderID" binding:"required"`
  1001. }
  1002. // QueryHsbyMarketGoodsDetail 查询三级市场(商城)商品信息详情
  1003. // @Summary 查询三级市场(商城)商品信息详情
  1004. // @Produce json
  1005. // @Security ApiKeyAuth
  1006. // @Param orderID query int true "委托单号"
  1007. // @Success 200 {object} models.HsbyMarketGoodsDetail
  1008. // @Failure 500 {object} app.Response
  1009. // @Router /HSBY/QueryHsbyMarketGoodsDetail [get]
  1010. // @Tags 定制【海商报业】
  1011. func QueryHsbyMarketGoodsDetail(c *gin.Context) {
  1012. appG := app.Gin{C: c}
  1013. // 获取请求参数
  1014. var req QueryHsbyMarketGoodsDetailReq
  1015. if err := appG.C.ShouldBindQuery(&req); err != nil {
  1016. logger.GetLogger().Errorf("QueryHsbyMarketGoodsDetail failed: %s", err.Error())
  1017. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  1018. return
  1019. }
  1020. // 获取数据
  1021. detail, err := models.GetHsbyMarketGoodsDetail(req.OrderID)
  1022. if err != nil {
  1023. // 查询失败
  1024. logger.GetLogger().Errorf("QueryHsbyMarketGoodsDetail failed: %s", err.Error())
  1025. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  1026. return
  1027. }
  1028. // 查询成功返回
  1029. logger.GetLogger().Debugln("QueryHsbyMarketGoodsDetail successed: %v", detail)
  1030. appG.Response(http.StatusOK, e.SUCCESS, detail)
  1031. }
  1032. // QueryMyCouponsReq 我的优惠卷查询请求参数
  1033. type QueryMyCouponsReq struct {
  1034. AccountIDs string `form:"accountIDs" binding:"required"`
  1035. GoodsID int `form:"goodsID"`
  1036. SellUserID int `form:"sellUserID"`
  1037. }
  1038. // QueryMyCoupons 我的优惠卷查询
  1039. // @Summary 我的优惠卷查询
  1040. // @Produce json
  1041. // @Security ApiKeyAuth
  1042. // @Param accountIDs query string true "资金账户列表,格式:1,2,3"
  1043. // @Param goodsID query int false "商品ID, 一般与sellUserID配套传入"
  1044. // @Param sellUserID query int false "卖方UserID"
  1045. // @Success 200 {object} models.MyCoupon
  1046. // @Failure 500 {object} app.Response
  1047. // @Router /HSBY/QueryMyCoupons [get]
  1048. // @Tags 定制【海商报业】
  1049. func QueryMyCoupons(c *gin.Context) {
  1050. appG := app.Gin{C: c}
  1051. // 获取请求参数
  1052. var req QueryMyCouponsReq
  1053. if err := appG.C.ShouldBindQuery(&req); err != nil {
  1054. logger.GetLogger().Errorf("QueryMyCoupons failed: %s", err.Error())
  1055. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  1056. return
  1057. }
  1058. // 获取数据
  1059. myCoupons, err := models.GetMyCoupons(req.AccountIDs, req.GoodsID, req.SellUserID)
  1060. if err != nil {
  1061. // 查询失败
  1062. logger.GetLogger().Errorf("QueryMyCoupons failed: %s", err.Error())
  1063. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  1064. return
  1065. }
  1066. // 查询成功返回
  1067. logger.GetLogger().Debugln("QueryMyCoupons successed: %v", myCoupons)
  1068. appG.Response(http.StatusOK, e.SUCCESS, myCoupons)
  1069. }
  1070. // QueryMyCouponHoldsReq 我的优惠卷持仓查询请求参数
  1071. type QueryMyCouponHoldsReq struct {
  1072. AccountIDs string `form:"accountIDs" binding:"required"`
  1073. }
  1074. // QueryMyCouponHolds 我的优惠卷持仓查询
  1075. // @Summary 我的优惠卷持仓查询
  1076. // @Produce json
  1077. // @Security ApiKeyAuth
  1078. // @Param accountIDs query string true "资金账户列表,格式:1,2,3"
  1079. // @Success 200 {object} models.MyCouponHold
  1080. // @Failure 500 {object} app.Response
  1081. // @Router /HSBY/QueryMyCouponHolds [get]
  1082. // @Tags 定制【海商报业】
  1083. func QueryMyCouponHolds(c *gin.Context) {
  1084. appG := app.Gin{C: c}
  1085. // 获取请求参数
  1086. var req QueryMyCouponHoldsReq
  1087. if err := appG.C.ShouldBindQuery(&req); err != nil {
  1088. logger.GetLogger().Errorf("QueryMyCouponHolds failed: %s", err.Error())
  1089. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  1090. return
  1091. }
  1092. // 获取数据
  1093. myCoupons, err := models.GetMyCouponHolds(req.AccountIDs)
  1094. if err != nil {
  1095. // 查询失败
  1096. logger.GetLogger().Errorf("QueryMyCouponHolds failed: %s", err.Error())
  1097. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  1098. return
  1099. }
  1100. // 查询成功返回
  1101. logger.GetLogger().Debugln("QueryMyCouponHolds successed: %v", myCoupons)
  1102. appG.Response(http.StatusOK, e.SUCCESS, myCoupons)
  1103. }