Commit 126d7495 authored by hujun's avatar hujun

实收汇总-办公楼

parent 279ac77f
...@@ -1952,7 +1952,6 @@ class Finance extends Basic ...@@ -1952,7 +1952,6 @@ class Finance extends Basic
} }
$m_partial = new OPartialCommission(); $m_partial = new OPartialCommission();
$m_store = new AStore(); $m_store = new AStore();
$m_agent = new AAgents();
$m_tax = new OTaxes(); $m_tax = new OTaxes();
$data['code'] = 200; $data['code'] = 200;
...@@ -2147,7 +2146,7 @@ class Finance extends Basic ...@@ -2147,7 +2146,7 @@ class Finance extends Basic
$export = new ExportExcelUntil(); $export = new ExportExcelUntil();
$title = ['收佣日期/开票日期', '成交日期/开票日期', '所属部门/门店', '业务员', '应分佣金(元)', '手续费(元)', '现金奖(元)', '慈善基金(元)', '实收佣金(元)', '税费(元)', '最终实收(元)']; $title = ['收佣日期/开票日期', '成交日期/开票日期', '所属部门/门店', '业务员', '应分佣金(元)', '手续费(元)', '现金奖(元)', '慈善基金(元)', '实收佣金(元)', '税费(元)', '最终实收(元)'];
$export->exportTable('分佣提成汇总表', $excel_data, 10, '分佣提成汇总表', $title); $export->exportTable('实收汇总表-商铺', $excel_data, 10, '实收汇总表-商铺', $title);
} }
return $this->response($data['code'], $data['msg'], $data['data']); return $this->response($data['code'], $data['msg'], $data['data']);
......
...@@ -12,6 +12,7 @@ use app\api_broker\service\OfficeOrderLogService; ...@@ -12,6 +12,7 @@ use app\api_broker\service\OfficeOrderLogService;
use app\index\extend\Basic; use app\index\extend\Basic;
use app\index\untils\ExportExcelUntil; use app\index\untils\ExportExcelUntil;
use app\model\AAgents; use app\model\AAgents;
use app\model\AStore;
use app\model\OfficeOPartialCommission; use app\model\OfficeOPartialCommission;
use app\model\OfficeORealIncome; use app\model\OfficeORealIncome;
use app\model\OfficeOTaxes; use app\model\OfficeOTaxes;
...@@ -332,4 +333,219 @@ class OfficeFinance extends Basic ...@@ -332,4 +333,219 @@ class OfficeFinance extends Basic
$export->exportTable('实收明细表', $result, 12, '实收明细表', $title); $export->exportTable('实收明细表', $result, 12, '实收明细表', $title);
return ''; return '';
} }
/**
* 分佣提成汇总表
*
* @return \think\Response|\think\response\View
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getCommissionTotalList()
{
if (!$this->request->isAjax() && $this->params['excel'] != 1) {
return view('commission_total');
}
$m_partial = new OfficeOPartialCommission();
$m_store = new AStore();
$m_tax = new OfficeOTaxes();
$data['code'] = 200;
$data['msg'] = "";
$data['data'] = $excel_data = [];
$pageSize = empty($this->params['pageSize']) ? 10 : $this->params['pageSize'];
$pageNo = empty($this->params['pageNo']) ? 1 : $this->params['pageNo'];
$operation_start_data = $operation_end_data = $income_date = $operation_date = '';
$where['a.confirm_status'] = 1;
$is_bargain = 0;
/**收佣日期 start**/
$sql_string = 'or a.agent_id in (SELECT agent_id FROM o_taxes WHERE is_del=0 and father_id > 0 and operation_date';
if (!empty($this->params['income_start_date']) && empty($this->params['income_end_date'])) {
$where[0] = ['EXP', "b.income_time > '{$this->params['income_start_date']}' {$sql_string} > '{$this->params['income_start_date']}' GROUP BY agent_id)"];
$income_date = date('Y.m.d', strtotime($this->params['income_start_date']));
$operation_start_data = $this->params['income_start_date'];
}
if (!empty($this->params['income_end_date']) && empty($this->params['income_start_date'])) {
$where[0] = ['EXP', "b.income_time < '{$this->params['income_end_date']}' {$sql_string} > '{$this->params['income_end_date']}' GROUP BY agent_id)"];
$income_date = '-' . date('Y.m.d', strtotime($this->params['income_end_date']));
$operation_end_data = $this->params['income_end_date'];
}
if (!empty($this->params['income_start_date']) && !empty($this->params['income_end_date'])) {
$where[0] =['EXP', "b.income_time BETWEEN '{$this->params['income_start_date']}' AND '{$this->params['income_end_date']}' {$sql_string} BETWEEN '{$this->params['income_start_date']}' AND '{$this->params['income_end_date']}' GROUP BY agent_id)"];
$income_date = date('Y.m.d', strtotime($this->params['income_start_date'])) . '-' . date('Y.m.d', strtotime($this->params['income_end_date']));
$operation_start_data = $this->params['income_start_date'];
$operation_end_data = $this->params['income_end_date'];
}
/**收佣日期 end**/
if (!empty($this->params['bargain_start_date']) && empty($this->params['bargain_end_date'])) {
$where[1] = ['EXP', "e.create_time > '{$this->params['bargain_start_date']} 00:00:00' {$sql_string} > '{$this->params['bargain_start_date']}' GROUP BY agent_id)"];
$operation_date = date('Y.m.d', strtotime($this->params['bargain_start_date']));
$operation_start_data = $this->params['bargain_start_date'];
$is_bargain = 1;
}
if (!empty($this->params['bargain_end_date']) && empty($this->params['bargain_start_date'])) {
$where[1] = ['EXP', "e.create_time < '{$this->params['bargain_end_date']} 23:59:59' {$sql_string} > '{$this->params['bargain_end_date']}' GROUP BY agent_id)"];
$operation_date = date('Y.m.d', strtotime($this->params['bargain_end_date']));
$operation_end_data = $this->params['bargain_end_date'];
$is_bargain = 1;
}
if (!empty($this->params['bargain_start_date']) && !empty($this->params['bargain_end_date'])) {
$where[1] =['EXP', "e.create_time BETWEEN '{$this->params['bargain_start_date']} 00:00:00' AND '{$this->params['bargain_end_date']} 23:59:59' {$sql_string} BETWEEN '{$this->params['bargain_start_date']}' AND '{$this->params['bargain_end_date']}' GROUP BY agent_id)"];
$operation_date = date('Y.m.d', strtotime($this->params['bargain_start_date'])) . '-' . date('Y.m.d', strtotime($this->params['bargain_end_date']));
$operation_start_data = $this->params['bargain_start_date'];
$operation_end_data = $this->params['bargain_end_date'];
$is_bargain = 1;
}
/**部门id**/
if (!empty($this->params['district_id'])) {
$taxes_where['c.district_id'] = $where['d.district_id'] = $this->params['district_id'];
}
/**门店名**/
if (!empty($this->params['store_id'])) {
$taxes_where['c.store_id'] = $where['d.store_id'] = $this->params['store_id'];
}
/**经纪人手机号**/
if (!empty($this->params['agent_id'])) {
$taxes_where['b.agent_id'] = $where['a.agent_id'] = $this->params['agent_id'];
}
$partial_fields = 'sum( a.practical_fee ) as practical_fee,sum( a.real_fee ) as real_fee,sum(a.cash) as cash,';
$partial_fields .= 'sum( a.service_charge ) as service_charge,sum( a.charity_fund ) as charity_fund';
$fields = 'a.agent_id,d.name,d.store_id,e.status';
$partial_where['b.status'] = ['IN', '10,11,13'];
$partial_where['a.is_del'] = $taxes_where['is_del'] = 0;
$taxes_where['a.father_id'] = ['>', 0];
$taxes_where['a.operation_date'] = ['between', [$operation_start_data, $operation_end_data]];
if (empty($this->params['excel']) && $this->params['excel'] != 1) {
$taxes_where['a.father_id'] = ['>', 0];
$taxes_where['a.is_del'] = 0;
$taxes_where['a.operation_date'] = ['between', [$operation_start_data, $operation_end_data]];
$data['data']['total_taxes'] = $m_tax->sumBargainFee('a.fee', $taxes_where);;
if (!empty($this->params['confirm_date'])) {
$partial_where['a.confirm_date'] = $where['a.confirm_date'] = ['<=', $this->params['confirm_date'].' 23:59:59'];
$partial_where['a.confirm_status'] = 1;
}
$list = $m_partial->getCommissionTotalList($pageNo, $pageSize, $fields, $where, $operation_start_data, $operation_end_data, $is_bargain);
foreach ($list as $k => $v) {
if (in_array($v['status'], [10,11,13])) {
$partial_where['a.agent_id'] =$v['agent_id'];
if ($is_bargain != 1) {
$partial_where['c.income_time'] = ['between', [$operation_start_data, $operation_end_data]];
} else {
$partial_where['b.create_time'] = ['between', [$operation_start_data, $operation_end_data]];
}
$partial_data = $m_partial->getSumMoney($partial_fields, $partial_where);
$list[$k]['service_charge'] = empty($partial_data['service_charge'])? 0:$partial_data['service_charge']; //手续费
$list[$k]['cash'] = empty($partial_data['cash']) ? 0:$partial_data['cash']; //现金奖
$list[$k]['charity_fund'] = empty($partial_data['charity_fund']) ? 0 : $partial_data['charity_fund']; //慈善基金
$list[$k]['practical_fee'] = empty($partial_data['practical_fee']) ? 0:$partial_data['practical_fee']; //实收佣金
} else {
$list[$k]['practical_fee'] = 0;
$list[$k]['real_fee'] = 0;
$list[$k]['service_charge'] = 0;
$list[$k]['charity_fund'] = 0;
}
$taxes_where['a.agent_id'] = $v['agent_id'];
$list[$k]['fee'] = $m_tax->sumBargainFee('a.fee', $taxes_where);
$list[$k]['income_date'] = $income_date;
$list[$k]['operation_date'] = $operation_date;
$list[$k]['district_store'] = $m_store->getStoreDistrictName($v['store_id']);
$list[$k]['name'] = $v['name'];
}
$data['data']['list'] = $list;
$data['data']['total'] = $m_partial->getCommissionTotalListTotal($where);
if (isset($where[0])) {
$where[0] = ['EXP',"b.income_time BETWEEN '{$this->params['income_start_date']}' AND '{$this->params['income_end_date']}'"];
}
if (isset($where[1])){
$where[1] =['EXP', "e.create_time BETWEEN '{$this->params['bargain_start_date']} 00:00:00' AND '{$this->params['bargain_end_date']} 23:59:59'"];
}
$where['e.status'] = ['IN', '10,11,13'];
unset($where['c.is_del']);
$data['data']['total_money'] = $m_partial->getCommissionTotalInfo('a.practical_fee', $where);
} else {
//导出Excel
$pageSize = 25000;
$partial_fields .= ',sum(a.should_commission) as should_commission,sum(a.cash) as cash';
if (!empty($this->params['confirm_date'])) {
$partial_where['a.confirm_date'] = $where['a.confirm_date'] = ['<=', $this->params['confirm_date'].' 23:59:59'];
$partial_where['a.confirm_status'] = 1;
}
$result_data = $m_partial->getCommissionTotalList($pageNo, $pageSize, $fields, $where, $operation_start_data, $operation_end_data, $is_bargain);
$partial_where['b.status'] = ['IN', '10,11,13'];
$partial_where['a.is_del'] = $taxes_where['is_del'] = 0;
if ($is_bargain != 1) {
$partial_where['c.income_time'] = ['between', [$operation_start_data, $operation_end_data]];
} else {
$partial_where['b.create_time'] = ['between', [$operation_start_data, $operation_end_data]];
}
foreach ($result_data as $k => $v) {
$excel_data[$k]['income_date'] = $income_date; //收佣日期
$excel_data[$k]['operation_date'] = $operation_date; //成交日期
$excel_data[$k]['district_store'] = $m_store->getStoreDistrictName($v['store_id']);; //所属部门/门店
$excel_data[$k]['name'] = $v['name']; //业务员
$partial_where['a.agent_id'] =$v['agent_id'];
$partial_data = $m_partial->getSumMoney($partial_fields, $partial_where);
$excel_data[$k]['should_commission'] = empty($partial_data['should_commission']) ? 0:$partial_data['should_commission']; //应分佣金
$excel_data[$k]['service_charge'] = empty($partial_data['service_charge'])? 0:$partial_data['service_charge']; //手续费
$excel_data[$k]['cash'] = empty($partial_data['cash']) ? 0:$partial_data['cash']; //现金奖
$excel_data[$k]['charity_fund'] = empty($partial_data['charity_fund']) ? 0 : $partial_data['charity_fund']; //慈善基金
$excel_data[$k]['practical_fee'] = empty($partial_data['practical_fee']) ? 0:$partial_data['practical_fee']; //实收佣金
//税费
$taxes_where['a.agent_id'] = $v['agent_id'];
$excel_data[$k]['fee'] = $m_tax->sumBargainFee('a.fee', $taxes_where);
$excel_data[$k]['over_fee'] = $partial_data['practical_fee'] - $excel_data[$k]['fee'];
}
$num = count($excel_data) + 2;
$excel_data[$num]['income_time'] = '合计'; //收佣日期
$excel_data[$num]['create_time'] = ''; //成交日期
$excel_data[$num]['district_store'] = ''; //所属部门/门店
$excel_data[$num]['name'] = ''; //业务员
$excel_data[$num]['should_commission'] = "=SUM(E3:E{$num})"; //应分佣金
$excel_data[$num]['service_charge'] = "=SUM(F3:F{$num})"; //手续费
$excel_data[$num]['cash'] = "=SUM(G3:G{$num})"; //现金奖
$excel_data[$num]['charity_fund'] = "=SUM(H3:H{$num})"; //慈善基金
$excel_data[$num]['money'] = "=SUM(I3:I{$num})"; //实收佣金
$excel_data[$num]['fee'] = "=SUM(J3:J{$num})"; //税费
$excel_data[$num]['over_fee'] = "=SUM(K3:K{$num})";
$export = new ExportExcelUntil();
$title = ['收佣日期/开票日期', '成交日期/开票日期', '所属部门/门店', '业务员', '应分佣金(元)', '手续费(元)', '现金奖(元)', '慈善基金(元)', '实收佣金(元)', '税费(元)', '最终实收(元)'];
$export->exportTable('实收汇总表-办公楼', $excel_data, 10, '实收汇总表-办公楼', $title);
}
return $this->response($data['code'], $data['msg'], $data['data']);
}
} }
...@@ -1216,7 +1216,7 @@ Route::group('office_index', [ ...@@ -1216,7 +1216,7 @@ Route::group('office_index', [
'getTallAgeList' => ['index/OfficeFinance/getTallAgeList', ['method' => 'GET']], //税费承担明细表 'getTallAgeList' => ['index/OfficeFinance/getTallAgeList', ['method' => 'GET']], //税费承担明细表
'selectReportAll' => ['index/OfficeFinance/selectReportAll', ['method' => 'GET']], //时间轴 'selectReportAll' => ['index/OfficeFinance/selectReportAll', ['method' => 'GET']], //时间轴
'exportExcel' => ['index/OfficeFinance/exportExcel', ['method' => 'get']], //导出分佣 'exportExcel' => ['index/OfficeFinance/exportExcel', ['method' => 'get']], //导出分佣
'getCommissionTotalList' => ['index/OfficeFinance/getCommissionTotalList', ['method' => 'GET']], //分佣提成汇总表
'performanceInfo' => ['index/OfficePerformanceInfo/performanceInfo', ['method' => 'GET|POST']],//业绩明细办公楼 'performanceInfo' => ['index/OfficePerformanceInfo/performanceInfo', ['method' => 'GET|POST']],//业绩明细办公楼
'selectDistrictPerformance' => ['index/OfficePerformance/selectDistrictPerformance', ['method' => 'GET|POST']],//区域业绩排行 'selectDistrictPerformance' => ['index/OfficePerformance/selectDistrictPerformance', ['method' => 'GET|POST']],//区域业绩排行
'selectStorePerformance' => ['index/OfficePerformance/selectStorePerformance', ['method' => 'GET|POST']],//门店排行 'selectStorePerformance' => ['index/OfficePerformance/selectStorePerformance', ['method' => 'GET|POST']],//门店排行
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment