/** * @Author: zou.yingbin * @Create : 2021/4/14 11:11 * @Modify : 2021/4/14 11:11 */ package models import ( "fmt" "mtp2_if/db" "mtp2_if/mtpcache" "mtp2_if/utils" ) // ErmcpDeliveryGoods 现货品种(交割品种) type ErmcpDeliveryGoods struct { DELIVERYGOODSID int32 `json:"deliverygoodsid" xorm:"'DELIVERYGOODSID'"` // 现货品种ID(SEQ_DELIVERYGOODS) DELIVERYGOODSCODE string `json:"deliverygoodscode" xorm:"'DELIVERYGOODSCODE'"` // 现货品种代码 DELIVERYGOODSNAME string `json:"deliverygoodsname" xorm:"'DELIVERYGOODSNAME'"` // 现货品种名称 GOODSUNITID int32 `json:"goodsunitid" xorm:"'GOODSUNITID'"` // 现货品种单位ID DELIVERYGOODSTYPE int32 `json:"deliverygoodstype" xorm:"'DELIVERYGOODSTYPE'"` // 现货品种类型: 1-整装不拆分 2-散装记录明细 3:整装拆分 4:散装不记录明细 STANDARDQTY int32 `json:"standardqty" xorm:"'STANDARDQTY'"` // 标准数量(库位数量) [标准品特有] STANDARDQTYRANGE int32 `json:"standardqtyrange" xorm:"'STANDARDQTYRANGE'"` // 标准数量偏差范围 [标准品特有] AUDITFLAG int32 `json:"auditflag" xorm:"'AUDITFLAG'"` // 交割是否需要审核 - 0:不需要 1:需要审核 默认为0 ISVALID int32 `json:"isvalid" xorm:"'ISVALID'"` // 是否有效 - 0:无效 1:有效 AGREEUNIT int32 `json:"agreeunit" xorm:"'AGREEUNIT'"` // 合约单位[散货时默认为1, 整装时默认为标准数量] QTYDECIMALPLACE int32 `json:"qtydecimalplace" xorm:"'QTYDECIMALPLACE'"` // 成交量小数位 CATEGORYID int32 `json:"categoryid" xorm:"'CATEGORYID'"` // 类别ID(SEQ_WRCATEGORY) DGSTATUS int32 `json:"dgstatus" xorm:"'DGSTATUS'"` // 品种状态 - 作废 - 0:未激活 1:正常 AREAUSERID int64 `json:"areauserid" xorm:"'AREAUSERID'"` // 所属机构 EnumdicName string `json:"enumdicname"` // 现货品种单位名称 ExcludeCfg int32 `json:"-"` // 排除已配置项 1-排除 } func (r *ErmcpDeliveryGoods) calc() { r.EnumdicName = mtpcache.GetEnumDicitemName(r.GOODSUNITID) } func (r *ErmcpDeliveryGoods) buildSql() string { var sqlId utils.SQLVal = "SELECT t.DELIVERYGOODSID," + " t.DELIVERYGOODSCODE," + " t.DELIVERYGOODSNAME," + " t.GOODSUNITID," + " t.DELIVERYGOODSTYPE," + " t.STANDARDQTY," + " t.STANDARDQTYRANGE," + " t.AUDITFLAG," + " t.ISVALID," + " t.ISSPLIT," + " t.AGREEUNIT," + " t.QTYDECIMALPLACE," + " t.CATEGORYID," + " t.DGSTATUS," + " t.AREAUSERID" + " FROM DELIVERYGOODS t" + " WHERE 1 = 1" sqlId.AndEx("t.AREAUSERID", r.AREAUSERID, r.AREAUSERID > 0) sqlId.AndEx("t.DELIVERYGOODSID", r.DELIVERYGOODSID, r.DELIVERYGOODSID > 0) if r.ExcludeCfg == 1 { sqlId.Join(" and t.deliverygoodsid not in(select distinct deliverygoodsid from ermcp_bizgroupspotgoods)") } return sqlId.String() } // GetDataEx 获取现货商品(交割商品) func (r *ErmcpDeliveryGoods) GetDataEx() (interface{}, error) { return r.GetData() } // GetData func (r *ErmcpDeliveryGoods) GetData() ([]ErmcpDeliveryGoods, error) { sData := make([]ErmcpDeliveryGoods, 0) err := db.GetEngine().SQL(r.buildSql()).Find(&sData) for i := range sData { sData[i].calc() } return sData, err } // ErmcpDGFactoryItem 品种选择项定义表 type ErmcpDGFactoryItem struct { DGFACTORYITEMID int64 // 选择项ID(SEQ_DGFACTORYITEM) DELIVERYGOODSID int32 // 品种ID DGFACTORYITEMTYPEID int64 // 要素项类型 DGFACTORYITEMVALUE string // 要素项值(类型为仓库时填写仓库名称) WAREHOUSEID int64 // 仓库ID(类型为仓库时填写) ISVALID int32 // 是否有效 - 0:无效 1:有效 ORDERINDEX int32 // 顺序 } func (r *ErmcpDGFactoryItem) buildSql() string { var sqlId utils.SQLVal = "SELECT DGFACTORYITEMID," + " t.DELIVERYGOODSID," + " to_char(t.DGFACTORYITEMTYPEID) DGFACTORYITEMTYPEID," + " t.DGFACTORYITEMVALUE," + " to_char(t.WAREHOUSEID) WAREHOUSEID," + " t.ISVALID," + " t.ORDERINDEX" + " FROM DGFACTORYITEM t" + " WHERE ISVALID = 1" sqlId.AndEx("t.DGFACTORYITEMID", r.DGFACTORYITEMID, r.DGFACTORYITEMID > 0) sqlId.AndEx("t.DELIVERYGOODSID", r.DELIVERYGOODSID, r.DELIVERYGOODSID > 0) sqlId.AndEx("t.DGFACTORYITEMTYPEID", r.DGFACTORYITEMTYPEID, r.DGFACTORYITEMTYPEID > 0) sqlId.AndEx("t.ORDERINDEX", r.ORDERINDEX, r.ORDERINDEX > 0) return sqlId.String() } // GetDataEx 获取品种选择项定义 func (r *ErmcpDGFactoryItem) GetDataEx() (interface{}, error) { return r.GetData() } // GetData func (r *ErmcpDGFactoryItem) GetData() (interface{}, error) { sData := make([]ErmcpDGFactoryItem, 0) err := db.GetEngine().SQL(r.buildSql()).Find(&sData) return sData, err } // ErmcpBrand 品牌(从品种选择项定义表中查) type ErmcpBrand struct { BRANDID int64 `json:"brandid"` // 品牌id BRANDNAME string `json:"brandname"` // 品牌名称 DELIVERYGOODSID int32 `json:"deliverygoodsid"` // 品种ID } // 获取品牌数据 func (r *ErmcpBrand) GetData() ([]ErmcpBrand, error) { m := ErmcpDGFactoryItem{ DELIVERYGOODSID: r.DELIVERYGOODSID, DGFACTORYITEMTYPEID: 2, ORDERINDEX: 1, } sData := make([]ErmcpBrand, 0) if d, err := m.GetDataEx(); err == nil { if dgLst, ok := d.([]ErmcpDGFactoryItem); ok { for _, val := range dgLst { sData = append(sData, ErmcpBrand{BRANDID: val.DGFACTORYITEMID, BRANDNAME: val.DGFACTORYITEMVALUE, DELIVERYGOODSID: val.DELIVERYGOODSID}) } } } return sData, nil } // ErmcpRelatedGoods 现货品种的关联交易商品 type ErmcpRelatedGoods struct { GoodsId int `json:"goodsid" xorm:"'GoodsId'"` // 商品id GoodsCode string `json:"goodscode" xorm:"'GoodsCode'"` // 商品代码 GoodsName string `json:"goodsname" xorm:"'GoodsName'"` // 商品名称 DELIVERYGOODSID int32 `json:"deliverygoodsid" xorm:"'DELIVERYGOODSID'"` // 品种ID AREAUSERID int64 `json:"-"` // 所属机构 } func (r *ErmcpRelatedGoods) buildSql() string { var sqlId utils.SQLVal = "select distinct t.deliverygoodsid, g.goodsid, g.goodscode, g.goodsname" + " from deliverygoods t" + " inner join ERMS2_WRSConvertDetail w" + " on t.deliverygoodsid = w.deliverygoodsid" + " inner join erms_middlegoods m" + " on w.middlegoodsid = m.middlegoodsid" + " inner join ERMCP_GGConvertConfig gc" + " on m.goodsgroupid = gc.destgoodsgroupid" + " inner join goods g" + " on gc.srcgoodsgroupid = g.goodsgroupid" + " where 1 = 1" sqlId.AndEx("t.AREAUSERID", r.AREAUSERID, r.AREAUSERID > 0) sqlId.AndEx("t.DELIVERYGOODSID", r.DELIVERYGOODSID, r.DELIVERYGOODSID > 0) return sqlId.String() } // GetDataEx 获取现货关联交易商品 func (r *ErmcpRelatedGoods) GetDataEx() (interface{}, error) { return r.GetData() } // GetData 获取现货关联交易商品 func (r *ErmcpRelatedGoods) GetData() ([]ErmcpRelatedGoods, error) { sData := make([]ErmcpRelatedGoods, 0) err := db.GetEngine().SQL(r.buildSql()).Find(&sData) return sData, err } // ErmcpDeliveryGoodsDetail 现货商品详情 type ErmcpDeliveryGoodsDetail struct { Data ErmcpDeliveryGoods `json:"data"` // 现货商品基本信息(交割品种) GmList []ErmcpWrstandard `json:"gmlist"` // 品类列表(仓单标准) GbList []ErmcpBrand `json:"gblist"` // 品牌列表 WrsList []WRSConverTDetail `json:"wrslist"` // 套保信息列表 GoodsList []ErmcpRelatedGoods `json:"goodslist"` // 关联交易商品列表 QryTradeGoods int32 `json:"-"` // 是否查询关联交易商品 1-查询 } func (r *ErmcpDeliveryGoodsDetail) addGmList(lst []ErmcpWrstandard) { for i := range lst { if lst[i].DELIVERYGOODSID == r.Data.DELIVERYGOODSID { r.GmList = append(r.GmList, lst[i]) } } } func (r *ErmcpDeliveryGoodsDetail) addGbList(lst []ErmcpBrand) { for i := range lst { if lst[i].DELIVERYGOODSID == r.Data.DELIVERYGOODSID { r.GbList = append(r.GbList, lst[i]) } } } func (r *ErmcpDeliveryGoodsDetail) addWrsList(lst []WRSConverTDetail) { for i := range lst { if lst[i].DELIVERYGOODSID == r.Data.DELIVERYGOODSID { r.WrsList = append(r.WrsList, lst[i]) } } } func (r *ErmcpDeliveryGoodsDetail) addGoodsList(lst []ErmcpRelatedGoods) { for i := range lst { if lst[i].DELIVERYGOODSID == r.Data.DELIVERYGOODSID { r.GoodsList = append(r.GoodsList, lst[i]) } } } // GetDataEx func (r *ErmcpDeliveryGoodsDetail) GetDataEx() (interface{}, error) { sData := make([]ErmcpDeliveryGoodsDetail, 0) m := ErmcpDeliveryGoods{AREAUSERID: r.Data.AREAUSERID, DELIVERYGOODSID: r.Data.DELIVERYGOODSID} data, err := m.GetData() if err != nil { return sData, err } if data == nil || len(data) == 0 { return sData, nil } // 基本信息 for i := range data { val := ErmcpDeliveryGoodsDetail{Data: data[i], GmList: make([]ErmcpWrstandard, 0), GbList: make([]ErmcpBrand, 0), WrsList: make([]WRSConverTDetail, 0), GoodsList: make([]ErmcpRelatedGoods, 0), } sData = append(sData, val) } //品类/品牌/套保信息 gm := ErmcpWrstandard{AREAUSERID: int(r.Data.AREAUSERID), DELIVERYGOODSID: r.Data.DELIVERYGOODSID, ISVALID: 1} gb := ErmcpBrand{DELIVERYGOODSID: r.Data.DELIVERYGOODSID} WrsC := WRSConverTDetail{DELIVERYGOODSID: r.Data.DELIVERYGOODSID} gmLst, _ := gm.GetData() gbLst, _ := gb.GetData() wrsLst, _ := WrsC.GetData() var goodLst []ErmcpRelatedGoods if r.QryTradeGoods == 1 { goodsM := ErmcpRelatedGoods{AREAUSERID: r.Data.AREAUSERID, DELIVERYGOODSID: r.Data.DELIVERYGOODSID} goodLst, _ = goodsM.GetData() } for i := range sData { sData[i].addGmList(gmLst) sData[i].addGbList(gbLst) sData[i].addWrsList(wrsLst) sData[i].addGoodsList(goodLst) } return sData, nil } // Ermcp3Contract 现货合同 type Ermcp3Contract struct { SPOTCONTRACTID string `json:"spotcontractid" xorm:"'SPOTCONTRACTID'"` // 现货合同ID(602+Unix秒时间戳(10位)+xxxxxx) CONTRACTNO string `json:"contractno" xorm:"'CONTRACTNO'"` // 现货合同编号 CONTRACTTYPE int32 `json:"contracttype" xorm:"'CONTRACTTYPE'"` // 现货合同类型 - 1:采购 -1:销售 USERID int64 `json:"userid" xorm:"'USERID'"` // 所属机构ID BUYUSERID int64 `json:"buyuserid" xorm:"'BUYUSERID'"` // 采购方ID BUYUSERName string `json:"buyusername" xorm:"'BUYUSERName'"` // 采购方名称 SELLUSERID int64 `json:"selluserid" xorm:"'SELLUSERID'"` // 销售方ID SELLUSERNAME string `json:"sellusername" xorm:"'SELLUSERNAME'"` // 销售方名称 DELIVERYGOODSID int32 `json:"deliverygoodsid" xorm:"'DELIVERYGOODSID'"` // 现货品种ID WRSTANDARDID int32 `json:"wrstandardid" xorm:"'wrstandardid'"` // 品类ID WRSTANDARDNAME string `json:"wrstandardname" xorm:"'WRSTANDARDNAME'"` // 品类名称 WRSTANDARDCODE string `json:"wrstandardcode" xorm:"'WRSTANDARDCODE'"` // 品类代码 DELIVERYGOODSCODE string `json:"deliverygoodscode" xorm:"'DELIVERYGOODSCODE'"` // 现货品种代码 DELIVERYGOODSNAME string `json:"deliverygoodsname" xorm:"'DELIVERYGOODSNAME'"` // 现货品种名称 PRODUCTTYPE int32 `json:"producttype" xorm:"'PRODUCTTYPE'"` // 产品类型 - 1:标准仓单 2:等标 3:非标 CONVERTFACTOR float64 `json:"convertfactor" xorm:"'CONVERTFACTOR'"` // 标仓系数(品类) SPOTGOODSDESC string `json:"spotgoodsdesc" xorm:"'SPOTGOODSDESC'"` // 商品型号 PRICETYPE int32 `json:"pricetype" xorm:"'PRICETYPE'"` // 定价类型 - 1:一口价 2:点价 3:暂定价 QTY float64 `json:"qty" xorm:"'QTY'"` // 数量 PRICE float64 `json:"price" xorm:"'PRICE'"` // 价格\暂定价 [1:一口价、3:暂定价] AMOUNT float64 `json:"amount" xorm:"'AMOUNT'"` // 金额 [1:一口价、3:暂定价] DELIVERYSTARTDATE string `json:"deliverystartdate" xorm:"'DELIVERYSTARTDATE'"` // 交收期(开始) DELIVERYENDDATE string `json:"deliveryenddate" xorm:"'DELIVERYENDDATE'"` // 交收期(结束) GOODSID int32 `json:"goodsid" xorm:"'GOODSID'"` // 点价合约ID - 0:为现货,其它为期货商品合约ID [2:点价 3:暂定价] GOODSCODE string `json:"goodscode" xorm:"'GOODSCODE'"` // 点价合约代码 GOODSNAME string `json:"goodsname" xorm:"'GOODSNAME'"` // 点价商品名称 PRICEMOVE float64 `json:"pricemove" xorm:"'PRICEMOVE'"` // 升贴水 [2:点价 3:暂定价] STARTDATE string `json:"startdate" xorm:"'STARTDATE'"` // 点价开始日期 [2:点价 3:暂定价] ENDDATE string `json:"enddate" xorm:"'ENDDATE'"` // 点价结束日期 [2:点价 3:暂定价] MARGIN float64 `json:"margin" xorm:"'MARGIN'"` // 当前保证金 CONTRACTMARGIN float64 `json:"contractmargin" xorm:"'CONTRACTMARGIN'"` // 合同保证金 EnumdicName string `json:"enumdicname" xorm:"'ENUMDICNAME'"` // 单位名称 CONTRACCTSTATUS int32 `json:"contracctstatus" xorm:"'CONTRACTSTATUS'"` // 合同状态 - 0:未提交 1:待审核 2:执行中 3:正常完结 4:审核拒绝 5:异常完结 6:已撤回 Remark string `json:"remark" xorm:"'Remark'"` // 备注 AUDITREMARK string `json:"auditremark" xorm:"'AUDITREMARK'"` // 审核意见 AUDITTIME string `json:"audittime" xorm:"'AUDITTIME'"` // 审核时间 CREATETIME string `json:"createtime" xorm:"'CREATETIME'"` // 创建时间 UPDATETIME string `json:"updatetime" xorm:"'UPDATETIME'"` // 更新时间 SPOTGOODSBRANDID int32 `json:"spotgoodsbrandid" xorm:"'SPOTGOODSBRANDID'"` // 现货品牌ID(DGFactoryItem表的ID) BRANDNAME string `json:"brandname" xorm:"'brandname'"` // 品牌名称 ATTACHMENT string `json:"attachment" xorm:"'ATTACHMENT'"` // 附件 UNITID int32 `json:"unitid" xorm:"'UNITID'"` // 单位id(取品类上的单位id) // 筛选条件 QryType int32 `json:"-"` // 查询类型 1-未提交 2-待审核 3-履约中 4-已完成 UserType int32 `json:"-"` // 用户类型 2-管理员 7-企业成员 OwnUserId int64 `json:"-"` // 登录用户id } func (r *Ermcp3Contract) getQryTypeStatus() string { var status string switch r.QryType { case 1: // 未提交 status = "0,4,6" case 2: // 待审核 status = "1" case 3: // 履约中 status = "2" case 4: // 已完成 status = "3,5" } return status } func (r *Ermcp3Contract) calc() { r.BUYUSERName = mtpcache.GetUserNameByUserId(r.BUYUSERID) r.SELLUSERNAME = mtpcache.GetUserNameByUserId(r.SELLUSERID) r.EnumdicName = mtpcache.GetEnumDicitemName(r.UNITID) } func (r *Ermcp3Contract) buildSql() string { var sqlId utils.SQLVal = "SELECT to_char(t.SPOTCONTRACTID) SPOTCONTRACTID," + " t.CONTRACTNO," + " t.CONTRACTTYPE," + " t.USERID," + " t.BUYUSERID," + " t.SELLUSERID," + " t.DELIVERYGOODSID," + " t.wrstandardid," + " t.PRODUCTTYPE," + " w.CONVERTFACTOR," + " t.SPOTGOODSDESC," + " t.PRICETYPE," + " t.QTY," + " t.PRICE," + " t.AMOUNT," + " to_char(t.DELIVERYSTARTDATE, 'yyyy-mm-dd hh24:mi:ss') DELIVERYSTARTDATE," + " to_char(t.DELIVERYENDDATE, 'yyyy-mm-dd hh24:mi:ss') DELIVERYENDDATE," + " t.GOODSID," + " t.PRICEMOVE," + " to_char(t.STARTDATE, 'yyyy-mm-dd hh24:mi:ss') STARTDATE," + " to_char(t.ENDDATE, 'yyyy-mm-dd hh24:mi:ss') ENDDATE," + " t.MARGIN," + " t.contractmargin," + " t.remark," + " t.auditremark," + " to_char(t.contractattachment) attachment," + " t.contractstatus," + " t.SPOTGOODSBRANDID," + " to_char(t.audittime, 'yyyy-mm-dd hh24:mi:ss') audittime," + " to_char(t.createtime, 'yyyy-mm-dd hh24:mi:ss') createtime," + " to_char(t.updatetime, 'yyyy-mm-dd hh24:mi:ss') updatetime," + " g.deliverygoodscode," + " g.deliverygoodsname," + " g2.goodscode," + " g2.goodsname," + " gb.dgfactoryitemvalue brandname," + " w.wrstandardname," + " w.wrstandardcode," + " w.unitid" + " FROM ERMCP_SPOTCONTRACT t" + " left join deliverygoods g" + " on t.deliverygoodsid = g.deliverygoodsid" + " left join goods g2" + " on t.goodsid = g2.goodsid" + " left join DGFACTORYITEM gb" + " on t.spotgoodsbrandid = gb.dgfactoryitemid" + " left join wrstandard w" + " on t.wrstandardid = w.wrstandardid" + " where 1 = 1" sqlId.AndEx("t.userid", r.USERID, r.USERID > 0) sqlId.AndEx("t.SPOTCONTRACTID", r.SPOTCONTRACTID, len(r.SPOTCONTRACTID) > 0) if r.UserType == 7 { // 企业成员 sqlId.Join(fmt.Sprintf(" and %v in(t.saleuserid, t.tradeuserid, t.meruserid)", r.OwnUserId)) } status := r.getQryTypeStatus() if len(status) > 0 { sqlId.Join(fmt.Sprintf(" and t.contractstatus in (%v)", status)) } return sqlId.String() } // GetDataEx func (r *Ermcp3Contract) GetDataEx() (interface{}, error) { sData := make([]Ermcp3Contract, 0) err := db.GetEngine().SQL(r.buildSql()).Find(&sData) for i := range sData { sData[i].calc() } return sData, err } // Ermcp3SellBuyContract 采购/销售合同 type Ermcp3SellBuyContract struct { UserID int64 `json:"userid" xorm:"'UserID'"` // 机构ID SpotContractId string `json:"spotcontractid" xorm:"'SPOTCONTRACTID'"` // 合同ID AccountName string `json:"accountname" xorm:"'ACCOUNTNAME'"` // 账户名称 DeliveryGoodsId int `json:"deliverygoodsid" xorm:"'DELIVERYGOODSID'"` // 现货商品ID DeliveryGoodsCode string `json:"deliverygoodscode" xorm:"'DELIVERYGOODSCODE'"` // 现货品种代码 DeliveryGoodsName string `json:"deliverygoodsname" xorm:"'DELIVERYGOODSNAME'"` // 现货品种名称 SpotGoodsdesc string `json:"spotgoodsdesc" xorm:"'SPOTGOODSDESC'"` // 商品型号(商品规格) GoodsId int `json:"goodsid" xorm:"'GOODSID'"` // 点价商品ID GOODSNAME string `json:"goodsname" xorm:"'GOODSNAME'"` // 点价商品名称 Goodscode string `json:"goodscode" xorm:"'GOODSCODE'"` // 点价商品代码 Pricemove float64 `json:"pricemove" xorm:"'PRICEMOVE'"` // 升贴水 Qty float64 `json:"qty" xorm:"'QTY'"` // 合同量 UnpricedQty float64 `json:"unpricedqty" xorm:"'UNPRICEDQTY'"` // 未定价量 PricedQty float64 `json:"pricedqty" xorm:"'PRICEDQTY'"` // 已定价量 UnsureQty float64 `json:"unsureqty" xorm:"'UNSUREQTY'"` // 未确定量 PayAmount float64 `json:"payamount" xorm:"'PAYAMOUNT'"` // 已收付额(收款或付款) UnpayAmount float64 `json:"unpayamount"` // 应收付款额(应支付或应收款) PrePayAmount float64 `json:"prepayamount"` // 预收付额 InvoiceAmount float64 `json:"invoiceamount" xorm:"'INVOICEAMOUNT'"` // 已开票额 DaikaiAmount float64 `json:"daikaiamount" xorm:"'DAIKAIAMOUNT'"` // 应收(开)票额 PreInvoiceAmount float64 `json:"preinvoiceamount"` // 预收(开)票额 StartDate string `json:"startdate" xorm:"'STARTDATE'"` // 点价开始日 EndDate string `json:"enddate" xorm:"'ENDDATE'"` // 点价结束日 DeliveryStartDate string `json:"deliverystartdate" xorm:"'DELIVERYSTARTDATE'"` // 交割开始日 DeliveryendDate string `json:"deliveryenddate" xorm:"'DELIVERYENDDATE'"` // 交割结束日 Convertfactor float64 `json:"convertfactor" xorm:"'CONVERTFACTOR'"` // 标仓系数(品类) EnumdicName string `json:"enumdicname" xorm:"'ENUMDICNAME'"` // 单位名称 Contracctstatus uint `json:"contracctstatus" xorm:"'CONTRACTSTATUS'"` // 合同状态- 0:未提交 1:待审核 2:执行中 3:正常完结 4:审核拒绝 5:异常完结 6:已撤回 PriceType int `json:"pricetype" xorm:"'PRICETYPE'"` // 定价类型 - 1:一口价 2:点价 3:暂定价 ProductType int `json:"producttype" xorm:"'PRODUCTTYPE'"` // 产品类型 - 1:标准仓单 2:等标 3:非标 Contracttype int32 `json:"contracttype" xorm:"'CONTRACTTYPE'"` // 合同类型 1-采购, -1-销售 Pricedamount float64 `json:"pricedamount" xorm:"'PRICEDAMOUNT'"` // 已定价额 PricedAvg float64 `json:"pricedavg" xorm:"'PRICEDAVG'"` // 已点均价 Margin float64 `json:"margin" xorm:"'MARGIN'"` // 保证金 CONTRACTMARGIN float64 `json:"contractmargin" xorm:"'CONTRACTMARGIN'"` // 合同保证金 Remark string `json:"remark" xorm:"'Remark'"` // 备注 ATTACHMENT string `json:"attachment" xorm:"'ATTACHMENT'"` // 附件 ReckonRealQty float64 `json:"reckonrealqty" xorm:"'ReckonRealQty'"` // 已确定量 ReckonOtherAmount float64 `json:"reckonotheramount" xorm:"'ReckonOtherAmount'"` // 其它费用 ReckonAdjustAmount float64 `json:"reckonadjustamount" xorm:"'ReckonAdjustAmount'"` // 调整金额 Price float64 `json:"price" xorm:"'Price'"` // 价格 LoanAmount float64 `json:"loanamount" xorm:"'LoanAmount'"` // 贷款总额=已定价额+调整金额 Contractno string `json:"contractno" xorm:"'Contractno'"` // 合同编号 TotalAmount float64 `json:"totalamount" xorm:"'-'"` // 合计总额 ReckonedAmount float64 `json:"reckonedamount" xorm:"'ReckonedAmount'"` // 实际已收付额(已确定额,已收付总额-已退款总额) BUYUSERID int64 `json:"-" xorm:"'BUYUSERID'"` // 采购方ID SELLUSERID int64 `json:"-" xorm:"'SELLUSERID'"` // 销售方ID AUDITTIME string `json:"audittime" xorm:"'AUDITTIME'"` // 审核时间 CREATETIME string `json:"createtime" xorm:"'CREATETIME'"` // 创建时间 SPOTGOODSBRANDID int32 `json:"spotgoodsbrandid" xorm:"'SPOTGOODSBRANDID'"` // 现货品牌ID(DGFactoryItem表的ID) BRANDNAME string `json:"brandname" xorm:"'brandname'"` // 品牌名称 WRSTANDARDID int64 `json:"wrstandardid" xorm:"'WRSTANDARDID'"` // 品类ID WRSTANDARDNAME string `json:"wrstandardname" xorm:"'WRSTANDARDNAME'"` // 品类名称 WRSTANDARDCODE string `json:"wrstandardcode" xorm:"'WRSTANDARDCODE'"` // 品类代码 // 筛选条件 QryType int32 `json:"-"` // 查询类型 1-未提交 2-待审核 3-履约中 4-已完成 UserType int32 `json:"-"` // 用户类型 2-管理员 7-企业成员 OwnUserId int64 `json:"-"` // 登录用户id } func (r *Ermcp3SellBuyContract) calc() { r.TotalAmount = r.LoanAmount + r.ReckonOtherAmount r.UnpayAmount = r.TotalAmount - r.ReckonedAmount r.PrePayAmount = r.ReckonedAmount - r.TotalAmount r.PreInvoiceAmount = r.InvoiceAmount - r.TotalAmount if r.Contracttype == 1 { //采购合同, 取销售方名称 r.AccountName = mtpcache.GetUserNameByUserId(r.SELLUSERID) } else { //销售合同, 取采购方名称 r.AccountName = mtpcache.GetUserNameByUserId(r.BUYUSERID) } } func (r *Ermcp3SellBuyContract) buildSql() string { var sqlId utils.SQLVal = "select t.contractno," + " to_char(t.SpotContractId) SpotContractId," + " t.deliverygoodsid," + " t.spotgoodsdesc," + " t.goodsid," + " t.pricemove," + " t.userid," + " t.BUYUSERID," + " t.SELLUSERID," + " t.qty," + " t.qty - t.pricedqty unpricedqty," + " t.pricedqty," + " (case" + " when t.pricetype = 3 then" + " t.qty - t.RECKONREALQTY" + " else" + " t.pricedqty - t.ReckonRealQty" + " end) unsureqty," + " t.reckonedamount PayAmount," + " t.invoiceamount," + " (t.pricedamount + t.RECKONADJUSTAMOUNT + t.RECKONOTHERAMOUNT -" + " t.invoiceamount) as daikaiAmount," + " to_char(t.startdate, 'yyyy-mm-dd hh24:mi:ss') startdate," + " to_char(t.enddate, 'yyyy-mm-dd hh24:mi:ss') enddate," + " to_char(t.deliverystartdate, 'yyyy-mm-dd hh24:mi:ss') deliverystartdate," + " to_char(t.deliveryenddate, 'yyyy-mm-dd hh24:mi:ss') deliveryenddate," + " w.convertfactor," + " t.contractstatus," + " t.pricetype," + " t.producttype," + " t.contracttype," + " t.remark," + " to_char(t.contractattachment) attachment," + " t.margin," + " t.contractmargin," + " t.SPOTGOODSBRANDID," + " g.deliverygoodscode," + " g.deliverygoodsname," + " wr.wrstandardid," + " wr.wrstandardname," + " wr.wrstandardcode," + " g2.goodscode," + " g2.goodsname," + " e.enumdicname," + " t.contracttype," + " t.pricedamount," + " case" + " when t.pricedqty > 0 then" + " (t.pricedamount) / t.pricedqty" + " else" + " 0" + " end pricedAvg," + " t.ReckonRealQty," + " t.ReckonOtherAmount," + " t.ReckonAdjustAmount," + " t.Price," + " t.ReckonedAmount," + " to_char(t.audittime, 'yyyy-mm-dd hh24:mi:ss') audittime," + " to_char(t.createtime, 'yyyy-mm-dd hh24:mi:ss') createtime," + " t.pricedamount + t.ReckonAdjustAmount as LoanAmount," + " gb.dgfactoryitemvalue BRANDNAME" + " from ermcp_spotcontract t" + " left join deliverygoods g" + " on t.deliverygoodsid = g.deliverygoodsid" + " left join goods g2" + " on t.goodsid = g2.goodsid" + " left join wrstandard wr" + " on t.wrstandardid = wr.wrstandardid" + " left join DGFactoryItem gb" + " on t.spotgoodsbrandid = gb.dgfactoryitemid" + " left join enumdicitem e" + " on wr.unitid = e.enumitemname" + " and e.enumdiccode = 'goodsunit'" + " where 1 = 1" sqlId.AndEx("t.userid", r.UserID, r.UserID > 0) sqlId.AndEx("t.SpotContractId", r.SpotContractId, len(r.SpotContractId) > 0) if r.UserType == 7 { // 企业成员 sqlId.Join(fmt.Sprintf(" and %v in(t.saleuserid, t.tradeuserid, t.meruserid)", r.OwnUserId)) } var tmp = Ermcp3Contract{QryType: r.QryType} status := tmp.getQryTypeStatus() if len(status) > 0 { sqlId.Join(fmt.Sprintf(" and t.contractstatus in (%v)", status)) } return sqlId.String() } // GetDataEx func (r *Ermcp3SellBuyContract) GetDataEx() (interface{}, error) { sData := make([]Ermcp3SellBuyContract, 0) err := db.GetEngine().SQL(r.buildSql()).Find(&sData) for i := range sData { sData[i].calc() } return sData, err }