hxp
2024-11-15 95ed566251586a404ed667336cc31dd318c773bd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
#!/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 PlayerDailyGiftbag
import PlayerFairyCeremony
import PlayerNewFairyCeremony
import PlayerGoldGift
import PlayerActTotalRecharge
import PlayerActGarbageSorting
import PlayerActRechargeRebateGold
import PlayerActFamilyCTGAssist
import PlayerActManyDayRecharge
import PlayerActSingleRecharge
import PlayerActRechargePrize
import PlayerFamilyRedPacket
import CrossActCTGBillboard
import CrossActAllRecharge
import PlayerActGrowupBuy
import OpenServerCampaign
import PlayerFeastTravel
import PlayerWeekParty
import PlayerGoldInvest
import PlayerActTurntable
import PlayerTongTianLing
import PlayerZhanling
import PlayerMineArea
import ItemCommon
import PyGameData
import CommFunc
 
import time
import copy
 
# ³äÖµ¶©µ¥ÀàÐÍ
PayOrderTypeList = (
PayOrderType_RMB, # ÈËÃñ±Ò 1
PayOrderType_USD, # ÃÀÔª 2
PayOrderType_VND, # Ô½Ä϶ܠ3
PayOrderType_Soha, # sohaƽ̨±Ò 4
PayOrderType_BuyOrder, # Ê¹Óö©µ¥¼ÛÖµ¶ÔÓ¦»õ±ÒÖ§¸¶ 5
PayOrderType_PayCoin, # ´ú±Ò 6
) = range(1, 1 + 6)
 
PayOrderType_Default = PayOrderType_RMB
 
# ³äÖµÀàÐͶ¨Òå
PayType_Gold = 2  # ³£¹æÏÉÓñ³äÖµ
PayType_GoldPlus = 3  # ÖÁ×ðÏÉÓñ³äÖµ
PayType_GrowupBuy = 16  # ³É³¤±ØÂò
PayType_PayCoin = 17  # ´ú±Ò³äÖµ
 
#---------------------------------------------------------------------
#×¢Òâ: GetChangeCoinPointTotal ³äÖµµãºÍÔùË͵ã×ܺÍ
#     GetPrizeCoinPointTotal  ÔùË͵ã×ܺÍ
 
#µã¾í¶Ò»»±ÈÂÊ(´Ë±ÈÂÊÑϽûÉÏÏßÔËÓªºóÐÞ¸Ä!!!)
def GetCoinRate(): return IpyGameDataPY.GetFuncCfg("PayRMB")
 
def OnLogin(curPlayer):
    if not DoResetCTGCountByTime(curPlayer):
        Sync_CoinToGoldCountInfo(curPlayer)
    if curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_DayFreeGoldGiftState):
        Sync_DayFreeGoldGiftState(curPlayer)
    if curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_OnlineRechargeTHAward):
        SyncOnlineRechargeTH(curPlayer)
    return
 
def DoResetCTGCountByTime(curPlayer):
    # ÖØÖóäÖµ´ÎÊý
    ctgResetTimeYMD = IpyGameDataPY.GetFuncCfg("CTG", 1)
    if not ctgResetTimeYMD:
        return
    if not isinstance(ctgResetTimeYMD, int):
        GameWorld.ErrLog("³äÖµÖØÖÃʱ¼äÅäÖñØÐëÊÇÊýÖµ¸ñʽ£¬²»Äܰüº¬·ûºÅ!")
        return
    curTime = int(time.time())
    #playerID = curPlayer.GetPlayerID()
    resetTime = GameWorld.ChangeTimeStrToNum(str(ctgResetTimeYMD), "%Y%m%d")
    if curTime < resetTime:
        #GameWorld.DebugLog("»¹Î´µ½´ï³äÖµ³äÖµ´ÎÊýʱ¼ä£¡curTime=%s < resetTime=%s" % (curTime, resetTime), playerID)
        return
    playerResetTime = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_CTGCountResetTime)
    if playerResetTime == resetTime:
        #GameWorld.DebugLog("ÒѾ­ÖØÖùý³äÖµ´ÎÊý£¡resetTime=%s" % resetTime, playerID)
        return
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_CTGCountResetTime, resetTime)
    
    DoResetCTGCount(curPlayer, ctgResetTimeYMD)
    return True
 
def DoResetCTGCount(curPlayer, resetEvent):
    # ÖØÖóäÖµ´ÎÊý
    
    playerID = curPlayer.GetPlayerID()
    ipyDataMgr = IpyGameDataPY.IPY_Data()
    for i in xrange(ipyDataMgr.GetCTGCount()):
        ipyData = ipyDataMgr.GetCTGByIndex(i)
        recordID = ipyData.GetRecordID()
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_CTGSelectItemValue % recordID, 0)
        if not ipyData.GetCanResetBuyCount():
            continue
        totalBuyCount = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_CTGGoodsBuyCount % recordID)
        todayBuyCount = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TodayCTGCount % recordID)
        weekBuyCount = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_WeekCTGCount % recordID)
        monthBuyCount = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_MonthCTGCount % recordID)
        if not totalBuyCount and not todayBuyCount and not weekBuyCount and not monthBuyCount:
            continue
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_CTGGoodsBuyCount % recordID, 0)
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_TodayCTGCount % recordID, 0)
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_WeekCTGCount % recordID, 0)
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_MonthCTGCount % recordID, 0)
        drDict = {"PlayerID":curPlayer.GetPlayerID(),"AccID":curPlayer.GetAccID(), "ResetEvent":resetEvent,
                  "totalBuyCount":totalBuyCount, "todayBuyCount":todayBuyCount, "recordID":recordID, 
                  "weekBuyCount":weekBuyCount, "monthBuyCount":monthBuyCount}
        DataRecordPack.SendEventPack("ResetCTGCount", drDict, curPlayer)
        GameWorld.Log("ÖØÖóäÖµ´ÎÊý: resetEvent=%s,recordID=%s,totalBuyCount=%s,todayBuyCount=%s" 
                      % (resetEvent, recordID, totalBuyCount, todayBuyCount), playerID)
    Sync_CoinToGoldCountInfo(curPlayer)
    return
 
