hsby.go 50 KB

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