package main

import (
	"math/rand"
	"time"

	"mongo.games.com/goserver/core/basic"
	"mongo.games.com/goserver/core/logger"
	"mongo.games.com/goserver/core/netlib"
	"mongo.games.com/goserver/core/task"

	"mongo.games.com/game/common"
	"mongo.games.com/game/model"
	"mongo.games.com/game/proto"
	"mongo.games.com/game/protocol/shop"
)

type CSShopInfoPacketFactory struct {
}

type CSShopInfoHandler struct {
}

func (this *CSShopInfoPacketFactory) CreatePacket() interface{} {
	pack := &shop.CSShopInfo{}
	return pack
}

func (this *CSShopInfoHandler) Process(s *netlib.Session, packetid int, data interface{}, sid int64) error {
	logger.Logger.Trace("CSShopInfoHandler Process recv ", data)
	if msg, ok := data.(*shop.CSShopInfo); ok {
		p := PlayerMgrSington.GetPlayer(sid)
		if p == nil {
			logger.Logger.Warn("CSShopInfoHandler p == nil")
			return nil
		}
		platform := p.GetPlatform()
		if platform == nil {
			return nil
		}
		shopInfos := ShopMgrSington.GetShopInfos(p, int(msg.NowLocation-1))
		pack := &shop.SCShopInfo{
			Infos: shopInfos,
		}
		logger.Logger.Trace("SCShopInfo:", pack, len(shopInfos))
		p.SendToClient(int(shop.SPacketID_PACKET_SC_SHOP_INFO), pack)
	}
	return nil
}

type CSAdLookedPacketFactory struct {
}

type CSAdLookedHandler struct {
}

func (this *CSAdLookedPacketFactory) CreatePacket() interface{} {
	pack := &shop.CSAdLooked{}
	return pack
}

func (this *CSAdLookedHandler) Process(s *netlib.Session, packetid int, data interface{}, sid int64) error {
	logger.Logger.Trace("CSAdLookedHandler Process recv ", data)
	if msg, ok := data.(*shop.CSAdLooked); ok {
		p := PlayerMgrSington.GetPlayer(sid)
		if p == nil {
			logger.Logger.Warn("CSAdLookedHandler p == nil")
			return nil
		}
		platform := p.GetPlatform()
		if platform == nil {
			return nil
		}
		pack := &shop.SCAdLooked{
			RetCode: shop.OpResultCode_OPRC_Error,
		}
		shopInfo := ShopMgrSington.GetShopInfo(msg.ShopId, p)
		if shopInfo == nil {
			return nil
		}
		if shopInfo.Ad == 0 {
			p.SendToClient(int(shop.SPacketID_PACKET_SC_SHOP_ADLOOKED), pack)
			logger.Logger.Warnf("CSAdLookedHandler shopId(%v) Ad(%v)", msg.ShopId, shopInfo.Ad == 0)
			return nil
		}
		if shopInfo.RemainingTime >= 5 { // 冷却时间大于5秒
			p.SendToClient(int(shop.SPacketID_PACKET_SC_SHOP_ADLOOKED), pack)
			logger.Logger.Warn("冷却中ing RemainingTime", shopInfo.RemainingTime)
			return nil
		}
		if shopTotal, ok1 := p.ShopTotal[msg.ShopId]; ok1 {
			if shopInfo.RepeatTimes <= shopTotal.AdReceiveNum {
				p.SendToClient(int(shop.SPacketID_PACKET_SC_SHOP_ADLOOKED), pack)
				logger.Logger.Warn("次数已满 已经领取的次数AdReceiveNum", shopInfo.AdReceiveNum)
				return nil
			}
			shopTotal.AdLookedNum++
		} else {
			p.ShopTotal[msg.ShopId] = &model.ShopTotal{AdLookedNum: 1}
		}
		b := ShopMgrSington.LookAdReceive(msg.ShopId, p, msg.GetPosition())
		pack.RetCode = b
		if b == shop.OpResultCode_OPRC_Sucess {
			p.ShopLastLookTime[msg.ShopId] = time.Now().Unix()
		}

		si := ShopMgrSington.GetShopInfo(msg.ShopId, p)
		if si != nil {
			pack.ShopInfo = ShopMgrSington.GetShopInfoProto(si, p, 0)
		}
		logger.Logger.Trace("ShopTotal:", p.ShopTotal[msg.ShopId])
		logger.Logger.Trace("SCAdLooked:", pack)
		p.SendToClient(int(shop.SPacketID_PACKET_SC_SHOP_ADLOOKED), pack)

		if pack.RetCode == shop.OpResultCode_OPRC_Sucess {
			ShopMgrSington.ShopCheckShowRed(p)
			ShopMgrSington.StartTimer(p.SnId, si.RemainingTime)
		}
	}
	return nil
}