def DoResetCTGCountByIDList(curPlayer, resetEvent, resetCTGIDList):
    # ÖØÖóäÖµ´ÎÊý
    if not resetCTGIDList:
        return
    playerID = curPlayer.GetPlayerID()
    for recordID in resetCTGIDList:
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_CTGSelectItemValue % recordID, 0)
        totalBuyCount = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_CTGGoodsBuyCount % recordID)
        todayBuyCount = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TodayCTGCount % recordID)
        weekBuyCount = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_WeekCTGCount % recordID)
        monthBuyCount = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_MonthCTGCount % recordID)
        if not totalBuyCount and not todayBuyCount and not weekBuyCount and not monthBuyCount:
            continue
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_CTGGoodsBuyCount % recordID, 0)
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_TodayCTGCount % recordID, 0)
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_WeekCTGCount % recordID, 0)
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_MonthCTGCount % recordID, 0)
        drDict = {"PlayerID":curPlayer.GetPlayerID(),"AccID":curPlayer.GetAccID(), "ResetEvent":resetEvent,
                  "totalBuyCount":totalBuyCount, "todayBuyCount":todayBuyCount, "recordID":recordID, 
                  "weekBuyCount":weekBuyCount, "monthBuyCount":monthBuyCount}
        DataRecordPack.SendEventPack("ResetCTGCount", drDict, curPlayer)
        GameWorld.Log("ÖØÖóäÖµ´ÎÊý: resetEvent=%s,recordID=%s,totalBuyCount=%s,todayBuyCount=%s" 
                      % (resetEvent, recordID, totalBuyCount, todayBuyCount), playerID)
    Sync_CoinToGoldCountInfo(curPlayer, resetCTGIDList)
    return
 
def OnDay(curPlayer):
    ## ³äÖµÏà¹Ø¹ýÌì
    
    #ÔÚÖØÖÃ֮ǰÐèÒª´¦ÀíµÄ
    PlayerActGrowupBuy.DoUpdateGrowupBuyStateOnDay(curPlayer) # ³É³¤±ØÂò
    
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_TodayCTGCoinTotal, 0)
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_CTGRealToday, 0)
    
    syncRecordIDList = []
    ipyDataMgr = IpyGameDataPY.IPY_Data()
    for i in xrange(ipyDataMgr.GetCTGCount()):
        ipyData = ipyDataMgr.GetCTGByIndex(i)
        #if not ipyData.GetDailyBuyCount():
        #    continue
        recordID = ipyData.GetRecordID()
        selectItemValue = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_CTGSelectItemValue % recordID)
        if not curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TodayCTGCount % recordID) and not selectItemValue:
            continue
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_TodayCTGCount % recordID, 0)
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_CTGSelectItemValue % recordID, 0)
        syncRecordIDList.append(recordID)
    if syncRecordIDList:
        Sync_CoinToGoldCountInfo(curPlayer, syncRecordIDList)
        
    if curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_DayFreeGoldGiftState):
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_DayFreeGoldGiftState, 0)
        Sync_DayFreeGoldGiftState(curPlayer)
    return
 
def OnWeek(curPlayer):
    syncRecordIDList = []
    ipyDataMgr = IpyGameDataPY.IPY_Data()
    for i in xrange(ipyDataMgr.GetCTGCount()):
        ipyData = ipyDataMgr.GetCTGByIndex(i)
        recordID = ipyData.GetRecordID()
        if not curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_WeekCTGCount % recordID):
            continue
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_WeekCTGCount % recordID, 0)
        syncRecordIDList.append(recordID)
    if syncRecordIDList:
        Sync_CoinToGoldCountInfo(curPlayer, syncRecordIDList)
    return
 
def OnMonth(curPlayer):
    syncRecordIDList = []
    ipyDataMgr = IpyGameDataPY.IPY_Data()
    for i in xrange(ipyDataMgr.GetCTGCount()):
        ipyData = ipyDataMgr.GetCTGByIndex(i)
        recordID = ipyData.GetRecordID()
        if not curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_MonthCTGCount % recordID):
            continue
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_MonthCTGCount % recordID, 0)
        syncRecordIDList.append(recordID)
    if syncRecordIDList:
        Sync_CoinToGoldCountInfo(curPlayer, syncRecordIDList)
    return
 
 
#// A1 23 ²éѯ³äÖµ´ÎÊý #tagCMQueryCoinToGoldCount
#
#struct tagCMQueryCoinToGoldCount
#{
#    tagHead        Head;
#    WORD        RecordID;    //³äÖµ¼Ç¼ID£¬Ò²¾ÍÊdzäÖµID£¬·¢0Ôò²éÈ«²¿
#};
def OnQueryCoinToGoldCount(index, clientData, tick):
    curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)
    recordID = clientData.RecordID
    Sync_CoinToGoldCountInfo(curPlayer, [recordID] if recordID else [])
    return
 
#// A1 26 ³äÖµ×ÔÑ¡ÎïÆ·Ñ¡Ôñ #tagCMSelectCTGItem
#
#struct    tagCMSelectCTGItem
#{
#    tagHead        Head;
#    WORD        RecordID;    //³äÖµID
#    DWORD        SelectItemValue; // ×ÔÑ¡ÎïÆ·Ë÷ÒýÖµ£¬Ã¿Á½Î»´æ´¢Ã¿¸ö×ÔÑ¡Ë÷Òý¶ÔӦѡÔñµÄÎïÆ·Ë÷Òý+1£¬´æ´¢Î»ÖµÎª0´ú±íδѡÔñ£¬×î¶àÖ§³ÖÑ¡Ôñ4ÖÖÎïÆ·
#};
def OnSelectCTGItem(index, clientData, tick):
    curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)
    playerID = curPlayer.GetPlayerID()
    recordID = clientData.RecordID
    selectItemValue = clientData.SelectItemValue
    if selectItemValue > ChConfig.Def_UpperLimit_DWord:
        GameWorld.ErrLog("³äÖµ×ÔÑ¡ÎïÆ·Ñ¡ÔñÖµÒç³ö! recordID=%s,selectItemValue=%s" % (recordID, selectItemValue), playerID)
        return
    ipyData = IpyGameDataPY.GetIpyGameData("CTG", recordID)
    if not ipyData:
        return
    selectItemInfo = ipyData.GetSelectItemInfo()
    selectItemList, errorInfo = GetSelectItemListInfo(selectItemInfo, selectItemValue)
    if errorInfo:
        GameWorld.ErrLog("³äÖµ×ÔÑ¡ÎïÆ·Ñ¡Ôñ´íÎó! recordID=%s,errorInfo=%s" % (recordID, errorInfo), playerID)
        return
    GameWorld.DebugLog("³äÖµ×ÔÑ¡ÎïÆ·: recordID=%s,selectItemValue=%s,selectItemList=%s" % (recordID, selectItemValue, selectItemList), playerID)
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_CTGSelectItemValue % recordID, selectItemValue)
    Sync_CoinToGoldCountInfo(curPlayer, [recordID])
    return
 
