12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- 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)
- h.resp.Status = 40000
- h.resp.Message = err.Error()
- return
- }
- // 2. 校验通过则创建样叽用户和子账号
- if tag == "1" {
- err := service.SubAccount.CreateSubAccount(h.ctx, newSubAccount)
- if err != nil {
- fmt.Println(err)
- h.resp.Status = 40000
- h.resp.Message = "创建失败"
- return
- } else {
- h.resp.Status = 20000
- h.resp.Message = "成功创建子账号"
- return
- }
- } else {
- // 验证码校验不通过的返回值
- h.resp.Status = 40000
- h.resp.Message = tag
- return
- }
- }
- func (h *AddNewSubAccountHandler) checkParam() error {
- return nil
- }
|