type CSVCPayShopPacketFactory struct {
}

type CSVCPayShopHandler struct {
}

func (this *CSVCPayShopPacketFactory) CreatePacket() interface{} {
	pack := &shop.CSVCPayShop{}
	return pack
}

func (this *CSVCPayShopHandler) Process(s *netlib.Session, packetid int, data interface{}, sid int64) error {
	logger.Logger.Trace("CSVCPayShopHandler Process recv ", data)
	if msg, ok := data.(*shop.CSVCPayShop); ok {
		p := PlayerMgrSington.GetPlayer(sid)
		if p == nil {
			logger.Logger.Warn("CSVCPayShopHandler p == nil")
			return nil
		}
		platform := p.GetPlatform()
		if platform == nil {
			return nil
		}
		shopInfo := ShopMgrSington.GetShopInfo(msg.ShopId, p)
		if shopInfo == nil {
			return nil
		}
		var lastLookTime int64
		if shopInfo.Ad > 0 {
			lastLookTime = p.ShopLastLookTime[msg.ShopId]
			adLookedNum := p.ShopTotal[msg.ShopId].AdLookedNum
			coolingTime := int64(shopInfo.CoolingTime[adLookedNum])
			if coolingTime != 0 && time.Now().Unix()-lastLookTime < coolingTime {
				logger.Logger.Error("时间差:", time.Now().Unix()-lastLookTime, int64(shopInfo.CoolingTime[adLookedNum]))
				return nil
			}
		}
		var pack = &shop.SCVCPayShop{}
		SendClient := func(ret shop.OpResultCode) {
			pack.RetCode = ret
			if ret == shop.OpResultCode_OPRC_Sucess {
				si := ShopMgrSington.GetShopInfo(msg.ShopId, p)
				if si != nil {
					pack.ShopInfo = ShopMgrSington.GetShopInfoProto(si, p, msg.VipShopId)
				}
				pack.ShopInfo.VipShopId = msg.VipShopId
			}
			logger.Logger.Trace("SCVCPayShop:", pack)
			proto.SetDefaults(pack)
			p.SendToClient(int(shop.SPacketID_PACKET_SC_SHOP_VCPAYSHOP), pack)
		}

		if p.VIP < shopInfo.VipLevel {
			logger.Logger.Errorf("VIP等级不足！snid = %v,Vip = %v,shopInfo.VipLevel = %v,Id = %v", p.SnId, p.VIP, shopInfo.VipLevel, shopInfo.Id)
			SendClient(shop.OpResultCode_OPRC_VipLevelNotEnough)
			return nil
		}

		if shopInfo.Page == ShopPageVip {
			if p.VipShopData[msg.VipShopId] == nil || p.VipShopData[msg.VipShopId].IsBuy {
				SendClient(shop.OpResultCode_OPRC_ExchangeLimit)
				logger.Logger.Tracef("玩家VIP商城购买 当前物品无法购买！ snid = %v,p.VipShopData[shopInfo.Id] = %v", p.SnId, p.GetVipShopData(shopInfo.Id, msg.VipShopId))
				return nil
			}
		}
		//不需要观看广告的
		var money int32 = rand.Int31n(shopInfo.CostArea[1]-shopInfo.CostArea[0]+1) + shopInfo.CostArea[0]
		if shopInfo.Page == ShopPageVip {
			money = p.VipShopData[msg.VipShopId].CostArea
		}
		switch shopInfo.ConstType {
		case ShopConsumeCoin:
			//金币
			if int64(money) > p.Coin {
				SendClient(shop.OpResultCode_OPRC_Error)
				return nil
			}
		case ShopConsumeDiamond:
			//钻石
			if int64(money) > p.Diamond {
				SendClient(shop.OpResultCode_OPRC_Error)
				return nil
			}
		case ShopConsumeMoney:
			SendClient(shop.OpResultCode_OPRC_Error)
			return nil
		case ShopConsumePhoneScore:
			if int64(money) > p.PhoneScore {
				SendClient(shop.OpResultCode_OPRC_Error)
				return nil
			}
		default:
			SendClient(shop.OpResultCode_OPRC_Error)
			return nil
		}
		op := ShopMgrSington.ReceiveVCPayShop(shopInfo, p, msg.VipShopId, msg.GetPosition())
		SendClient(op)
	}
	return nil
}