#// A1 25 ´ú±Ò¹ºÂò³äÖµÉÌÆ·±àºÅÉÌÆ· #tagCMCoinBuyOrderInfo
#
#struct    tagCMCoinBuyOrderInfo
#{
#    tagHead        Head;
#    BYTE        AppIDLen;
#    char        AppID[AppIDLen];
#    BYTE        OrderInfoLen;
#    char        OrderInfo[OrderInfoLen];    //ÉÌÆ·±àºÅ
#};
def OnCoinBuyOrderInfo(index, clientData, tick):
    curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)
    appID = clientData.AppID
    orderInfo = clientData.OrderInfo
    
    ipyData = IpyGameDataPY.GetIpyGameData("OrderInfo", orderInfo, appID)
    if not ipyData:
        return
    cPlayerCoin = CPY_PlayerCoinToGold()
    cPlayerCoin.useCoin = CommFunc.RMBToCoin(ipyData.GetUsdMoney(), 100)
    cPlayerCoin.orderInfo = orderInfo
    cPlayerCoin.appID = appID
    cPlayerCoin.orderID = ""
    PlayerCoinToGold(curPlayer, cPlayerCoin, "CoinBuyOrderInfo", PayOrderType_PayCoin)
    return
 
def ExchangePayCoin(curPlayer, errorInfo, addDRDict):
    ''' ³äÖµ¶Ò»»³É´ú±Ò
                Ò»°ã¿ÉÓÃÓÚһЩ³äÖµ¶©µ¥¶Ò»»ÓÎÏ·¹¦ÄÜʱ£¬ÓÎÏ·¹¦ÄÜÓÐÏÞÖÆÈçÏÞ¹º£¬
                ¸Ã³äÖµÊÓΪ³É¹¦£¬²¢×ª»¯Îª¶ÔÓ¦´ú±Ò£¬¿ÉÒÔÀí½âΪÀàËÆ³äÖµµãȯ£¬´ú±Ò¿ÉÓÃÓÚÏ´γäֵʱ֧¸¶£»
    '''
    orderInfo = addDRDict.get("orderInfo", "")
    orderCoin = addDRDict.get("orderCoin", 0)
    payOrderType = addDRDict.get("payOrderType", PayOrderType_Default)
    if not orderCoin or not orderInfo:
        DataRecordPack.DR_CTGError(curPlayer, errorInfo, addDRDict)
        return
    eventName = addDRDict.get("eventName", "ExchangePayCoin")
    playerID = curPlayer.GetPlayerID()
    befPayCoin = PlayerControl.GetPayCoin(curPlayer)
    drDict = {ChConfig.Def_Give_Reason_SonKey:orderInfo, "payOrderType":payOrderType, "orderInfo":orderInfo}
    PlayerControl.GiveMoney(curPlayer, ShareDefine.TYPE_Price_PayCoin, orderCoin, eventName, drDict)
    aftPayCoin = PlayerControl.GetPayCoin(curPlayer)
    GameWorld.Log("³äֵת»¯Îª´ú±Ò: orderInfo=%s,orderCoin=%s,payOrderType=%s,eventName=%s,befPayCoin=%s,aftPayCoin=%s,errorInfo=%s" 
                  % (orderInfo, orderCoin, payOrderType, eventName, befPayCoin, aftPayCoin, errorInfo), playerID)
    
    addItemList = []
    paramList = [orderInfo, orderCoin]
    PlayerControl.SendMailByKey("ExchangeToPayCoin", [playerID], addItemList, paramList)
    
    if payOrderType != PayOrderType_PayCoin:
        serverDay = GameWorld.GetGameWorld().GetGameWorldDictByKey(ShareDefine.Def_Notify_WorldKey_ServerDay) + 1
        addDRDict.update({"coinType":ChConfig.CoinType_ExchangePayCoin, "PayCoin":[befPayCoin, aftPayCoin], 
                          "VIPLv":curPlayer.GetVIPLv(), "ServerDay":serverDay, "eventName":eventName})
        DataRecordPack.DR_CTGOK(curPlayer, addDRDict)
    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):
    ## Ö±½Ó³äÖµ×Ô¶¨Òå½ð¶î
    
    appID = GameWorld.GetPlayerPlatform(curPlayer)
    payRMBNum = 1
    oneRMBIpyData = None # Ä¬ÈÏÈ¡µ¥Î»1»õ±Ò¶ÔÓ¦³äÖµÅäÖÃ
    ipyDataMgr = IpyGameDataPY.IPY_Data()
    for i in xrange(ipyDataMgr.GetOrderInfoCount()):
        ipyData = ipyDataMgr.GetOrderInfoByIndex(i)
        # µ¥Î»1ÔªÅäÖ㬲»¹ØÁª³äÖµID¡¢Àñ°üID
        if appID == ipyData.GetAppID() and ipyData.GetPayRMBNum() == payRMBNum and not ipyData.GetCTGID() and not ipyData.GetGiftbagID():
            oneRMBIpyData = ipyData
            break
    if not oneRMBIpyData:
        GameWorld.ErrLog("Can not found one RMB pay num orderInfo! appID=%s,payRMBNum=%s" % (appID, payRMBNum), curPlayer.GetPlayerID())
        return
    
    oneRMBCoinExp = oneRMBIpyData.GetCoinExp()
    
    prizeGold = 0
    giveItemList = []
    orderCoin = CommFunc.RMBToCoin(orderRMB)
    coinExp = int(orderRMB * oneRMBCoinExp)
    addGold = coinExp # ´Ë·½Ê½Ôö¼ÓµÄÏÉÓñ = Ö±³ä¾­Ñé
    addDRDict = {"orderCoin":orderCoin, "isAddBourseMoney":isAddBourseMoney, "eventName":eventName}
    DoCTGLogic(curPlayer, ChConfig.CoinType_Gold, orderCoin, addGold, prizeGold, giveItemList, isAddBourseMoney, eventName, addDRDict, coinExp=coinExp)
    return True
 
def PlayerItemCTG(curPlayer, orderRMB, eventName, isAddBourseMoney, addDataDict={}):
    ## Ê¹ÓÃÔùË͵ÄÎïÆ·¶Ò»»µãȯ£¬Ò»°ãÓÃÓÚbt°æ£¬ÏÞ³¬¼¶ÏÖ½ð
    # 20210120 ¸Ų̂Ö÷¸É°æÔÝ·ÏÆú
