hsby.go 46 KB

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