refactor: 修改Identifier

master
howell 3 years ago
parent f23ef2b4bd
commit ed4ca03234

@ -2,6 +2,7 @@ package service
import ( import (
"fmt" "fmt"
"math/rand"
"recook/internal/cache" "recook/internal/cache"
"recook/internal/dbc" "recook/internal/dbc"
"recook/internal/define" "recook/internal/define"
@ -55,6 +56,7 @@ func (r *registerUser) UserAdd(c *gin.Context, login *user.Login, info *user.Inf
} }
} }
rd := fmt.Sprintf("%06v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(1000000))
*info = user.Information{ *info = user.Information{
ID: lastId, ID: lastId,
AncestorID: 1, AncestorID: 1,
@ -65,7 +67,7 @@ func (r *registerUser) UserAdd(c *gin.Context, login *user.Login, info *user.Inf
Audit: r.Audit, Audit: r.Audit,
Phone: mobile, Phone: mobile,
AssessBegin: formatime.NewSecondNow(), // 第一次的起始时间是注册时间 AssessBegin: formatime.NewSecondNow(), // 第一次的起始时间是注册时间
Identifier: time.Now().Format("060102") + baseCode.Encode(uint64(lastId)), Identifier: time.Now().Format("060102") + rd,
Level: level, Level: level,
ParentID: parentID, ParentID: parentID,
RootID: rootID, RootID: rootID,

@ -3,6 +3,7 @@ package company
import ( import (
"errors" "errors"
"fmt" "fmt"
"math/rand"
"recook/internal/define" "recook/internal/define"
"recook/internal/libs/bean" "recook/internal/libs/bean"
"recook/internal/service/baseCode" "recook/internal/service/baseCode"
@ -227,6 +228,7 @@ func (o logic) Sure(args CompanySureApply) error {
return errors.New("手机号已使用") return errors.New("手机号已使用")
} else { } else {
mobile := obj.Mobile mobile := obj.Mobile
rd := fmt.Sprintf("%06v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(1000000))
sql := `select max(id)+floor(1+rand()*5) from recook_user_info` sql := `select max(id)+floor(1+rand()*5) from recook_user_info`
var lastId int64 var lastId int64
if err := tx.Raw(sql).Count(&lastId).Error; err != nil { if err := tx.Raw(sql).Count(&lastId).Error; err != nil {
@ -239,7 +241,7 @@ func (o logic) Sure(args CompanySureApply) error {
Birthday: formatime.NewSecondFrom(define.DefaultBirthday), Birthday: formatime.NewSecondFrom(define.DefaultBirthday),
HeadImgUrl: "", HeadImgUrl: "",
Phone: mobile, Phone: mobile,
Identifier: time.Now().Format("060102") + baseCode.Encode(uint64(lastId)), Identifier: time.Now().Format("060102") + rd,
Level: 10, Level: 10,
ParentID: 0, ParentID: 0,
RootID: 0, RootID: 0,

@ -3,6 +3,7 @@ package jyy
import ( import (
"errors" "errors"
"fmt" "fmt"
"math/rand"
"recook/internal/define" "recook/internal/define"
"recook/internal/libs/bean" "recook/internal/libs/bean"
"recook/internal/service/baseCode" "recook/internal/service/baseCode"
@ -92,6 +93,7 @@ func (o logic) Vip(args AppUserReq) error {
// 没有就创建 // 没有就创建
if err := mysql.Db.Transaction(func(tx *gorm.DB) error { if err := mysql.Db.Transaction(func(tx *gorm.DB) error {
sql := `select max(id)+floor(1+rand()*5) from recook_user_info` sql := `select max(id)+floor(1+rand()*5) from recook_user_info`
rd := fmt.Sprintf("%06v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(1000000))
var lastId int64 var lastId int64
if err := tx.Raw(sql).Count(&lastId).Error; err != nil { if err := tx.Raw(sql).Count(&lastId).Error; err != nil {
return err return err
@ -103,7 +105,7 @@ func (o logic) Vip(args AppUserReq) error {
Birthday: formatime.NewSecondFrom(define.DefaultBirthday), Birthday: formatime.NewSecondFrom(define.DefaultBirthday),
HeadImgUrl: "", HeadImgUrl: "",
Phone: mobile, Phone: mobile,
Identifier: time.Now().Format("060102") + baseCode.Encode(uint64(lastId)), Identifier: time.Now().Format("060102") + rd,
Level: 2, Level: 2,
ParentID: 0, ParentID: 0,
RootID: 3212341, RootID: 3212341,

@ -2,6 +2,7 @@ package upgrade
import ( import (
"fmt" "fmt"
"math/rand"
"recook/internal/define" "recook/internal/define"
"recook/internal/libs/bean" "recook/internal/libs/bean"
"recook/internal/service/baseCode" "recook/internal/service/baseCode"
@ -83,6 +84,7 @@ func (o logic) Sure(args ApplySure) error {
if err := mysql.Db.Transaction(func(tx *gorm.DB) error { if err := mysql.Db.Transaction(func(tx *gorm.DB) error {
sql := `select max(id)+floor(1+rand()*5) from recook_user_info` sql := `select max(id)+floor(1+rand()*5) from recook_user_info`
rd := fmt.Sprintf("%06v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(1000000))
var lastId int64 var lastId int64
if err := tx.Raw(sql).Count(&lastId).Error; err != nil { if err := tx.Raw(sql).Count(&lastId).Error; err != nil {
return err return err
@ -94,7 +96,7 @@ func (o logic) Sure(args ApplySure) error {
Birthday: formatime.NewSecondFrom(define.DefaultBirthday), Birthday: formatime.NewSecondFrom(define.DefaultBirthday),
HeadImgUrl: "", HeadImgUrl: "",
Phone: mobile, Phone: mobile,
Identifier: time.Now().Format("060102") + baseCode.Encode(uint64(lastId)), Identifier: time.Now().Format("060102") + rd,
Level: 2, Level: 2,
ParentID: 0, ParentID: 0,
RootID: ae.ParentID, RootID: ae.ParentID,

Loading…
Cancel
Save