addNewSubAccount.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. package handler
  2. import (
  3. "fmt"
  4. "github.com/gin-gonic/gin"
  5. "youngee_b_api/model/http_model"
  6. "youngee_b_api/service"
  7. )
  8. func WrapAddNewSubAccountHandler(ctx *gin.Context) {
  9. handler := newAddNewSubAccountHandler(ctx)
  10. baseRun(handler)
  11. }
  12. func newAddNewSubAccountHandler(ctx *gin.Context) *AddNewSubAccountHandler {
  13. return &AddNewSubAccountHandler{
  14. req: http_model.NewAddSubAccountRequest(),
  15. resp: http_model.NewAddSubAccountResponse(),
  16. ctx: ctx,
  17. }
  18. }
  19. type AddNewSubAccountHandler struct {
  20. req *http_model.AddNewSubAccountRequest
  21. resp *http_model.CommonResponse
  22. ctx *gin.Context
  23. }
  24. func (h *AddNewSubAccountHandler) getRequest() interface{} {
  25. return h.req
  26. }
  27. func (h *AddNewSubAccountHandler) getContext() *gin.Context {
  28. return h.ctx
  29. }
  30. func (h *AddNewSubAccountHandler) getResponse() interface{} {
  31. return h.resp
  32. }
  33. func (h *AddNewSubAccountHandler) run() {
  34. // fmt.Println("AddNewSubAccountHandler Running")
  35. newSubAccount := http_model.AddNewSubAccountRequest{}
  36. newSubAccount = *h.req
  37. tag, err := service.LoginAuth.SubAccountAuthCode(h.ctx, newSubAccount.PhoneNumber, newSubAccount.Code)
  38. if err != nil {
  39. fmt.Println(err)
  40. }
  41. if tag == "1" {
  42. err := service.SubAccount.CreateSubAccount(h.ctx, newSubAccount)
  43. if err != nil {
  44. fmt.Println(err)
  45. h.resp.Message = "创建失败"
  46. } else {
  47. h.resp.Message = "成功创建子账号"
  48. }
  49. } else {
  50. h.resp.Message = tag
  51. }
  52. return
  53. }
  54. func (h *AddNewSubAccountHandler) checkParam() error {
  55. return nil
  56. }