send_smscode.go 807 字节
package command

import (
	"fmt"

	"github.com/beego/beego/v2/core/validation"
)

type SendSmsCodeCommand struct {
	Phone string `json:"phone" valid:"Required"`
	// 0:无  1:需要账号存在于账号系统内,才能发送验证码
	Flag int `json:"flag"`
	// [1:登录][2:修改密码][3:找回密码][4:注册][5:修改手机号]
	Action int `json:"action"`
}

func (cmd *SendSmsCodeCommand) Valid(validation *validation.Validation) {

}

func (cmd *SendSmsCodeCommand) ValidateCommand() error {
	valid := validation.Validation{}
	b, err := valid.Valid(cmd)
	if cmd.Action == 1 || cmd.Action == 2 || cmd.Action == 3 {
		cmd.Flag = 1
	}
	if err != nil {
		return err
	}
	if !b {
		for _, validErr := range valid.Errors {
			return fmt.Errorf("%s  %s", validErr.Key, validErr.Message)
		}
	}
	return nil
}