master
ELF 4 years ago
parent 0f534009b4
commit afad195062

@ -0,0 +1,116 @@
<?php
namespace Base\Service;
use Base\Facade\Request;
use Base\Tool\GameCatClient;
class PromoteGradeService
{
/**
* @config
* reach_level
* grades
* - name
* - value
*/
public function saveSetting($params, $promote)
{
$id = $params['id'] ?? 0;
$setting = null;
if ($id > 0) {
$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('不允许修改其他公司的配置');
}
}
$config = [];
$config['reach_level'] = $params['level'];
$config['grades'] = $params['grades'];
$data = [];
$data['company_id'] = $promote['company_id'];
$data['status'] = 1;
$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);
}
private function checkGrades($grades)
{
}
public function hadSetting($promote)
{
$setting = M('promote_grade_setting', 'tab_')->field(['id'])->where(['status' => 1, 'company_id' => $promote['company_id']])->find();
if ($setting) {
return true;
}
return false;
}
public function searchGradeByPromotes($promotes, $params)
{
/**
* @todo 通过设置获取
*/
$settingLevel = 50;
$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;
$betweenTime = [$beginTime, $endTime];
$userSubSql = M('user', 'tab_')
->field(['id'])
->where(['register_time' => ['between', $betweenTime], 'promote_id' => ['in', $promoteIds]])
->group('promote_id')
->select(false);
$accountItems = M('user_play_info', 'tab_')
->field(['promote_id', 'count(DISTINCT user_id) num'])
->where([
'role_level' => ['egt', $settingLevel],
'create_time' => ['between', $betweenTime],
'promote_id' => ['in', $promoteIds],
'_string' => 'user_id in (' . $userSubSql . ')'
])
->group('promote_id')
->select();
$accountItems = index_by_column('promote_id', $accountItems);
$amountItems = M('spend', 'tab_')
->field(['promote_id', 'sum(pay_amount) amount'])
->where([
'pay_time' => ['between', $betweenTime],
'pay_status' => 1, 'promote_id' => ['in', $promoteIds],
'_string' => 'user_id in (' . $userSubSql . ')'
])
->group('promote_id')
->select();
$amountItems = index_by_column('promote_id', $amountItems);
$records = [];
foreach ($promotes as $promote) {
$amountItem = $amountItems[$promote['id']] ?? null;
$accountItem = $accountItems[$promote['id']] ?? null;
$records[] = [
'amount' => $amountItem ? $amountItem['amount'] : 0,
'num' => $accountItem ? $accountItem['num'] : 0,
'real_name' => $promote['real_name'],
'account' => $promote['account'],
'promote_group' => $promote['promote_group']
];
}
return $records;
}
}

