From eaaa634e5abb193733290620d291aa08186978b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E5=B0=B9=E5=B2=9A?= <770236076@qq.com> Date: Mon, 16 Nov 2020 11:39:36 +0800 Subject: [PATCH] tuiguangm --- business/jxstore/cms/user2.go | 2 ++ business/jxutils/jxutils.go | 14 ++++++++++++++ business/model/user.go | 1 + 3 files changed, 17 insertions(+) diff --git a/business/jxstore/cms/user2.go b/business/jxstore/cms/user2.go index e96fc01cc..c1c5ee147 100644 --- a/business/jxstore/cms/user2.go +++ b/business/jxstore/cms/user2.go @@ -226,6 +226,8 @@ func CreateUser(user *model.User, creatorName string) (err error) { user.UserID = utils.GetUUID() user.Status = model.UserStatusNormal // user.DividePercentage = 1 + //推广码 + user.PopCode = jxutils.GenValidateCode(6) return dao.CreateEntity(nil, user) } diff --git a/business/jxutils/jxutils.go b/business/jxutils/jxutils.go index d171af663..a5d5d3d83 100644 --- a/business/jxutils/jxutils.go +++ b/business/jxutils/jxutils.go @@ -893,3 +893,17 @@ func polarTriangleArea(tan1, lng1, tan2, lng2 float64) (s float64) { t := tan1 * tan2 return 2 * math.Atan2(t*math.Sin(deltaLng), 1+t*math.Cos(deltaLng)) } + +func GenValidateCode(width int) string { + numeric := [36]byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, + 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', + 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'} + r := len(numeric) + rand.Seed(time.Now().UnixNano()) + + var sb strings.Builder + for i := 0; i < width; i++ { + fmt.Fprintf(&sb, "%d", numeric[rand.Intn(r)]) + } + return sb.String() +} diff --git a/business/model/user.go b/business/model/user.go index 98e164928..ae6a0eac5 100644 --- a/business/model/user.go +++ b/business/model/user.go @@ -56,6 +56,7 @@ type User struct { LastLoginAt *time.Time `orm:"null" json:"lastLoginAt"` LastLoginIP string `orm:"size(64);column(last_login_ip)" json:"lastLoginIP"` LastLoginType string `orm:"size(16)" json:"lastLoginType"` + PopCode string `json:"popCode"` //推广码 } func (*User) TableUnique() [][]string {