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
PHP
254 lines
8.9 KiB
PHP
<?php
|
|
|
|
|
|
namespace Home\Controller;
|
|
|
|
use Base\Model\PromoteModel;
|
|
use Base\Service\PromoteService;
|
|
use Base\Service\PromoteGradeService;
|
|
|
|
class PromoteGradeController extends BaseController
|
|
{
|
|
protected function _initialize()
|
|
{
|
|
parent::_initialize();
|
|
|
|
$loginPromote = $this->getLoginPromote();
|
|
if(C('APP_ENV') == 'dev' || $loginPromote['company_id'] == 334) {
|
|
|
|
} else {
|
|
return $this->error('您没有权限');
|
|
}
|
|
}
|
|
|
|
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();
|
|
$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 = '自己';
|
|
}
|
|
|
|
$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']];
|
|
if ($promoteId > 0) {
|
|
$map['id'] = $promoteId;
|
|
}
|
|
|
|
$promoteGradeService = new PromoteGradeService();
|
|
|
|
$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 = [];
|
|
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;
|
|
}
|
|
}
|
|
|
|
$this->meta_title = '团队评级';
|
|
|
|
$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();
|
|
|
|
$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 = [];
|
|
foreach ($items as $item) {
|
|
$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' => '全部'
|
|
];
|
|
} else {
|
|
$firstGrade = $config['grades'][0];
|
|
$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']
|
|
];
|
|
foreach ($config['grades'] as $key => $grade) {
|
|
$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']
|
|
];
|
|
}
|
|
}
|
|
}
|
|
|
|
$promoteService = new PromoteService();
|
|
$baseGames = $promoteService->getVisibleBaseGames($loginPromote);
|
|
$this->assign('baseGames', $baseGames);
|
|
$this->assign('records', $records);
|
|
$this->display();
|
|
}
|
|
|
|
public function setting()
|
|
{
|
|
$this->checkSettingPermission();
|
|
$loginPromote = $this->getLoginPromote();
|
|
|
|
$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);
|
|
}
|
|
}
|
|
|
|
$promoteService = new PromoteService();
|
|
$baseGames = $promoteService->getVisibleBaseGames($loginPromote);
|
|
$this->assign('baseGames', $baseGames);
|
|
$this->assign('setting', $setting);
|
|
$this->display();
|
|
}
|
|
|
|
public function delete()
|
|
{
|
|
$this->checkSettingPermission();
|
|
$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('删除成功');
|
|
}
|
|
|
|
public function saveSetting()
|
|
{
|
|
$this->checkSettingPermission();
|
|
|
|
$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());
|
|
}
|
|
}
|
|
|
|
public function checkSettingPermission()
|
|
{
|
|
$loginPromote = $this->getLoginPromote();
|
|
if ($loginPromote['level'] > 2) {
|
|
return $this->error('您没有权限');
|
|
}
|
|
}
|
|
} |