type CSShopExchangeRecordPacketFactory struct {
}

type CSShopExchangeRecordHandler struct {
}

func (this *CSShopExchangeRecordPacketFactory) CreatePacket() interface{} {
	pack := &shop.CSShopExchangeRecord{}
	return pack
}

func (this *CSShopExchangeRecordHandler) Process(s *netlib.Session, packetid int, data interface{}, sid int64) error {
	logger.Logger.Trace("CSShopExchangeRecordHandler Process recv ", data)
	if msg, ok := data.(*shop.CSShopExchangeRecord); ok {
		p := PlayerMgrSington.GetPlayer(sid)
		if p == nil {
			logger.Logger.Warn("CSShopExchangeRecordHandler p == nil")
			return nil
		}
		platform := p.GetPlatform()
		if platform == nil {
			return nil
		}
		ShopMgrSington.GetExchangeRecord(p, msg.PageNo)

	}
	return nil
}

type CSShopExchangePacketFactory struct {
}

type CSShopExchangeHandler struct {
}

func (this *CSShopExchangePacketFactory) CreatePacket() interface{} {
	pack := &shop.CSShopExchange{}
	return pack
}

func (this *CSShopExchangeHandler) Process(s *netlib.Session, packetid int, data interface{}, sid int64) error {
	logger.Logger.Trace("CSShopExchangeHandler Process recv ", data)
	if msg, ok := data.(*shop.CSShopExchange); ok {
		p := PlayerMgrSington.GetPlayer(sid)
		if p == nil {
			logger.Logger.Warn("CSShopExchangeHandler p == nil")
			return nil
		}
		_, f := BlackListMgrSington.CheckExchange(p.PlayerData)
		if !f {
			pack := &shop.SCShopExchange{
				RetCode: shop.OpResultCode_OPRC_ExchangeLimitAcc,
			}
			p.SendToClient(int(shop.SPacketID_PACKET_SC_SHOP_EXCHANGE), pack)
			return nil
		}
		if msg.Amount <= 0 || msg.Amount > 100 {
			return nil
		}
		ShopMgrSington.Exchange(p, msg.GoodsId, msg.UserName, msg.Mobile, msg.Comment, msg.Id, msg.Amount)
	}
	return nil
}

// 兑换列表
type CSShopExchangeListPacketFactory struct {
}

type CSShopExchangeListHandler struct {
}

func (this *CSShopExchangeListPacketFactory) CreatePacket() interface{} {
	pack := &shop.CSShopExchangeList{}
	return pack
}