#    prizeGold = 0
#    giveItemList = []
#    orderCoin = CommFunc.RMBToCoin(orderRMB) # µ¥Î»£¬·Ö
#    addGold = orderRMB * GetCoinRate()
#    addDRDict = {"orderCoin":orderCoin, "eventName":eventName}
#    addDRDict.update(addDataDict)
#    DoCTGLogic(curPlayer, ChConfig.CoinType_ItemSuper, 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 = CommFunc.RMBToCoin(ipyData.GetUsdMoney(), 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, payOrderType=PayOrderType_Default):
    ## °´ÉÌÆ·±àºÅ³äÖµ
    orderCoin = chargeInfo.GetCoin()
    #notePrizeCoin = chargeInfo.GetPrizeCoin()
    orderInfo = chargeInfo.GetOrderInfo() # ÉÌÆ·±àºÅ
    orderID = chargeInfo.GetOrderID() #¶©µ¥ºÅ£¬¶Ò»»³É¹¦ºóÇå³ý
    isAddBourseMoney = chargeInfo.GetIsAddBourseMoney()
    if orderID:
        curPlayer.SendDBFinishRecharge(orderID)
        
    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
    
    # Ô½Äϰ汾Åä±í¼°coin¾ùʹÓÃÔ½Ä϶ÜÔ­Öµ£¬µ«ÊÇÑéÖ¤ÓÃÃÀÔªÑéÖ¤
    GameWorld.Log("Ô½ÄϳäÖµÑéÖ¤ÃÀÔª: orderInfo=%s,orderCoin=%s,orderID=%s" % (orderInfo, orderCoin, orderID), curPlayer.GetPlayerID())
    orderCoinUsd = orderCoin # Èë¿âµÄÊÇÃÀÔª·Ö
    orderCoin = CommFunc.RMBToCoin(ipyData.GetPayRMBNum()) # ÓÎÏ·ÄÚorderCoinת»¯ÎªÔ½Ä϶Ü
    usdMoney = ipyData.GetUsdMoney()
    GameWorld.Log("    ×ª»¯ºó: orderInfo=%s,orderCoin=%s,orderCoinUsd=%s" % (orderInfo, orderCoin, orderCoinUsd), curPlayer.GetPlayerID())
    addDRDict["orderCoin"] = orderCoin
    addDRDict["orderCoinUsd"] = orderCoinUsd
    if orderCoinUsd != CommFunc.RMBToCoin(usdMoney, 100):
        DataRecordPack.DR_CTGError(curPlayer, "The orderCoinUsd is not equal to the ipyData's UsdMoney(%s)!" % usdMoney, addDRDict)
        return
    
    if payOrderType == PayOrderType_PayCoin:
        if ipyData.GetCTGID():
            ctgIpyData = IpyGameDataPY.GetIpyGameData("CTG", ipyData.GetCTGID())
            if ctgIpyData:
                if ctgIpyData.GetPayType() == PayType_PayCoin:
                    GameWorld.ErrLog("´ú±Ò¿É²»ÓÃÓÚÖ§¸¶´ú±Ò³äÖµ!appID=%s,orderInfo=%s" % (appID, orderInfo), curPlayer.GetPlayerID())
                    return
                ctgID = ctgIpyData.GetRecordID()
                payCoinLimitCTGIDList = IpyGameDataPY.GetFuncEvalCfg("RechargeLimit", 1)
                if ctgID in payCoinLimitCTGIDList:
                    GameWorld.ErrLog("¸Ã³äÖµID¿É²»ÓÃÓÚÖ§¸¶´ú±Ò³äÖµ!appID=%s,orderInfo=%s,ctgID=%s" % (appID, orderInfo, ctgID), curPlayer.GetPlayerID())
                    return
        #Ö±½Ó¿Û£¬ÀàËÆ³äÖµ¿ÛÇ®£¬ÕâÀïÊÇ·¢·ÅÎïÆ·£¬¿ÉÄÜ»áÓз¢·Åʧ°ÜµÄµ±×ö CTGError ´¦Àí
        if not PlayerControl.PayMoney(curPlayer, ShareDefine.TYPE_Price_PayCoin, orderCoin, eventName, {ChConfig.Def_Cost_Reason_SonKey:orderInfo, "orderInfo":orderInfo}):
            GameWorld.ErrLog("´ú±Ò²»×ã! appID=%s,orderInfo=%s,orderCoin=%s,curPayCoinTotal=%s" 
                             % (appID, orderInfo, orderCoin, PlayerControl.GetPayCoinTotal(curPlayer)), curPlayer.GetPlayerID())
            return
        
    addDRDict["payOrderType"] = payOrderType
    
    moneyType, addGold, prizeGold, giveItemList, ctgIpyData = 0, 0, 0, [], None
    
    if ipyData.GetCTGID():
        ctgResultInfo = __GetCTGInfoByID(curPlayer, ipyData.GetCTGID(), addDRDict)
        if not ctgResultInfo:
            return
        moneyType, addGold, prizeGold, giveItemList, ctgIpyData = ctgResultInfo
        
    elif ipyData.GetGiftbagID():
        giftbagID = ipyData.GetGiftbagID()
        if 100 <= giftbagID < 199:
            if not PlayerDailyGiftbag.OnPlayerOrderDailyGiftbag(curPlayer, giftbagID, addDRDict):
                return
        elif not PlayerFlashGiftbag.OnPlayerOrderGiftbag(curPlayer, [ipyData.GetGiftbagID()], addDRDict):
            return
    else:
        #ÓÃÓÚÖ§¸¶ÆäËûµÄÉÌÆ·£¬´ýÀ©Õ¹...
        DataRecordPack.DR_CTGError(curPlayer, "The orderInfo is useless!", addDRDict)
        return
    
    coinExp = ipyData.GetCoinExp()
    coinType = ChConfig.CoinType_Gold if (ctgIpyData and ctgIpyData.GetPayType() in [PayType_Gold, PayType_GoldPlus]) else ChConfig.CoinType_Buy # ¹æ¶¨2Ϊֱ³ä£¬ÆäËûΪֱ¹º
    if not DoCTGLogic(curPlayer, coinType, orderCoin, addGold, prizeGold, giveItemList, isAddBourseMoney, eventName, addDRDict, ctgIpyData, moneyType, coinExp):
        return
    
    #³äÖµ³É¹¦Ö÷¶¯²éѯһ´Î£¬ÎÞ³äÖµÊýÁ¿¾Í²»»á¼ÌÐø²éѯ
    if orderID:
        #curPlayer.SendDBFinishRecharge(orderID)
        pass
        
    # ³äÖµ³É¹¦»Ø±¨¿Í»§¶Ë£¬SDKµÈ»áÓõ½
    recordID = ctgIpyData.GetRecordID() if ctgIpyData else 0
    Sync_CoinToGoldReport(curPlayer, orderID, orderCoin, recordID, orderInfo)
    
    curPlayer.SendDBQueryRecharge()
    return True
 
