feat: vip history

master
howell 3 years ago
parent fc109cb2ef
commit df962f0f33

@ -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),
})
}
}

@ -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)

@ -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"
}

@ -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())

Loading…
Cancel
Save