func (this *CSShopExchangeListHandler) Process(s *netlib.Session, packetid int, data interface{}, sid int64) error {
	logger.Logger.Trace("CSShopExchangeListHandler Process recv ", data)
	if _, ok := data.(*shop.CSShopExchangeList); ok {
		p := PlayerMgrSington.GetPlayer(sid)
		if p == nil {
			logger.Logger.Warn("CSShopExchangeListHandler p == nil")
			return nil
		}

		ShopMgrSington.ExchangeList(p)
	}
	return nil
}

// 充值
type CSPayInfoPacketFactory struct {
}

type CSPayInfoHandler struct {
}

func (this *CSPayInfoPacketFactory) CreatePacket() interface{} {
	pack := &shop.CSPayInfo{}
	return pack
}

func (this *CSPayInfoHandler) Process(s *netlib.Session, packetid int, data interface{}, sid int64) error {
	logger.Logger.Trace("CSPayInfoHandler Process recv ", data)
	if msg, ok := data.(*shop.CSPayInfo); ok {
		p := PlayerMgrSington.GetPlayer(sid)
		if p == nil {
			logger.Logger.Warn("CSPayInfoHandler p == nil")
			return nil
		}

		SendClient := func(ret shop.OpResultCode) {
			pack := &shop.SCPayInfo{
				RetCode: ret,
			}
			p.SendToClient(int(shop.SPacketID_PACKET_SCPAYINFO), pack)
		}
		//充值限制
		_, f := BlackListMgrSington.CheckRecharge(p.PlayerData)
		if !f {
			SendClient(shop.OpResultCode_OPRC_ExchangeLimitAcc)
			return nil
		}
		if msg.GoodsId >= ShopTypeStart {
			//商城id
			shopInfo := ShopMgrSington.GetShopInfo(msg.GoodsId, p)
			if shopInfo == nil {
				SendClient(shop.OpResultCode_OPRC_ExchangeSoldOut)
				return nil
			}
			if shopInfo.ConstType != ShopConsumeMoney {
				SendClient(shop.OpResultCode_OPRC_Error)
				return nil
			}
			if shopInfo.Page == ShopPageVip {
				//判断是否购买过了
				vipLevel := p.VIP
				if shopInfo.Type == 1 {
					vipCfg := VipMgrSington.GetVipCfg(p.Platform, p.VIP)
					if vipCfg == nil || vipCfg.ShopId2 != msg.GoodsId {
						SendClient(shop.OpResultCode_OPRC_Error)
						return nil
					}
				} else {
					vipLevel = shopInfo.VipLevel
				}
				if p.GetPlayerVipBagStatus(shopInfo.Id, vipLevel) == 1 {
					logger.Logger.Error("充值购买VIP礼包失败！！！！！！！！！！！！！")
					SendClient(shop.OpResultCode_OPRC_Error)
					return nil
				}
				/*				//VIP金币礼包 判断当前vip等级的礼包是否领取过
								if p.WelfData.VIPBag == nil {
									p.WelfData.VIPBag = make(map[int32]map[int32]int32)
								}
								if p.WelfData.VIPBag[vipLevel] != nil && p.WelfData.VIPBag[vipLevel][msg.GoodsId] == shopInfo.Type {
									logger.Logger.Error("充值购买VIP礼包失败！！！！！！！！！！！！！")
									SendClient(shop.OpResultCode_OPRC_Error)
									return nil
								}*/
			}
			ShopMgrSington.SendAPICreateOrder(p, msg.ConfigPayId, shopInfo, "shop_goods_xj")

		} else {
			//活动
			switch msg.GoodsId {
			case BlindBox:
				WelfareMgrSington.BuyBlindBox(p, msg.BuyId, msg.ConfigPayId)
			case FirstPay:
				WelfareMgrSington.BuyFirstPay(p, msg.ConfigPayId)
			case ContinuousPay:
				WelfareMgrSington.BuyContinuousPay(p, msg.ConfigPayId)
			case Exchange:
				cdata := ShopMgrSington.GetExchangeData(p.Platform, msg.BuyId)
				if cdata == nil {
					SendClient(shop.OpResultCode_OPRC_ExchangeSoldOut)
					return nil
				}
				if msg.ExchangeNum <= 0 {
					return nil
				}
				cdata.OrderId = msg.ExchangeOrderId
				cdata.ExchangeTypeId = msg.ExchangeId
				cdata.ExchangeNum = msg.ExchangeNum
				ShopMgrSington.SendAPICreateOrder(p, msg.ConfigPayId, cdata, "shop_exchange")
			}
		}

	}
	return nil
}

