This commit is contained in:
liwei1dao 2022-11-09 16:58:47 +08:00
commit 61a17f909b
11 changed files with 124 additions and 53 deletions

View File

@ -1,8 +1,7 @@
[
{
"id": 1,
"id": "yueka_lv1",
"name": "经典月卡",
"proid": "yueka_lv1",
"assert_day": 30,
"renew_day": 3,
"day_reward": [
@ -24,9 +23,8 @@
]
},
{
"id": 2,
"id": "yueka_lv2",
"name": "典藏月卡",
"proid": "yueka_lv2",
"assert_day": 30,
"renew_day": 3,
"day_reward": [

View File

@ -30,6 +30,7 @@ const (
ItemType = "item" //道具物品资源
HeroType = "hero" //卡片资源 例如英雄卡,检验卡
EquipmentType = "equi" //武器资源
VipType = "vip" //vip
)
type Autogenerated struct {

View File

@ -234,9 +234,9 @@ type (
}
IPrivilege interface {
// 创建一个新的特权卡
CreatePrivilegeCard(session IUserSession, cid int32) (data *pb.DBPrivilege, code pb.ErrorCode)
CreatePrivilegeCard(session IUserSession, cId string) (res []*pb.UserAssets, code pb.ErrorCode)
// 续费特权卡
RenewPrivilegeCard(session IUserSession, cid int32) (data *pb.DBPrivilege, code pb.ErrorCode)
RenewPrivilegeCard(session IUserSession, cId string) (res []*pb.UserAssets, code pb.ErrorCode)
// 检查特权
CheckPrivilege(session IUserSession)
}

View File

@ -68,7 +68,7 @@ func (this *GM) CreateCmd(session comm.IUserSession, cmd string) (code pb.ErrorC
this.Debugf("create CMD :%s", cmd) // 打印个日志方便查询
datas := strings.Split(keys[1], ",")
if len(datas) == 3 && (datas[0] == comm.AttrType || datas[0] == comm.ItemType ||
datas[0] == comm.HeroType || datas[0] == comm.EquipmentType) {
datas[0] == comm.HeroType || datas[0] == comm.EquipmentType || datas[0] == comm.VipType) {
num, err := strconv.Atoi(datas[2])
if err != nil {
code = pb.ErrorCode_ReqParameterError

View File

@ -37,6 +37,7 @@ type ModuleBase struct {
ModuleFriend comm.IFriend //好友
ModuleRtask comm.IRtask //随机任务
ModuleSociaty comm.ISociaty //公会
ModulePrivilege comm.IPrivilege // 月卡
}
//重构模块配置对象
@ -106,6 +107,11 @@ func (this *ModuleBase) Start() (err error) {
return
}
this.ModuleSociaty = module.(comm.ISociaty)
if module, err = this.service.GetModule(comm.ModulePrivilege); err != nil {
return
}
this.ModulePrivilege = module.(comm.IPrivilege)
return
}
@ -315,11 +321,13 @@ func (this *ModuleBase) DispenseRes(session comm.IUserSession, res []*cfg.Gameat
heros map[string]int32 // 英雄
attrs map[string]int32 // 属性
equips map[string]uint32 // 装备
vip map[string]int32 // vip
)
items = make(map[string]int32, 0)
heros = make(map[string]int32, 0)
attrs = make(map[string]int32, 0)
equips = make(map[string]uint32, 0)
vip = make(map[string]int32, 0)
for _, v := range res {
switch v.A {
@ -333,6 +341,8 @@ func (this *ModuleBase) DispenseRes(session comm.IUserSession, res []*cfg.Gameat
if v.N > 0 { // 不允许减少装备
equips[v.T] += uint32(v.N)
}
case comm.VipType:
vip[v.T] += v.N
default:
this.Errorf("not found res type") // 找不到资源类型
}
@ -354,7 +364,13 @@ func (this *ModuleBase) DispenseRes(session comm.IUserSession, res []*cfg.Gameat
code = this.ModuleEquipment.AddNewEquipments(session, equips, bPush)
this.Debugf("发放装备资源: %v [%v]", equips, code)
}
if len(vip) > 0 { //卡片资源
for k := range vip {
_, code = this.ModulePrivilege.CreatePrivilegeCard(session, k)
this.Debugf("发放月卡资源: %v [%v]", k, code)
}
}
return
}

View File

@ -28,7 +28,7 @@ func (this *configureComp) Init(service core.IService, module core.IModule, comp
return
}
func (this *configureComp) GetPrivilegeCard(id int32) (configure *cfg.GamePrivilegeCardData, err error) {
func (this *configureComp) GetPrivilegeCard(id string) (configure *cfg.GamePrivilegeCardData, err error) {
var (
v interface{}
ok bool

View File

@ -49,42 +49,93 @@ func (this *Privilege) EventUserOffline(session comm.IUserSession) {
}
// 购买了一个新的特权
func (this *Privilege) CreatePrivilegeCard(session comm.IUserSession, cid int32) (data *pb.DBPrivilege, code pb.ErrorCode) {
func (this *Privilege) CreatePrivilegeCard(session comm.IUserSession, cId string) (res []*pb.UserAssets, code pb.ErrorCode) {
var (
data *pb.DBPrivilege
bFind bool
)
atn := &pb.UserAssets{
A: "vip",
T: "",
N: 1,
}
conf, err := this.configure.GetPrivilegeCard(cId)
if err != nil {
code = pb.ErrorCode_ConfigNoFound
return nil, code
}
// 是不是购买过
list, err := this.modelPrivilege.getPrivilegeList(session.GetUserId())
if err != nil {
code = pb.ErrorCode_DBError
return
}
for _, v := range list {
if v.CId == cId {
if v.ETime > configure.Now().Unix() { // 加时间
v.ETime += int64(conf.AssertDay) * 24 * 3600
} else {
v.ETime = configure.Now().Unix() + int64(conf.AssertDay)*24*3600
}
if err = this.modelPrivilege.Change(session.GetUserId(), map[string]interface{}{
"eTime": v.ETime,
}); err != nil {
this.Errorf("err:%v", err)
return
}
data = v
bFind = true
break
}
}
if !bFind {
data = &pb.DBPrivilege{
Id: primitive.NewObjectID().Hex(),
Uid: session.GetUserId(),
Cid: cid,
CId: cId,
PrivilegeID: []int32{},
CTime: configure.Now().Unix(),
ETime: 0,
RewardTime: configure.Now().Unix(),
}
conf, err := this.configure.GetPrivilegeCard(cid)
if err != nil {
code = pb.ErrorCode_ConfigNoFound
return nil, code
}
data.ETime = configure.Now().Unix() + int64(conf.AssertDay*24*3600) // 设置过期时间
for _, v := range conf.PrivilegeId {
data.PrivilegeID = append(data.PrivilegeID, v)
}
this.modelPrivilege.addNewPrivilegeData(session.GetUserId(), data)
code = this.DispenseRes(session, []*cfg.Gameatn{conf.DisposableReward}, true)
}
if code = this.DispenseRes(session, []*cfg.Gameatn{conf.DisposableReward}, true); code != pb.ErrorCode_Success {
return
}
atn.T = conf.Id
res = append(res, atn) // 加资源
res = append(res, &pb.UserAssets{
A: conf.DisposableReward.A,
T: conf.DisposableReward.T,
N: conf.DisposableReward.N,
})
// 推送
session.SendMsg(string(this.GetType()), PrivilegeGetListResp, &pb.PrivilegeGetListResp{Data: []*pb.DBPrivilege{data}})
return
}
// 续费特权
func (this *Privilege) RenewPrivilegeCard(session comm.IUserSession, cid int32) (data *pb.DBPrivilege, code pb.ErrorCode) {
func (this *Privilege) RenewPrivilegeCard(session comm.IUserSession, cId string) (res []*pb.UserAssets, code pb.ErrorCode) {
atn := &pb.UserAssets{
A: "vip",
T: "",
N: 1,
}
list, err := this.modelPrivilege.getPrivilegeList(session.GetUserId())
if err != nil {
return
}
for _, v := range list {
if v.Cid == cid {
conf, err := this.configure.GetPrivilegeCard(cid)
if v.CId == cId {
conf, err := this.configure.GetPrivilegeCard(cId)
if err != nil {
code = pb.ErrorCode_ConfigNoFound
return nil, code
@ -95,20 +146,26 @@ func (this *Privilege) RenewPrivilegeCard(session comm.IUserSession, cid int32)
mapData["eTime"] = v.ETime
this.modelPrivilege.modifyPrivilegeData(session.GetUserId(), v.Id, mapData)
// 发放奖励
code = this.DispenseRes(session, []*cfg.Gameatn{conf.DisposableReward}, true)
if code = this.DispenseRes(session, []*cfg.Gameatn{conf.DisposableReward}, true); code != pb.ErrorCode_Success {
break
}
data = v
session.SendMsg(string(this.GetType()), PrivilegeGetListResp, &pb.PrivilegeGetListResp{Data: []*pb.DBPrivilege{v}})
return
atn.T = conf.Id
res = append(res, atn) // 加资源
res = append(res, &pb.UserAssets{
A: conf.DisposableReward.A,
T: conf.DisposableReward.T,
N: conf.DisposableReward.N,
})
} else {
code = pb.ErrorCode_PrivilegeRenewTime
data = nil
return
}
break
}
}
code = pb.ErrorCode_PrivilegeNotFound
data = nil
return
}

View File

@ -28,8 +28,8 @@ type DBPrivilege struct {
Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id" bson:"_id"` //ID
Uid string `protobuf:"bytes,2,opt,name=uid,proto3" json:"uid" bson:"uid"` //用户ID
Cid int32 `protobuf:"varint,3,opt,name=cid,proto3" json:"cid" bson:"privilegeID"` //特权id
PrivilegeID []int32 `protobuf:"varint,4,rep,packed,name=privilegeID,proto3" json:"privilegeID" bson:"privilegeID"`
CId string `protobuf:"bytes,3,opt,name=cId,proto3" json:"cId" bson:"cId"` //计费点数ID
PrivilegeID []int32 `protobuf:"varint,4,rep,packed,name=privilegeID,proto3" json:"privilegeID" bson:"privilegeID"` //特权ID
CTime int64 `protobuf:"varint,5,opt,name=cTime,proto3" json:"cTime" bson:"cTime"` ////购买时间
ETime int64 `protobuf:"varint,6,opt,name=eTime,proto3" json:"eTime" bson:"eTime"` ////到期时间
RewardTime int64 `protobuf:"varint,7,opt,name=rewardTime,proto3" json:"rewardTime" bson:"rewardTime"` //每日奖励时间
@ -81,11 +81,11 @@ func (x *DBPrivilege) GetUid() string {
return ""
}
func (x *DBPrivilege) GetCid() int32 {
func (x *DBPrivilege) GetCId() string {
if x != nil {
return x.Cid
return x.CId
}
return 0
return ""
}
func (x *DBPrivilege) GetPrivilegeID() []int32 {
@ -124,8 +124,8 @@ var file_privilege_privilege_db_proto_rawDesc = []byte{
0x01, 0x0a, 0x0b, 0x44, 0x42, 0x50, 0x72, 0x69, 0x76, 0x69, 0x6c, 0x65, 0x67, 0x65, 0x12, 0x0e,
0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, 0x10,
0x0a, 0x03, 0x75, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x75, 0x69, 0x64,
0x12, 0x10, 0x0a, 0x03, 0x63, 0x69, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x05, 0x52, 0x03, 0x63,
0x69, 0x64, 0x12, 0x20, 0x0a, 0x0b, 0x70, 0x72, 0x69, 0x76, 0x69, 0x6c, 0x65, 0x67, 0x65, 0x49,
0x12, 0x10, 0x0a, 0x03, 0x63, 0x49, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x63,
0x49, 0x64, 0x12, 0x20, 0x0a, 0x0b, 0x70, 0x72, 0x69, 0x76, 0x69, 0x6c, 0x65, 0x67, 0x65, 0x49,
0x44, 0x18, 0x04, 0x20, 0x03, 0x28, 0x05, 0x52, 0x0b, 0x70, 0x72, 0x69, 0x76, 0x69, 0x6c, 0x65,
0x67, 0x65, 0x49, 0x44, 0x12, 0x14, 0x0a, 0x05, 0x63, 0x54, 0x69, 0x6d, 0x65, 0x18, 0x05, 0x20,
0x01, 0x28, 0x03, 0x52, 0x05, 0x63, 0x54, 0x69, 0x6d, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x65, 0x54,

View File

@ -26,6 +26,7 @@ import (
"go_dreamfactory/modules/notify"
"go_dreamfactory/modules/pagoda"
"go_dreamfactory/modules/pay"
"go_dreamfactory/modules/privilege"
"go_dreamfactory/modules/rtask"
"go_dreamfactory/modules/shop"
"go_dreamfactory/modules/smithy"
@ -96,7 +97,7 @@ func main() {
sociaty.NewModule(),
horoscope.NewModule(),
pay.NewModule(),
//privilege.NewModule(),
privilege.NewModule(),
growtask.NewModule(),
worldtask.NewModule(),
academy.NewModule(),

View File

@ -9,13 +9,13 @@
package cfg
type GamePrivilegeCard struct {
_dataMap map[int32]*GamePrivilegeCardData
_dataMap map[string]*GamePrivilegeCardData
_dataList []*GamePrivilegeCardData
}
func NewGamePrivilegeCard(_buf []map[string]interface{}) (*GamePrivilegeCard, error) {
_dataList := make([]*GamePrivilegeCardData, 0, len(_buf))
dataMap := make(map[int32]*GamePrivilegeCardData)
dataMap := make(map[string]*GamePrivilegeCardData)
for _, _ele_ := range _buf {
if _v, err2 := DeserializeGamePrivilegeCardData(_ele_); err2 != nil {
return nil, err2
@ -27,7 +27,7 @@ func NewGamePrivilegeCard(_buf []map[string]interface{}) (*GamePrivilegeCard, er
return &GamePrivilegeCard{_dataList:_dataList, _dataMap:dataMap}, nil
}
func (table *GamePrivilegeCard) GetDataMap() map[int32]*GamePrivilegeCardData {
func (table *GamePrivilegeCard) GetDataMap() map[string]*GamePrivilegeCardData {
return table._dataMap
}
@ -35,7 +35,7 @@ func (table *GamePrivilegeCard) GetDataList() []*GamePrivilegeCardData {
return table._dataList
}
func (table *GamePrivilegeCard) Get(key int32) *GamePrivilegeCardData {
func (table *GamePrivilegeCard) Get(key string) *GamePrivilegeCardData {
return table._dataMap[key]
}

View File

@ -11,9 +11,8 @@ package cfg
import "errors"
type GamePrivilegeCardData struct {
Id int32
Id string
Name string
Proid string
AssertDay int32
RenewDay int32
DayReward []*Gameatn
@ -28,9 +27,8 @@ func (*GamePrivilegeCardData) GetTypeId() int32 {
}
func (_v *GamePrivilegeCardData)Deserialize(_buf map[string]interface{}) (err error) {
{ var _ok_ bool; var _tempNum_ float64; if _tempNum_, _ok_ = _buf["id"].(float64); !_ok_ { err = errors.New("id error"); return }; _v.Id = int32(_tempNum_) }
{ var _ok_ bool; if _v.Id, _ok_ = _buf["id"].(string); !_ok_ { err = errors.New("id error"); return } }
{ var _ok_ bool; if _v.Name, _ok_ = _buf["name"].(string); !_ok_ { err = errors.New("name error"); return } }
{ var _ok_ bool; if _v.Proid, _ok_ = _buf["proid"].(string); !_ok_ { err = errors.New("proid error"); return } }
{ var _ok_ bool; var _tempNum_ float64; if _tempNum_, _ok_ = _buf["assert_day"].(float64); !_ok_ { err = errors.New("assert_day error"); return }; _v.AssertDay = int32(_tempNum_) }
{ var _ok_ bool; var _tempNum_ float64; if _tempNum_, _ok_ = _buf["renew_day"].(float64); !_ok_ { err = errors.New("renew_day error"); return }; _v.RenewDay = int32(_tempNum_) }
{