|
|
@@ -2527,7 +2527,7 @@ func (r *WrDeliveryDetail) buildSql() string {
|
|
|
" left join useraccount u on ta.userid=u.userid" +
|
|
|
" left join taaccount ta2 on t.accountid=ta2.accountid" +
|
|
|
" left join useraccount u2 on ta2.userid=u2.userid" +
|
|
|
- "where 1=1"
|
|
|
+ " where 1=1"
|
|
|
sqlId.AndEx("u.userid", r.USERID, r.USERID > 0)
|
|
|
sqlId.AndEx("t.accountid", r.ACCOUNTID, r.ACCOUNTID > 0)
|
|
|
return sqlId.String()
|
|
|
@@ -2820,3 +2820,135 @@ func (r *WrQuoteOrderMyq) GetDataByPage() (interface{}, error, int, int, int) {
|
|
|
}
|
|
|
return sData, err, r.Page, r.PageSize, total
|
|
|
}
|
|
|
+
|
|
|
+// WrDeliveryAvalidHoldLB 合约交收可点选仓单
|
|
|
+type WrDeliveryAvalidHoldLB struct {
|
|
|
+ ACCOUNTID int64 `json:"accountid" xorm:"'ACCOUNTID'" form:"accountid"` // 资金账号
|
|
|
+ GOODSID int32 `json:"goodsid" xorm:"'GOODSID'" form:"goodsid"` // x合约商品id
|
|
|
+ WRSTANDARDID int32 `json:"wrstandardid" xorm:"'WRSTANDARDID'"` // 品类d
|
|
|
+ UQTY float64 `json:"-" xorm:"'UQTY'"` // 用户持有数量
|
|
|
+ QTY float64 `json:"-" xorm:"'QTY'"` // 用户仓单数量
|
|
|
+ WRFACTORTYPEID string `json:"wrfactortypeid" xorm:"'WRFACTORTYPEID'"` // 仓单要素id
|
|
|
+ LADINGBILLID string `json:"ladingbillid" xorm:"'LADINGBILLID'"` // 提单id
|
|
|
+ SUBNUM int64 `json:"subnum" xorm:"'SUBNUM'"` // 提单子id
|
|
|
+ DELIVERYGOODSID int32 `json:"deliverygoodsid" xorm:"'DELIVERYGOODSID'"` // 品种id
|
|
|
+ USERID int64 `json:"userid" xorm:"'USERID'"` // 用户id
|
|
|
+ WRFACTORTYPENAME2 string `json:"-" xorm:"'WRFACTORTYPENAME2'"` // 仓单要素名称(不含仓库)
|
|
|
+ WAREHOUSEID int32 `json:"warehouseid" xorm:"'WAREHOUSEID'"` // 仓库id
|
|
|
+ AVALIDQTY float64 `json:"avalidqty" xorm:"'AVALIDQTY'"` // 数量(可点选数量)
|
|
|
+ WRSTANDARDNAME string `json:"wrstandardname" xorm:"'WRSTANDARDNAME'"` // 品类名称
|
|
|
+ WRSTANDARDCODE string `json:"wrstandardcode" xorm:"'WRSTANDARDCODE'"` // 品代码
|
|
|
+ WAREHOUSECODE string `json:"warehousecode" xorm:"'WAREHOUSECODE'"` // 仓库代码
|
|
|
+ WAREHOUSENAME string `json:"warehousename" xorm:"'WAREHOUSENAME'"` // 仓库名称
|
|
|
+ XGOODSCODE string `json:"xgoodscode" xorm:"'XGOODSCODE'"` // x合约代码
|
|
|
+ XGOODSNAME string `json:"xgoodsname" xorm:"'XGOODSNAME'"` // x合约名称
|
|
|
+ PGOODSID int32 `json:"pgoodsid" xorm:"'PGOODSID'"` // p商品id(点价合约)
|
|
|
+ PGOODSCODE string `json:"pgoodscode" xorm:"'PGOODSCODE'"` // p商品代码(点价合约)
|
|
|
+ PGOODSNAME string `json:"pgoodsname" xorm:"'PGOODSNAME'"` // p商品名称(点价合约)
|
|
|
+ USERNAME string `json:"username" xorm:"'USERNAME'"` // 仓单持有人
|
|
|
+ PRICEMOVE float64 `json:"pricemove" xorm:"'PRICEMOVE'"` // 升贴水
|
|
|
+ WRTYPENAME string `json:"wrtypename"` // 商品
|
|
|
+}
|
|
|
+
|
|
|
+func (r *WrDeliveryAvalidHoldLB) calc() {
|
|
|
+ r.USERNAME = EncryptByStar(r.USERNAME)
|
|
|
+ if r.WRTYPENAME == "" {
|
|
|
+ if len(r.WRFACTORTYPENAME2) > 0 {
|
|
|
+ r.WRTYPENAME = r.WRSTANDARDNAME + r.WRFACTORTYPENAME2
|
|
|
+ } else {
|
|
|
+ r.WRTYPENAME = r.WRSTANDARDNAME
|
|
|
+ }
|
|
|
+ }
|
|
|
+ r.WRTYPENAME = strings.ReplaceAll(r.WRTYPENAME, ",", "-")
|
|
|
+}
|
|
|
+
|
|
|
+func (r *WrDeliveryAvalidHoldLB) buildSql() string {
|
|
|
+ var sqlId utils.SQLVal = "with tmp as(" +
|
|
|
+ "select k.wrfactortypeid, k.goodsid, sum(k.pricemove) pricemove" +
|
|
|
+ " from (select to_char(t.wrfactortypeid) wrfactortypeid," +
|
|
|
+ " b.dgfactoryitemtypeid," +
|
|
|
+ " b.itemtypename," +
|
|
|
+ " c.dgfactoryitemvalue," +
|
|
|
+ " t.optioncompare," +
|
|
|
+ " t.warehouseid," +
|
|
|
+ " t.wrstandardid," +
|
|
|
+ " c.dgfactoryitemid," +
|
|
|
+ " t.wrfactortypename," +
|
|
|
+ " t.wrfactortypename2," +
|
|
|
+ " r.goodsid," +
|
|
|
+ " nvl(r.premiumvalue, 0) pricemove" +
|
|
|
+ " from wrfactortype t" +
|
|
|
+ " inner join wrfactortypeitem a" +
|
|
|
+ " on t.wrfactortypeid = a.wrfactortypeid" +
|
|
|
+ " inner join dgfactoryitemtype b" +
|
|
|
+ " on t.deliverygoodsid = b.deliverygoodsid" +
|
|
|
+ " and a.dgfactoryitemtypeid = b.dgfactoryitemtypeid" +
|
|
|
+ " left join dgfactoryitem c" +
|
|
|
+ " on a.dgfactoryitemid = c.dgfactoryitemid" +
|
|
|
+ " and b.deliverygoodsid = c.deliverygoodsid" +
|
|
|
+ " left join deliveryrelationdetail r" +
|
|
|
+ " on c.dgfactoryitemid = r.dgfactoryitemid" +
|
|
|
+ " and b.dgfactoryitemtypeid = r.dgfactoryitemtypeid" +
|
|
|
+ " where 1 = 1) k" +
|
|
|
+ " group by k.wrfactortypeid, k.goodsid" +
|
|
|
+ " )" +
|
|
|
+ "select a.*," +
|
|
|
+ " case" +
|
|
|
+ " when a.uqty < a.qty then" +
|
|
|
+ " a.uqty" +
|
|
|
+ " else" +
|
|
|
+ " a.qty" +
|
|
|
+ " end as avalidqty," +
|
|
|
+ " wd.wrstandardname," +
|
|
|
+ " wd.wrstandardcode," +
|
|
|
+ " h.warehousecode," +
|
|
|
+ " h.warehousename," +
|
|
|
+ " g1.goodscode xgoodscode," +
|
|
|
+ " g1.goodsname xgoodsname," +
|
|
|
+ " r.pgoodsid," +
|
|
|
+ " g2.goodscode pgoodscode," +
|
|
|
+ " g2.goodsname pgoodsname," +
|
|
|
+ " u.accountname username," +
|
|
|
+ " tmp.pricemove" +
|
|
|
+ " from (select t.accountid," +
|
|
|
+ " t.goodsid," +
|
|
|
+ " t.wrstandardid," +
|
|
|
+ " t.inqty - t.cancelqty - t.deliveryqty - t.curpresaleqty as uqty," +
|
|
|
+ " hl.qty - hl.freezerqty qty," +
|
|
|
+ " to_char(hl.wrfactortypeid) wrfactortypeid," +
|
|
|
+ " to_char(hl.ladingbillid) ladingbillid," +
|
|
|
+ " hl.subnum," +
|
|
|
+ " hl.deliverygoodsid," +
|
|
|
+ " hl.userid," +
|
|
|
+ " w.wrfactortypename2," +
|
|
|
+ " w.warehouseid" +
|
|
|
+ " from cptrade_usergoodsdata t" +
|
|
|
+ " inner join wrholdlb hl" +
|
|
|
+ " on t.accountid = hl.accountid" +
|
|
|
+ " inner join wrfactortype w" +
|
|
|
+ " on t.wrstandardid = w.wrstandardid and hl.wrfactortypeid=w.wrfactortypeid) a" +
|
|
|
+ " left join wrstandard wd" +
|
|
|
+ " on a.wrstandardid = wd.wrstandardid" +
|
|
|
+ " left join warehouseinfo h" +
|
|
|
+ " on a.warehouseid = h.autoid" +
|
|
|
+ " inner join deliveryrelation r on a.goodsid=r.goodsid and a.wrstandardid=r.wrstandardid" +
|
|
|
+ " left join goods g1 on a.goodsid=g1.goodsid" +
|
|
|
+ " left join goods g2 on r.pgoodsid=g2.goodsid" +
|
|
|
+ " left join useraccount u on a.userid=u.userid" +
|
|
|
+ " left join tmp on a.wrfactortypeid=tmp.wrfactortypeid and a.goodsid=tmp.goodsid" +
|
|
|
+ " where a.uqty > 0" +
|
|
|
+ " and a.qty > 0"
|
|
|
+ sqlId.And("a.accountid", r.ACCOUNTID)
|
|
|
+ sqlId.And("a.goodsid", r.GOODSID)
|
|
|
+ return sqlId.String()
|
|
|
+}
|
|
|
+
|
|
|
+// GetDataEx 获取合约交收可点选仓单
|
|
|
+func (r *WrDeliveryAvalidHoldLB) GetDataEx() (interface{}, error) {
|
|
|
+ sData := make([]WrDeliveryAvalidHoldLB, 0)
|
|
|
+ err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
|
|
|
+ for i := range sData {
|
|
|
+ sData[i].calc()
|
|
|
+ }
|
|
|
+ return sData, err
|
|
|
+}
|