master
elf@home 4 years ago
parent afad195062
commit c4eb04428e

@ -6,6 +6,11 @@ use Base\Tool\GameCatClient;
class PromoteGradeService
{
public static $symbols = [
1 => '>=',
2 => '>',
];
/**
* @config
* reach_level
@ -19,27 +24,39 @@ class PromoteGradeService
$setting = null;
if ($id > 0) {
$setting = M('promote_grade_setting', 'tab')->where(['id' => $id])->find();
$setting = M('promote_grade_setting', 'tab_')->where(['id' => $id])->find();
if (is_null($setting)) {
throw new \Exception('记录不存在');
}
if ($setting['company_id'] != $promote['company_id']) {
throw new \Exception('不允许修改其他公司的配置');
}
} else {
$setting = M('promote_grade_setting', 'tab_')->where(['company_id' => $promote['company_id']])->find();
if ($setting) {
throw new \Exception('您已经设置过了');
}
}
$config = [];
$config['reach_level'] = $params['level'];
$config['grades'] = $params['grades'];
$config['default_grade_name'] = $params['default_grade_name'];
$data = [];
$data['company_id'] = $promote['company_id'];
$data['status'] = 1;
$data['name'] = $params['name'];
$data['config'] = json_encode($config);
$data['create_time'] = time();
$data['update_time'] = time();
M('promote_grade_setting', 'tab_')->add($data);
M('promote_grade_setting', 'tab_')->where(['id' => $id])->save($data);
if ($setting) {
$data['create_time'] = time();
M('promote_grade_setting', 'tab_')->where(['id' => $id])->save($data);
} else {
$data['company_id'] = $promote['company_id'];
$data['create_time'] = time();
$data['update_time'] = time();
M('promote_grade_setting', 'tab_')->add($data);
}
}
private function checkGrades($grades)
@ -47,26 +64,20 @@ class PromoteGradeService
}
public function hadSetting($promote)
public function getCurrentSetting($promote)
{
$setting = M('promote_grade_setting', 'tab_')->field(['id'])->where(['status' => 1, 'company_id' => $promote['company_id']])->find();
if ($setting) {
return true;
}
return false;
return M('promote_grade_setting', 'tab_')->where(['status' => 1, 'company_id' => $promote['company_id']])->find();
}
public function searchGradeByPromotes($promotes, $params)
public function searchGradeByPromotes($promotes, $params, $setting)
{
/**
* @todo 通过设置获取
*/
$settingLevel = 50;
$config = json_decode($setting['config'], true);
$settingLevel = $config['reach_level'];
$month = $params['month'] ?? date('Y-m');
$promoteIds = array_column($promotes, 'id');
$beginTime = strtotime($month . '-01 00:00:00');
$endTime = strtotime($month . '-01 00:00:00') + 24*3600 - 1;
$endDate = date('Y-m-01 00:00:00', strtotime($month . '-01' . ' +1 month'));
$endTime = strtotime($endDate) - 1;
$betweenTime = [$beginTime, $endTime];
@ -99,18 +110,60 @@ class PromoteGradeService
->select();
$amountItems = index_by_column('promote_id', $amountItems);
$promoteService = new PromoteService();
$records = [];
foreach ($promotes as $promote) {
$amountItem = $amountItems[$promote['id']] ?? null;
$accountItem = $accountItems[$promote['id']] ?? null;
$amount = $amountItem ? $amountItem['amount'] : 0;
$num = $accountItem ? $accountItem['num'] : 0;
$value = $num == 0 ? 0 : round($amount / $num, 2);
$records[] = [
'amount' => $amountItem ? $amountItem['amount'] : 0,
'num' => $accountItem ? $accountItem['num'] : 0,
'real_name' => $promote['real_name'],
'id' => $promote['id'],
'level' => $promote['level'],
'amount' => $amount,
'num' => $num,
'real_name' => hideRealName($promote['real_name']),
'account' => $promote['account'],
'promote_group' => $promote['promote_group']
'promote_group' => $promoteService->getGroupNameByChain($promote['chain'], $promote['id']),
'value' => $value,
'grade_name' => $this->getGradeByValue($value, $setting),
'current_display' => ''
];
}
return $records;
}
public function getGradeByValue($value, $setting)
{
$config = json_decode($setting['config'], true);
$grades = $config['grades'];
$gradeName = $config['default_grade_name'];
foreach ($grades as $key => $grade) {
if ($key == 0 && !$this->isBigger($value, $grade)) {
$gradeName = $config['default_grade_name'];
break;
}
$nextGrade = $grade[$key + 1] ?? null;
if ($this->isBigger($value, $grade) && !$this->isBigger($value, $nextGrade)) {
$gradeName = $grade['name'];
break;
}
}
return $gradeName;
}
private function isBigger($value, $grade)
{
if (is_null($grade)) {
return false;
}
if ($grade['symbol'] == 1 && $value >= $grade['value']) {
return true;
} elseif ($grade['symbol'] == 2 && $value > $grade['value']) {
return true;
}
return false;
}
}

