You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
146 lines
5.0 KiB
PHP
146 lines
5.0 KiB
PHP
<?php
|
|
|
|
namespace Base\Repository;
|
|
|
|
use Base\Service\PromoteService;
|
|
use Base\Tool\Registry;
|
|
|
|
class GameRepository
|
|
{
|
|
public function getBaseGames($isRefresh = false)
|
|
{
|
|
$baseGames = Registry::get('base_games');
|
|
if ($isRefresh || is_null($baseGames)) {
|
|
$baseGames = M('base_game', 'tab_')->where('1=1')->select();
|
|
Registry::set('base_games', $baseGames);
|
|
}
|
|
return $baseGames;
|
|
}
|
|
|
|
public function getBaseGameByGameId($gameId, array $baseGames = null)
|
|
{
|
|
if (is_null($baseGames)) {
|
|
return M('base_game', 'tab_')->where('android_game_id=' . $gameId . ' or ios_game_id=' . $gameId)->find();
|
|
}
|
|
foreach ($baseGames as $baseGame) {
|
|
if ($baseGame['android_game_id'] == $gameId || $baseGame['ios_game_id'] == $gameId) {
|
|
return $baseGame;
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public function getChoiceGames(array $visibleGameIds = null, $fields = ['id', 'game_name'])
|
|
{
|
|
$map = [];
|
|
$map['_string'] = '1=1';
|
|
if (is_null($visibleGameIds)) {
|
|
|
|
} elseif (count($visibleGameIds) > 0) {
|
|
$map['_string'] = ' and id in (' . implode(',', $visibleGameIds) . ')';
|
|
} else {
|
|
$map['_string'] = ' and 1=0';
|
|
}
|
|
return M('game', 'tab_')->field($fields)->where($map)->select();
|
|
}
|
|
|
|
public function getServersByGameId($gameId, $fields = ['id', 'server_name', 'server_id'])
|
|
{
|
|
$map = [];
|
|
$map['game_id'] = $gameId;
|
|
return M('server', 'tab_')
|
|
->field($fields)
|
|
->where($map)
|
|
->order('server_id asc')
|
|
->select();
|
|
}
|
|
|
|
public function getServersByBaseGameId($baseGameId, $fields = ['id', 'server_name', 'server_id'])
|
|
{
|
|
$baseGame = M('base_game', 'tab_')->where(['id' => $baseGameId])->find();
|
|
$map = [];
|
|
$map['game_id'] = ['in', $this->getGameIdsByBaseGame($baseGame)];
|
|
return M('server', 'tab_')
|
|
->field($fields)
|
|
->where($map)
|
|
->group('server_id')
|
|
->order('server_id asc')
|
|
->select();
|
|
}
|
|
|
|
public function getGameIdsByBaseGame($baseGame, $deviceType = 0)
|
|
{
|
|
$gameIds = [];
|
|
if ($deviceType == 1) {
|
|
$gameIds[] = $baseGame['android_game_id'];
|
|
} elseif ($deviceType == 2) {
|
|
$gameIds[] = $baseGame['ios_game_id'];
|
|
} else {
|
|
$gameIds[] = $baseGame['android_game_id'];
|
|
$gameIds[] = $baseGame['ios_game_id'];
|
|
}
|
|
return $gameIds;
|
|
}
|
|
|
|
public function getUserRegisterCount($baseGame, $date, $deviceType = 0, $promote = null)
|
|
{
|
|
$gameIds = $this->getGameIdsByBaseGame($baseGame, $deviceType);
|
|
$timeBegin = strtotime($date . ' 00:00:00');
|
|
$timeEnd = strtotime($date . ' 23:59:59');
|
|
|
|
$subCondition = [
|
|
'game_id' => ['in', $gameIds],
|
|
'_string' => 'tab_user_play.user_id=tab_user_play_info.user_id'
|
|
];
|
|
|
|
$subSql = M('user_play_info', 'tab_')->field('1')->where($subCondition)->select(false);
|
|
$sqlStr = 'exists (' . $subSql . ')';
|
|
|
|
if ($promote) {
|
|
$promoteService = new PromoteService();
|
|
if ($promote['model_type'] == 'company') {
|
|
$sqlStr .= ' and promote_id in (' . $promoteService->subInCompanySql($promote) . ')';
|
|
} else {
|
|
$sqlStr .= ' and promote_id in (' . $promoteService->subInSql($promote) . ')';
|
|
}
|
|
}
|
|
|
|
return M('user_play', 'tab_')->where([
|
|
// 'register_time' => ['between', [$timeBegin, $timeEnd]],
|
|
'create_time' => ['between', [$timeBegin, $timeEnd]],
|
|
'_string' => $sqlStr
|
|
])->count();
|
|
}
|
|
|
|
public function getUserRetentionCount($baseGame, $date, $day, $deviceType = 0, $promote = null)
|
|
{
|
|
$gameIds = $this->getGameIdsByBaseGame($baseGame, $deviceType);
|
|
|
|
$timeBegin = strtotime($date . ' 00:00:00');
|
|
$timeEnd = strtotime($date . ' 23:59:59');
|
|
$retentionTime = $timeBegin + ($day * 24 * 3600);
|
|
|
|
$subCondition = [
|
|
'game_id' => ['in', $gameIds],
|
|
'_string' => 'tab_user_play.user_id=tab_user_play_info.user_id',
|
|
'play_time' => ['egt', $retentionTime],
|
|
];
|
|
|
|
$subSql = M('user_play_info', 'tab_')->field('1')->where($subCondition)->select(false);
|
|
$sqlStr = 'exists (' . $subSql . ')';
|
|
if ($promote) {
|
|
$promoteService = new PromoteService();
|
|
if ($promote['model_type'] == 'company') {
|
|
$sqlStr .= ' and promote_id in (' . $promoteService->subInCompanySql($promote) . ')';
|
|
} else {
|
|
$sqlStr .= ' and promote_id in (' . $promoteService->subInSql($promote) . ')';
|
|
}
|
|
}
|
|
|
|
return M('user_play', 'tab_')->where([
|
|
// 'register_time' => ['between', [$timeBegin, $timeEnd]],
|
|
'create_time' => ['between', [$timeBegin, $timeEnd]],
|
|
'_string' => $sqlStr
|
|
])->count();
|
|
}
|
|
} |