diff --git a/Application/Admin/Controller/ConsoleController.class.php b/Application/Admin/Controller/ConsoleController.class.php
index 8be9a8ce8..3ccb27eaa 100644
--- a/Application/Admin/Controller/ConsoleController.class.php
+++ b/Application/Admin/Controller/ConsoleController.class.php
@@ -14,6 +14,7 @@ use Base\Task\Task;
use Base\Service\MarketService;
use Base\Tool\AggregateClient;
use Base\Repository\GameRepository;
+use Base\Service\PromoteCompanyService;
use Base\Tool\Redis;
use Think\Model;
@@ -861,4 +862,33 @@ class ConsoleController extends Think {
}
return $hash;
}
+
+ public function generateCompanyMonthlyData($month = '')
+ {
+ $service = new PromoteCompanyService();
+ $service->generateCompanyMonthlyData($month);
+ }
+
+ public function generateCompanyMontlyDatahDaily()
+ {
+ $d = date('j');
+ $month = date('Y-m');
+ if ($d <= 7) {
+ $lastMonth = date('Y-m', strtotime("$month -1 month"));
+ $service = new PromoteCompanyService();
+ $service->generateCompanyMonthlyData($lastMonth);
+ }
+ $service->generateCompanyMonthlyData($month);
+ }
+
+ public function initCompanyMontlyIsWarning()
+ {
+ $month = '2019-09';
+ $lastMonth = '2021-12';
+ do {
+ $service = new PromoteCompanyService();
+ $service->setCompanyMontlyIsWarning($month);
+ $month = date('Y-m', strtotime("$month +1 month"));
+ } while ($month <= $lastMonth);
+ }
}
diff --git a/Application/Admin/Controller/PromoteCompanyWarningController.class.php b/Application/Admin/Controller/PromoteCompanyWarningController.class.php
new file mode 100644
index 000000000..b52c5afe7
--- /dev/null
+++ b/Application/Admin/Controller/PromoteCompanyWarningController.class.php
@@ -0,0 +1,230 @@
+admininfo = $_SESSION['onethink_admin']['user_auth'];
+ parent::_initialize();
+ }
+
+ public function monthly()
+ {
+ $this->search('monthly');
+ }
+
+ public function total()
+ {
+ $this->search('total');
+ }
+
+ public function search($type)
+ {
+ $month = I('month', '');
+ $companyId = I('company_id', 0);
+ $isExport = I('is_export', 0);
+ $isSignContact = I('is_sign_contact', -1);
+ $where = [
+ '_string' => '1=1 and b.company_id is not null',
+ 'c.company_belong' => ['in', [1, 2]],
+ ];
+ if ($type == 'monthly') {
+ $where['b.is_warning'] = 1;
+ }
+ if ($companyId != 0) {
+ $where['b.company_id'] = $companyId;
+ }
+ if ($isSignContact != -1) {
+ $where['c.is_sign_contact'] = $isSignContact;
+ }
+ if ($month != '') {
+ $monthNumber = date('Ym', strtotime($month.'-01'));
+ $where['b.month'] = $monthNumber;
+ }
+
+ $joinDataTable = 'tab_company_monthly_data';
+ $columns = ['b.company_id', 'c.company_name', 'c.is_sign_contact', 'b.pay_amount'];
+ $orderBy = 'b.company_id asc';
+ if ($type == 'total') {
+ $subSql = M('company_monthly_data', 'tab_')->field('company_id')->where(['is_warning' => 1])->select(false);
+
+ $warningAmount = C('PRO_COM_TOTAL_AMOUNT', null, 100000);
+ $tmpTable = M('company_monthly_data', 'tab_')
+ ->field(['company_id', 'sum(pay_amount) pay_amount'])
+ ->where(['_string' => 'company_id not in(' . $subSql . ')'])
+ ->group('company_id')
+ ->having('pay_amount >= ' . $warningAmount)
+ ->select(false);
+ $joinDataTable = '(' . $tmpTable . ')';
+ } else {
+ $columns[] = 'b.month';
+ $orderBy = 'b.month desc, b.company_id asc';
+ }
+
+ $query = M('promote_company', 'tab_')->alias('c')
+ ->field($columns)
+ ->join('left join ' . $joinDataTable . ' b on b.company_id=c.id')
+ ->where($where)
+ ->order($orderBy);
+
+ $items = [];
+ $page = '';
+ if ($isExport) {
+ $items = $query->select();
+ } else {
+ [$items, $page, $count] = $this->paginate($query);
+ }
+
+ $companyPromotes = [];
+ $admins = [];
+ $adminDepartments = [];
+ if (count($items) > 0) {
+ $companyIds = array_column($items, 'company_id');
+ $promotes = M('promote', 'tab_')->field(['id', 'account', 'admin_id', 'company_id'])->where(['company_id' => ['in', $companyIds], 'level' => 1])->select();
+ $adminIds = array_column($promotes, 'admin_id');
+ $admins = M('member', 'sys_')->field(['uid', 'real_name'])->where(['uid' => ['in', $adminIds]])->select();
+ $adminDepartments = getAdminDepartmentList($adminIds);
+ $admins = index_by_column('uid', $admins);
+
+ foreach ($promotes as $promote) {
+ $companyPromotes[$promote['company_id']][] = $promote;
+ }
+ }
+
+ $records = [];
+ foreach ($items as $key => $item) {
+ $item['month'] = date('Y-m', strtotime($item['month'].'01'));
+ $item['is_sign_contact_text'] = $item['is_sign_contact'] == 1 ? '是' : '否';
+ $itemPromotes = $companyPromotes[$item['company_id']];
+ $promoteCount = count($itemPromotes);
+ $index = 0;
+ foreach ($itemPromotes as $promote) {
+ if ($index == 0) {
+ $item['rowspan'] = $promoteCount;
+ } else {
+ $item['rowspan'] = 0;
+ }
+ $item['market_department_name'] = $adminDepartments[$promote['admin_id']] ?? '无';
+ $admin = $admins[$promote['admin_id']] ?? null;
+ $item['market_user_name'] = $admin ? $admin['real_name'] : '无';
+ $item['account'] = $promote['account'];
+ $index ++;
+ $records[] = $item;
+ }
+ }
+
+ $records = [];
+ foreach ($items as $key => $item) {
+ if (isset($item['month'])) {
+ $item['month'] = date('Y-m', strtotime($item['month'].'01'));
+ }
+ $item['is_sign_contact_text'] = $item['is_sign_contact'] == 1 ? '是' : '否';
+ $itemPromotes = $companyPromotes[$item['company_id']];
+ $promoteCount = count($itemPromotes);
+ $index = 0;
+ foreach ($itemPromotes as $promote) {
+ if ($index == 0) {
+ $item['rowspan'] = $promoteCount;
+ } else {
+ $item['rowspan'] = 0;
+ }
+ $item['market_department_name'] = $adminDepartments[$promote['admin_id']] ?? '无';
+ $admin = $admins[$promote['admin_id']] ?? null;
+ $item['market_user_name'] = $admin ? $admin['real_name'] : '无';
+ $item['account'] = $promote['account'];
+ $index ++;
+ $records[] = $item;
+ }
+ }
+
+ $pageTypeNames = [
+ 'monthly' => '合同签订当月流水预警',
+ 'total' => '合同签订累计流水预警',
+ ];
+ $pageTypeName = $pageTypeNames[$type];
+
+ $this->assign('records', $records);
+ $this->assign('pageType', $type);
+ $this->assign('pageTypeName', $pageTypeName);
+
+ if($isExport){
+ addOperationLog(['op_type'=>3,'key'=>getNowDate(),'op_name'=>'导出推广公司','url'=>U('PromoteCompany/lists'),'menu'=>'推广员-公司档案管理-' . $pageTypeName]);
+ $this->display("export");
+ return;
+ }
+
+ if($page) {
+ $this->assign('_page', $page);
+ }
+
+ $totalWarningAmount = C('PRO_COM_TOTAL_AMOUNT', null, 100000);
+ $monthlyWarningAmount = C('PRO_COM_MONTHLY_AMOUNT', null, 50000);
+
+ $this->assign('totalWarningAmount', $totalWarningAmount);
+ $this->assign('monthlyWarningAmount', $monthlyWarningAmount);
+
+ $companies = M('promote_company', 'tab_')->field(['company_name', 'id'])->where(['company_belong' => ['in', [1, 2]]])->select();
+ $this->assign('companies', $companies);
+ $this->display('records');
+ }
+
+ public function saveSetting()
+ {
+ $monthlyAmount = I('monthly_amount', 0);
+ $totalAmount = I('total_amount', 0);
+ $beforeTotalAmount = C('PRO_COM_TOTAL_AMOUNT');
+ $beforeMonthlyAmount = C('PRO_COM_MONTHLY_AMOUNT');
+
+ if (!is_numeric($monthlyAmount)) {
+ $this->ajaxReturn([
+ 'status' => 0,
+ 'message' => '月达标金额格式错误'
+ ]);
+ }
+
+ if (!is_numeric($totalAmount)) {
+ $this->ajaxReturn([
+ 'status' => 0,
+ 'message' => '累计达标金额格式错误'
+ ]);
+ }
+
+ if ($monthlyAmount < 0) {
+ $this->ajaxReturn([
+ 'status' => 0,
+ 'message' => '月达标金额需大于0'
+ ]);
+ }
+
+ if ($totalAmount < 0) {
+ $this->ajaxReturn([
+ 'status' => 0,
+ 'message' => '累计达标金额需大于0'
+ ]);
+ }
+
+ if ($monthlyAmount != $beforeMonthlyAmount) {
+ M('config', 'sys_')->where(['name' => 'PRO_COM_MONTHLY_AMOUNT'])->save(['value' => $monthlyAmount]);
+ S('DB_CONFIG_DATA', null);
+ $service = new PromoteCompanyService();
+ $month = date('Y-m');
+ $service->setCompanyMontlyIsWarning($month);
+ }
+
+ if ($totalAmount != $beforeTotalAmount) {
+ M('config', 'sys_')->where(['name' => 'PRO_COM_TOTAL_AMOUNT'])->save(['value' => $totalAmount]);
+ S('DB_CONFIG_DATA', null);
+ }
+
+ $this->ajaxReturn([
+ 'status' => 1,
+ 'message' => '操作成功'
+ ]);
+ }
+}
diff --git a/Application/Admin/View/PromoteCompanyWarning/export.html b/Application/Admin/View/PromoteCompanyWarning/export.html
new file mode 100644
index 000000000..6ebba3678
--- /dev/null
+++ b/Application/Admin/View/PromoteCompanyWarning/export.html
@@ -0,0 +1,102 @@
+
+
+
+
+
+
+ 游戏登陆列表|----软件管理平台
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 导出进行中。。。
+ 如果导出成功你也可以手动关闭此页面
+
+
+
+
+
+ 合作方名称 |
+ 流水金额 |
+
+ 达标月份 |
+
+ 会长账号 |
+ 市场专员 |
+ 所属市场部 |
+ 是否签约 |
+
+
+
+
+
+
+ aOh! 暂时还没有内容! |
+
+
+ 0):?>class="new_row">
+ 0):?>
+ {$data.company_name} |
+ {$data.pay_amount} |
+
+ {$data.month} |
+
+
+ {$data.account} |
+ {$data.market_user_name} |
+ {$data.market_department_name} |
+ 0):?>
+ {$data.is_sign_contact_text} |
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Application/Admin/View/PromoteCompanyWarning/records.html b/Application/Admin/View/PromoteCompanyWarning/records.html
new file mode 100644
index 000000000..451f7e52c
--- /dev/null
+++ b/Application/Admin/View/PromoteCompanyWarning/records.html
@@ -0,0 +1,314 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
{$pageTypeName}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 合作方名称 |
+ 流水金额 |
+
+ 达标月份 |
+
+ 会长账号 |
+ 市场专员 |
+ 所属市场部 |
+ 是否签约 |
+
+
+
+
+
+
+ aOh! 暂时还没有内容! |
+
+
+ 0):?>class="new_row">
+ 0):?>
+ {$data.company_name} |
+ {$data.pay_amount} |
+
+ {$data.month} |
+
+
+ {$data.account} |
+ {$data.market_user_name} |
+ {$data.market_department_name} |
+ 0):?>
+ {$data.is_sign_contact_text} |
+
+
+
+
+
+
+
+
+
+
+ {$_page|default=''}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Application/Base/Service/PromoteCompanyService.class.php b/Application/Base/Service/PromoteCompanyService.class.php
index e4b46b431..5b57a75be 100644
--- a/Application/Base/Service/PromoteCompanyService.class.php
+++ b/Application/Base/Service/PromoteCompanyService.class.php
@@ -321,4 +321,66 @@ class PromoteCompanyService
addOperationLog(['op_type'=>1, 'key'=> $application['id'], "op_name"=>"市场部审核", 'url'=>U('index')]);
return $application;
}
+
+ public function statCompanyMonthlyAmount($month = null)
+ {
+ $conditions = ['pay_status' => 1];
+ if ($month) {
+ $firstDay = $month . '-01';
+ $lastDay = date('Y-m-d', strtotime("$month +1 month -1 day"));
+ $conditions['pay_time'] = ['between', [strtotime($firstDay . ' 00:00:00'), strtotime($lastDay . ' 23:59:59')]];
+ }
+ return M('spend', 'tab_')
+ ->field(['IFNULL(company_id, 0) company_id', 'sum(pay_amount) pay_amount', 'FROM_UNIXTIME(pay_time, "%Y%m") month'])
+ ->join('left join tab_promote on tab_spend.promote_id=tab_promote.id')
+ ->where($conditions)
+ ->group('company_id, month')
+ ->order('month asc, company_id asc')
+ ->select();
+
+ }
+
+ public function generateCompanyMonthlyData($month = null)
+ {
+ $records = $this->statCompanyMonthlyAmount($month);
+ if ($month) {
+ $monthNumber = date('Ym', strtotime($month.'-01'));
+ $monthData = M('company_monthly_data', 'tab_')->field(['concat(month, "_", company_id) unique_key'])->where(['month' => $monthNumber])->select();
+ if (count($monthData) > 0) {
+ $monthRows = [];
+ foreach ($monthData as $item) {
+ $monthRows[$item['unique_key']] = true;
+ }
+ foreach ($records as $index => $item) {
+ $uniqueKey = $item['month'] . '_' . $item['company_id'];
+ if (isset($monthRows[$uniqueKey])) {
+ unset($records[$index]);
+ M('company_monthly_data', 'tab_')->where(['month' => $item['month'], 'company_id' => $item['company_id']])->save($item);
+ }
+ }
+ $records = array_values($records);
+ }
+ }
+ if (count($records) > 0) {
+ M('company_monthly_data', 'tab_')->addAll($records);
+ }
+ }
+
+ public function setCompanyMontlyIsWarning($month)
+ {
+ $monthNumber = date('Ym', strtotime($month.'-01'));
+
+ $conditions = ['_string' => '1=1'];
+ $conditions['month'] = $monthNumber;
+ $conditions['pay_amount'] = ['egt', C('PRO_COM_MONTHLY_AMOUNT', null, 50000)];
+
+ $subSql = M('company_monthly_data', 'tab_')->field('company_id')->where(['month' => ['lt', $monthNumber], 'is_warning' => 1])->select(false);
+ $conditions['_string'] .= ' and company_id not in(' . $subSql . ')';
+
+ M('company_monthly_data', 'tab_')->where(['month' => $monthNumber])->save(['is_warning' => 0]);
+ $rows = M('company_monthly_data', 'tab_')->field(['id'])->where($conditions)->select();
+ if (count($rows) > 0) {
+ M('company_monthly_data', 'tab_')->where(['id' => ['in', array_column($rows, 'id')]])->save(['is_warning' => 1]);
+ }
+ }
}
\ No newline at end of file