326 lines
9.1 KiB
Go
326 lines
9.1 KiB
Go
package shopcenter
|
|
|
|
import (
|
|
"fmt"
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/pb"
|
|
"go_dreamfactory/sys/configure"
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
"go_dreamfactory/utils"
|
|
)
|
|
|
|
// 参数校验
|
|
func (this *apiComp) ReceiveCheck(session comm.IUserSession, req *pb.ShopCenterReceiveReq) (errdata *pb.ErrorData) {
|
|
|
|
return
|
|
}
|
|
|
|
// /获取自己的排行榜信息
|
|
func (this *apiComp) Receive(session comm.IUserSession, req *pb.ShopCenterReceiveReq) (errdata *pb.ErrorData) {
|
|
var (
|
|
conf *cfg.GameShopCenterControlData
|
|
pconfs []*cfg.GameShopCenterSubmeterData
|
|
pconf *cfg.GameShopCenterSubmeterData
|
|
fconf *cfg.GameShopCenterFundData
|
|
fconfs []*cfg.GameShopCenterFundData
|
|
info *pb.DBShopCenter
|
|
item *pb.DBShopCenterItem
|
|
user *pb.DBUser
|
|
drop []int32
|
|
items []*cfg.Gameatn
|
|
itemsgroup []*cfg.Gameatn
|
|
award []*pb.UserAtno
|
|
ok bool
|
|
err error
|
|
)
|
|
if errdata = this.ReceiveCheck(session, req); errdata != nil {
|
|
return
|
|
}
|
|
|
|
if conf, err = this.module.configure.getGameShopCenterControl(req.Fid); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ConfigNoFound,
|
|
Title: pb.ErrorCode_ConfigNoFound.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
|
|
if info, err = this.module.modelshop.getUserShopCenter(session.GetUserId()); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_DBError,
|
|
Title: pb.ErrorCode_DBError.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
|
|
if item, ok = info.Item[req.Fid]; !ok {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Title: pb.ErrorCode_ReqParameterError.ToString(),
|
|
Message: "no is vip",
|
|
}
|
|
}
|
|
|
|
if !item.Vip {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Title: pb.ErrorCode_ReqParameterError.ToString(),
|
|
Message: "you no buy vip",
|
|
}
|
|
}
|
|
|
|
if !item.Open {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Title: pb.ErrorCode_ReqParameterError.ToString(),
|
|
Message: "activity is close",
|
|
}
|
|
}
|
|
if user, err = this.module.GetUserForSession(session); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_DBError,
|
|
Title: pb.ErrorCode_DBError.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
switch conf.Type {
|
|
case 1:
|
|
if req.Pid != 0 {
|
|
if _, ok = item.Record[req.Pid]; ok {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Title: pb.ErrorCode_ReqParameterError.ToString(),
|
|
Message: "Received!",
|
|
}
|
|
return
|
|
}
|
|
if pconf, err = this.module.configure.getGameShopCenterSubmeter(req.Pid); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ConfigNoFound,
|
|
Title: pb.ErrorCode_ConfigNoFound.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
level := this.module.mainline.InquireMainLinePassLevel(session.GetUserId())
|
|
if _, ok = level[pconf.Mianlevel]; !ok {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Title: pb.ErrorCode_ReqParameterError.ToString(),
|
|
Message: "mainline no pass",
|
|
}
|
|
return
|
|
}
|
|
drop = append(drop, pconf.Group)
|
|
item.Record[req.Pid] = true
|
|
} else {
|
|
if pconfs, err = this.module.configure.getGameShopCenterSubmeters(); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ConfigNoFound,
|
|
Title: pb.ErrorCode_ConfigNoFound.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
level := this.module.mainline.InquireMainLinePassLevel(session.GetUserId())
|
|
for _, v := range pconfs {
|
|
if v.Index == conf.Index {
|
|
if _, ok = item.Record[v.Id]; !ok {
|
|
if _, ok = level[v.Mianlevel]; ok {
|
|
drop = append(drop, pconf.Group)
|
|
item.Record[v.Id] = true
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
case 2:
|
|
if req.Pid != 0 {
|
|
if _, ok = item.Record[req.Pid]; ok {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Title: pb.ErrorCode_ReqParameterError.ToString(),
|
|
Message: "Received!",
|
|
}
|
|
return
|
|
}
|
|
if fconf, err = this.module.configure.getGameShopCenterFund(req.Pid); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ConfigNoFound,
|
|
Title: pb.ErrorCode_ConfigNoFound.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
if conf.Type == 2 { //等级基金
|
|
if user.Lv < fconf.Unlock { //没有达到目标等级
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Title: pb.ErrorCode_ReqParameterError.ToString(),
|
|
Message: "user lv no achieve",
|
|
}
|
|
return
|
|
}
|
|
}
|
|
drop = append(drop, fconf.Group)
|
|
item.Record[req.Pid] = true
|
|
} else {
|
|
if fconfs, err = this.module.configure.getGameShopCenterFunds(); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ConfigNoFound,
|
|
Title: pb.ErrorCode_ConfigNoFound.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
for _, v := range fconfs {
|
|
if conf.Type == v.Type && v.Position == conf.Index {
|
|
if _, ok = item.Record[v.Id]; !ok {
|
|
if user.Lv >= v.Unlock { //没有达到目标等级
|
|
drop = append(drop, v.Group)
|
|
item.Record[v.Id] = true
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
break
|
|
case 3, 4, 5:
|
|
if req.Pid != 0 {
|
|
if _, ok = item.Record[req.Pid]; ok {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Title: pb.ErrorCode_ReqParameterError.ToString(),
|
|
Message: "Received!",
|
|
}
|
|
return
|
|
}
|
|
if fconf, err = this.module.configure.getGameShopCenterFund(req.Pid); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ConfigNoFound,
|
|
Title: pb.ErrorCode_ConfigNoFound.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
days := int32(utils.DiffDays(configure.Now().Unix(), item.Opemtime)) + 1
|
|
if days < fconf.Unlock {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Title: pb.ErrorCode_ReqParameterError.ToString(),
|
|
Message: fmt.Sprintf("days:%d no achieve", days),
|
|
}
|
|
return
|
|
}
|
|
drop = append(drop, fconf.Group)
|
|
item.Record[req.Pid] = true
|
|
} else {
|
|
if fconfs, err = this.module.configure.getGameShopCenterFunds(); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ConfigNoFound,
|
|
Title: pb.ErrorCode_ConfigNoFound.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
days := int32(utils.DiffDays(configure.Now().Unix(), item.Opemtime)) + 1
|
|
for _, v := range fconfs {
|
|
if conf.Type == v.Type && v.Position == conf.Index {
|
|
if _, ok = item.Record[v.Id]; !ok {
|
|
if days >= v.Unlock { //没有达到目标等级
|
|
drop = append(drop, v.Group)
|
|
item.Record[v.Id] = true
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
break
|
|
case 6:
|
|
if req.Pid != 0 {
|
|
if _, ok = item.Record[req.Pid]; ok {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Title: pb.ErrorCode_ReqParameterError.ToString(),
|
|
Message: "Received!",
|
|
}
|
|
return
|
|
}
|
|
if fconf, err = this.module.configure.getGameShopCenterFund(req.Pid); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ConfigNoFound,
|
|
Title: pb.ErrorCode_ConfigNoFound.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
days := int32(utils.DiffDays(configure.Now().Unix(), item.Buytime)) + 1
|
|
if days < fconf.Unlock {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Title: pb.ErrorCode_ReqParameterError.ToString(),
|
|
Message: fmt.Sprintf("days:%d no achieve", days),
|
|
}
|
|
return
|
|
}
|
|
drop = append(drop, fconf.Group)
|
|
item.Record[req.Pid] = true
|
|
} else {
|
|
if fconfs, err = this.module.configure.getGameShopCenterFunds(); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ConfigNoFound,
|
|
Title: pb.ErrorCode_ConfigNoFound.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
days := int32(utils.DiffDays(configure.Now().Unix(), item.Buytime)) + 1
|
|
for _, v := range fconfs {
|
|
if conf.Type == v.Type && v.Position == conf.Index {
|
|
if _, ok = item.Record[v.Id]; !ok {
|
|
if days >= v.Unlock { //没有达到目标等级
|
|
drop = append(drop, v.Group)
|
|
item.Record[v.Id] = true
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
break
|
|
}
|
|
|
|
for _, v := range drop {
|
|
if items = this.module.ModuleTools.GetGroupDataByLottery(v, user.Vip, user.Lv); len(items) == 0 {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ConfigNoFound,
|
|
Title: pb.ErrorCode_ConfigNoFound.ToString(),
|
|
Message: fmt.Sprintf("掉落组未找到:%d", drop),
|
|
}
|
|
return
|
|
}
|
|
itemsgroup = append(itemsgroup, items...)
|
|
}
|
|
|
|
if errdata, award = this.module.DispenseAtno(session, itemsgroup, true); errdata != nil {
|
|
return
|
|
}
|
|
|
|
if err = this.module.modelshop.Change(session.GetUserId(), map[string]interface{}{
|
|
"item": info.Item,
|
|
}); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_DBError,
|
|
Title: pb.ErrorCode_DBError.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
}
|
|
session.SendMsg(string(this.module.GetType()), "receive", &pb.ShopCenterReceiveResp{Fid: req.Fid, Pid: req.Pid, Item: item, Award: award})
|
|
go this.module.AsynHandleSession(session.Clone(), func(session comm.IUserSession) {
|
|
this.module.WriteUserLog(session.GetUserId(), req, comm.GMResAddType, "ShopCenterReceiveReq", award)
|
|
})
|
|
return
|
|
}
|