Game.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. /**
  3. * 同步游戏表
  4. * User: solu
  5. */
  6. class Sync_Game extends Sync_Base {
  7. protected $dbKey = 'dw_baccarat';
  8. protected $frequency = 1;
  9. protected $index = 2;
  10. protected $dataField = ['game_state', 'update_time_int', 'create_block_num'];
  11. /**
  12. * 清除数据的时间间隔
  13. * @var int
  14. */
  15. protected $clearTtl = 600;
  16. protected $clearAction = 'cleargame';
  17. public function __construct() {
  18. parent::__construct('game', 'id', 'update_time_int');
  19. }
  20. protected function addNewRows($newRows) {
  21. foreach ($newRows as $k => $row) {
  22. $row['banker'] = implode('|', $row['banker']);
  23. $row['player'] = implode('|', $row['player']);
  24. $row['create_time'] = $this->formatDateTime($row['create_time']);
  25. $trxId = $row['create_trans_id'];
  26. $block_num = Eos::getRealBlockNum($trxId, Eos::getTempBlockNum($trxId));
  27. if ($block_num) {
  28. $row['create_block_num'] = $block_num;
  29. }
  30. $newRows[$k] = $row;
  31. }
  32. parent::addNewRows($newRows);
  33. foreach ($newRows as $row) {
  34. $eventData = [
  35. 'old' => $this->objTable->getOne([
  36. '_field' => 'id',
  37. '_where' => "id<{$row['id']}",
  38. '_sortKey' => 'id DESC',
  39. '_limit' => 1,
  40. ]),
  41. 'new' => $row['id'],
  42. ];
  43. Eos::pubEvent('baccarat:new_game', $eventData);
  44. }
  45. }
  46. // protected function updateDb($rows) {
  47. //
  48. // parent::updateDb($rows);
  49. // }
  50. protected function updateRow($row, $priValue, $dbRow) {
  51. if ($row['game_state'] == Game::STATUS_PLAYING && in_array($dbRow['game_state'], [Game::STATUS_PLAYING, Game::STATUS_OPENING]) && $dbRow['create_block_num']) {
  52. return;
  53. }
  54. $row['banker'] = implode('|', $row['banker']);
  55. $row['player'] = implode('|', $row['player']);
  56. $row['create_time'] = $this->formatDateTime($row['create_time']);
  57. if (!$dbRow['create_block_num']) {
  58. $trxId = $row['create_trans_id'];
  59. $block_num = Eos::getRealBlockNum($trxId, Eos::getTempBlockNum($trxId));
  60. if ($block_num) {
  61. $row['create_block_num'] = $block_num;
  62. }
  63. }
  64. parent::updateRow($row, $priValue, $dbRow);
  65. }
  66. }