diff --git a/Application/Base/Service/PromoteGradeService.class.php b/Application/Base/Service/PromoteGradeService.class.php index 4f303e06b..6636aff96 100644 --- a/Application/Base/Service/PromoteGradeService.class.php +++ b/Application/Base/Service/PromoteGradeService.class.php @@ -6,6 +6,8 @@ use Base\Tool\GameCatClient; class PromoteGradeService { + const FOREVER_TIME = 300001; + public static $symbols = [ 1 => '>=', 2 => '>', @@ -22,6 +24,14 @@ class PromoteGradeService { $id = $params['id'] ?? 0; + if (empty($params['base_game_id'])) { + throw new \Exception('请选择游戏'); + } + $monthBegin = isset($params['month_begin']) && $params['month_begin'] ? + date('Ym', strtotime($params['month_begin'])) : 0; + $monthEnd = isset($params['month_end']) && $params['month_end'] ? + date('Ym', strtotime($params['month_end'])) : self::FOREVER_TIME; + $setting = null; if ($id > 0) { $setting = M('promote_grade_setting', 'tab_')->where(['id' => $id])->find(); @@ -32,12 +42,16 @@ class PromoteGradeService throw new \Exception('不允许修改其他公司的配置'); } } else { - $setting = M('promote_grade_setting', 'tab_')->where(['company_id' => $promote['company_id']])->find(); - if ($setting) { - throw new \Exception('您已经设置过了'); + $count = $this->getRepeatRuleCount($promote['company_id'], $params['base_game_id'], $monthBegin, $monthEnd); + if ($count > 0) { + throw new \Exception('该游戏在相同时间段内已经设置规则'); } } + if ($monthBegin > 0 && $monthEnd > 0 && $monthBegin > $monthEnd) { + throw new \Exception('规则截止时间不能大于规则开始时间'); + } + $config = []; $config['reach_level'] = $params['level']; $config['grades'] = $this->sortGrades($params['grades']); @@ -45,6 +59,9 @@ class PromoteGradeService $data = []; $data['status'] = 1; + $data['base_game_id'] = $params['base_game_id']; + $data['month_begin'] = $monthBegin; + $data['month_end'] = $monthEnd; $data['name'] = $params['name']; $data['config'] = json_encode($config); @@ -75,9 +92,35 @@ class PromoteGradeService return $grades; } - public function getCurrentSetting($promote) + public function getTimeRepeatCondition($monthBegin, $monthEnd) + { + return ' ((month_begin >= ' . $monthBegin . ' AND month_begin <= ' . $monthEnd . ') OR (month_begin <= ' . $monthBegin . ' AND month_end >= ' . $monthEnd + . ') OR (month_end >= ' . $monthBegin . ' AND month_end <= ' . $monthEnd . '))'; + } + + public function getRepeatRuleCount($companyId, $baseGameId, $monthBegin, $monthEnd) + { + $conditions = [ + 'compnay_id' => $companyId, + 'base_game_id' => $baseGameId, + ]; + $conditions['_string'] = $this->getTimeRepeatCondition($monthBegin, $monthEnd); + $count = M('promote_grade_setting', 'tab_')->where($conditions)->count(); + return intval($count); + } + + public function getCurrentSetting($promote, $baseGameId, $month) { - return M('promote_grade_setting', 'tab_')->where(['status' => 1, 'company_id' => $promote['company_id']])->find(); + $timeCondition = 'month_end >= ' . $month . ' and month_begin <= ' . $month; + + return M('promote_grade_setting', 'tab_') + ->where([ + 'status' => 1, + 'company_id' => $promote['company_id'], + 'base_game_id' => $baseGameId, + '_string' => $timeCondition + ]) + ->find(); } public function searchGradeByPromotes($promotes, $params, $setting) diff --git a/Application/Base/Service/PromoteService.class.php b/Application/Base/Service/PromoteService.class.php index e40bf47e9..0d2cbb3a2 100644 --- a/Application/Base/Service/PromoteService.class.php +++ b/Application/Base/Service/PromoteService.class.php @@ -1194,6 +1194,19 @@ class PromoteService { return $groupName; } + public function getVisibleBaseGames($promote) + { + $gameIds = $this->getVisibleGameIds($promote); + if (count($gameIds) == 0) { + return []; + } + return M('base_game', 'tab_')->where([ + '_logic' => 'or', + 'android_game_id' => ['in', $gameIds], + 'ios_game_id' => ['in', $gameIds], + ])->select(); + } + public function getVisibleGameIds($promote) { /* $gameIds = M('game', 'tab_')->getField('id', true); diff --git a/Application/Home/Controller/PromoteGradeController.class.php b/Application/Home/Controller/PromoteGradeController.class.php index 35fab0f3b..d3d178b95 100644 --- a/Application/Home/Controller/PromoteGradeController.class.php +++ b/Application/Home/Controller/PromoteGradeController.class.php @@ -24,14 +24,9 @@ class PromoteGradeController extends BaseController public function index($p = 1) { $month = I('month', date('Y-m')); + $month = $month ? $month : date('Y-m'); + $baseGameId = I('base_game_id', 0); $loginPromote = $this->getLoginPromote(); - - $promoteGradeService = new PromoteGradeService(); - $setting = $promoteGradeService->getCurrentSetting($loginPromote); - if (is_null($setting)) { - return $this->error('未设置评级规则'); - } - $parentId = I('parent_id', 0); $promoteId = I('promote_id', 0); $searchLevel = 0; @@ -51,6 +46,9 @@ class PromoteGradeController extends BaseController $currentDisplay = '自己'; } + $searchLevel = $parent['level'] + 1; + $searchLevelName = $promoteService->getLevelName($searchLevel); + $subPromotes = M('promote', 'tab_')->field(['id', 'account', 'real_name', 'group_remark'])->where(['parent_id' => $parent['id']])->select(); $map = ['parent_id' => $parent['id']]; @@ -58,34 +56,71 @@ class PromoteGradeController extends BaseController $map['id'] = $promoteId; } - $query = M('promote', 'tab_')->field(['id', 'account', 'real_name', 'level', 'chain'])->where($map); - list($promotes, $pagination, $count) = $this->paginate($query); + $promoteGradeService = new PromoteGradeService(); - if (I('p', 1) == 1) { - array_unshift($promotes, $parent); + $error = ''; + $status = true; + $setting = null; + $pagination = null; + if ($baseGameId == 0) { + $status = false; + $error = '请选择游戏'; + } else { + $monthNumber = date('Ym', strtotime($month . '-01')); + $setting = $promoteGradeService->getCurrentSetting($loginPromote, $baseGameId, $monthNumber); + if (is_null($setting)) { + $status = false; + $error = '该游戏在此月份未设置评级规则'; + } } - $records = $promoteGradeService->searchGradeByPromotes($promotes, [ - 'month' => $month, - ], $setting); + $records = []; + if ($status) { + $query = M('promote', 'tab_')->field(['id', 'account', 'real_name', 'level', 'chain'])->where($map); + list($promotes, $pagination, $count) = $this->paginate($query); + + if (I('p', 1) == 1) { + array_unshift($promotes, $parent); + } + + $records = $promoteGradeService->searchGradeByPromotes($promotes, [ + 'month' => $month, + ], $setting); - if (I('p', 1) == 1) { - $records[0]['current_display'] = $currentDisplay; + if (I('p', 1) == 1) { + $records[0]['current_display'] = $currentDisplay; + } } $this->meta_title = '团队评级'; - $this->assign('month', $month); + $baseGames = $promoteService->getVisibleBaseGames($loginPromote); + $this->assign('baseGames', $baseGames); + $this->assign('error', $error); $this->assign('prevParentId', $prevParentId); $this->assign('searchLevelName', $searchLevelName); $this->assign('subPromotes', $subPromotes); $this->assign('parentId', $parentId); $this->assign('records', $records); + $this->assign('month', $month); $this->assign('pagination', $pagination); $this->display(); } + private function getMonthRangeDisplay($monthBegin, $monthEnd) + { + if ($monthBegin == 0 && $monthEnd == 0) { + return '永久'; + } elseif ($monthBegin == 0 && $monthEnd > 0) { + return '从前 至 ' . date('Y-m', strtotime($monthEnd . '01')); + } elseif ($monthBegin > 0 && $monthEnd == 0) { + return date('Y-m', strtotime($monthBegin . '01')) . ' 至 永久'; + } else { + return date('Y-m', strtotime($monthBegin . '01')) . ' 至 ' . date('Y-m', strtotime($monthEnd . '01')); + } + } + public function settings() { $this->checkSettingPermission(); @@ -93,6 +128,13 @@ class PromoteGradeController extends BaseController $loginPromote = $this->getLoginPromote(); $items = M('promote_grade_setting', 'tab_')->where(['company_id' => $loginPromote['company_id']])->select(); + $baseGameIds = array_column($items, 'base_game_id'); + $itemBaseGames = []; + if (count($baseGameIds) > 0) { + $itemBaseGames = M('base_game', 'tab_')->where(['id' => ['in', $baseGameIds]])->select(); + $itemBaseGames = index_by_column('id', $itemBaseGames); + } + $symbols = PromoteGradeService::$symbols; $records = []; @@ -100,11 +142,16 @@ class PromoteGradeController extends BaseController $i = 0; $config = json_decode($item['config'], true); $gradeCount = count($config['grades']) + 1; + $baseGame = $itemBaseGames[$item['base_game_id']] ?? null; + $baseGameName = $baseGame ? $baseGame['name'] : '--'; + $monthRangeDisplay = $this->getMonthRangeDisplay($item['month_begin'], $item['month_end']); if ($gradeCount == 1) { $records[] = [ 'id' => $item['id'], 'name' => $item['name'], + 'game_name' => $baseGameName, 'grade_count' => $gradeCount, + 'month_range' => $monthRangeDisplay, 'reach_level' => $config['reach_level'], 'grade_name' => $config['default_grade_name'], 'grade_value' => '全部' @@ -114,7 +161,9 @@ class PromoteGradeController extends BaseController $records[] = [ 'id' => $item['id'], 'name' => $item['name'], + 'game_name' => $baseGameName, 'grade_count' => $gradeCount, + 'month_range' => $monthRangeDisplay, 'reach_level' => $config['reach_level'], 'grade_name' => $config['default_grade_name'], 'grade_value' => ($firstGrade['symbol'] == 1 ? '<' : '<=') . $firstGrade['value'] @@ -123,7 +172,9 @@ class PromoteGradeController extends BaseController $records[] = [ 'id' => $item['id'], 'name' => $item['name'], + 'game_name' => $baseGameName, 'grade_count' => 0, + 'month_range' => $monthRangeDisplay, 'reach_level' => $config['reach_level'], 'grade_name' => $grade['name'], 'grade_value' => $symbols[$grade['symbol']] . $grade['value'] @@ -131,6 +182,10 @@ class PromoteGradeController extends BaseController } } } + + $promoteService = new PromoteService(); + $baseGames = $promoteService->getVisibleBaseGames($loginPromote); + $this->assign('baseGames', $baseGames); $this->assign('records', $records); $this->display(); } @@ -138,6 +193,8 @@ class PromoteGradeController extends BaseController public function setting() { $this->checkSettingPermission(); + $loginPromote = $this->getLoginPromote(); + $id = I('id', 0); $setting = null; if ($id > 0) { @@ -148,6 +205,10 @@ class PromoteGradeController extends BaseController $setting['config'] = json_decode($setting['config'], true); } } + + $promoteService = new PromoteService(); + $baseGames = $promoteService->getVisibleBaseGames($loginPromote); + $this->assign('baseGames', $baseGames); $this->assign('setting', $setting); $this->display(); } diff --git a/Application/Home/View/default/PromoteGrade/index.html b/Application/Home/View/default/PromoteGrade/index.html index 7d619ae9c..35013ba1d 100644 --- a/Application/Home/View/default/PromoteGrade/index.html +++ b/Application/Home/View/default/PromoteGrade/index.html @@ -39,6 +39,16 @@ +
暂无数据
暂无数据
' ?>