优化特权存储时机+ 过滤
This commit is contained in:
parent
11fd4ceb56
commit
f9f521c6f9
@ -3,12 +3,9 @@ package privilege
|
|||||||
import (
|
import (
|
||||||
"go_dreamfactory/comm"
|
"go_dreamfactory/comm"
|
||||||
"go_dreamfactory/lego/core"
|
"go_dreamfactory/lego/core"
|
||||||
"go_dreamfactory/lego/sys/mgo"
|
|
||||||
"go_dreamfactory/modules"
|
"go_dreamfactory/modules"
|
||||||
"go_dreamfactory/pb"
|
"go_dreamfactory/pb"
|
||||||
"go_dreamfactory/sys/configure"
|
|
||||||
|
|
||||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
|
||||||
"go.mongodb.org/mongo-driver/mongo"
|
"go.mongodb.org/mongo-driver/mongo"
|
||||||
"go.mongodb.org/mongo-driver/x/bsonx"
|
"go.mongodb.org/mongo-driver/x/bsonx"
|
||||||
)
|
)
|
||||||
@ -33,16 +30,8 @@ func (this *ModelVip) Init(service core.IService, module core.IModule, comp core
|
|||||||
// 获取vip信息
|
// 获取vip信息
|
||||||
func (this *ModelVip) getVipList(uid string) (vip *pb.DBVip, err error) {
|
func (this *ModelVip) getVipList(uid string) (vip *pb.DBVip, err error) {
|
||||||
vip = &pb.DBVip{}
|
vip = &pb.DBVip{}
|
||||||
if err = this.Get(uid, vip); err == mgo.MongodbNil { // 没有数据 直接创建一条
|
if err = this.Get(uid, vip); err != nil {
|
||||||
|
return
|
||||||
vip.Id = primitive.NewObjectID().Hex()
|
|
||||||
vip.CTime = configure.Now().Unix()
|
|
||||||
if err = this.Add(uid, vip); err != nil {
|
|
||||||
this.module.Errorf("err:%v", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
err = nil
|
|
||||||
return vip, err
|
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -51,3 +40,14 @@ func (this *ModelVip) getVipList(uid string) (vip *pb.DBVip, err error) {
|
|||||||
func (this *ModelVip) modifyVipData(uid string, data map[string]interface{}) error {
|
func (this *ModelVip) modifyVipData(uid string, data map[string]interface{}) error {
|
||||||
return this.Change(uid, data)
|
return this.Change(uid, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 增加vip信息
|
||||||
|
func (this *ModelVip) addVipData(uId string, vip *pb.DBVip) (err error) {
|
||||||
|
|
||||||
|
if err = this.Add(uId, vip); err != nil {
|
||||||
|
this.module.Errorf("err:%v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
@ -4,10 +4,10 @@ import (
|
|||||||
"go_dreamfactory/comm"
|
"go_dreamfactory/comm"
|
||||||
"go_dreamfactory/lego/core"
|
"go_dreamfactory/lego/core"
|
||||||
"go_dreamfactory/lego/sys/event"
|
"go_dreamfactory/lego/sys/event"
|
||||||
|
"go_dreamfactory/lego/sys/mgo"
|
||||||
"go_dreamfactory/modules"
|
"go_dreamfactory/modules"
|
||||||
"go_dreamfactory/pb"
|
"go_dreamfactory/pb"
|
||||||
"go_dreamfactory/sys/configure"
|
"go_dreamfactory/sys/configure"
|
||||||
"go_dreamfactory/sys/db"
|
|
||||||
"go_dreamfactory/utils"
|
"go_dreamfactory/utils"
|
||||||
|
|
||||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||||
@ -46,6 +46,7 @@ func (this *Privilege) OnInstallComp() {
|
|||||||
this.api_comp = this.RegisterComp(new(apiComp)).(*apiComp)
|
this.api_comp = this.RegisterComp(new(apiComp)).(*apiComp)
|
||||||
this.modelPrivilege = this.RegisterComp(new(ModelPrivilege)).(*ModelPrivilege)
|
this.modelPrivilege = this.RegisterComp(new(ModelPrivilege)).(*ModelPrivilege)
|
||||||
this.configure = this.RegisterComp(new(configureComp)).(*configureComp)
|
this.configure = this.RegisterComp(new(configureComp)).(*configureComp)
|
||||||
|
this.modelVip = this.RegisterComp(new(ModelVip)).(*ModelVip)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *Privilege) Start() (err error) {
|
func (this *Privilege) Start() (err error) {
|
||||||
@ -61,7 +62,7 @@ func (this *Privilege) Start() (err error) {
|
|||||||
|
|
||||||
//Event------------------------------------------------------------------------------------------------------------
|
//Event------------------------------------------------------------------------------------------------------------
|
||||||
func (this *Privilege) EventUserOffline(session comm.IUserSession) {
|
func (this *Privilege) EventUserOffline(session comm.IUserSession) {
|
||||||
this.modelPrivilege.DelByUId(session.GetUserId(), db.SetDBMgoLog(false))
|
//this.modelPrivilege.DelByUId(session.GetUserId(), db.SetDBMgoLog(false))
|
||||||
}
|
}
|
||||||
|
|
||||||
// 购买了一个新的特权
|
// 购买了一个新的特权
|
||||||
@ -82,20 +83,23 @@ func (this *Privilege) CreatePrivilegeCard(session comm.IUserSession, cId string
|
|||||||
}
|
}
|
||||||
for _, v := range list {
|
for _, v := range list {
|
||||||
if v.CId == cId {
|
if v.CId == cId {
|
||||||
|
update := map[string]interface{}{}
|
||||||
if v.ETime > configure.Now().Unix() { // 加时间
|
if v.ETime > configure.Now().Unix() { // 加时间
|
||||||
v.ETime += int64(conf.AssertDay) * 24 * 3600
|
|
||||||
} else {
|
|
||||||
// 检测能否续费
|
// 检测能否续费
|
||||||
if configure.Now().Unix()-v.ETime <= int64(conf.RenewDay)*24*3600 {
|
if v.ETime-configure.Now().Unix() > int64(conf.RenewDay)*24*3600 {
|
||||||
v.ETime = configure.Now().Unix() + int64(conf.AssertDay)*24*3600
|
|
||||||
} else {
|
|
||||||
code = pb.ErrorCode_PayRenewTimeErr
|
code = pb.ErrorCode_PayRenewTimeErr
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
v.ETime += int64(conf.AssertDay) * 24 * 3600
|
||||||
|
update["eTime"] = v.ETime
|
||||||
|
} else { // 过期了
|
||||||
|
v.CTime = configure.Now().Unix()
|
||||||
|
v.ETime = v.CTime + int64(conf.AssertDay)*24*3600
|
||||||
|
update["cTime"] = v.CTime
|
||||||
|
update["eTime"] = v.ETime
|
||||||
}
|
}
|
||||||
if err = this.modelPrivilege.Change(session.GetUserId(), map[string]interface{}{
|
if err = this.modelPrivilege.Change(session.GetUserId(), update); err != nil {
|
||||||
"eTime": v.ETime,
|
|
||||||
}); err != nil {
|
|
||||||
this.Errorf("err:%v", err)
|
this.Errorf("err:%v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -103,36 +107,55 @@ func (this *Privilege) CreatePrivilegeCard(session comm.IUserSession, cId string
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !bFind {
|
if !bFind { // 创建一条新的信息
|
||||||
|
|
||||||
data := &pb.DBPrivilege{
|
data := &pb.DBPrivilege{
|
||||||
Id: primitive.NewObjectID().Hex(),
|
Id: primitive.NewObjectID().Hex(),
|
||||||
Uid: session.GetUserId(),
|
Uid: session.GetUserId(),
|
||||||
CId: cId,
|
CId: cId,
|
||||||
|
|
||||||
CTime: configure.Now().Unix(),
|
CTime: configure.Now().Unix(),
|
||||||
ETime: 0,
|
ETime: configure.Now().Unix() + int64(conf.AssertDay*24*3600), // 设置过期时间
|
||||||
RewardTime: configure.Now().Unix(),
|
RewardTime: configure.Now().Unix(),
|
||||||
}
|
}
|
||||||
data.ETime = configure.Now().Unix() + int64(conf.AssertDay*24*3600) // 设置过期时间
|
|
||||||
|
|
||||||
// 特权插入
|
// 特权插入
|
||||||
vip, err := this.modelVip.getVipList(session.GetUserId())
|
vip, err := this.modelVip.getVipList(session.GetUserId())
|
||||||
if err == nil {
|
if err != nil && err == mgo.MongodbNil { // 没有数据 直接创建一条
|
||||||
|
vip = &pb.DBVip{
|
||||||
|
Id: primitive.NewObjectID().Hex(),
|
||||||
|
Uid: session.GetUserId(),
|
||||||
|
Reward: map[int32]bool{},
|
||||||
|
Privilege: map[int32]*pb.PrivilegeData{},
|
||||||
|
CTime: configure.Now().Unix(),
|
||||||
|
RewardTime: 0,
|
||||||
|
}
|
||||||
|
if err = this.modelVip.addVipData(session.GetUserId(), vip); err != nil {
|
||||||
|
this.Errorf("err:%v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if vip.Id != "" {
|
||||||
update := map[string]interface{}{}
|
update := map[string]interface{}{}
|
||||||
for _, v := range conf.PrivilegeId {
|
for _, v := range conf.PrivilegeId {
|
||||||
conf := this.configure.GetPrivilegeData(v)
|
conf := this.configure.GetPrivilegeData(v)
|
||||||
if conf != nil {
|
if conf != nil {
|
||||||
|
|
||||||
if _, ok := vip.Privilege[conf.PrivilegeType]; ok {
|
if _, ok := vip.Privilege[conf.PrivilegeType]; ok {
|
||||||
vip.Privilege[conf.PrivilegeType].PrivilegeID = append(vip.Privilege[conf.PrivilegeType].PrivilegeID, v)
|
// 过滤重复的特权
|
||||||
|
bRepeat := false
|
||||||
|
for _, v1 := range vip.Privilege[conf.PrivilegeType].PrivilegeID {
|
||||||
|
if v1 == v {
|
||||||
|
bRepeat = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !bRepeat {
|
||||||
|
vip.Privilege[conf.PrivilegeType].PrivilegeID = append(vip.Privilege[conf.PrivilegeType].PrivilegeID, v)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
sz := &pb.PrivilegeData{}
|
sz := &pb.PrivilegeData{}
|
||||||
sz.PrivilegeID = append(sz.PrivilegeID, v)
|
sz.PrivilegeID = append(sz.PrivilegeID, v)
|
||||||
vip.Privilege[conf.PrivilegeType] = sz
|
vip.Privilege[conf.PrivilegeType] = sz
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
update["privilege"] = vip.Privilege
|
update["privilege"] = vip.Privilege
|
||||||
this.modelVip.modifyVipData(session.GetUserId(), update)
|
this.modelVip.modifyVipData(session.GetUserId(), update)
|
||||||
@ -141,7 +164,7 @@ func (this *Privilege) CreatePrivilegeCard(session comm.IUserSession, cId string
|
|||||||
this.modelPrivilege.addNewPrivilegeData(session.GetUserId(), data)
|
this.modelPrivilege.addNewPrivilegeData(session.GetUserId(), data)
|
||||||
this.SendDailyMail(session, cId, 1, conf.PType)
|
this.SendDailyMail(session, cId, 1, conf.PType)
|
||||||
}
|
}
|
||||||
|
// 即使奖励 马上发送
|
||||||
if code = this.DispenseRes(session, conf.DisposableReward, true); code != pb.ErrorCode_Success {
|
if code = this.DispenseRes(session, conf.DisposableReward, true); code != pb.ErrorCode_Success {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -223,9 +246,6 @@ func (this *Privilege) CheckDailyPrivilegeMail(session comm.IUserSession) {
|
|||||||
}
|
}
|
||||||
if v.ETime < configure.Now().Unix() { // 判断当前特权是否过期
|
if v.ETime < configure.Now().Unix() { // 判断当前特权是否过期
|
||||||
|
|
||||||
if err := this.modelPrivilege.DelListlds(session.GetUserId(), v.Id); err != nil {
|
|
||||||
this.Errorf("delete privilege failed:%v", err)
|
|
||||||
}
|
|
||||||
update := map[string]interface{}{}
|
update := map[string]interface{}{}
|
||||||
for _, id := range conf.PrivilegeId { // 找到过期的特权 并删除
|
for _, id := range conf.PrivilegeId { // 找到过期的特权 并删除
|
||||||
data := this.configure.GetPrivilegeData(id)
|
data := this.configure.GetPrivilegeData(id)
|
||||||
@ -307,8 +327,19 @@ func (this *Privilege) AddVipData(session comm.IUserSession, oldVip, newVip int3
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
vip, err := this.modelVip.getVipList(session.GetUserId())
|
vip, err := this.modelVip.getVipList(session.GetUserId())
|
||||||
if err != nil {
|
if err != nil && err == mgo.MongodbNil { // 没有数据 直接创建一条
|
||||||
return
|
vip = &pb.DBVip{
|
||||||
|
Id: primitive.NewObjectID().Hex(),
|
||||||
|
Uid: session.GetUserId(),
|
||||||
|
Reward: map[int32]bool{},
|
||||||
|
Privilege: map[int32]*pb.PrivilegeData{},
|
||||||
|
CTime: configure.Now().Unix(),
|
||||||
|
RewardTime: 0,
|
||||||
|
}
|
||||||
|
if err = this.modelVip.addVipData(session.GetUserId(), vip); err != nil {
|
||||||
|
this.Errorf("err:%v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
update := map[string]interface{}{}
|
update := map[string]interface{}{}
|
||||||
for i := oldVip; i < newVip; i++ {
|
for i := oldVip; i < newVip; i++ {
|
||||||
|
Loading…
Reference in New Issue
Block a user