77 lines
2.0 KiB
Go
77 lines
2.0 KiB
Go
package privilege
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/pb"
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
)
|
|
|
|
//参数校验
|
|
func (this *apiComp) BuyGiftCheck(session comm.IUserSession, req *pb.PrivilegeBuyGiftReq) (errdata *pb.ErrorData) {
|
|
if req.VipLv == 0 {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Title: pb.ErrorCode_ReqParameterError.ToString(),
|
|
}
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
///获取特权列表
|
|
func (this *apiComp) BuyGift(session comm.IUserSession, req *pb.PrivilegeBuyGiftReq) (errdata *pb.ErrorData) {
|
|
if errdata = this.BuyGiftCheck(session, req); errdata != nil {
|
|
return
|
|
}
|
|
|
|
userinfo := this.module.ModuleUser.GetUser(session.GetUserId())
|
|
if userinfo.Vip == 0 || userinfo.Vip < req.VipLv {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_VipLvError, // vip 等级不足
|
|
Title: pb.ErrorCode_VipLvError.ToString(),
|
|
}
|
|
return
|
|
}
|
|
conf := this.module.configure.GetVipConfigureData(req.VipLv)
|
|
if conf == nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ConfigNoFound,
|
|
Title: pb.ErrorCode_ConfigNoFound.ToString(),
|
|
}
|
|
return
|
|
}
|
|
vip, err := this.module.modelVip.getVipList(session.GetUserId())
|
|
if err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_DBError,
|
|
Title: pb.ErrorCode_DBError.ToString(),
|
|
}
|
|
return
|
|
}
|
|
if _, ok := vip.Reward[req.VipLv]; ok {
|
|
errdata = &pb.ErrorData{ // 礼包重复购买
|
|
Code: pb.ErrorCode_VipBuyRepeat,
|
|
Title: pb.ErrorCode_VipBuyRepeat.ToString(),
|
|
}
|
|
return
|
|
}
|
|
// 消耗检测
|
|
if conf.PriceDiscount.N > 0 {
|
|
if errdata = this.module.ConsumeRes(session, []*cfg.Gameatn{conf.PriceDiscount}, true); errdata != nil {
|
|
return
|
|
}
|
|
}
|
|
// 加资源
|
|
if errdata = this.module.DispenseRes(session, conf.Giftinfo, true); errdata != nil {
|
|
return
|
|
}
|
|
vip.Reward[req.VipLv] = true
|
|
|
|
this.module.modelVip.modifyVipData(session.GetUserId(), map[string]interface{}{
|
|
"reward": vip.Reward,
|
|
})
|
|
// 推送
|
|
session.SendMsg(string(this.module.GetType()), PrivilegeBuyGiftResp, &pb.PrivilegeBuyGiftResp{Data: vip})
|
|
return
|
|
}
|