def __GetCTGInfoByID(curPlayer, recordID, addDRDict):
    ## ¸ù¾Ý³äÖµÊý¾ÝID»ñÈ¡³äÖµÐÅÏ¢
    
    ipyData = IpyGameDataPY.GetIpyGameData("CTG", recordID)
    if not ipyData:
        DataRecordPack.DR_CTGError(curPlayer, "Can not find CTG ipyData!", addDRDict)
        return
    
    addDRDict.update({"recordID":recordID})
    
    # ³É³¤±ØÂòÀàÐÍ
    if ipyData.GetPayType() == PayType_GrowupBuy:
        canBuy, errInfo = PlayerActGrowupBuy.CheckGrowupBuyState(curPlayer, recordID)
        if not canBuy:
            DataRecordPack.DR_CTGError(curPlayer, errInfo, addDRDict)
            return
        
    totalBuyCountLimit = ipyData.GetTotalBuyCount()
    totalBuyCount = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_CTGGoodsBuyCount % recordID)
    if totalBuyCountLimit:
        addDRDict.update({"totalBuyCountLimit":totalBuyCountLimit, "totalBuyCount":totalBuyCount})
        if totalBuyCount >= totalBuyCountLimit:
            ExchangePayCoin(curPlayer, "Pay count limit total!totalBuyCount=%s" % totalBuyCount, addDRDict)
            return        
    
    dailyBuyCountLimit = ipyData.GetDailyBuyCount()
    todayBuyCount = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TodayCTGCount % recordID)
    if dailyBuyCountLimit:
        addDRDict.update({"dailyBuyCountLimit":dailyBuyCountLimit, "todayBuyCount":todayBuyCount})
        if todayBuyCount >= dailyBuyCountLimit:
            ExchangePayCoin(curPlayer, "Pay count limit today!todayBuyCount=%s" % todayBuyCount, addDRDict)
            return
        
    weekBuyCountLimit = ipyData.GetWeekBuyCount()
    weekBuyCount = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_WeekCTGCount % recordID)
    if weekBuyCountLimit:
        addDRDict.update({"weekBuyCountLimit":weekBuyCountLimit, "weekBuyCount":weekBuyCount})
        if weekBuyCount >= weekBuyCountLimit:
            ExchangePayCoin(curPlayer, "Pay count limit week!weekBuyCount=%s" % weekBuyCount, addDRDict)
            return
        
    monthBuyCountLimit = ipyData.GetMonthBuyCount()
    monthBuyCount = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_MonthCTGCount % recordID)
    if monthBuyCountLimit:
        addDRDict.update({"monthBuyCountLimit":monthBuyCountLimit, "monthBuyCount":monthBuyCount})
        if monthBuyCount >= monthBuyCountLimit:
            ExchangePayCoin(curPlayer, "Pay count limit month!monthBuyCount=%s" % monthBuyCount, addDRDict)
            return
        
    selectItemList = []
    selectItemInfo = ipyData.GetSelectItemInfo()
    if selectItemInfo:
        selectItemValue = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_CTGSelectItemValue % recordID)
        addDRDict.update({"selectItemValue":selectItemValue})
        selectItemList, errorInfo = GetSelectItemListInfo(selectItemInfo, selectItemValue)
        if errorInfo:
            ExchangePayCoin(curPlayer, errorInfo, addDRDict)
            return
        addDRDict.update({"selectItemList":selectItemList})
        
    totalBuyCountUpd = min(totalBuyCount + 1, ChConfig.Def_UpperLimit_DWord)
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_CTGGoodsBuyCount % recordID, totalBuyCountUpd)
    addDRDict.update({"totalBuyCountUpd":totalBuyCountUpd})
    
    todayBuyCountUpd = min(todayBuyCount + 1, ChConfig.Def_UpperLimit_DWord)
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_TodayCTGCount % recordID, todayBuyCountUpd)
    addDRDict.update({"todayBuyCountUpd":todayBuyCountUpd})
    
    weekBuyCountUpd = min(weekBuyCount + 1, ChConfig.Def_UpperLimit_DWord)
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_WeekCTGCount % recordID, weekBuyCountUpd)
    addDRDict.update({"weekBuyCountUpd":weekBuyCountUpd})
    
    monthBuyCountUpd = min(monthBuyCount + 1, ChConfig.Def_UpperLimit_DWord)
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_MonthCTGCount % recordID, monthBuyCountUpd)
    addDRDict.update({"monthBuyCountUpd":monthBuyCountUpd})
    
    giveItemList = []
    giveItemList += GetCTGGiveItemList(ipyData)
    giveItemList += selectItemList
    
    payType = ipyData.GetPayType()
    moneyType = ipyData.GetMoneyType() # »ñµÃ»õ±ÒÀàÐÍ
    addGold = ipyData.GetGainGold() # »ñµÃ»õ±ÒÊý
    gainGoldPrize = ipyData.GetGainGoldPrize() # ÔùËÍ»õ±ÒÊý£¬Ê״γäÖµÔùËÍÏÉÓñʱ£¬´ËÏÉÓñ²»¸ø
    firstGoldPrize = ipyData.GetFirstGoldPrize() # Ê״γäÖµÔùË͵ÄÏÉÓñ
    prizeGold = firstGoldPrize if (not totalBuyCount and firstGoldPrize) else gainGoldPrize
    if moneyType == IPY_GameWorld.TYPE_Price_Gold_Money:
        if payType in [PayType_Gold, PayType_GoldPlus] and PlayerGoldInvest.GetInvestState(curPlayer, ChConfig.InvestType_Life):
            prizeGold = addGold # bt tqxbqy °æ±¾£¬ÓÀ¾Ã¿¨ÏÉÓñÖ±³ä¹Ì¶¨Ë«±¶
        actPrizeGold = PlayerActRechargePrize.DoAddPlayerActRechargePrizeCount(curPlayer, recordID)
        if actPrizeGold:
            prizeGold += actPrizeGold
            addDRDict.update({"actRechargePrize":1})
            
    Sync_CoinToGoldCountInfo(curPlayer, [recordID])
    return moneyType, addGold, prizeGold, giveItemList, ipyData
 
