|
|
|
@ -41,10 +41,59 @@ func (this *modelUserComp) Init(service core.IService, module core.IModule, comp |
|
|
|
this.module.Errorln(err) |
|
|
|
} |
|
|
|
this.migrateLegacyBucketsToCompute() |
|
|
|
this.grantTouristEntitlement() |
|
|
|
|
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
// touristEntitlementKey 游客权益补发标记。存在即不再跑,避免把花掉的算力再补回 1000。
|
|
|
|
const touristEntitlementKey = "TOURIST_ENTITLEMENT_1000" |
|
|
|
|
|
|
|
// 与 findtouristformac 同一口径:所有登录身份都空,才是游客。NULL 与空串都算空。
|
|
|
|
const touristIdentitySQL = "COALESCE(phone,'')='' AND COALESCE(mail,'')='' AND COALESCE(account,'')='' " + |
|
|
|
"AND COALESCE(wxopenid,'')='' AND COALESCE(googleopenid,'')='' " + |
|
|
|
"AND COALESCE(facebookopenid,'')='' AND COALESCE(appleopenid,'')=''" |
|
|
|
|
|
|
|
// grantTouristEntitlement 给存量游客补到 1000 天 VIP、1000 算力。只跑一次。
|
|
|
|
//
|
|
|
|
// 只抬底:会员已经更长、算力已经更多的不动。禁用账号不补。
|
|
|
|
// 比较用的是「此刻起 1000 天」,所以会员剩 10 天的会被续到 1000 天,剩 2000 天的保持不动。
|
|
|
|
func (this *modelUserComp) grantTouristEntitlement() { |
|
|
|
marker := &pb.DBAppConfigItem{} |
|
|
|
if err := mysql.FindOne(comm.TableAppConfig, marker, "`key`=?", touristEntitlementKey); err == nil { |
|
|
|
return |
|
|
|
} else if err != mysql.ErrNoDocuments { |
|
|
|
this.module.Warn("游客权益:读标记失败,本次跳过", log.Field{Key: "err", Value: err.Error()}) |
|
|
|
return |
|
|
|
} |
|
|
|
sec := touristVipDays * 24 * 60 * 60 |
|
|
|
res := mysql.Exec( |
|
|
|
"UPDATE "+comm.TableUser+" SET "+ |
|
|
|
"computebalance = GREATEST(computebalance, ?), "+ |
|
|
|
"vipexptime = GREATEST(vipexptime, UNIX_TIMESTAMP() + ?) "+ |
|
|
|
"WHERE "+touristIdentitySQL+" AND state = ? "+ |
|
|
|
"AND (computebalance < ? OR vipexptime < UNIX_TIMESTAMP() + ?)", |
|
|
|
touristCompute, sec, int32(pb.UserState_Normal), touristCompute, sec) |
|
|
|
if res.Error != nil { |
|
|
|
this.module.Error("游客权益:补发失败", log.Field{Key: "err", Value: res.Error.Error()}) |
|
|
|
return |
|
|
|
} |
|
|
|
if err := mysql.Insert(comm.TableAppConfig, &pb.DBAppConfigItem{ |
|
|
|
Group: "compute", Key: touristEntitlementKey, Value: "1", |
|
|
|
Description: "存量游客已补到 1000 天 VIP + 1000 算力(自动迁移标记,勿删)", |
|
|
|
}); err != nil { |
|
|
|
// 同一容器里 home/api 会各跑一次。另一边已经写过标记就不必再警告。
|
|
|
|
again := &pb.DBAppConfigItem{} |
|
|
|
if mysql.FindOne(comm.TableAppConfig, again, "`key`=?", touristEntitlementKey) == nil { |
|
|
|
this.module.Infof("游客权益:已为 %d 个游客补到底线", res.RowsAffected) |
|
|
|
return |
|
|
|
} |
|
|
|
this.module.Warn("游客权益:写标记失败,下次启动会再补一次", log.Field{Key: "err", Value: err.Error()}) |
|
|
|
return |
|
|
|
} |
|
|
|
this.module.Infof("游客权益:已为 %d 个游客补到底线", res.RowsAffected) |
|
|
|
} |
|
|
|
|
|
|
|
// legacyComputeMigratedKey config 表里的一次性迁移标记;存在即不再跑。
|
|
|
|
const legacyComputeMigratedKey = "COMPUTE_LEGACY_MIGRATED" |
|
|
|
|
|
|
|
|