Commit 62289f0b authored by hujun's avatar hujun

财务汇总税费计算修改

parent 0da80820
......@@ -1017,45 +1017,56 @@ class Finance extends Basic
$pageSize = empty($this->params['pageSize']) ? 15 : $this->params['pageSize'];
$where['b.status'] = ['in', '10,11,13']; //10已提交 11审核成功
$where[] = ['EXP', '(c.father_id > 0 or c.father_id is NULL)']; //去除税费总佣金
$where['a.confirm_status'] = 1; //确认分佣
$income_date = $operation_date = '';
$operation_start_data = $operation_end_data = $income_date = $operation_date = '';
/**收佣日期 start**/
if (!empty($this->params['income_start_date']) && empty($this->params['income_end_date'])) {
$where[] = [ 'EXP', " f.income_time > {$this->params['income_start_date']} or c.operation_date > {$this->params['income_start_date']}"];
$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[] = [ 'EXP', " f.income_time < {$this->params['income_end_date']} or c.operation_date < {$this->params['income_start_date']}"];
$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[] = [ 'EXP', "(f.income_time > {$this->params['income_start_date']} and f.income_time < {$this->params['income_end_date']}) or
(c.operation_date > {$this->params['income_start_date']} or c.operation_date < {$this->params['income_end_date']})"];
$where[] = ['EXP', "(f.income_time BETWEEN '{$this->params['income_start_date']}' and '{$this->params['income_end_date']}')"];
$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**/
/**提交成交报告日期 start**/
if (!empty($this->params['bargain_start_date']) && empty($this->params['bargain_end_date'])) {
$where[] = [ 'EXP', "a.create_time > {$this->params['bargain_start_date']} . ' 00:00:00' or c.operation_date > {$this->params['bargain_start_date']}"];
$where[] = [ 'EXP', "a.create_time > {$this->params['bargain_start_date']} . ' 00:00:00' OR c.operation_date > {$this->params['bargain_start_date']}"];
$operation_date = date('Y.m.d', strtotime($this->params['bargain_start_date']));
$operation_start_data = $this->params['bargain_start_date'];
}
if (!empty($this->params['bargain_end_date']) && empty($this->params['bargain_start_date'])) {
$where[] = [ 'EXP', "a.create_time < {$this->params['bargain_end_date']} . ' 23:59:59' or c.operation_date < {$this->params['bargain_end_date']}"];
$where[] = [ 'EXP', "a.create_time < {$this->params['bargain_end_date']} . ' 23:59:59' OR c.operation_date < {$this->params['bargain_end_date']}"];
$operation_date = date('Y.m.d', strtotime($this->params['bargain_end_date']));
$operation_end_data = $this->params['bargain_end_date'];
}
if (!empty($this->params['bargain_start_date']) && !empty($this->params['bargain_end_date'])) {
$where[] = [ 'EXP', "(a.create_time > '{$this->params['bargain_start_date']} 00:00:00' and a.create_time < '{$this->params['bargain_end_date']} 23:59:59') or
(c.operation_date > {$this->params['bargain_start_date']} and c.operation_date < {$this->params['bargain_end_date']})"];
$where[] = ['EXP', "(a.create_time BETWEEN '{$this->params['income_start_date']}' and '{$this->params['income_end_date']}')"];
$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'];
}
/**部门id**/
......@@ -1081,9 +1092,9 @@ class Finance extends Basic
$m_bargain = new OPartialCommission();
if (empty($this->params['excel']) && $this->params['excel'] != 1) {
$fields = 'f.income_time,b.create_time,b.id,b.agent_id,sum(c.fee) as fee,sum(a.practical_fee) as practical_fee,sum(a.cash) as cash,';
$fields = 'f.income_time,b.create_time,b.id,b.agent_id,sum(a.practical_fee) as practical_fee,sum(a.cash) as cash,';
$fields .= 'sum(a.real_fee) as real_fee,d.name,d.phone';
$data['data']['list'] = $m_bargain->getCommissionTotalList($pageNo, $pageSize, 'a.id desc', $fields, $where, $whereOr);
$data['data']['list'] = $m_bargain->getCommissionTotalList($pageNo, $pageSize, 'a.id desc', $fields, $where, $operation_start_data, $operation_end_data);
foreach ($data['data']['list'] as $k=>$v) {
$data['data']['list'][$k]['income_date'] = $income_date;
......@@ -1091,17 +1102,17 @@ class Finance extends Basic
$data['data']['list'][$k]['over_fee'] = $v['practical_fee'] - $v['fee'];
}
$data['data']['total'] = $m_bargain->getCommissionTotalListTotal($where, $whereOr);
$data['data']['total'] = $m_bargain->getCommissionTotalListTotal($where);
} else {
//导出Excel
$fields = 'f.income_time,b.create_time,sum(c.fee) as fee,sum(f.money) as money,sum(a.cash) as cash,';
$fields = 'f.income_time,b.create_time,sum(f.money) as money,sum(a.cash) as cash,';
$fields .= 'sum(a.service_charge) as service_charge,a.agent_id,sum(a.practical_fee) as practical_fee,';
$fields .= 'd.name,d.phone,sum(a.charity_fund) as charity_fund, sum(a.should_commission) as should_commission';
$pageSize = 25000;
$data = $m_bargain->getCommissionTotalList($pageNo, $pageSize, 'a.id desc', $fields, $where, $whereOr);
$data = $m_bargain->getCommissionTotalList($pageNo, $pageSize, 'a.id desc', $fields, $where, $operation_start_data, $operation_end_data);
foreach ($data as $k => $v) {
$excel_data[$k]['income_date'] = $income_date; //收佣日期
......
......@@ -224,22 +224,21 @@ class OPartialCommission extends BaseModel
* @param string $order_
* @param string $field
* @param string $params
* @param $whereOr
* @param $operation_start_data
* @param $operation_end_data
* @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 = '', $operation_start_data, $operation_end_data)
{
$data = $this->alias('a')
->field($field)
->join('o_bargain b', 'a.bargain_id = b.id', 'left')
->join('o_taxes c', 'b.id = c.bargain_id', 'left')
->join('o_real_income f', 'b.id = f.bargain_id', 'left')
->join('a_agents d', 'a.agent_id = d.id', 'left')
->where($params)
->whereOr($whereOr)
->order($order_)
->limit($pageSize)
->page($pageNo)
......@@ -247,10 +246,16 @@ class OPartialCommission extends BaseModel
->select();
$m_agent = new AAgents();
$m_tax = new OTaxes();
foreach ($data as $k => $v) {
if (isset($v['agent_id'])) {
$district_store = $m_agent->getStoreDistrict('store_name,district_name', [ 'a.id' => $v['agent_id'] ]);
$data[$k]['district_store'] = $district_store['district_name'] . '-' . $district_store['store_name'];
//税费
$data[$k]['fee'] = $m_tax->where('operation_date', 'between time', [$operation_start_data, $operation_end_data])
->where('agent_id', $v['agent_id'])->sum('fee');
}
}
......@@ -259,18 +264,15 @@ class OPartialCommission extends BaseModel
/**
* @param $params
* @param array $whereOr
* @return int|string
*/
public function getCommissionTotalListTotal($params, $whereOr = [])
public function getCommissionTotalListTotal($params)
{
return $this->alias('a')
->join('o_bargain b', 'a.bargain_id = b.id', 'left')
->join('o_taxes c', 'b.id = c.bargain_id', 'left')
->join('o_real_income f', 'b.id = f.bargain_id', 'left')
->join('a_agents d', 'a.agent_id = d.id', 'left')
->where($params)
->whereOr($whereOr)
->group('a.agent_id')
->count();
}
......
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