def GetSelectItemListInfo(selectItemInfo, selectItemValue):
    errorInfo = ""
    selectItemList = []
    selectValue = selectItemValue
    GameWorld.DebugLog("selectItemValue=%s,selectItemInfo=%s" % (selectItemValue, selectItemInfo))
    for selectNum, selectIDList in enumerate(selectItemInfo, 1):
        selectIndex = selectValue % 100 - 1 # ¼Ç¼µÄʱºò+1
        if selectIndex < 0:
            errorInfo = "Select item is not complete!selectItemValue=%s,selectNum=%s,selectIndex=%s" % (selectItemValue, selectNum, selectIndex)
            return selectItemList, errorInfo
        if selectIndex >= len(selectIDList):
            errorInfo = "Select item index out of range!selectItemValue=%s,selectNum=%s,selectIndex=%s" % (selectItemValue, selectNum, selectIndex)
            return selectItemList, errorInfo
        selectID = selectIDList[selectIndex]
        selectIpyData = IpyGameDataPY.GetIpyGameData("CTGSelectItem", selectID)
        if not selectIpyData:
            errorInfo = "SelectID is not exist!selectItemValue=%s,selectNum=%s,selectIndex=%s,selectID=%s" % (selectItemValue, selectNum, selectIndex, selectID)
            return selectItemList, errorInfo
        selectItemList.append([selectIpyData.GetItemID(), selectIpyData.GetItemCount(), selectIpyData.GetIsAuctionItem()])
        selectValue = selectValue / 100
        GameWorld.DebugLog("    selectNum=%s,selectIndex=%s,selectID=%s,selectItemList=%s,selectItemValue=%s" 
                           % (selectNum, selectIndex, selectID, selectItemList, selectItemValue))
    return selectItemList, errorInfo
 
def GetCTGGiveItemList(ipyData):
    ## »ñÈ¡³äÖµID¶ÔÓ¦¸øÎïÆ·Áбí
    if not ipyData:
        return []
    
    gainItemList = ipyData.GetGainItemList()
    actWorldLVGainItemInfo = ipyData.GetActWorldLVGainItemInfo()
    giveItemList = []
    # »î¶¯ÊÀ½çµÈ¼¶¶ÔÓ¦ÎïÆ·ÐÅÏ¢£¬Èç¹ûÓжÔÓ¦»î¶¯Ö§³Ö ÇÒ ¸ÃÅäÖÃÓÐÅ䣬ÔòĬÈÏ×߸ÃÅäÖ㬷ñÔòʹÓ󣹿µÄĬÈÏÎïÆ·ÅäÖÃ
    payTypeActNameDict = {PayType_GrowupBuy:ShareDefine.OperationActionName_GrowupBuy,
                          
                          # ... ÓÐÐÂÔöµÄ»î¶¯ÐèÒªÖ§³Ö£¬ÔòÔÚ´ËÐÂÔöÅäÖÃÉϼ´¿É£¬ºóÃæÈ¡ÎïÆ·µÄÂß¼­¶¼ÊÇÒ»ÑùµÄ
                          }
    if actWorldLVGainItemInfo and ipyData.GetPayType() in payTypeActNameDict:
        actName = payTypeActNameDict[ipyData.GetPayType()]
        actInfo = PyGameData.g_operationActionDict.get(actName, {}) # ×¢£ºÏà¹Ø×´Ì¬ÔÚǰÖÃÂß¼­ÒѾ­ÅжϹý£¬ÕâÀï²»ÔÙÅжÏ
        actWorldLV = actInfo.get(ShareDefine.ActKey_WorldLV, 0)
        actWorldLVList = [int(strWorldLV) for strWorldLV in actWorldLVGainItemInfo.keys()]
        actWorldLVList.sort() # Ê¹Óàint µÄÖµÅÅ£¬·ñÔò¿ÉÄÜÒýÆðÅÅÐò´íÎó
        for worldLV in actWorldLVList:
            if actWorldLV <= worldLV:
                giveItemList = actWorldLVGainItemInfo[str(worldLV)]
                break
        if not giveItemList:
            giveItemList = actWorldLVGainItemInfo[str(actWorldLVList[-1])] # Ã»ÓÐÆ¥Åäµ½µÄ»°Ä¬ÈÏÈ¡×îºóÒ»¸öµÈ¼¶ÅäÖÃ
    else:
        giveItemList = gainItemList
    return giveItemList
 
