| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928 |
- 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 查询二级市场(挂牌点选)商品信息详情
- // @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)
- 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
- }
- 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)
- break
- }
- }
- // 查询成功返回
- 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" binding:"required"`
- 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 true "摘牌方资金账户列表,格式: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 说明: 全部:一二级市场买委托;抢购中:一级市场买摘; 求购中:二级市场买挂; 3:已完成:一二级市场已完成买委托;
- // @Produce json
- // @Security ApiKeyAuth
- // @Param accountIDs query string true "资金账户列表,格式:1,2,3"
- // @Param myBuyStatus query int false "'我的订单'状态, 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 查询“我的商品”信息
- // @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" binding:"required"`
- }
- // QueryHsbyPreGoodsDetail 查询一级市场(产能预售)商品信息详情
- // @Summary 查询一级市场(产能预售)商品信息详情
- // @Produce json
- // @Security ApiKeyAuth
- // @Param goodsID query int true "商品ID"
- // @Param accountID query int true "资金账户,主要用于获取预售商品购买上限"
- // @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"` // 我的包裹待收货数量
- }
- // 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
- }
- // 统计数量
- 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++
- }
- }
- // 查询成功返回
- logger.GetLogger().Debugln("GetHsbyMyCount successed: %v", rsp)
- appG.Response(http.StatusOK, e.SUCCESS, rsp)
- }
- // QueryTradePayOrdersReq 待付款信息查询请求参数
- type QueryTradePayOrdersReq struct {
- app.PageInfo
- AccountIDs string `form:"accountIDs" binding:"required"`
- }
- // QueryTradePayOrders 获取待付款信息
- // @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 "买方委托单号"
- // @Success 200 {object} models.HsbyBuyMyPayOrder
- // @Failure 500 {object} app.Response
- // @Router /HSBY/QueryTradePayOrders [get]
- // @Tags 定制【海商报业】
- func QueryTradePayOrders(c *gin.Context) {
- appG := app.Gin{C: c}
- // 获取请求参数
- var req QueryTradePayOrdersReq
- if err := appG.C.ShouldBindQuery(&req); err != nil {
- logger.GetLogger().Errorf("QueryTradePayOrders failed: %s", err.Error())
- appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
- return
- }
- // 获取数据
- orders, err := models.GetHsbyBuyMyPayOrders(req.AccountIDs)
- if err != nil {
- // 查询失败
- logger.GetLogger().Errorf("QueryTradePayOrders 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.Before(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("QueryTradePayOrders successed: %v", orders)
- appG.ResponseByPage(http.StatusOK, e.SUCCESS, orders, app.PageInfo{Page: req.Page, PageSize: req.PageSize, Total: total})
- } else {
- logger.GetLogger().Debugln("QueryTradePayOrders successed: %v", orders)
- appG.Response(http.StatusOK, e.SUCCESS, orders)
- }
- }
|