@ -0,0 +1,106 @@
<?php
namespace Home\Controller;
use Base\Model\PromoteModel;
use Base\Service\PromoteService;
use Base\Service\PromoteGradeService;
class PromoteGradeController extends BaseController
{
public function index($p = 1)
{
$loginPromote = $this->getLoginPromote();
/* $promoteGradeService = new PromoteGradeService();
if (!$promoteGradeService->hadSetting($loginPromote)) {
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 = '';
$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 = '自己';
}
$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;
}
$query = M('promote', 'tab_')->field(['id', 'account', 'real_name', 'level', 'chain'])->where($map);
list($promotes, $pagination, $count) = $this->paginate($query);
$records = $promoteGradeService->searchGradeByPromotes($promotes, [
'month' => $month,
]);
$this->meta_title = '团队评级';
$this->assign('records', $records);
$this->assign('prevParentId', $prevParentId);
$this->assign('searchLevelName', $searchLevelName);
$this->assign('subPromotes', $subPromotes);
$this->assign('records', $records);
$this->assign('pagination', $pagination);
$this->display();
}
public function settings()
{
$loginPromote = $this->getLoginPromote();
$items = M('promote_grade_setting', 'tab_')->where(['company_id' => $loginPromote['company_id']])->select();
$records = [];
foreach ($items as $key => $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'];
}
}
$this->assign('records', $records);
$this->display();
}
public function setting()
{
$this->display();
}
public function saveSetting()
{
var_dump(I('post.'));
}
}

@ -0,0 +1,162 @@
<extend name="Public/promote_base"/>
<block name="css">
<link href="__CSS__/20180207/account.css" rel="stylesheet" >
<style>
.form-group {
float: left;
margin-bottom: 10px;
}
.form-group label {
line-height: 34px;
height: 34px;
}
.pointer-hand {
cursor: pointer;
}
</style>
</block>
<block name="body">
<div class="page-list normal_list promote-mychlid-list">
<div class="trunk-title">
<div class="location">
<div class="location-container">当前位置:<span>评级管理></span><span>团队评级</span></div>
</div>
<img src="__IMG__/20180207/icon_normal_game.png">
<span class="title_main">团队评级</span>
</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">
<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;" >
<option value="0">请选择{$searchLevelName}</option>
<volist name="subPromotes" id="promote">
<option ba-id="{$promote.id}" value="{$promote.id}" <if condition="I('promote_id') == $promote['id']">selected</if>>
{$promote.account}({$promote.real_name})
<?=$promote['group_remark'] ? ' - ' . $promote['group_remark'] : '' ?>
</option>
</volist>
</select>
</div>
<div class="form-group normal_space fr">
<input type="text" class="txt range-date" name="time" placeholder="起止时间" value="{$time}" >
</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>
</div>
<?php endif;?>
</form>
</div>
<div class="trunk-list list_normal">
<table class="table normal_table">
<tr class="odd">
<th>账号(姓名)</th>
<th>等级</th>
<th>当月玩家达标个数</th>
<th>当月注册充值总额</th>
<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>
<else />
<volist name="records" id="record" mod="2">
<tr data-id="{$vo.id}" class="<eq name='mod' value='1'>odd</eq>">
<td>{$record.account}({$record.real_name}
<?php if($record['promote_group'] != ''):?>
/{$record.promote_group}
<?php endif;?>
)
<?php if($record['current_display'] != ''):?>
<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>
<?php if($record['current_display'] == '' && $record['level'] < 4):?>
<a href="{:U('Query/achievement', ['parent_id' => $record['id'], 'time' => I('time', '')])}">查看下级</a>
<?php endif;?>
</td>
</tr>
</volist>
</empty>
</table>
</div>
<div class="pagenation clearfix">
<?php if ($loginer['level'] !== 4) :?>
<a id="sch-btn" href="{:U('download/achievement_data_export',array_merge(['parent_id'=>$parentid,'time'=>$time],I('post.')))}" class="ajax-get">导出</a>
<?php endif ;?>
{$pagination}
</div>
</div>
<div class="page-explain promote-mychlid-explain">
<div class="trunk-content article border_normal">
<!-- <table class="desccontent">
<tr><td class="title" style="width: 100px;display: inline-block;">二级渠道说明:</td><td class="det">推广员默认为一级渠道,一级渠道可通过推广员后台新增二级渠道;二级渠道由一级渠道管理开启权限,并由一级渠道给二级渠道结算,结算可到财务管理操作。</td></tr>
</table>-->
</div>
</div>
</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>
<eq name='timeout' value='1'>
<script>
layer.msg('时间间隔不能超过31天');
</script>
</eq>
<script type="text/javascript">
$(function() {
var defaultDate = $('.range-date').val()
defaultDate = defaultDate == '' ? [] : defaultDate.split(' 至 ')
$('.range-date').flatpickr({
mode: 'range',
locale: 'zh',
dateFormat: "Y-m-d",
defaultDate: defaultDate,
})
$('.select_gallery').select2()
var gameId = $('#game-select').val();
var sdkVersion = $('#sdk_version').val();
var defaultServerId = $('#server-select').attr('data-server');
getGameServers(gameId, sdkVersion, defaultServerId)
$('#game-select,#sdk_version').on({
change: function name() {
gameId = $('#game-select').val();
sdkVersion = $('#sdk_version').val();
getGameServers(gameId, sdkVersion, 0);
}
});
function getGameServers(gameId, sdkVersion, defaultServerId) {
$.ajax({
url: "{:U('Query/getGameServers')}",
dataType: 'json',
data: {game_id: gameId, sdk_version: sdkVersion},
success: function(response) {
var options = '<option value="0">请选择区服</option>'
for (var i in response.data.servers) {
var server = response.data.servers[i]
var selected = ''
if (defaultServerId > 0 && server.id==defaultServerId) {
selected = 'selected'
}
options += '<option value="' + server.server_id + '"' + selected + '>' + server.server_name + '</option>'
}
$('#server-select').html(options)
$("#server-select").val(defaultServerId).trigger("change")
}
})
}
})
</script>
</block>

@ -0,0 +1,233 @@
<extend name="Public/promote_base"/>
<block name="css">
<link href="__CSS__/20180207/account.css" rel="stylesheet" >
<style>
.add-rule {
margin-top: 10px;
margin-bottom: 15px;
width: 80px;
height: 36px;
line-height: 36px;
background: #409eff;
color: #fff;
border-radius: 4px;
border: none;
padding: 0;
cursor: pointer;
}
.delete-rule {
margin-left: 10px;
width: 60px;
height: 36px;
line-height: 36px;
background: rgb(249,104,104);
color: #fff;
border-radius: 4px;
border: none;
padding: 0;
cursor: pointer;
}
.rule-list {
margin-bottom: 20px;
}
.rule-list .rule-item {
margin-bottom: 10px;
}
.rule-list .rule-item .select2 {
margin-right: 5px;
}
.trunk-list .table2 .l {
width: 140px;
}
</style>
</block>
<block name="body">
<div class="page-list normal_list promote-add_chlid-form">
<div class="trunk-title">
<div class="location">
<div class="location-container">当前位置:<span>评级管理></span><span>评级设定</span></div>
</div>
<img src="__IMG__/20180207/icon_normal_ziqudao.png">
<span class="title_main">评级设定</span>
</div>
<div class="trunk-content article">
<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)}">
<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="请输入评级规则名称">
</td>
</tr>
<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="玩家角色达标等级">
</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="默认等级名称">
</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> -->
</div>
</td>
</tr>
<tr>
<td class="l"></td>
<td class="r">
<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>
</table>
</form>
</div>
</div>
</div>
</block>
<block name="script">
<script type="text/javascript" src="__JS__/20170831/select2.min.js"></script>
<script type="text/javascript">
$(".select_gallery").select2();
$('#add-rule').on({
click: function () {
var html = '<div class="rule-item">'
+ '系数值:' + "\n"
+ '<select class="symbol-item reselect select_gallery" style="width: 60px;" >'
+ '<option value="1">>=</option>'
+ '<option value="2">></option>'
+ '</select>' + "\n"
+ '<input type="text" class="value-item name input-txt txt" maxlength="4" minlength="1" placeholder="系数值">' + "\n"
+ '&nbsp;&nbsp;&nbsp;&nbsp;' + "\n"
+ '等级名称:' + "\n"
+ '<input type="text" class="name-item name input-txt txt" placeholder="等级名称">'
+ '<button type="button" class="delete-rule">删除</button>'
+ '</div>';
$('#rule-list').append(html)
$(".select_gallery").select2();
}
})
function check() {
if (!validation()) {
return
}
var form = $('#rule-form');
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()
$.ajax({
type:"POST",
url:"{:U('saveSetting')}",
data:{
name: name,
level: level,
defaultGradeName: defaultGradeName,
grades: getGrades()
},
success:function(res){
if(res.status == 1){
layer.msg(res.msg);
setTimeout(function(){
window.location.href="{:U('settings')}";
},1000);
}else{
layer.msg(res.msg);
}
}
});
// $('#form_reg').submit();
}
$('#rule-list').on('click', '.delete-rule', function() {
$(this).parents('.rule-item').eq(0).remove()
})
function getGrades() {
var grades = []
$('#rule-list').children('.rule-item').each(function(index, elem) {
var item = $(elem)
var symbol = item.find('.symbol-item').val()
var value = item.find('.value-item').val()
var name = item.find('.name-item').val()
grades.push({
name: name,
value: value,
symbol: symbol
})
})
return grades
}
function validation() {
var form = $('#rule-form');
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()
if (name == '') {
layer.msg('请输入评级规则名称');
return false;
}
if (level == '') {
layer.msg('玩家角色达标等级');
return false;
}
var levelReg = /^\d+$/;
if(!levelReg.test(level)){
layer.msg('玩家角色达标等级必须为数字');
return false;
}
if (level > 10000) {
layer.msg('玩家角色达标等级不能超过10000');
return false;
}
if (defaultGradeName == '') {
layer.msg('默认等级名称不能为空');
return false;
}
var grades = getGrades()
for(var i in grades) {
if (grades[i].name == '') {
layer.msg('请输入等级名称');
return false;
}
if (grades[i].value == '') {
layer.msg('请输入系数值');
return false;
}
/* var numReg = /([+]\d+[.]\d+|[-]\d+[.]\d+|\d+[.]\d+|[+]\d+|[-]\d+|\d+)/ig;
if(!numReg.test(grades[i].value)){
layer.msg('系数值必须为整数或浮点数');
return false;
} */
}
return true;
}
</script>
</block>