// 获取充值记录
type CSGetPayInfoListPacketFactory struct {
}

type CSGetPayInfoListHandler struct {
}

func (this *CSGetPayInfoListPacketFactory) CreatePacket() interface{} {
	pack := &shop.CSGetPayInfoList{}
	return pack
}

func (this *CSGetPayInfoListHandler) Process(s *netlib.Session, packetid int, data interface{}, sid int64) error {
	logger.Logger.Trace("CSGetPayInfoListHandler Process recv ", data)
	if msg, ok := data.(*shop.CSGetPayInfoList); ok {
		p := PlayerMgrSington.GetPlayer(sid)
		if p == nil {
			logger.Logger.Warn("CSGetPayInfoListHandler p == nil")
			return nil
		}
		task.New(nil, task.CallableWrapper(func(o *basic.Object) interface{} {
			return model.GetDbShopLogsByPage(p.Platform, p.SnId, msg.OpType)
		}), task.CompleteNotifyWrapper(func(data interface{}, t task.Task) {
			logger.Logger.Trace("model.GetDbShopLogsByPage", data)
			pack := &shop.SCGetPayInfoList{}
			if data != nil {
				info := data.([]*model.DbShop)
				for _, dbShop := range info {
					var itemInfo []*shop.ItemInfo
					for _, i2 := range dbShop.ItemInfo {
						itemInfo = append(itemInfo, &shop.ItemInfo{
							ItemId:  i2.ItemId,
							ItemNum: i2.ItemNum,
						})
					}
					pack.Info = append(pack.Info, &shop.PayInfoList{
						OrderId:     dbShop.LogId.Hex(),
						ConsumeType: dbShop.Consume,
						ConsumeNum:  dbShop.ConsumeNum,
						Amount:      dbShop.Amount,
						ItemInfo:    itemInfo,
						State:       dbShop.State,
						Ts:          dbShop.CreateTs.Unix(),
					})
				}

			}
			proto.SetDefaults(pack)
			p.SendToClient(int(shop.SPacketID_PACKET_SCGETPAYINFOLIST), pack)
			logger.Logger.Tracef("SCGetPayInfoListHandler sid:%v", pack)
		}), "model.GetDbShopLogsByPage").Start()
	}
	return nil
}

// 1.增加 2.查询 3.删除
const (
	AddAddr    int32 = 1
	SelectAddr int32 = 2
	DelAddr    int32 = 3
	UpdateAddr int32 = 4
)

// 添加玩家地址
type CSPlayerAddrPacketFactory struct {
}

type CSPlayerAddrHandler struct {
}

func (this *CSPlayerAddrPacketFactory) CreatePacket() interface{} {
	pack := &shop.CSPlayerAddr{}
	return pack
}

