qhj.go 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /**
  2. * @Author: zou.yingbin
  3. * @Create : 2021/6/1 14:14
  4. * @Modify : 2021/6/1 14:14
  5. */
  6. package models
  7. import (
  8. "fmt"
  9. "mtp2_if/db"
  10. "mtp2_if/mtpcache"
  11. "mtp2_if/utils"
  12. )
  13. // 大连千海金
  14. // QhjContract 千海金融资明细(合同)
  15. type QhjContract struct {
  16. USERID int64 `json:"userid" xorm:"USERID"` // 用户ID
  17. SCFCONTRACTID int64 `json:"scfcontractid" xorm:"SCFCONTRACTID"` // SCF合同ID(310+Unix秒时间戳(10位)+xxxxxx)
  18. SCFCONTRACTTYPE int32 `json:"scfcontracttype" xorm:"SCFCONTRACTTYPE"` // 合同类型 - 1:仓单回购 2:仓单质押 3:合作套保 4:资金贷款 5:融资单
  19. GOODSID int32 `json:"goodsid" xorm:"GOODSID"` // 商品ID [5:融资单]
  20. CONTRACTCONFIRMTIME string `json:"contractconfirmtime" xorm:"CONTRACTCONFIRMTIME"` // 合同确认时间(时间)
  21. WRQTY int32 `json:"wrqty" xorm:"WRQTY"` // 仓单数量(数量)
  22. TRADEPRICE float64 `json:"tradeprice" xorm:"TRADEPRICE"` // 成交价格(成本价格)
  23. LENDERAMOUNT float64 `json:"lenderamount" xorm:"LENDERAMOUNT"` // 贷款金额(总额|订单总额)
  24. MARGINRATIO float64 `json:"marginratio" xorm:"MARGINRATIO"` // 保证金比率(首付比例)
  25. INITMARGIN float64 `json:"initmargin" xorm:"'INITMARGIN'"` // 初始保证金(首付款)
  26. RECOVEREDMARGIN float64 `json:"recoveredmargin" xorm:"'RECOVEREDMARGIN'"` // 已追缴保证金
  27. REMAINAMOUNT float64 `json:"remainamount" xorm:"'REMAINAMOUNT'"` // 合同剩余金额(融资额)
  28. TOTALINTEREST float64 `json:"totalinterest" xorm:"'TOTALINTEREST'"` // 已计总利息(利息)
  29. GOODSCODE string `json:"goodscode" xorm:"'GOODSCODE'"` // 商品代码
  30. GOODSNAME string `json:"goodsname" xorm:"'GOODSNAME'"` // 商品名称
  31. GOODUNITID int32 `json:"goodunitid" xorm:"'GOODUNITID'"` // 商品单位id
  32. PAYAMOUNT float64 `json:"payamount" xorm:"'PAYAMOUNT'"` // 已付(已付货款)
  33. USERNAME string `json:"username" xorm:"'USERNAME'"` // 用户名称
  34. ENUMDICNAME string `json:"enumdicname"` // 单位名称
  35. }
  36. func (r *QhjContract) calc() {
  37. r.USERNAME = mtpcache.GetUserNameByUserId(r.USERID)
  38. r.ENUMDICNAME = mtpcache.GetEnumDicitemName(r.GOODUNITID)
  39. // 已付(已付货款) = 已追缴保证金 + 初始保证金
  40. r.PAYAMOUNT = r.RECOVEREDMARGIN + r.INITMARGIN
  41. }
  42. func (r *QhjContract) buildSql() string {
  43. var sqlId utils.SQLVal = "select t.borroweruserid userid," +
  44. " t.scfcontractid," +
  45. " t.scfcontracttype," +
  46. " t.goodsid," +
  47. " to_char(t.contractconfirmtime, 'yyyy-mm-dd hh24:mi:ss') contractconfirmtime," +
  48. " t.wrqty," +
  49. " t.tradeprice," +
  50. " t.lenderamount," +
  51. " t.marginratio," +
  52. " s.initmargin," +
  53. " s.recoveredmargin," +
  54. " s.remainamount," +
  55. " s.totalinterest," +
  56. " g.goodscode," +
  57. " g.goodsname," +
  58. " g.goodunitid" +
  59. " from scf_contract t" +
  60. " left join scf_contractinfo s" +
  61. " on t.scfcontractid = s.scfcontractid" +
  62. " left join goods g" +
  63. " on t.goodsid = g.goodsid" +
  64. " where 1=1"
  65. sqlId.And("t.borroweruserid", r.USERID)
  66. sqlId.AndEx("t.SCFCONTRACTID", r.SCFCONTRACTID, r.SCFCONTRACTID > 0)
  67. return sqlId.String()
  68. }
  69. // GetDataEx 获取融资明细(合同)
  70. func (r *QhjContract) GetDataEx() (interface{}, error) {
  71. sData := make([]QhjContract, 0)
  72. err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
  73. for i := range sData {
  74. sData[i].calc()
  75. }
  76. return sData, err
  77. }
  78. // QhjContractLog 融资明细流水log
  79. type QhjContractLog struct {
  80. LOGID string `json:"logid" xorm:"LOGID"` // LogID(315+Unix秒时间戳(10位)+2位(MarketServiceID)+xxxx)
  81. SCFCONTRACTID int64 `json:"scfcontractid" xorm:"SCFCONTRACTID"` // SCF合同ID(310+Unix秒时间戳(10位)+xxxxxx)
  82. AMOUNTTYPE int32 `json:"amounttype" xorm:"AMOUNTTYPE"` // 资金类型 - 1:首付款2:尾款 3:利息 4:追加款
  83. AMOUNT float64 `json:"amount" xorm:"AMOUNT"` // 支付金额
  84. REMAINAMOUNT float64 `json:"remainamount" xorm:"REMAINAMOUNT"` // 剩余货款
  85. UPDATETIME string `json:"updatetime" xorm:"UPDATETIME"` // 更新时间
  86. FilterType string `json:"-"` // 资金类型
  87. }
  88. func (r *QhjContractLog) calc() {
  89. }
  90. func (r *QhjContractLog) buildSql() string {
  91. var sqlId utils.SQLVal = "SELECT t.LOGID," +
  92. " t.SCFCONTRACTID," +
  93. " t.AMOUNTTYPE," +
  94. " t.AMOUNT," +
  95. " t.REMAINAMOUNT," +
  96. " to_char(t.UPDATETIME, 'yyyy-mm-dd hh24:mi:ss') UPDATETIME" +
  97. " FROM SCF_CONTRACTAMOUNTLOG t" +
  98. " WHERE 1 = 1"
  99. sqlId.AndEx("t.SCFCONTRACTID", r.SCFCONTRACTID, r.SCFCONTRACTID > 0)
  100. sqlId.JoinEx(len(r.FilterType) > 0, fmt.Sprintf(" and t.AMOUNTTYPE in(%v)", r.FilterType))
  101. return sqlId.String()
  102. }
  103. // GetDataEx 获取融资明细流水log
  104. func (r *QhjContractLog) GetDataEx() (interface{}, error) {
  105. sData := make([]QhjContractLog, 0)
  106. err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
  107. for i := range sData {
  108. sData[i].calc()
  109. }
  110. return sData, err
  111. }