Commit 80113065 authored by hujun's avatar hujun

应收佣金

parent 2e1ade74
......@@ -1689,6 +1689,8 @@ class Finance extends Basic
if ($result_data['status'] == 'successful') {
$data = $result_data['data'];
$should_where['confirm_date'] = ['between time', [ $operation_start_data, $operation_end_data]];
$should_where['confirm_status'] = 1;
foreach ($data as $k => $v) {
$commission_where['agent_id'] = $v['agent_id'];
$commission_data = $m_partial->sumCommission($commission_fields, $commission_where);
......@@ -1696,7 +1698,15 @@ class Finance extends Basic
$excel_data[$k]['operation_date'] = $operation_date; //成交日期
$excel_data[$k]['district_store'] = $v['district_store']; //所属部门/门店
$excel_data[$k]['name'] = $v['name'] . '-' . $v['phone']; //业务员
$excel_data[$k]['should_commission'] = $v['should_commission']; //应分佣金
$should_where['agent_id'] = $v['agent_id'];
if (empty($this->params['confirm_date'])) {
$should_where['confirm_date'] = ['between time', [ $operation_start_data, $operation_end_data ]];
} else {
$should_where['confirm_date'] = ['between time', [ $operation_start_data, $this->params['confirm_date'] . ' 23:59:59' ]];
}
$should_commission = $m_partial->sumFieldsGroup('should_commission', $should_where);
$excel_data[$k]['should_commission'] = $should_commission; //应分佣金
$excel_data[$k]['service_charge'] = $commission_data['service_charge']; //手续费
$excel_data[$k]['cash'] = $commission_data['cash']; //现金奖
$excel_data[$k]['charity_fund'] = $commission_data['charity_fund']; //慈善基金
......
......@@ -308,18 +308,18 @@ class OPartialCommission extends BaseModel
$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'];
//去除多次应分佣金
$should_commission = $this->where('confirm_date', 'between time', [ $operation_start_data, $operation_end_data ])
->where('agent_id', $v['agent_id'])
->where('confirm_status', 1)
->where('is_del', 0)
->group('bargain_id')
->column('should_commission');
$data[$k]['should_commission'] = 0;
foreach ($should_commission as $kk => $vv) {
$data[$k]['should_commission'] += $vv;
}
// //去除多次应分佣金
// $should_commission = $this->where('confirm_date', 'between time', [ $operation_start_data, $operation_end_data ])
// ->where('agent_id', $v['agent_id'])
// ->where('confirm_status', 1)
// ->where('is_del', 0)
// ->group('bargain_id')
// ->column('should_commission');
//
// $data[$k]['should_commission'] = 0;
// foreach ($should_commission as $kk => $vv) {
// $data[$k]['should_commission'] += $vv;
// }
}
}
......@@ -465,4 +465,26 @@ class OPartialCommission extends BaseModel
->where($where)
->find();
}
/**
* @param $fields
* @param $where
* @param string $group
* @return int
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function sumFieldsGroup($fields, $where, $group = 'bargain_id') {
$where['is_del'] = $num = 0;
$data = $this->field($fields)
->where($where)
->group($group)
->find();
foreach ($data as $k=>$v) {
$num += $v[$fields];
}
return $num;
}
}
\ No newline at end of file
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