package model

import "mtp20_assisted/global"

// Get 通过采购成交单ID获取信息
func (t *Thjpurchasetradedetail) Get() (has bool, err error) {
	return global.M2A_DB.Where("WRTRADEDETAILID = ?", t.WRTRADEDETAILID).Get(t)
}

// Get 通过预售申请ID获取信息
func (t *Wrpresaleinfo) Get() (has bool, err error) {
	return global.M2A_DB.Where("PRESALEAPPLYID = ?", t.PRESALEAPPLYID).Get(t)
}

// UpdateContractAddrBuy 更新预售模板合同地址
func (t *Thjpurchasetradedetail) UpdateContractAddrBuy() (err error) {
	_, err = global.M2A_DB.Where("WRTRADEDETAILID = ?", t.WRTRADEDETAILID).Cols("CONTRACTADDRBUY").Update(t)
	return
}

// Get 协议转让ID获取信息
func (t *Thjpurchasetransfer) Get() (has bool, err error) {
	return global.M2A_DB.Where("TRANSFERID = ?", t.TRANSFERID).Get(t)
}

// UpdateContractAddr 更新协议转让合同地址
func (t *Thjpurchasetransfer) UpdateContractAddr() (err error) {
	_, err = global.M2A_DB.Where("TRANSFERID = ?", t.TRANSFERID).Cols("CONTRACTADDR").Update(t)
	return
}

// Get 通过仓单贸易成交单ID获取信息
func (t *Wrtradetradequote) Get() (has bool, err error) {
	return global.M2A_DB.Where("WRTRADEDETAILID = ?", t.WRTRADEDETAILID).Get(t)
}

// UpdateContractAddr 更新合同地址
func (t *Wrtradetradequote) UpdateContractAddr(buyOrSell int) (err error) {
	field := "CONTRACTADDRBUY"
	if buyOrSell == 1 {
		field = "CONTRACTADDRSELL"
	}
	_, err = global.M2A_DB.Where("WRTRADEDETAILID = ?", t.WRTRADEDETAILID).Cols(field).Update(t)
	return
}
