htfutures_account_controller.go 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. package web_hook
  2. import (
  3. logger "eta/eta_mini_ht_api/common/component/log"
  4. "eta/eta_mini_ht_api/common/exception"
  5. "eta/eta_mini_ht_api/controllers"
  6. userService "eta/eta_mini_ht_api/domian/user"
  7. )
  8. type HTFuturesAccountController struct {
  9. controllers.WebHookController
  10. }
  11. type Risk struct{}
  12. // SyncCustomerRiskLevel 风险测评同步接口
  13. // @Summary 风险测评同步接口
  14. // @Description 风险测评同步接口
  15. // @Success 200 {object} controllers.BaseResponse
  16. // @router /v1/syncRiskLevel/ [post]
  17. func (h *HTFuturesAccountController) SyncCustomerRiskLevel() {
  18. controllers.WrapWebhook(&h.WebHookController, func() (result *controllers.WrapData, err error) {
  19. result = h.InitWrapData("同步风险等级")
  20. syncCustomerRiskLevelReq := new(SyncCustomerRiskLevelReq)
  21. h.GetPostParams(syncCustomerRiskLevelReq)
  22. custInfo := syncCustomerRiskLevelReq.CustInfo
  23. riskInfo := syncCustomerRiskLevelReq.RiskInfo
  24. if custInfo.ClientName == "" {
  25. err = exception.New(exception.SyncRiskError)
  26. h.FailedResult("用户名字不能为空", result)
  27. return
  28. }
  29. if custInfo.MobileTel == "" {
  30. err = exception.New(exception.SyncRiskError)
  31. h.FailedResult("手机号码不能为空", result)
  32. return
  33. }
  34. if custInfo.IdNo == "" {
  35. err = exception.New(exception.SyncRiskError)
  36. h.FailedResult("身份证号不能为空", result)
  37. return
  38. }
  39. //if !utils.IsValidIDCard(custInfo.IdNo) && !utils.IsValidOldIDCard(custInfo.IdNo) {
  40. // err = exception.New(exception.SyncRiskError)
  41. // h.FailedResult("身份证号不合法", result)
  42. // return
  43. //}
  44. if riskInfo.CorpRiskLevel == "" {
  45. err = exception.New(exception.SyncRiskError)
  46. h.FailedResult("风险等级不能为空", result)
  47. return
  48. }
  49. if riskInfo.CorpEndDate == "" {
  50. err = exception.New(exception.SyncRiskError)
  51. h.FailedResult("风险测评有效结束日期不能为空", result)
  52. return
  53. }
  54. err = userService.UpdateRiskLevelInfo(userService.RiskLevelInfoDTO{
  55. Name: custInfo.ClientName,
  56. PhoneNumber: custInfo.MobileTel,
  57. RiskLevel: riskInfo.CorpRiskLevel,
  58. RiskValidEndDate: riskInfo.CorpEndDate,
  59. })
  60. if err != nil {
  61. logger.ErrorWithTraceId(h.Ctx, err.Error())
  62. h.FailedResult(err.Error(), result)
  63. err = exception.New(exception.SyncRiskError)
  64. return
  65. }
  66. logger.InfoWithTraceId(h.Ctx, err.Error())
  67. result = h.InitWrapData("同步风险等级成功")
  68. h.SuccessResult("success", syncCustomerRiskLevelReq, result)
  69. return
  70. })
  71. }
  72. // SyncCustomerAccountInfo 开户信息同步接口
  73. // @Summary 开户信息同步接口
  74. // @Description 开户信息同步接口
  75. // @Success 200 {object} controllers.BaseResponse
  76. // @router /v1/syncAccountInfo/ [post]
  77. func (h *HTFuturesAccountController) SyncCustomerAccountInfo() {
  78. controllers.WrapWebhook(&h.WebHookController, func() (result *controllers.WrapData, err error) {
  79. result = h.InitWrapData("同步风险等级")
  80. syncCustomerRiskLevelReq := new(SyncCustomerRiskLevelReq)
  81. h.GetPostParams(syncCustomerRiskLevelReq)
  82. custInfo := syncCustomerRiskLevelReq.CustInfo
  83. riskInfo := syncCustomerRiskLevelReq.RiskInfo
  84. if custInfo.ClientName == "" {
  85. err = exception.New(exception.SyncRiskError)
  86. h.FailedResult("用户名字不能为空", result)
  87. return
  88. }
  89. if custInfo.MobileTel == "" {
  90. err = exception.New(exception.SyncRiskError)
  91. h.FailedResult("手机号码不能为空", result)
  92. return
  93. }
  94. if custInfo.IdNo == "" {
  95. err = exception.New(exception.SyncRiskError)
  96. h.FailedResult("身份证号不能为空", result)
  97. return
  98. }
  99. //if !utils.IsValidIDCard(custInfo.IdNo) && !utils.IsValidOldIDCard(custInfo.IdNo) {
  100. // err = exception.New(exception.SyncRiskError)
  101. // h.FailedResult("身份证号不合法", result)
  102. // return
  103. //}
  104. if riskInfo.CorpRiskLevel == "" {
  105. err = exception.New(exception.SyncRiskError)
  106. h.FailedResult("风险等级不能为空", result)
  107. return
  108. }
  109. if riskInfo.CorpEndDate == "" {
  110. err = exception.New(exception.SyncRiskError)
  111. h.FailedResult("风险测评有效结束日期不能为空", result)
  112. return
  113. }
  114. err = userService.UpdateRiskLevelInfo(userService.RiskLevelInfoDTO{
  115. Name: custInfo.ClientName,
  116. PhoneNumber: custInfo.MobileTel,
  117. RiskLevel: riskInfo.CorpRiskLevel,
  118. RiskValidEndDate: riskInfo.CorpEndDate,
  119. })
  120. if err != nil {
  121. logger.ErrorWithTraceId(h.Ctx, err.Error())
  122. h.FailedResult(err.Error(), result)
  123. err = exception.New(exception.SyncRiskError)
  124. return
  125. }
  126. logger.InfoWithTraceId(h.Ctx, err.Error())
  127. result = h.InitWrapData("同步风险等级成功")
  128. h.SuccessResult("success", syncCustomerRiskLevelReq, result)
  129. return
  130. })
  131. }
  132. type SyncCustomerRiskLevelReq struct {
  133. CustInfo CustInfo `json:"custInfo"`
  134. RiskInfo RiskInfo `json:"riskInfo"`
  135. }
  136. type CustInfo struct {
  137. MobileTel string `json:"mobile_tel"`
  138. ClientName string `json:"client_name"`
  139. IdKind string `json:"id_kind"`
  140. IdNo string `json:"id_no"`
  141. }
  142. type RiskInfo struct {
  143. CorpBeginDate string `json:"corp_begin_date"`
  144. CorpEndDate string `json:"corp_end_date"`
  145. UserInvestTerm string `json:"user_invest_term"`
  146. UserInvestKind string `json:"user_invest_kind"`
  147. CorpRiskLevel string `json:"corp_risk_level"`
  148. }
  149. type SyncCustomerAccountInfoReq struct {
  150. CustInfo CustInfo `json:"custInfo"`
  151. RiskInfo RiskInfo `json:"riskInfo"`
  152. }