You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
98 lines
3.9 KiB
98 lines
3.9 KiB
package user
|
|
|
|
import (
|
|
"yunyan/comm"
|
|
"yunyan/lego/sys/mysql"
|
|
"yunyan/pb"
|
|
)
|
|
|
|
// 新用户开户礼:注册即到账,不需要任何操作。
|
|
//
|
|
// ⚠️ 这是**临时**的拉新政策(2026-08-28 起)。要停掉就把 newUserGiftEnabled 置 false,
|
|
// 或直接删掉 applyNewUserGift 的调用点(api_sgin.go 里创建用户那一处)。
|
|
//
|
|
// 2026-09 起三个额度桶停用,开户礼改成「VIP 天数 + 算力」(算力归账号、不过期,见 comm/compute.go)。
|
|
// 两个数额由**后台「会员与算力」页配置**(comm.LoadOpsParams),改了不用发版;
|
|
// 配置表里没有这两行时回落到 comm 的默认值(30 天 + 100 算力)。
|
|
//
|
|
// ⚠️ 两项都配 0 = 注册不送任何东西,这是合法配置而不是「没配」——所以 ParseOpsParams
|
|
// 区分「键不存在」与「值为 0」,别改成 `if v > 0` 那种写法。
|
|
const newUserGiftEnabled = true
|
|
|
|
// applyNewUserGift 把开户礼写进尚未落库的新用户对象。
|
|
// 只在「用户不存在 → 新建」的分支调用,老用户不受影响。
|
|
//
|
|
// 直接赋值而非累加:这是刚 new 出来的对象,几个额度字段都还是零值。
|
|
// p 由调用方传入(comm.LoadOpsParams())而不是在函数里各读一次:发放与流水必须用**同一份快照**,
|
|
// 否则两次读之间后台改了配置,就会出现「送的是 A、流水记的是 B」的对不上账。
|
|
func applyNewUserGift(user *pb.DBUser, now int64, p comm.OpsParams) {
|
|
if !newUserGiftEnabled || user == nil {
|
|
return
|
|
}
|
|
if p.NewUserGiftVipDays > 0 {
|
|
user.Vipexptime = now + int64(p.NewUserGiftVipDays)*24*60*60
|
|
}
|
|
user.Computebalance = p.NewUserGiftCompute
|
|
}
|
|
|
|
// 游客权益:固定 1000 天 VIP + 1000 算力,不走后台「开户礼」配置。
|
|
//
|
|
// 游客没有手机号/支付账号,后台那档开户礼(默认 30 天 + 100 算力)不够用。
|
|
// 只抬底、不削顶:已经比这个多的(更长的会员、更多的算力)保持原值。
|
|
// 新建账号从零值抬上来就是正好 1000;存量补发用同一套比较,避免把花掉的算力再补回去——
|
|
// 存量只在启动时补一次,见 modelUserComp.grantTouristEntitlement。
|
|
const (
|
|
touristVipDays int64 = 1000
|
|
touristCompute int64 = 1000
|
|
)
|
|
|
|
// applyTouristEntitlement 把游客权益写进尚未落库的新游客。
|
|
func applyTouristEntitlement(user *pb.DBUser, now int64) {
|
|
if user == nil {
|
|
return
|
|
}
|
|
user.Vipexptime, user.Computebalance = raiseTouristEntitlement(user.Vipexptime, user.Computebalance, now)
|
|
}
|
|
|
|
// raiseTouristEntitlement 会员到期与算力向游客底线靠拢。返回值可直接写回用户。
|
|
func raiseTouristEntitlement(vipExp, compute, now int64) (int64, int64) {
|
|
floorExp := now + touristVipDays*24*60*60
|
|
if vipExp < floorExp {
|
|
vipExp = floorExp
|
|
}
|
|
if compute < touristCompute {
|
|
compute = touristCompute
|
|
}
|
|
return vipExp, compute
|
|
}
|
|
|
|
// logTouristEntitlement 记一条游客开户流水。礼包已随用户落库,流水写失败不回滚。
|
|
func logTouristEntitlement(uid string, now int64) {
|
|
_ = mysql.Insert(comm.TableUserUseLog, &pb.DBUserUseLog{
|
|
Uid: uid,
|
|
Ts: now,
|
|
Logtype: pb.UserLogType_ActivityReward,
|
|
Addvipday: touristVipDays,
|
|
Compute: touristCompute,
|
|
Extra: "tourist entitlement",
|
|
})
|
|
}
|
|
|
|
// logNewUserGift 记一条活动奖励流水,便于后台对账「送出去多少」。
|
|
// 礼包已经随用户一起落库了,这条流水写失败不回滚、只忽略。
|
|
func logNewUserGift(uid string, now int64, p comm.OpsParams) {
|
|
if !newUserGiftEnabled {
|
|
return
|
|
}
|
|
if p.NewUserGiftVipDays == 0 && p.NewUserGiftCompute == 0 {
|
|
return // 后台配成不送,就别记一条全 0 的流水
|
|
}
|
|
_ = mysql.Insert(comm.TableUserUseLog, &pb.DBUserUseLog{
|
|
Uid: uid,
|
|
Ts: now,
|
|
Logtype: pb.UserLogType_ActivityReward,
|
|
Addvipday: int64(p.NewUserGiftVipDays),
|
|
Compute: p.NewUserGiftCompute,
|
|
Extra: "new user register gift",
|
|
})
|
|
}
|
|
|