| #!/usr/bin/python  | 
| # -*- coding: GBK -*-  | 
| #---------------------------------------------------------------------  | 
| #  | 
| #---------------------------------------------------------------------  | 
| ##@package PlayerCoin  | 
| # @todo: Íæ¼Òµã¾í´¦Àí  | 
| #  | 
| # @author: panwei  | 
| # @date 2011-06-30  | 
| # @version 2.8  | 
| #  | 
| # @note: ´Ëº¯ÊýÂß¼¸Ä¶¯ÐèÉ÷ÖØ!!!  | 
| #  | 
| # @change: "2013-07-26 17:00" Alee VIP¸Ä³É¹ºÂò  | 
| # @change: "2013-12-27 16:30" Alee ·ö³ÖÕ˺Š | 
| # @change: "2014-01-22 16:00" hxp Ð޸ijäֵʼþͬ²½ÊýֵΪnoteCoin  | 
| # @change: "2014-04-24 19:10" xcc »Ö¸´ÔÀ´³äÖµÉý¼¶vipµÈ¼¶µÄ´¦Àí  | 
| # @change: "2014-06-12 21:00" hxp Ôö¼Ó³äÖµÀñ°ü´¦ÀíÈë¿Ú  | 
| # @change: "2014-06-21 15:20" hxp Ôö¼ÓÌØ»Ý³äÖµ»î¶¯  | 
| # @change: "2014-10-16 19:00" Alee CTG²»·¢Ëͺǫ́¼Ç¼£¬Á÷Ïò¼Ç¼֧³ÖСÊýµã  | 
| # @change: "2014-11-11 16:30" xmnathan Ôö¼Ó³äÖµÅÅÐаñ  | 
| # @change: "2014-11-25 19:30" hxp Ôö¼Ó¿ª·þ³äÖµ»î¶¯  | 
| # @change: "2014-12-03 14:30" hxp Ôö¼ÓºÏ·þ³äÖµ»î¶¯  | 
| # @change: "2014-12-23 00:30" hxp Ôö¼Ó³äֵǰÐÅÏ¢Á÷Ïò  | 
| # @change: "2015-01-14 00:30" hxp Ôö¼ÓCTGʼþ»ã±¨  | 
| # @change: "2015-06-08 20:30" hxp Ôö¼Óµãȯ¶Ò»»Ê¼þ»ã±¨  | 
| # @change: "2015-08-26 14:00" zqx Ôö¼Ó»ñµÃ×êʯ³É¾Í  | 
| # @change: "2016-06-30 21:30" hxp È¥³ý¿ª·þ»î¶¯  | 
| # @change: "2016-07-20 14:30" hxp µãȯ¶Ò»»Ôö¼ÓÁ÷ÏòÀàÐÍ; Á÷ÏòÕûºÏ  | 
| #------------------------------------------------------------------------------  | 
| #"""Version = 2016-07-20 14:30"""  | 
| #------------------------------------------------------------------------------  | 
| import PlayerControl  | 
| import ItemControler  | 
| import GameWorld  | 
| import IPY_GameWorld  | 
| import DataRecordPack  | 
| import ChConfig  | 
| import ChPyNetSendPack  | 
| import NetPackCommon  | 
| import PlayerVip  | 
| import IpyGameDataPY  | 
| import ShareDefine  | 
| import PlayerFlashGiftbag  | 
| import PlayerFairyCeremony  | 
| import PlayerGoldGift  | 
| import PlayerActTotalRecharge  | 
| import ItemCommon  | 
|   | 
| #---------------------------------------------------------------------  | 
| #×¢Òâ: GetChangeCoinPointTotal ³äÖµµãºÍÔùË͵ã×ÜºÍ  | 
| #     GetPrizeCoinPointTotal  ÔùË͵ã×ÜºÍ  | 
|   | 
| #µã¾í¶Ò»»±ÈÂÊ(´Ë±ÈÂÊÑϽûÉÏÏßÔËÓªºóÐÞ¸Ä!!!)  | 
| def GetCoinRate(): return IpyGameDataPY.GetFuncCfg("PayRMB")  | 
|   | 
| def OnLogin(curPlayer):  | 
|       | 
|     # ÖØÖóäÖµ´ÎÊý  | 
|     if not GameWorld.GetDictValueByBit(curPlayer, ChConfig.Def_Player_Dict_VersionFix, ChConfig.Def_VerFix_CTGDoublePrize):  | 
|         GameWorld.SetDictValueByBit(curPlayer, ChConfig.Def_Player_Dict_VersionFix, ChConfig.Def_VerFix_CTGDoublePrize, 1)  | 
|         ipyDataMgr = IpyGameDataPY.IPY_Data()  | 
|         for i in xrange(ipyDataMgr.GetCTGCount()):  | 
|             ipyData = ipyDataMgr.GetCTGByIndex(i)  | 
|             recordID = ipyData.GetRecordID()  | 
|             totalBuyCount = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_CTGGoodsBuyCount % recordID)  | 
|             todayBuyCount = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TodayCTGCount % recordID)  | 
|             if not totalBuyCount and not todayBuyCount:  | 
|                 continue  | 
|             PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_CTGGoodsBuyCount % recordID, 0)  | 
|             PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_TodayCTGCount % recordID, 0)  | 
|             drDict = {"PlayerID":curPlayer.GetPlayerID(),"AccID":curPlayer.GetAccID(), "totalBuyCount":totalBuyCount, "todayBuyCount":todayBuyCount, "recordID":recordID}  | 
|             DataRecordPack.SendEventPack("ResetCTGCount", drDict, curPlayer)  | 
|             GameWorld.Log("ÖØÖóäÖµ´ÎÊý: recordID=%s,totalBuyCount=%s,todayBuyCount=%s"   | 
|                           % (recordID, totalBuyCount, todayBuyCount), curPlayer.GetPlayerID())  | 
|     else:  | 
|         GameWorld.DebugLog("ÒÑ¾ÖØÖùý³äÖµ´ÎÊý£¡")  | 
|               | 
|     Sync_CoinToGoldCountInfo(curPlayer)  | 
|     return  | 
|   | 
| def OnDay(curPlayer):  | 
|     syncRecordIDList = []  | 
|     ipyDataMgr = IpyGameDataPY.IPY_Data()  | 
|     for i in xrange(ipyDataMgr.GetCTGCount()):  | 
|         ipyData = ipyDataMgr.GetCTGByIndex(i)  | 
|         if not ipyData.GetDailyBuyCount():  | 
|             continue  | 
|         recordID = ipyData.GetRecordID()  | 
|         if not curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TodayCTGCount % recordID):  | 
|             continue  | 
|         PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_TodayCTGCount % recordID, 0)  | 
|         syncRecordIDList.append(recordID)  | 
|     if syncRecordIDList:  | 
|         Sync_CoinToGoldCountInfo(curPlayer, syncRecordIDList)  | 
|     return  | 
|   | 
| ## ´´½ÇÔùËÍ  | 
| #  @param curPlayer Íæ¼ÒʵÀý  | 
| #  @return None  | 
| def GiveGoldByCreate(curPlayer):  | 
|     giveCoinByCreate = IpyGameDataPY.GetFuncCfg("CornerPresentedMoney", 1)  | 
|     if not giveCoinByCreate:  | 
|         return  | 
|     isAddBourseMoney = IpyGameDataPY.GetFuncCfg("CornerPresentedMoney", 2)  | 
|       | 
|     PlayerCoinToGoldEx(curPlayer, giveCoinByCreate, ChConfig.Def_GiveMoney_SuperAccountCreate, isAddBourseMoney)  | 
|     return  | 
|   | 
| def PlayerCoinToGoldEx(curPlayer, orderRMB, eventName, isAddBourseMoney):  | 
|     ## Ö±½Ó³äÖµ×Ô¶¨Òå½ð¶î  | 
|     prizeGold = 0  | 
|     giveItemList = []  | 
|     orderCoin = orderRMB * 100  | 
|     addGold = orderRMB * GetCoinRate()  | 
|     addDRDict = {"orderCoin":orderCoin, "isAddBourseMoney":isAddBourseMoney, "eventName":eventName}  | 
|     DoCTGLogic(curPlayer, orderCoin, addGold, prizeGold, giveItemList, isAddBourseMoney, eventName, addDRDict)  | 
|     return  | 
|   | 
| def DoGMCTG(curPlayer, orderInfo, appID, isAddBourseMoney, eventName):  | 
|     ## GM³äÖµ£¬°üº¬GMÃüÁîÖ±½Ó³äÖµ¡¢ºǫ́GM¹¤¾ß³äÖµ  | 
|     ipyData = IpyGameDataPY.GetIpyGameData("OrderInfo", orderInfo, appID)  | 
|     if not ipyData:  | 
|         return  | 
|       | 
|     cPlayerCoin = CPY_PlayerCoinToGold()  | 
|     cPlayerCoin.useCoin = int(ipyData.GetPayRMBNum() * 100)  | 
|     cPlayerCoin.orderInfo = orderInfo  | 
|     cPlayerCoin.appID = appID  | 
|     cPlayerCoin.isAddBourseMoney = isAddBourseMoney  | 
|     return PlayerCoinToGold(curPlayer, cPlayerCoin, eventName)  | 
|   | 
| ##ÌØ±ð˵Ã÷£º³äÖµÔùË͵ãȯ¶¼Òª¼ÆËãµ½¸÷¸ö»î¶¯ÖÐ  | 
| ##Íæ¼Òµã¾í¶Ò»»Ôª±¦.  | 
| # @param curPlayer Íæ¼ÒʵÀý  | 
| # @param useCoin Ê¹Óõĵã¾í  | 
| # @param eventName ¶Ò»»Ê¼þÃû  | 
| # @return None  | 
| def PlayerCoinToGold(curPlayer, chargeInfo, eventName):  | 
|     ## °´ÉÌÆ·±àºÅ³äÖµ  | 
|     orderCoin = chargeInfo.GetCoin() # ½ð¶î ÒѳËÒÔ100  ÈËÃñ±Òµ¥Î»Îª·Ö  | 
|     #notePrizeCoin = chargeInfo.GetPrizeCoin()  | 
|     orderInfo = chargeInfo.GetOrderInfo() # ÉÌÆ·±àºÅ  | 
|     orderID = chargeInfo.GetOrderID() #¶©µ¥ºÅ£¬¶Ò»»³É¹¦ºóÇå³ý  | 
|     isAddBourseMoney = chargeInfo.GetIsAddBourseMoney()  | 
|     appID = chargeInfo.GetAppID()  | 
|     if not appID:  | 
|         appID = GameWorld.GetPlayerPlatform(curPlayer)  | 
|     addDRDict = {"orderCoin":orderCoin, "orderInfo":orderInfo, "orderID":orderID,   | 
|                  "isAddBourseMoney":isAddBourseMoney, "eventName":eventName, "appID":appID}  | 
|       | 
|     if orderCoin <= 0:  | 
|         DataRecordPack.DR_CTGError(curPlayer, "The orderCoin is zero!", addDRDict)  | 
|         return  | 
|       | 
|     ipyData = IpyGameDataPY.GetIpyGameData("OrderInfo", orderInfo, appID)  | 
|     if not ipyData:  | 
|         DataRecordPack.DR_CTGError(curPlayer, "Can not found the orderInfo.", addDRDict)  | 
|         return  | 
|       | 
|     payRMBNum = ipyData.GetPayRMBNum() # µ¥Î»£¬Ôª  | 
|     if orderCoin != int(payRMBNum * 100):  | 
|         DataRecordPack.DR_CTGError(curPlayer, "The orderCoin is not equal to the ipyData's RMB(%s)!" % payRMBNum, addDRDict)  | 
|         return  | 
|       | 
|     addGold, prizeGold, giveItemList = 0, 0, []  | 
|       | 
|     if ipyData.GetCTGID():  | 
|         ctgResultInfo = __GetCTGInfoByID(curPlayer, chargeInfo, ipyData.GetCTGID(), eventName, addDRDict, isAddBourseMoney)  | 
|         if not ctgResultInfo:  | 
|             return  | 
|         addGold, prizeGold, giveItemList = ctgResultInfo  | 
|           | 
|     elif ipyData.GetGiftbagID():  | 
|         if not PlayerFlashGiftbag.OnPlayerOrderGiftbag(curPlayer, [ipyData.GetGiftbagID()], addDRDict):  | 
|             return  | 
|     else:  | 
|         #ÓÃÓÚÖ§¸¶ÆäËûµÄÉÌÆ·£¬´ýÀ©Õ¹...  | 
|         DataRecordPack.DR_CTGError(curPlayer, "The orderInfo is useless!", addDRDict)  | 
|         return  | 
|       | 
|     DoCTGLogic(curPlayer, orderCoin, addGold, prizeGold, giveItemList, isAddBourseMoney, eventName, addDRDict)  | 
|       | 
|     #³äÖµ³É¹¦Ö÷¶¯²éѯһ´Î£¬ÎÞ³äÖµÊýÁ¿¾Í²»»á¼ÌÐø²éѯ  | 
|     if orderID:  | 
|         curPlayer.SendDBFinishRecharge(orderID)  | 
|         # ³äÖµ³É¹¦»Ø±¨¿Í»§¶Ë£¬SDKµÈ»áÓõ½  | 
|         Sync_CoinToGoldReport(curPlayer, orderID, orderCoin)  | 
|           | 
|     curPlayer.SendDBQueryRecharge()  | 
|     return True  | 
|   | 
| def __GetCTGInfoByID(curPlayer, chargeInfo, recordID, eventName, addDRDict, isAddBourseMoney):  | 
|     ## ¸ù¾Ý³äÖµÊý¾ÝID»ñÈ¡³äÖµÐÅÏ¢  | 
|       | 
|     ipyData = IpyGameDataPY.GetIpyGameData("CTG", recordID)  | 
|     if not ipyData:  | 
|         DataRecordPack.DR_CTGError(curPlayer, "Can not find CTG ipyData!", addDRDict)  | 
|         return  | 
|       | 
|     dailyBuyCount = ipyData.GetDailyBuyCount()  | 
|     addDRDict.update({"recordID":recordID})  | 
|     todayBuyCount = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TodayCTGCount % recordID)  | 
|     if dailyBuyCount:  | 
|         addDRDict.update({"dailyCanBuyCount":dailyBuyCount, "todayBuyCount":todayBuyCount})  | 
|         if todayBuyCount >= dailyBuyCount:  | 
|             DataRecordPack.DR_CTGError(curPlayer, "Pay count limit today!todayBuyCount=%s" % todayBuyCount, addDRDict)  | 
|             return  | 
|     PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_TodayCTGCount % recordID, todayBuyCount + 1)  | 
|       | 
|     giveItemList = ipyData.GetGainItemList()  | 
|     addGold = ipyData.GetGainGold() # »ñµÃÏÉÓñÊý  | 
|     gainGoldPrize = ipyData.GetGainGoldPrize() # ÔùËÍÏÉÓñÊý£¬Ê״γäÖµÔùËÍÏÉÓñʱ£¬´ËÏÉÓñ²»¸ø  | 
|     firstGoldPrize = ipyData.GetFirstGoldPrize() # Ê״γäÖµÔùË͵ÄÏÉÓñ  | 
|     totalBuyCount = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_CTGGoodsBuyCount % recordID)  | 
|     PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_CTGGoodsBuyCount % recordID, totalBuyCount + 1)  | 
|     prizeGold = firstGoldPrize if (not totalBuyCount and firstGoldPrize) else gainGoldPrize  | 
|       | 
|     addDRDict.update({"totalBuyCount":(totalBuyCount + 1)})  | 
|       | 
|     Sync_CoinToGoldCountInfo(curPlayer, [recordID])  | 
|     return addGold, prizeGold, giveItemList  | 
|   | 
| def DoCTGLogic(curPlayer, orderCoin, addGold, prizeGold, giveItemList, isAddBourseMoney, eventName, addDRDict):  | 
|     goldBefore = curPlayer.GetGold()  | 
|     bourseMoneyBefore = PlayerControl.GetMoney(curPlayer, ShareDefine.TYPE_Price_BourseMoney)  | 
|       | 
|     if addGold:  | 
|         PlayerControl.GiveMoney(curPlayer, IPY_GameWorld.TYPE_Price_Gold_Money, addGold, eventName, addDRDict, isGiveBourseMoney=isAddBourseMoney)  | 
|           | 
|     if prizeGold:  | 
|         PlayerControl.GiveMoney(curPlayer, IPY_GameWorld.TYPE_Price_Gold_Money, prizeGold, eventName, addDRDict, isGiveBourseMoney=isAddBourseMoney)  | 
|           | 
|     if giveItemList:  | 
|         needSpace = len(giveItemList)  | 
|         emptySpace = ItemCommon.GetItemPackSpace(curPlayer, IPY_GameWorld.rptItem, needSpace)  | 
|         if emptySpace < needSpace:  | 
|             PlayerControl.SendMailByKey("", [curPlayer.GetPlayerID()], giveItemList)  | 
|         else:  | 
|             for itemID, itemCount, isBind in giveItemList:  | 
|                 ItemControler.GivePlayerItem(curPlayer, itemID, itemCount, isBind, [IPY_GameWorld.rptItem],   | 
|                                              event=[ChConfig.ItemGive_CTG, True, addDRDict])  | 
|                   | 
|     addVIPExp = int(orderCoin / 100 * GetCoinRate())  | 
|     PlayerVip.AddVIPExp(curPlayer, addVIPExp)  | 
|       | 
|     changeCoinPointBefore = curPlayer.GetChangeCoinPointTotal()  | 
|     curPlayer.SetChangeCoinPointTotal(changeCoinPointBefore + orderCoin, 0)  | 
|     PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_FirstGoldTry, 0)  | 
|       | 
|     goldAfter = curPlayer.GetGold()  | 
|     changeCoinPointAfter = curPlayer.GetChangeCoinPointTotal()  | 
|     bourseMoneyAfter = PlayerControl.GetMoney(curPlayer, ShareDefine.TYPE_Price_BourseMoney)  | 
|     addDRDict.update({"gold":[goldBefore, goldAfter], "changeCoinPoint":[changeCoinPointBefore, changeCoinPointAfter],   | 
|                       "bourseMoney":[bourseMoneyBefore, bourseMoneyAfter], "addGold":addGold, "prizeGold":prizeGold, "giveItemList":giveItemList})  | 
|       | 
|     DataRecordPack.DR_CTGOK(curPlayer, addDRDict)  | 
|       | 
|     #---³äÖµ³É¹¦ºóÂß¼---  | 
|     #ÏɽçÊ¢µä-³äÖµ´óÀñ  | 
|     PlayerFairyCeremony.OnFCRecharge(curPlayer)  | 
|     PlayerGoldGift.DayChargeRedPackAward(curPlayer)  | 
|     PlayerActTotalRecharge.AddTotalRechargeGold(curPlayer, addGold)  | 
|     GameWorld.Log("Billing: eventName=%s, %s" % (eventName, addDRDict), curPlayer.GetPlayerID())  | 
|     return  | 
|   | 
| #===============================================================================  | 
|   | 
| ## Ä£Äâ³äÖµÐÅÏ¢£¬µãȯ³äÖµÐÅÏ¢  | 
| #  | 
| # µãȯ³äÖµÐÅÏ¢  | 
| class CPY_PlayerCoinToGold():  | 
|       | 
|     ## ³õʼ»¯  | 
|     #  @param ²ÎÊý  | 
|     #  @return ·µ»ØÖµ  | 
|     #  @remarks   | 
|     def __init__(self):  | 
|           | 
|         self.useCoin = 0    # ³äÖµ½ð¶î webÓжԽð¶î½øÐд¦Àí£¬×ªÕûÊýÈ絥λ1.10ԪתΪ110·Ö  | 
|         self.prizeCoin = 0  # Ôݲ»Ê¹Óà  | 
|         self.appendix = ''  # Ôݲ»Ê¹Óà  | 
|         self.orderInfo = ""     # ÉÌÆ·±àºÅ È繺ÂòÀñ°ü Ô¿¨ ³äÖµ½ð¶îµÈ  | 
|         self.appID = ""  | 
|         self.orderID = ""  | 
|         self.isAddBourseMoney = False # ÊÇ·ñͬ²½Ôö¼Ó½»Ò×Ëù¹ºÂò¶î¶È  | 
|         return  | 
|   | 
|     ## Ê¹ÓõãȯÊý  | 
|     #  @param ²ÎÊý  | 
|     #  @return ·µ»ØÖµ  | 
|     #  @remarks   | 
|     def GetCoin(self):  | 
|         return self.useCoin  | 
|       | 
|       | 
|     ## ÔùË͵ãȯÊý  | 
|     #  @param ²ÎÊý  | 
|     #  @return ·µ»ØÖµ  | 
|     #  @remarks   | 
|     def GetPrizeCoin(self):  | 
|         return self.prizeCoin  | 
|       | 
|       | 
|     ## ¸½¼ÓÐÅÏ¢  | 
|     #  @param self  | 
|     #  @return None  | 
|     def GetAppendix(self):  | 
|         return self.appendix  | 
|       | 
|     # ÉÌÆ·±àºÅ  | 
|     def GetOrderInfo(self):  | 
|         return self.orderInfo  | 
|       | 
|     def GetAppID(self): return self.appID  | 
|           | 
|     def GetOrderID(self):  | 
|         return self.orderID  | 
|       | 
|     def GetIsAddBourseMoney(self): return self.isAddBourseMoney  | 
|       | 
|   | 
| # Í¨Öª¿Í»§¶Ë±¾´Î³äÖµ½ð¶î£¬ÓÃÓÚSDKµÈ£¬coinΪÈËÃñ±Òµ¥Î»·Ö  | 
| def Sync_CoinToGoldReport(curPlayer, orderID, money):  | 
|     openGleeGame = ChPyNetSendPack.tagMCCoinToGoldReport()  | 
|     openGleeGame.Clear()  | 
|     openGleeGame.OrderLen = len(orderID)  | 
|     openGleeGame.OrderID = orderID  | 
|     openGleeGame.Coin = money  | 
|       | 
|     NetPackCommon.SendFakePack(curPlayer, openGleeGame)  | 
|     return  | 
|   | 
| def Sync_CoinToGoldCountInfo(curPlayer, syncRecordIDList=[]):  | 
|     if not syncRecordIDList:  | 
|         ipyDataMgr = IpyGameDataPY.IPY_Data()  | 
|         for i in xrange(ipyDataMgr.GetCTGCount()):  | 
|             ipyData = ipyDataMgr.GetCTGByIndex(i)  | 
|             syncRecordIDList.append(ipyData.GetRecordID())  | 
|               | 
|     if not syncRecordIDList:  | 
|         return  | 
|       | 
|     countInfoPack = ChPyNetSendPack.tagMCCoinToGoldCountInfo()  | 
|     countInfoPack.Clear()  | 
|     countInfoPack.CTGCountInfoList = []  | 
|     for recordID in syncRecordIDList:  | 
|         countInfo = ChPyNetSendPack.tagMCCoinToGoldCount()  | 
|         countInfo.RecordID = recordID  | 
|         countInfo.TodayPayCount = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TodayCTGCount % recordID)  | 
|         countInfo.TotalPayCount = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_CTGGoodsBuyCount % recordID)  | 
|         countInfoPack.CTGCountInfoList.append(countInfo)  | 
|     countInfoPack.RecordCount = len(countInfoPack.CTGCountInfoList)  | 
|     NetPackCommon.SendFakePack(curPlayer, countInfoPack)  | 
|     return  | 
|   |