@ -0,0 +1,72 @@
<extend name="Public/promote_base"/>
<block name="css">
<link href="__CSS__/20180207/account.css" rel="stylesheet" >
<style>
.form-group {
float: left;
margin-bottom: 10px;
}
.form-group label {
line-height: 34px;
height: 34px;
}
.pointer-hand {
cursor: pointer;
}
</style>
</block>
<block name="body">
<div class="page-list normal_list promote-mychlid-list">
<div class="trunk-title">
<div class="location">
<div class="location-container">当前位置:<span>评级管理></span><span>团队评级</span></div>
</div>
<img src="__IMG__/20180207/icon_normal_game.png">
<span class="title_main">团队评级</span>
</div>
<div class="trunk-content article">
<div class="trunk-search clearfix">
<div class="form-group">
<a class="submit normal_space" href="{:U('PromoteGrade/setting')}" style="line-height: 36px; display: inline-block; text-align: center; background: #409eff; color: #ffffff; cursor: pointer;">新增评级规则</a>
</div>
</div>
<div class="trunk-list list_normal">
<table class="table normal_table">
<tr class="odd">
<th>ID</th>
<th>当月注册玩家角色达标等级</th>
<th>系数值</th>
<th>等级名称</th>
<th>操作</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>
<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>
<?php endforeach;?>
</empty>
</table>
</div>
</div>
<div class="page-explain promote-mychlid-explain">
<div class="trunk-content article border_normal">
<!-- <table class="desccontent">
<tr><td class="title" style="width: 100px;display: inline-block;">二级渠道说明:</td><td class="det">推广员默认为一级渠道,一级渠道可通过推广员后台新增二级渠道;二级渠道由一级渠道管理开启权限,并由一级渠道给二级渠道结算,结算可到财务管理操作。</td></tr>
</table>-->
</div>
</div>
</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>
</block>

@ -2626,4 +2626,14 @@ CREATE TABLE `tab_aggregate_statement_pool` (
ALTER TABLE `tab_company_info` ALTER TABLE `tab_company_info`
ADD COLUMN `invoice_item` varchar(255) NULL DEFAULT '' COMMENT '开票内容' AFTER `fax_ratio`, ADD COLUMN `invoice_item` varchar(255) NULL DEFAULT '' COMMENT '开票内容' AFTER `fax_ratio`,
ADD COLUMN `invoice_type` varchar(255) NULL DEFAULT '' COMMENT '开票类型' AFTER `invoice_item`; ADD COLUMN `invoice_type` varchar(255) NULL DEFAULT '' COMMENT '开票类型' AFTER `invoice_item`;
CREATE TABLE `tab_promote_grade_setting` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`company_id` int(11) NOT NULL COMMENT '推广公司ID',
`config` varchar(255) NOT NULL COMMENT '配置',
`status` tinyint(11) NOT NULL DEFAULT '0' COMMENT '状态',
`create_time` int(11) NOT NULL DEFAULT '0',
`update_time` int(11) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='推广评级设定';
Loading…
Cancel
Save