Commit aaa6a7ca authored by hujun's avatar hujun

汇总表导出

parent 0ed1cc9f
......@@ -741,7 +741,7 @@ class Finance extends Basic
* @throws \think\exception\DbException
*/
public function getCommissionTotalList() {
if (!$this->request->isAjax()) {
if (!$this->request->isAjax() && $this->params['excel'] != 1) {
return view('commission_total');
}
......@@ -752,26 +752,22 @@ class Finance extends Basic
$pageNo = empty($this->params['pageNo']) ? 1 : $this->params['pageNo'];
$pageSize = empty($this->params['pageSize']) ? 15 : $this->params['pageSize'];
$fields = 'a.id,a.agent_id,sum(b.fee) as fee,sum(c.practical_fee) as practical_fee,sum(c.cash) as cash,';
$fields .= 'sum(c.service_charge) as service_charge,sum(b.fee) as fee,sum(c.real_fee) as real_fee,';
$fields .= 'd.name,d.phone';
$where['c.is_del'] = 0; //订单状态
$where['a.status'] = ['in', '10,11']; //10已提交 11审核成功
$where['b.father_id'] = ['<>', 0]; //去除税费总佣金
$where['c.confirm_status'] = 1; //确认分佣
// $where['a.status'] = ['in', '10,11']; //10已提交 11审核成功
// $where['b.father_id'] = ['<>', 0]; //去除税费总佣金
// $where['c.confirm_status'] = 1; //确认分佣
/**收佣日期 start**/
if(!empty($this->params['commission_start_date']) && empty($this->params['commission_end_date'])) {
$where['b.operation_date'] = ['> time', $this->params['commission_start_time']];
$where['b.operatiof.income_time'] = ['> time', $this->params['commission_start_time']];
}
if(!empty($this->params['commission_end_date']) && empty($this->params['commission_start_date'])) {
$where['b.operation_date'] = ['< time', $this->params['commission_end_time']];
$where['f.income_time'] = ['< time', $this->params['commission_end_time']];
}
if (!empty($this->params['commission_start_date']) && !empty($this->params['commission_end_date'])) {
$where['b.operation_date'] = ['between time', [$this->params['commission_start_date'], $this->params['commission_end_date']]];
$where['f.income_time'] = ['between time', [$this->params['commission_start_date'], $this->params['commission_end_date']]];
}
/**收佣日期 end**/
......@@ -791,25 +787,17 @@ class Finance extends Basic
/**开票日期 start**/
if (!empty($this->params['operation_start_date']) && empty($this->params['operation_end_date'])) {
$where_fee['operation_date'] = ['> time', $this->params['operation_start_date']];
$where_fee['b.operation_date'] = ['> time', $this->params['operation_start_date']];
}
if (!empty($this->params['operation_end_date']) && empty($this->params['operation_start_date'])) {
$where_fee['operation_date'] = ['> time', $this->params['operation_start_date']];
$where_fee['b.operation_date'] = ['> time', $this->params['operation_start_date']];
}
if (!empty($this->params['operation_start_date']) && !empty($this->params['operation_end_date'])) {
$where_fee['operation_date'] = ['between time', [$this->params['operation_start_date'] , $this->params['operation_end_date']]];
$where_fee['b.operation_date'] = ['between time', [$this->params['operation_start_date'] , $this->params['operation_end_date']]];
}
if (isset($where_fee['operation_date'])) {
// $m_fee = new OTaxes();
// $where_fee['type'] = 1;
// $bargain_id = $m_fee->getFeeListColumn('bargain_id', $where_fee);
// if (!empty($bargain_id)) {
// $whereOr['a.id'] = implode(',',$bargain_id);
// }
}
/**开票日期 end**/
/**经纪人手机号**/
......@@ -835,8 +823,54 @@ class Finance extends Basic
}
$m_bargain = new OBargainModel();
if (!empty($this->params['excel']) && $this->params['excel'] == 1) {
$fields = 'f.income_time,a.create_time,sum(b.fee) as fee,sum(f.money) as money,sum(c.cash) as cash,';
$fields .= 'sum(c.service_charge) as service_charge,';
$fields .= 'd.name,d.phone,sum(c.charity_fund) as charity_fund, sum(should_commission) as should_commission';
$pageSize = 25000;
$data = $m_bargain->getCommissionTotalList($pageNo, $pageSize, 'a.id desc', $fields, $where, $whereOr);
foreach ($data as $k => $v) {
$excel_data[$k]['income_time'] = $v['income_time']; //收佣日期
$excel_data[$k]['create_time'] = $v['create_time']; //成交日期
$excel_data[$k]['district_store'] = $v['district_store']; //所属部门/门店
$excel_data[$k]['name'] = $v['name'] .'-'.$v['phone']; //业务员
$excel_data[$k]['should_commission'] = $v['should_commission']; //应分佣金
$excel_data[$k]['service_charge'] = $v['service_charge']; //手续费
$excel_data[$k]['cash'] = $v['cash']; //现金奖
$excel_data[$k]['charity_fund'] = $v['charity_fund']; //慈善基金
$excel_data[$k]['money'] = $v['money']; //实收佣金
$excel_data[$k]['fee'] = $v['fee']; //税费
$excel_data[$k]['over_fee'] = $v['real_fee'] - $v['charity_fund'];
}
$num = count($excel_data) + 1;
$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, 11, '分佣提成汇总表', $title);
return ;
} else {
$fields = 'a.id,a.agent_id,sum(b.fee) as fee,sum(c.practical_fee) as practical_fee,sum(c.cash) as cash,';
$fields .= 'sum(c.service_charge) as service_charge,sum(b.fee) as fee,sum(c.real_fee) as real_fee,';
$fields .= 'd.name,d.phone';
$data['data']['list'] = $m_bargain->getCommissionTotalList($pageNo, $pageSize, 'a.id desc', $fields, $where, $whereOr);
$data['data']['total'] = $m_bargain->getCommissionTotalListTotal($where, $whereOr);
}
return $this->response($data['code'], $data['msg'], $data['data']);
}
......
......@@ -609,17 +609,19 @@ class OBargainModel extends Model
* @param string $order_
* @param string $field
* @param string $params
* @param $whereOr
* @return false|\PDOStatement|string|\think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getCommissionTotalList($pageNo = 1, $pageSize = 15, $order_ = 'a.id desc', $field = '', $params = '', $whereOr) {
public function getCommissionTotalList($pageNo = 1, $pageSize = 15, $order_ = 'a.id desc', $field = '', $params = '', $whereOr = []) {
$data = $this->alias('a')
->field($field)
->join('o_taxes b', 'a.id = b.bargain_id', 'left')
->join('o_partial_commission c', 'a.id = c.bargain_id', 'left')
->join('a_agents d', 'a.agent_id = d.id', 'left')
->join('o_real_income f', 'a.id = f.bargain_id', 'left')
->where($params)
->whereOr($whereOr)
->order($order_)
......@@ -646,16 +648,15 @@ class OBargainModel extends Model
* 分佣提成汇总表总数
*
* @param $params
* @return false|\PDOStatement|string|\think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
* @param array $whereOr
* @return int|string
*/
public function getCommissionTotalListTotal($params, $whereOr) {
public function getCommissionTotalListTotal($params, $whereOr = []) {
return $this->alias('a')
->join('o_taxes b', 'a.id = b.bargain_id', 'left')
->join('o_partial_commission c', 'a.id = c.bargain_id', 'left')
->join('a_agents d', 'a.agent_id = d.id', 'left')
->join('o_real_income f', 'a.id = f.bargain_id', 'left')
->where($params)
->whereOr($whereOr)
->group('d.id')
......
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