htfutures_account_controller.go 5.2 KB

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