|
|
@ -17,14 +17,22 @@ class PromoteLimitRuleController extends ThinkController
|
|
|
|
$row = I('row', 10);
|
|
|
|
$row = I('row', 10);
|
|
|
|
$companyId = I('company_id', 0);
|
|
|
|
$companyId = I('company_id', 0);
|
|
|
|
$promoteId = I('promote_id', 0);
|
|
|
|
$promoteId = I('promote_id', 0);
|
|
|
|
|
|
|
|
$account = I('account', '');
|
|
|
|
|
|
|
|
$baseGameId = I('base_game_id', -1);
|
|
|
|
|
|
|
|
$batchNo = I('batch_no', '');
|
|
|
|
|
|
|
|
|
|
|
|
$conditions = [];
|
|
|
|
$conditions = ['_string' => '1=1'];
|
|
|
|
$promoteIds = [];
|
|
|
|
$promoteIds = [];
|
|
|
|
if ($promoteId !== 0) {
|
|
|
|
if ($account != '') {
|
|
|
|
$promoteIds = [$promoteId];
|
|
|
|
$promote = M('promote', 'tab_')->field(['id'])->where(['account' => $account])->find();
|
|
|
|
|
|
|
|
if ($promote) {
|
|
|
|
|
|
|
|
$promoteIds = [$promote['id']];
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
$conditions['_string'] .= ' and 1=0';
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ($companyId !== 0) {
|
|
|
|
if ($companyId !== 0) {
|
|
|
|
$companyPromoteIds = M('promote', 'tab_')->field(['id'])->where(['company_id' => $companyId, 'level' => 1])->getField('id', true);
|
|
|
|
$companyPromoteIds = M('promote', 'tab_')->field(['id'])->where(['company_id' => $companyId])->getField('id', true);
|
|
|
|
if (count($companyPromoteIds) > 0) {
|
|
|
|
if (count($companyPromoteIds) > 0) {
|
|
|
|
$promoteIds = count($promoteIds) ? array_intersect($companyPromoteIds, $promoteIds) : $companyPromoteIds;
|
|
|
|
$promoteIds = count($promoteIds) ? array_intersect($companyPromoteIds, $promoteIds) : $companyPromoteIds;
|
|
|
|
$promoteIds[] = 0;
|
|
|
|
$promoteIds[] = 0;
|
|
|
@ -35,10 +43,16 @@ class PromoteLimitRuleController extends ThinkController
|
|
|
|
if (count($promoteIds)) {
|
|
|
|
if (count($promoteIds)) {
|
|
|
|
$conditions['promote_id'] = ['in', $promoteIds];
|
|
|
|
$conditions['promote_id'] = ['in', $promoteIds];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($baseGameId != -1) {
|
|
|
|
|
|
|
|
$conditions['base_game_id'] = $baseGameId;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($batchNo != '') {
|
|
|
|
|
|
|
|
$conditions['batch_no'] = $batchNo;
|
|
|
|
|
|
|
|
}
|
|
|
|
$query = M('promote_limit_rules', 'tab_')->where($conditions);
|
|
|
|
$query = M('promote_limit_rules', 'tab_')->where($conditions);
|
|
|
|
|
|
|
|
|
|
|
|
$countQuery = clone $query;
|
|
|
|
$countQuery = clone $query;
|
|
|
|
$rules = $query->page($page, $row)->select();
|
|
|
|
$rules = $query->order('id desc')->page($page, $row)->select();
|
|
|
|
$count = $countQuery->count();
|
|
|
|
$count = $countQuery->count();
|
|
|
|
|
|
|
|
|
|
|
|
$recordPromotes = [];
|
|
|
|
$recordPromotes = [];
|
|
|
@ -49,8 +63,12 @@ class PromoteLimitRuleController extends ThinkController
|
|
|
|
if (count($recordCompanyIds) > 0) {
|
|
|
|
if (count($recordCompanyIds) > 0) {
|
|
|
|
$recordCompanys = M('promote_company', 'tab_')->field(['id', 'company_name', 'company_belong'])->where(['id' => ['in', $recordCompanyIds]])->select();
|
|
|
|
$recordCompanys = M('promote_company', 'tab_')->field(['id', 'company_name', 'company_belong'])->where(['id' => ['in', $recordCompanyIds]])->select();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$baseGames = M('base_game', 'tab_')->where(['id' => ['in', array_column($rules, 'base_game_id')]])->select();
|
|
|
|
|
|
|
|
|
|
|
|
$recordPromotes = index_by_column('id', $recordPromotes);
|
|
|
|
$recordPromotes = index_by_column('id', $recordPromotes);
|
|
|
|
$recordCompanys = index_by_column('id', $recordCompanys);
|
|
|
|
$recordCompanys = index_by_column('id', $recordCompanys);
|
|
|
|
|
|
|
|
$baseGames = index_by_column('id', $baseGames);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -63,6 +81,9 @@ class PromoteLimitRuleController extends ThinkController
|
|
|
|
'promote_account' => $recordPromotes[$rule['promote_id']]['account'],
|
|
|
|
'promote_account' => $recordPromotes[$rule['promote_id']]['account'],
|
|
|
|
'company_name' => $recordCompanys[$recordPromotes[$rule['promote_id']]['company_id']]['company_name'],
|
|
|
|
'company_name' => $recordCompanys[$recordPromotes[$rule['promote_id']]['company_id']]['company_name'],
|
|
|
|
'company_belong' => $companyTypes[$recordCompanys[$recordPromotes[$rule['promote_id']]['company_id']]['company_belong']],
|
|
|
|
'company_belong' => $companyTypes[$recordCompanys[$recordPromotes[$rule['promote_id']]['company_id']]['company_belong']],
|
|
|
|
|
|
|
|
'base_game_name' => $rule['base_game_id'] > 0 ? $baseGames[$rule['base_game_id']]['name'] : '所有游戏',
|
|
|
|
|
|
|
|
'with_sub' => $rule['with_sub'] == 1 ? '是' : '否',
|
|
|
|
|
|
|
|
'batch_no' => $rule['batch_no'],
|
|
|
|
'limit_rule' => $this->getDisplayRule($rule),
|
|
|
|
'limit_rule' => $this->getDisplayRule($rule),
|
|
|
|
];
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -72,6 +93,9 @@ class PromoteLimitRuleController extends ThinkController
|
|
|
|
if($page) {
|
|
|
|
if($page) {
|
|
|
|
$this->assign('_page', $page);
|
|
|
|
$this->assign('_page', $page);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$baseGames = M('base_game', 'tab_')->select();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$this->assign('baseGames', $baseGames);
|
|
|
|
$this->assign('records', $records);
|
|
|
|
$this->assign('records', $records);
|
|
|
|
$this->assign('companys', $companys);
|
|
|
|
$this->assign('companys', $companys);
|
|
|
|
$this->display();
|
|
|
|
$this->display();
|
|
|
@ -102,6 +126,10 @@ class PromoteLimitRuleController extends ThinkController
|
|
|
|
$promote = M('promote', 'tab_')->where(['id' => $record['promote_id']])->field(['id', 'company_id', 'account'])->find();
|
|
|
|
$promote = M('promote', 'tab_')->where(['id' => $record['promote_id']])->field(['id', 'company_id', 'account'])->find();
|
|
|
|
$company = M('promote_company', 'tab_')->where(['id' => $promote['company_id']])->field(['id', 'company_name'])->find();
|
|
|
|
$company = M('promote_company', 'tab_')->where(['id' => $promote['company_id']])->field(['id', 'company_name'])->find();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$baseGames = M('base_game', 'tab_')->select();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$this->assign('baseGames', $baseGames);
|
|
|
|
$this->assign('promote', $promote);
|
|
|
|
$this->assign('promote', $promote);
|
|
|
|
$this->assign('company', $company);
|
|
|
|
$this->assign('company', $company);
|
|
|
|
$this->assign('companys', $companys);
|
|
|
|
$this->assign('companys', $companys);
|
|
|
@ -112,7 +140,11 @@ class PromoteLimitRuleController extends ThinkController
|
|
|
|
public function save()
|
|
|
|
public function save()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
$id = I('id', 0);
|
|
|
|
$id = I('id', 0);
|
|
|
|
$promoteId = I('promote_id', 0);
|
|
|
|
$baseGameId = I('base_game_id', 0);
|
|
|
|
|
|
|
|
$account = I('account', '');
|
|
|
|
|
|
|
|
$accountsStr = I('accounts', '');
|
|
|
|
|
|
|
|
$limitType = I('limit_type', 1);
|
|
|
|
|
|
|
|
$withSub = I('with_sub', 1);
|
|
|
|
$startedAt = I('started_at', '');
|
|
|
|
$startedAt = I('started_at', '');
|
|
|
|
$endedAt = I('ended_at', '');
|
|
|
|
$endedAt = I('ended_at', '');
|
|
|
|
|
|
|
|
|
|
|
@ -124,62 +156,122 @@ class PromoteLimitRuleController extends ThinkController
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$record = null;
|
|
|
|
$record = null;
|
|
|
|
|
|
|
|
$promotes = [];
|
|
|
|
if ($id > 0) {
|
|
|
|
if ($id > 0) {
|
|
|
|
$record = M('promote_limit_rules', 'tab_')->where(['id' => $id])->find();
|
|
|
|
$record = M('promote_limit_rules', 'tab_')->where(['id' => $id])->find();
|
|
|
|
if (!$record) {
|
|
|
|
if (!$record) {
|
|
|
|
return $this->error('修改记录不存在');
|
|
|
|
return $this->error('修改记录不存在');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
if (empty($promoteId)) {
|
|
|
|
try {
|
|
|
|
return $this->error('请选择会长');
|
|
|
|
$accounts = [];
|
|
|
|
|
|
|
|
if ($limitType == 1) {
|
|
|
|
|
|
|
|
$accounts = [$account];
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
$accounts = $this->parseAccountsStr($accountsStr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$promoteRecord = M('promote_limit_rules', 'tab_')->where(['promote_id' => $promoteId])->find();
|
|
|
|
$promotes = $this->getPromotes($accounts);
|
|
|
|
if ($promoteRecord) {
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
return $this->error('该会长已经设定限制规则,请前往更新');
|
|
|
|
return $this->error($e->getMessage());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if ($record) {
|
|
|
|
if ($record) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$promote = M('promote', 'tab_')->field(['id'])->where(['account' => $account])->find();
|
|
|
|
|
|
|
|
|
|
|
|
$data = [];
|
|
|
|
$data = [];
|
|
|
|
|
|
|
|
$data['promote_id'] = $promote['id'];
|
|
|
|
|
|
|
|
$data['base_game_id'] = $baseGameId;
|
|
|
|
|
|
|
|
$data['with_sub'] = $withSub;
|
|
|
|
$data['started_at'] = $startedAt;
|
|
|
|
$data['started_at'] = $startedAt;
|
|
|
|
$data['ended_at'] = $endedAt;
|
|
|
|
$data['ended_at'] = $endedAt;
|
|
|
|
$data['update_time'] = time();
|
|
|
|
$data['update_time'] = time();
|
|
|
|
M('promote_limit_rules', 'tab_')->where(['id' => $id])->save($data);
|
|
|
|
M('promote_limit_rules', 'tab_')->where(['id' => $id])->save($data);
|
|
|
|
addOperationLog([
|
|
|
|
|
|
|
|
'op_type' => 1,
|
|
|
|
|
|
|
|
'key'=> $promoteId . '/' . $startedAt . '/' . $endedAt,
|
|
|
|
|
|
|
|
'op_name' => '修改推广限制',
|
|
|
|
|
|
|
|
'url' => U('PresidentDeposit/edit', ['id'=>$id]), 'menu'=>'推广员-推广员管理-推广限制-修改推广限制'
|
|
|
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
$data = [];
|
|
|
|
$data = [];
|
|
|
|
$data['promote_id'] = $promoteId;
|
|
|
|
$data['base_game_id'] = $baseGameId;
|
|
|
|
|
|
|
|
$data['with_sub'] = $withSub;
|
|
|
|
$data['started_at'] = $startedAt;
|
|
|
|
$data['started_at'] = $startedAt;
|
|
|
|
$data['ended_at'] = $endedAt;
|
|
|
|
$data['ended_at'] = $endedAt;
|
|
|
|
|
|
|
|
$data['batch_no'] = date('Ymdhis') . rand(1000, 9999);
|
|
|
|
$data['create_time'] = time();
|
|
|
|
$data['create_time'] = time();
|
|
|
|
$data['update_time'] = time();
|
|
|
|
$data['update_time'] = time();
|
|
|
|
M('promote_limit_rules', 'tab_')->add($data);
|
|
|
|
|
|
|
|
|
|
|
|
$records = [];
|
|
|
|
|
|
|
|
foreach ($promotes as $promote) {
|
|
|
|
|
|
|
|
$records[] = array_merge($data, ['promote_id' => $promote['id']]);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
M('promote_limit_rules', 'tab_')->addAll($records);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ($id > 0) {
|
|
|
|
|
|
|
|
addOperationLog([
|
|
|
|
|
|
|
|
'op_type' => 1,
|
|
|
|
|
|
|
|
'key'=> '',
|
|
|
|
|
|
|
|
'op_name' => '修改推广限制',
|
|
|
|
|
|
|
|
'url' => U('PromoteLimitRule/save'), 'menu'=>'推广员-推广员管理-推广限制-修改推广限制',
|
|
|
|
|
|
|
|
'content' => json_encode(I('post.'))
|
|
|
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
addOperationLog([
|
|
|
|
addOperationLog([
|
|
|
|
'op_type' => 0,
|
|
|
|
'op_type' => 0,
|
|
|
|
'key'=> $promoteId . '/' . $startedAt . '/' . $endedAt,
|
|
|
|
'key'=> '',
|
|
|
|
'op_name' => '新增推广限制',
|
|
|
|
'op_name' => '新增推广限制',
|
|
|
|
'url' => U('PresidentDeposit/edit', ['promote_id'=>$promoteId]), 'menu'=>'推广员-推广员管理-推广限制-新增推广限制'
|
|
|
|
'url' => U('PromoteLimitRule/save'), 'menu'=>'推广员-推广员管理-推广限制-新增推广限制',
|
|
|
|
|
|
|
|
'content' => json_encode(I('post.'))
|
|
|
|
]);
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return $this->success('保存成功', U('records'));
|
|
|
|
return $this->success('保存成功', U('records'));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private function parseAccountsStr($accountsStr)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if ($accountsStr == '') {
|
|
|
|
|
|
|
|
throw new \Exception('推广员账号数量不能为0');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
$accountArr = json_decode($accountsStr, true);
|
|
|
|
|
|
|
|
$accounts = [];
|
|
|
|
|
|
|
|
foreach ($accountArr as $key => $item) {
|
|
|
|
|
|
|
|
$accounts[] = trim($item['推广账号']);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return array_unique($accounts);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private function getPromotes($accounts)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
$promotes = M('promote', 'tab_')->field(['id', 'account'])->where(['account' => ['in', $accounts]])->select();
|
|
|
|
|
|
|
|
if (count($accounts) != count($promotes)) {
|
|
|
|
|
|
|
|
$promotes = index_by_column('account', $promotes);
|
|
|
|
|
|
|
|
$noExistAcounts = [];
|
|
|
|
|
|
|
|
foreach ($accounts as $account) {
|
|
|
|
|
|
|
|
if (!isset($promotes[$account])) {
|
|
|
|
|
|
|
|
$noExistAcounts[] = $account;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
throw new \Exception('含有不存在的推广账号: ' . implode(',', $noExistAcounts));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return $promotes;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function delete()
|
|
|
|
public function delete()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
$id = I('id', 0);
|
|
|
|
$id = I('id', 0);
|
|
|
|
M('promote_limit_rules', 'tab_')->where(['id' => $id])->delete();
|
|
|
|
$batchNo = I('batch_no', '');
|
|
|
|
|
|
|
|
$conditions = [];
|
|
|
|
|
|
|
|
if ($id > 0) {
|
|
|
|
|
|
|
|
$conditions['id'] = $id;
|
|
|
|
|
|
|
|
} elseif ($batchNo != '') {
|
|
|
|
|
|
|
|
$conditions['batch_no'] = $batchNo;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
M('promote_limit_rules', 'tab_')->where($conditions)->delete();
|
|
|
|
|
|
|
|
|
|
|
|
addOperationLog([
|
|
|
|
addOperationLog([
|
|
|
|
'op_type' => 2,
|
|
|
|
'op_type' => 2,
|
|
|
|
'key' => $id,
|
|
|
|
'key' => $id,
|
|
|
|
'op_name' => '删除会长推广限制',
|
|
|
|
'op_name' => '删除会长推广限制',
|
|
|
|
'url' => U('PresidentDeposit/delete', ['id' => $id]),
|
|
|
|
'url' => U('PresidentDeposit/delete', ['id' => $id, 'batch' => $batchNo]),
|
|
|
|
'menu' => '推广员-推广员管理-推广限制-删除推广限制'
|
|
|
|
'menu' => '推广员-推广员管理-推广限制-删除推广限制'
|
|
|
|
]);
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
|
|