addNewSubAccount.go 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. }
  42. // 2. 校验通过则创建样叽用户和子账号
  43. if tag == "1" {
  44. subAccountData, err := service.SubAccount.CreateSubAccount(h.ctx, newSubAccount)
  45. respData := http_model.AddNewSubAccountData{
  46. UserID: int64(subAccountData.UserId),
  47. SupplierId: subAccountData.SupplierId,
  48. SubAccountID: subAccountData.SubAccountId,
  49. }
  50. if err != nil {
  51. fmt.Println(err)
  52. h.resp.Message = "创建失败"
  53. } else {
  54. h.resp.Message = "成功创建子账号"
  55. h.resp.Data = respData
  56. }
  57. } else {
  58. // 验证码校验不通过的返回值
  59. h.resp.Message = tag
  60. }
  61. return
  62. }
  63. func (h *AddNewSubAccountHandler) checkParam() error {
  64. return nil
  65. }