| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481 |
- package hsby
- import (
- "mtp2_if/global/app"
- "mtp2_if/global/e"
- "mtp2_if/logger"
- "mtp2_if/models"
- "mtp2_if/pb"
- "net/http"
- "sort"
- "github.com/gin-gonic/gin"
- "github.com/golang/protobuf/proto"
- )
- // QueryHsbyTopGoodsesReq 查询热门商品列表请求参数
- type QueryHsbyTopGoodsesReq struct {
- app.PageInfo
- MarketIDs string `form:"marketIDs" binding:"required"`
- DescProvinceID int `form:"descProvinceID"`
- DescCityID int `form:"descCityID"`
- }
- // QueryHsbyTopGoodses 查询热卖商品列表(二级市场挂牌点选)
- // @Summary 查询热卖商品列表(二级市场挂牌点选)
- // @Description 说明:查询结果已按Hotindex(景点热度)从大到小排序
- // @Produce json
- // @Security ApiKeyAuth
- // @Param page query int false "页码"
- // @Param pagesize query int false "每页条数"
- // @Param marketIDs query string true "市场ID列表,格式:1,2,3"
- // @Param descProvinceID query int false "目的地(省)ID"
- // @Param descCityID query int false "目的地(市)ID"
- // @Success 200 {object} models.HsbyTopGoods
- // @Failure 500 {object} app.Response
- // @Router /HSBY/QueryHsbyTopGoodses [get]
- // @Tags 定制【海商报业】
- func QueryHsbyTopGoodses(c *gin.Context) {
- appG := app.Gin{C: c}
- // 获取请求参数
- var req QueryHsbyTopGoodsesReq
- if err := appG.C.ShouldBindQuery(&req); err != nil {
- logger.GetLogger().Errorf("QueryHsbyTopGoodses failed: %s", err.Error())
- appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
- return
- }
- // 获取数据
- topGoodses, err := models.GetHsbyTopGoodses(req.MarketIDs, req.DescProvinceID, req.DescCityID)
- if err != nil {
- // 查询失败
- logger.GetLogger().Errorf("QueryHsbyTopGoodses failed: %s", err.Error())
- appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
- return
- }
- // 排序
- sort.Slice(topGoodses, func(i int, j int) bool {
- return topGoodses[i].Hotindex > topGoodses[j].Hotindex
- })
- // 分页
- total := len(topGoodses)
- if req.PageSize > 0 {
- rstByPage := make([]models.HsbyTopGoods, 0)
- // 开始上标
- start := req.Page * req.PageSize
- // 结束下标
- end := start + req.PageSize
- if start <= len(topGoodses) {
- // 判断结束下标是否越界
- if end > len(topGoodses) {
- end = len(topGoodses)
- }
- rstByPage = topGoodses[start:end]
- } else {
- rstByPage = topGoodses[0:0]
- }
- topGoodses = rstByPage
- }
- // 查询成功返回
- if req.PageSize > 0 {
- logger.GetLogger().Debugln("QueryHsbyTopGoodses successed: %v", topGoodses)
- appG.ResponseByPage(http.StatusOK, e.SUCCESS, topGoodses, app.PageInfo{Page: req.Page, PageSize: req.PageSize, Total: total})
- } else {
- logger.GetLogger().Debugln("QueryHsbyTopGoodses successed: %v", topGoodses)
- appG.Response(http.StatusOK, e.SUCCESS, topGoodses)
- }
- }
- // QueryHsbyListingGoodsDetailReq 查询二级市场(挂牌点选)商品信息详情请求参数
- type QueryHsbyListingGoodsDetailReq struct {
- GoodsID int `form:"goodsID" binding:"required"`
- AccountID int `form:"accountID"`
- }
- // QueryHsbyListingGoodsDetail 查询二级市场(挂牌点选)商品信息详情
- // @Summary 查询二级市场(挂牌点选)商品信息详情
- // @Description 说明:“我的商品”详情中,二级(挂牌点选)和三级(商城)的商品详情都使用此接口
- // @Produce json
- // @Security ApiKeyAuth
- // @Param goodsID query int true "商品ID"
- // @Param accountID query int false "资金账户,主要用于获取交易规则。不传则获取通用规则。"
- // @Success 200 {object} models.HsbyListingGoodsDetail
- // @Failure 500 {object} app.Response
- // @Router /HSBY/QueryHsbyListingGoodsDetail [get]
- // @Tags 定制【海商报业】
- func QueryHsbyListingGoodsDetail(c *gin.Context) {
- appG := app.Gin{C: c}
- // 获取请求参数
- var req QueryHsbyListingGoodsDetailReq
- if err := appG.C.ShouldBindQuery(&req); err != nil {
- logger.GetLogger().Errorf("QueryHsbyListingGoodsDetail failed: %s", err.Error())
- appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
- return
- }
- // 获取数据
- goodsInfo, err := models.GetHsbyListingGoodsDetail(req.GoodsID, req.AccountID)
- if err != nil {
- // 查询失败
- logger.GetLogger().Errorf("QueryHsbyListingGoodsDetail failed: %s", err.Error())
- appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
- return
- }
- // 获取交易规则
- rule, err := models.GetTodayAccountTradeRule(req.AccountID, req.GoodsID)
- if err != nil {
- // 查询失败
- logger.GetLogger().Errorf("QueryHsbyListingGoodsDetail failed: %s", err.Error())
- appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
- return
- }
- if rule != nil {
- tradeRuleInfoStruct := &pb.TradeRuleInfoStruct{}
- if err := proto.Unmarshal([]byte(rule.Infocontent), tradeRuleInfoStruct); err != nil {
- // 查询失败
- logger.GetLogger().Errorf("QueryHsbyListingGoodsDetail failed: %s", err.Error())
- appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
- return
- }
- // INSERT INTO TRADERULEDESCRIPTION (RULEID, RULENAME, REGEXPRESS, DEFAULTVALUE, REMARK) VALUES (103, '单笔最小交易量', '^[1-9]\d*$', 1, '请输入正整数!');
- for _, v := range tradeRuleInfoStruct.TradeRules {
- if int(*v.RuleID) == 103 {
- goodsInfo.LotSize = int(*v.ParamValue)
- }
- // 挂牌点选的最大建仓手数与预售的不一样,直接从规则里取
- if int(*v.RuleID) == 104 {
- goodsInfo.Buymaxqty = int(*v.ParamValue)
- }
- }
- }
- // 查询成功返回
- logger.GetLogger().Debugln("QueryHsbyListingGoodsDetail successed: %v", goodsInfo)
- appG.Response(http.StatusOK, e.SUCCESS, goodsInfo)
- }
- // QueryHsbyGoodsOrderDetailsReq 查询二级市场(挂牌点选)商品对应的挂牌委托单信息请求参数
- type QueryHsbyGoodsOrderDetailsReq struct {
- GoodsID int `form:"goodsID" binding:"required"`
- AccountIDs string `form:"accountIDs"`
- BuyOrSell int `form:"buyOrSell"`
- Price float64 `form:"price"`
- Speed int `form:"speed"`
- }
- // QueryHsbyGoodsOrderDetails 查询二级市场(挂牌点选)商品对应的挂牌委托单信息
- // @Summary 查询二级市场(挂牌点选)商品对应的挂牌委托单信息
- // @Description 说明:查询结果已按委托价格和委托时间排序
- // @Produce json
- // @Security ApiKeyAuth
- // @Param goodsID query int true "商品ID"
- // @Param accountIDs query string false "摘牌方资金账户列表,格式:1,2,3。主要用于过滤自己的挂牌单"
- // @Param buyOrSell query int false "挂牌委托单方向(对手单方向),0:买 1:卖"
- // @Param price query number false " 参考价格。对手单买方向委托单则价格大于等于(站在摘牌人的角度,摘牌方面是卖,我的闲置下单);对手单卖方向委托单则价格小于等于(站在摘牌人的角度,摘牌方面是买,热门商品下单)"
- // @Param speed query int false "档位,不传则默认为3档"
- // @Success 200 {object} models.HsbyGoodsOrderDetail
- // @Failure 500 {object} app.Response
- // @Router /HSBY/QueryHsbyGoodsOrderDetails [get]
- // @Tags 定制【海商报业】
- func QueryHsbyGoodsOrderDetails(c *gin.Context) {
- appG := app.Gin{C: c}
- // 获取请求参数
- var req QueryHsbyGoodsOrderDetailsReq
- if err := appG.C.ShouldBindQuery(&req); err != nil {
- logger.GetLogger().Errorf("QueryHsbyGoodsOrderDetails failed: %s", err.Error())
- appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
- return
- }
- // 获取数据
- orderDetails, err := models.GetHsbyGoodsOrderDetails(req.GoodsID, req.BuyOrSell, req.Price, req.AccountIDs)
- if err != nil {
- // 查询失败
- logger.GetLogger().Errorf("QueryHsbyGoodsOrderDetails failed: %s", err.Error())
- appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
- return
- }
- // 按时间和价格排序
- if req.BuyOrSell == 0 {
- // 买方向
- sort.Slice(orderDetails, func(i int, j int) bool {
- // 委托价格一样则按时间顺序排
- if orderDetails[i].Orderprice == orderDetails[j].Orderprice {
- return orderDetails[i].Ordertime.Before(orderDetails[j].Ordertime)
- }
- // 站在摘牌者的角度,买方向的委托单价格高的在前面
- return orderDetails[i].Orderprice > orderDetails[j].Orderprice
- })
- } else {
- // 卖方向
- sort.Slice(orderDetails, func(i int, j int) bool {
- // 委托价格一样则按时间顺序排
- if orderDetails[i].Orderprice == orderDetails[j].Orderprice {
- return orderDetails[i].Ordertime.Before(orderDetails[j].Ordertime)
- }
- return orderDetails[i].Orderprice < orderDetails[j].Orderprice
- })
- }
- // 取N档,默认3档
- if req.Speed == 0 {
- req.Speed = 3
- }
- // 判断结束下标是否越界
- end := req.Speed
- if req.Speed > len(orderDetails) {
- end = len(orderDetails)
- }
- orderDetails = orderDetails[0:end]
- // 查询成功返回
- logger.GetLogger().Debugln("QueryHsbyGoodsOrderDetails successed: %v", orderDetails)
- appG.Response(http.StatusOK, e.SUCCESS, orderDetails)
- }
- // QueryHsbyMyBuyOrderDetailsReq 查询“我的订单”信息请求参数
- type QueryHsbyMyBuyOrderDetailsReq struct {
- AccountIDs string `form:"accountIDs" binding:"required"`
- MyBuyStatus int `form:"myBuyStatus"`
- }
- // QueryHsbyMyBuyOrderDetails 查询“我的订单”信息
- // @Summary 查询“我的订单”信息
- // @Description 说明: myBuyStatus: 1,2 - 待成交;3 - 已提交;4 - 已撤消;5 - 委托失败
- // @Produce json
- // @Security ApiKeyAuth
- // @Param accountIDs query string true "资金账户列表,格式:1,2,3"
- // @Success 200 {object} models.HybsMyBuyOrderDetail
- // @Failure 500 {object} app.Response
- // @Router /HSBY/QueryHsbyMyBuyOrderDetails [get]
- // @Tags 定制【海商报业】
- func QueryHsbyMyBuyOrderDetails(c *gin.Context) {
- appG := app.Gin{C: c}
- // 获取请求参数
- var req QueryHsbyMyBuyOrderDetailsReq
- if err := appG.C.ShouldBindQuery(&req); err != nil {
- logger.GetLogger().Errorf("QueryHsbyMyBuyOrderDetails failed: %s", err.Error())
- appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
- return
- }
- // 获取数据
- myOrderDetails, err := models.GetHsbyBuyMyOrderDetails(req.AccountIDs, req.MyBuyStatus)
- if err != nil {
- // 查询失败
- logger.GetLogger().Errorf("QueryHsbyMyBuyOrderDetails failed: %s", err.Error())
- appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
- return
- }
- // 按时间排序
- sort.Slice(myOrderDetails, func(i int, j int) bool {
- return myOrderDetails[i].Ordertime.After(myOrderDetails[j].Ordertime)
- })
- // 查询成功返回
- logger.GetLogger().Debugln("QueryHsbyMyBuyOrderDetails successed: %v", myOrderDetails)
- appG.Response(http.StatusOK, e.SUCCESS, myOrderDetails)
- }
- // QueryHsbyMyGoodsReq 查询“我的商品”请求参数
- type QueryHsbyMyGoodsReq struct {
- AccountIDs string `form:"accountIDs" binding:"required"`
- }
- // QueryHsbyMyGoods 查询“我的商品”信息
- // @Summary 查询“我的商品”信息
- // @Description 说明: 挂牌点选(tradeMode = 16)价格取last; 商城(tradeMode = 70)价格取goodsprice
- // @Produce json
- // @Security ApiKeyAuth
- // @Param accountIDs query string true "资金账户列表,格式:1,2,3"
- // @Success 200 {object} models.HsbyMyGoods
- // @Failure 500 {object} app.Response
- // @Router /HSBY/QueryHsbyMyGoods [get]
- // @Tags 定制【海商报业】
- func QueryHsbyMyGoods(c *gin.Context) {
- appG := app.Gin{C: c}
- // 获取请求参数
- var req QueryHsbyMyGoodsReq
- if err := appG.C.ShouldBindQuery(&req); err != nil {
- logger.GetLogger().Errorf("QueryHsbyMyGoods failed: %s", err.Error())
- appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
- return
- }
- // 获取数据
- myGoodses, err := models.GetHsbyMyGoods(req.AccountIDs)
- if err != nil {
- // 查询失败
- logger.GetLogger().Errorf("QueryHsbyMyGoods failed: %s", err.Error())
- appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
- return
- }
- // 查询成功返回
- logger.GetLogger().Debugln("QueryHsbyMyGoods successed: %v", myGoodses)
- appG.Response(http.StatusOK, e.SUCCESS, myGoodses)
- }
- // QueryHsbyPreGoodsesReq 查询新品上市商品列表请求参数
- type QueryHsbyPreGoodsesReq struct {
- app.PageInfo
- MarketIDs string `form:"marketIDs" binding:"required"`
- DescProvinceID int `form:"descProvinceID"`
- DescCityID int `form:"descCityID"`
- }
- // QueryHsbyPreGoodses 查询新品上市商品列表(一级市场预售)
- // @Summary 查询新品上市商品列表(一级市场预售)
- // @Description 说明:结果已先显示已开始商品(按结束时间顺序排),再显示未开始商品(按开始时间顺序排)
- // @Produce json
- // @Security ApiKeyAuth
- // @Param page query int false "页码"
- // @Param pagesize query int false "每页条数"
- // @Param marketIDs query string true "市场ID列表,格式:1,2,3"
- // @Param descProvinceID query int false "目的地(省)ID"
- // @Param descCityID query int false "目的地(市)ID"
- // @Success 200 {object} models.HsbyPreGoods
- // @Failure 500 {object} app.Response
- // @Router /HSBY/QueryHsbyPreGoodses [get]
- // @Tags 定制【海商报业】
- func QueryHsbyPreGoodses(c *gin.Context) {
- appG := app.Gin{C: c}
- // 获取请求参数
- var req QueryHsbyPreGoodsesReq
- if err := appG.C.ShouldBindQuery(&req); err != nil {
- logger.GetLogger().Errorf("QueryHsbyPreGoodses failed: %s", err.Error())
- appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
- return
- }
- // 获取数据
- preGoodses, err := models.GetHsbyPreGoodses(req.MarketIDs, req.DescProvinceID, req.DescCityID)
- if err != nil {
- // 查询失败
- logger.GetLogger().Errorf("QueryHsbyPreGoodses failed: %s", err.Error())
- appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
- return
- }
- // 排序,先显示已开始商品(按结束时间顺序排),再显示未开始商品(按开始时间顺序排)
- sort.Slice(preGoodses, func(i int, j int) bool {
- if preGoodses[i].Goodsstatus == 3 && preGoodses[j].Goodsstatus == 2 {
- // 先显示已开始商品
- return true
- } else if preGoodses[i].Goodsstatus == 3 && preGoodses[j].Goodsstatus == 3 {
- // 已开始商品按结束时间顺序排
- return preGoodses[i].Lasttradedate.Before(preGoodses[j].Lasttradedate)
- } else if preGoodses[i].Goodsstatus == 2 && preGoodses[j].Goodsstatus == 2 {
- // 未开始商品按开始时间顺序排
- return preGoodses[i].Listingdate.Before(preGoodses[j].Listingdate)
- }
- return false
- })
- // 分页
- total := len(preGoodses)
- if req.PageSize > 0 {
- rstByPage := make([]models.HsbyPreGoods, 0)
- // 开始上标
- start := req.Page * req.PageSize
- // 结束下标
- end := start + req.PageSize
- if start <= len(preGoodses) {
- // 判断结束下标是否越界
- if end > len(preGoodses) {
- end = len(preGoodses)
- }
- rstByPage = preGoodses[start:end]
- } else {
- rstByPage = preGoodses[0:0]
- }
- preGoodses = rstByPage
- }
- // 查询成功返回
- if req.PageSize > 0 {
- logger.GetLogger().Debugln("QueryHsbyPreGoodses successed: %v", preGoodses)
- appG.ResponseByPage(http.StatusOK, e.SUCCESS, preGoodses, app.PageInfo{Page: req.Page, PageSize: req.PageSize, Total: total})
- } else {
- logger.GetLogger().Debugln("QueryHsbyPreGoodses successed: %v", preGoodses)
- appG.Response(http.StatusOK, e.SUCCESS, preGoodses)
- }
- }
- // QueryHsbyPreGoodsDetailReq 查询一级市场(预售)商品信息详情请求参数
- type QueryHsbyPreGoodsDetailReq struct {
- GoodsID int `form:"goodsID" binding:"required"`
- AccountID int `form:"accountID"`
- }
- // QueryHsbyPreGoodsDetail 查询一级市场(预售)商品信息详情
- // @Summary 查询一级市场(预售)商品信息详情
- // @Produce json
- // @Security ApiKeyAuth
- // @Param goodsID query int true "商品ID"
- // @Param accountID query int false "资金账户,主要用于获取预售商品购买上限"
- // @Success 200 {object} models.HsbyPreGoodsDetail
- // @Failure 500 {object} app.Response
- // @Router /HSBY/QueryHsbyPreGoodsDetail [get]
- // @Tags 定制【海商报业】
- func QueryHsbyPreGoodsDetail(c *gin.Context) {
- appG := app.Gin{C: c}
- // 获取请求参数
- var req QueryHsbyPreGoodsDetailReq
- if err := appG.C.ShouldBindQuery(&req); err != nil {
- logger.GetLogger().Errorf("QueryHsbyPreGoodsDetail failed: %s", err.Error())
- appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
- return
- }
- // 获取数据
- goodsInfo, err := models.GetHsbyPreGoodsDetail(req.GoodsID, req.AccountID)
- if err != nil {
- // 查询失败
- logger.GetLogger().Errorf("QueryHsbyPreGoodsDetail failed: %s", err.Error())
- appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
- return
- }
- // 查询成功返回
- logger.GetLogger().Debugln("QueryHsbyPreGoodsDetail successed: %v", goodsInfo)
- appG.Response(http.StatusOK, e.SUCCESS, goodsInfo)
- }
- // QueryHsbySellMyDetailReq 查询"我的闲置"单据信息请求参数
- type QueryHsbySellMyDetailReq struct {
- app.PageInfo
- AccountIDs string `form:"accountIDs" binding:"required"`
- OrderType int `form:"orderType"`
- }
- // QueryHsbySellMyDetails 查询"我的闲置"单据信息
- // @Summary 查询"我的闲置"单据信息
- // @Description 说明:发布中 - 二级市场卖挂,3:委托成功、7:部分成交; 已完成 - 二级市场成交单,包括历史数据。查询结果已按时间从近到远排序
- // @Produce json
- // @Security ApiKeyAuth
- // @Param page query int false "页码"
- // @Param pagesize query int false "每页条数"
- // @Param accountIDs query string true "资金账户列表,格式:1,2,3"
- // @Param orderType query int false "单据类型:0 - 发布中(默认), 1 - 已完成"
- // @Success 200 {object} models.HsbySellMyDetail
- // @Failure 500 {object} app.Response
- // @Router /HSBY/QueryHsbySellMyDetails [get]
- // @Tags 定制【海商报业】
- func QueryHsbySellMyDetails(c *gin.Context) {
- appG := app.Gin{C: c}
- // 获取请求参数
- var req QueryHsbySellMyDetailReq
- if err := appG.C.ShouldBindQuery(&req); err != nil {
- logger.GetLogger().Errorf("QueryHsbySellMyDetails failed: %s", err.Error())
- appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
- return
- }
- // 获取数据
- var orders []models.HsbySellMyDetail
- if req.OrderType == 0 {
- // 发布中
- var err error
- orders, err = models.GetHsbySellMyOrderDetails(req.AccountIDs)
- if err != nil {
- // 查询失败
- logger.GetLogger().Errorf("QueryHsbySellMyDetails failed: %s", err.Error())
- appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
- return
- }
- } else {
- // 已完成
- var err error
- orders, err = models.GetHsbySellMyTradeDetails(req.AccountIDs)
- if err != nil {
- // 查询失败
- logger.GetLogger().Errorf("QueryHsbySellMyDetails failed: %s", err.Error())
- appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
- return
- }
- }
- // 排序
- sort.Slice(orders, func(i int, j int) bool {
- return orders[i].Time.After(orders[j].Time)
- })
- // 分页
- total := len(orders)
- if req.PageSize > 0 {
- rstByPage := make([]models.HsbySellMyDetail, 0)
- // 开始上标
- start := req.Page * req.PageSize
- // 结束下标
- end := start + req.PageSize
- if start <= len(orders) {
- // 判断结束下标是否越界
- if end > len(orders) {
- end = len(orders)
- }
- rstByPage = orders[start:end]
- } else {
- rstByPage = orders[0:0]
- }
- orders = rstByPage
- }
- // 查询成功返回
- if req.PageSize > 0 {
- logger.GetLogger().Debugln("QueryHsbySellMyDetails successed: %v", orders)
- appG.ResponseByPage(http.StatusOK, e.SUCCESS, orders, app.PageInfo{Page: req.Page, PageSize: req.PageSize, Total: total})
- } else {
- logger.GetLogger().Debugln("QueryHsbySellMyDetails successed: %v", orders)
- appG.Response(http.StatusOK, e.SUCCESS, orders)
- }
- }
- // QueryHsbyMyPackagesReq 查询我的包裹信息请求参数
- type QueryHsbyMyPackagesReq struct {
- AccountIDs string `form:"accountIDs" binding:"required"`
- TakeOrderStatus int `form:"takeOrderStatus"`
- }
- // QueryHsbyMyPackages 查询我的包裹信息
- // @Summary 查询我的包裹信息
- // @Produce json
- // @Security ApiKeyAuth
- // @Param accountIDs query string true "资金账户列表,格式:1,2,3"
- // @Param takeOrderStatus query int false "提货状态 - 1:待发货 2:已发货 3:已收货"
- // @Success 200 {object} models.HsbyMyPackage
- // @Failure 500 {object} app.Response
- // @Router /HSBY/QueryHsbyMyPackages [get]
- // @Tags 定制【海商报业】
- func QueryHsbyMyPackages(c *gin.Context) {
- appG := app.Gin{C: c}
- // 获取请求参数
- var req QueryHsbyMyPackagesReq
- if err := appG.C.ShouldBindQuery(&req); err != nil {
- logger.GetLogger().Errorf("QueryHsbyMyPackages failed: %s", err.Error())
- appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
- return
- }
- // 获取数据
- goodsInfo, err := models.GetHsbyMyPackages(req.AccountIDs, req.TakeOrderStatus)
- if err != nil {
- // 查询失败
- logger.GetLogger().Errorf("QueryHsbyMyPackages failed: %s", err.Error())
- appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
- return
- }
- // 查询成功返回
- logger.GetLogger().Debugln("QueryHsbyMyPackages successed: %v", goodsInfo)
- appG.Response(http.StatusOK, e.SUCCESS, goodsInfo)
- }
- // SetHsbyMyPackagesStatusReq 设置我的包裹已收货状态
- type SetHsbyMyPackagesStatusReq struct {
- TakeOrderID string `form:"takeOrderID" binding:"required"`
- AccountID int `form:"accountID" binding:"required"`
- }
- // SetHsbyMyPackagesStatus 设置我的包裹已收货状态
- // @Summary 设置我的包裹已收货状态
- // @Produce json
- // @Security ApiKeyAuth
- // @Param takeOrderID query string true "提货单号"
- // @Param accountID query int true "资金账号"
- // @Success 200 {object} app.Response
- // @Failure 500 {object} app.Response
- // @Router /HSBY/SetHsbyMyPackagesStatus [post]
- // @Tags 定制【海商报业】
- func SetHsbyMyPackagesStatus(c *gin.Context) {
- appG := app.Gin{C: c}
- // 获取请求参数
- var req SetHsbyMyPackagesStatusReq
- if err := appG.C.ShouldBind(&req); err != nil {
- logger.GetLogger().Errorf("SetHsbyMyPackagesStatus failed: %s", err.Error())
- appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
- return
- }
- // 3 - 已收货
- if err := models.SetHsbyMyPackagesStatus(req.TakeOrderID, req.AccountID, 3); err != nil {
- // 执行失败
- logger.GetLogger().Errorf("SetHsbyMyPackagesStatus failed: %s", err.Error())
- appG.Response(http.StatusBadRequest, e.ERROR_OPERATION_FAILED, nil)
- return
- }
- // 执行成功
- logger.GetLogger().Debugln("SetHsbyMyPackagesStatus successed: %v", "ok")
- appG.Response(http.StatusOK, e.SUCCESS, "")
- }
- // QueryProvincesAndCitiesReq 查询省市信息请求参数
- type QueryProvincesAndCitiesReq struct {
- ProvinceID int `form:"provinceID"` // 省ID
- }
- // QueryProvincesAndCitiesRsp 查询省市信息返回模型
- type QueryProvincesAndCitiesRsp struct {
- Province models.Division // 省
- Cities []models.Division // 市
- }
- // QueryProvincesAndCities 查询省市信息(不包括区)
- // @Summary 查询省市信息(不包括区)
- // @Description 查询结果只包括二级市场商品已关连的省市信息。
- // @Produce json
- // @Security ApiKeyAuth
- // @Param provinceID query int false "省ID"
- // @Success 200 {object} QueryProvincesAndCitiesRsp
- // @Failure 500 {object} app.Response
- // @Router /HSBY/QueryProvincesAndCities [get]
- // @Tags 定制【海商报业】
- func QueryProvincesAndCities(c *gin.Context) {
- appG := app.Gin{C: c}
- // 获取请求参数
- var req QueryProvincesAndCitiesReq
- if err := appG.C.ShouldBindQuery(&req); err != nil {
- logger.GetLogger().Errorf("QueryProvincesAndCities failed: %s", err.Error())
- appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
- return
- }
- // 获取省市信息
- provinces, err := models.GetHsbyProvincesAndCities(req.ProvinceID)
- if err != nil {
- // 查询失败
- logger.GetLogger().Errorf("QueryProvincesAndCities failed: %s", err.Error())
- appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
- return
- }
- // 分解省市数据
- // Golang Map元素取址问题: cannot assign to struct field XXXX in map
- // https://blog.csdn.net/makenothing/article/details/105037977
- pMap := make(map[string]*QueryProvincesAndCitiesRsp)
- // 构建省节点
- for _, v := range provinces {
- if v.Divisionlevel == "province" {
- pMap[v.Divisioncode] = &QueryProvincesAndCitiesRsp{Province: v, Cities: make([]models.Division, 0)}
- }
- }
- // 为省节点增加市信息
- for _, v := range provinces {
- if v.Divisionlevel == "city" {
- pMap[v.Parentcode].Cities = append(pMap[v.Parentcode].Cities, v)
- }
- }
- // map to slice
- rst := make([]QueryProvincesAndCitiesRsp, 0)
- for _, v := range pMap {
- rst = append(rst, *v)
- }
- // 查询成功
- logger.GetLogger().Debugln("QueryProvincesAndCities successed: %v", rst)
- appG.Response(http.StatusOK, e.SUCCESS, rst)
- }
- // QueryHsbyBuyMyTradeDetailReq 查询"我的订单 - 已完成"单据信息请求参数
- type QueryHsbyBuyMyTradeDetailReq struct {
- app.PageInfo
- AccountIDs string `form:"accountIDs" binding:"required"`
- }
- // QueryHsbyBuyMyTradeDetail 查询"我的订单 - 已完成"单据信息
- // @Summary 查询"我的订单 - 已完成"单据信息
- // @Produce json
- // @Security ApiKeyAuth
- // @Param page query int false "页码"
- // @Param pagesize query int false "每页条数"
- // @Param accountIDs query string true "资金账户列表,格式:1,2,3"
- // @Success 200 {object} models.HsbyBuyMyTradeDetail
- // @Failure 500 {object} app.Response
- // @Router /HSBY/QueryHsbyBuyMyTradeDetail [get]
- // @Tags 定制【海商报业】
- func QueryHsbyBuyMyTradeDetail(c *gin.Context) {
- appG := app.Gin{C: c}
- // 获取请求参数
- var req QueryHsbyBuyMyTradeDetailReq
- if err := appG.C.ShouldBindQuery(&req); err != nil {
- logger.GetLogger().Errorf("QueryHsbyBuyMyTradeDetail failed: %s", err.Error())
- appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
- return
- }
- // 获取数据
- var orders []models.HsbyBuyMyTradeDetail
- var err error
- orders, err = models.GetHsbyBuyMyTradeDetails(req.AccountIDs)
- if err != nil {
- // 查询失败
- logger.GetLogger().Errorf("QueryHsbyBuyMyTradeDetail failed: %s", err.Error())
- appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
- return
- }
- // 排序
- sort.Slice(orders, func(i int, j int) bool {
- return orders[i].Time.After(orders[j].Time)
- })
- // 分页
- total := len(orders)
- if req.PageSize > 0 {
- rstByPage := make([]models.HsbyBuyMyTradeDetail, 0)
- // 开始上标
- start := req.Page * req.PageSize
- // 结束下标
- end := start + req.PageSize
- if start <= len(orders) {
- // 判断结束下标是否越界
- if end > len(orders) {
- end = len(orders)
- }
- rstByPage = orders[start:end]
- } else {
- rstByPage = orders[0:0]
- }
- orders = rstByPage
- }
- // 查询成功返回
- if req.PageSize > 0 {
- logger.GetLogger().Debugln("QueryHsbyBuyMyTradeDetail successed: %v", orders)
- appG.ResponseByPage(http.StatusOK, e.SUCCESS, orders, app.PageInfo{Page: req.Page, PageSize: req.PageSize, Total: total})
- } else {
- logger.GetLogger().Debugln("QueryHsbyBuyMyTradeDetail successed: %v", orders)
- appG.Response(http.StatusOK, e.SUCCESS, orders)
- }
- }
- // GetHsbyMyCountReq 获取我的订单与包裹数量请求参数模型
- type GetHsbyMyCountReq struct {
- AccountIDs string `form:"accountIDs" binding:"required"`
- }
- // GetHsbyMyCountRsp 获取我的订单与包裹数量返回模型
- type GetHsbyMyCountRsp struct {
- MyOrderDetailPreCount int `json:"myOrderDetailPreCount"` // 我的订单抢购中数量
- MyOrderDetailListingCount int `json:"myOrderDetailListingCount"` // 我的订单求购中数量
- MyPackageUnSendCount int `json:"myPackageUnSendCount"` // 我的包裹待发货数量
- MyPackageUnReceiveCount int `json:"myPackageUnReceiveCount"` // 我的包裹待收货数量
- MyPayOrderCount int `json:"myPayOrderCount"` // 我的订单待付款数量
- MyCouponCount int `json:"myCouponCount"` // 我的优惠卷数量
- }
- // GetHsbyMyCount 获取我的订单与包裹数量
- // @Summary 获取我的订单与包裹数量
- // @Description 说明: 不包括已完成的数量。
- // @Produce json
- // @Security ApiKeyAuth
- // @Param accountIDs query string true "资金账户列表,格式:1,2,3"
- // @Success 200 {object} GetHsbyMyCountRsp
- // @Failure 500 {object} app.Response
- // @Router /HSBY/GetHsbyMyCount [get]
- // @Tags 定制【海商报业】
- func GetHsbyMyCount(c *gin.Context) {
- appG := app.Gin{C: c}
- // 获取请求参数
- var req GetHsbyMyCountReq
- if err := appG.C.ShouldBindQuery(&req); err != nil {
- logger.GetLogger().Errorf("GetHsbyMyCount failed: %s", err.Error())
- appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
- return
- }
- // 获取我的订单数据
- myOrderDetails, err := models.GetHsbyBuyMyOrderDetails(req.AccountIDs, 0)
- if err != nil {
- // 查询失败
- logger.GetLogger().Errorf("GetHsbyMyCount failed: %s", err.Error())
- appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
- return
- }
- // 获取我的包裹数据
- myPackages, err := models.GetHsbyMyPackages(req.AccountIDs, 0)
- if err != nil {
- // 查询失败
- logger.GetLogger().Errorf("GetHsbyMyCount failed: %s", err.Error())
- appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
- return
- }
- // 获取我的订单待付款数量
- myPayOrders, err := models.GetHsbyBuyMyPayOrders(req.AccountIDs, 0, 0)
- if err != nil {
- // 查询失败
- logger.GetLogger().Errorf("GetHsbyMyCount failed: %s", err.Error())
- appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
- return
- }
- // 获取我的优惠卷数量
- // myCoupons, err := models.GetMyCoupons(req.AccountIDs, 0, 0)
- // 改用优惠卷持仓明细
- myCoupons, err := models.GetMyCouponHolds(req.AccountIDs, "2")
- if err != nil {
- // 查询失败
- logger.GetLogger().Errorf("GetHsbyMyCount failed: %s", err.Error())
- appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
- return
- }
- // 统计数量
- rsp := GetHsbyMyCountRsp{}
- for _, v := range myOrderDetails {
- if v.MyBuyStatus == 1 {
- // 抢购中
- rsp.MyOrderDetailPreCount++
- } else if v.MyBuyStatus == 2 {
- // 求购中
- rsp.MyOrderDetailListingCount++
- }
- }
- for _, v := range myPackages {
- if v.Takeorderstatus == 1 {
- // 待发货
- rsp.MyPackageUnSendCount++
- } else if v.Takeorderstatus == 2 {
- // 待收货
- rsp.MyPackageUnReceiveCount++
- }
- }
- rsp.MyPayOrderCount = len(myPayOrders)
- for _, v := range myCoupons {
- rsp.MyCouponCount += int(v.Qty)
- }
- // 查询成功返回
- logger.GetLogger().Debugln("GetHsbyMyCount successed: %v", rsp)
- appG.Response(http.StatusOK, e.SUCCESS, rsp)
- }
- // QueryMyPayOrdersReq 我的订单中待付款信息查询请求参数
- type QueryMyPayOrdersReq struct {
- app.PageInfo
- AccountIDs string `form:"accountIDs" binding:"required"`
- BuyOrderID int `form:"buyOrderID"`
- SellOrderID int `form:"sellOrderID"`
- }
- // QueryMyPayOrders 获取我的订单中待付款信息
- // @Summary 获取我的订单中待付款信息
- // @Produce json
- // @Security ApiKeyAuth
- // @Param page query int false "页码"
- // @Param pagesize query int false "每页条数"
- // @Param accountIDs query string true "资金账户列表,格式:1,2,3"
- // @Param buyOrderID query int false "买方委托单号"
- // @Param sellOrderID query int false "卖方委托单号"
- // @Success 200 {object} models.HsbyBuyMyPayOrder
- // @Failure 500 {object} app.Response
- // @Router /HSBY/QueryMyPayOrders [get]
- // @Tags 定制【海商报业】
- func QueryMyPayOrders(c *gin.Context) {
- appG := app.Gin{C: c}
- // 获取请求参数
- var req QueryMyPayOrdersReq
- if err := appG.C.ShouldBindQuery(&req); err != nil {
- logger.GetLogger().Errorf("QueryMyPayOrders failed: %s", err.Error())
- appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
- return
- }
- // 获取数据
- orders, err := models.GetHsbyBuyMyPayOrders(req.AccountIDs, req.BuyOrderID, req.SellOrderID)
- if err != nil {
- // 查询失败
- logger.GetLogger().Errorf("QueryMyPayOrders failed: %s", err.Error())
- appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
- return
- }
- // 排序
- sort.Slice(orders, func(i int, j int) bool {
- return orders[i].Createtime.After(orders[j].Createtime)
- })
- // 分页
- total := len(orders)
- if req.PageSize > 0 {
- rstByPage := make([]models.HsbyBuyMyPayOrder, 0)
- // 开始上标
- start := req.Page * req.PageSize
- // 结束下标
- end := start + req.PageSize
- if start <= len(orders) {
- // 判断结束下标是否越界
- if end > len(orders) {
- end = len(orders)
- }
- rstByPage = orders[start:end]
- } else {
- rstByPage = orders[0:0]
- }
- orders = rstByPage
- }
- // 查询成功返回
- if req.PageSize > 0 {
- logger.GetLogger().Debugln("QueryMyPayOrders successed: %v", orders)
- appG.ResponseByPage(http.StatusOK, e.SUCCESS, orders, app.PageInfo{Page: req.Page, PageSize: req.PageSize, Total: total})
- } else {
- logger.GetLogger().Debugln("QueryMyPayOrders successed: %v", orders)
- appG.Response(http.StatusOK, e.SUCCESS, orders)
- }
- }
- // QueryMyCollectionOrdersReq 我的闲置中收款信息查询请求参数
- type QueryMyCollectionOrdersReq struct {
- app.PageInfo
- AccountIDs string `form:"accountIDs" binding:"required"`
- }
- // QueryMyCollectionOrders 我的闲置中收款信息查询
- // @Summary 我的闲置中收款信息查询
- // @Produce json
- // @Security ApiKeyAuth
- // @Param page query int false "页码"
- // @Param pagesize query int false "每页条数"
- // @Param accountIDs query string true "资金账户,格式:1,2,3"
- // @Success 200 {object} models.HsbySellCollectionOrder
- // @Failure 500 {object} app.Response
- // @Router /HSBY/QueryMyCollectionOrders [get]
- // @Tags 定制【海商报业】
- func QueryMyCollectionOrders(c *gin.Context) {
- appG := app.Gin{C: c}
- // 获取请求参数
- var req QueryMyCollectionOrdersReq
- if err := appG.C.ShouldBindQuery(&req); err != nil {
- logger.GetLogger().Errorf("QueryMyCollectionOrders failed: %s", err.Error())
- appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
- return
- }
- // 获取数据
- orders, err := models.GetHsbySellCollectionOrders(req.AccountIDs)
- if err != nil {
- // 查询失败
- logger.GetLogger().Errorf("QueryMyCollectionOrders failed: %s", err.Error())
- appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
- return
- }
- // 排序
- sort.Slice(orders, func(i int, j int) bool {
- return orders[i].Createtime.After(orders[j].Createtime)
- })
- // 分页
- total := len(orders)
- if req.PageSize > 0 {
- rstByPage := make([]models.HsbySellCollectionOrder, 0)
- // 开始上标
- start := req.Page * req.PageSize
- // 结束下标
- end := start + req.PageSize
- if start <= len(orders) {
- // 判断结束下标是否越界
- if end > len(orders) {
- end = len(orders)
- }
- rstByPage = orders[start:end]
- } else {
- rstByPage = orders[0:0]
- }
- orders = rstByPage
- }
- // 查询成功返回
- if req.PageSize > 0 {
- logger.GetLogger().Debugln("QueryMyCollectionOrders successed: %v", orders)
- appG.ResponseByPage(http.StatusOK, e.SUCCESS, orders, app.PageInfo{Page: req.Page, PageSize: req.PageSize, Total: total})
- } else {
- logger.GetLogger().Debugln("QueryMyCollectionOrders successed: %v", orders)
- appG.Response(http.StatusOK, e.SUCCESS, orders)
- }
- }
- // QueryHsbyMarkets 查询海商报业相关市场信息
- // @Summary 查询海商报业相关市场信息
- // @Produce json
- // @Security ApiKeyAuth
- // @Success 200 {object} models.HsbyMarketInfo
- // @Failure 500 {object} app.Response
- // @Router /HSBY/QueryHsbyMarkets [get]
- // @Tags 定制【海商报业】
- func QueryHsbyMarkets(c *gin.Context) {
- appG := app.Gin{C: c}
- // 获取数据
- markets, err := models.GetHsbyMarketInfos()
- if err != nil {
- // 查询失败
- logger.GetLogger().Errorf("QueryHsbyMarkets failed: %s", err.Error())
- appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
- return
- }
- // 查询成功返回
- logger.GetLogger().Debugln("QueryHsbyMarkets successed: %v", markets)
- appG.Response(http.StatusOK, e.SUCCESS, markets)
- }
- // QueryHsbyVisitorMarketGoodsesReq 查询游客特卖商品列表(三级商城)请求参数
- type QueryHsbyVisitorMarketGoodsesReq struct {
- app.PageInfo
- MarketIDs string `form:"marketIDs" binding:"required"`
- CategoryID int `form:"categoryID"`
- GoodsIDs string `form:"goodsIDs"`
- }
- // QueryHsbyVisitorMarketGoodses 查询游客特卖商品列表(三级商城)
- // @Summary 查询游客特卖商品列表(三级商城)
- // @Description 说明:使用于未登录状态查询商城商品列表,登录后请使用QueryHsbyMarketGoodses接口进行查询。
- // @Produce json
- // @Security ApiKeyAuth
- // @Param page query int false "页码"
- // @Param pagesize query int false "每页条数"
- // @Param marketIDs query string true "市场ID列表,格式:1,2,3"
- // @Param categoryID query int false "类别ID"
- // @Param goodsIDs query string false "商品ID列表,格式:1,2,3。主要用于商品搜索。"
- // @Success 200 {object} models.HsbyMarketGoods
- // @Failure 500 {object} app.Response
- // @Router /HSBY/QueryHsbyVisitorMarketGoodses [get]
- // @Tags 定制【海商报业】
- func QueryHsbyVisitorMarketGoodses(c *gin.Context) {
- appG := app.Gin{C: c}
- // 获取请求参数
- var req QueryHsbyVisitorMarketGoodsesReq
- if err := appG.C.ShouldBindQuery(&req); err != nil {
- logger.GetLogger().Errorf("QueryHsbyVisitorMarketGoodses failed: %s", err.Error())
- appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
- return
- }
- // 获取数据
- goodses, err := models.GetHsbyMarketGoodsesByVisitor(req.MarketIDs, req.CategoryID, req.GoodsIDs)
- if err != nil {
- // 查询失败
- logger.GetLogger().Errorf("QueryHsbyVisitorMarketGoodses failed: %s", err.Error())
- appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
- return
- }
- // 排序
- sort.Slice(goodses, func(i int, j int) bool {
- return goodses[i].Hotindex > goodses[j].Hotindex
- })
- // 分页
- total := len(goodses)
- if req.PageSize > 0 {
- rstByPage := make([]models.HsbyMarketGoods, 0)
- // 开始上标
- start := req.Page * req.PageSize
- // 结束下标
- end := start + req.PageSize
- if start <= len(goodses) {
- // 判断结束下标是否越界
- if end > len(goodses) {
- end = len(goodses)
- }
- rstByPage = goodses[start:end]
- } else {
- rstByPage = goodses[0:0]
- }
- goodses = rstByPage
- }
- // 查询成功返回
- if req.PageSize > 0 {
- logger.GetLogger().Debugln("QueryHsbyVisitorMarketGoodses successed: %v", goodses)
- appG.ResponseByPage(http.StatusOK, e.SUCCESS, goodses, app.PageInfo{Page: req.Page, PageSize: req.PageSize, Total: total})
- } else {
- logger.GetLogger().Debugln("QueryHsbyVisitorMarketGoodses successed: %v", goodses)
- appG.Response(http.StatusOK, e.SUCCESS, goodses)
- }
- }
- // QueryHsbyMarketGoodsesReq 查询特卖商品列表(三级商城)请求参数
- type QueryHsbyMarketGoodsesReq struct {
- app.PageInfo
- MarketIDs string `form:"marketIDs" binding:"required"`
- AccountID int `form:"accountID" binding:"required"`
- CategoryID int `form:"categoryID"`
- GoodsIDs string `form:"goodsIDs"`
- CouponTypeID int `form:"couponTypeID"`
- }
- // QueryHsbyMarketGoodses 查询特卖商品列表(三级商城)
- // @Summary 查询特卖商品列表(三级商城)
- // @Produce json
- // @Security ApiKeyAuth
- // @Param page query int false "页码"
- // @Param pagesize query int false "每页条数"
- // @Param marketIDs query string true "市场ID列表,格式:1,2,3"
- // @Param accountID query int true "资金账户,用于判断商品是否有可用的优惠卷;同时只显示此账户所属机构下的商城委托单。"
- // @Param categoryID query int false "类别ID"
- // @Param goodsIDs query string false "商品ID列表,格式:1,2,3。主要用于商品搜索。"
- // @Param couponTypeID query int false "优惠券类型ID,主要用于显示优惠卷对应的商品列表。"
- // @Success 200 {object} models.HsbyMarketGoods
- // @Failure 500 {object} app.Response
- // @Router /HSBY/QueryHsbyMarketGoodses [get]
- // @Tags 定制【海商报业】
- func QueryHsbyMarketGoodses(c *gin.Context) {
- appG := app.Gin{C: c}
- // 获取请求参数
- var req QueryHsbyMarketGoodsesReq
- if err := appG.C.ShouldBindQuery(&req); err != nil {
- logger.GetLogger().Errorf("QueryHsbyMarketGoodses failed: %s", err.Error())
- appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
- return
- }
- // 获取数据
- goodses, err := models.GetHsbyMarketGoodses(req.MarketIDs, req.AccountID, req.CategoryID, req.GoodsIDs, req.CouponTypeID)
- if err != nil {
- // 查询失败
- logger.GetLogger().Errorf("QueryHsbyMarketGoodses failed: %s", err.Error())
- appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
- return
- }
- // 排序
- sort.Slice(goodses, func(i int, j int) bool {
- return goodses[i].Hotindex > goodses[j].Hotindex
- })
- // 分页
- total := len(goodses)
- if req.PageSize > 0 {
- rstByPage := make([]models.HsbyMarketGoods, 0)
- // 开始上标
- start := req.Page * req.PageSize
- // 结束下标
- end := start + req.PageSize
- if start <= len(goodses) {
- // 判断结束下标是否越界
- if end > len(goodses) {
- end = len(goodses)
- }
- rstByPage = goodses[start:end]
- } else {
- rstByPage = goodses[0:0]
- }
- goodses = rstByPage
- }
- // 查询成功返回
- if req.PageSize > 0 {
- logger.GetLogger().Debugln("QueryHsbyMarketGoodses successed: %v", goodses)
- appG.ResponseByPage(http.StatusOK, e.SUCCESS, goodses, app.PageInfo{Page: req.Page, PageSize: req.PageSize, Total: total})
- } else {
- logger.GetLogger().Debugln("QueryHsbyMarketGoodses successed: %v", goodses)
- appG.Response(http.StatusOK, e.SUCCESS, goodses)
- }
- }
- // QueryHsbyVisitorMarketGoodsDetailReq 查询游客三级市场(商城)商品信息详情请求参数
- type QueryHsbyVisitorMarketGoodsDetailReq struct {
- GoodsID int `form:"goodsID" binding:"required"`
- }
- // QueryHsbyVisitorMarketGoodsDetail 查询游客三级市场(商城)商品信息详情
- // @Summary 查询游客三级市场(商城)商品信息详情
- // @Description 说明:使用于未登录状态查询商城商品详情,登录后请使用QueryHsbyMarketGoodsDetail接口进行查询。
- // @Produce json
- // @Security ApiKeyAuth
- // @Param goodsID query int true "商品ID"
- // @Success 200 {object} models.HsbyMarketGoodsDetail
- // @Failure 500 {object} app.Response
- // @Router /HSBY/QueryHsbyVisitorMarketGoodsDetail [get]
- // @Tags 定制【海商报业】
- func QueryHsbyVisitorMarketGoodsDetail(c *gin.Context) {
- appG := app.Gin{C: c}
- // 获取请求参数
- var req QueryHsbyVisitorMarketGoodsDetailReq
- if err := appG.C.ShouldBindQuery(&req); err != nil {
- logger.GetLogger().Errorf("QueryHsbyVisitorMarketGoodsDetail failed: %s", err.Error())
- appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
- return
- }
- // 获取数据
- detail, err := models.GetHsbyMarketGoodsDetailByVisitor(req.GoodsID)
- if err != nil {
- // 查询失败
- logger.GetLogger().Errorf("QueryHsbyVisitorMarketGoodsDetail failed: %s", err.Error())
- appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
- return
- }
- // 查询成功返回
- logger.GetLogger().Debugln("QueryHsbyVisitorMarketGoodsDetail successed: %v", detail)
- appG.Response(http.StatusOK, e.SUCCESS, detail)
- }
- // QueryHsbyMarketGoodsDetailReq 查询三级市场(商城)商品信息详情请求参数
- type QueryHsbyMarketGoodsDetailReq struct {
- OrderID int `form:"orderID" binding:"required"`
- AccountID int `form:"accountID"`
- }
- // QueryHsbyMarketGoodsDetail 查询三级市场(商城)商品信息详情
- // @Summary 查询三级市场(商城)商品信息详情
- // @Produce json
- // @Security ApiKeyAuth
- // @Param orderID query int true "委托单号"
- // @Param accountID query int false "资金账户,主要用于判断商品最大开仓手数;如未登录可不传。"
- // @Success 200 {object} models.HsbyMarketGoodsDetail
- // @Failure 500 {object} app.Response
- // @Router /HSBY/QueryHsbyMarketGoodsDetail [get]
- // @Tags 定制【海商报业】
- func QueryHsbyMarketGoodsDetail(c *gin.Context) {
- appG := app.Gin{C: c}
- // 获取请求参数
- var req QueryHsbyMarketGoodsDetailReq
- if err := appG.C.ShouldBindQuery(&req); err != nil {
- logger.GetLogger().Errorf("QueryHsbyMarketGoodsDetail failed: %s", err.Error())
- appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
- return
- }
- // 获取数据
- detail, err := models.GetHsbyMarketGoodsDetail(req.OrderID, req.AccountID)
- if err != nil {
- // 查询失败
- logger.GetLogger().Errorf("QueryHsbyMarketGoodsDetail failed: %s", err.Error())
- appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
- return
- }
- // 获取交易规则
- rule, err := models.GetTodayAccountTradeRule(int(detail.Accountid), int(detail.Goodsid))
- if err != nil {
- // 查询失败
- logger.GetLogger().Errorf("QueryHsbyListingGoodsDetail failed: %s", err.Error())
- appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
- return
- }
- if rule != nil {
- tradeRuleInfoStruct := &pb.TradeRuleInfoStruct{}
- if err := proto.Unmarshal([]byte(rule.Infocontent), tradeRuleInfoStruct); err != nil {
- // 查询失败
- logger.GetLogger().Errorf("QueryHsbyListingGoodsDetail failed: %s", err.Error())
- appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
- return
- }
- // INSERT INTO TRADERULEDESCRIPTION (RULEID, RULENAME, REGEXPRESS, DEFAULTVALUE, REMARK) VALUES (103, '单笔最小交易量', '^[1-9]\d*$', 1, '请输入正整数!');
- for _, v := range tradeRuleInfoStruct.TradeRules {
- if int(*v.RuleID) == 103 {
- detail.LotSize = int(*v.ParamValue)
- }
- // 商城的最大建仓手数与预售的不一样,直接从规则里取
- if int(*v.RuleID) == 104 {
- detail.Buymaxqty = int(*v.ParamValue)
- }
- }
- }
- // 查询成功返回
- logger.GetLogger().Debugln("QueryHsbyMarketGoodsDetail successed: %v", detail)
- appG.Response(http.StatusOK, e.SUCCESS, detail)
- }
- // QueryMyCouponsReq 我的优惠卷查询请求参数
- type QueryMyCouponsReq struct {
- AccountIDs string `form:"accountIDs" binding:"required"`
- GoodsID int `form:"goodsID"`
- SellUserID int `form:"sellUserID"`
- }
- // QueryMyCoupons 我的优惠卷查询
- // @Summary 我的优惠卷查询
- // @Produce json
- // @Security ApiKeyAuth
- // @Param accountIDs query string true "资金账户列表,格式:1,2,3"
- // @Param goodsID query int false "商品ID, 一般与sellUserID配套传入"
- // @Param sellUserID query int false "卖方UserID"
- // @Success 200 {object} models.MyCoupon
- // @Failure 500 {object} app.Response
- // @Router /HSBY/QueryMyCoupons [get]
- // @Tags 定制【海商报业】
- func QueryMyCoupons(c *gin.Context) {
- appG := app.Gin{C: c}
- // 获取请求参数
- var req QueryMyCouponsReq
- if err := appG.C.ShouldBindQuery(&req); err != nil {
- logger.GetLogger().Errorf("QueryMyCoupons failed: %s", err.Error())
- appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
- return
- }
- // 获取数据
- myCoupons, err := models.GetMyCoupons(req.AccountIDs, req.GoodsID, req.SellUserID)
- if err != nil {
- // 查询失败
- logger.GetLogger().Errorf("QueryMyCoupons failed: %s", err.Error())
- appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
- return
- }
- // 查询成功返回
- logger.GetLogger().Debugln("QueryMyCoupons successed: %v", myCoupons)
- appG.Response(http.StatusOK, e.SUCCESS, myCoupons)
- }
- // QueryMyCouponHoldsReq 我的优惠卷持仓查询请求参数
- type QueryMyCouponHoldsReq struct {
- AccountIDs string `form:"accountIDs" binding:"required"`
- HoldStatus string `form:"holdStatus"`
- }
- // QueryMyCouponHolds 我的优惠卷持仓查询
- // @Summary 我的优惠卷持仓查询
- // @Description 说明:当holdStatus传入4(已过期)后,会从历史表中查询已过期的优惠卷数据。
- // @Produce json
- // @Security ApiKeyAuth
- // @Param accountIDs query string true "资金账户列表,格式:1,2,3"
- // @Param holdStatus query string false "持仓状态 - 1:未生效 2:已生效 3:已使用 4:已过期,格式:1,2,3"
- // @Success 200 {object} models.MyCouponHold
- // @Failure 500 {object} app.Response
- // @Router /HSBY/QueryMyCouponHolds [get]
- // @Tags 定制【海商报业】
- func QueryMyCouponHolds(c *gin.Context) {
- appG := app.Gin{C: c}
- // 获取请求参数
- var req QueryMyCouponHoldsReq
- if err := appG.C.ShouldBindQuery(&req); err != nil {
- logger.GetLogger().Errorf("QueryMyCouponHolds failed: %s", err.Error())
- appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
- return
- }
- // 获取数据
- myCoupons, err := models.GetMyCouponHolds(req.AccountIDs, req.HoldStatus)
- if err != nil {
- // 查询失败
- logger.GetLogger().Errorf("QueryMyCouponHolds failed: %s", err.Error())
- appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
- return
- }
- // 查询成功返回
- logger.GetLogger().Debugln("QueryMyCouponHolds successed: %v", myCoupons)
- appG.Response(http.StatusOK, e.SUCCESS, myCoupons)
- }
- // QueryMyUsedCouponReq 已使用优惠卷查询请求参数
- type QueryMyUsedCouponReq struct {
- AccountIDs string `form:"accountIDs" binding:"required"`
- }
- // QueryMyUsedCoupon 已使用优惠卷查询
- // @Summary 已使用优惠卷查询
- // @Produce json
- // @Security ApiKeyAuth
- // @Param accountIDs query string true "资金账户列表,格式:1,2,3"
- // @Success 200 {object} models.MyUsedCoupon
- // @Failure 500 {object} app.Response
- // @Router /HSBY/QueryMyUsedCoupon [get]
- // @Tags 定制【海商报业】
- func QueryMyUsedCoupon(c *gin.Context) {
- appG := app.Gin{C: c}
- // 获取请求参数
- var req QueryMyUsedCouponReq
- if err := appG.C.ShouldBindQuery(&req); err != nil {
- logger.GetLogger().Errorf("QueryMyUsedCoupon failed: %s", err.Error())
- appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
- return
- }
- // 获取数据
- myCoupons, err := models.GetMyUsedCoupon(req.AccountIDs)
- if err != nil {
- // 查询失败
- logger.GetLogger().Errorf("QueryMyUsedCoupon failed: %s", err.Error())
- appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
- return
- }
- // 查询成功返回
- logger.GetLogger().Debugln("QueryMyUsedCoupon successed: %v", myCoupons)
- appG.Response(http.StatusOK, e.SUCCESS, myCoupons)
- }
- // QueryClientFixedADConfigs 获取终端固定广告配置
- // @Summary 获取终端固定广告配置
- // @Produce json
- // @Security ApiKeyAuth
- // @Success 200 {object} models.Clientfixedadconfig
- // @Failure 500 {object} app.Response
- // @Router /HSBY/QueryClientFixedADConfigs [get]
- // @Tags 定制【海商报业】
- func QueryClientFixedADConfigs(c *gin.Context) {
- appG := app.Gin{C: c}
- // 获取数据
- adConfigs, err := models.GetClientFixedADConfigs()
- if err != nil {
- // 查询失败
- logger.GetLogger().Errorf("QueryClientFixedADConfigs failed: %s", err.Error())
- appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
- return
- }
- // 查询成功返回
- logger.GetLogger().Debugln("QueryClientFixedADConfigs successed: %v", adConfigs)
- appG.Response(http.StatusOK, e.SUCCESS, adConfigs)
- }
|