| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- /**
- * @Author: zou.yingbin
- * @Create : 2021/6/1 14:14
- * @Modify : 2021/6/1 14:14
- */
- package models
- import (
- "fmt"
- "mtp2_if/db"
- "mtp2_if/mtpcache"
- "mtp2_if/utils"
- )
- // 大连千海金
- // QhjContract 千海金融资明细(合同)
- type QhjContract struct {
- USERID int64 `json:"userid" xorm:"USERID"` // 用户ID
- SCFCONTRACTID int64 `json:"scfcontractid" xorm:"SCFCONTRACTID"` // SCF合同ID(310+Unix秒时间戳(10位)+xxxxxx)
- SCFCONTRACTTYPE int32 `json:"scfcontracttype" xorm:"SCFCONTRACTTYPE"` // 合同类型 - 1:仓单回购 2:仓单质押 3:合作套保 4:资金贷款 5:融资单
- GOODSID int32 `json:"goodsid" xorm:"GOODSID"` // 商品ID [5:融资单]
- CONTRACTCONFIRMTIME string `json:"contractconfirmtime" xorm:"CONTRACTCONFIRMTIME"` // 合同确认时间(时间)
- WRQTY int32 `json:"wrqty" xorm:"WRQTY"` // 仓单数量(数量)
- TRADEPRICE float64 `json:"tradeprice" xorm:"TRADEPRICE"` // 成交价格(成本价格)
- LENDERAMOUNT float64 `json:"lenderamount" xorm:"LENDERAMOUNT"` // 贷款金额(总额|订单总额)
- MARGINRATIO float64 `json:"marginratio" xorm:"MARGINRATIO"` // 保证金比率(首付比例)
- INITMARGIN float64 `json:"initmargin" xorm:"'INITMARGIN'"` // 初始保证金(首付款)
- RECOVEREDMARGIN float64 `json:"recoveredmargin" xorm:"'RECOVEREDMARGIN'"` // 已追缴保证金
- REMAINAMOUNT float64 `json:"remainamount" xorm:"'REMAINAMOUNT'"` // 合同剩余金额(融资额)
- TOTALINTEREST float64 `json:"totalinterest" xorm:"'TOTALINTEREST'"` // 已计总利息(利息)
- GOODSCODE string `json:"goodscode" xorm:"'GOODSCODE'"` // 商品代码
- GOODSNAME string `json:"goodsname" xorm:"'GOODSNAME'"` // 商品名称
- GOODUNITID int32 `json:"goodunitid" xorm:"'GOODUNITID'"` // 商品单位id
- PAYAMOUNT float64 `json:"payamount" xorm:"'PAYAMOUNT'"` // 已付(已付货款)
- USERNAME string `json:"username" xorm:"'USERNAME'"` // 用户名称
- ENUMDICNAME string `json:"enumdicname"` // 单位名称
- }
- func (r *QhjContract) calc() {
- r.USERNAME = mtpcache.GetUserNameByUserId(r.USERID)
- r.ENUMDICNAME = mtpcache.GetEnumDicitemName(r.GOODUNITID)
- // 已付(已付货款) = 已追缴保证金 + 初始保证金
- r.PAYAMOUNT = r.RECOVEREDMARGIN + r.INITMARGIN
- }
- func (r *QhjContract) buildSql() string {
- var sqlId utils.SQLVal = "select t.borroweruserid userid," +
- " t.scfcontractid," +
- " t.scfcontracttype," +
- " t.goodsid," +
- " to_char(t.contractconfirmtime, 'yyyy-mm-dd hh24:mi:ss') contractconfirmtime," +
- " t.wrqty," +
- " t.tradeprice," +
- " t.lenderamount," +
- " t.marginratio," +
- " s.initmargin," +
- " s.recoveredmargin," +
- " s.remainamount," +
- " s.totalinterest," +
- " g.goodscode," +
- " g.goodsname," +
- " g.goodunitid" +
- " from scf_contract t" +
- " left join scf_contractinfo s" +
- " on t.scfcontractid = s.scfcontractid" +
- " left join goods g" +
- " on t.goodsid = g.goodsid" +
- " where 1=1"
- sqlId.And("t.borroweruserid", r.USERID)
- sqlId.AndEx("t.SCFCONTRACTID", r.SCFCONTRACTID, r.SCFCONTRACTID > 0)
- return sqlId.String()
- }
- // GetDataEx 获取融资明细(合同)
- func (r *QhjContract) GetDataEx() (interface{}, error) {
- sData := make([]QhjContract, 0)
- err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
- for i := range sData {
- sData[i].calc()
- }
- return sData, err
- }
- // QhjContractLog 融资明细流水log
- type QhjContractLog struct {
- LOGID string `json:"logid" xorm:"LOGID"` // LogID(315+Unix秒时间戳(10位)+2位(MarketServiceID)+xxxx)
- SCFCONTRACTID int64 `json:"scfcontractid" xorm:"SCFCONTRACTID"` // SCF合同ID(310+Unix秒时间戳(10位)+xxxxxx)
- AMOUNTTYPE int32 `json:"amounttype" xorm:"AMOUNTTYPE"` // 资金类型 - 1:首付款2:尾款 3:利息 4:追加款
- AMOUNT float64 `json:"amount" xorm:"AMOUNT"` // 支付金额
- REMAINAMOUNT float64 `json:"remainamount" xorm:"REMAINAMOUNT"` // 剩余货款
- UPDATETIME string `json:"updatetime" xorm:"UPDATETIME"` // 更新时间
- FilterType string `json:"-"` // 资金类型
- }
- func (r *QhjContractLog) calc() {
- }
- func (r *QhjContractLog) buildSql() string {
- var sqlId utils.SQLVal = "SELECT t.LOGID," +
- " t.SCFCONTRACTID," +
- " t.AMOUNTTYPE," +
- " t.AMOUNT," +
- " t.REMAINAMOUNT," +
- " to_char(t.UPDATETIME, 'yyyy-mm-dd hh24:mi:ss') UPDATETIME" +
- " FROM SCF_CONTRACTAMOUNTLOG t" +
- " WHERE 1 = 1"
- sqlId.AndEx("t.SCFCONTRACTID", r.SCFCONTRACTID, r.SCFCONTRACTID > 0)
- sqlId.JoinEx(len(r.FilterType) > 0, fmt.Sprintf(" and t.AMOUNTTYPE in(%v)", r.FilterType))
- return sqlId.String()
- }
- // GetDataEx 获取融资明细流水log
- func (r *QhjContractLog) GetDataEx() (interface{}, error) {
- sData := make([]QhjContractLog, 0)
- err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
- for i := range sData {
- sData[i].calc()
- }
- return sData, err
- }
|