func (this *CSPlayerAddrHandler) Process(s *netlib.Session, packetid int, data interface{}, sid int64) error {
	logger.Logger.Trace("CSPlayerAddr Process recv ", data)
	if msg, ok := data.(*shop.CSPlayerAddr); ok {
		p := PlayerMgrSington.GetPlayer(sid)
		if p == nil {
			logger.Logger.Warn("CSPlayerAddr p == nil")
			return nil
		}
		switch msg.OpType {
		case AddAddr:
			addr := msg.Addr
			if len(addr) > 200 {
				logger.Logger.Warnf("玩家添加地址 地址长度过长len = %v,SnId = &v,addr = %v", len(addr), p.SnId, addr)
				return nil
			}
			if len(p.PlayerData.Addr) >= 3 {
				logger.Logger.Warn("最多添加3条地址！")
				return nil
			}
			logger.Logger.Trace("添加的地址:", addr)

			p.PlayerData.Addr = append(p.PlayerData.Addr, addr)
		case DelAddr:
			id := msg.Id
			p.PlayerData.Addr = append(p.PlayerData.Addr[:id], p.PlayerData.Addr[id+1:]...)
		case UpdateAddr:
			id := msg.Id
			if id >= 3 {
				return nil
			}
			addr := msg.Addr
			if len(addr) > 200 {
				return nil
			}
			if len(p.PlayerData.Addr) != 0 && len(p.PlayerData.Addr) < int(id) {
				return nil
			}
			p.PlayerData.Addr[id] = addr
		case SelectAddr:

		}
		//返回消息
		pack := &shop.SCGetPlayerAddrs{}
		for k, v := range p.PlayerData.Addr {
			pack.Addrs = append(pack.Addrs, &shop.AddrData{
				Id:   int32(k),
				Addr: v,
			})
		}
		p.SendToClient(int(shop.SPacketID_PACKET_SCPLAYERADDR), pack)
	}
	return nil
}

// 添加玩家地址
type CSUpdateVipShopPacketFactory struct {
}

type CSUpdateVipShopHandler struct {
}

func (this *CSUpdateVipShopPacketFactory) CreatePacket() interface{} {
	pack := &shop.CSUpdateVipShop{}
	return pack
}