@ -11,22 +11,17 @@ class PromoteGradeController extends BaseController
{
public function index($p = 1)
{
$month = I('month', date('Y-m'));
$loginPromote = $this->getLoginPromote();
/* $promoteGradeService = new PromoteGradeService();
if (!$promoteGradeService->hadSetting($loginPromote)) {
$promoteGradeService = new PromoteGradeService();
$setting = $promoteGradeService->getCurrentSetting($loginPromote);
if (is_null($setting)) {
return $this->error('未设置评级规则');
} */
$time = I('time', date('Y-m-d'));
if (!empty($time)) {
$defaultTime = $time;
} else {
$defaultTime = date('Y-m-d', time());
}
$parentId = I('parent_id', 0);
$promoteId = I('promote_id', 0);
$status = I('status', 0);
$searchLevel = 0;
$searchLevelName = '';
$currentDisplay = '';
@ -54,13 +49,21 @@ class PromoteGradeController extends BaseController
$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 = '团队评级';
$this->assign('records', $records);
$this->assign('month', $month);
$this->assign('prevParentId', $prevParentId);
$this->assign('searchLevelName', $searchLevelName);
$this->assign('subPromotes', $subPromotes);
@ -76,31 +79,90 @@ class PromoteGradeController extends BaseController
$loginPromote = $this->getLoginPromote();
$items = M('promote_grade_setting', 'tab_')->where(['company_id' => $loginPromote['company_id']])->select();
$symbols = PromoteGradeService::$symbols;
$records = [];
foreach ($items as $key => $item) {
foreach ($items as $item) {
$i = 0;
$config = json_decode($item['config'], true);
$gradeCount = count($config['grades']);
foreach ($config['grades'] as $grade) {
$records['id'] = $item['id'];
$records['grade_count'] = $item['id'];
$records['reach_level'] = $config['reach_level'];
$records['grade_name'] = $grade['name'];
$records['grade_value'] = $grade['symbol'] . $grade['value'];
$gradeCount = count($config['grades']) + 1;
if ($gradeCount == 1) {
$records[] = [
'id' => $item['id'],
'name' => $item['name'],
'grade_count' => $gradeCount,
'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'],
'grade_count' => $gradeCount,
'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'],
'grade_count' => 0,
'reach_level' => $config['reach_level'],
'grade_name' => $grade['name'],
'grade_value' => $symbols[$grade['symbol']] . $grade['value']
];
}
}
}
$this->assign('records', $records);
$this->display();
}
public function setting()
{
$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);
}
}
$this->assign('setting', $setting);
$this->display();
}
public function delete()
{
$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()
{
var_dump(I('post.'));
$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());
}
}
}

