diff --git a/internal/v2/controller/manage/jyy/activity.go b/internal/v2/controller/manage/jyy/activity.go index c77cb92..e255fd6 100644 --- a/internal/v2/controller/manage/jyy/activity.go +++ b/internal/v2/controller/manage/jyy/activity.go @@ -39,7 +39,16 @@ func (o Proxy) CreateActiviy(c *gin.Context) { } func (o Proxy) UpdateActiviy(c *gin.Context) { - + var args jyy.ActivityInfoUpdate + if err := tools.Params(&args, c); err != nil { + back.Fail(c, err.Error()) + return + } + if err := jyy.Logic.UpdateActiviy(args); err != nil { + back.Fail(c, err.Error()) + } else { + back.Suc(c, "ok", "") + } } func (o Proxy) DeleteActiviy(c *gin.Context) { diff --git a/internal/v2/logic/app/upgrade/upgrade.go b/internal/v2/logic/app/upgrade/upgrade.go index acefd99..57b5ec5 100644 --- a/internal/v2/logic/app/upgrade/upgrade.go +++ b/internal/v2/logic/app/upgrade/upgrade.go @@ -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 { diff --git a/internal/v2/logic/manage/jyy/activity.go b/internal/v2/logic/manage/jyy/activity.go index 27d4c13..d255265 100644 --- a/internal/v2/logic/manage/jyy/activity.go +++ b/internal/v2/logic/manage/jyy/activity.go @@ -5,6 +5,7 @@ import ( "recook/internal/v2/model/jyy" "git.oa00.com/go/mysql" + "gorm.io/gorm" ) type ActivityList struct { @@ -14,13 +15,12 @@ type ActivityList struct { func (o logic) GetActivites(args ActivityList) (res []jyy.Activity, total int64, err error) { query := mysql.Db.Table((&jyy.Activity{}).TableName()) query.Count(&total) - query.Limit(args.GetLimit()).Offset(args.GetStart()).Find(&res) + query.Preload("GoodsList.GoodsInfo").Limit(args.GetLimit()).Offset(args.GetStart()).Find(&res) return } type ActivityInfo struct { jyy.Activity - } func (o logic) CreateActiviy(obj ActivityInfo) error { @@ -31,8 +31,20 @@ func (o logic) CreateActiviy(obj ActivityInfo) error { return nil } -func (o logic) UpdateActiviy() { +type ActivityInfoUpdate struct { + jyy.Activity + Name string `json:"name"` + Icon string `json:"icon"` +} +func (o logic) UpdateActiviy(obj ActivityInfoUpdate) error { + if obj.ID == 0 { + return gorm.ErrRecordNotFound + } + if err := mysql.Db.Model(&obj).Updates(obj).Error; err != nil { + return err + } + return nil } func (o logic) DeleteActiviy() { diff --git a/internal/v2/logic/manage/upgrade/upgrade.go b/internal/v2/logic/manage/upgrade/upgrade.go index 46d31f1..888cd8a 100644 --- a/internal/v2/logic/manage/upgrade/upgrade.go +++ b/internal/v2/logic/manage/upgrade/upgrade.go @@ -26,6 +26,7 @@ type ApplyList struct { State upgrade.State `json:"state" validate:"oneof=0 1 2 3"` Mobile string `json:"mobile"` ApplyUserName string `json:"apply_user_name"` + Kind uint `json:"kind"` } func (o logic) List(args ApplyList) (res []upgrade.ApplyEntry, total int64, err error) { @@ -42,6 +43,9 @@ func (o logic) List(args ApplyList) (res []upgrade.ApplyEntry, total int64, err Select("id").Where("nickname like ?", fmt.Sprintf("%%%s%%", args.ApplyUserName)) query = query.Where("apply_user_id in (?)", sub) } + if args.Kind != 0 { + query = query.Where("kind=?", args.Kind) + } } query.Count(&total) query.Preload(clause.Associations).Limit(args.GetLimit()).Offset(args.GetStart()).Find(&res) @@ -62,14 +66,14 @@ func (o logic) Sure(args ApplySure) error { var mu user.RecookUserInfoModel mysql.Db.First(&mu, "mobile=?") - if mu.Level > 0 { - return nil - } - mobile := ae.Mobile if len(mobile) != 11 || !strings.HasPrefix(mobile, "1") { return fmt.Errorf("手机格式不正确") } + offline := true + if ae.Kind == 1 { + offline = false + } if mu.Id == 0 { // 没有就创建 if err := mysql.Db.Transaction(func(tx *gorm.DB) error { @@ -90,7 +94,7 @@ func (o logic) Sure(args ApplySure) error { Level: 2, ParentID: 0, RootID: ae.ParentID, - IsOffline: true, + IsOffline: offline, UpgradeTime2: formatime.NewSecondNow(), } @@ -142,7 +146,7 @@ func (o logic) Sure(args ApplySure) error { "parent_id": 0, "root_id": ae.ParentID, "upgrade_time1": formatime.NewSecondNow(), - "is_offline": true, + "is_offline": offline, }).Error; err != nil { return err } diff --git a/internal/v2/model/jyy/jyy.go b/internal/v2/model/jyy/jyy.go index 2fbd29a..505967f 100644 --- a/internal/v2/model/jyy/jyy.go +++ b/internal/v2/model/jyy/jyy.go @@ -43,22 +43,18 @@ type Activity struct { Icon string `json:"icon" validate:"required"` OrderSort int `json:"order_sort"` Status bool `json:"status"` - GoodsList []ActivityGoods `json:"goods_list" gorm:"foreignKey:activity_id"` - GoodsName []string `json:"goods_name" gorm:"-"` + GoodsList []ActivityGoods `json:"goods_list" gorm:"foreignKey:ActivityID"` } func (o Activity) TableName() string { return "jyy_activity" } func (o *Activity) AfterFind(db *gorm.DB) error { - for _, v := range o.GoodsList { - o.GoodsName = append(o.GoodsName, v.GoodsName) - } return nil } type ActivityGoods struct { - ID uint `json:"-"` + ID uint `json:"id"` ActivityID uint `json:"activity_id"` GoodsID uint `json:"goods_id"` GoodsInfo goods.RecookGoodsInfoModel `json:"-" gorm:"foreignKey:goods_id"`