|
|
|
@ -4,12 +4,9 @@ import (
|
|
|
|
|
"errors"
|
|
|
|
|
"fmt"
|
|
|
|
|
"recook/internal/cache"
|
|
|
|
|
"recook/internal/define"
|
|
|
|
|
"recook/internal/service/baseCode"
|
|
|
|
|
"recook/internal/v2/model/recook/user"
|
|
|
|
|
"recook/internal/v2/model/upgrade"
|
|
|
|
|
"strings"
|
|
|
|
|
"time"
|
|
|
|
|
|
|
|
|
|
"git.oa00.com/go/mysql"
|
|
|
|
|
"github.com/golangkit/formatime"
|
|
|
|
@ -77,17 +74,17 @@ func (o logic) Create(args ApplyCreate) error {
|
|
|
|
|
parentID = u1.RootID
|
|
|
|
|
}
|
|
|
|
|
state := upgrade.Apply
|
|
|
|
|
if args.Kind == 1 {
|
|
|
|
|
state = upgrade.Suc
|
|
|
|
|
}
|
|
|
|
|
// if args.Kind == 1 {
|
|
|
|
|
// state = upgrade.Suc
|
|
|
|
|
// }
|
|
|
|
|
if args.Code != cache.GetUpgradeSMSCode(u1.Id) {
|
|
|
|
|
return fmt.Errorf("验证码不正确")
|
|
|
|
|
}
|
|
|
|
|
if err := mysql.Db.Transaction(func(tx *gorm.DB) error {
|
|
|
|
|
now := formatime.NewSecondNow()
|
|
|
|
|
if args.Kind == 2 {
|
|
|
|
|
now = formatime.Second{}
|
|
|
|
|
}
|
|
|
|
|
// now := formatime.NewSecondNow()
|
|
|
|
|
// if args.Kind == 2 {
|
|
|
|
|
// now = formatime.Second{}
|
|
|
|
|
// }
|
|
|
|
|
obj := upgrade.ApplyEntry{
|
|
|
|
|
Mobile: args.Mobile,
|
|
|
|
|
ApplyUserID: args.UserID,
|
|
|
|
@ -98,73 +95,74 @@ func (o logic) Create(args ApplyCreate) error {
|
|
|
|
|
BusinessPhoto: args.BusinessPhoto,
|
|
|
|
|
MainPhoto: args.MainPhoto,
|
|
|
|
|
ParentID: parentID,
|
|
|
|
|
ProcessTime: now,
|
|
|
|
|
// ProcessTime: now,
|
|
|
|
|
}
|
|
|
|
|
if err := tx.Create(&obj).Error; err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
if args.Kind == 1 {
|
|
|
|
|
var u1 user.RecookUserInfoModel
|
|
|
|
|
if err := tx.First(&u1, "mobile = ?", args.Mobile).Error; err != nil {
|
|
|
|
|
if err != gorm.ErrRecordNotFound {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if u1.Id == 0 {
|
|
|
|
|
mobile := args.Mobile
|
|
|
|
|
sql := `select max(id)+floor(1+rand()*5) from recook_user_info`
|
|
|
|
|
var lastId int64
|
|
|
|
|
if err := tx.Raw(sql).Count(&lastId).Error; err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
info := user.RecookUserInfoModel{
|
|
|
|
|
Id: uint(lastId),
|
|
|
|
|
Nickname: "左家右厨" + mobile[7:],
|
|
|
|
|
Mobile: mobile,
|
|
|
|
|
Birthday: formatime.NewSecondFrom(define.DefaultBirthday),
|
|
|
|
|
HeadImgUrl: "",
|
|
|
|
|
Phone: mobile,
|
|
|
|
|
Identifier: time.Now().Format("060102") + baseCode.Encode(uint64(lastId)),
|
|
|
|
|
Level: 2,
|
|
|
|
|
ParentID: 0,
|
|
|
|
|
RootID: parentID,
|
|
|
|
|
UpgradeTime2: formatime.NewSecondNow(),
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if err := tx.Create(&info).Error; err != nil {
|
|
|
|
|
tx.Rollback()
|
|
|
|
|
err = fmt.Errorf("创建用户错误101:" + err.Error())
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 生成邀请码和推荐码
|
|
|
|
|
info.InvitationNo = baseCode.Encode(uint64(info.Id))
|
|
|
|
|
if err := tx.Save(&info).Error; err != nil {
|
|
|
|
|
err = fmt.Errorf("创建用户错误102:" + err.Error())
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
// 建立钱包
|
|
|
|
|
wallet := user.RecookUserWalletModel{
|
|
|
|
|
UserId: info.Id,
|
|
|
|
|
}
|
|
|
|
|
if err := tx.Create(&wallet).Error; err != nil {
|
|
|
|
|
tx.Rollback()
|
|
|
|
|
err = fmt.Errorf("创建用户错误103:" + err.Error())
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if u1.Level < 2 {
|
|
|
|
|
if err := tx.Model(&u1).Updates(map[string]interface{}{
|
|
|
|
|
"level": 2,
|
|
|
|
|
"root_id": parentID,
|
|
|
|
|
"parent_id": 0,
|
|
|
|
|
"upgrade_time2": formatime.NewSecondNow(),
|
|
|
|
|
}).Error; err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// 需求变更 审核通过
|
|
|
|
|
// if args.Kind == 1 {
|
|
|
|
|
// var u1 user.RecookUserInfoModel
|
|
|
|
|
// if err := tx.First(&u1, "mobile = ?", args.Mobile).Error; err != nil {
|
|
|
|
|
// if err != gorm.ErrRecordNotFound {
|
|
|
|
|
// return err
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// if u1.Id == 0 {
|
|
|
|
|
// mobile := args.Mobile
|
|
|
|
|
// sql := `select max(id)+floor(1+rand()*5) from recook_user_info`
|
|
|
|
|
// var lastId int64
|
|
|
|
|
// if err := tx.Raw(sql).Count(&lastId).Error; err != nil {
|
|
|
|
|
// return err
|
|
|
|
|
// }
|
|
|
|
|
// info := user.RecookUserInfoModel{
|
|
|
|
|
// Id: uint(lastId),
|
|
|
|
|
// Nickname: "左家右厨" + mobile[7:],
|
|
|
|
|
// Mobile: mobile,
|
|
|
|
|
// Birthday: formatime.NewSecondFrom(define.DefaultBirthday),
|
|
|
|
|
// HeadImgUrl: "",
|
|
|
|
|
// Phone: mobile,
|
|
|
|
|
// Identifier: time.Now().Format("060102") + baseCode.Encode(uint64(lastId)),
|
|
|
|
|
// Level: 2,
|
|
|
|
|
// ParentID: 0,
|
|
|
|
|
// RootID: parentID,
|
|
|
|
|
// UpgradeTime2: formatime.NewSecondNow(),
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// if err := tx.Create(&info).Error; err != nil {
|
|
|
|
|
// tx.Rollback()
|
|
|
|
|
// err = fmt.Errorf("创建用户错误101:" + err.Error())
|
|
|
|
|
// return err
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// // 生成邀请码和推荐码
|
|
|
|
|
// info.InvitationNo = baseCode.Encode(uint64(info.Id))
|
|
|
|
|
// if err := tx.Save(&info).Error; err != nil {
|
|
|
|
|
// err = fmt.Errorf("创建用户错误102:" + err.Error())
|
|
|
|
|
// return err
|
|
|
|
|
// }
|
|
|
|
|
// // 建立钱包
|
|
|
|
|
// wallet := user.RecookUserWalletModel{
|
|
|
|
|
// UserId: info.Id,
|
|
|
|
|
// }
|
|
|
|
|
// if err := tx.Create(&wallet).Error; err != nil {
|
|
|
|
|
// tx.Rollback()
|
|
|
|
|
// err = fmt.Errorf("创建用户错误103:" + err.Error())
|
|
|
|
|
// return err
|
|
|
|
|
// }
|
|
|
|
|
// } else {
|
|
|
|
|
// if u1.Level < 2 {
|
|
|
|
|
// if err := tx.Model(&u1).Updates(map[string]interface{}{
|
|
|
|
|
// "level": 2,
|
|
|
|
|
// "root_id": parentID,
|
|
|
|
|
// "parent_id": 0,
|
|
|
|
|
// "upgrade_time2": formatime.NewSecondNow(),
|
|
|
|
|
// }).Error; err != nil {
|
|
|
|
|
// return err
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
}); err != nil {
|
|
|
|
|