def DoCTGLogic(curPlayer, coinType, orderCoin, addGold, prizeGold, giveItemList, isAddBourseMoney, eventName, addDRDict, ctgIpyData=None, moneyType=IPY_GameWorld.TYPE_Price_Gold_Money, coinExp=0):
    
    if ctgIpyData and ctgIpyData.GetPayType() == PayType_PayCoin:
        # ´ú±Ò³äÖµ£¬½ö¸ø´ú±Ò£¬²»´¥·¢ÆäËûÄÚÈÝ
        coinType = ChConfig.CoinType_PayCoin
        orderInfo = addDRDict.get("orderInfo", "")
        orderCoin = addDRDict.get("orderCoin", 0)
        payOrderType = addDRDict.get("payOrderType", PayOrderType_Default)
        playerID = curPlayer.GetPlayerID()
        befPayCoin = PlayerControl.GetPayCoin(curPlayer)
        if addGold and moneyType == ShareDefine.TYPE_Price_PayCoin:
            drDict = {ChConfig.Def_Give_Reason_SonKey:orderInfo, "payOrderType":payOrderType, "orderInfo":orderInfo}
            PlayerControl.GiveMoney(curPlayer, moneyType, addGold, eventName, drDict)
        aftPayCoin = PlayerControl.GetPayCoin(curPlayer)
        GameWorld.Log("³äÖµ´ú±Ò: orderInfo=%s,orderCoin=%s,payOrderType=%s,eventName=%s,befPayCoin=%s,aftPayCoin=%s" 
                      % (orderInfo, orderCoin, payOrderType, eventName, befPayCoin, aftPayCoin), playerID)
        
        serverDay = GameWorld.GetGameWorld().GetGameWorldDictByKey(ShareDefine.Def_Notify_WorldKey_ServerDay) + 1
        addDRDict.update({"coinType":coinType, "PayCoin":[befPayCoin, aftPayCoin], 
                          "VIPLv":curPlayer.GetVIPLv(), "ServerDay":serverDay, "eventName":eventName})
        DataRecordPack.DR_CTGOK(curPlayer, addDRDict)
        return True
    
    if coinType not in [ChConfig.CoinType_Gold, ChConfig.CoinType_Buy, ChConfig.CoinType_ItemSuper]:
        DataRecordPack.DR_CTGError(curPlayer, "coinType error! coinType(%s)!" % coinType, addDRDict)
        return
    
    isRealMoney = True if addDRDict.get("orderID") else False # ÊÇ·ñÕæÊµ»õ±Ò³äÖµ£¬½öÕæÊµ»õ±Ò³äÖµ¶©µ¥ÓÐorderID£¬ºǫ́³äÖµµÄ²»ËãÕæÊµ»õ±Ò³äÖµ
    payOrderType = addDRDict.get("payOrderType", PayOrderType_Default)
    if payOrderType == PayOrderType_PayCoin:
        #isRealMoney = True # ´ú±Ò³äÖµÔÚÓÎÏ·ÄÚÈÝÉÏËãÕæÊµ³äÖµ£¬tqxbqyÔݲ»Ë㣬´ú±ÒÀ´Ô´¿ÉÄÜÊÇÔùË͵쬹ÊÔݲ»Ëã
        coinType = ChConfig.CoinType_UsePayCoin # tqxbqyÐè񻂿·Ö´ú±ÒÖ§¸¶
    ctgRealToday = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_CTGRealToday) # µ±ÈÕÕæÊµ»õ±Ò³äÖµCoinÊý £¬²»º¬ºǫ́³äÖµ- ½ñÈÕ
    ctgRealTotal = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_CTGRealTotal) # ÀÛ¼ÆÕæÊµ»õ±Ò³äÖµCoinÊý £¬²»°üºǫ́³äÖµ - ×ܼÆ
    ctgRealFirstTime = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_CTGRealFirstTime) # Ê×´ÎÕæÊµ»õ±Ò³äֵʱ¼ä´Á
    if isRealMoney:
        if not ctgRealFirstTime:
            ctgRealFirstTime = int(time.time())
            PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_CTGRealFirstTime, ctgRealFirstTime)
        ctgRealToday = min(ctgRealToday + orderCoin, ChConfig.Def_UpperLimit_DWord)
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_CTGRealToday, ctgRealToday)
        ctgRealTotal = min(ctgRealTotal + orderCoin, ChConfig.Def_UpperLimit_DWord)
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_CTGRealTotal, ctgRealTotal)
        Sync_CoinToGoldCountInfo(curPlayer, [])
        
    notifyMark = ctgIpyData.GetNotifyMark() if ctgIpyData else ""
    goldBefore = curPlayer.GetGold()
    bourseMoneyBefore = PlayerControl.GetMoney(curPlayer, ShareDefine.TYPE_Price_BourseMoney)
    
    if addGold:
        PlayerControl.GiveMoney(curPlayer, moneyType, addGold, eventName, addDRDict, isGiveBourseMoney=isAddBourseMoney)
        
    if prizeGold:
        PlayerControl.GiveMoney(curPlayer, moneyType, prizeGold, eventName, addDRDict, isGiveBourseMoney=isAddBourseMoney)
        
    if giveItemList:
        ItemControler.GivePlayerItemOrMail(curPlayer, giveItemList, "", event=[ChConfig.ItemGive_CTG, True, copy.deepcopy(addDRDict)])
        if notifyMark:
            mainItemID = giveItemList[0][0]
            PlayerControl.WorldNotify(0, notifyMark, [curPlayer.GetName(), mainItemID, ''])
    else:
        if notifyMark:
            PlayerControl.WorldNotify(0, notifyMark, [curPlayer.GetName()])
            
    addVIPExp = coinExp
    PlayerVip.AddVIPExp(curPlayer, addVIPExp)
    
    changeCoinPointBefore = curPlayer.GetChangeCoinPointTotal()
    curPlayer.SetChangeCoinPointTotal(min(changeCoinPointBefore + orderCoin, ChConfig.Def_UpperLimit_DWord), 0)
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_FirstGoldTry, 0)
    
    todayCTGCoinTotal = min(curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TodayCTGCoinTotal) + orderCoin, ChConfig.Def_UpperLimit_DWord)
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_TodayCTGCoinTotal, todayCTGCoinTotal)
    
    goldAfter = curPlayer.GetGold()
    changeCoinPointAfter = curPlayer.GetChangeCoinPointTotal()
    bourseMoneyAfter = PlayerControl.GetMoney(curPlayer, ShareDefine.TYPE_Price_BourseMoney)
    
    #---³äÖµ³É¹¦ºóÂß¼­---
    # ¹¦ÄÜͳһÒÔ·Ö´æ´¢¼Ç¼£¬Íæ¼Ò×ֵ䲻֧³Ö´æÐ¡Êý
    
    # ËùÓÐÕæÊµ³äÖµ¾ùÓÐЧµÄ
    if coinType in [ChConfig.CoinType_Gold, ChConfig.CoinType_Buy]:
        #¿ç·þ³äÖµÅÅÐл
        CrossActCTGBillboard.AddCTGRMB(curPlayer, orderCoin)
        #¿ç·þÈ«Ãñ³äÖµ
        CrossActAllRecharge.AddCTGRMB(curPlayer, orderCoin)
        PlayerActManyDayRecharge.AddManyDayRechargeValue(curPlayer, orderCoin) # ¶àÈÕÁ¬³ä
        #ºì°ü, ÐèÒªÕæÊµ³äÖµ
        PlayerFamilyRedPacket.OnPlayerRecharge(curPlayer, orderCoin)
        
    # Ö»Ëã³äÏÉÓñµÄ
    if coinType == ChConfig.CoinType_Gold:
        PlayerActRechargeRebateGold.AddRechargeRebateGoldRMB(curPlayer, addGold)
        
    #ÏɽçÊ¢µä-³äÖµ´óÀñ
    PlayerFairyCeremony.OnFCRecharge(curPlayer)
    PlayerNewFairyCeremony.OnFCRecharge(curPlayer)
    PlayerGoldGift.OnPlayerChargeGold(curPlayer)
    #ÀÛ»ý³äÖµXÔª
    PlayerActTotalRecharge.AddTotalRechargeGold(curPlayer, orderCoin, coinType)
    PlayerActGarbageSorting.AddActGarbageTaskProgress(curPlayer, ChConfig.Def_GarbageTask_CTG, addVIPExp, coinType) # À¬»ø·ÖÀà
    PlayerActSingleRecharge.UpdSingleRechargeValue(curPlayer, orderCoin, coinType) # µ¥±ÊÀÛ³ä
    PlayerActTurntable.OnPlayerRecharge(curPlayer, orderCoin, coinType) # ×ªÅÌ
    PlayerFairyCeremony.AddFCCTGRMB(curPlayer, orderCoin)
    PlayerNewFairyCeremony.AddFCCostGold(curPlayer, orderCoin)
    PlayerActFamilyCTGAssist.OnPlayerCTG(curPlayer)
    #¿ª·þ»î¶¯
    #OpenServerCampaign.AddOpenServerCampaignRecordData(curPlayer, ShareDefine.Def_Campaign_Type_Recharge, orderCoin)
    PlayerWeekParty.AddWeekPartyActionCnt(curPlayer, ChConfig.Def_WPAct_Recharge, addVIPExp)
    PlayerFeastTravel.AddFeastTravelTaskValue(curPlayer, ChConfig.Def_FeastTravel_CTGExp, addVIPExp)
    #Ͷ×Ê
    if ctgIpyData:
        ctgID = ctgIpyData.GetRecordID()
        PlayerGoldInvest.InvestByCTG(curPlayer, ctgID)
        PlayerGoldGift.OnGiftByCTGID(curPlayer, ctgID)
        PlayerZhanling.OnActiviteByCTGID(curPlayer, ctgID)
        PlayerMineArea.OnMineTreasureByCTGID(curPlayer, ctgID)
        PlayerTongTianLing.OnActiviteTTTByCTGID(curPlayer, ctgID)
        
    serverDay = GameWorld.GetGameWorld().GetGameWorldDictByKey(ShareDefine.Def_Notify_WorldKey_ServerDay) + 1
    addDRDict.update({"gold":[goldBefore, goldAfter], "changeCoinPoint":[changeCoinPointBefore, changeCoinPointAfter], "todayCTGCoinTotal":todayCTGCoinTotal,
                      "bourseMoney":[bourseMoneyBefore, bourseMoneyAfter], "addGold":addGold, "prizeGold":prizeGold, "giveItemList":giveItemList, "coinType":coinType,
                      "coinExp":coinExp, "addVIPExp":addVIPExp, "VIPLv":curPlayer.GetVIPLv(), "ServerDay":serverDay,
                      "ctgRealToday":ctgRealToday, "ctgRealTotal":ctgRealTotal, "ctgRealFirstTime":GameWorld.ChangeTimeNumToStr(ctgRealFirstTime) if ctgRealFirstTime else ""})
    DataRecordPack.DR_CTGOK(curPlayer, addDRDict)
    GameWorld.Log("Billing: coinType=%s,eventName=%s, %s" % (coinType, eventName, addDRDict), curPlayer.GetPlayerID())
    return True
 
