htfutures_account_controller.go 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  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. "fmt"
  8. "time"
  9. )
  10. type HTFuturesAccountController struct {
  11. controllers.WebHookController
  12. }
  13. //
  14. //// SyncCustomerRiskLevel 风险测评同步接口
  15. //// @Summary 风险测评同步接口
  16. //// @Description 风险测评同步接口
  17. //// @Success 200 {object} controllers.BaseResponse
  18. //// @router /riskLevel [post]
  19. //func (h *UserController) SyncCustomerRiskLevel() {
  20. // controllers.Wrap(&h.BaseController, func() (result *controllers.WrapData, err error) {
  21. // result = h.InitWrapData("同步风险等级")
  22. // htConfig := config.GetConfig(contants.HT).(*config.HTBizConfig)
  23. // webhookRequest := new(WebhookRequest)
  24. // h.GetPostParams(webhookRequest)
  25. // privateKey, err := authUtils.ParsePrivateKey(htConfig.GetWebhookPrivateKey())
  26. // if err != nil {
  27. // err = exception.NewWithException(exception.SysError, err.Error())
  28. // logger.Error("解析私钥失败: %v", err)
  29. // h.FailedResult("解析私钥失败", result)
  30. // return
  31. // }
  32. // decodeData, err := authUtils.DecryptWithRSA(privateKey, webhookRequest.Data)
  33. // if err != nil {
  34. // err = exception.NewWithException(exception.SysError, err.Error())
  35. // logger.Error("解密请求体失败: %v", err)
  36. // h.FailedResult("解密请求体失败", result)
  37. // return
  38. // }
  39. // syncCustomerRiskLevelReq := new(SyncCustomerRiskLevelReq)
  40. // err = json.Unmarshal(decodeData, syncCustomerRiskLevelReq)
  41. // if err != nil {
  42. // err = exception.NewWithException(exception.SyncRiskError, err.Error())
  43. // logger.Error("解析请求体失败: %v", err)
  44. // h.FailedResult("解析请求体失败", result)
  45. // return
  46. // }
  47. // custInfo := syncCustomerRiskLevelReq.CustInfo
  48. // riskInfo := syncCustomerRiskLevelReq.RiskInfo
  49. // if custInfo.ClientName == "" {
  50. // err = exception.New(exception.SyncRiskError)
  51. // h.FailedResult("用户名字不能为空", result)
  52. // return
  53. // }
  54. // if custInfo.MobileTel == "" {
  55. // err = exception.New(exception.SyncRiskError)
  56. // h.FailedResult("手机号码不能为空", result)
  57. // return
  58. // }
  59. // if custInfo.IdNo == "" {
  60. // err = exception.New(exception.SyncRiskError)
  61. // h.FailedResult("身份证号不能为空", result)
  62. // return
  63. // }
  64. // //if !utils.IsValidIDCard(custInfo.IdNo) && !utils.IsValidOldIDCard(custInfo.IdNo) {
  65. // // err = exception.New(exception.SyncRiskError)
  66. // // h.FailedResult("身份证号不合法", result)
  67. // // return
  68. // //}
  69. // if riskInfo.CorpRiskLevel == "" {
  70. // err = exception.New(exception.SyncRiskError)
  71. // h.FailedResult("风险等级不能为空", result)
  72. // return
  73. // }
  74. // if riskInfo.CorpEndDate == "" {
  75. // err = exception.New(exception.SyncRiskError)
  76. // h.FailedResult("风险测评有效结束日期不能为空", result)
  77. // return
  78. // }
  79. // err = userService.UpdateRiskLevelInfo(userService.RiskLevelInfoDTO{
  80. // Name: custInfo.ClientName,
  81. // PhoneNumber: custInfo.MobileTel,
  82. // RiskLevel: riskInfo.CorpRiskLevel,
  83. // RiskValidEndDate: riskInfo.CorpEndDate,
  84. // })
  85. // if err != nil {
  86. // logger.ErrorWithTraceId(h.Ctx, err.Error())
  87. // h.FailedResult(err.Error(), result)
  88. // err = exception.New(exception.SyncRiskError)
  89. // return
  90. // }
  91. // logger.InfoWithTraceId(h.Ctx, err.Error())
  92. // result = h.InitWrapData("同步风险等级成功")
  93. // h.SuccessResult("success", syncCustomerRiskLevelReq, result)
  94. // return
  95. // })
  96. //}
  97. // SyncCustomerRiskLevel 风险测评同步接口
  98. // @Summary 风险测评同步接口
  99. // @Description 风险测评同步接口
  100. // @Success 200 {object} controllers.BaseResponse
  101. // @router /v1/syncRiskLevel/ [post]
  102. func (h *HTFuturesAccountController) SyncCustomerRiskLevel() {
  103. controllers.WrapWebhook(&h.WebHookController, func() (result *controllers.WrapData, err error) {
  104. result = h.InitWrapData("同步风险等级")
  105. syncCustomerRiskLevelReq := new(SyncCustomerRiskLevelReq)
  106. h.GetPostParams(syncCustomerRiskLevelReq)
  107. custInfo := syncCustomerRiskLevelReq.CustInfo
  108. riskInfo := syncCustomerRiskLevelReq.RiskInfo
  109. if custInfo.ClientName == "" {
  110. err = exception.New(exception.SyncRiskError)
  111. h.FailedResult("用户名字不能为空", result)
  112. return
  113. }
  114. if custInfo.DealMobileTel == "" {
  115. err = exception.New(exception.SyncRiskError)
  116. h.FailedResult("手机号码不能为空", result)
  117. return
  118. }
  119. if custInfo.IdNo == "" {
  120. err = exception.New(exception.SyncRiskError)
  121. h.FailedResult("身份证号不能为空", result)
  122. return
  123. }
  124. if custInfo.MobileTel != "" && custInfo.DealMobileTel != custInfo.MobileTel {
  125. err = exception.New(exception.SyncRiskError)
  126. h.FailedResult(fmt.Sprintf("柜台预留手机号码不一致,测评手机:%s,柜台预留手机:%s", custInfo.DealMobileTel, custInfo.MobileTel), result)
  127. return
  128. }
  129. if riskInfo.CorpRiskLevel == "" {
  130. err = exception.New(exception.SyncRiskError)
  131. h.FailedResult("风险等级不能为空", result)
  132. return
  133. }
  134. if riskInfo.CorpEndDate == "" {
  135. err = exception.New(exception.SyncRiskError)
  136. h.FailedResult("风险测评有效结束日期不能为空", result)
  137. return
  138. }
  139. riskEndDate, parseErr := time.Parse("20060102", riskInfo.CorpEndDate)
  140. if parseErr != nil {
  141. err = exception.New(exception.SyncRiskError)
  142. h.FailedResult("风险测评有效结束日期不合法["+riskInfo.CorpEndDate+"]", result)
  143. return
  144. }
  145. err = userService.UpdateRiskLevelInfo(userService.RiskLevelInfoDTO{
  146. Name: custInfo.ClientName,
  147. PhoneNumber: custInfo.DealMobileTel,
  148. RiskLevel: fmt.Sprintf("C%s", riskInfo.CorpRiskLevel),
  149. RiskValidEndDate: riskEndDate.Format(time.DateOnly),
  150. })
  151. if err != nil {
  152. logger.ErrorWithTraceId(h.Ctx, err.Error())
  153. h.FailedResult(err.Error(), result)
  154. err = exception.New(exception.SyncRiskError)
  155. return
  156. }
  157. result = h.InitWrapData("同步风险等级成功")
  158. h.SuccessResult("success", syncCustomerRiskLevelReq, result)
  159. return
  160. })
  161. }
  162. // SyncCustomerAccountInfo 开户信息同步接口
  163. // @Summary 开户信息同步接口
  164. // @Description 开户信息同步接口
  165. // @Success 200 {object} controllers.BaseResponse
  166. // @router /v1/syncAccountInfo/ [post]
  167. func (h *HTFuturesAccountController) SyncCustomerAccountInfo() {
  168. controllers.WrapWebhook(&h.WebHookController, func() (result *controllers.WrapData, err error) {
  169. result = h.InitWrapData("同步风险等级")
  170. syncCustomerRiskLevelReq := new(SyncCustomerRiskLevelReq)
  171. h.GetPostParams(syncCustomerRiskLevelReq)
  172. custInfo := syncCustomerRiskLevelReq.CustInfo
  173. riskInfo := syncCustomerRiskLevelReq.RiskInfo
  174. if custInfo.ClientName == "" {
  175. err = exception.New(exception.SyncRiskError)
  176. h.FailedResult("用户名字不能为空", result)
  177. return
  178. }
  179. if custInfo.MobileTel == "" {
  180. err = exception.New(exception.SyncRiskError)
  181. h.FailedResult("手机号码不能为空", result)
  182. return
  183. }
  184. if custInfo.IdNo == "" {
  185. err = exception.New(exception.SyncRiskError)
  186. h.FailedResult("身份证号不能为空", result)
  187. return
  188. }
  189. //if !utils.IsValidIDCard(custInfo.IdNo) && !utils.IsValidOldIDCard(custInfo.IdNo) {
  190. // err = exception.New(exception.SyncRiskError)
  191. // h.FailedResult("身份证号不合法", result)
  192. // return
  193. //}
  194. if riskInfo.CorpRiskLevel == "" {
  195. err = exception.New(exception.SyncRiskError)
  196. h.FailedResult("风险等级不能为空", result)
  197. return
  198. }
  199. if riskInfo.CorpEndDate == "" {
  200. err = exception.New(exception.SyncRiskError)
  201. h.FailedResult("风险测评有效结束日期不能为空", result)
  202. return
  203. }
  204. err = userService.UpdateRiskLevelInfo(userService.RiskLevelInfoDTO{
  205. Name: custInfo.ClientName,
  206. PhoneNumber: custInfo.MobileTel,
  207. RiskLevel: fmt.Sprintf("C%s", riskInfo.CorpRiskLevel),
  208. RiskValidEndDate: riskInfo.CorpEndDate,
  209. })
  210. if err != nil {
  211. logger.ErrorWithTraceId(h.Ctx, err.Error())
  212. h.FailedResult(err.Error(), result)
  213. err = exception.New(exception.SyncRiskError)
  214. return
  215. }
  216. logger.InfoWithTraceId(h.Ctx, err.Error())
  217. result = h.InitWrapData("同步风险等级成功")
  218. h.SuccessResult("success", syncCustomerRiskLevelReq, result)
  219. return
  220. })
  221. }
  222. type SyncCustomerRiskLevelReq struct {
  223. CustInfo CustInfo `json:"custInfo"`
  224. RiskInfo RiskInfo `json:"riskInfo"`
  225. }
  226. type CustInfo struct {
  227. MobileTel string `json:"mobile_tel"`
  228. DealMobileTel string `json:"deal_mobile_tel"`
  229. ClientName string `json:"client_name"`
  230. IdKind string `json:"id_kind"`
  231. IdNo string `json:"id_no"`
  232. }
  233. type RiskInfo struct {
  234. CorpBeginDate string `json:"corp_begin_date"`
  235. CorpEndDate string `json:"corp_end_date"`
  236. UserInvestTerm string `json:"user_invest_term"`
  237. UserInvestKind string `json:"user_invest_kind"`
  238. CorpRiskLevel string `json:"corp_risk_level"`
  239. }
  240. type SyncCustomerAccountInfoReq struct {
  241. CustInfo CustInfo `json:"custInfo"`
  242. RiskInfo RiskInfo `json:"riskInfo"`
  243. }