hsby.go 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334
  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. if err != nil {
  753. // 查询失败
  754. logger.GetLogger().Errorf("GetHsbyMyCount failed: %s", err.Error())
  755. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  756. return
  757. }
  758. // 统计数量
  759. rsp := GetHsbyMyCountRsp{}
  760. for _, v := range myOrderDetails {
  761. if v.MyBuyStatus == 1 {
  762. // 抢购中
  763. rsp.MyOrderDetailPreCount++
  764. } else if v.MyBuyStatus == 2 {
  765. // 求购中
  766. rsp.MyOrderDetailListingCount++
  767. }
  768. }
  769. for _, v := range myPackages {
  770. if v.Takeorderstatus == 1 {
  771. // 待发货
  772. rsp.MyPackageUnSendCount++
  773. } else if v.Takeorderstatus == 2 {
  774. // 待收货
  775. rsp.MyPackageUnReceiveCount++
  776. }
  777. }
  778. rsp.MyPayOrderCount = len(myPayOrders)
  779. for _, v := range myCoupons {
  780. rsp.MyCouponCount += int(v.Curqty)
  781. }
  782. // 查询成功返回
  783. logger.GetLogger().Debugln("GetHsbyMyCount successed: %v", rsp)
  784. appG.Response(http.StatusOK, e.SUCCESS, rsp)
  785. }
  786. // QueryMyPayOrdersReq 我的订单中待付款信息查询请求参数
  787. type QueryMyPayOrdersReq struct {
  788. app.PageInfo
  789. AccountIDs string `form:"accountIDs" binding:"required"`
  790. BuyOrderID int `form:"buyOrderID"`
  791. SellOrderID int `form:"sellOrderID"`
  792. }
  793. // QueryMyPayOrders 获取我的订单中待付款信息
  794. // @Summary 获取我的订单中待付款信息
  795. // @Produce json
  796. // @Security ApiKeyAuth
  797. // @Param page query int false "页码"
  798. // @Param pagesize query int false "每页条数"
  799. // @Param accountIDs query string true "资金账户列表,格式:1,2,3"
  800. // @Param buyOrderID query int false "买方委托单号"
  801. // @Param sellOrderID query int false "卖方委托单号"
  802. // @Success 200 {object} models.HsbyBuyMyPayOrder
  803. // @Failure 500 {object} app.Response
  804. // @Router /HSBY/QueryMyPayOrders [get]
  805. // @Tags 定制【海商报业】
  806. func QueryMyPayOrders(c *gin.Context) {
  807. appG := app.Gin{C: c}
  808. // 获取请求参数
  809. var req QueryMyPayOrdersReq
  810. if err := appG.C.ShouldBindQuery(&req); err != nil {
  811. logger.GetLogger().Errorf("QueryMyPayOrders failed: %s", err.Error())
  812. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  813. return
  814. }
  815. // 获取数据
  816. orders, err := models.GetHsbyBuyMyPayOrders(req.AccountIDs, req.BuyOrderID, req.SellOrderID)
  817. if err != nil {
  818. // 查询失败
  819. logger.GetLogger().Errorf("QueryMyPayOrders failed: %s", err.Error())
  820. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  821. return
  822. }
  823. // 排序
  824. sort.Slice(orders, func(i int, j int) bool {
  825. return orders[i].Createtime.After(orders[j].Createtime)
  826. })
  827. // 分页
  828. total := len(orders)
  829. if req.PageSize > 0 {
  830. rstByPage := make([]models.HsbyBuyMyPayOrder, 0)
  831. // 开始上标
  832. start := req.Page * req.PageSize
  833. // 结束下标
  834. end := start + req.PageSize
  835. if start <= len(orders) {
  836. // 判断结束下标是否越界
  837. if end > len(orders) {
  838. end = len(orders)
  839. }
  840. rstByPage = orders[start:end]
  841. } else {
  842. rstByPage = orders[0:0]
  843. }
  844. orders = rstByPage
  845. }
  846. // 查询成功返回
  847. if req.PageSize > 0 {
  848. logger.GetLogger().Debugln("QueryMyPayOrders successed: %v", orders)
  849. appG.ResponseByPage(http.StatusOK, e.SUCCESS, orders, app.PageInfo{Page: req.Page, PageSize: req.PageSize, Total: total})
  850. } else {
  851. logger.GetLogger().Debugln("QueryMyPayOrders successed: %v", orders)
  852. appG.Response(http.StatusOK, e.SUCCESS, orders)
  853. }
  854. }
  855. // QueryMyCollectionOrdersReq 我的闲置中收款信息查询请求参数
  856. type QueryMyCollectionOrdersReq struct {
  857. app.PageInfo
  858. AccountIDs string `form:"accountIDs" binding:"required"`
  859. }
  860. // QueryMyCollectionOrders 我的闲置中收款信息查询
  861. // @Summary 我的闲置中收款信息查询
  862. // @Produce json
  863. // @Security ApiKeyAuth
  864. // @Param page query int false "页码"
  865. // @Param pagesize query int false "每页条数"
  866. // @Param accountIDs query string true "资金账户,格式:1,2,3"
  867. // @Success 200 {object} models.HsbySellCollectionOrder
  868. // @Failure 500 {object} app.Response
  869. // @Router /HSBY/QueryMyCollectionOrders [get]
  870. // @Tags 定制【海商报业】
  871. func QueryMyCollectionOrders(c *gin.Context) {
  872. appG := app.Gin{C: c}
  873. // 获取请求参数
  874. var req QueryMyCollectionOrdersReq
  875. if err := appG.C.ShouldBindQuery(&req); err != nil {
  876. logger.GetLogger().Errorf("QueryMyCollectionOrders failed: %s", err.Error())
  877. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  878. return
  879. }
  880. // 获取数据
  881. orders, err := models.GetHsbySellCollectionOrders(req.AccountIDs)
  882. if err != nil {
  883. // 查询失败
  884. logger.GetLogger().Errorf("QueryMyCollectionOrders failed: %s", err.Error())
  885. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  886. return
  887. }
  888. // 排序
  889. sort.Slice(orders, func(i int, j int) bool {
  890. return orders[i].Createtime.After(orders[j].Createtime)
  891. })
  892. // 分页
  893. total := len(orders)
  894. if req.PageSize > 0 {
  895. rstByPage := make([]models.HsbySellCollectionOrder, 0)
  896. // 开始上标
  897. start := req.Page * req.PageSize
  898. // 结束下标
  899. end := start + req.PageSize
  900. if start <= len(orders) {
  901. // 判断结束下标是否越界
  902. if end > len(orders) {
  903. end = len(orders)
  904. }
  905. rstByPage = orders[start:end]
  906. } else {
  907. rstByPage = orders[0:0]
  908. }
  909. orders = rstByPage
  910. }
  911. // 查询成功返回
  912. if req.PageSize > 0 {
  913. logger.GetLogger().Debugln("QueryMyCollectionOrders successed: %v", orders)
  914. appG.ResponseByPage(http.StatusOK, e.SUCCESS, orders, app.PageInfo{Page: req.Page, PageSize: req.PageSize, Total: total})
  915. } else {
  916. logger.GetLogger().Debugln("QueryMyCollectionOrders successed: %v", orders)
  917. appG.Response(http.StatusOK, e.SUCCESS, orders)
  918. }
  919. }
  920. // QueryHsbyMarkets 查询海商报业相关市场信息
  921. // @Summary 查询海商报业相关市场信息
  922. // @Produce json
  923. // @Security ApiKeyAuth
  924. // @Success 200 {object} models.HsbyMarketInfo
  925. // @Failure 500 {object} app.Response
  926. // @Router /HSBY/QueryHsbyMarkets [get]
  927. // @Tags 定制【海商报业】
  928. func QueryHsbyMarkets(c *gin.Context) {
  929. appG := app.Gin{C: c}
  930. // 获取数据
  931. markets, err := models.GetHsbyMarketInfos()
  932. if err != nil {
  933. // 查询失败
  934. logger.GetLogger().Errorf("QueryHsbyMarkets failed: %s", err.Error())
  935. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  936. return
  937. }
  938. // 查询成功返回
  939. logger.GetLogger().Debugln("QueryHsbyMarkets successed: %v", markets)
  940. appG.Response(http.StatusOK, e.SUCCESS, markets)
  941. }
  942. // QueryHsbyMarketGoodsesReq 查询特卖商品列表(三级商城)列表请求参数
  943. type QueryHsbyMarketGoodsesReq struct {
  944. app.PageInfo
  945. MarketIDs string `form:"marketIDs" binding:"required"`
  946. AccountID int `form:"accountID"`
  947. CategoryID int `form:"categoryID"`
  948. GoodsIDs string `form:"goodsIDs"`
  949. CouponTypeID int `form:"couponTypeID"`
  950. }
  951. // QueryHsbyMarketGoodses 查询特卖商品列表(三级商城)
  952. // @Summary 查询特卖商品列表(三级商城)
  953. // @Produce json
  954. // @Security ApiKeyAuth
  955. // @Param page query int false "页码"
  956. // @Param pagesize query int false "每页条数"
  957. // @Param marketIDs query string true "市场ID列表,格式:1,2,3"
  958. // @Param accountID query int false "资金账户,主要用于判断商品是否有可用的优惠卷;如未登录可不传。"
  959. // @Param categoryID query int false "类别ID"
  960. // @Param goodsIDs query string false "商品ID列表,格式:1,2,3。主要用于商品搜索。"
  961. // @Param couponTypeID query int false "优惠券类型ID,主要用于显示优惠卷对应的商品列表。"
  962. // @Success 200 {object} models.HsbyMarketGoods
  963. // @Failure 500 {object} app.Response
  964. // @Router /HSBY/QueryHsbyMarketGoodses [get]
  965. // @Tags 定制【海商报业】
  966. func QueryHsbyMarketGoodses(c *gin.Context) {
  967. appG := app.Gin{C: c}
  968. // 获取请求参数
  969. var req QueryHsbyMarketGoodsesReq
  970. if err := appG.C.ShouldBindQuery(&req); err != nil {
  971. logger.GetLogger().Errorf("QueryHsbyMarketGoodses failed: %s", err.Error())
  972. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  973. return
  974. }
  975. // 获取数据
  976. goodses, err := models.GetHsbyMarketGoodses(req.MarketIDs, req.AccountID, req.CategoryID, req.GoodsIDs, req.CouponTypeID)
  977. if err != nil {
  978. // 查询失败
  979. logger.GetLogger().Errorf("QueryHsbyMarketGoodses 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("QueryHsbyMarketGoodses 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("QueryHsbyMarketGoodses successed: %v", goodses)
  1012. appG.Response(http.StatusOK, e.SUCCESS, goodses)
  1013. }
  1014. }
  1015. // QueryHsbyMarketGoodsDetailReq 查询三级市场(商城)商品信息详情请求参数
  1016. type QueryHsbyMarketGoodsDetailReq struct {
  1017. OrderID int `form:"orderID" binding:"required"`
  1018. AccountID int `form:"accountID"`
  1019. }
  1020. // QueryHsbyMarketGoodsDetail 查询三级市场(商城)商品信息详情
  1021. // @Summary 查询三级市场(商城)商品信息详情
  1022. // @Produce json
  1023. // @Security ApiKeyAuth
  1024. // @Param orderID query int true "委托单号"
  1025. // @Param accountID query int false "资金账户,主要用于判断商品最大开仓手数;如未登录可不传。"
  1026. // @Success 200 {object} models.HsbyMarketGoodsDetail
  1027. // @Failure 500 {object} app.Response
  1028. // @Router /HSBY/QueryHsbyMarketGoodsDetail [get]
  1029. // @Tags 定制【海商报业】
  1030. func QueryHsbyMarketGoodsDetail(c *gin.Context) {
  1031. appG := app.Gin{C: c}
  1032. // 获取请求参数
  1033. var req QueryHsbyMarketGoodsDetailReq
  1034. if err := appG.C.ShouldBindQuery(&req); err != nil {
  1035. logger.GetLogger().Errorf("QueryHsbyMarketGoodsDetail failed: %s", err.Error())
  1036. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  1037. return
  1038. }
  1039. // 获取数据
  1040. detail, err := models.GetHsbyMarketGoodsDetail(req.OrderID, req.AccountID)
  1041. if err != nil {
  1042. // 查询失败
  1043. logger.GetLogger().Errorf("QueryHsbyMarketGoodsDetail failed: %s", err.Error())
  1044. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  1045. return
  1046. }
  1047. // 获取交易规则
  1048. rule, err := models.GetTodayAccountTradeRule(int(detail.Accountid), int(detail.Goodsid))
  1049. if err != nil {
  1050. // 查询失败
  1051. logger.GetLogger().Errorf("QueryHsbyListingGoodsDetail failed: %s", err.Error())
  1052. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  1053. return
  1054. }
  1055. if rule != nil {
  1056. tradeRuleInfoStruct := &pb.TradeRuleInfoStruct{}
  1057. if err := proto.Unmarshal([]byte(rule.Infocontent), tradeRuleInfoStruct); err != nil {
  1058. // 查询失败
  1059. logger.GetLogger().Errorf("QueryHsbyListingGoodsDetail failed: %s", err.Error())
  1060. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  1061. return
  1062. }
  1063. // INSERT INTO TRADERULEDESCRIPTION (RULEID, RULENAME, REGEXPRESS, DEFAULTVALUE, REMARK) VALUES (103, '单笔最小交易量', '^[1-9]\d*$', 1, '请输入正整数!');
  1064. for _, v := range tradeRuleInfoStruct.TradeRules {
  1065. if int(*v.RuleID) == 103 {
  1066. detail.LotSize = int(*v.ParamValue)
  1067. }
  1068. // 商城的最大建仓手数与预售的不一样,直接从规则里取
  1069. if int(*v.RuleID) == 104 {
  1070. detail.Buymaxqty = int(*v.ParamValue)
  1071. }
  1072. }
  1073. }
  1074. // 查询成功返回
  1075. logger.GetLogger().Debugln("QueryHsbyMarketGoodsDetail successed: %v", detail)
  1076. appG.Response(http.StatusOK, e.SUCCESS, detail)
  1077. }
  1078. // QueryMyCouponsReq 我的优惠卷查询请求参数
  1079. type QueryMyCouponsReq struct {
  1080. AccountIDs string `form:"accountIDs" binding:"required"`
  1081. GoodsID int `form:"goodsID"`
  1082. SellUserID int `form:"sellUserID"`
  1083. }
  1084. // QueryMyCoupons 我的优惠卷查询
  1085. // @Summary 我的优惠卷查询
  1086. // @Produce json
  1087. // @Security ApiKeyAuth
  1088. // @Param accountIDs query string true "资金账户列表,格式:1,2,3"
  1089. // @Param goodsID query int false "商品ID, 一般与sellUserID配套传入"
  1090. // @Param sellUserID query int false "卖方UserID"
  1091. // @Success 200 {object} models.MyCoupon
  1092. // @Failure 500 {object} app.Response
  1093. // @Router /HSBY/QueryMyCoupons [get]
  1094. // @Tags 定制【海商报业】
  1095. func QueryMyCoupons(c *gin.Context) {
  1096. appG := app.Gin{C: c}
  1097. // 获取请求参数
  1098. var req QueryMyCouponsReq
  1099. if err := appG.C.ShouldBindQuery(&req); err != nil {
  1100. logger.GetLogger().Errorf("QueryMyCoupons failed: %s", err.Error())
  1101. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  1102. return
  1103. }
  1104. // 获取数据
  1105. myCoupons, err := models.GetMyCoupons(req.AccountIDs, req.GoodsID, req.SellUserID)
  1106. if err != nil {
  1107. // 查询失败
  1108. logger.GetLogger().Errorf("QueryMyCoupons failed: %s", err.Error())
  1109. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  1110. return
  1111. }
  1112. // 查询成功返回
  1113. logger.GetLogger().Debugln("QueryMyCoupons successed: %v", myCoupons)
  1114. appG.Response(http.StatusOK, e.SUCCESS, myCoupons)
  1115. }
  1116. // QueryMyCouponHoldsReq 我的优惠卷持仓查询请求参数
  1117. type QueryMyCouponHoldsReq struct {
  1118. AccountIDs string `form:"accountIDs" binding:"required"`
  1119. HoldStatus string `form:"holdStatus"`
  1120. }
  1121. // QueryMyCouponHolds 我的优惠卷持仓查询
  1122. // @Summary 我的优惠卷持仓查询
  1123. // @Produce json
  1124. // @Security ApiKeyAuth
  1125. // @Param accountIDs query string true "资金账户列表,格式:1,2,3"
  1126. // @Param holdStatus query string false "持仓状态 - 1:未生效 2:已生效 3:已使用 4:已过期,格式:1,2,3"
  1127. // @Success 200 {object} models.MyCouponHold
  1128. // @Failure 500 {object} app.Response
  1129. // @Router /HSBY/QueryMyCouponHolds [get]
  1130. // @Tags 定制【海商报业】
  1131. func QueryMyCouponHolds(c *gin.Context) {
  1132. appG := app.Gin{C: c}
  1133. // 获取请求参数
  1134. var req QueryMyCouponHoldsReq
  1135. if err := appG.C.ShouldBindQuery(&req); err != nil {
  1136. logger.GetLogger().Errorf("QueryMyCouponHolds failed: %s", err.Error())
  1137. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  1138. return
  1139. }
  1140. // 获取数据
  1141. myCoupons, err := models.GetMyCouponHolds(req.AccountIDs, req.HoldStatus)
  1142. if err != nil {
  1143. // 查询失败
  1144. logger.GetLogger().Errorf("QueryMyCouponHolds failed: %s", err.Error())
  1145. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  1146. return
  1147. }
  1148. // 查询成功返回
  1149. logger.GetLogger().Debugln("QueryMyCouponHolds successed: %v", myCoupons)
  1150. appG.Response(http.StatusOK, e.SUCCESS, myCoupons)
  1151. }
  1152. // QueryMyUsedCouponReq 已使用优惠卷查询请求参数
  1153. type QueryMyUsedCouponReq struct {
  1154. AccountIDs string `form:"accountIDs" binding:"required"`
  1155. }
  1156. // QueryMyUsedCoupon 已使用优惠卷查询
  1157. // @Summary 已使用优惠卷查询
  1158. // @Produce json
  1159. // @Security ApiKeyAuth
  1160. // @Param accountIDs query string true "资金账户列表,格式:1,2,3"
  1161. // @Success 200 {object} models.MyUsedCoupon
  1162. // @Failure 500 {object} app.Response
  1163. // @Router /HSBY/QueryMyUsedCoupon [get]
  1164. // @Tags 定制【海商报业】
  1165. func QueryMyUsedCoupon(c *gin.Context) {
  1166. appG := app.Gin{C: c}
  1167. // 获取请求参数
  1168. var req QueryMyUsedCouponReq
  1169. if err := appG.C.ShouldBindQuery(&req); err != nil {
  1170. logger.GetLogger().Errorf("QueryMyUsedCoupon failed: %s", err.Error())
  1171. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  1172. return
  1173. }
  1174. // 获取数据
  1175. myCoupons, err := models.GetMyUsedCoupon(req.AccountIDs)
  1176. if err != nil {
  1177. // 查询失败
  1178. logger.GetLogger().Errorf("QueryMyUsedCoupon failed: %s", err.Error())
  1179. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  1180. return
  1181. }
  1182. // 查询成功返回
  1183. logger.GetLogger().Debugln("QueryMyUsedCoupon successed: %v", myCoupons)
  1184. appG.Response(http.StatusOK, e.SUCCESS, myCoupons)
  1185. }