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