Offer.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <?php
  2. /**
  3. * 同布赌注表
  4. * User: ben
  5. */
  6. class Sync_Offer extends Sync_Base {
  7. protected $dbKey = 'dw_baccarat';
  8. protected $frequency = 1;
  9. protected $index = 4;
  10. protected $dataField = ['player','win', 'win_int', 'state', 'update_time_int', 'transfer_trx_id'];
  11. private $objRewardRelation;
  12. private $objAccount;
  13. /**
  14. * 清除数据的时间间隔
  15. * @var int
  16. */
  17. protected $clearTtl = 600;
  18. protected $clearAction = 'clearoffer';
  19. public function __construct() {
  20. $this->objRewardRelation = new TableHelper('referee_relation', 'dw_eos');
  21. $this->objAccount = new Account();
  22. parent::__construct('offer', 'id', 'update_time_int');
  23. }
  24. protected function addNewRows($newRows) {
  25. $ids = [];
  26. $players = [];
  27. foreach ($newRows as $k => $row) {
  28. $players[] = $row['player'];
  29. $row['offerall_int'] = Eos::toNumber($row['offerall']);
  30. $row['offertype'] = implode('|', $row['offertype']);
  31. $row['offeramount_int'] = implode('|', array_map('Eos::toNumber', $row['offeramount']));
  32. $row['offeramount'] = implode('|', $row['offeramount']);
  33. $row['create_time'] = $this->formatDateTime($row['create_time']);
  34. $row['win_int'] = Eos::toNumber($row['win']);
  35. $ids[] = $row['id'];
  36. $newRows[$k] = $row;
  37. }
  38. parent::addNewRows($newRows);
  39. $vips = $this->objAccount->getVipLevels($players);
  40. $offerAmount = [];
  41. $offerIds = [];
  42. foreach ($newRows as $row) {
  43. $player = $row['player'];
  44. $eventData = [
  45. 'id' => $row['id'],
  46. 'game_id' => $row['game_id'],
  47. 'player' => $row['player'],
  48. 'offerall' => $row['offerall_int'],
  49. 'offertype' => $row['offertype'],
  50. 'offeramount' => $row['offeramount_int'],
  51. 'vip_level' => $vips[$player] ?: 0,
  52. ];
  53. Eos::pubEvent('baccarat:new_offer', $eventData);
  54. $offerAmount[$player] = $row['offerall_int'];
  55. $offerIds[$player] = $row['id'];
  56. // 绑定信息
  57. if ($row['ref']) { // 有邀请人
  58. list($rt, $msg) = Account::bindReferee($player, $row['ref'], $this->objRewardRelation, $this->objAccount);
  59. if (!$rt) {
  60. Eos::log("Referee: offerId:{$row['id']}, player:{$player} 受邀请失败,msg:{$msg}");
  61. }
  62. }
  63. }
  64. //检查推广奖励
  65. $relations = $this->objRewardRelation->getAll(['player' => $players]);
  66. $refereePlayers = arrayFormatKey($relations, 'player', 'referee_player');
  67. foreach ($refereePlayers as $player => $refereePlayer) {
  68. $refereeData = [
  69. 'gameid' => $offerIds[$player],
  70. 'bet_amount' => $offerAmount[$player],
  71. ];
  72. list($flag, $msg) = Account::addRefereeReward($player, $refereePlayer, $refereeData);
  73. if (!$flag) {
  74. Eos::log("offerId:{$offerIds[$player]}, player:{$player}, refereePlayer:{$refereePlayer}, referee reward error:{$msg}");
  75. }
  76. }
  77. }
  78. // protected function updateDb($rows) {
  79. //
  80. // parent::updateDb($rows);
  81. // }
  82. protected function updateRow($row, $priValue, $dbRow) {
  83. $row['offerall_int'] = Eos::toNumber($row['offerall']);
  84. $row['offertype'] = implode('|', $row['offertype']);
  85. $row['offeramount'] = implode('|', $row['offeramount']);
  86. $row['create_time'] = $this->formatDateTime($row['create_time']);
  87. $row['win_int'] = Eos::toNumber($row['win']);
  88. parent::updateRow($row, $priValue, $dbRow);
  89. }
  90. }