addNewSubAccount.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. // 1. 验证码校验
  38. tag, err := service.LoginAuth.SubAccountAuthCode(h.ctx, newSubAccount.PhoneNumber, newSubAccount.Code)
  39. if err != nil {
  40. fmt.Println(err)
  41. h.resp.Status = 40000
  42. h.resp.Message = err.Error()
  43. return
  44. }
  45. // 2. 校验通过则创建样叽用户和子账号
  46. if tag == "1" {
  47. err := service.SubAccount.CreateSubAccount(h.ctx, newSubAccount)
  48. if err != nil {
  49. fmt.Println(err)
  50. h.resp.Status = 40000
  51. h.resp.Message = "创建失败"
  52. return
  53. } else {
  54. h.resp.Status = 20000
  55. h.resp.Message = "成功创建子账号"
  56. return
  57. }
  58. } else {
  59. // 验证码校验不通过的返回值
  60. h.resp.Status = 40000
  61. h.resp.Message = tag
  62. return
  63. }
  64. }
  65. func (h *AddNewSubAccountHandler) checkParam() error {
  66. return nil
  67. }