htfutures_account_controller.go 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. type SyncCustomerRiskLevelReq struct {
  73. CustInfo CustInfo `json:"custInfo"`
  74. RiskInfo RiskInfo `json:"riskInfo"`
  75. }
  76. type CustInfo struct {
  77. MobileTel string `json:"mobile_tel"`
  78. ClientName string `json:"client_name"`
  79. IdKind string `json:"id_kind"`
  80. IdNo string `json:"id_no"`
  81. }
  82. type RiskInfo struct {
  83. CorpBeginDate string `json:"corp_begin_date"`
  84. CorpEndDate string `json:"corp_end_date"`
  85. UserInvestTerm string `json:"user_invest_term"`
  86. UserInvestKind string `json:"user_invest_kind"`
  87. CorpRiskLevel string `json:"corp_risk_level"`
  88. }