Game.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. $row['create_block_num'] = Eos::getRealBlockNum($row['create_trans_id']);
  26. $newRows[$k] = $row;
  27. }
  28. parent::addNewRows($newRows);
  29. foreach ($newRows as $row) {
  30. $eventData = [
  31. 'old' => $this->objTable->getOne([
  32. '_field' => 'id',
  33. '_where' => "id<{$row['id']}",
  34. '_sortKey' => 'id DESC',
  35. '_limit' => 1,
  36. ]),
  37. 'new' => $row['id'],
  38. ];
  39. Eos::pubEvent('baccarat:new_game', $eventData);
  40. }
  41. }
  42. // protected function updateDb($rows) {
  43. //
  44. // parent::updateDb($rows);
  45. // }
  46. protected function updateRow($row, $priValue, $dbRow) {
  47. if ($row['game_state'] == Game::STATUS_PLAYING && in_array($dbRow['game_state'], [Game::STATUS_PLAYING, Game::STATUS_OPENING]) && $dbRow['create_block_num']) {
  48. return;
  49. }
  50. $row['banker'] = implode('|', $row['banker']);
  51. $row['player'] = implode('|', $row['player']);
  52. $row['create_time'] = $this->formatDateTime($row['create_time']);
  53. $row['create_block_num'] = Eos::getRealBlockNum($row['create_trans_id']);
  54. parent::updateRow($row, $priValue, $dbRow);
  55. }
  56. }