diff --git a/internal/api/mobile/pay/public/pay_success.go b/internal/api/mobile/pay/public/pay_success.go index 7c16561..2ccef35 100755 --- a/internal/api/mobile/pay/public/pay_success.go +++ b/internal/api/mobile/pay/public/pay_success.go @@ -89,7 +89,8 @@ func PaySuccessCallback(tx *gorm.DB, orderInfo order.Information, completeTime f if err := tx.First(&u1, "id = ?", orderInfo.UserID).Error; err != nil { return err } - if u1.Level == 10 { + if u1.IsVip() { + // 合伙人或者真实vip店铺无需操作 return nil } else { var sku goods.Sku @@ -125,6 +126,32 @@ func PaySuccessCallback(tx *gorm.DB, orderInfo order.Information, completeTime f if err := tx.Table((&user.Information{}).TableName()).Where("id = ?", u1.ID).Updates(patch).Error; err != nil { return err } + kind := user.Month + if sku.EffectDayType == 1 { + // 七天体验 + kind = user.SevenDay + } + switch sku.EffectTime { + case 1: + kind = user.Month + case 3: + kind = user.Third + case 12: + kind = user.Year + } + tx.Create(&user.VipHistory{ + UserID: int(orderInfo.UserID), + Name: kind.Str(), + Start: &now, + End: &end, + Amount: orderInfo.ActualTotalAmount, + Level: u1.Level, + NickName: u1.Nickname, + Mobile: u1.Mobile, + Kind: kind, + ShareID: int(orderInfo.SharerID), + OrderID: uint64(orderInfo.ID), + }) } } diff --git a/internal/model/user/info.go b/internal/model/user/info.go index 1eb3050..c837eb3 100755 --- a/internal/model/user/info.go +++ b/internal/model/user/info.go @@ -72,6 +72,10 @@ func (i *Information) TableName() string { return "recook_user_info" } +func (i *Information) IsVip() bool { + return i.Level == 10 || (i.Level == 2 && i.IsOffline && !i.VipUpgradeEnd.Valid) +} + func (i *Information) BeforeCreate() (err error) { if len(i.Mobile) == 11 { pr, e := phonedata.Find(i.Mobile) diff --git a/internal/model/user/vip.go b/internal/model/user/vip.go index 19a8fe7..e7ff729 100644 --- a/internal/model/user/vip.go +++ b/internal/model/user/vip.go @@ -2,15 +2,46 @@ package user import ( "time" + + "github.com/shopspring/decimal" +) + +type Kind int + +const ( + SevenDay Kind = 1 + iota + Month + Third + Year ) -type Recovery struct { - ID int - UserID int - EndTime time.Time - EntryID int +var kindMap = map[Kind]string{ + SevenDay: "7天权益卡", + Month: "月卡", + Third: "季卡", + Year: "年卡", +} + +func (o Kind) Str() string { + return kindMap[o] +} + +type VipHistory struct { + ID int `json:"id"` + UserID int `json:"user_id"` + Name string `json:"name"` + Start *time.Time `json:"start"` + End *time.Time `json:"end"` + CreatedAt *time.Time `json:"created_at" gorm:"autoCreateTime"` + Amount decimal.Decimal `json:"amount"` + Level int `json:"level"` + NickName string `json:"nickname"` + Mobile string `json:"mobile"` + Kind Kind `json:"kind"` + ShareID int `json:"share_id"` + OrderID uint64 `json:"order_id"` } -func (o Recovery) TableName() string { - return "recook_vip_recovery" +func (o VipHistory) TableName() string { + return "recook_user_vip_history" } diff --git a/internal/v2/controller/app/vip/vip.go b/internal/v2/controller/app/vip/vip.go index 960c3c6..601704a 100644 --- a/internal/v2/controller/app/vip/vip.go +++ b/internal/v2/controller/app/vip/vip.go @@ -71,6 +71,10 @@ func (o Proxy) VipActive(c *gin.Context) { var u1 user.Information mysql.Db.First(&u1, "id = ?", id) + if u1.IsVip() { + dbc.Rds.SAdd(key2, id) + return + } patch := make(map[string]interface{}) patch["level"] = 2 @@ -100,6 +104,20 @@ func (o Proxy) VipActive(c *gin.Context) { if r1, _ := res.Result(); r1 == 0 { return errors.New("已使用") } + kind := user.SevenDay + tx.Create(&user.VipHistory{ + UserID: int(id), + Name: kind.Str(), + Start: &now, + End: &end, + Amount: decimal.Zero, + Level: u1.Level, + NickName: u1.Nickname, + Mobile: u1.Mobile, + Kind: kind, + ShareID: int(id), + OrderID: 0, + }) return nil }); err != nil { back.Fail(c, err.Error())