/** * @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 } // QhjRStrategy 定投规则策略 type QhjRStrategy struct { REGULARLYCYCLE int32 `json:"regularlycycle" xorm:"REGULARLYCYCLE"` // 定投频率 - 1:每周 2:每月 REGULARLYCYCLEVALUE string `json:"regularlycyclevalue" xorm:"REGULARLYCYCLEVALUE"` // 定投频率值 - 每周几(0-6) 或 每月几号(<=28) REGULARLYMODE int32 `json:"regularlymode" xorm:"REGULARLYMODE"` // 定投方式 - 1:按数量 2:按金额 REGULARLYMODEVALUE float64 `json:"regularlymodevalue" xorm:"REGULARLYMODEVALUE"` // 定投方式值 - 数量或金额 REMARK string `json:"remark" xorm:"REMARK"` // 备注 REGULARLYSTRATEGYSTATUS int32 `json:"regularlystrategystatus" xorm:"REGULARLYSTRATEGYSTATUS"` // 策略状态 - 1:正常 2:暂停 3:终止 TRIGGERTOTALTIMES string `json:"triggertotaltimes" xorm:"TRIGGERTOTALTIMES"` // 累计定投总次数 TRIGGERSUCCESSTIMES string `json:"triggersuccesstimes" xorm:"TRIGGERSUCCESSTIMES"` // 累计定投成功次数 TRIGGERTOTALQTY float64 `json:"triggertotalqty" xorm:"TRIGGERTOTALQTY"` // 累计定投数量(成功) [按小数位放大值] TRIGGERTOTALAMOUNT float64 `json:"triggertotalamount" xorm:"TRIGGERTOTALAMOUNT"` // 累计定投金额(成功) LASTEFFECTTRADEDATE string `json:"lasteffecttradedate" xorm:"LASTEFFECTTRADEDATE"` // 最新生效交易日 LASTSTOPTRADEDATE string `json:"laststoptradedate" xorm:"LASTSTOPTRADEDATE"` // 最新暂停交易日 LASTTRIGGERTRADEDATE string `json:"lasttriggertradedate" xorm:"LASTTRIGGERTRADEDATE"` // 最新触发交易日 NEXTTRIGGERDATE string `json:"nexttriggerdate" xorm:"NEXTTRIGGERDATE"` // 下次触发日期 NEXTTRIGGERQTY float64 `json:"nexttriggerqty" xorm:"NEXTTRIGGERQTY"` // 下次触发数量 [按小数位放大值] NEXTTRIGGERAMOUNT float64 `json:"nexttriggeramount" xorm:"NEXTTRIGGERAMOUNT"` // 下次触发金额 UPDATORID string `json:"updatorid" xorm:"UPDATORID"` // 更新人 UPDATESRC int32 `json:"updatesrc" xorm:"UPDATESRC"` // 更新来源 - 1:管理端 2:终端 UPDATETIME string `json:"updatetime" xorm:"UPDATETIME"` // 更新时间 REGULARLYSTRATEGYID int64 `json:"regularlystrategyid" xorm:"REGULARLYSTRATEGYID"` // 定投策略ID (SEQ_QHJ_REGULARLYSTRATEGY) USERID int64 `json:"userid" xorm:"USERID"` // 所属用户ID ACCOUNTID int64 `json:"accountid" xorm:"ACCOUNTID"` // 用户资金账户 GOODSID string `json:"goodsid" xorm:"GOODSID"` // 定投商品ID GOODSCODE string `json:"goodscode" xorm:"'GOODSCODE'"` // 定投商品代码 GOODSNAME string `json:"goodsname" xorm:"'GOODSNAME'"` // 定投商品名称 GOODUNITID int32 `json:"goodunitid" xorm:"'GOODUNITID'"` // 定投商品单位id CURRENCYID int32 `json:"currencyid" xorm:"'CURRENCYID'"` // 币种id USERNAME string `json:"username"` // 用户名称(userid对应的名称) ACCOUNTNAME string `json:"accountname"` // 账号名称(ACCOUNTID对应的名称) ENUMDICNAME string `json:"enumdicname"` // 单位名称 CURRENCYNAME string `json:"currencyname"` // 币种名称 FilterStatus string `json:"-"` // 状态过滤条件 } func (r *QhjRStrategy) calc() { r.USERNAME = mtpcache.GetUserNameByUserId(r.USERID) r.ENUMDICNAME = mtpcache.GetEnumDicitemName(r.GOODUNITID) r.CURRENCYNAME = mtpcache.GetCurrencyName(r.CURRENCYID) } func (r *QhjRStrategy) buildSql() string { var sqlId utils.SQLVal = "SELECT t.REGULARLYCYCLE," + " t.REGULARLYCYCLEVALUE," + " t.REGULARLYMODE," + " t.REGULARLYMODEVALUE," + " t.REMARK," + " t.REGULARLYSTRATEGYSTATUS," + " t.TRIGGERTOTALTIMES," + " t.TRIGGERSUCCESSTIMES," + " t.TRIGGERTOTALQTY," + " t.TRIGGERTOTALAMOUNT," + " t.LASTEFFECTTRADEDATE," + " t.LASTSTOPTRADEDATE," + " t.LASTTRIGGERTRADEDATE," + " to_char(t.NEXTTRIGGERDATE, 'yyyy-mm-dd hh24:mi:ss') NEXTTRIGGERDATE," + " t.NEXTTRIGGERQTY," + " t.NEXTTRIGGERAMOUNT," + " t.UPDATORID," + " t.UPDATESRC," + " to_char(t.UPDATETIME, 'yyyy-mm-dd hh24:mi:ss') UPDATETIME," + " t.REGULARLYSTRATEGYID," + " t.USERID," + " t.ACCOUNTID," + " t.GOODSID," + " g.goodscode," + " g.goodsname," + " g.goodunitid," + " ta.accountname" + " FROM QHJ_REGULARLYSTRATEGY t" + " LEFT JOIN GOODS g on t.goodsid=g.goodsid" + " LEFT JOIN TAACCOUNT ta on t.accountid=ta.accountid" + " WHERE 1 = 1" sqlId.And("t.USERID", r.USERID) sqlId.JoinEx(len(r.FilterStatus) > 0, fmt.Sprintf(" and t.REGULARLYSTRATEGYSTATUS in(%v)", r.FilterStatus)) return sqlId.String() } // GetDataEx 获取定投规则策略 func (r *QhjRStrategy) GetDataEx() (interface{}, error) { sData := make([]QhjRStrategy, 0) err := db.GetEngine().SQL(r.buildSql()).Find(&sData) for i := range sData { sData[i].calc() } return sData, err } // QhjRSTriggerLog 定投规则策略触发记录 type QhjRSTriggerLog struct { TRADEID string `json:"tradeid" xorm:"TRADEID"` // 成交单ID LOGID string `json:"logid" xorm:"LOGID"` // LogID(SEQ_QHJ_RSTRIGGERLOG) REGULARLYSTRATEGYID int64 `json:"regularlystrategyid" xorm:"REGULARLYSTRATEGYID"` // 定投策略ID USERID int64 `json:"userid" xorm:"USERID"` // 所属用户ID ACCOUNTID int64 `json:"accountid" xorm:"ACCOUNTID"` // 用户资金账户 GOODSID string `json:"goodsid" xorm:"GOODSID"` // 定投商品ID REGULARLYCYCLE int32 `json:"regularlycycle" xorm:"REGULARLYCYCLE"` // 定投频率 - 1:每周 2:每月 REGULARLYCYCLEVALUE string `json:"regularlycyclevalue" xorm:"REGULARLYCYCLEVALUE"` // 定投频率值 - 每周几(0-6) 或 每月几号(<=28) REGULARLYMODE int32 `json:"regularlymode" xorm:"REGULARLYMODE"` // 定投方式 - 1:按数量 2:按金额 REGULARLYMODEVALUE float64 `json:"regularlymodevalue" xorm:"REGULARLYMODEVALUE"` // 定投方式值 - 数量或金额 TRIGGERTIME string `json:"triggertime" xorm:"TRIGGERTIME"` // 触发时间 TRIGGERTRADEDATE string `json:"triggertradedate" xorm:"TRIGGERTRADEDATE"` // 触发交易日 TRIGGERQTY float64 `json:"triggerqty" xorm:"TRIGGERQTY"` // 触发数量 TRIGGERAMOUNT float64 `json:"triggeramount" xorm:"TRIGGERAMOUNT"` // 触发金额 TRIGGERSTATUS int32 `json:"triggerstatus" xorm:"TRIGGERSTATUS"` // 触发状态 - 1:成功 2:失败 RETCODE string `json:"retcode" xorm:"RETCODE"` // 错误码 GOODSCODE string `json:"goodscode" xorm:"'GOODSCODE'"` // 定投商品代码 GOODSNAME string `json:"goodsname" xorm:"'GOODSNAME'"` // 定投商品名称 GOODUNITID int32 `json:"goodunitid" xorm:"'GOODUNITID'"` // 定投商品单位id CURRENCYID int32 `json:"currencyid" xorm:"'CURRENCYID'"` // 币种id USERNAME string `json:"username"` // 用户名称(userid对应的名称) ACCOUNTNAME string `json:"accountname"` // 账号名称(ACCOUNTID对应的名称) ENUMDICNAME string `json:"enumdicname"` // 单位名称 CURRENCYNAME string `json:"currencyname"` // 币种名称 } func (r *QhjRSTriggerLog) calc() { r.USERNAME = mtpcache.GetUserNameByUserId(r.USERID) r.ENUMDICNAME = mtpcache.GetEnumDicitemName(r.GOODUNITID) r.CURRENCYNAME = mtpcache.GetCurrencyName(r.CURRENCYID) } func (r *QhjRSTriggerLog) buildSql() string { var sqlId utils.SQLVal = "SELECT t.TRADEID," + " t.LOGID," + " t.REGULARLYSTRATEGYID," + " t.USERID," + " t.ACCOUNTID," + " t.GOODSID," + " t.REGULARLYCYCLE," + " t.REGULARLYCYCLEVALUE," + " t.REGULARLYMODE," + " t.REGULARLYMODEVALUE," + " to_char(t.TRIGGERTIME, 'yyyy-mm-dd hh24:mi:ss') TRIGGERTIME," + " t.TRIGGERTRADEDATE," + " t.TRIGGERQTY," + " t.TRIGGERAMOUNT," + " t.TRIGGERSTATUS," + " t.RETCODE," + " g.goodscode," + " g.goodsname," + " g.goodunitid," + " ta.accountname," + " ta.currencyid" + " FROM QHJ_RSTRIGGERLOG t" + " LEFT JOIN GOODS g" + " on t.goodsid = g.goodsid" + " LEFT JOIN TAACCOUNT ta" + " on t.accountid = ta.accountid" + " WHERE 1 = 1" sqlId.And("t.USERID", r.USERID) sqlId.AndEx("t.REGULARLYSTRATEGYID", r.REGULARLYSTRATEGYID, r.REGULARLYSTRATEGYID > 0) return sqlId.String() } // GetDataEx 获取定投规则策略触发记录 func (r *QhjRSTriggerLog) GetDataEx() (interface{}, error) { sData := make([]QhjRSTriggerLog, 0) err := db.GetEngine().SQL(r.buildSql()).Find(&sData) for i := range sData { sData[i].calc() } return sData, err }