You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
116 lines
3.7 KiB
PHTML
116 lines
3.7 KiB
PHTML
4 years ago
|
<?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;
|
||
|
}
|
||
|
}
|