hsby.go 40 KB

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