update_subaccount_info.go 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. package handler
  2. import (
  3. "github.com/gin-gonic/gin"
  4. "github.com/sirupsen/logrus"
  5. log "github.com/sirupsen/logrus"
  6. "youngee_m_api/consts"
  7. "youngee_m_api/db"
  8. "youngee_m_api/model/http_model"
  9. "youngee_m_api/service"
  10. "youngee_m_api/util"
  11. )
  12. func WrapEditSubAccountHandler(ctx *gin.Context) {
  13. handler := newUpdateSubAccountHandler(ctx)
  14. BaseRun(handler)
  15. }
  16. func newUpdateSubAccountHandler(ctx *gin.Context) *UpdateSubAccountInfoHandler {
  17. return &UpdateSubAccountInfoHandler{
  18. req: http_model.NewUpdateSubAccountInfoRequest(),
  19. resp: http_model.NewUpdateSubAccountInfoResponse(),
  20. ctx: ctx,
  21. }
  22. }
  23. type UpdateSubAccountInfoHandler struct {
  24. req *http_model.UpdateSubaccountInfoRequest
  25. resp *http_model.CommonResponse
  26. ctx *gin.Context
  27. }
  28. func (u UpdateSubAccountInfoHandler) getContext() *gin.Context { return u.ctx }
  29. func (u UpdateSubAccountInfoHandler) getResponse() interface{} {
  30. return u.resp
  31. }
  32. func (u UpdateSubAccountInfoHandler) getRequest() interface{} {
  33. return u.req
  34. }
  35. func (u UpdateSubAccountInfoHandler) run() {
  36. data := http_model.UpdateSubaccountInfoRequest{}
  37. data = *u.req
  38. message, err := service.Register.CodeJudge(u.ctx, data.PhoneNumber, data.Code)
  39. if err != nil {
  40. logrus.Errorf("[UpdateSubaccountInfoHandler] call UpdateSubaccountInfo err:%+v\n", err)
  41. util.HandlerPackErrorResp(u.resp, consts.ErrorInternal, "")
  42. logrus.Info("UpdateSubaccountInfoHandler fail,req:%+v", u.req)
  43. return
  44. }
  45. if message == "" {
  46. res, Error := db.UPdateSubaccountInfo(u.ctx, &data)
  47. if Error != nil {
  48. logrus.Errorf("[UpdateSubaccountInfoHandler] call UpdateSubaccountInfo err:%+v\n", err)
  49. util.HandlerPackErrorResp(u.resp, consts.ErrorInternal, "")
  50. log.Info("UpdateSubaccountInfo fail,req:%+v", u.req)
  51. return
  52. }
  53. u.resp.Message = "编辑成功"
  54. u.resp.Data = res
  55. } else {
  56. u.resp.Message = message
  57. }
  58. }
  59. func (u UpdateSubAccountInfoHandler) checkParam() error {
  60. return nil
  61. }