|
|
@@ -7,6 +7,7 @@ import (
|
|
|
"mtp2_if/logger"
|
|
|
"mtp2_if/utils"
|
|
|
"strconv"
|
|
|
+ "strings"
|
|
|
"sync"
|
|
|
"time"
|
|
|
)
|
|
|
@@ -427,3 +428,172 @@ func (r *RegisterMoney) GetDataEx() (interface{}, error) {
|
|
|
}
|
|
|
return sData, nil
|
|
|
}
|
|
|
+
|
|
|
+// THJWrstandardDetail_GoodsInfo 采购商品信息
|
|
|
+type THJWrstandardDetail_GoodsInfo struct {
|
|
|
+ WRSTANDARDID int64 `json:"wrstandardid" xorm:"WRSTANDARDID"` // 现货商品ID(自增 SEQ_GOODS 确保不重复)
|
|
|
+ WRSTANDARDCODE string `json:"wrstandardcode" xorm:"WRSTANDARDCODE"` // 现货商品代码
|
|
|
+ WRSTANDARDNAME string `json:"wrstandardname" xorm:"WRSTANDARDNAME"` // 现货商品名称
|
|
|
+ DELIVERYGOODSID int32 `json:"-" xorm:"DELIVERYGOODSID"` // 现货品种ID
|
|
|
+ UNITID int32 `json:"-" xorm:"UNITID"` // 现货商品单位ID
|
|
|
+ MINIVALUE int64 `json:"-" xorm:"MINIVALUE"` // 最小变动值
|
|
|
+ MINIVALUEDP int64 `json:"-" xorm:"MINIVALUEDP"` // 最小变动值小数位
|
|
|
+ REALMINIVALUE int64 `json:"-" xorm:"REALMINIVALUE"` // 实际最小变动值
|
|
|
+ REALMINIVALUEDP int64 `json:"-" xorm:"REALMINIVALUEDP"` // 实际最小变动值小数位
|
|
|
+ WRSSTATUS int32 `json:"-" xorm:"WRSSTATUS"` // 状态 - 作废 - 0:未激活 1:正常
|
|
|
+ CREATORID int64 `json:"-" xorm:"CREATORID"` // 创建人
|
|
|
+ CREATETIME time.Time `json:"-" xorm:"CREATETIME"` // 创建时间
|
|
|
+ UPDATORID int64 `json:"-" xorm:"UPDATORID"` // 更新人
|
|
|
+ UPDATETIME time.Time `json:"-" xorm:"UPDATETIME"` // 更新时间
|
|
|
+ FACTORYITEMJSON string `json:"-" xorm:"FACTORYITEMJSON"` // 要素项定义Json[{"DGFactoryItemTypeID": ,"ItemTypeMode": ,"FactoryItemIDs": },{.....},]DGFactoryItemTypeID - 要素项类型ID --DGFactoryItem->DGFactoryItemTypeIDItemTypeMode - 要素项类型模式 --DGFactoryItem->ItemTypeModeFactoryItemIDs - 选择项IDs--DGFactoryItem->DGFactoryItemID, 逗号分隔
|
|
|
+ ISVALID int32 `json:"-" xorm:"ISVALID"` // 是否有效 - 0:无效 1:有效
|
|
|
+ AREAUSERID int64 `json:"-" xorm:"AREAUSERID"` // 所属机构
|
|
|
+ REMARK string `json:"-" xorm:"REMARK"` // 备注
|
|
|
+ CONVERTFACTOR float64 `json:"-" xorm:"CONVERTFACTOR"` // 标仓系数
|
|
|
+ VATRATE float64 `json:"-" xorm:"VATRATE"` // 现货增值税率
|
|
|
+ STORAGEFEE float64 `json:"-" xorm:"STORAGEFEE"` // 仓储费(固定: 111)
|
|
|
+ THUMURLS string `json:"-" xorm:"THUMURLS"` // 缩略图片(1:1)(逗号分隔)
|
|
|
+ PICTUREURLS string `json:"pictureurls" xorm:"PICTUREURLS"` // 详情图片(逗号分隔)
|
|
|
+ BANNERPICURL string `json:"-" xorm:"BANNERPICURL"` // Banner图(逗号分隔)
|
|
|
+ PROVIDERUSERID int64 `json:"-" xorm:"PROVIDERUSERID"` // 供应链提供商
|
|
|
+ PROVIDERACCOUNTID int64 `json:"-" xorm:"PROVIDERACCOUNTID"` // 供应链提供商资金账户 ID
|
|
|
+
|
|
|
+ SPOTGOODSPRICE float64 `json:"spotgoodsprice" xorm:"SPOTGOODSPRICE"` // 现货价格
|
|
|
+}
|
|
|
+
|
|
|
+// THJDeliveryMode 交割方式
|
|
|
+type THJDeliveryMode struct {
|
|
|
+ ENUMDICNAME string `json:"enumdicname" xorm:"ENUMDICNAME"` // 枚举项名称
|
|
|
+ ENUMITEMNAME int64 `json:"enumitemname" xorm:"ENUMITEMNAME"` // 枚举项值
|
|
|
+}
|
|
|
+
|
|
|
+// THJDeliveryMonth 交割月份
|
|
|
+type THJDeliveryMonth struct {
|
|
|
+ PRESALEAPPLYID int64 `json:"presaleapplyid" xorm:"PRESALEAPPLYID"` // 预售申请ID(184+Unix秒时间戳(10位)+xxxxxx)
|
|
|
+ ENDMONTH string `json:"endmonth" xorm:"ENDMONTH"` // 预售结束月份(yyyy-mm)
|
|
|
+ ENDDATE string `json:"enddate" xorm:"ENDDATE"` // 预售结束日期(yyyy-mm-dd)
|
|
|
+ ORDERQTY int64 `json:"orderqty" xorm:"ORDERQTY"` // 委托数量
|
|
|
+ TRADEQTY int64 `json:"tradeqty" xorm:"TRADEQTY"` // 成交数量
|
|
|
+ REMAINQTY int64 `json:"remainqty" xorm:"REMAINQTY"` // 可用数量
|
|
|
+}
|
|
|
+
|
|
|
+// THJPresaleApplyDeposit 支付方式
|
|
|
+type THJPresaleApplyDeposit struct {
|
|
|
+ DEPOSITRATE float64 `json:"depositrate" xorm:"DEPOSITRATE"` // 定金比例
|
|
|
+ DISCOUNTAMOUNT float64 `json:"discountamount" xorm:"DISCOUNTAMOUNT"` // 优惠金额(每吨)
|
|
|
+}
|
|
|
+
|
|
|
+// THJSpotGoodsPriceLog 历史价格走势
|
|
|
+type THJSpotGoodsPriceLog struct {
|
|
|
+ SPOTGOODSPRICE float64 `json:"spotgoodsprice" xorm:"SPOTGOODSPRICE"` // 现货价格
|
|
|
+ TRADEDATE string `json:"tradedate" xorm:"TRADEDATE"` // 交易日(yyyyMMdd)
|
|
|
+}
|
|
|
+
|
|
|
+type THJWrstandardDetailReq struct {
|
|
|
+ WRSTANDARDID int64 `form:"wrstandardid" binding:"required"` // 现货商品ID
|
|
|
+}
|
|
|
+
|
|
|
+// THJWrstandardDetailRsp 采购商品详情
|
|
|
+type THJWrstandardDetailRsp struct {
|
|
|
+ GoodsInfo THJWrstandardDetail_GoodsInfo // 商品信息
|
|
|
+ DeliveryModes []THJDeliveryMode // 交割方式
|
|
|
+ DeliveryMonth []THJDeliveryMonth // 交割月份
|
|
|
+ PresaleApplyDeposits []THJPresaleApplyDeposit // 支付方式
|
|
|
+ SpotGoodsPriceLogs []THJSpotGoodsPriceLog // 历史价格走势
|
|
|
+}
|
|
|
+
|
|
|
+// GetTHJWrstandardDetail 获取采购商品详情
|
|
|
+func (r *THJWrstandardDetailReq) GetTHJWrstandardDetail() (rsp *THJWrstandardDetailRsp, err error) {
|
|
|
+ engine := db.GetEngine()
|
|
|
+
|
|
|
+ // 采购商品信息
|
|
|
+ goodsInfo := new(THJWrstandardDetail_GoodsInfo)
|
|
|
+ sql := fmt.Sprintf(`
|
|
|
+ select
|
|
|
+ t.WRSTANDARDID,
|
|
|
+ t.WRSTANDARDCODE,
|
|
|
+ t.WRSTANDARDNAME,
|
|
|
+ t.PICTUREURLS,
|
|
|
+ p.SPOTGOODSPRICE
|
|
|
+ from wrstandard t
|
|
|
+ left join ERMCP_SpotGoodsPrice p on t.WRSTANDARDID = p.WRSTANDARDID and p.spotgoodsbrandid=0 and p.currencyid = 1
|
|
|
+ where t.WRSTANDARDID = %v
|
|
|
+ `, r.WRSTANDARDID)
|
|
|
+ if _, err = engine.SQL(sql).Get(goodsInfo); err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ rsp.GoodsInfo = *goodsInfo
|
|
|
+
|
|
|
+ // 交割方式
|
|
|
+ deliveryModes := make([]THJDeliveryMode, 0)
|
|
|
+ sql = `
|
|
|
+ select
|
|
|
+ t.ENUMDICNAME,
|
|
|
+ t.ENUMITEMNAME
|
|
|
+ from enumdicitem t
|
|
|
+ where t.enumdiccode = 'THJDeliveryMode';
|
|
|
+ `
|
|
|
+ if err = engine.SQL(sql).Find(&deliveryModes); err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ rsp.DeliveryModes = deliveryModes
|
|
|
+
|
|
|
+ // 交割月份
|
|
|
+ deliveryMonths := make([]THJDeliveryMonth, 0)
|
|
|
+ sql = fmt.Sprintf(`
|
|
|
+ select
|
|
|
+ t.PRESALEAPPLYID,
|
|
|
+ to_char(t.ENDDATE, 'yyyy-mm') ENDMONTH,
|
|
|
+ to_char(t.ENDDATE, 'yyyy-mm-dd') ENDDATE,
|
|
|
+ t.ORDERQTY,
|
|
|
+ t.TRADEQTY,
|
|
|
+ (od.orderqty - od.tradeqty) REMAINQTY
|
|
|
+ from WR_PresaleInfo t
|
|
|
+ inner join wrtrade_orderdetail od on t.sellwrtradeorderid = od.wrtradeorderid
|
|
|
+ where t.wrstandardid = %v
|
|
|
+ and t.presalestatus = 2
|
|
|
+ and od.wrtradeorderstatus in (3, 7)
|
|
|
+ and (od.orderqty - od.tradeqty) > 0
|
|
|
+ `, r.WRSTANDARDID)
|
|
|
+ if err = engine.SQL(sql).Find(&deliveryMonths); err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ rsp.DeliveryMonth = deliveryMonths
|
|
|
+
|
|
|
+ // 支付方式
|
|
|
+ ids := make([]string, 0)
|
|
|
+ for _, item := range deliveryMonths {
|
|
|
+ ids = append(ids, strconv.Itoa(int(item.PRESALEAPPLYID)))
|
|
|
+ }
|
|
|
+ if len(ids) > 0 {
|
|
|
+ presaleApplyDeposits := make([]THJPresaleApplyDeposit, 0)
|
|
|
+ sql = fmt.Sprintf(`
|
|
|
+ select
|
|
|
+ t.DEPOSITRATE,
|
|
|
+ t.DISCOUNTAMOUNT
|
|
|
+ from THJ_PresaleApplyDeposit t
|
|
|
+ where t.presaleapplyid in (%v)
|
|
|
+ `, strings.Join(ids, ","))
|
|
|
+ if err = engine.SQL(sql).Find(&presaleApplyDeposits); err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ rsp.PresaleApplyDeposits = presaleApplyDeposits
|
|
|
+ }
|
|
|
+
|
|
|
+ // 历史价格走势
|
|
|
+ spotGoodsPriceLogs := make([]THJSpotGoodsPriceLog, 0)
|
|
|
+ sql = fmt.Sprintf(`
|
|
|
+ select
|
|
|
+ t.SPOTGOODSPRICE,
|
|
|
+ t.TRADEDATE
|
|
|
+ from ERMCP_SpotGoodsPriceLog t
|
|
|
+ where t.wrstandardid = %v
|
|
|
+ order by t.operatetime
|
|
|
+ `, r.WRSTANDARDID)
|
|
|
+ if err = engine.SQL(sql).Find(&spotGoodsPriceLogs); err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ rsp.SpotGoodsPriceLogs = spotGoodsPriceLogs
|
|
|
+
|
|
|
+ return
|
|
|
+}
|