hsby.go 50 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481
  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. // QueryHsbyVisitorMarketGoodsesReq 查询游客特卖商品列表(三级商城)请求参数
  945. type QueryHsbyVisitorMarketGoodsesReq struct {
  946. app.PageInfo
  947. MarketIDs string `form:"marketIDs" binding:"required"`
  948. CategoryID int `form:"categoryID"`
  949. GoodsIDs string `form:"goodsIDs"`
  950. }
  951. // QueryHsbyVisitorMarketGoodses 查询游客特卖商品列表(三级商城)
  952. // @Summary 查询游客特卖商品列表(三级商城)
  953. // @Description 说明:使用于未登录状态查询商城商品列表,登录后请使用QueryHsbyMarketGoodses接口进行查询。
  954. // @Produce json
  955. // @Security ApiKeyAuth
  956. // @Param page query int false "页码"
  957. // @Param pagesize query int false "每页条数"
  958. // @Param marketIDs query string true "市场ID列表,格式:1,2,3"
  959. // @Param categoryID query int false "类别ID"
  960. // @Param goodsIDs query string false "商品ID列表,格式:1,2,3。主要用于商品搜索。"
  961. // @Success 200 {object} models.HsbyMarketGoods
  962. // @Failure 500 {object} app.Response
  963. // @Router /HSBY/QueryHsbyVisitorMarketGoodses [get]
  964. // @Tags 定制【海商报业】
  965. func QueryHsbyVisitorMarketGoodses(c *gin.Context) {
  966. appG := app.Gin{C: c}
  967. // 获取请求参数
  968. var req QueryHsbyVisitorMarketGoodsesReq
  969. if err := appG.C.ShouldBindQuery(&req); err != nil {
  970. logger.GetLogger().Errorf("QueryHsbyVisitorMarketGoodses failed: %s", err.Error())
  971. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  972. return
  973. }
  974. // 获取数据
  975. goodses, err := models.GetHsbyMarketGoodsesByVisitor(req.MarketIDs, req.CategoryID, req.GoodsIDs)
  976. if err != nil {
  977. // 查询失败
  978. logger.GetLogger().Errorf("QueryHsbyVisitorMarketGoodses failed: %s", err.Error())
  979. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  980. return
  981. }
  982. // 排序
  983. sort.Slice(goodses, func(i int, j int) bool {
  984. return goodses[i].Hotindex > goodses[j].Hotindex
  985. })
  986. // 分页
  987. total := len(goodses)
  988. if req.PageSize > 0 {
  989. rstByPage := make([]models.HsbyMarketGoods, 0)
  990. // 开始上标
  991. start := req.Page * req.PageSize
  992. // 结束下标
  993. end := start + req.PageSize
  994. if start <= len(goodses) {
  995. // 判断结束下标是否越界
  996. if end > len(goodses) {
  997. end = len(goodses)
  998. }
  999. rstByPage = goodses[start:end]
  1000. } else {
  1001. rstByPage = goodses[0:0]
  1002. }
  1003. goodses = rstByPage
  1004. }
  1005. // 查询成功返回
  1006. if req.PageSize > 0 {
  1007. logger.GetLogger().Debugln("QueryHsbyVisitorMarketGoodses successed: %v", goodses)
  1008. appG.ResponseByPage(http.StatusOK, e.SUCCESS, goodses, app.PageInfo{Page: req.Page, PageSize: req.PageSize, Total: total})
  1009. } else {
  1010. logger.GetLogger().Debugln("QueryHsbyVisitorMarketGoodses successed: %v", goodses)
  1011. appG.Response(http.StatusOK, e.SUCCESS, goodses)
  1012. }
  1013. }
  1014. // QueryHsbyMarketGoodsesReq 查询特卖商品列表(三级商城)请求参数
  1015. type QueryHsbyMarketGoodsesReq struct {
  1016. app.PageInfo
  1017. MarketIDs string `form:"marketIDs" binding:"required"`
  1018. AccountID int `form:"accountID" binding:"required"`
  1019. CategoryID int `form:"categoryID"`
  1020. GoodsIDs string `form:"goodsIDs"`
  1021. CouponTypeID int `form:"couponTypeID"`
  1022. }
  1023. // QueryHsbyMarketGoodses 查询特卖商品列表(三级商城)
  1024. // @Summary 查询特卖商品列表(三级商城)
  1025. // @Produce json
  1026. // @Security ApiKeyAuth
  1027. // @Param page query int false "页码"
  1028. // @Param pagesize query int false "每页条数"
  1029. // @Param marketIDs query string true "市场ID列表,格式:1,2,3"
  1030. // @Param accountID query int true "资金账户,用于判断商品是否有可用的优惠卷;同时只显示此账户所属机构下的商城委托单。"
  1031. // @Param categoryID query int false "类别ID"
  1032. // @Param goodsIDs query string false "商品ID列表,格式:1,2,3。主要用于商品搜索。"
  1033. // @Param couponTypeID query int false "优惠券类型ID,主要用于显示优惠卷对应的商品列表。"
  1034. // @Success 200 {object} models.HsbyMarketGoods
  1035. // @Failure 500 {object} app.Response
  1036. // @Router /HSBY/QueryHsbyMarketGoodses [get]
  1037. // @Tags 定制【海商报业】
  1038. func QueryHsbyMarketGoodses(c *gin.Context) {
  1039. appG := app.Gin{C: c}
  1040. // 获取请求参数
  1041. var req QueryHsbyMarketGoodsesReq
  1042. if err := appG.C.ShouldBindQuery(&req); err != nil {
  1043. logger.GetLogger().Errorf("QueryHsbyMarketGoodses failed: %s", err.Error())
  1044. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  1045. return
  1046. }
  1047. // 获取数据
  1048. goodses, err := models.GetHsbyMarketGoodses(req.MarketIDs, req.AccountID, req.CategoryID, req.GoodsIDs, req.CouponTypeID)
  1049. if err != nil {
  1050. // 查询失败
  1051. logger.GetLogger().Errorf("QueryHsbyMarketGoodses failed: %s", err.Error())
  1052. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  1053. return
  1054. }
  1055. // 排序
  1056. sort.Slice(goodses, func(i int, j int) bool {
  1057. return goodses[i].Hotindex > goodses[j].Hotindex
  1058. })
  1059. // 分页
  1060. total := len(goodses)
  1061. if req.PageSize > 0 {
  1062. rstByPage := make([]models.HsbyMarketGoods, 0)
  1063. // 开始上标
  1064. start := req.Page * req.PageSize
  1065. // 结束下标
  1066. end := start + req.PageSize
  1067. if start <= len(goodses) {
  1068. // 判断结束下标是否越界
  1069. if end > len(goodses) {
  1070. end = len(goodses)
  1071. }
  1072. rstByPage = goodses[start:end]
  1073. } else {
  1074. rstByPage = goodses[0:0]
  1075. }
  1076. goodses = rstByPage
  1077. }
  1078. // 查询成功返回
  1079. if req.PageSize > 0 {
  1080. logger.GetLogger().Debugln("QueryHsbyMarketGoodses successed: %v", goodses)
  1081. appG.ResponseByPage(http.StatusOK, e.SUCCESS, goodses, app.PageInfo{Page: req.Page, PageSize: req.PageSize, Total: total})
  1082. } else {
  1083. logger.GetLogger().Debugln("QueryHsbyMarketGoodses successed: %v", goodses)
  1084. appG.Response(http.StatusOK, e.SUCCESS, goodses)
  1085. }
  1086. }
  1087. // QueryHsbyVisitorMarketGoodsDetailReq 查询游客三级市场(商城)商品信息详情请求参数
  1088. type QueryHsbyVisitorMarketGoodsDetailReq struct {
  1089. GoodsID int `form:"goodsID" binding:"required"`
  1090. }
  1091. // QueryHsbyVisitorMarketGoodsDetail 查询游客三级市场(商城)商品信息详情
  1092. // @Summary 查询游客三级市场(商城)商品信息详情
  1093. // @Description 说明:使用于未登录状态查询商城商品详情,登录后请使用QueryHsbyMarketGoodsDetail接口进行查询。
  1094. // @Produce json
  1095. // @Security ApiKeyAuth
  1096. // @Param goodsID query int true "商品ID"
  1097. // @Success 200 {object} models.HsbyMarketGoodsDetail
  1098. // @Failure 500 {object} app.Response
  1099. // @Router /HSBY/QueryHsbyVisitorMarketGoodsDetail [get]
  1100. // @Tags 定制【海商报业】
  1101. func QueryHsbyVisitorMarketGoodsDetail(c *gin.Context) {
  1102. appG := app.Gin{C: c}
  1103. // 获取请求参数
  1104. var req QueryHsbyVisitorMarketGoodsDetailReq
  1105. if err := appG.C.ShouldBindQuery(&req); err != nil {
  1106. logger.GetLogger().Errorf("QueryHsbyVisitorMarketGoodsDetail failed: %s", err.Error())
  1107. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  1108. return
  1109. }
  1110. // 获取数据
  1111. detail, err := models.GetHsbyMarketGoodsDetailByVisitor(req.GoodsID)
  1112. if err != nil {
  1113. // 查询失败
  1114. logger.GetLogger().Errorf("QueryHsbyVisitorMarketGoodsDetail failed: %s", err.Error())
  1115. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  1116. return
  1117. }
  1118. // 查询成功返回
  1119. logger.GetLogger().Debugln("QueryHsbyVisitorMarketGoodsDetail successed: %v", detail)
  1120. appG.Response(http.StatusOK, e.SUCCESS, detail)
  1121. }
  1122. // QueryHsbyMarketGoodsDetailReq 查询三级市场(商城)商品信息详情请求参数
  1123. type QueryHsbyMarketGoodsDetailReq struct {
  1124. OrderID int `form:"orderID" binding:"required"`
  1125. AccountID int `form:"accountID"`
  1126. }
  1127. // QueryHsbyMarketGoodsDetail 查询三级市场(商城)商品信息详情
  1128. // @Summary 查询三级市场(商城)商品信息详情
  1129. // @Produce json
  1130. // @Security ApiKeyAuth
  1131. // @Param orderID query int true "委托单号"
  1132. // @Param accountID query int false "资金账户,主要用于判断商品最大开仓手数;如未登录可不传。"
  1133. // @Success 200 {object} models.HsbyMarketGoodsDetail
  1134. // @Failure 500 {object} app.Response
  1135. // @Router /HSBY/QueryHsbyMarketGoodsDetail [get]
  1136. // @Tags 定制【海商报业】
  1137. func QueryHsbyMarketGoodsDetail(c *gin.Context) {
  1138. appG := app.Gin{C: c}
  1139. // 获取请求参数
  1140. var req QueryHsbyMarketGoodsDetailReq
  1141. if err := appG.C.ShouldBindQuery(&req); err != nil {
  1142. logger.GetLogger().Errorf("QueryHsbyMarketGoodsDetail failed: %s", err.Error())
  1143. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  1144. return
  1145. }
  1146. // 获取数据
  1147. detail, err := models.GetHsbyMarketGoodsDetail(req.OrderID, req.AccountID)
  1148. if err != nil {
  1149. // 查询失败
  1150. logger.GetLogger().Errorf("QueryHsbyMarketGoodsDetail failed: %s", err.Error())
  1151. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  1152. return
  1153. }
  1154. // 获取交易规则
  1155. rule, err := models.GetTodayAccountTradeRule(int(detail.Accountid), int(detail.Goodsid))
  1156. if err != nil {
  1157. // 查询失败
  1158. logger.GetLogger().Errorf("QueryHsbyListingGoodsDetail failed: %s", err.Error())
  1159. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  1160. return
  1161. }
  1162. if rule != nil {
  1163. tradeRuleInfoStruct := &pb.TradeRuleInfoStruct{}
  1164. if err := proto.Unmarshal([]byte(rule.Infocontent), tradeRuleInfoStruct); err != nil {
  1165. // 查询失败
  1166. logger.GetLogger().Errorf("QueryHsbyListingGoodsDetail failed: %s", err.Error())
  1167. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  1168. return
  1169. }
  1170. // INSERT INTO TRADERULEDESCRIPTION (RULEID, RULENAME, REGEXPRESS, DEFAULTVALUE, REMARK) VALUES (103, '单笔最小交易量', '^[1-9]\d*$', 1, '请输入正整数!');
  1171. for _, v := range tradeRuleInfoStruct.TradeRules {
  1172. if int(*v.RuleID) == 103 {
  1173. detail.LotSize = int(*v.ParamValue)
  1174. }
  1175. // 商城的最大建仓手数与预售的不一样,直接从规则里取
  1176. if int(*v.RuleID) == 104 {
  1177. detail.Buymaxqty = int(*v.ParamValue)
  1178. }
  1179. }
  1180. }
  1181. // 查询成功返回
  1182. logger.GetLogger().Debugln("QueryHsbyMarketGoodsDetail successed: %v", detail)
  1183. appG.Response(http.StatusOK, e.SUCCESS, detail)
  1184. }
  1185. // QueryMyCouponsReq 我的优惠卷查询请求参数
  1186. type QueryMyCouponsReq struct {
  1187. AccountIDs string `form:"accountIDs" binding:"required"`
  1188. GoodsID int `form:"goodsID"`
  1189. SellUserID int `form:"sellUserID"`
  1190. }
  1191. // QueryMyCoupons 我的优惠卷查询
  1192. // @Summary 我的优惠卷查询
  1193. // @Produce json
  1194. // @Security ApiKeyAuth
  1195. // @Param accountIDs query string true "资金账户列表,格式:1,2,3"
  1196. // @Param goodsID query int false "商品ID, 一般与sellUserID配套传入"
  1197. // @Param sellUserID query int false "卖方UserID"
  1198. // @Success 200 {object} models.MyCoupon
  1199. // @Failure 500 {object} app.Response
  1200. // @Router /HSBY/QueryMyCoupons [get]
  1201. // @Tags 定制【海商报业】
  1202. func QueryMyCoupons(c *gin.Context) {
  1203. appG := app.Gin{C: c}
  1204. // 获取请求参数
  1205. var req QueryMyCouponsReq
  1206. if err := appG.C.ShouldBindQuery(&req); err != nil {
  1207. logger.GetLogger().Errorf("QueryMyCoupons failed: %s", err.Error())
  1208. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  1209. return
  1210. }
  1211. // 获取数据
  1212. myCoupons, err := models.GetMyCoupons(req.AccountIDs, req.GoodsID, req.SellUserID)
  1213. if err != nil {
  1214. // 查询失败
  1215. logger.GetLogger().Errorf("QueryMyCoupons failed: %s", err.Error())
  1216. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  1217. return
  1218. }
  1219. // 查询成功返回
  1220. logger.GetLogger().Debugln("QueryMyCoupons successed: %v", myCoupons)
  1221. appG.Response(http.StatusOK, e.SUCCESS, myCoupons)
  1222. }
  1223. // QueryMyCouponHoldsReq 我的优惠卷持仓查询请求参数
  1224. type QueryMyCouponHoldsReq struct {
  1225. AccountIDs string `form:"accountIDs" binding:"required"`
  1226. HoldStatus string `form:"holdStatus"`
  1227. }
  1228. // QueryMyCouponHolds 我的优惠卷持仓查询
  1229. // @Summary 我的优惠卷持仓查询
  1230. // @Description 说明:当holdStatus传入4(已过期)后,会从历史表中查询已过期的优惠卷数据。
  1231. // @Produce json
  1232. // @Security ApiKeyAuth
  1233. // @Param accountIDs query string true "资金账户列表,格式:1,2,3"
  1234. // @Param holdStatus query string false "持仓状态 - 1:未生效 2:已生效 3:已使用 4:已过期,格式:1,2,3"
  1235. // @Success 200 {object} models.MyCouponHold
  1236. // @Failure 500 {object} app.Response
  1237. // @Router /HSBY/QueryMyCouponHolds [get]
  1238. // @Tags 定制【海商报业】
  1239. func QueryMyCouponHolds(c *gin.Context) {
  1240. appG := app.Gin{C: c}
  1241. // 获取请求参数
  1242. var req QueryMyCouponHoldsReq
  1243. if err := appG.C.ShouldBindQuery(&req); err != nil {
  1244. logger.GetLogger().Errorf("QueryMyCouponHolds failed: %s", err.Error())
  1245. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  1246. return
  1247. }
  1248. // 获取数据
  1249. myCoupons, err := models.GetMyCouponHolds(req.AccountIDs, req.HoldStatus)
  1250. if err != nil {
  1251. // 查询失败
  1252. logger.GetLogger().Errorf("QueryMyCouponHolds failed: %s", err.Error())
  1253. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  1254. return
  1255. }
  1256. // 查询成功返回
  1257. logger.GetLogger().Debugln("QueryMyCouponHolds successed: %v", myCoupons)
  1258. appG.Response(http.StatusOK, e.SUCCESS, myCoupons)
  1259. }
  1260. // QueryMyUsedCouponReq 已使用优惠卷查询请求参数
  1261. type QueryMyUsedCouponReq struct {
  1262. AccountIDs string `form:"accountIDs" binding:"required"`
  1263. }
  1264. // QueryMyUsedCoupon 已使用优惠卷查询
  1265. // @Summary 已使用优惠卷查询
  1266. // @Produce json
  1267. // @Security ApiKeyAuth
  1268. // @Param accountIDs query string true "资金账户列表,格式:1,2,3"
  1269. // @Success 200 {object} models.MyUsedCoupon
  1270. // @Failure 500 {object} app.Response
  1271. // @Router /HSBY/QueryMyUsedCoupon [get]
  1272. // @Tags 定制【海商报业】
  1273. func QueryMyUsedCoupon(c *gin.Context) {
  1274. appG := app.Gin{C: c}
  1275. // 获取请求参数
  1276. var req QueryMyUsedCouponReq
  1277. if err := appG.C.ShouldBindQuery(&req); err != nil {
  1278. logger.GetLogger().Errorf("QueryMyUsedCoupon failed: %s", err.Error())
  1279. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  1280. return
  1281. }
  1282. // 获取数据
  1283. myCoupons, err := models.GetMyUsedCoupon(req.AccountIDs)
  1284. if err != nil {
  1285. // 查询失败
  1286. logger.GetLogger().Errorf("QueryMyUsedCoupon failed: %s", err.Error())
  1287. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  1288. return
  1289. }
  1290. // 查询成功返回
  1291. logger.GetLogger().Debugln("QueryMyUsedCoupon successed: %v", myCoupons)
  1292. appG.Response(http.StatusOK, e.SUCCESS, myCoupons)
  1293. }
  1294. // QueryClientFixedADConfigs 获取终端固定广告配置
  1295. // @Summary 获取终端固定广告配置
  1296. // @Produce json
  1297. // @Security ApiKeyAuth
  1298. // @Success 200 {object} models.Clientfixedadconfig
  1299. // @Failure 500 {object} app.Response
  1300. // @Router /HSBY/QueryClientFixedADConfigs [get]
  1301. // @Tags 定制【海商报业】
  1302. func QueryClientFixedADConfigs(c *gin.Context) {
  1303. appG := app.Gin{C: c}
  1304. // 获取数据
  1305. adConfigs, err := models.GetClientFixedADConfigs()
  1306. if err != nil {
  1307. // 查询失败
  1308. logger.GetLogger().Errorf("QueryClientFixedADConfigs failed: %s", err.Error())
  1309. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  1310. return
  1311. }
  1312. // 查询成功返回
  1313. logger.GetLogger().Debugln("QueryClientFixedADConfigs successed: %v", adConfigs)
  1314. appG.Response(http.StatusOK, e.SUCCESS, adConfigs)
  1315. }