hsby.go 40 KB

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