package handler import ( "fmt" "github.com/gin-gonic/gin" "youngee_b_api/model/http_model" "youngee_b_api/service" ) func WrapAddNewSubAccountHandler(ctx *gin.Context) { handler := newAddNewSubAccountHandler(ctx) baseRun(handler) } func newAddNewSubAccountHandler(ctx *gin.Context) *AddNewSubAccountHandler { return &AddNewSubAccountHandler{ req: http_model.NewAddSubAccountRequest(), resp: http_model.NewAddSubAccountResponse(), ctx: ctx, } } type AddNewSubAccountHandler struct { req *http_model.AddNewSubAccountRequest resp *http_model.CommonResponse ctx *gin.Context } func (h *AddNewSubAccountHandler) getRequest() interface{} { return h.req } func (h *AddNewSubAccountHandler) getContext() *gin.Context { return h.ctx } func (h *AddNewSubAccountHandler) getResponse() interface{} { return h.resp } func (h *AddNewSubAccountHandler) run() { // fmt.Println("AddNewSubAccountHandler Running") newSubAccount := http_model.AddNewSubAccountRequest{} newSubAccount = *h.req // 1. 验证码校验 tag, err := service.LoginAuth.SubAccountAuthCode(h.ctx, newSubAccount.PhoneNumber, newSubAccount.Code) if err != nil { fmt.Println(err) } // 2. 校验通过则创建样叽用户和子账号 if tag == "1" { subAccountData, err := service.SubAccount.CreateSubAccount(h.ctx, newSubAccount) respData := http_model.AddNewSubAccountData{ UserID: int64(subAccountData.UserId), SupplierId: subAccountData.SupplierId, SubAccountID: subAccountData.SubAccountId, } if err != nil { fmt.Println(err) h.resp.Message = "创建失败" } else { h.resp.Message = "成功创建子账号" h.resp.Data = respData } } else { // 验证码校验不通过的返回值 h.resp.Message = tag } return } func (h *AddNewSubAccountHandler) checkParam() error { return nil }