diff --git a/Application/Base/Service/PromoteGradeService.class.php b/Application/Base/Service/PromoteGradeService.class.php
new file mode 100644
index 000000000..4f303e06b
--- /dev/null
+++ b/Application/Base/Service/PromoteGradeService.class.php
@@ -0,0 +1,180 @@
+ '>=',
+ 2 => '>',
+ ];
+
+ /**
+ * @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('不允许修改其他公司的配置');
+ }
+ } 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'] = $this->sortGrades($params['grades']);
+ $config['default_grade_name'] = $params['default_grade_name'];
+
+ $data = [];
+ $data['status'] = 1;
+ $data['name'] = $params['name'];
+ $data['config'] = json_encode($config);
+
+ 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 sortGrades($grades)
+ {
+ if (count($grades) == 0) {
+ return $grades;
+ }
+ $values = [];
+ $symbols = [];
+ foreach ($grades as $key => $row) {
+ $values[$key] = $row['value'];
+ $symbols[$key] = $row['symbol'];
+ }
+
+ array_multisort($values, SORT_ASC, $symbols, SORT_ASC, $grades);
+ return $grades;
+ }
+
+ public function getCurrentSetting($promote)
+ {
+ return M('promote_grade_setting', 'tab_')->where(['status' => 1, 'company_id' => $promote['company_id']])->find();
+ }
+
+ public function searchGradeByPromotes($promotes, $params, $setting)
+ {
+ $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');
+ $endDate = date('Y-m-01 00:00:00', strtotime($month . '-01' . ' +1 month'));
+ $endTime = strtotime($endDate) - 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);
+
+ $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[] = [
+ 'id' => $promote['id'],
+ 'level' => $promote['level'],
+ 'amount' => $amount,
+ 'num' => $num,
+ 'real_name' => hideRealName($promote['real_name']),
+ 'account' => $promote['account'],
+ '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 = $grades[$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;
+ }
+}
\ No newline at end of file
diff --git a/Application/Home/Controller/DownloadController.class.php b/Application/Home/Controller/DownloadController.class.php
index 7c0d13d60..2f260fbc7 100644
--- a/Application/Home/Controller/DownloadController.class.php
+++ b/Application/Home/Controller/DownloadController.class.php
@@ -8,6 +8,7 @@ use Base\Repository\PromoteRepository;
use Base\Repository\SpendRepository;
use Base\Repository\UserRepository;
use Base\Service\PromoteService;
+use Base\Service\PromoteGradeService;
use Base\Facade\Request;
use Base\Service\ApplyService;
use Base\Service\PromoteCoinRecordService;
@@ -1888,6 +1889,66 @@ class DownloadController extends BaseController {
$this->success('添加下载成功',U('listsIndex'));
}
+
+ public function promote_grade_export()
+ {
+ $month = I('month', date('Y-m'));
+ $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;
+ $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;
+ }
+
+ $promotes = M('promote', 'tab_')->field(['id', 'account', 'real_name', 'level', 'chain'])->where($map)->select();
+ array_unshift($promotes, $parent);
+
+ $conditions = json_encode(['promotes' => $promotes, 'setting' => $setting, 'month' => $month], true);
+ $addtime = time();
+ $data1 = [
+ 'logid' => 'pg_'.time(),
+ 'promote_id' => PID,
+ 'type' => '/Home/PromoteGrade/index',
+ 'dataname' => '团队评级',
+ 'status' => 0,
+ 'addtime' => $addtime,
+ 'begintime' => 0,
+ 'content' => '',
+ 'conditions' => $conditions
+ ];
+ $res = M('downloadlog','tab_')->add($data1);
+ if (!$res) {
+ $this->error('添加下载失败');
+ }
+ $this->success('添加下载成功', U('listsIndex'));
+ }
//玩家角色
public function userRoles_data_export() {
$gameId = I('relation_game_id', 0);
@@ -2158,6 +2219,9 @@ class DownloadController extends BaseController {
case "推广员业绩":
$this->achievementExcelInfo($id,$map);
break;
+ case "团队评级":
+ $this->promoteGradeExcelInfo($id,$map);
+ break;
case "渠道管理":
$this->childrenExcelInfo($id,$map);
break;
@@ -3973,6 +4037,35 @@ public function iosDetailExcelInfo($id,$map) {
}
+ public function promoteGradeExcelInfo($tid, $map)
+ {
+ $xlsName = "团队评级";
+ $xlsCell = array(
+ array('account','账号'),
+ array('real_name','姓名'),
+ array('promote_group', '部门/小组'),
+ array('grade_name','等级'),
+ array('value','系数值'),
+ array('num','当月玩家达标个数'),
+ array('amount','当月注册充值总额'),
+ );
+
+ recordPromoteLogs('评级管理', '团队评级导出');
+
+ $map = json_decode(json_encode($map), true);
+
+ $promoteGradeService = new PromoteGradeService();
+ $records = $promoteGradeService->searchGradeByPromotes($map['promotes'], [
+ 'month' => $map['month'],
+ ], $map['setting']);
+
+ $xlsData = [];
+ foreach ($records as $key => $value) {
+ $xlsData[] = $value;
+ }
+ $this->exportExcel($xlsName, $xlsCell, $xlsData, $tid);
+ }
+
public function achievementExcelInfo($tid, $map) {
$xlsName = "推广员业绩";
$xlsCell = array(
diff --git a/Application/Home/Controller/PromoteGradeController.class.php b/Application/Home/Controller/PromoteGradeController.class.php
new file mode 100644
index 000000000..c9cc191b8
--- /dev/null
+++ b/Application/Home/Controller/PromoteGradeController.class.php
@@ -0,0 +1,180 @@
+getLoginPromote();
+ if((C('APP_ENV') == 'dev' || $loginPromote['company_id'] == 334) && $loginPromote['level'] <= 2) {
+
+ } else {
+ return $this->error('您没有权限');
+ }
+ }
+
+ public function index($p = 1)
+ {
+ $month = I('month', date('Y-m'));
+ $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;
+ $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);
+
+ 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('month', $month);
+ $this->assign('prevParentId', $prevParentId);
+ $this->assign('searchLevelName', $searchLevelName);
+ $this->assign('subPromotes', $subPromotes);
+ $this->assign('parentId', $parentId);
+ $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();
+
+ $symbols = PromoteGradeService::$symbols;
+
+ $records = [];
+ foreach ($items as $item) {
+ $i = 0;
+ $config = json_decode($item['config'], true);
+ $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()
+ {
+ $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());
+ }
+ }
+}
\ No newline at end of file
diff --git a/Application/Home/View/default/PromoteGrade/index.html b/Application/Home/View/default/PromoteGrade/index.html
new file mode 100644
index 000000000..7d619ae9c
--- /dev/null
+++ b/Application/Home/View/default/PromoteGrade/index.html
@@ -0,0 +1,162 @@
+ 暂无数据
+ 团队评级
+
+
+
+
+
+ 账号(姓名)
+ 等级
+ 系数值
+ 当月玩家达标个数
+ 当月注册充值总额
+ 操作
+
+
+
+ {$record.account}({$record.real_name}
+
+ /{$record.promote_group}
+
+ )
+
+ [{$record['current_display']}]
+
+
+ {$record.grade_name}
+ {$record.value}
+ {$record.num}
+ {$record.amount}
+
+
+ 查看下级
+
+
+
+ 评级设定
+