zhongrong.go 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. package models
  2. import (
  3. "encoding/hex"
  4. "fmt"
  5. "mtp2_if/db"
  6. "mtp2_if/utils"
  7. "time"
  8. )
  9. // Tradepositiontransfer 持仓过户申请表 - 16所有权(中融需求)
  10. type InTradepositiontransfer struct {
  11. APPLYID string `json:"applyid" xorm:"APPLYID"` // 申请ID(185+Unix秒时间戳(10位)+2位(MarketServiceID)+xxxx)
  12. OUTUSERID int64 `json:"outuserid" xorm:"OUTUSERID"` // 转出方用户ID(申请方)
  13. OUTLOGINID int64 `json:"outloginid" xorm:"OUTLOGINID"` // 转出方登录账号
  14. OUTACCOUNTID int64 `json:"outaccountid" xorm:"OUTACCOUNTID"` // 转出方资金ID(申请方)
  15. INUSERID int64 `json:"inuserid" xorm:"INUSERID" form:"userid" binding:"required"` // 转入方用户ID(确认方)
  16. INACCOUNTID int64 `json:"inaccountid" xorm:"INACCOUNTID"` // 转入方资金ID(确认方)
  17. INLOGINID int64 `json:"inloginid" xorm:"INLOGINID"` // 转入方登录账号
  18. GOODSID int32 `json:"goodsid" xorm:"GOODSID"` // 商品ID
  19. MARKETID int32 `json:"marketid" xorm:"MARKETID"` // 市场ID
  20. BUYORSELL int32 `json:"buyorsell" xorm:"BUYORSELL"` // 买卖 - 0:买 1:卖
  21. QTY int64 `json:"qty" xorm:"QTY"` // 转让数量
  22. TRANSFERPRICE float64 `json:"transferprice" xorm:"TRANSFERPRICE"` // 转让价格
  23. TRANSFERAPPLYSTATUS int32 `json:"transferapplystatus" xorm:"TRANSFERAPPLYSTATUS"` // 过户申请状态 - 1: 待审核 2:待确认 3:确认处理中 4:已确认 5:申请失败 6:系统撤销 7:审核拒绝- 枚举"transferapplystatus"
  24. FREEZEDAYS int64 `json:"freezedays" xorm:"FREEZEDAYS"` // 冻结天数(T+N)
  25. APPLYREMARK string `json:"applyremark" xorm:"APPLYREMARK"` // 申请备注
  26. RETREMARK string `json:"retremark" xorm:"RETREMARK"` // 返回信息
  27. RETCODE int32 `json:"retcode" xorm:"RETCODE"` // 错误代码
  28. TRADEDATE string `json:"tradedate" xorm:"TRADEDATE"` // 交易日
  29. APPLICANTID int64 `json:"applicantid" xorm:"APPLICANTID"` // 申请人ID
  30. APPLYTIME string `json:"applytime" xorm:"APPLYTIME"` // 申请时间
  31. TRANSFERTYPE int32 `json:"transfertype" xorm:"TRANSFERTYPE"` // 转让类型 - 1.协议转让
  32. TRANSFERAMOUNT float64 `json:"transferamount" xorm:"TRANSFERAMOUNT"` // 转让总金额
  33. GOODSCURPRICE float64 `json:"goodscurprice" xorm:"GOODSCURPRICE"` // 商品实时价格
  34. GOODSCURAMOUNT float64 `json:"goodscuramount" xorm:"GOODSCURAMOUNT"` // 商品实时价金额
  35. OPENFEEALGORITHM int32 `json:"openfeealgorithm" xorm:"OPENFEEALGORITHM"` // 建仓手续费收取方式 1:比率 2:固定
  36. OPENMEMBERCHARGEVALUE float64 `json:"openmemberchargevalue" xorm:"OPENMEMBERCHARGEVALUE"` // 建仓会员手续费设置值
  37. OPENEXCHAGECHARGEVALUE float64 `json:"openexchagechargevalue" xorm:"OPENEXCHAGECHARGEVALUE"` // 建仓交易所手续费设置值
  38. CLOSEFEEALGORITHM int32 `json:"closefeealgorithm" xorm:"CLOSEFEEALGORITHM"` // 平仓手续费收取方式(转出方) 1:比率 2:固定
  39. CLOSEMEMBERCHARGEVALUE float64 `json:"closememberchargevalue" xorm:"CLOSEMEMBERCHARGEVALUE"` // 平仓会员手续费设置值(转出方)
  40. CLOSEEXCHAGECHARGEVALUE float64 `json:"closeexchagechargevalue" xorm:"CLOSEEXCHAGECHARGEVALUE"` // 平仓交易所手续费设置值(转出方)
  41. OUTCHARGE float64 `json:"outcharge" xorm:"OUTCHARGE"` // 转出方手续费
  42. INCHARGE float64 `json:"incharge" xorm:"INCHARGE"` // 转入方手续费
  43. CONFIRMDATE time.Time `json:"confirmdate" xorm:"CONFIRMDATE"` // 确认时间
  44. AUDITORID int64 `json:"auditorid" xorm:"AUDITORID"` // 审核人
  45. AUDITTIME time.Time `json:"audittime" xorm:"AUDITTIME"` // 审核时间
  46. AUDITREMARK string `json:"auditremark" xorm:"AUDITREMARK"` // 审核备注
  47. CLIENTTICKET string `json:"clientticket" xorm:"CLIENTTICKET"` // 客户端流水号
  48. GOODSDISPLAY string `json:"goodsdisplay" xorm:"GOODSDISPLAY"` // 商品名称
  49. OUTUSERNAME string `json:"outusername" xorm:"OUTUSERNAME"` // 转出方
  50. APPLYSTATUS string `json:"applystatus" xorm:"APPLYSTATUS"` // 状态
  51. PageEx `xorm:"extends"` // 页码信息
  52. }
  53. func (r *InTradepositiontransfer) calc() {
  54. }
  55. func (r *InTradepositiontransfer) buildSql() string {
  56. var sqlId utils.SQLVal = `
  57. select
  58. g.goodscode || '/' || g.goodsname as GOODSDISPLAY,
  59. vlogin.LOGINIDS || '/' || ui.customername as OUTUSERNAME,
  60. en.enumdicname as APPLYSTATUS,
  61. to_char(t.applyid) APPLYID,
  62. t.outaccountid,
  63. t.inaccountid,
  64. t.marketid,
  65. t.transferprice,
  66. t.transferapplystatus,
  67. t.freezedays,
  68. t.applyremark,
  69. t.retremark,
  70. t.tradedate,
  71. t.applicantid,
  72. to_char(t.applytime, 'yyyy-mm-dd hh24:mi:ss') APPLYTIME,
  73. t.transfertype,
  74. t.transferamount,
  75. t.goodscuramount,
  76. t.openfeealgorithm,
  77. t.openmemberchargevalue,
  78. t.openexchagechargevalue,
  79. t.closefeealgorithm,
  80. t.closememberchargevalue,
  81. t.closeexchagechargevalue,
  82. t.outcharge,
  83. t.incharge,
  84. t.confirmdate,
  85. t.auditorid,
  86. t.audittime,
  87. t.auditremark
  88. from Trade_PositionTransfer t
  89. left join goods g
  90. on t.goodsid = g.goodsid
  91. left join userinfo ui
  92. on t.outuserid = ui.userid
  93. left join VIEW_USER_LOGINIDS vlogin
  94. on t.outuserid = vlogin.USERID
  95. left join enumdicitem en
  96. on en.enumdiccode = 'transferapplystatus'
  97. and en.enumitemname = t.transferapplystatus
  98. where t.inuserid = %v
  99. and t.transferapplystatus not in (1, 5)
  100. order by t.applytime desc
  101. `
  102. sqlId.FormatParam(r.INUSERID)
  103. sqlId.Page(r.Page, r.PageSize)
  104. return sqlId.String()
  105. }
  106. func (r *InTradepositiontransfer) GetDataByPage() (interface{}, error, int, int, int) {
  107. sData := make([]InTradepositiontransfer, 0)
  108. err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
  109. total := 0
  110. for i := range sData {
  111. sData[i].calc()
  112. total = sData[i].Total
  113. }
  114. return sData, err, r.Page, r.PageSize, total
  115. }
  116. // OutTradepositiontransfer 持仓过户申请表 - 16所有权(中融需求)
  117. type OutTradepositiontransfer struct {
  118. APPLYID string `json:"applyid" xorm:"APPLYID"` // 申请ID(185+Unix秒时间戳(10位)+2位(MarketServiceID)+xxxx)
  119. OUTUSERID int64 `json:"outuserid" xorm:"OUTUSERID" form:"userid" binding:"required"` // 转出方用户ID(申请方)
  120. OUTLOGINID int64 `json:"outloginid" xorm:"OUTLOGINID"` // 转出方登录账号
  121. OUTACCOUNTID int64 `json:"outaccountid" xorm:"OUTACCOUNTID"` // 转出方资金ID(申请方)
  122. INUSERID int64 `json:"inuserid" xorm:"INUSERID"` // 转入方用户ID(确认方)
  123. INACCOUNTID int64 `json:"inaccountid" xorm:"INACCOUNTID"` // 转入方资金ID(确认方)
  124. INLOGINID int64 `json:"inloginid" xorm:"INLOGINID"` // 转入方登录账号
  125. GOODSID int32 `json:"goodsid" xorm:"GOODSID"` // 商品ID
  126. MARKETID int32 `json:"marketid" xorm:"MARKETID"` // 市场ID
  127. BUYORSELL int32 `json:"buyorsell" xorm:"BUYORSELL"` // 买卖 - 0:买 1:卖
  128. QTY int64 `json:"qty" xorm:"QTY"` // 转让数量
  129. TRANSFERPRICE float64 `json:"transferprice" xorm:"TRANSFERPRICE"` // 转让价格
  130. TRANSFERAPPLYSTATUS int32 `json:"transferapplystatus" xorm:"TRANSFERAPPLYSTATUS"` // 过户申请状态 - 1: 待审核 2:待确认 3:确认处理中 4:已确认 5:申请失败 6:系统撤销 7:审核拒绝- 枚举"transferapplystatus"
  131. FREEZEDAYS int64 `json:"freezedays" xorm:"FREEZEDAYS"` // 冻结天数(T+N)
  132. APPLYREMARK string `json:"applyremark" xorm:"APPLYREMARK"` // 申请备注
  133. RETREMARK string `json:"retremark" xorm:"RETREMARK"` // 返回信息
  134. RETCODE int32 `json:"retcode" xorm:"RETCODE"` // 错误代码
  135. TRADEDATE string `json:"tradedate" xorm:"TRADEDATE"` // 交易日
  136. APPLICANTID int64 `json:"applicantid" xorm:"APPLICANTID"` // 申请人ID
  137. APPLYTIME string `json:"applytime" xorm:"APPLYTIME"` // 申请时间
  138. TRANSFERTYPE int32 `json:"transfertype" xorm:"TRANSFERTYPE"` // 转让类型 - 1.协议转让
  139. TRANSFERAMOUNT float64 `json:"transferamount" xorm:"TRANSFERAMOUNT"` // 转让总金额
  140. GOODSCURPRICE float64 `json:"goodscurprice" xorm:"GOODSCURPRICE"` // 商品实时价格
  141. GOODSCURAMOUNT float64 `json:"goodscuramount" xorm:"GOODSCURAMOUNT"` // 商品实时价金额
  142. OPENFEEALGORITHM int32 `json:"openfeealgorithm" xorm:"OPENFEEALGORITHM"` // 建仓手续费收取方式 1:比率 2:固定
  143. OPENMEMBERCHARGEVALUE float64 `json:"openmemberchargevalue" xorm:"OPENMEMBERCHARGEVALUE"` // 建仓会员手续费设置值
  144. OPENEXCHAGECHARGEVALUE float64 `json:"openexchagechargevalue" xorm:"OPENEXCHAGECHARGEVALUE"` // 建仓交易所手续费设置值
  145. CLOSEFEEALGORITHM int32 `json:"closefeealgorithm" xorm:"CLOSEFEEALGORITHM"` // 平仓手续费收取方式(转出方) 1:比率 2:固定
  146. CLOSEMEMBERCHARGEVALUE float64 `json:"closememberchargevalue" xorm:"CLOSEMEMBERCHARGEVALUE"` // 平仓会员手续费设置值(转出方)
  147. CLOSEEXCHAGECHARGEVALUE float64 `json:"closeexchagechargevalue" xorm:"CLOSEEXCHAGECHARGEVALUE"` // 平仓交易所手续费设置值(转出方)
  148. OUTCHARGE float64 `json:"outcharge" xorm:"OUTCHARGE"` // 转出方手续费
  149. INCHARGE float64 `json:"incharge" xorm:"INCHARGE"` // 转入方手续费
  150. CONFIRMDATE time.Time `json:"confirmdate" xorm:"CONFIRMDATE"` // 确认时间
  151. AUDITORID int64 `json:"auditorid" xorm:"AUDITORID"` // 审核人
  152. AUDITTIME time.Time `json:"audittime" xorm:"AUDITTIME"` // 审核时间
  153. AUDITREMARK string `json:"auditremark" xorm:"AUDITREMARK"` // 审核备注
  154. CLIENTTICKET string `json:"clientticket" xorm:"CLIENTTICKET"` // 客户端流水号
  155. GOODSDISPLAY string `json:"goodsdisplay" xorm:"GOODSDISPLAY"` // 商品名称
  156. INUSERNAME string `json:"inusername" xorm:"INUSERNAME"` // 转入方
  157. APPLYSTATUS string `json:"applystatus" xorm:"APPLYSTATUS"` // 状态
  158. PageEx `xorm:"extends"` // 页码信息
  159. }
  160. func (r *OutTradepositiontransfer) calc() {
  161. }
  162. func (r *OutTradepositiontransfer) buildSql() string {
  163. var sqlId utils.SQLVal = `
  164. select
  165. g.goodscode || '/' || g.goodsname as GOODSDISPLAY,
  166. vlogin.LOGINIDS || '/' || ui.customername as INUSERNAME,
  167. en.enumdicname as APPLYSTATUS,
  168. to_char(t.applyid) APPLYID,
  169. t.outuserid,
  170. t.outloginid,
  171. t.outaccountid,
  172. t.inuserid,
  173. t.inaccountid,
  174. t.inloginid,
  175. t.goodsid,
  176. t.marketid,
  177. t.buyorsell,
  178. t.qty,
  179. t.transferprice,
  180. t.transferapplystatus,
  181. t.freezedays,
  182. t.applyremark,
  183. t.retremark,
  184. t.retcode,
  185. t.tradedate,
  186. t.applicantid,
  187. to_char(t.applytime, 'yyyy-mm-dd hh24:mi:ss') APPLYTIME,
  188. t.transfertype,
  189. t.transferamount,
  190. t.goodscurprice,
  191. t.goodscuramount,
  192. t.openfeealgorithm,
  193. t.openmemberchargevalue,
  194. t.openexchagechargevalue,
  195. t.closefeealgorithm,
  196. t.closememberchargevalue,
  197. t.closeexchagechargevalue,
  198. t.outcharge,
  199. t.incharge,
  200. t.confirmdate,
  201. t.auditorid,
  202. t.audittime,
  203. t.auditremark,
  204. t.clientticket
  205. from Trade_PositionTransfer t
  206. left join goods g
  207. on t.goodsid = g.goodsid
  208. left join userinfo ui
  209. on t.inuserid = ui.userid
  210. left join VIEW_USER_LOGINIDS vlogin
  211. on t.inuserid = vlogin.USERID
  212. left join enumdicitem en
  213. on en.enumdiccode = 'transferapplystatus'
  214. and en.enumitemname = t.transferapplystatus
  215. where t.outuserid = %v
  216. order by t.applytime desc
  217. `
  218. sqlId.FormatParam(r.OUTUSERID)
  219. sqlId.Page(r.Page, r.PageSize)
  220. return sqlId.String()
  221. }
  222. func (r *OutTradepositiontransfer) GetDataByPage() (interface{}, error, int, int, int) {
  223. sData := make([]OutTradepositiontransfer, 0)
  224. err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
  225. total := 0
  226. for i := range sData {
  227. sData[i].calc()
  228. total = sData[i].Total
  229. }
  230. return sData, err, r.Page, r.PageSize, total
  231. }
  232. func GetUserInfoByUserIDorMobile(param string) (userinfo *Userinfo, err error) {
  233. // 先尝试加密手机号码,手机号码需要AES加密
  234. mobile := ""
  235. key, _ := hex.DecodeString(utils.AESSecretKey)
  236. if mobileEncrypted, err := utils.AESEncrypt([]byte(param), key); err == nil {
  237. mobile = hex.EncodeToString(mobileEncrypted)
  238. }
  239. userinfos := make([]Userinfo, 0)
  240. sql := fmt.Sprintf(`
  241. SELECT
  242. t.*
  243. FROM userinfo t
  244. INNER JOIN loginaccount l
  245. ON l.userid = t.userid
  246. WHERE l.loginid = %v
  247. `, param)
  248. if mobile != "" {
  249. sql = fmt.Sprintf("%v OR t.mobile = '%v'", sql, mobile)
  250. }
  251. err = db.GetEngine().SQL(sql).Find(&userinfos)
  252. if len(userinfos) > 0 {
  253. userinfo = &userinfos[0]
  254. }
  255. return
  256. }