@ -26,7 +26,7 @@
</div>
<div class="trunk-content article">
<div class="trunk-search clearfix">
<form action="{:U('Query/achievement',['row'=>I('get.row')])}" method="post" enctype="multipart/form-data">
<form action="{:U('PromoteGrade/index',['row'=>I('get.row')])}" method="post" enctype="multipart/form-data">
<input type="hidden" name="parent_id" value="{:I('parent_id', 0)}">
<div class="form-group normal_space">
<select name="promote_id" class="reselect select_gallery" style="width: 220px;" >
@ -40,14 +40,14 @@
</select>
</div>
<div class="form-group normal_space fr">
<input type="text" class="txt range-date" name="time" placeholder="起止时间" value="{$time}" >
<input type="text" class="txt month-date" name="month" placeholder="月份" value="{$month}" >
</div>
<div class="form-group">
<input type="submit" class="submit normal_space" value="查询">
</div>
<?php if ($prevParentId > 0):?>
<div class="form-group">
<a class="submit normal_space" href="{:U('Query/achievement', ['row'=>I('get.row'), 'parent_id' => $prevParentId,'time'=>$time])}" style="line-height: 36px; display: inline-block; text-align: center; background: #E5E5E5; color: #2bd8ed; cursor: pointer;">返回上级</a>
<a class="submit normal_space" href="{:U('PromoteGrade/index', ['row'=>I('get.row'), 'parent_id' => $prevParentId, 'month'=>$month])}" style="line-height: 36px; display: inline-block; text-align: center; background: #E5E5E5; color: #2bd8ed; cursor: pointer;">返回上级</a>
</div>
<?php endif;?>
</form>
@ -57,6 +57,7 @@
<tr class="odd">
<th>账号(姓名)</th>
<th>等级</th>
<th>系数值</th>
<th>当月玩家达标个数</th>
<th>当月注册充值总额</th>
<th>操作</th>
@ -65,7 +66,7 @@
<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>
<else />
<volist name="records" id="record" mod="2">
<tr data-id="{$vo.id}" class="<eq name='mod' value='1'>odd</eq>">
<tr data-id="{$record.id}" class="<eq name='mod' value='1'>odd</eq>">
<td>{$record.account}({$record.real_name}
<?php if($record['promote_group'] != ''):?>
/{$record.promote_group}
@ -75,12 +76,13 @@
<span style="color: #06C;">[{$record['current_display']}]</span>
<?php endif;?>
</td>
<td>{$record.create_role_count}</td>
<td>{$record.create_role_user_count}</td>
<td>{$record.new_create_role_user_count}</td>
<td>{$record.grade_name}</td>
<td>{$record.value}</td>
<td>{$record.num}</td>
<td>{$record.amount}</td>
<td>
<?php if($record['current_display'] == '' && $record['level'] < 4):?>
<a href="{:U('Query/achievement', ['parent_id' => $record['id'], 'time' => I('time', '')])}">查看下级</a>
<a href="{:U('PromoteGrade/index', ['parent_id' => $record['id'], 'month' => I('month', '')])}">查看下级</a>
<?php endif;?>
</td>
</tr>
@ -117,12 +119,10 @@
</eq>
<script type="text/javascript">
$(function() {
var defaultDate = $('.range-date').val()
defaultDate = defaultDate == '' ? [] : defaultDate.split(' 至 ')
$('.range-date').flatpickr({
mode: 'range',
var defaultDate = $('.month-date').val()
$('.month-date').flatpickr({
locale: 'zh',
dateFormat: "Y-m-d",
dateFormat: "Y-m",
defaultDate: defaultDate,
})
$('.select_gallery').select2()

@ -54,45 +54,51 @@
<div class="trunk-list list_normal">
<form action="{:U('PromoteGrade/saveSetting')}" novalidate="novalidate" method="post" class="base_info" id="rule-form">
<table class="table2">
<input type="hidden" name="promote_type" value="{:I('promote_type', 0)}">
<input type="hidden" name="id" value="<?= $setting['id'] ?? 0 ?>">
<tr>
<td class="l">* 评级规则名称:</td>
<td class="r">
<input type="text" class="name input-txt txt" name="name" id="name" maxlength="4" minlength="2" placeholder="请输入评级规则名称">
<input type="text" class="name input-txt txt" name="name" value="<?= $setting['name'] ?? '' ?>" placeholder="请输入评级规则名称">
</td>
</tr>
<?php $settingConfig = $setting ? $setting['config'] : null ?>
<tr>
<td class="l">* 玩家角色达标等级:</td>
<td class="r">
<input type="text" class="name input-txt txt" name="level" id="level" maxlength="4" minlength="2" placeholder="玩家角色达标等级">
<input type="text" class="name input-txt txt" name="level" value="<?= $settingConfig['reach_level'] ?? '' ?>" maxlength="4" minlength="1" placeholder="玩家角色达标等级">
</td>
</tr>
<tr>
<td class="l" style="vertical-align: top; padding-top: 15px;"><span class="req">*</span>等级设定:</td>
<td class="r" style="padding-top: 15px;">
<div style="margin-bottom: 10px">
<input type="text" class="name input-txt txt" name="default_grade_name" id="default_grade_name" maxlength="4" minlength="2" placeholder="默认等级名称">
<input type="text" class="name input-txt txt" name="default_grade_name" id="default_grade_name" value="<?= $settingConfig['default_grade_name'] ?? '' ?>" placeholder="默认等级名称">
<span style="font-size: 12px; color: #F8AC59">默认等级名称</span>
</div>
<button id="add-rule" type="button" class="add-rule">添加等级</button>
<div id="rule-list" class="rule-list">
<!-- <div class="rule-item">
系数值:
<select class="symbol-item reselect select_gallery" style="width: 60px;" >
<option value="1">>=</option>
<option value="2">></option>
</select>
<input type="text" class="value-item name input-txt txt" maxlength="4" minlength="1" placeholder="系数值">
&nbsp;&nbsp;&nbsp;&nbsp;
等级名称:
<input type="text" class="name-item name input-txt txt" placeholder="等级名称">
</div> -->
<?php if($setting):?>
<?php foreach($settingConfig['grades'] as $grade):?>
<div class="rule-item">
系数值:
<select class="symbol-item reselect select_gallery" style="width: 60px;" >
<option value="1" <?php if($grade['symbol'] == 1):?>selected<?php endif;?> >>=</option>
<option value="2" <?php if($grade['symbol'] == 2):?>selected<?php endif;?> >></option>
</select>
<input type="text" class="value-item name input-txt txt" value="<?=$grade['value']?>" maxlength="8" minlength="1" placeholder="系数值">
&nbsp;&nbsp;&nbsp;&nbsp;
等级名称:
<input type="text" class="name-item name input-txt txt" value="<?=$grade['name']?>" placeholder="等级名称">
</div>
<?php endforeach;?>
<?php endif;?>
</div>
</td>
</tr>
<tr>
<td class="l"></td>
<td class="r">
<input type="button" onclick="check()" class="tj btn" value="确认添加" title="" style="cursor: pointer;">
<input type="button" onclick="check()" class="tj btn" value="保存" title="" style="cursor: pointer;">
<a class="back_btn " alt="返回上一页" title="返回上一页" href="javascript:window.history.back();">返回</a>
</td>
</tr>
@ -131,6 +137,7 @@
return
}
var form = $('#rule-form');
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 defaultGradeName = form.find('input[name=default_grade_name]').val()
@ -139,19 +146,20 @@
type:"POST",
url:"{:U('saveSetting')}",
data:{
id: id,
name: name,
level: level,
defaultGradeName: defaultGradeName,
default_grade_name: defaultGradeName,
grades: getGrades()
},
success:function(res){
if(res.status == 1){
layer.msg(res.msg);
layer.msg(res.info);
setTimeout(function(){
window.location.href="{:U('settings')}";
},1000);
}else{
layer.msg(res.msg);
layer.msg(res.info);
}
}
});

@ -34,21 +34,31 @@
<table class="table normal_table">
<tr class="odd">
<th>ID</th>
<th>当月注册玩家角色达标等级</th>
<th style="width: 200px;">规则名称</th>
<th style="width: 200px;">当月注册玩家角色达标等级</th>
<th>系数值</th>
<th>等级名称</th>
<th>操作</th>
<th style="width: 150px;">操作</th>
</tr>
<empty name="records">
<tr><td colspan="5" 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="6" style="text-align: center;height: 45vh;"><img src="__IMG__/20180207/icon_wushujv2.png"/><p style="line-height: 40px;color: #A5A5A5;">暂无数据</p></td></tr>
<else />
<?php foreach($records as $record):?>
<tr>
<th rowspan="<?=$record['grade_count']?>"><?=$record['id']?></th>
<th rowspan="<?=$record['grade_count']?>"><?=$record['reach_level']?></th>
<th><?=$record['grade_value']?></th>
<th><?=$record['grade_name']?></th>
<th rowspan="<?=$record['grade_count']?>">操作</th>
<tr data-id="<?=$record['id']?>">
<?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['reach_level']?></td>
<?php endif;?>
<td><?=$record['grade_value']?></td>
<td><?=$record['grade_name']?></td>
<?php if($record['grade_count'] > 0):?>
<td rowspan="<?=$record['grade_count']?>">
<a href="{:U('PromoteGrade/setting',['id'=>$record['id']])}" class="editbtn">编辑</a>
&nbsp;&nbsp;
<a href="javascript:;" style="color: red;" class="delete-btn editbtn">删除</a>
</td>
<?php endif;?>
</tr>
<?php endforeach;?>
</empty>
@ -69,4 +79,26 @@
<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">
$('.delete-btn').on({
click: function() {
var tr = $(this).parents('tr').eq(0)
var id = tr.attr('data-id')
layer.confirm('是否要删除该设置?', {icon: 3, title:'提示'}, function(index){
$.ajax({
url: "{:U('PromoteGrade/delete')}",
data: {id: id},
type: 'post',
dataType: 'json',
success: function(response) {
layer.msg(response.info, {time: 1000}, function() {
window.location.href = window.location.href
})
}
})
})
}
})
</script>
</block>
Loading…
Cancel
Save