Commit 7b15f999 authored by hujun's avatar hujun

佣金统计

parent 5b30726d
...@@ -3115,7 +3115,7 @@ class Finance extends Basic ...@@ -3115,7 +3115,7 @@ class Finance extends Basic
} }
if ($this->params['status'] > -1) { if ($this->params['status'] > -1) {
$where['agent_id'] = $this->params['agent_id']; $where['status'] = $this->params['status'] == 2 ? 2 : ['in', '0,1'];
} }
$m_daily = new ODaily(); $m_daily = new ODaily();
...@@ -3241,7 +3241,84 @@ class Finance extends Basic ...@@ -3241,7 +3241,84 @@ class Finance extends Basic
return $this->response($code, '', $result); return $this->response($code, '', $result);
} }
public function sumPrice() { /**
* 佣金统计
*
* @return \think\Response
*/
public function getPayLogTotalPrice() {
//付款类型 10意向金 20定金 30保管金 40押金 50 租金 60 进场费 70转让费 80其他 90佣金 91中介费 92 案场费
//调整类型 意向金:1转中介费 2转案场费 3转意向金 保管金:4转中介费 5转案场费 6转保管金
$agent_fee = $this->sumPayLogBargainByType(91, 0);//未开业中介费
$case_fee = $this->sumPayLogBargainByType(92, 0);//未开业案场费
$data['not_open_commission'] = $agent_fee + $case_fee; //中介费入账
$open_agent_fee = $this->sumPayLogBargainByType(91, 1);//开业中介费
$open_case_fee = $this->sumPayLogBargainByType(92, 1);//开业案场费
$data['open_commission'] = $open_agent_fee + $open_case_fee; //案场费入账
//佣金总计:中介费入账+案场费入账-中介费退款-案场费退款
$data['total_commission'] = $data['not_open_commission'] + $data['open_commission'];
$data['intention_recorded'] = $this->sumPayLogPriceByType(10, 0);//意向金入账
$agent_fee = $this->sumPayLogPriceByType(1, 1);//意向金转中介费
$case_fee = $this->sumPayLogPriceByType(2, 1);//意向金转案场费
$intention_fee = $this->sumPayLogPriceByType(3, 1);//意向金转意向金
//意向金转意向金+意向金转中介费+意向金转案场费
$data['intention_adjustment'] = $agent_fee + $case_fee + $intention_fee;//意向金调整
$data['intention_refund'] = 0;//意向金退款
//意向金入账-意向金调整-意向金退款
$data['total_intention_recorded'] = $data['intention_recorded'] - $data['intention_adjustment'] - $data['intention_refund']; //账上意向金
$data['custody_recorded'] = $this->sumPayLogPriceByType(30, 0);//保管金入账
$agent_fee = $this->sumPayLogPriceByType(4, 1);//保管金转中介费
$case_fee = $this->sumPayLogPriceByType(5, 1);//保管金转案场费
$custody_fee = $this->sumPayLogPriceByType(6, 1);//保管金转保管金
//保管金调整:保管金转保管金+保管金转中介费+保管金转案场费
$data['custody_adjustment'] = $agent_fee + $case_fee + $custody_fee;//保管金调整
$data['custody_refund '] = 0;//保管金转定
//意向金入账-意向金调整-意向金退款
$data['total_custody_recorded'] = $data['custody_recorded'] - $data['custody_adjustment'] - $data['custody_refund']; //账上保管金
//待处理款项总计:未开业佣金+账上意向金+账上保管金
$data['wait_total_fee'] = $data['not_open_commission'] + $data['intention_recorded'] + $data['custody_recorded'];
return $this->response( 200, '', $data);
}
/**
* @param $type
* @param int $is_open
* @return float|int|string
*/
private function sumPayLogBargainByType($type, $is_open = 0) {
$m_pay = new OPayLogModel();
if ($is_open) {
$where['b.is_open'] = $is_open;
}
$where['a.type'] = $type;
$price = $m_pay->sumBargainPrice('a.money', $where); //未开业中介费
return empty($price) ? '' : $price;
}
/**
* @param int $type
* @param int $is_adjustment 0调整前 1调整后
* @return float|int|string
*/
private function sumPayLogPriceByType(int $type, int $is_adjustment = 0) {
$m_pay = new OPayLogModel();
if ($is_adjustment) {
$where['b.type'] = $type;
$where['source'] = 2;
$price = $m_pay->sumAdjustment('b.money', $where, $is_adjustment);
} else {
$where['a.type'] = $type;
$price = $m_pay->sumAdjustment('a.money', $where, $is_adjustment);
}
return empty($price) ? '' : $price;
} }
} }
...@@ -545,4 +545,38 @@ class OPayLogModel extends Model ...@@ -545,4 +545,38 @@ class OPayLogModel extends Model
->where($where) ->where($where)
->select(); ->select();
} }
/**
* @param $field
* @param $where
* @return float|int
*/
public function sumBargainPrice($field, $where) {
return $this->db_->alias('a')
->join('o_bargain b','a.id=b.order_id')
->where($where)
->sum($field);
}
/**
* @param string $field
* @param array $where
* @param int $type 1 调整前 0调整后
* @return float|int|string
*/
public function sumAdjustment(string $field, array $where, int $type = 1) {
if ($type) {
$field = $this->db_->alias('a')
->join('o_paylog_adjustment b','a.id=b.paylog_id')
->where($where)
->sum($field);
} else {
$field = $this->db_->alias('a')
->join('o_paylog_adjustment b','a.id=b.new_paylog_id')
->where($where)
->sum($field);
}
return $field;
}
} }
\ No newline at end of file
...@@ -280,6 +280,7 @@ Route::group('index', [ ...@@ -280,6 +280,7 @@ Route::group('index', [
'getAdjustment' => ['index/Finance/getAdjustment', ['method' => 'get']],//剩余可以调整或退款的钱 'getAdjustment' => ['index/Finance/getAdjustment', ['method' => 'get']],//剩余可以调整或退款的钱
'delAdjustment' => ['index/Finance/delAdjustment', ['method' => 'post']],//撤销调整 'delAdjustment' => ['index/Finance/delAdjustment', ['method' => 'post']],//撤销调整
'getAdjustmentDetail' => ['index/Finance/getAdjustmentDetail', ['method' => 'get']],//调整详情 'getAdjustmentDetail' => ['index/Finance/getAdjustmentDetail', ['method' => 'get']],//调整详情
'getPayLogTotalPrice' => ['index/Finance/getPayLogTotalPrice', ['method' => 'get']],//佣金统计
'performanceInfo' => ['index/PerformanceInfo/performanceInfo', ['method' => 'post|get']],//业绩明细 'performanceInfo' => ['index/PerformanceInfo/performanceInfo', ['method' => 'post|get']],//业绩明细
'getPerformanceInfoExcel' => ['index/PerformanceInfo/getPerformanceInfoExcel', ['method' => 'post|get']],//业绩明细 'getPerformanceInfoExcel' => ['index/PerformanceInfo/getPerformanceInfoExcel', ['method' => 'post|get']],//业绩明细
......
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