修改评级

master
ELF 4 years ago
parent 3c11826a1c
commit 8c8d01a446

@ -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)

@ -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);

@ -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();
}

@ -39,6 +39,16 @@
</volist>
</select>
</div>
<div class="form-group normal_space">
<select name="base_game_id" class="reselect select_gallery" style="width: 220px;" >
<option value="0">请选择游戏</option>
<volist name="baseGames" id="baseGame">
<option ba-id="{$baseGame.id}" value="{$baseGame.id}" <if condition="I('base_game_id') == $baseGame['id']">selected</if>>
{$baseGame.name}
</option>
</volist>
</select>
</div>
<div class="form-group normal_space fr">
<input type="text" class="txt month-date" name="month" placeholder="月份" value="{$month}" >
</div>
@ -63,7 +73,9 @@
<th>操作</th>
</tr>
<empty name="records">
<tr><td colspan="14" style="text-align: center;height: 45vh;"><img src="__IMG__/20180207/icon_wushujv2.png"/><p style="line-height: 40px;color: #A5A5A5;">暂无数据</p></td></tr>
<tr><td colspan="13" class="text-align: center;height: 45vh;"">
<?= $error ? '<span style="color: #ff0000;">' . $error . '</span>': '<img src="__IMG__/20180207/icon_wushujv2.png"/><p style="line-height: 40px;color: #A5A5A5;">暂无数据</p>' ?></td>
</tr>
<else />
<volist name="records" id="record" mod="2">
<tr data-id="{$record.id}" class="<eq name='mod' value='1'>odd</eq>">
@ -82,7 +94,7 @@
<td>{$record.amount}</td>
<td>
<?php if($record['current_display'] == '' && $record['level'] < 4):?>
<a href="{:U('PromoteGrade/index', ['parent_id' => $record['id'], 'month' => I('month', '')])}">查看下级</a>
<a href="{:U('PromoteGrade/index', ['parent_id' => $record['id'], 'base_game_id' => I('base_game_id', 0), 'month' => I('month', '')])}">查看下级</a>
<?php endif;?>
</td>
</tr>

@ -61,6 +61,33 @@
<input type="text" class="name input-txt txt" name="name" value="<?= $setting['name'] ?? '' ?>" placeholder="请输入评级规则名称">
</td>
</tr>
<tr>
<td class="l">* 对应游戏:</td>
<td class="r">
<select id="baseGameId" name="base_game_id" class="reselect select_gallery" style="width: 220px;" >
<option value="0">请选择游戏</option>
<?php foreach($baseGames as $baseGame):?>
<option value="<?= $baseGame['id'] ?>" <?php if($baseGame['id'] == $setting['base_game_id']):?>selected<?php endif;?>>
<?= $baseGame['name'] ?>
</option>
<?php endforeach;?>
</select>
</td>
</tr>
<tr>
<td class="l">规则开始月份:</td>
<td class="r">
<input type="text" class="txt month-date" name="month_begin" placeholder="规则开始月份" value="<?= $setting['month_begin'] == 0 ? '' : date('Y-m', strtotime($setting['month_begin'] . '01')) ?>" >
<span style="font-size: 12px; color: #F8AC59">仅可选月份</span>
</td>
</tr>
<tr>
<td class="l">规则截止月份:</td>
<td class="r">
<input type="text" class="txt month-date" name="month_end" placeholder="规则截止月份" value="<?= $setting['month_end'] == 0 ? '' : date('Y-m', strtotime($setting['month_end'] . '01')) ?>" >
<span style="font-size: 12px; color: #F8AC59">仅可选月份,不选则表示截止时间为永久</span>
</td>
</tr>
<?php $settingConfig = $setting ? $setting['config'] : null ?>
<tr>
<td class="l">* 玩家角色达标等级:</td>
@ -109,10 +136,18 @@
</div>
</block>
<block name="script">
<link rel="stylesheet" href="__STATIC__/flatpickr/flatpickr.min.css">
<script src="__STATIC__/flatpickr/flatpickr.min.js"></script>
<script src="__STATIC__/flatpickr/l10n/zh.js"></script>
<script type="text/javascript" src="__JS__/20170831/select2.min.js"></script>
<script type="text/javascript">
$(".select_gallery").select2();
var defaultDate = $('.month-date').val()
$('.month-date').flatpickr({
locale: 'zh',
dateFormat: "Y-m",
defaultDate: defaultDate,
})
$('#add-rule').on({
click: function () {
var html = '<div class="rule-item">'
@ -140,6 +175,9 @@
var id = form.find('input[name=id]').val()
var name = form.find('input[name=name]').val()
var level = form.find('input[name=level]').val()
var baseGameId = $('#baseGameId').val()
var monthBegin = form.find('input[name=month_begin]').val()
var monthEnd = form.find('input[name=month_end]').val()
var defaultGradeName = form.find('input[name=default_grade_name]').val()
$.ajax({
@ -150,7 +188,10 @@
name: name,
level: level,
default_grade_name: defaultGradeName,
grades: getGrades()
grades: getGrades(),
month_begin: monthBegin,
month_end: monthEnd,
base_game_id: baseGameId
},
success:function(res){
if(res.status == 1){

@ -35,6 +35,8 @@
<tr class="odd">
<th>ID</th>
<th style="width: 200px;">规则名称</th>
<th style="width: 200px;">规则所属游戏</th>
<th style="width: 200px;">规则有效期</th>
<th style="width: 200px;">当月注册玩家角色达标等级</th>
<th>系数值</th>
<th>等级名称</th>
@ -48,6 +50,8 @@
<?php if($record['grade_count'] > 0):?>
<td rowspan="<?=$record['grade_count']?>"><?=$record['id']?></td>
<td rowspan="<?=$record['grade_count']?>"><?=$record['name']?></td>
<td rowspan="<?=$record['grade_count']?>"><?=$record['game_name']?></td>
<td rowspan="<?=$record['grade_count']?>"><?=$record['month_range']?></td>
<td rowspan="<?=$record['grade_count']?>"><?=$record['reach_level']?></td>
<?php endif;?>
<td><?=$record['grade_value']?></td>

@ -47,9 +47,9 @@
</div>
<div class="form-group normal_space">
<select id="sdk_version" name="device_type" class="reselect select_gallery" style="width: 220px;" >
<option value="0">请选择设备类型</option>
<option value="1" <if condition="I('device_type') === '1'">selected</if>>Andriod</option>
<option value="2" <if condition="I('device_type') === '2'">selected</if>>IOS</option>
<option value="">请选择设备类型</option>
<option value="android" <if condition="I('device_type') === 'android'">selected</if>>Andriod</option>
<option value="ios" <if condition="I('device_type') === 'ios'">selected</if>>IOS</option>
</select>
</div>
<include file="Public/promote_select" />

@ -2675,3 +2675,9 @@ CREATE TABLE `tab_testing_game_setting` (
`update_time` int(11) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='测试资源游戏设置';
ALTER TABLE `tab_promote_grade_setting`
ADD COLUMN `base_game_id` int(11) not NULL DEFAULT 0 COMMENT '游戏ID' AFTER `name`,
ADD COLUMN `month_begin` int(11) not NULL DEFAULT 0 COMMENT '规则截止月份' AFTER `base_game_id`,
ADD COLUMN `month_end` int(11) not NULL DEFAULT 0 COMMENT '规则开始月份' AFTER `month_begin`;
Loading…
Cancel
Save