package user import ( logger "eta/eta_mini_ht_api/common/component/log" "eta/eta_mini_ht_api/common/exception" "eta/eta_mini_ht_api/controllers" "eta/eta_mini_ht_api/service/facade" "eta/eta_mini_ht_api/service/user" "github.com/google/uuid" "net/url" "strings" ) type AccountController struct { controllers.BaseController } type RiskInfoTokenResp struct { Token string `json:"token"` } const ( TraceHeaderKey = "X-Trace-ID" MDCTraceId = "traceId" ) const ( AccountNotOpen = 430 IDExpired = 431 RiskUnTest = 432 RiskNotMatch = 433 RiskExpired = 434 AccountOpening = 435 orderPending = "pending" orderPaid = "paid" orderRefund = "refund" orderClosed = "closed" ) func (a *AccountController) Prepare() { var requestBody string uri := a.Ctx.Input.URI() method := a.Ctx.Input.Method() if method == "GET" { requestBody = a.Ctx.Request.RequestURI } else { requestBody, _ = url.QueryUnescape(string(a.Ctx.Input.RequestBody)) } ip := a.Ctx.Input.IP() a.Ctx.Input.URL() traceId := uuid.NewString() traceId = strings.ReplaceAll(traceId, "-", "") a.Ctx.Output.Header(TraceHeaderKey, traceId) //// 设置MDC中的traceId a.Ctx.Input.SetData(MDCTraceId, traceId) // 清理MDC中的traceId logger.InfoWithTraceId(a.Ctx, "webhookRequest:[uri:%s, requestBody:%s, ip:%s]", uri, requestBody, ip) } // GetRiskInfoToken 获取风险测评问卷请求Token // @Summary 获取风险测评问卷请求Token // @Description 获取风险测评问卷请求Token // @Success 200 {object} controllers.BaseResponse // @router /v1/riskTestToken/ [get] func (a *AccountController) GetRiskInfoToken() { controllers.Wrap(&a.BaseController, func() (result *controllers.WrapData, err error) { result = a.InitWrapData("获取风险测评问卷请求Token失败") userInfo := a.Data["user"].(user.User) token, err := facade.GetRiskTestToken(userInfo.Id, userInfo.Mobile) if err != nil { logger.InfoWithTraceId(a.Ctx, err.Error()) a.FailedResult("风险测评问卷请求token生成失败", result) return } result = a.InitWrapData("风险测评问卷请求token生成成功") a.SuccessResult("success", RiskInfoTokenResp{ Token: token, }, result) return }) } // CheckUserStatus 获取风险测评问卷请求Token // @Summary 获取风险测评问卷请求Token // @Description 获取风险测评问卷请求Token // @Success 200 {object} controllers.BaseResponse // @router /checkUserStatus/ [post] func (a *AccountController) CheckUserStatus() { controllers.Wrap(&a.BaseController, func() (result *controllers.WrapData, err error) { result = a.InitWrapData("获取风险测评问卷请求Token失败") userInfo := a.Data["user"].(user.User) //校验是否已经购买并且在有效期内 //是否开户 //未开户 officialUser, err := user.GetUserByTemplateUserId(userInfo.Id) if err != nil { if err.Error() == exception.GetMsg(exception.OfficialUserNotFound) { err = exception.New(exception.OfficialUserNotFound) result.Ret = AccountNotOpen a.FailedResult("用户未开通账户", result) } else { a.FailedResult("获取用户账户信息失败", result) } return } switch officialUser.AccountStatus { case "unopen": result.Ret = AccountNotOpen err = exception.New(exception.AccountNotOpen) a.FailedResult("用户未开通账户", result) return case "opening": result.Ret = AccountOpening err = exception.New(exception.AccountNotOpen) a.FailedResult("用户开户中", result) return case "opened": default: err = exception.New(exception.IllegalAccountStatus) a.FailedResult(result.Msg, result) return } //证件信息是否过期 if !officialUser.IDValid { err = exception.New(exception.IDExpired) result.Ret = IDExpired a.FailedResult("用户证件有效期过期", result) return } a.SuccessResult("校验用户信息成功", nil, result) return }) }