| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402 |
- package taaccount
- import (
- "mtp2_if/controllers/order"
- "mtp2_if/db"
- "mtp2_if/global/app"
- "mtp2_if/global/e"
- "mtp2_if/logger"
- "mtp2_if/models"
- "net/http"
- "strconv"
- "strings"
- "github.com/gin-gonic/gin"
- )
- // GetTaAccountsReq 获取资金账户请求参数
- type GetTaAccountsReq struct {
- LoginID int `form:"loginID" binding:"required"`
- TaAccountType int `form:"taAccountType"`
- }
- // GetTaAccounts 获取资金账户信息
- // @Summary 获取资金账户信息
- // @Produce json
- // @Security ApiKeyAuth
- // @Param loginID query int true "登录账户"
- // @Param taAccountType query int false "账号类型 - 1:外部账号 2:内部账号 3:内部做市自营账号 4:内部做市接单账号"
- // @Success 200 {object} models.Taaccount
- // @Failure 500 {object} app.Response
- // @Router /TaAccount/GetTaAccounts [get]
- // @Tags 资金账户
- func GetTaAccounts(c *gin.Context) {
- appG := app.Gin{C: c}
- // 获取请求参数
- var req GetTaAccountsReq
- if err := appG.C.ShouldBindQuery(&req); err != nil {
- logger.GetLogger().Errorf("GetTaAccounts failed: %s", err.Error())
- appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
- return
- }
- // 查询数据
- taAccounts, err := models.GetTaAccountsByLoginID(req.LoginID, req.TaAccountType)
- if err != nil {
- // 查询失败
- logger.GetLogger().Errorf("GetTaAccounts failed: %s", err.Error())
- appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
- return
- }
- // 如果是母账户,要从对冲外部资金账户表获取资金信息
- for i := range taAccounts {
- item := &taAccounts[i]
- if item.Ismain == 1 {
- hedgeOutTaAccount, _ := models.GetHedgeOutTaAccount(int(item.Accountid))
- if hedgeOutTaAccount != nil {
- item.Balance = hedgeOutTaAccount.Prebalance
- item.Currentbalance = hedgeOutTaAccount.Balance
- item.Usedmargin = hedgeOutTaAccount.Usedmargin
- item.Freezemargin = hedgeOutTaAccount.Freezemargin
- item.Freezecharge = hedgeOutTaAccount.Freezecharge
- item.Otherfreezemargin = hedgeOutTaAccount.Otherfreezemargin
- item.Inamount = hedgeOutTaAccount.Inamount
- item.Outamount = hedgeOutTaAccount.Outamount
- item.Paycharge = hedgeOutTaAccount.Paycharge
- item.Closepl = hedgeOutTaAccount.Closepl
- }
- }
- // 取币种小数位
- if item.Currencyid > 0 {
- var decimalplace int = 2
- currencyEnums, _ := models.GetEnumDicItem("currency", int(item.Currencyid))
- if len(currencyEnums) > 0 {
- num, err := strconv.Atoi(currencyEnums[0].Param1)
- if err == nil {
- decimalplace = num
- }
- }
- item.CurrencyDecimalplace = int32(decimalplace)
- }
- }
- if len(taAccounts) > 0 {
- // 查融资额
- var a models.InStrBuilder
- for i := range taAccounts {
- a.Add(taAccounts[i].Accountid)
- }
- mRemainAmount := models.QhjContractRemainAmount{FilterAccId: a.InStr()}
- if d, err := mRemainAmount.GetData(); err == nil {
- for _, v := range d {
- for i := range taAccounts {
- if v.ACCOUNTID == taAccounts[i].Accountid {
- taAccounts[i].REMAINAMOUNT = v.REMAINACOUNT
- }
- }
- }
- }
- // 查总市值
- if rst, bRet := order.GetTradePosition(a.InStr(), ""); bRet {
- for i := range taAccounts {
- for _, v := range rst {
- if taAccounts[i].Accountid == v.AccountID {
- taAccounts[i].CURAMOUNT += v.MarketAmount
- }
- }
- }
- }
- }
- // 查询成功
- logger.GetLogger().Debugln("GetTaAccounts successed: %v", taAccounts)
- appG.Response(http.StatusOK, e.SUCCESS, taAccounts)
- }
- // QueryAmountLogReq 资金流水查询(当前)请求参数
- type QueryAmountLogReq struct {
- app.PageInfo
- AccountID string `form:"accountID"` // 资金账户
- OperateType string `form:"operateType"` // 资金操作类型
- }
- // QueryAmountLogRsp 资金流水查询(当前)返回模型
- type QueryAmountLogRsp struct {
- models.Taaccountlog `xorm:"extends"`
- models.TaaccountLogQueryEx `xorm:"extends"` // 扩展字段
- }
- // QueryAmountLog 资金流水查询(当前)
- // @Summary 资金流水查询(当前)
- // @Produce json
- // @Security ApiKeyAuth
- // @Param page query int false "页码"
- // @Param pagesize query int false "每页条数"
- // @Param pageflag query int false "分页标志 0-page从0开始 1-page从1开始"
- // @Param accountID query string true "资金账户 - 格式:1,2,3"
- // @Param operateType query string false "资金操作类型 - 格式:1,2,3"
- // @Success 200 {object} QueryAmountLogRsp
- // @Failure 500 {object} app.Response
- // @Router /TaAccount/QueryAmountLog [get]
- // @Tags 资金账户
- // 参考通用查询:QueryClientAmountLog
- func QueryAmountLog(c *gin.Context) {
- appG := app.Gin{C: c}
- // 获取请求参数
- var req QueryAmountLogReq
- if err := appG.C.ShouldBindQuery(&req); err != nil {
- logger.GetLogger().Errorf("QueryAmountLog failed: %s", err.Error())
- appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
- return
- }
- // 查询数据
- datas := make([]QueryAmountLogRsp, 0)
- engine := db.GetEngine()
- accountIDs := strings.Split(req.AccountID, ",")
- // OPERATETYPENAME 显示时,旧的号段用operateType, 新的使用accountBusinessCode
- s := engine.Table("TAACCOUNTLOG").
- Join("INNER", "ENUMDICITEM", "ENUMDICITEM.ENUMITEMSTATUS = 1 and ENUMDICITEM.ENUMDICCODE = 'accountBusinessCode' and ENUMDICITEM.ENUMITEMNAME = TAACCOUNTLOG.BUSINESSCODE").
- Select(`to_char(TAACCOUNTLOG.RELATIONORDERID) as RELATIONORDERID, TAACCOUNTLOG.*,
- CASE
- WHEN (TAACCOUNTLOG.BUSINESSCODE > 700 AND TAACCOUNTLOG.BUSINESSCODE < 800) OR (TAACCOUNTLOG.BUSINESSCODE > 1900)
- THEN 'accountBusinessCode'
- ELSE
- 'operateType'
- END AS CHANGETYPEENUMCODE,
- CASE
- WHEN (TAACCOUNTLOG.BUSINESSCODE > 700 AND TAACCOUNTLOG.BUSINESSCODE < 800) OR (TAACCOUNTLOG.BUSINESSCODE > 1900)
- THEN TAACCOUNTLOG.BUSINESSCODE
- ELSE
- TAACCOUNTLOG.OPERATETYPE
- END AS CHANGETYPEENUMVALUE
- `).
- Where("TAACCOUNTLOG.AMOUNT <> 0").
- In("TAACCOUNTLOG.ACCOUNTID", accountIDs).
- Desc("TAACCOUNTLOG.AUTOID")
- if len(req.OperateType) > 0 {
- // s = s.And(fmt.Sprintf("TAACCOUNTLOG.OPERATETYPE in (%s)", req.OperateType))
- operateTypes := strings.Split(req.OperateType, ",")
- s = s.In("TAACCOUNTLOG.OPERATETYPE", operateTypes)
- }
- if err := s.Find(&datas); err != nil {
- // 查询失败
- logger.GetLogger().Errorf("QueryAmountLog failed: %s", err.Error())
- appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
- return
- }
- // 查询成功返回
- if req.PageSize > 0 {
- // 分页
- var rst []QueryAmountLogRsp
- // 开始上标
- // 终端分页1开始
- p := req.Page
- if req.PageFlag != 0 {
- p -= 1
- if p < 0 {
- p = 0
- }
- }
- start := p * req.PageSize
- // 结束下标
- end := start + req.PageSize
- if start <= len(datas) {
- // 判断结束下标是否越界
- if end > len(datas) {
- end = len(datas)
- }
- rst = datas[start:end]
- } else {
- rst = datas[0:0]
- }
- logger.GetLogger().Debugln("QueryAmountLog successed: %v", rst)
- appG.ResponseByPage(http.StatusOK, e.SUCCESS, rst, app.PageInfo{Page: req.Page, PageSize: req.PageSize, Total: len(datas)})
- } else {
- // 不分页
- logger.GetLogger().Debugln("QueryAmountLog successed: %v", datas)
- appG.Response(http.StatusOK, e.SUCCESS, datas)
- }
- }
- // QueryHisAmountLogReq 资金流水查询(历史)请求参数
- type QueryHisAmountLogReq struct {
- app.PageInfo
- AccountID string `form:"accountID"` // 资金账户
- OperateType string `form:"operateType"` // 资金操作类型
- StartDate string `form:"startDate"` // 开始时间
- EndDate string `form:"endDate"` // 结束时间
- }
- // QueryHisAmountLogRsp 资金流水查询(历史)返回模型
- type QueryHisAmountLogRsp struct {
- models.Histaaccountlog `xorm:"extends"`
- models.TaaccountLogQueryEx `xorm:"extends"` // 扩展字段
- }
- // QueryHisAmountLog 资金流水查询(历史)
- // @Summary 资金流水查询(历史)
- // @Produce json
- // @Security ApiKeyAuth
- // @Param page query int false "页码"
- // @Param pagesize query int false "每页条数"
- // @Param pageflag query int false "分页标志 0-page从0开始 1-page从1开始"
- // @Param accountID query string true "资金账户 - 格式:1,2,3"
- // @Param operateType query string false "资金操作类型 - 格式:1,2,3"
- // @Param startDate query string false "开始时间 - 闭区间,格式:yyyy-MM-dd"
- // @Param endDate query string false "结束时间 - 闭区间,格式:yyyy-MM-dd"
- // @Success 200 {object} QueryHisAmountLogRsp
- // @Failure 500 {object} app.Response
- // @Router /TaAccount/QueryHisAmountLog [get]
- // @Tags 资金账户
- // 参考通用查询:Client_QueryHis_taaccountlog
- func QueryHisAmountLog(c *gin.Context) {
- appG := app.Gin{C: c}
- // 获取请求参数
- var req QueryHisAmountLogReq
- if err := appG.C.ShouldBindQuery(&req); err != nil {
- logger.GetLogger().Errorf("QueryHisAmountLog failed: %s", err.Error())
- appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
- return
- }
- // 查询数据
- datas := make([]QueryHisAmountLogRsp, 0)
- engine := db.GetEngine()
- // OPERATETYPENAME 显示时,旧的号段用operateType, 新的使用accountBusinessCode
- s := engine.Table("HIS_TAACCOUNTLOG").
- Join("INNER", "ENUMDICITEM", "ENUMDICITEM.ENUMITEMSTATUS = 1 and ENUMDICITEM.ENUMDICCODE = 'accountBusinessCode' and ENUMDICITEM.ENUMITEMNAME = HIS_TAACCOUNTLOG.BUSINESSCODE").
- Select(`to_char(HIS_TAACCOUNTLOG.RELATIONORDERID) as RELATIONORDERID, HIS_TAACCOUNTLOG.*,
- CASE
- WHEN (HIS_TAACCOUNTLOG.BUSINESSCODE > 700 AND HIS_TAACCOUNTLOG.BUSINESSCODE < 800) OR (HIS_TAACCOUNTLOG.BUSINESSCODE > 1900)
- THEN 'accountBusinessCode'
- ELSE
- 'operateType'
- END AS CHANGETYPEENUMCODE,
- CASE
- WHEN (HIS_TAACCOUNTLOG.BUSINESSCODE > 700 AND HIS_TAACCOUNTLOG.BUSINESSCODE < 800) OR (HIS_TAACCOUNTLOG.BUSINESSCODE > 1900)
- THEN HIS_TAACCOUNTLOG.BUSINESSCODE
- ELSE
- HIS_TAACCOUNTLOG.OPERATETYPE
- END AS CHANGETYPEENUMVALUE
- `).
- Where("HIS_TAACCOUNTLOG.ISVALIDDATA = 1 and HIS_TAACCOUNTLOG.AMOUNT <> 0").
- In("HIS_TAACCOUNTLOG.ACCOUNTID", strings.Split(req.AccountID, ",")).
- Desc("HIS_TAACCOUNTLOG.AUTOID")
- if len(req.OperateType) > 0 {
- s = s.In("HIS_TAACCOUNTLOG.OPERATETYPE", strings.Split(req.OperateType, ","))
- }
- if len(req.StartDate) > 0 {
- // s = s.And("to_date(HIS_TAACCOUNTLOG.HISTRADEDATE,'yyyyMMdd') >= to_date(?,'yyyy-MM-dd')", req.StartDate)
- s = s.And("HIS_TAACCOUNTLOG.HISTRADEDATE >= ?", strings.Replace(req.StartDate, "-", "", -1))
- }
- if len(req.EndDate) > 0 {
- // s = s.And("to_date(HIS_TAACCOUNTLOG.HISTRADEDATE,'yyyyMMdd') <= to_date(?,'yyyy-MM-dd')", req.EndDate)
- s = s.And("HIS_TAACCOUNTLOG.HISTRADEDATE <= ?", strings.Replace(req.EndDate, "-", "", -1))
- }
- if err := s.Find(&datas); err != nil {
- // 查询失败
- logger.GetLogger().Errorf("QueryHisAmountLog failed: %s", err.Error())
- appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
- return
- }
- // 查询成功返回
- if req.PageSize > 0 {
- // 分页
- var rst []QueryHisAmountLogRsp
- // 开始上标
- // 终端分页1开始
- p := req.Page
- if req.PageFlag != 0 {
- p -= 1
- if p < 0 {
- p = 0
- }
- }
- start := p * req.PageSize
- // 结束下标
- end := start + req.PageSize
- if start <= len(datas) {
- // 判断结束下标是否越界
- if end > len(datas) {
- end = len(datas)
- }
- rst = datas[start:end]
- } else {
- rst = datas[0:0]
- }
- logger.GetLogger().Debugln("QueryHisAmountLog successed: %v", rst)
- appG.ResponseByPage(http.StatusOK, e.SUCCESS, rst, app.PageInfo{Page: req.Page, PageSize: req.PageSize, Total: len(datas)})
- } else {
- // 不分页
- logger.GetLogger().Debugln("QueryHisAmountLog successed: %v", datas)
- appG.Response(http.StatusOK, e.SUCCESS, datas)
- }
- }
- // QueryRelatedTaAccount
- // @Summary 查询关联资金账户信息
- // @Produce json
- // @Security ApiKeyAuth
- // @Param relateduserid query int true "关联UserID"
- // @Success 200 {array} models.RelatedTaAccount
- // @Failure 500 {object} app.Response
- // @Router /TaAccount/QueryRelatedTaAccount [get]
- // @Tags 资金账户
- func QueryRelatedTaAccount(c *gin.Context) {
- a := app.GinUtils{Gin: app.Gin{C: c}}
- m := models.RelatedTaAccount{}
- a.DoBindReq(&m)
- a.DoGetDataI(&m)
- }
- // GetGtwithholdsigninfo
- // @Summary 获取代扣签约信息表
- // @Produce json
- // @Param userid query int true "用户ID"
- // @Success 200 {array} models.Gtwithholdsigninfo
- // @Failure 500 {object} app.Response
- // @Router /TaAccount/GetGtwithholdsigninfo [get]
- // @Tags 资金账户
- func GetGtwithholdsigninfo(c *gin.Context) {
- a := app.GinUtils{Gin: app.Gin{C: c}}
- m := models.Gtwithholdsigninfo{}
- a.DoBindReq(&m)
- a.DoGetDataEx(&m)
- }
- // QueryTHJFriends
- // @Summary 查询代扣入金申请表
- // @Produce json
- // @Security ApiKeyAuth
- // @Param userid query int true "用户ID"
- // @Param begindate query string false "开始交易日(yyyymmdd)"
- // @Param enddate query string false "结束交易日(yyyymmdd)"
- // @Param billresult query int false "批扣结果 - 0-扣费成功、1-扣费失败"
- // @Param page query int false "页码"
- // @Param pagesize query int false "每页条数"
- // @Success 200 {array} models.Gtwithholddepositapply
- // @Failure 500 {object} app.Response
- // @Router /TaAccount/QueryGtwithholddepositapply [get]
- // @Tags 资金账户
- func QueryGtwithholddepositapply(c *gin.Context) {
- a := app.GinUtils{Gin: app.Gin{C: c}}
- m := models.Gtwithholddepositapply{}
- a.DoBindReq(&m)
- a.DoGetDataByPage(&m)
- }
|