#===============================================================================
 
## Ä£Äâ³äÖµÐÅÏ¢£¬µãȯ³äÖµÐÅÏ¢
#
# µãȯ³äÖµÐÅÏ¢
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, recordID, orderInfo):
    openGleeGame = ChPyNetSendPack.tagMCCoinToGoldReport()
    openGleeGame.Clear()
    openGleeGame.OrderLen = len(orderID)
    openGleeGame.OrderID = orderID
    openGleeGame.Coin = money
    openGleeGame.RecordID = recordID
    openGleeGame.OrderInfo = orderInfo
    openGleeGame.OrderInfoLen = len(openGleeGame.OrderInfo)
    
    NetPackCommon.SendFakePack(curPlayer, openGleeGame)
    return
 
def Sync_CoinToGoldCountInfo(curPlayer, syncRecordIDList=None):
    if syncRecordIDList == None:
        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.RealToday = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_CTGRealToday)
    countInfoPack.RealTotal = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_CTGRealTotal)
    countInfoPack.RealFirstTime = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_CTGRealFirstTime)
    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)
        countInfo.WeekPayCount = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_WeekCTGCount % recordID)
        countInfo.MonthPayCount = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_MonthCTGCount % recordID)
        countInfo.SelectItemValue = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_CTGSelectItemValue % recordID)
        countInfoPack.CTGCountInfoList.append(countInfo)
    countInfoPack.RecordCount = len(countInfoPack.CTGCountInfoList)
    NetPackCommon.SendFakePack(curPlayer, countInfoPack)
    return
 
## ---------- Ã¿ÈÕÃâ·ÑÖ±¹ºÀñ°ü ----------------
 
def OnGetDayFreeGoldGift(curPlayer):
    ''' ÁìȡÿÈÕÃâ·ÑÖ±¹ºÀñ°ü
    '''
    
    isGet = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_DayFreeGoldGiftState)
    if isGet:
        #GameWorld.DebugLog("ÒѾ­ÁìÈ¡¹ýÿÈÕÃâ·ÑÖ±¹ºÀñ°ü!")
        return
    
    rewardItemList = IpyGameDataPY.GetFuncEvalCfg("DayFreeGoldGift", 1)
    if not rewardItemList:
        return
    
    needSpace = len(rewardItemList)
    packSpace = ItemCommon.GetItemPackSpace(curPlayer, IPY_GameWorld.rptItem, needSpace)
    if needSpace > packSpace:
        PlayerControl.NotifyCode(curPlayer, "GeRen_chenxin_998371")
        return
    
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_DayFreeGoldGiftState, 1)
    
    # ¸øÎïÆ·
    isAuctionItem = False
    for itemID, itemCount in rewardItemList:        
        ItemControler.GivePlayerItem(curPlayer, itemID, itemCount, isAuctionItem, [IPY_GameWorld.rptItem])
        
    # Í¨Öª¿Í»§¶Ë
    Sync_DayFreeGoldGiftState(curPlayer)
    return
 
def Sync_DayFreeGoldGiftState(curPlayer):
    clientPack = ChPyNetSendPack.tagMCDayFreeGoldGiftState()
    clientPack.DayFreeGoldGiftState = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_DayFreeGoldGiftState)
    NetPackCommon.SendFakePack(curPlayer, clientPack)
    return
 
## ------------------------------------------
## ---------- ´´½ÇÔÚÏß³äÖµÌØ»Ý ---------------
 
def OnGetOnlineRechargeTH(curPlayer):
    ## ÁìÈ¡´´½ÇÔÚÏß³äÖµÌØ»Ý
    awardState = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_OnlineRechargeTHAward)
    if awardState:
        #GameWorld.DebugLog("ÒÑÁìÈ¡¸Ã½±Àø!")
        return
    
    # ºó¶ËÖ»ÑéÖ¤ÊÇ·ñÓгäÖµÆäÖÐÒ»¸ö¼´¿É£¬²»ÑéÖ¤³äֵʱ¼ä£¨³äֵͬ²½µ½ÓÎÏ··þÎñÆ÷ÓÐʱ¼ä²î£©
    canGet = False
    needCtgIDList = IpyGameDataPY.GetFuncEvalCfg("OnlineRechargeTH", 2)
    for ctgID in needCtgIDList:
        if curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_CTGGoodsBuyCount % ctgID):
            canGet = True
            break
        
    if not canGet:
        return
    
    awardItemList = IpyGameDataPY.GetFuncEvalCfg("OnlineRechargeTH", 3)
    if not ItemControler.CheckPackSpaceEnough(curPlayer, awardItemList):
        return
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_OnlineRechargeTHAward, 1)
    
    for itemID, itemCount, isAuctionItem in awardItemList:
        ItemControler.GivePlayerItem(curPlayer, itemID, itemCount, isAuctionItem, [IPY_GameWorld.rptItem], 
                                     event=["OnlineRechargeTH", False, {}])
        
    SyncOnlineRechargeTH(curPlayer)
    return
 
def SyncOnlineRechargeTH(curPlayer):
    clientPack = ChPyNetSendPack.tagMCOnlineRechargeTH()
    clientPack.AwardState = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_OnlineRechargeTHAward)
    NetPackCommon.SendFakePack(curPlayer, clientPack)
    return
 
## ------------------------------------------