优化查询

master
ELF 5 years ago
parent afbdec3d5d
commit 065245d657

@ -260,10 +260,10 @@ class PromoteRepository {
if (count($ids) == 0) { if (count($ids) == 0) {
return []; return [];
} }
$params['time_column'] = 'login_time'; $params['time_column'] = 'create_time';
$map = $this->getPublicAchievementMap($ids, $params); $map = $this->getPublicAchievementMap($ids, $params);
$items = M('login_daily_record', 'tab_')->field(['count(DISTINCT user_id) as count', 'promote_id'])->where($map)->group('promote_id')->select();
$promoteIds = $map['promote_id'][1]; /* $promoteIds = $map['promote_id'][1];
$tempRows = []; $tempRows = [];
$tempCount = 0; $tempCount = 0;
$items = []; $items = [];
@ -272,13 +272,13 @@ class PromoteRepository {
$tempRows[] = $promoteId; $tempRows[] = $promoteId;
if ($tempCount == 20) { if ($tempCount == 20) {
$map['promote_id'] = ['in', $tempRows]; $map['promote_id'] = ['in', $tempRows];
$rows = M('user_login_record', 'tab_')->field(['count(DISTINCT user_id) as count', 'promote_id'])->where($map)->group('promote_id')->select(); $rows = M('login_daily_record', 'tab_')->field(['count(DISTINCT user_id) as count', 'promote_id'])->where($map)->group('promote_id')->select();
$tempRows = []; $tempRows = [];
$tempCount = 0; $tempCount = 0;
$items = array_merge($items, $rows); $items = array_merge($items, $rows);
} }
} }
*/
$records = []; $records = [];
foreach ($items as $item) { foreach ($items as $item) {
$promoteId = $item['promote_id']; $promoteId = $item['promote_id'];

@ -122,9 +122,9 @@ class UserRepository
public function getLoginCountGroupByDay($params) public function getLoginCountGroupByDay($params)
{ {
$dayList = $params['dayList'] ?? []; $dayList = $params['dayList'] ?? [];
$params['time_column'] = 'login_time'; $params['time_column'] = 'create_time';
$conditions = $this->getDayGroupConditions($params); $conditions = $this->getDayGroupConditions($params);
$items = M('user_login_record', 'tab_')->field('FROM_UNIXTIME(login_time, "%Y-%m-%d") as day, count(DISTINCT user_id) as count') $items = M('login_daily_record', 'tab_')->field('FROM_UNIXTIME(create_time, "%Y-%m-%d") as day, count(DISTINCT user_id) as count')
->where($conditions) ->where($conditions)
->group('day') ->group('day')
->select(); ->select();

Loading…
Cancel
Save