2022-06-29 08:03:50 +00:00
|
|
|
package model
|
|
|
|
|
2022-07-12 13:20:57 +00:00
|
|
|
import (
|
2022-09-29 07:49:16 +00:00
|
|
|
"fmt"
|
2022-07-12 13:20:57 +00:00
|
|
|
"github.com/codinl/go-logger"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
2022-09-29 07:49:16 +00:00
|
|
|
// gen:qs
|
2024-05-20 07:17:50 +00:00
|
|
|
//
|
|
|
|
//go:generate goqueryset -in analyse.go
|
2022-06-29 08:03:50 +00:00
|
|
|
type Statistic struct {
|
|
|
|
Model
|
|
|
|
|
2022-09-29 07:49:16 +00:00
|
|
|
Count uint32 `json:"count" gorm:"default:0"` // 计数
|
|
|
|
EventType uint32 `json:"event_type" gorm:"index"` // 类型:1-运费包曝光次数
|
2022-07-12 13:20:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const (
|
|
|
|
UserRenewalLogActionPop = 1 // 弹窗
|
|
|
|
UserRenewalLogActionEnterActivity = 2 // 进入活动
|
|
|
|
UserRenewalLogActionPickGold = 3 // 领取黄金会员
|
|
|
|
UserRenewalLogActionPickPlatinum = 4 // 领取白金会员
|
|
|
|
UserRenewalLogActionPickBlackGold = 5 // 领取黑金会员
|
|
|
|
UserRenewalLogActionUseGold = 6 // 使用黄金会员
|
|
|
|
UserRenewalLogActionUsePlatinum = 7 // 使用白金会员
|
|
|
|
UserRenewalLogActionUseBlackGold = 8 // 使用黑金会员
|
|
|
|
)
|
|
|
|
|
|
|
|
// gen:qs
|
|
|
|
type UserRenewalLog struct {
|
|
|
|
Model
|
|
|
|
|
|
|
|
Uid uint32 `json:"uid"`
|
|
|
|
Action uint32 `json:"action"`
|
|
|
|
MemberExpire time.Time `json:"member_expire"`
|
|
|
|
Type uint32 `json:"type"` // 类型:1-续费 2-升级
|
|
|
|
RenewalNum uint32 `json:"renewal_num"`
|
|
|
|
Serial uint32 `json:"serial"`
|
|
|
|
// user_renewal_log
|
|
|
|
}
|
|
|
|
|
|
|
|
func (l *UserRenewalLog) Add() error {
|
|
|
|
err := DB.Create(l).Error
|
|
|
|
if err != nil {
|
|
|
|
logger.Error("user log add err:", err)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func GetActionUserRenewalLog(uid, action uint32) (UserRenewalLog, error) {
|
|
|
|
var userRenewalLog UserRenewalLog
|
2022-09-29 07:49:16 +00:00
|
|
|
err := NewUserRenewalLogQuerySet(DB).UidEq(uid).ActionEq(action).OrderDescByID().
|
|
|
|
Limit(1).One(&userRenewalLog)
|
2022-07-12 13:20:57 +00:00
|
|
|
if err != nil && err != RecordNotFound {
|
|
|
|
logger.Error("user renewal log err:", err)
|
|
|
|
return userRenewalLog, err
|
|
|
|
}
|
|
|
|
return userRenewalLog, nil
|
2022-06-29 08:03:50 +00:00
|
|
|
}
|
2022-07-25 04:02:53 +00:00
|
|
|
|
|
|
|
// gen:qs
|
|
|
|
type UserMemberRecord struct {
|
|
|
|
Model
|
|
|
|
Uid uint32 `json:"uid" gorm:"index"`
|
|
|
|
BeforeMemberLevel uint32 `json:"before_member_level"`
|
|
|
|
AfterMemberLevel uint32 `json:"after_member_level"`
|
|
|
|
BeforeMemberExpire time.Time `json:"before_member_expire"`
|
|
|
|
AfterMemberExpire time.Time `json:"after_member_expire"`
|
|
|
|
InviteUid uint32 `json:"invite_uid" gorm:"index"`
|
|
|
|
DeductionDays uint32 `json:"deduction_days"` // 抵扣天数
|
|
|
|
DeductionFee uint32 `json:"deduction_fee"` // 抵扣金额
|
|
|
|
CouponId uint32 `json:"coupon_id"` // 优惠券id
|
|
|
|
Serial uint32 `json:"serial" gorm:"index"` // 日志
|
|
|
|
Type uint32 `json:"type" gorm:"index"` // 1-开通黄金 2-开通白金 3-开通黑金 4-续费黄金 5-续费白金 6-续费黑金 7-升级白金 8-升级黑金
|
|
|
|
OpenMemberLevel uint32 `json:"open_member_level"`
|
|
|
|
OpenMemberTime time.Time `json:"open_member_time"`
|
2022-11-15 01:58:21 +00:00
|
|
|
|
|
|
|
// user_member_record
|
2022-07-25 04:02:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func GetUserMemberRecordType(level uint32, memberType uint32) uint32 {
|
2024-05-20 07:17:50 +00:00
|
|
|
if memberType == 1 { // 开通会员
|
2022-07-25 04:02:53 +00:00
|
|
|
switch level {
|
2024-05-20 07:17:50 +00:00
|
|
|
case 2: // 黄金
|
|
|
|
return 1 //开通黄金
|
|
|
|
case 4: // 白金
|
|
|
|
return 2 // 开通白金
|
|
|
|
case 5: // 黑金
|
|
|
|
return 3 // 开通黑金
|
2022-07-25 04:02:53 +00:00
|
|
|
}
|
2024-05-20 07:17:50 +00:00
|
|
|
} else if memberType == 2 { // 续费会员
|
2022-07-25 04:02:53 +00:00
|
|
|
switch level {
|
2024-05-20 07:17:50 +00:00
|
|
|
case 2: // 黄金
|
|
|
|
return 4 //续费黄金
|
|
|
|
case 4: // 白金
|
|
|
|
return 5 //续费白金
|
|
|
|
case 5: // 黑金
|
|
|
|
return 6 //续费黑金
|
2022-07-25 04:02:53 +00:00
|
|
|
}
|
2024-05-20 07:17:50 +00:00
|
|
|
} else if memberType == 3 { // 升级会员
|
2022-07-25 04:02:53 +00:00
|
|
|
switch level {
|
2024-05-20 07:17:50 +00:00
|
|
|
case 4: // 白金
|
|
|
|
return 7 // 升级白金
|
|
|
|
case 5: // 黑金
|
|
|
|
return 8 // 升级黑金
|
2022-07-25 04:02:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *UserMemberRecord) Add() {
|
|
|
|
go func() {
|
|
|
|
err := DB.Create(m).Error
|
|
|
|
if err != nil {
|
|
|
|
logger.Error("create user member record err:", err)
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
}
|
2022-09-29 07:49:16 +00:00
|
|
|
|
|
|
|
// gen:qs
|
|
|
|
type UserActionLog struct {
|
|
|
|
Model
|
|
|
|
|
|
|
|
Uid uint32 `json:"uid" gorm:"index"`
|
|
|
|
ActionType uint32 `json:"action_type"` // 1-运费包_领券送时长专题页 2-运费包_购买运费包
|
|
|
|
First uint32 `json:"first"` // 1-首次
|
|
|
|
// user_action_log
|
|
|
|
}
|
|
|
|
|
|
|
|
func IsFirstUserAction(uid, actionType uint32) (bool, error) {
|
|
|
|
return QueryRecordExist(fmt.Sprintf("SELECT * FROM user_action_log WHERE uid=%d AND action_type=%d", uid, actionType))
|
|
|
|
}
|