package szdz import ( "fmt" "mtp2_if/db" "mtp2_if/global/app" "mtp2_if/global/e" "mtp2_if/logger" "mtp2_if/models" "net/http" "github.com/gin-gonic/gin" ) // QueryRecieptOrderReq 点选挂牌委托单据查询参数 type QueryRecieptOrderReq struct { GoodsID int `form:"goodsID" binding:"required"` // 商品ID,必填 AccountName string `form:"accountName"` // 所属账户名称 MarketID int `form:"marketID"` // 市场ID } // QueryRecieptOrderRsp 点选挂牌委托单据查询返回模型 type QueryRecieptOrderRsp struct { Goodsid int64 `json:"goodsid" xorm:"'GOODSID'"` // 商品ID Goodscode string `json:"goodscode" xorm:"'GOODSCODE'"` // 商品代码 Goodsname string `json:"goodsname" xorm:"'GOODSNAME'"` // 商品名称 Buyorsell int64 `json:"buyorsell" xorm:"'BUYORSELL'"` // 方向 - 0:买 1:卖 Orderid int64 `json:"orderid" xorm:"'ORDERID'"` // 委托单号 Tradedate string `json:"tradedate" xorm:"'TRADEDATE'"` // 交易日(yyyyMMdd) Orderprice float64 `json:"orderprice" xorm:"'ORDERPRICE'"` // 委托价格 EnableQty int64 `json:"enableqty" xorm:"ENABLEQTY"` // 可摘数量 AccountName string `json:"accountName" xorm:"ACCOUNTNAME"` // 所属账号名称(已脱敏) } // QueryRecieptOrder 点选挂牌委托单据查询(摘牌大厅) // @Summary 点选挂牌委托单据查询(摘牌大厅) // @Produce json // @Security ApiKeyAuth // @Param goodsID query int true "商品ID" // @Param accountName query string false "所属账户名称" // @Param marketID query int false "市场ID" // @Success 200 {object} QueryRecieptOrderRsp // @Failure 500 {object} app.Response // @Router /SZDZ/QueryRecieptOrder [get] // @Tags 尚志大宗 func QueryRecieptOrder(c *gin.Context) { appG := app.Gin{C: c} // 获取请求参数 var req QueryRecieptOrderReq if err := appG.C.ShouldBindQuery(&req); err != nil { logger.GetLogger().Errorf("QueryRecieptOrder failed: %s", err.Error()) appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil) return } datas := make([]QueryRecieptOrderRsp, 0) engine := db.GetEngine() // 投资者挂牌委托单 s := engine.Table("TRADE_ORDERDETAIL"). Join("INNER", "GOODS", "TRADE_ORDERDETAIL.GOODSID = GOODS.GOODSID"). Join("LEFT", "TAACCOUNT", "TAACCOUNT.ACCOUNTID = TRADE_ORDERDETAIL.ACCOUNTID"). Join("LEFT", "USERACCOUNT", "USERACCOUNT.USERID = TAACCOUNT.RELATEDUSERID"). Select(`GOODS.GOODSID, GOODS.GOODSCODE, GOODS.GOODSNAME, TRADE_ORDERDETAIL.BUYORSELL, TRADE_ORDERDETAIL.ORDERID, TRADE_ORDERDETAIL.TRADEDATE, TRADE_ORDERDETAIL.ORDERPRICE, TRADE_ORDERDETAIL.ORDERQTY - TRADE_ORDERDETAIL.TRADEQTY - TRADE_ORDERDETAIL.CANCELQTY as ENABLEQTY, substr(USERACCOUNT.ACCOUNTNAME,0,1)||'****' as ACCOUNTNAME`). Where("TRADE_ORDERDETAIL.ORDERSTATUS in (3,7,12) and GOODS.GOODSID = ?", req.GoodsID) if len(req.AccountName) > 0 { s = s.And("USERACCOUNT.ACCOUNTNAME = ?", req.AccountName) } if req.MarketID > 0 { s = s.And("TRADE_ORDERDETAIL.MARKETID = ?", req.MarketID) } d1 := make([]QueryRecieptOrderRsp, 0) if err := s.Find(&d1); err != nil { // 查询失败 logger.GetLogger().Errorf("QueryRecieptOrder failed: %s", err.Error()) appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil) return } datas = append(datas, d1...) // 报价商挂牌委托 s = engine.Table("TRADE_QUOTEDETAILNEW"). Join("INNER", "GOODS", "TRADE_QUOTEDETAILNEW.GOODSID = GOODS.GOODSID"). Join("INNER", "QUOTER", "QUOTER.QUOTERID = TRADE_QUOTEDETAILNEW.QUOTERID"). Join("INNER", "AREAROLE", "AREAROLE.USERID = QUOTER.DEFAULTMAKERID and AREAROLE.ROLETYPE = 8"). Select(`GOODS.GOODSID, GOODS.GOODSCODE, GOODS.GOODSNAME, TRADE_QUOTEDETAILNEW.BUYORSELL, TRADE_QUOTEDETAILNEW.ORDERID, TRADE_QUOTEDETAILNEW.TRADEDATE, TRADE_QUOTEDETAILNEW.PRICE as ORDERPRICE, TRADE_QUOTEDETAILNEW.CURQTY as ENABLEQTY, substr(QUOTER.QUOTERNAME,0,1)||'****' as ACCOUNTNAME`). Where("(TRADE_QUOTEDETAILNEW.CURQTY > 0 or TRADE_QUOTEDETAILNEW.PRICE > 0) and TRADE_QUOTEDETAILNEW.ISVALID != 1 and TRADE_QUOTEDETAILNEW.FREEZESTATUS != 3") d2 := make([]QueryRecieptOrderRsp, 0) if err := s.Find(&d2); err != nil { // 查询失败 logger.GetLogger().Errorf("QueryRecieptOrder failed: %s", err.Error()) appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil) return } datas = append(datas, d2...) // FIXME: - 排序 & 分页 // 查询成功返回 logger.GetLogger().Infof("QueryRecieptOrder successed: %v", datas) appG.Response(http.StatusOK, e.SUCCESS, datas) } // QueryGoodsPickupReq 商品提货单查询请求参数 type QueryGoodsPickupReq struct { AccountID string `form:"accountID" binding:"required"` TakeOrderStatus int `form:"takeOrderStatus"` } // QueryGoodsPickup 商品提货单查询 // @Summary 商品提货单查询 // @Produce json // @Security ApiKeyAuth // @Param accountID query string true "资金账户 - 格式:1,2,3" // @Param takeOrderStatus query int false "提货状态 - 1:待发货 2:已发货 3:已收货" // @Success 200 {object} models.Szdz3goodspickup // @Failure 500 {object} app.Response // @Router /SZDZ/QueryGoodsPickup [get] // @Tags 尚志大宗 func QueryGoodsPickup(c *gin.Context) { appG := app.Gin{C: c} // 获取请求参数 var req QueryGoodsPickupReq if err := appG.C.ShouldBindQuery(&req); err != nil { logger.GetLogger().Errorf("QueryGoodsPickup failed: %s", err.Error()) appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil) return } datas := make([]models.Szdz3goodspickup, 0) engine := db.GetEngine() s := engine.Where(fmt.Sprintf(`ACCOUNTID in (%s)`, req.AccountID)) if req.TakeOrderStatus > 0 { s = s.And("TAKEORDERSTATUS = ?", req.TakeOrderStatus) } if err := s.Find(&datas); err != nil { // 查询失败 logger.GetLogger().Errorf("QueryGoodsPickup failed: %s", err.Error()) appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil) return } // 查询成功返回 logger.GetLogger().Infof("QueryGoodsPickup successed: %v", datas) appG.Response(http.StatusOK, e.SUCCESS, datas) }