user_controller.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644
  1. package user
  2. import (
  3. "encoding/json"
  4. "encoding/xml"
  5. "eta/eta_mini_ht_api/common/component/cache"
  6. "eta/eta_mini_ht_api/common/component/config"
  7. logger "eta/eta_mini_ht_api/common/component/log"
  8. "eta/eta_mini_ht_api/common/contants"
  9. "eta/eta_mini_ht_api/common/exception"
  10. authUtils "eta/eta_mini_ht_api/common/utils/auth"
  11. "eta/eta_mini_ht_api/controllers"
  12. userService "eta/eta_mini_ht_api/domian/user"
  13. "eta/eta_mini_ht_api/service/auth"
  14. "eta/eta_mini_ht_api/service/user"
  15. "fmt"
  16. "strconv"
  17. "strings"
  18. "time"
  19. )
  20. // UserController Operations about Users
  21. type UserController struct {
  22. controllers.BaseController
  23. redis *cache.RedisCache
  24. }
  25. func (u *UserController) Prepare() {
  26. u.redis = cache.GetInstance()
  27. }
  28. type LoginCode struct {
  29. Code int `json:"code"`
  30. Msg string `json:"msg"`
  31. }
  32. // Get @Title GetAll
  33. // @Description get all Users
  34. // @Success 200 {object} models.User
  35. // @router / [get]
  36. func (u *UserController) Get() {
  37. logger.Warn("查询用户列表:%s")
  38. fmt.Print("查询用户列表")
  39. u.ServeJSON()
  40. }
  41. type FeedbackReq struct {
  42. Mobile string `json:"mobile"`
  43. Message string `json:"message"`
  44. }
  45. type FollowAnalystReq struct {
  46. AnalystId int `json:"analystId"`
  47. AnalystName string `json:"analystName"`
  48. FollowType string `json:"followType"`
  49. Mobile string `json:"mobile"`
  50. ByName bool `json:"byName"`
  51. }
  52. // Feedback 用户意见反馈
  53. // @Summary 用户意见反馈
  54. // @Description 用户意见反馈
  55. // @Success 200 {object} controllers.BaseResponse
  56. // @router /feedback [post]
  57. func (u *UserController) Feedback() {
  58. controllers.Wrap(&u.BaseController, func() (result *controllers.WrapData, err error) {
  59. result = u.InitWrapData("提交反馈失败")
  60. feedback := new(FeedbackReq)
  61. u.GetPostParams(feedback)
  62. if !authUtils.IsValidMobile(feedback.Mobile) {
  63. u.FailedResult("手机号非法", result)
  64. err = exception.New(exception.IllegalPhoneNumber)
  65. return
  66. }
  67. var userInfo user.User
  68. userInfo = u.Data["user"].(user.User)
  69. if userInfo.Mobile != feedback.Mobile {
  70. u.FailedResult("非当前用户的手机号提交", result)
  71. err = exception.New(exception.NotCurrentUserError)
  72. return
  73. }
  74. if feedback.Message == "" {
  75. u.FailedResult("反馈信息不能为空", result)
  76. err = exception.New(exception.FeedBackMsgEmpty)
  77. return
  78. }
  79. err = user.FeedBack(userInfo.Id, feedback.Mobile, feedback.Message)
  80. if err != nil {
  81. err = exception.New(exception.FeedBackError)
  82. u.FailedResult("提交反馈失败", result)
  83. return
  84. }
  85. u.SuccessResult("提交反馈成功", nil, result)
  86. return
  87. })
  88. }
  89. type BatchFollowResp struct {
  90. FollowStatus string `json:"followStatus"`
  91. List []userService.FollowDTO `json:"list"`
  92. }
  93. type FollowResp struct {
  94. AnalystId int `json:"analystId"`
  95. FollowedType string `json:"FollowedType"`
  96. }
  97. type FollowAnalystsReq struct {
  98. AnalystNames string `json:"analystNames"`
  99. FollowType string `json:"followType"`
  100. Mobile string `json:"mobile"`
  101. }
  102. // FollowAnalysts 批量关注研究员
  103. // @Summary 批量关注研究员
  104. // @Description 批量关注研究员
  105. // @Success 200 {object} controllers.BaseResponse
  106. // @router /followAnalysts [post]
  107. func (u *UserController) FollowAnalysts() {
  108. controllers.Wrap(&u.BaseController, func() (result *controllers.WrapData, err error) {
  109. result = u.InitWrapData("批量关注失败")
  110. followAnalyst := new(FollowAnalystsReq)
  111. u.GetPostParams(followAnalyst)
  112. if !authUtils.IsValidMobile(followAnalyst.Mobile) {
  113. u.FailedResult("手机号非法", result)
  114. err = exception.New(exception.IllegalPhoneNumber)
  115. return
  116. }
  117. var userInfo user.User
  118. userInfo = u.Data["user"].(user.User)
  119. if userInfo.Mobile != followAnalyst.Mobile {
  120. u.FailedResult("非当前用户的手机号提交", result)
  121. err = exception.New(exception.NotCurrentUserError)
  122. return
  123. }
  124. if !checkFollowType(followAnalyst.FollowType) {
  125. u.FailedResult("关注状态非法", result)
  126. err = exception.New(exception.IllegalFollowType)
  127. return
  128. }
  129. var msg string
  130. switch followAnalyst.FollowType {
  131. case "following":
  132. msg = "批量关注研究员"
  133. case "unfollowed":
  134. msg = "批量取消关注研究员"
  135. }
  136. var nameList []string
  137. names := followAnalyst.AnalystNames
  138. if strings.HasPrefix(names, ",") {
  139. names = names[1:]
  140. }
  141. if strings.HasSuffix(names, ",") {
  142. names = names[0 : len(names)-1]
  143. }
  144. if names == "" {
  145. nameList = []string{}
  146. } else {
  147. nameList = strings.Split(names, ",")
  148. }
  149. for i := 0; i < len(nameList); i++ {
  150. nameList[i] = strings.TrimSpace(nameList[i])
  151. if nameList[i] == "" {
  152. u.FailedResult("通过研究员姓名关注失败", result)
  153. err = exception.New(exception.AnalystNameEmptyError)
  154. return
  155. }
  156. }
  157. err = user.FollowAnalystsByName(userInfo.Id, nameList, followAnalyst.FollowType)
  158. if err != nil {
  159. u.FailedResult(msg+"失败", result)
  160. return
  161. }
  162. u.SuccessResult(msg+"成功", nil, result)
  163. return
  164. })
  165. }
  166. // CheckFollowStatus 获取关注状态
  167. // @Summary 获取关注状态
  168. // @Description 获取关注状态
  169. // @Success 200 {object} controllers.BaseResponse
  170. // @router /checkFollowStatus [get]
  171. func (u *UserController) CheckFollowStatus(names string) {
  172. controllers.Wrap(&u.BaseController, func() (result *controllers.WrapData, err error) {
  173. result = u.InitWrapData("获取关注状态失败")
  174. var userInfo user.User
  175. userInfo = u.Data["user"].(user.User)
  176. var nameList []string
  177. if strings.HasPrefix(names, ",") {
  178. names = names[1:len(names)]
  179. }
  180. if strings.HasSuffix(names, ",") {
  181. names = names[0 : len(names)-1]
  182. }
  183. if names == "" {
  184. nameList = []string{}
  185. } else {
  186. nameList = strings.Split(names, ",")
  187. }
  188. for i := 0; i < len(nameList); i++ {
  189. nameList[i] = strings.TrimSpace(nameList[i])
  190. }
  191. list, err := user.CheckFollowStatusByNames(userInfo.Id, nameList)
  192. status := true
  193. data := BatchFollowResp{
  194. List: list,
  195. }
  196. for i := 0; i < len(list); i++ {
  197. if !checkFollowing(list[i].FollowType) {
  198. status = false
  199. break
  200. }
  201. }
  202. if status {
  203. data.FollowStatus = "following"
  204. } else {
  205. data.FollowStatus = "unfollowed"
  206. }
  207. if err != nil {
  208. u.FailedResult("获取关注状态失败", result)
  209. return
  210. }
  211. u.SuccessResult("获取关注状态成功", data, result)
  212. return
  213. })
  214. }
  215. func checkFollowing(followType string) bool {
  216. return followType == "following"
  217. }
  218. // FollowAnalyst 关注研究员
  219. // @Summary 关注研究员
  220. // @Description 关注研究员
  221. // @Success 200 {object} controllers.BaseResponse
  222. // @router /followAnalyst [post]
  223. func (u *UserController) FollowAnalyst() {
  224. controllers.Wrap(&u.BaseController, func() (result *controllers.WrapData, err error) {
  225. result = u.InitWrapData("")
  226. followAnalyst := new(FollowAnalystReq)
  227. u.GetPostParams(followAnalyst)
  228. if !authUtils.IsValidMobile(followAnalyst.Mobile) {
  229. u.FailedResult("手机号非法", result)
  230. err = exception.New(exception.IllegalPhoneNumber)
  231. return
  232. }
  233. var userInfo user.User
  234. userInfo = u.Data["user"].(user.User)
  235. if userInfo.Mobile != followAnalyst.Mobile {
  236. u.FailedResult("非当前用户的手机号提交", result)
  237. err = exception.New(exception.NotCurrentUserError)
  238. return
  239. }
  240. if !checkFollowType(followAnalyst.FollowType) {
  241. u.FailedResult("关注状态非法", result)
  242. err = exception.New(exception.IllegalFollowType)
  243. return
  244. }
  245. var msg string
  246. switch followAnalyst.FollowType {
  247. case "following":
  248. msg = "关注研究员"
  249. case "unfollowed":
  250. msg = "取消关注研究员"
  251. }
  252. if followAnalyst.ByName {
  253. logger.Info("通过研究员姓名关注")
  254. if followAnalyst.AnalystName == "" {
  255. u.FailedResult("通过研究员姓名关注失败", result)
  256. err = exception.New(exception.AnalystNameEmptyError)
  257. return
  258. }
  259. err = user.FollowAnalystByName(userInfo.Id, followAnalyst.AnalystName, followAnalyst.FollowType)
  260. } else {
  261. if followAnalyst.AnalystId <= 0 {
  262. u.FailedResult("通过研究员姓名关注失败", result)
  263. err = exception.New(exception.IllegalAnalystIdError)
  264. return
  265. }
  266. err = user.FollowAnalyst(userInfo.Id, followAnalyst.AnalystId, followAnalyst.FollowType)
  267. }
  268. if err != nil {
  269. u.FailedResult(msg+"失败", result)
  270. return
  271. }
  272. resp := FollowResp{
  273. AnalystId: followAnalyst.AnalystId,
  274. FollowedType: followAnalyst.FollowType,
  275. }
  276. u.SuccessResult(msg+"成功", resp, result)
  277. return
  278. })
  279. }
  280. func checkFollowType(followType string) bool {
  281. return followType == "following" || followType == "unfollowed"
  282. }
  283. // FollowingAnalysts 关注研究员
  284. // @Summary 关注研究员
  285. // @Description 关注研究员
  286. // @Success 200 {object} controllers.BaseResponse
  287. // @router /followingAnalysts [get]
  288. func (u *UserController) FollowingAnalysts(analystId int) {
  289. controllers.Wrap(&u.BaseController, func() (result *controllers.WrapData, err error) {
  290. result = u.InitWrapData("关注研究员列表失败")
  291. fmt.Println(analystId)
  292. userInfo := u.Data["user"].(user.User)
  293. detail, err := user.GetAnalystDetail(userInfo.Id, analystId)
  294. if err != nil {
  295. u.FailedResult("关注研究员失败", result)
  296. return
  297. }
  298. u.SuccessResult("关注研究员成功", detail, result)
  299. return
  300. })
  301. }
  302. type UserProfileReq struct {
  303. UserName string `json:"userName"`
  304. RiskLevel string `json:"riskLevel"`
  305. Mobile string `json:"mobile"`
  306. RiskLevelStatus string `json:"riskLevelStatus"`
  307. }
  308. // Profile 获取用户信息
  309. // @Summary 获取用户信息
  310. // @Description 获取用户信息
  311. // @Success 200 {object} controllers.BaseResponse
  312. // @router /profile [get]
  313. func (u *UserController) Profile() {
  314. controllers.Wrap(&u.BaseController, func() (result *controllers.WrapData, err error) {
  315. result = u.InitWrapData("获取用户信息详情失败")
  316. userInfo := u.Data["user"].(user.User)
  317. var userProfile user.UserProfile
  318. userProfile, err = user.GetUserProfile(userInfo.Id)
  319. u.SuccessResult("获取研究员详情成功", userProfile, result)
  320. return
  321. })
  322. }
  323. // FollowingAnalystList 获取关注动态列表
  324. // @Summary 获取关注动态列表
  325. // @Description 获取关注动态列表
  326. // @Success 200 {object} controllers.BaseResponse
  327. // @router /followingAnalystList [get]
  328. func (u *UserController) FollowingAnalystList() {
  329. controllers.Wrap(&u.BaseController, func() (result *controllers.WrapData, err error) {
  330. result = u.InitWrapData("获取研究员详情失败")
  331. userInfo := u.Data["user"].(user.User)
  332. detail, err := user.GetFollowingAnalystList(userInfo.Id)
  333. if err != nil {
  334. u.FailedResult("获取关注研究员列表失败", result)
  335. return
  336. }
  337. u.SuccessResult("获取关注研究员列表成功", detail, result)
  338. return
  339. })
  340. }
  341. // UnReadMessageList 获取未读消息
  342. // @Summary 获取未读消息
  343. // @Description 获取未读消息
  344. // @Success 200 {object} controllers.BaseResponse
  345. // @router /message [get]
  346. func (u *UserController) UnReadMessageList() {
  347. controllers.Wrap(&u.BaseController, func() (result *controllers.WrapData, err error) {
  348. result = u.InitWrapData("获取我的未读消息失败")
  349. userInfo := u.Data["user"].(user.User)
  350. messages, err := user.GetUnReadMessageList(userInfo.Id)
  351. if err != nil {
  352. u.FailedResult("获取我的未读消息失败", result)
  353. return
  354. }
  355. u.SuccessResult("获取我的未读消息成功", messages, result)
  356. return
  357. })
  358. }
  359. type ReadMessageReq struct {
  360. AnalystId int `json:"analystId"`
  361. MessageId int `json:"MessageId"`
  362. }
  363. // ReadMessage 获取未读消息
  364. // @Summary 获取未读消息
  365. // @Description 获取未读消息
  366. // @Success 200 {object} controllers.BaseResponse
  367. // @router /readMessage [post]
  368. func (u *UserController) ReadMessage() {
  369. controllers.Wrap(&u.BaseController, func() (result *controllers.WrapData, err error) {
  370. result = u.InitWrapData("获取我的未读消息失败")
  371. readMessageReq := new(ReadMessageReq)
  372. u.GetPostParams(readMessageReq)
  373. if readMessageReq.MessageId <= 0 {
  374. logger.Error("消息Id非法")
  375. err = exception.New(exception.IllegalMessageId)
  376. u.FailedResult("已读消息失败", result)
  377. return
  378. }
  379. userInfo := u.Data["user"].(user.User)
  380. if user.ReadMessage(userInfo.Id, readMessageReq.MessageId) {
  381. u.SuccessResult("已读消息成功", nil, result)
  382. return
  383. } else {
  384. err = exception.New(exception.ReadMessageFailed)
  385. u.FailedResult("已读消息失败", result)
  386. return
  387. }
  388. })
  389. }
  390. // ReadMessages 获取未读消息
  391. // @Summary 获取未读消息
  392. // @Description 获取未读消息
  393. // @Success 200 {object} controllers.BaseResponse
  394. // @router /readMessages [post]
  395. func (u *UserController) ReadMessages() {
  396. controllers.Wrap(&u.BaseController, func() (result *controllers.WrapData, err error) {
  397. result = u.InitWrapData("获取我的未读消息失败")
  398. readMessageReq := new(ReadMessageReq)
  399. u.GetPostParams(readMessageReq)
  400. if readMessageReq.AnalystId <= 0 {
  401. logger.Error("研究员Id非法")
  402. err = exception.New(exception.IllegalAnalystId)
  403. u.FailedResult("已读消息失败", result)
  404. return
  405. }
  406. userInfo := u.Data["user"].(user.User)
  407. if user.ReadMessages(userInfo.Id, readMessageReq.AnalystId) {
  408. u.SuccessResult("已读消息成功", nil, result)
  409. return
  410. } else {
  411. err = exception.New(exception.ReadMessageFailed)
  412. u.FailedResult("已读消息失败", result)
  413. return
  414. }
  415. })
  416. }
  417. // ReadMessages 绑定微信公众号
  418. // @Summary 绑定微信公众号
  419. // @Description 绑定微信公众号
  420. // @Success 200 {object} controllers.BaseResponse
  421. // @router /bind_gzh [post]
  422. func (u *UserController) BindGzh() {
  423. controllers.Wrap(&u.BaseController, func() (result *controllers.WrapData, err error) {
  424. result = u.InitWrapData("绑定公众号失败")
  425. bindReq := new(BindGzhReq)
  426. u.GetPostParams(bindReq)
  427. code := bindReq.Code
  428. isBind, err := auth.BindWxGzh(code)
  429. if err != nil {
  430. logger.Error("绑定公众号失败:%v", err)
  431. u.FailedResult("绑定公众号失败", result)
  432. return
  433. }
  434. u.SuccessResult("绑定成功", IsBindGzhRes{
  435. IsBind: isBind,
  436. }, result)
  437. return
  438. })
  439. }
  440. type IsBindGzhRes struct {
  441. IsBind bool `json:"isBind"`
  442. }
  443. type BindGzhReq struct {
  444. Code string `json:"Code"`
  445. }
  446. // Notify 微信公众号回调
  447. // @Summary 微信公众号回调
  448. // @Description 微信公众号回调
  449. // @Success 200 {object} controllers.BaseResponse
  450. // @router /wx/notify [get,post]
  451. func (u *UserController) Notify() {
  452. echostr := u.GetString("echostr")
  453. method := u.Ctx.Input.Method()
  454. if method == "POST" {
  455. body := u.Ctx.Input.RequestBody
  456. item := new(Notify)
  457. err := xml.Unmarshal(body, &item)
  458. if err != nil {
  459. logger.Info("xml.Unmarshal:" + err.Error())
  460. }
  461. contactMsg := "你好,欢迎关注期海通行-投研点金!"
  462. var openId, returnResult string
  463. if item.MsgType != "" {
  464. openId = item.FromUserName
  465. }
  466. xmlTpl := `<xml>
  467. <ToUserName><![CDATA[%s]]></ToUserName>
  468. <FromUserName><![CDATA[%s]]></FromUserName>
  469. <CreateTime>%s</CreateTime>
  470. <MsgType><![CDATA[text]]></MsgType>
  471. <Content><![CDATA[%s]]></Content>
  472. </xml>`
  473. createTime := strconv.FormatInt(time.Now().Unix(), 10)
  474. // WxId := "gh_5dc508325c6f" // 弘则投研公众号原始id
  475. xmlTpl = fmt.Sprintf(xmlTpl, openId, auth.HT_WX_ID, createTime, contactMsg)
  476. if item.MsgType == "event" {
  477. switch item.Event {
  478. case "subscribe":
  479. fmt.Println("关注")
  480. go auth.BindWxGzhByOpenId(openId)
  481. case "unsubscribe":
  482. fmt.Println("取消关注")
  483. go auth.UnSubscribeWxGzhByOpenId(openId)
  484. case "CLICK":
  485. //returnResult = xmlTpl
  486. default:
  487. logger.Info("wechat notify event:" + item.Event)
  488. }
  489. u.Ctx.WriteString(xmlTpl)
  490. } else {
  491. returnResult = xmlTpl
  492. }
  493. u.Ctx.WriteString(returnResult)
  494. } else {
  495. u.Ctx.WriteString(echostr)
  496. }
  497. }
  498. type Notify struct {
  499. ToUserName string `xml:"ToUserName"`
  500. FromUserName string `xml:"FromUserName"`
  501. CreateTime int `xml:"CreateTime"`
  502. MsgType string `xml:"MsgType"`
  503. Event string `xml:"Event"`
  504. EventKey string `xml:"EventKey"`
  505. Content string `xml:"Content"`
  506. }
  507. type SyncCustomerRiskLevelReq struct {
  508. CustInfo CustInfo `json:"custInfo"`
  509. RiskInfo RiskInfo `json:"riskInfo"`
  510. }
  511. type CustInfo struct {
  512. MobileTel string `json:"mobile_tel"`
  513. ClientName string `json:"client_name"`
  514. IdKind string `json:"id_kind"`
  515. IdNo string `json:"id_no"`
  516. }
  517. type RiskInfo struct {
  518. CorpBeginDate string `json:"corp_begin_date"`
  519. CorpEndDate string `json:"corp_end_date"`
  520. UserInvestTerm string `json:"user_invest_term"`
  521. UserInvestKind string `json:"user_invest_kind"`
  522. CorpRiskLevel string `json:"corp_risk_level"`
  523. }
  524. type WebhookRequest struct {
  525. Data string `json:"data"`
  526. //EncryptKey string `json:"encryptKey"`
  527. }
  528. // SyncCustomerRiskLevel 风险测评同步接口
  529. // @Summary 风险测评同步接口
  530. // @Description 风险测评同步接口
  531. // @Success 200 {object} controllers.BaseResponse
  532. // @router /riskLevel [post]
  533. func (h *UserController) SyncCustomerRiskLevel() {
  534. controllers.Wrap(&h.BaseController, func() (result *controllers.WrapData, err error) {
  535. result = h.InitWrapData("同步风险等级")
  536. htConfig := config.GetConfig(contants.HT).(*config.HTBizConfig)
  537. webhookRequest := new(WebhookRequest)
  538. h.GetPostParams(webhookRequest)
  539. privateKey, err := authUtils.ParsePrivateKey(htConfig.GetWebhookPrivateKey())
  540. if err != nil {
  541. err = exception.NewWithException(exception.SysError, err.Error())
  542. logger.Error("解析私钥失败: %v", err)
  543. h.FailedResult("解析私钥失败", result)
  544. return
  545. }
  546. decodeData, err := authUtils.DecryptWithRSA(privateKey, webhookRequest.Data)
  547. if err != nil {
  548. err = exception.NewWithException(exception.SysError, err.Error())
  549. logger.Error("解密请求体失败: %v", err)
  550. h.FailedResult("解密请求体失败", result)
  551. return
  552. }
  553. syncCustomerRiskLevelReq := new(SyncCustomerRiskLevelReq)
  554. err = json.Unmarshal(decodeData, syncCustomerRiskLevelReq)
  555. if err != nil {
  556. err = exception.NewWithException(exception.SyncRiskError, err.Error())
  557. logger.Error("解析请求体失败: %v", err)
  558. h.FailedResult("解析请求体失败", result)
  559. return
  560. }
  561. custInfo := syncCustomerRiskLevelReq.CustInfo
  562. riskInfo := syncCustomerRiskLevelReq.RiskInfo
  563. if custInfo.ClientName == "" {
  564. err = exception.New(exception.SyncRiskError)
  565. h.FailedResult("用户名字不能为空", result)
  566. return
  567. }
  568. if custInfo.MobileTel == "" {
  569. err = exception.New(exception.SyncRiskError)
  570. h.FailedResult("手机号码不能为空", result)
  571. return
  572. }
  573. if custInfo.IdNo == "" {
  574. err = exception.New(exception.SyncRiskError)
  575. h.FailedResult("身份证号不能为空", result)
  576. return
  577. }
  578. //if !utils.IsValidIDCard(custInfo.IdNo) && !utils.IsValidOldIDCard(custInfo.IdNo) {
  579. // err = exception.New(exception.SyncRiskError)
  580. // h.FailedResult("身份证号不合法", result)
  581. // return
  582. //}
  583. if riskInfo.CorpRiskLevel == "" {
  584. err = exception.New(exception.SyncRiskError)
  585. h.FailedResult("风险等级不能为空", result)
  586. return
  587. }
  588. if riskInfo.CorpEndDate == "" {
  589. err = exception.New(exception.SyncRiskError)
  590. h.FailedResult("风险测评有效结束日期不能为空", result)
  591. return
  592. }
  593. err = userService.UpdateRiskLevelInfo(userService.RiskLevelInfoDTO{
  594. Name: custInfo.ClientName,
  595. PhoneNumber: custInfo.MobileTel,
  596. RiskLevel: riskInfo.CorpRiskLevel,
  597. RiskValidEndDate: riskInfo.CorpEndDate,
  598. })
  599. if err != nil {
  600. logger.ErrorWithTraceId(h.Ctx, err.Error())
  601. h.FailedResult(err.Error(), result)
  602. err = exception.New(exception.SyncRiskError)
  603. return
  604. }
  605. logger.InfoWithTraceId(h.Ctx, err.Error())
  606. result = h.InitWrapData("同步风险等级成功")
  607. h.SuccessResult("success", syncCustomerRiskLevelReq, result)
  608. return
  609. })
  610. }