taaccount.go 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402
  1. package taaccount
  2. import (
  3. "mtp2_if/controllers/order"
  4. "mtp2_if/db"
  5. "mtp2_if/global/app"
  6. "mtp2_if/global/e"
  7. "mtp2_if/logger"
  8. "mtp2_if/models"
  9. "net/http"
  10. "strconv"
  11. "strings"
  12. "github.com/gin-gonic/gin"
  13. )
  14. // GetTaAccountsReq 获取资金账户请求参数
  15. type GetTaAccountsReq struct {
  16. LoginID int `form:"loginID" binding:"required"`
  17. TaAccountType int `form:"taAccountType"`
  18. }
  19. // GetTaAccounts 获取资金账户信息
  20. // @Summary 获取资金账户信息
  21. // @Produce json
  22. // @Security ApiKeyAuth
  23. // @Param loginID query int true "登录账户"
  24. // @Param taAccountType query int false "账号类型 - 1:外部账号 2:内部账号 3:内部做市自营账号 4:内部做市接单账号"
  25. // @Success 200 {object} models.Taaccount
  26. // @Failure 500 {object} app.Response
  27. // @Router /TaAccount/GetTaAccounts [get]
  28. // @Tags 资金账户
  29. func GetTaAccounts(c *gin.Context) {
  30. appG := app.Gin{C: c}
  31. // 获取请求参数
  32. var req GetTaAccountsReq
  33. if err := appG.C.ShouldBindQuery(&req); err != nil {
  34. logger.GetLogger().Errorf("GetTaAccounts failed: %s", err.Error())
  35. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  36. return
  37. }
  38. // 查询数据
  39. taAccounts, err := models.GetTaAccountsByLoginID(req.LoginID, req.TaAccountType)
  40. if err != nil {
  41. // 查询失败
  42. logger.GetLogger().Errorf("GetTaAccounts failed: %s", err.Error())
  43. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  44. return
  45. }
  46. // 如果是母账户,要从对冲外部资金账户表获取资金信息
  47. for i := range taAccounts {
  48. item := &taAccounts[i]
  49. if item.Ismain == 1 {
  50. hedgeOutTaAccount, _ := models.GetHedgeOutTaAccount(int(item.Accountid))
  51. if hedgeOutTaAccount != nil {
  52. item.Balance = hedgeOutTaAccount.Prebalance
  53. item.Currentbalance = hedgeOutTaAccount.Balance
  54. item.Usedmargin = hedgeOutTaAccount.Usedmargin
  55. item.Freezemargin = hedgeOutTaAccount.Freezemargin
  56. item.Freezecharge = hedgeOutTaAccount.Freezecharge
  57. item.Otherfreezemargin = hedgeOutTaAccount.Otherfreezemargin
  58. item.Inamount = hedgeOutTaAccount.Inamount
  59. item.Outamount = hedgeOutTaAccount.Outamount
  60. item.Paycharge = hedgeOutTaAccount.Paycharge
  61. item.Closepl = hedgeOutTaAccount.Closepl
  62. }
  63. }
  64. // 取币种小数位
  65. if item.Currencyid > 0 {
  66. var decimalplace int = 2
  67. currencyEnums, _ := models.GetEnumDicItem("currency", int(item.Currencyid))
  68. if len(currencyEnums) > 0 {
  69. num, err := strconv.Atoi(currencyEnums[0].Param1)
  70. if err == nil {
  71. decimalplace = num
  72. }
  73. }
  74. item.CurrencyDecimalplace = int32(decimalplace)
  75. }
  76. }
  77. if len(taAccounts) > 0 {
  78. // 查融资额
  79. var a models.InStrBuilder
  80. for i := range taAccounts {
  81. a.Add(taAccounts[i].Accountid)
  82. }
  83. mRemainAmount := models.QhjContractRemainAmount{FilterAccId: a.InStr()}
  84. if d, err := mRemainAmount.GetData(); err == nil {
  85. for _, v := range d {
  86. for i := range taAccounts {
  87. if v.ACCOUNTID == taAccounts[i].Accountid {
  88. taAccounts[i].REMAINAMOUNT = v.REMAINACOUNT
  89. }
  90. }
  91. }
  92. }
  93. // 查总市值
  94. if rst, bRet := order.GetTradePosition(a.InStr(), ""); bRet {
  95. for i := range taAccounts {
  96. for _, v := range rst {
  97. if taAccounts[i].Accountid == v.AccountID {
  98. taAccounts[i].CURAMOUNT += v.MarketAmount
  99. }
  100. }
  101. }
  102. }
  103. }
  104. // 查询成功
  105. logger.GetLogger().Debugln("GetTaAccounts successed: %v", taAccounts)
  106. appG.Response(http.StatusOK, e.SUCCESS, taAccounts)
  107. }
  108. // QueryAmountLogReq 资金流水查询(当前)请求参数
  109. type QueryAmountLogReq struct {
  110. app.PageInfo
  111. AccountID string `form:"accountID"` // 资金账户
  112. OperateType string `form:"operateType"` // 资金操作类型
  113. }
  114. // QueryAmountLogRsp 资金流水查询(当前)返回模型
  115. type QueryAmountLogRsp struct {
  116. models.Taaccountlog `xorm:"extends"`
  117. models.TaaccountLogQueryEx `xorm:"extends"` // 扩展字段
  118. }
  119. // QueryAmountLog 资金流水查询(当前)
  120. // @Summary 资金流水查询(当前)
  121. // @Produce json
  122. // @Security ApiKeyAuth
  123. // @Param page query int false "页码"
  124. // @Param pagesize query int false "每页条数"
  125. // @Param pageflag query int false "分页标志 0-page从0开始 1-page从1开始"
  126. // @Param accountID query string true "资金账户 - 格式:1,2,3"
  127. // @Param operateType query string false "资金操作类型 - 格式:1,2,3"
  128. // @Success 200 {object} QueryAmountLogRsp
  129. // @Failure 500 {object} app.Response
  130. // @Router /TaAccount/QueryAmountLog [get]
  131. // @Tags 资金账户
  132. // 参考通用查询:QueryClientAmountLog
  133. func QueryAmountLog(c *gin.Context) {
  134. appG := app.Gin{C: c}
  135. // 获取请求参数
  136. var req QueryAmountLogReq
  137. if err := appG.C.ShouldBindQuery(&req); err != nil {
  138. logger.GetLogger().Errorf("QueryAmountLog failed: %s", err.Error())
  139. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  140. return
  141. }
  142. // 查询数据
  143. datas := make([]QueryAmountLogRsp, 0)
  144. engine := db.GetEngine()
  145. accountIDs := strings.Split(req.AccountID, ",")
  146. // OPERATETYPENAME 显示时,旧的号段用operateType, 新的使用accountBusinessCode
  147. s := engine.Table("TAACCOUNTLOG").
  148. Join("INNER", "ENUMDICITEM", "ENUMDICITEM.ENUMITEMSTATUS = 1 and ENUMDICITEM.ENUMDICCODE = 'accountBusinessCode' and ENUMDICITEM.ENUMITEMNAME = TAACCOUNTLOG.BUSINESSCODE").
  149. Select(`to_char(TAACCOUNTLOG.RELATIONORDERID) as RELATIONORDERID, TAACCOUNTLOG.*,
  150. CASE
  151. WHEN (TAACCOUNTLOG.BUSINESSCODE > 700 AND TAACCOUNTLOG.BUSINESSCODE < 800) OR (TAACCOUNTLOG.BUSINESSCODE > 1900)
  152. THEN 'accountBusinessCode'
  153. ELSE
  154. 'operateType'
  155. END AS CHANGETYPEENUMCODE,
  156. CASE
  157. WHEN (TAACCOUNTLOG.BUSINESSCODE > 700 AND TAACCOUNTLOG.BUSINESSCODE < 800) OR (TAACCOUNTLOG.BUSINESSCODE > 1900)
  158. THEN TAACCOUNTLOG.BUSINESSCODE
  159. ELSE
  160. TAACCOUNTLOG.OPERATETYPE
  161. END AS CHANGETYPEENUMVALUE
  162. `).
  163. Where("TAACCOUNTLOG.AMOUNT <> 0").
  164. In("TAACCOUNTLOG.ACCOUNTID", accountIDs).
  165. Desc("TAACCOUNTLOG.AUTOID")
  166. if len(req.OperateType) > 0 {
  167. // s = s.And(fmt.Sprintf("TAACCOUNTLOG.OPERATETYPE in (%s)", req.OperateType))
  168. operateTypes := strings.Split(req.OperateType, ",")
  169. s = s.In("TAACCOUNTLOG.OPERATETYPE", operateTypes)
  170. }
  171. if err := s.Find(&datas); err != nil {
  172. // 查询失败
  173. logger.GetLogger().Errorf("QueryAmountLog failed: %s", err.Error())
  174. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  175. return
  176. }
  177. // 查询成功返回
  178. if req.PageSize > 0 {
  179. // 分页
  180. var rst []QueryAmountLogRsp
  181. // 开始上标
  182. // 终端分页1开始
  183. p := req.Page
  184. if req.PageFlag != 0 {
  185. p -= 1
  186. if p < 0 {
  187. p = 0
  188. }
  189. }
  190. start := p * req.PageSize
  191. // 结束下标
  192. end := start + req.PageSize
  193. if start <= len(datas) {
  194. // 判断结束下标是否越界
  195. if end > len(datas) {
  196. end = len(datas)
  197. }
  198. rst = datas[start:end]
  199. } else {
  200. rst = datas[0:0]
  201. }
  202. logger.GetLogger().Debugln("QueryAmountLog successed: %v", rst)
  203. appG.ResponseByPage(http.StatusOK, e.SUCCESS, rst, app.PageInfo{Page: req.Page, PageSize: req.PageSize, Total: len(datas)})
  204. } else {
  205. // 不分页
  206. logger.GetLogger().Debugln("QueryAmountLog successed: %v", datas)
  207. appG.Response(http.StatusOK, e.SUCCESS, datas)
  208. }
  209. }
  210. // QueryHisAmountLogReq 资金流水查询(历史)请求参数
  211. type QueryHisAmountLogReq struct {
  212. app.PageInfo
  213. AccountID string `form:"accountID"` // 资金账户
  214. OperateType string `form:"operateType"` // 资金操作类型
  215. StartDate string `form:"startDate"` // 开始时间
  216. EndDate string `form:"endDate"` // 结束时间
  217. }
  218. // QueryHisAmountLogRsp 资金流水查询(历史)返回模型
  219. type QueryHisAmountLogRsp struct {
  220. models.Histaaccountlog `xorm:"extends"`
  221. models.TaaccountLogQueryEx `xorm:"extends"` // 扩展字段
  222. }
  223. // QueryHisAmountLog 资金流水查询(历史)
  224. // @Summary 资金流水查询(历史)
  225. // @Produce json
  226. // @Security ApiKeyAuth
  227. // @Param page query int false "页码"
  228. // @Param pagesize query int false "每页条数"
  229. // @Param pageflag query int false "分页标志 0-page从0开始 1-page从1开始"
  230. // @Param accountID query string true "资金账户 - 格式:1,2,3"
  231. // @Param operateType query string false "资金操作类型 - 格式:1,2,3"
  232. // @Param startDate query string false "开始时间 - 闭区间,格式:yyyy-MM-dd"
  233. // @Param endDate query string false "结束时间 - 闭区间,格式:yyyy-MM-dd"
  234. // @Success 200 {object} QueryHisAmountLogRsp
  235. // @Failure 500 {object} app.Response
  236. // @Router /TaAccount/QueryHisAmountLog [get]
  237. // @Tags 资金账户
  238. // 参考通用查询:Client_QueryHis_taaccountlog
  239. func QueryHisAmountLog(c *gin.Context) {
  240. appG := app.Gin{C: c}
  241. // 获取请求参数
  242. var req QueryHisAmountLogReq
  243. if err := appG.C.ShouldBindQuery(&req); err != nil {
  244. logger.GetLogger().Errorf("QueryHisAmountLog failed: %s", err.Error())
  245. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  246. return
  247. }
  248. // 查询数据
  249. datas := make([]QueryHisAmountLogRsp, 0)
  250. engine := db.GetEngine()
  251. // OPERATETYPENAME 显示时,旧的号段用operateType, 新的使用accountBusinessCode
  252. s := engine.Table("HIS_TAACCOUNTLOG").
  253. Join("INNER", "ENUMDICITEM", "ENUMDICITEM.ENUMITEMSTATUS = 1 and ENUMDICITEM.ENUMDICCODE = 'accountBusinessCode' and ENUMDICITEM.ENUMITEMNAME = HIS_TAACCOUNTLOG.BUSINESSCODE").
  254. Select(`to_char(HIS_TAACCOUNTLOG.RELATIONORDERID) as RELATIONORDERID, HIS_TAACCOUNTLOG.*,
  255. CASE
  256. WHEN (HIS_TAACCOUNTLOG.BUSINESSCODE > 700 AND HIS_TAACCOUNTLOG.BUSINESSCODE < 800) OR (HIS_TAACCOUNTLOG.BUSINESSCODE > 1900)
  257. THEN 'accountBusinessCode'
  258. ELSE
  259. 'operateType'
  260. END AS CHANGETYPEENUMCODE,
  261. CASE
  262. WHEN (HIS_TAACCOUNTLOG.BUSINESSCODE > 700 AND HIS_TAACCOUNTLOG.BUSINESSCODE < 800) OR (HIS_TAACCOUNTLOG.BUSINESSCODE > 1900)
  263. THEN HIS_TAACCOUNTLOG.BUSINESSCODE
  264. ELSE
  265. HIS_TAACCOUNTLOG.OPERATETYPE
  266. END AS CHANGETYPEENUMVALUE
  267. `).
  268. Where("HIS_TAACCOUNTLOG.ISVALIDDATA = 1 and HIS_TAACCOUNTLOG.AMOUNT <> 0").
  269. In("HIS_TAACCOUNTLOG.ACCOUNTID", strings.Split(req.AccountID, ",")).
  270. Desc("HIS_TAACCOUNTLOG.AUTOID")
  271. if len(req.OperateType) > 0 {
  272. s = s.In("HIS_TAACCOUNTLOG.OPERATETYPE", strings.Split(req.OperateType, ","))
  273. }
  274. if len(req.StartDate) > 0 {
  275. // s = s.And("to_date(HIS_TAACCOUNTLOG.HISTRADEDATE,'yyyyMMdd') >= to_date(?,'yyyy-MM-dd')", req.StartDate)
  276. s = s.And("HIS_TAACCOUNTLOG.HISTRADEDATE >= ?", strings.Replace(req.StartDate, "-", "", -1))
  277. }
  278. if len(req.EndDate) > 0 {
  279. // s = s.And("to_date(HIS_TAACCOUNTLOG.HISTRADEDATE,'yyyyMMdd') <= to_date(?,'yyyy-MM-dd')", req.EndDate)
  280. s = s.And("HIS_TAACCOUNTLOG.HISTRADEDATE <= ?", strings.Replace(req.EndDate, "-", "", -1))
  281. }
  282. if err := s.Find(&datas); err != nil {
  283. // 查询失败
  284. logger.GetLogger().Errorf("QueryHisAmountLog failed: %s", err.Error())
  285. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  286. return
  287. }
  288. // 查询成功返回
  289. if req.PageSize > 0 {
  290. // 分页
  291. var rst []QueryHisAmountLogRsp
  292. // 开始上标
  293. // 终端分页1开始
  294. p := req.Page
  295. if req.PageFlag != 0 {
  296. p -= 1
  297. if p < 0 {
  298. p = 0
  299. }
  300. }
  301. start := p * req.PageSize
  302. // 结束下标
  303. end := start + req.PageSize
  304. if start <= len(datas) {
  305. // 判断结束下标是否越界
  306. if end > len(datas) {
  307. end = len(datas)
  308. }
  309. rst = datas[start:end]
  310. } else {
  311. rst = datas[0:0]
  312. }
  313. logger.GetLogger().Debugln("QueryHisAmountLog successed: %v", rst)
  314. appG.ResponseByPage(http.StatusOK, e.SUCCESS, rst, app.PageInfo{Page: req.Page, PageSize: req.PageSize, Total: len(datas)})
  315. } else {
  316. // 不分页
  317. logger.GetLogger().Debugln("QueryHisAmountLog successed: %v", datas)
  318. appG.Response(http.StatusOK, e.SUCCESS, datas)
  319. }
  320. }
  321. // QueryRelatedTaAccount
  322. // @Summary 查询关联资金账户信息
  323. // @Produce json
  324. // @Security ApiKeyAuth
  325. // @Param relateduserid query int true "关联UserID"
  326. // @Success 200 {array} models.RelatedTaAccount
  327. // @Failure 500 {object} app.Response
  328. // @Router /TaAccount/QueryRelatedTaAccount [get]
  329. // @Tags 资金账户
  330. func QueryRelatedTaAccount(c *gin.Context) {
  331. a := app.GinUtils{Gin: app.Gin{C: c}}
  332. m := models.RelatedTaAccount{}
  333. a.DoBindReq(&m)
  334. a.DoGetDataI(&m)
  335. }
  336. // GetGtwithholdsigninfo
  337. // @Summary 获取代扣签约信息表
  338. // @Produce json
  339. // @Param userid query int true "用户ID"
  340. // @Success 200 {array} models.Gtwithholdsigninfo
  341. // @Failure 500 {object} app.Response
  342. // @Router /TaAccount/GetGtwithholdsigninfo [get]
  343. // @Tags 资金账户
  344. func GetGtwithholdsigninfo(c *gin.Context) {
  345. a := app.GinUtils{Gin: app.Gin{C: c}}
  346. m := models.Gtwithholdsigninfo{}
  347. a.DoBindReq(&m)
  348. a.DoGetDataEx(&m)
  349. }
  350. // QueryTHJFriends
  351. // @Summary 查询代扣入金申请表
  352. // @Produce json
  353. // @Security ApiKeyAuth
  354. // @Param userid query int true "用户ID"
  355. // @Param begindate query string false "开始交易日(yyyymmdd)"
  356. // @Param enddate query string false "结束交易日(yyyymmdd)"
  357. // @Param billresult query int false "批扣结果 - 0-扣费成功、1-扣费失败"
  358. // @Param page query int false "页码"
  359. // @Param pagesize query int false "每页条数"
  360. // @Success 200 {array} models.Gtwithholddepositapply
  361. // @Failure 500 {object} app.Response
  362. // @Router /TaAccount/QueryGtwithholddepositapply [get]
  363. // @Tags 资金账户
  364. func QueryGtwithholddepositapply(c *gin.Context) {
  365. a := app.GinUtils{Gin: app.Gin{C: c}}
  366. m := models.Gtwithholddepositapply{}
  367. a.DoBindReq(&m)
  368. a.DoGetDataByPage(&m)
  369. }