func (this *CSUpdateVipShopHandler) Process(s *netlib.Session, packetid int, data interface{}, sid int64) error {
	p := PlayerMgrSington.GetPlayer(sid)
	if p == nil {
		logger.Logger.Warn("CSPayInfoHandler p == nil")
		return nil
	}
	if p.VIP == 0 {
		return nil
	}
	vipConfig := VipMgrSington.GetVIPLevelCfg(p.Platform, p.VIP)
	if vipConfig == nil {
		return nil
	}

	if p.VipShopRefreshCount >= vipConfig.Privilege3[0] {
		logger.Logger.Error("玩家VIP商城刷新次数不足 snid = ", p.SnId)
		return nil
	}
	ShopMgrSington.UpdateVipShopData(p)
	p.VipShopRefreshCount += 1
	pack := &shop.SCUpdateVipShop{
		RefreshCount: p.VipShopRefreshCount, //玩家当前刷新次数
	}
	for i, info := range p.VipShopData {
		si := ShopMgrSington.ShopInfos[p.Platform][info.Id]
		data := &shop.ShopInfo{
			Id:                info.Id,
			AdLookedNum:       si.AdLookedNum,
			AdReceiveNum:      si.AdReceiveNum,
			LastLookTime:      si.LastLookTime,
			RoleAdded:         si.RoleAdded,
			PetAdded:          si.PetAdded,
			ItemId:            si.ItemId,
			Order:             si.Order,
			Page:              si.Page,
			Type:              si.Type,
			Location:          si.Location,
			Picture:           si.Picture,
			Name:              si.Name,
			Ad:                si.Ad,
			AdTime:            si.AdTime,
			RepeatTimes:       si.RepeatTimes,
			CoolingTime:       si.CoolingTime,
			Label:             si.Label,
			Added:             info.AddArea,
			Amount:            si.Amount * int64(info.CostArea),
			Consume:           si.ConstType,
			ConsumptionAmount: info.CostArea,
			AddItemInfo:       si.AddItemInfo,
			VipLevel:          si.VipLevel,
			EndTime:           si.EndTime,
			IsBuy:             info.IsBuy,
			VipShopId:         i,
			AmountFinal:       ShopMgrSington.GetAmountFinal(p, si.Id, i),
		}

		pack.Info = append(pack.Info, data)
	}
	p.SendToClient(int(shop.SPacketID_PACKET_SC_UPDATE_VIP_SHOP), pack)
	return nil
}
func init() {
	// 获取商城商品信息列表
	common.RegisterHandler(int(shop.SPacketID_PACKET_CS_SHOP_INFO), &CSShopInfoHandler{})
	netlib.RegisterFactory(int(shop.SPacketID_PACKET_CS_SHOP_INFO), &CSShopInfoPacketFactory{})
	// 看广告领取商品，校验冷却时间和领取次数（免费）
	common.RegisterHandler(int(shop.SPacketID_PACKET_CS_SHOP_ADLOOKED), &CSAdLookedHandler{})
	netlib.RegisterFactory(int(shop.SPacketID_PACKET_CS_SHOP_ADLOOKED), &CSAdLookedPacketFactory{})
	// 看广告领取商品，校验冷却时间（非免费）
	common.RegisterHandler(int(shop.SPacketID_PACKET_CS_SHOP_VCPAYSHOP), &CSVCPayShopHandler{})
	netlib.RegisterFactory(int(shop.SPacketID_PACKET_CS_SHOP_VCPAYSHOP), &CSVCPayShopPacketFactory{})
	// 获取订单记录（非现金：金币，道具；现金的走透传后台获取）
	common.RegisterHandler(int(shop.SPacketID_PACKET_CSGETPAYINFOLIST), &CSGetPayInfoListHandler{})
	netlib.RegisterFactory(int(shop.SPacketID_PACKET_CSGETPAYINFOLIST), &CSGetPayInfoListPacketFactory{})

	// 获取商城商品兑换列表
	common.RegisterHandler(int(shop.SPacketID_PACKET_CS_SHOP_EXCHANGELIST), &CSShopExchangeListHandler{})
	netlib.RegisterFactory(int(shop.SPacketID_PACKET_CS_SHOP_EXCHANGELIST), &CSShopExchangeListPacketFactory{})
	// 兑换商品（非现金）
	common.RegisterHandler(int(shop.SPacketID_PACKET_CS_SHOP_EXCHANGE), &CSShopExchangeHandler{})
	netlib.RegisterFactory(int(shop.SPacketID_PACKET_CS_SHOP_EXCHANGE), &CSShopExchangePacketFactory{})
	// 兑换商品（现金，创建订单）
	common.RegisterHandler(int(shop.SPacketID_PACKET_CSPAYINFO), &CSPayInfoHandler{})
	netlib.RegisterFactory(int(shop.SPacketID_PACKET_CSPAYINFO), &CSPayInfoPacketFactory{})
	// 获取兑换记录
	//todo 客户端走透传后台获取
	common.RegisterHandler(int(shop.SPacketID_PACKET_CS_SHOP_EXCHANGERECORD), &CSShopExchangeRecordHandler{})
	netlib.RegisterFactory(int(shop.SPacketID_PACKET_CS_SHOP_EXCHANGERECORD), &CSShopExchangeRecordPacketFactory{})

	//玩家地址操作
	common.RegisterHandler(int(shop.SPacketID_PACKET_CSPLAYERADDR), &CSPlayerAddrHandler{})
	netlib.RegisterFactory(int(shop.SPacketID_PACKET_CSPLAYERADDR), &CSPlayerAddrPacketFactory{})
	//VIP商城刷新
	common.RegisterHandler(int(shop.SPacketID_PACKET_CS_UPDATE_VIP_SHOP), &CSUpdateVipShopHandler{})
	netlib.RegisterFactory(int(shop.SPacketID_PACKET_CS_UPDATE_VIP_SHOP), &CSUpdateVipShopPacketFactory{})
}
