1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- <?php
- /**
- * 同步游戏表
- * User: solu
- */
- class Sync_Game extends Sync_Base {
- protected $dbKey = 'dw_baccarat';
- protected $frequency = 1;
- protected $index = 2;
- protected $dataField = ['game_state', 'update_time_int', 'create_block_num'];
- /**
- * 清除数据的时间间隔
- * @var int
- */
- protected $clearTtl = 600;
- protected $clearAction = 'cleargame';
- public function __construct() {
- parent::__construct('game', 'id', 'update_time_int');
- }
- protected function addNewRows($newRows) {
- foreach ($newRows as $k => $row) {
- $row['banker'] = implode('|', $row['banker']);
- $row['player'] = implode('|', $row['player']);
- $row['create_time'] = $this->formatDateTime($row['create_time']);
- $row['create_block_num'] = Eos::getRealBlockNum($row['create_trans_id']);
- $newRows[$k] = $row;
- }
- parent::addNewRows($newRows);
- foreach ($newRows as $row) {
- $eventData = [
- 'old' => $this->objTable->getOne([
- '_field' => 'id',
- '_where' => "id<{$row['id']}",
- '_sortKey' => 'id DESC',
- '_limit' => 1,
- ]),
- 'new' => $row['id'],
- ];
- Eos::pubEvent('baccarat:new_game', $eventData);
- }
- }
- // protected function updateDb($rows) {
- //
- // parent::updateDb($rows);
- // }
- protected function updateRow($row, $priValue, $dbRow) {
- if ($row['game_state'] == Game::STATUS_PLAYING && in_array($dbRow['game_state'], [Game::STATUS_PLAYING, Game::STATUS_OPENING]) && $dbRow['create_block_num']) {
- return;
- }
- $row['banker'] = implode('|', $row['banker']);
- $row['player'] = implode('|', $row['player']);
- $row['create_time'] = $this->formatDateTime($row['create_time']);
- $row['create_block_num'] = Eos::getRealBlockNum($row['create_trans_id']);
- parent::updateRow($row, $priValue, $dbRow);
- }
- }
|