|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Admin\Controller;
|
|
|
|
|
|
|
|
use User\Api\UserApi as UserApi;
|
|
|
|
use Base\Service\PresidentDepositService;
|
|
|
|
use Base\Task\Task;
|
|
|
|
/**
|
|
|
|
* 市场
|
|
|
|
*/
|
|
|
|
class MarketController extends ThinkController
|
|
|
|
{
|
|
|
|
public function rebindRecords()
|
|
|
|
{
|
|
|
|
$page = I('p', 1);
|
|
|
|
$row = I('row', 10);
|
|
|
|
$companyId = I('company_id', 0);
|
|
|
|
$promoteId = I('promote_id', 0);
|
|
|
|
|
|
|
|
$conditions = [];
|
|
|
|
$promoteIds = [];
|
|
|
|
if ($promoteId !== 0) {
|
|
|
|
$promoteIds = [$promoteId];
|
|
|
|
}
|
|
|
|
if ($companyId !== 0) {
|
|
|
|
$companyPromoteIds = M('promote', 'tab_')->field(['id'])->where(['company_id' => $companyId, 'level' => 1])->getField('id', true);
|
|
|
|
if (count($companyPromoteIds) > 0) {
|
|
|
|
$promoteIds = count($promoteIds) ? array_intersect($companyPromoteIds, $promoteIds) : $companyPromoteIds;
|
|
|
|
$promoteIds[] = 0;
|
|
|
|
} else {
|
|
|
|
$promoteIds = [0];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (count($promoteIds)) {
|
|
|
|
$conditions['promote_id'] = ['in', $promoteIds];
|
|
|
|
}
|
|
|
|
$query = M('market_shift', 'tab_')->where($conditions);
|
|
|
|
|
|
|
|
$countQuery = clone $query;
|
|
|
|
$items = $query->order('id desc')->page($page, $row)->select();
|
|
|
|
$count = $countQuery->count();
|
|
|
|
|
|
|
|
$recordPromotes = [];
|
|
|
|
$recordCompanys = [];
|
|
|
|
if (count($items) > 0) {
|
|
|
|
$recordPromotes = M('promote', 'tab_')->field(['id', 'account', 'company_id'])->where(['id' => ['in', array_column($items, 'promote_id')]])->select();
|
|
|
|
$recordCompanyIds = array_column($recordPromotes, 'company_id');
|
|
|
|
if (count($recordCompanyIds) > 0) {
|
|
|
|
$recordCompanys = M('promote_company', 'tab_')->field(['id', 'company_name', 'company_belong'])->where(['id' => ['in', $recordCompanyIds]])->select();
|
|
|
|
}
|
|
|
|
$adminIds = array_merge(array_column($items, 'from_id'), array_column($items, 'to_id'));
|
|
|
|
$recordAdmins = M('ucenter_member', 'sys_')->field(['id', 'username'])->where(['id' => ['in', $adminIds]])->select();
|
|
|
|
$recordPromotes = index_by_column('id', $recordPromotes);
|
|
|
|
$recordCompanys = index_by_column('id', $recordCompanys);
|
|
|
|
$recordAdmins = index_by_column('id', $recordAdmins);
|
|
|
|
}
|
|
|
|
|
|
|
|
$companyTypes = [
|
|
|
|
0 => '内团',
|
|
|
|
1 => '外团',
|
|
|
|
2 => '外团-分发联盟',
|
|
|
|
3 => '无'
|
|
|
|
];
|
|
|
|
|
|
|
|
$statusList = [
|
|
|
|
0 => '待处理',
|
|
|
|
1 => '处理成功',
|
|
|
|
2 => '处理失败',
|
|
|
|
3 => '已取消'
|
|
|
|
];
|
|
|
|
|
|
|
|
$records = [];
|
|
|
|
foreach ($items as $item) {
|
|
|
|
$records[] = [
|
|
|
|
'id' => $item['id'],
|
|
|
|
'promote_account' => $recordPromotes[$item['promote_id']]['account'],
|
|
|
|
'company_name' => $recordCompanys[$recordPromotes[$item['promote_id']]['company_id']]['company_name'],
|
|
|
|
'company_belong' => $companyTypes[$recordCompanys[$recordPromotes[$item['promote_id']]['company_id']]['company_belong']],
|
|
|
|
'remark' => $item['remark'],
|
|
|
|
'from_username' => $recordAdmins[$item['from_id']]['username'],
|
|
|
|
'to_username' => $recordAdmins[$item['to_id']]['username'],
|
|
|
|
'split_time' => $item['split_time'] == 0 ? '全部' : date('Y-m-d H:i:s', $item['split_time']),
|
|
|
|
'created_time' => date('Y-m-d H:i:s', $item['created_time']),
|
|
|
|
'status_text' => $statusList[$item['status']],
|
|
|
|
'status' => $item['status']
|
|
|
|
];
|
|
|
|
}
|
|
|
|
$companys = M('promote_company', 'tab_')->field(['id', 'company_name'])->where(['company_belong' => ['in', [1, 2]]])->select();
|
|
|
|
|
|
|
|
$page = set_pagination($count, $row);
|
|
|
|
if($page) {
|
|
|
|
$this->assign('_page', $page);
|
|
|
|
}
|
|
|
|
$this->assign('records', $records);
|
|
|
|
$this->assign('companys', $companys);
|
|
|
|
$this->display();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function rebind()
|
|
|
|
{
|
|
|
|
$this->meta_title = '新增换绑';
|
|
|
|
$id = I('id', 0);
|
|
|
|
$companys = M('promote_company', 'tab_')->field(['id', 'company_name'])->where(['company_belong' => ['in', [1, 2]]])->select();
|
|
|
|
$marketAdmins = getMarketAdmins();
|
|
|
|
$this->assign('companys', $companys);
|
|
|
|
$this->assign('marketAdmins', $marketAdmins);
|
|
|
|
$this->display('rebind');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function save()
|
|
|
|
{
|
|
|
|
$records = I('records', []);
|
|
|
|
if (count($records) == 0) {
|
|
|
|
$this->ajaxReturn([
|
|
|
|
'status' => 0,
|
|
|
|
'message' => '未提交换绑数据'
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
$status = true;
|
|
|
|
$message = '';
|
|
|
|
foreach ($records as $record) {
|
|
|
|
if ($record['from_id'] == $record['to_id']) {
|
|
|
|
$status = false;
|
|
|
|
$message = '含有原市场专员与新市场专员相同数据,不可转换。';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!$status) {
|
|
|
|
$this->ajaxReturn([
|
|
|
|
'status' => 0,
|
|
|
|
'message' => $message
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
$hasRecord = M('market_shift', 'tab_')->where(['promote_id' => ['in', array_column($records, 'promote_id')], 'status' => 0])->find();
|
|
|
|
if ($hasRecord) {
|
|
|
|
$this->ajaxReturn([
|
|
|
|
'status' => 0,
|
|
|
|
'message' => '该会长含有未完成的市场换绑任务,请稍后再申请。'
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
$userAuth = session('user_auth');
|
|
|
|
foreach ($records as $record) {
|
|
|
|
$item = [
|
|
|
|
'promote_id' => $record['promote_id'],
|
|
|
|
'from_id' => $record['from_id'],
|
|
|
|
'to_id' => $record['to_id'],
|
|
|
|
'split_time' => strtotime($record['split_time']),
|
|
|
|
'remark' => $record['remark'],
|
|
|
|
'creator_id' => $userAuth['uid'],
|
|
|
|
'created_time' => time()
|
|
|
|
];
|
|
|
|
$id = M('market_shift', 'tab_')->add($item);
|
|
|
|
if ($id) {
|
|
|
|
Task::add('market-shift', ['market_shift_id' => $id]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->ajaxReturn([
|
|
|
|
'status' => 1,
|
|
|
|
'message' => '提交成功,等待后台处理'
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function delete()
|
|
|
|
{
|
|
|
|
$id = I('id', 0);
|
|
|
|
M('market_shift', 'tab_')->where(['id' => $id])->delete();
|
|
|
|
|
|
|
|
addOperationLog([
|
|
|
|
'op_type' => 2,
|
|
|
|
'key' => $id,
|
|
|
|
'op_name' => '删除市场换绑记录',
|
|
|
|
'url' => U('Market/delete', ['id' => $id]),
|
|
|
|
'menu' => '推广员-推广员管理-市场换绑-删除市场换绑记录'
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->ajaxReturn([
|
|
|
|
'status' => 1,
|
|
|
|
'message' => '删除成功'
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function cancel()
|
|
|
|
{
|
|
|
|
$id = I('id', 0);
|
|
|
|
$shift = M('market_shift', 'tab_')->where(['id' => $id])->find();
|
|
|
|
|
|
|
|
if ($shift['status'] != 0) {
|
|
|
|
$this->ajaxReturn([
|
|
|
|
'status' => 0,
|
|
|
|
'message' => '该换绑非待处理状态,不可取消'
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
addOperationLog([
|
|
|
|
'op_type' => 2,
|
|
|
|
'key' => $id,
|
|
|
|
'op_name' => '取消市场换绑记录',
|
|
|
|
'url' => U('Market/delete', ['id' => $id]),
|
|
|
|
'menu' => '推广员-推广员管理-市场换绑-取消市场换绑记录'
|
|
|
|
]);
|
|
|
|
|
|
|
|
M('market_shift', 'tab_')->where(['id' => $id])->save(['status' => 3]);
|
|
|
|
|
|
|
|
$this->ajaxReturn([
|
|
|
|
'status' => 1,
|
|
|
|
'message' => '取消成功'
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getPromotesByCompany()
|
|
|
|
{
|
|
|
|
$companyId = I('company_id', 0);
|
|
|
|
$promotes = M('promote', 'tab_')->field(['id', 'account', 'admin_id'])
|
|
|
|
->where(['level' => 1, 'company_id' => $companyId, 'admin_id' => ['gt', 0]])
|
|
|
|
->select();
|
|
|
|
|
|
|
|
$marketAdmins = index_by_column('id', getMarketAdmins());
|
|
|
|
|
|
|
|
$records = [];
|
|
|
|
foreach ($promotes as $promote) {
|
|
|
|
$admin = isset($marketAdmins[$promote['admin_id']]) ? $marketAdmins[$promote['admin_id']] : null;
|
|
|
|
$records[] = [
|
|
|
|
'id' => $promote['id'],
|
|
|
|
'account' => $promote['account'],
|
|
|
|
'admin_id' => $promote['admin_id'],
|
|
|
|
'admin_username' => $admin ? $admin['username'] : '',
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->ajaxReturn([
|
|
|
|
'status' => 1,
|
|
|
|
'message' => '获取成功',
|
|
|
|
'data' => [
|
|
|
|
'promotes' => $records
|
|
|
|
]
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|