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.

254 lines
8.9 KiB
PHTML

4 years ago
<?php
namespace Home\Controller;
use Base\Model\PromoteModel;
use Base\Service\PromoteService;
use Base\Service\PromoteGradeService;
class PromoteGradeController extends BaseController
{
4 years ago
protected function _initialize()
{
4 years ago
parent::_initialize();
4 years ago
$loginPromote = $this->getLoginPromote();
4 years ago
if(C('APP_ENV') == 'dev' || $loginPromote['company_id'] == 334) {
4 years ago
} else {
return $this->error('您没有权限');
}
}
4 years ago
public function index($p = 1)
{
4 years ago
$month = I('month', date('Y-m'));
4 years ago
$month = $month ? $month : date('Y-m');
$baseGameId = I('base_game_id', 0);
4 years ago
$loginPromote = $this->getLoginPromote();
$parentId = I('parent_id', 0);
$promoteId = I('promote_id', 0);
$searchLevel = 0;
$searchLevelName = '';
$currentDisplay = '';
$prevParentId = 0;
$promoteService = new PromoteService();
$parent = null;
if ($parentId > 0) {
$parent = M('promote', 'tab_')->where(['id' => $parentId])->find();
$currentDisplay = $promoteService->getLevelName($parent['level']) . '推广';
$prevParentId = $parent['parent_id'] == $loginPromote['parent_id'] ? 0 : $parent['parent_id'];
} else {
$parent = $loginPromote;
$currentDisplay = '自己';
}
4 years ago
$searchLevel = $parent['level'] + 1;
$searchLevelName = $promoteService->getLevelName($searchLevel);
4 years ago
$subPromotes = M('promote', 'tab_')->field(['id', 'account', 'real_name', 'group_remark'])->where(['parent_id' => $parent['id']])->select();
$map = ['parent_id' => $parent['id']];
if ($promoteId > 0) {
$map['id'] = $promoteId;
}
4 years ago
$promoteGradeService = new PromoteGradeService();
4 years ago
4 years ago
$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 = '该游戏在此月份未设置评级规则';
}
4 years ago
}
4 years ago
$records = [];
if ($status) {
$query = M('promote', 'tab_')->field(['id', 'account', 'real_name', 'level', 'chain'])->where($map);
list($promotes, $pagination, $count) = $this->paginate($query);
4 years ago
4 years ago
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;
}
4 years ago
}
4 years ago
$this->meta_title = '团队评级';
4 years ago
$baseGames = $promoteService->getVisibleBaseGames($loginPromote);
$this->assign('baseGames', $baseGames);
$this->assign('error', $error);
4 years ago
$this->assign('prevParentId', $prevParentId);
$this->assign('searchLevelName', $searchLevelName);
$this->assign('subPromotes', $subPromotes);
4 years ago
$this->assign('parentId', $parentId);
4 years ago
$this->assign('records', $records);
4 years ago
$this->assign('month', $month);
4 years ago
$this->assign('pagination', $pagination);
$this->display();
}
4 years ago
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'));
}
}
4 years ago
public function settings()
{
4 years ago
$this->checkSettingPermission();
4 years ago
$loginPromote = $this->getLoginPromote();
$items = M('promote_grade_setting', 'tab_')->where(['company_id' => $loginPromote['company_id']])->select();
4 years ago
$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);
}
4 years ago
$symbols = PromoteGradeService::$symbols;
4 years ago
$records = [];
4 years ago
foreach ($items as $item) {
4 years ago
$i = 0;
$config = json_decode($item['config'], true);
4 years ago
$gradeCount = count($config['grades']) + 1;
4 years ago
$baseGame = $itemBaseGames[$item['base_game_id']] ?? null;
$baseGameName = $baseGame ? $baseGame['name'] : '--';
$monthRangeDisplay = $this->getMonthRangeDisplay($item['month_begin'], $item['month_end']);
4 years ago
if ($gradeCount == 1) {
$records[] = [
'id' => $item['id'],
'name' => $item['name'],
4 years ago
'game_name' => $baseGameName,
4 years ago
'grade_count' => $gradeCount,
4 years ago
'month_range' => $monthRangeDisplay,
4 years ago
'reach_level' => $config['reach_level'],
'grade_name' => $config['default_grade_name'],
'grade_value' => '全部'
];
} else {
$firstGrade = $config['grades'][0];
$records[] = [
'id' => $item['id'],
'name' => $item['name'],
4 years ago
'game_name' => $baseGameName,
4 years ago
'grade_count' => $gradeCount,
4 years ago
'month_range' => $monthRangeDisplay,
4 years ago
'reach_level' => $config['reach_level'],
'grade_name' => $config['default_grade_name'],
'grade_value' => ($firstGrade['symbol'] == 1 ? '<' : '<=') . $firstGrade['value']
];
foreach ($config['grades'] as $key => $grade) {
$records[] = [
'id' => $item['id'],
'name' => $item['name'],
4 years ago
'game_name' => $baseGameName,
4 years ago
'grade_count' => 0,
4 years ago
'month_range' => $monthRangeDisplay,
4 years ago
'reach_level' => $config['reach_level'],
'grade_name' => $grade['name'],
'grade_value' => $symbols[$grade['symbol']] . $grade['value']
];
}
4 years ago
}
}
4 years ago
$promoteService = new PromoteService();
$baseGames = $promoteService->getVisibleBaseGames($loginPromote);
$this->assign('baseGames', $baseGames);
4 years ago
$this->assign('records', $records);
$this->display();
}
public function setting()
{
4 years ago
$this->checkSettingPermission();
4 years ago
$loginPromote = $this->getLoginPromote();
4 years ago
$id = I('id', 0);
$setting = null;
if ($id > 0) {
$setting = M('promote_grade_setting', 'tab_')->where(['id' => $id])->find();
if (is_null($setting)) {
return $this->error('记录不存在');
} else {
$setting['config'] = json_decode($setting['config'], true);
}
}
4 years ago
$promoteService = new PromoteService();
$baseGames = $promoteService->getVisibleBaseGames($loginPromote);
$this->assign('baseGames', $baseGames);
4 years ago
$this->assign('setting', $setting);
4 years ago
$this->display();
}
4 years ago
public function delete()
{
4 years ago
$this->checkSettingPermission();
4 years ago
$id = I('id', 0);
if ($id == 0) {
return $this->error('记录不存在');
}
$setting = M('promote_grade_setting', 'tab_')->field(['id'])->where(['id' => $id])->find();
if (is_null($setting)) {
return $this->error('记录不存在');
}
M('promote_grade_setting', 'tab_')->where(['id' => $id])->delete();
return $this->success('删除成功');
}
4 years ago
public function saveSetting()
{
4 years ago
$this->checkSettingPermission();
4 years ago
$params = I('post.');
$loginPromote = $this->getLoginPromote();
$promoteGradeService = new PromoteGradeService();
try {
$promoteGradeService->saveSetting($params, $loginPromote);
return $this->success('保存成功');
} catch (\Exception $e) {
return $this->error($e->getMessage());
}
4 years ago
}
4 years ago
public function checkSettingPermission()
{
$loginPromote = $this->getLoginPromote();
if ($loginPromote['level'] > 2) {
return $this->error('您没有权限');
}
}
4 years ago
}