Commit dbd3a9eb authored by hujun's avatar hujun

income_time

parent fa2e9619
...@@ -4196,47 +4196,60 @@ class Finance extends Basic ...@@ -4196,47 +4196,60 @@ class Finance extends Basic
* @return \think\Response * @return \think\Response
*/ */
public function getPayLogTotalPrice() { public function getPayLogTotalPrice() {
$this->params['start_time'] = '2019-4-9';
$this->params['end_time'] = '2019-4-10';
if (empty($this->params['start_time']) || empty($this->params['end_time'])) {
return $this->response(101, '参数错误');
}
if (!strtotime($this->params['start_time']) || !strtotime($this->params['end_time'])) {
return $this->response(101, '时间格式错误');
}
$income_start = $this->params['start_time'] . ' 00:00:00';
$income_end = $this->params['end_time']. ' 23:59:59';
//付款类型 10意向金 20定金 30保管金 40押金 50 租金 60 进场费 70转让费 80其他 90佣金 91中介费 92 案场费 //付款类型 10意向金 20定金 30保管金 40押金 50 租金 60 进场费 70转让费 80其他 90佣金 91中介费 92 案场费
//调整类型 意向金:1转中介费 2转案场费 3转意向金 保管金:4转中介费 5转案场费 6转保管金 //调整类型 意向金:1转中介费 2转案场费 3转意向金 保管金:4转中介费 5转案场费 6转保管金
//退款类型:0退意向金1意向金转定2退保管金3保管金转定4退中介费5退案场 //退款类型:0退意向金1意向金转定2退保管金3保管金转定4退中介费5退案场
$agent_fee = $this->sumPayLogBargainByType(91, 0);//未开业中介费 $agent_fee = $this->sumPayLogBargainByType(91, 0, $income_start, $income_end);//未开业中介费
$case_fee = $this->sumPayLogBargainByType(92, 0);//未开业案场费 $case_fee = $this->sumPayLogBargainByType(92, 0, $income_start, $income_end);//未开业案场费
$agent_refund_fee = $this->sumPayLogRefundByType(4, 0);//未开业中介费退款 $agent_refund_fee = $this->sumPayLogRefundByType(4, 0, 0,$income_start, $income_end);//未开业中介费退款
$case_refund_fee = $this->sumPayLogRefundByType(5, 0);//未开业案场费退款 $case_refund_fee = $this->sumPayLogRefundByType(5, 0, 0,$income_start, $income_end);//未开业案场费退款
$data['not_open_commission'] = $agent_fee + $case_fee - $agent_refund_fee - $case_refund_fee; //未开业佣金 $data['not_open_commission'] = $agent_fee + $case_fee - $agent_refund_fee - $case_refund_fee; //未开业佣金
$open_agent_fee = $this->sumPayLogBargainByType(91, 1);//开业中介费 $open_agent_fee = $this->sumPayLogBargainByType(91, 1, $income_start, $income_end);//开业中介费
$open_case_fee = $this->sumPayLogBargainByType(92, 1);//开业案场费 $open_case_fee = $this->sumPayLogBargainByType(92, 1, $income_start, $income_end);//开业案场费
$open_agent_refund = $this->sumPayLogRefundByType(4, 1);//开业中介费退款 $open_agent_refund = $this->sumPayLogRefundByType(4, 1, 0,$income_start, $income_end);//开业中介费退款
$open_case_refund = $this->sumPayLogRefundByType(5, 1);//开业案场费退款 $open_case_refund = $this->sumPayLogRefundByType(5, 1, 0,$income_start, $income_end);//开业案场费退款
$data['open_commission'] = $open_agent_fee + $open_case_fee - $open_agent_refund - $open_case_refund; //已开业佣金 $data['open_commission'] = $open_agent_fee + $open_case_fee - $open_agent_refund - $open_case_refund; //已开业佣金
//佣金总计:中介费入账+案场费入账-中介费退款-案场费退款 //佣金总计:中介费入账+案场费入账-中介费退款-案场费退款
$data['total_commission'] = $data['not_open_commission'] + $data['open_commission']; $data['total_commission'] = $data['not_open_commission'] + $data['open_commission'];
$data['intention_recorded'] = $this->sumPayLogPriceByType(10, 0);//意向金入账 $data['intention_recorded'] = $this->sumPayLogPriceByType(10, 0, $income_start, $income_end);//意向金入账
$agent_fee = $this->sumPayLogPriceByType(1, 1);//意向金转中介费 $agent_fee = $this->sumPayLogPriceByType(1, 1, $income_start, $income_end);//意向金转中介费
$case_fee = $this->sumPayLogPriceByType(2, 1);//意向金转案场费 $case_fee = $this->sumPayLogPriceByType(2, 1, $income_start, $income_end);//意向金转案场费
$intention_fee = $this->sumPayLogPriceByType(3, 1);//意向金转意向金 $intention_fee = $this->sumPayLogPriceByType(3, 1, $income_start, $income_end);//意向金转意向金
$custody_fee = $this->sumPayLogPriceByType(7, 1);//意向金转保管金 $custody_fee = $this->sumPayLogPriceByType(7, 1, $income_start, $income_end);//意向金转保管金
//意向金转意向金+意向金转中介费+意向金转案场费 //意向金转意向金+意向金转中介费+意向金转案场费
$data['intention_adjustment'] = $agent_fee + $case_fee + $intention_fee + $custody_fee;//意向金调整 $data['intention_adjustment'] = $agent_fee + $case_fee + $intention_fee + $custody_fee;//意向金调整
$data['intention_refund'] = $this->sumPayLogRefundByType(0, 0, 0);//意向金退款 $data['intention_refund'] = $this->sumPayLogRefundByType(0, 0, 0, $income_start, $income_end);//意向金退款
$data['intention_refund'] += $this->sumPayLogRefundByType(1, 0, 0);//意向金退款 $data['intention_refund'] += $this->sumPayLogRefundByType(1, 0, 0, $income_start, $income_end);//意向金退款
$data['intention_refund'] = round($data['intention_refund'], 2); $data['intention_refund'] = round($data['intention_refund'], 2);
//意向金入账-意向金调整-意向金退款 //意向金入账-意向金调整-意向金退款
$data['total_intention_recorded'] = $data['intention_recorded'] - $data['intention_adjustment'] - $data['intention_refund']; //账上意向金 $data['total_intention_recorded'] = $data['intention_recorded'] - $data['intention_adjustment'] - $data['intention_refund']; //账上意向金
$data['custody_recorded'] = $this->sumPayLogPriceByType(30, 0);//保管金入账 $data['custody_recorded'] = $this->sumPayLogPriceByType(30, 0, $income_start, $income_end);//保管金入账
$agent_fee = $this->sumPayLogPriceByType(4, 1);//保管金转中介费 $agent_fee = $this->sumPayLogPriceByType(4, 1, $income_start, $income_end);//保管金转中介费
$case_fee = $this->sumPayLogPriceByType(5, 1);//保管金转案场费 $case_fee = $this->sumPayLogPriceByType(5, 1, $income_start, $income_end);//保管金转案场费
$custody_fee = $this->sumPayLogPriceByType(6, 1);//保管金转保管金 $custody_fee = $this->sumPayLogPriceByType(6, 1, $income_start, $income_end);//保管金转保管金
//保管金调整:保管金转保管金+保管金转中介费+保管金转案场费 //保管金调整:保管金转保管金+保管金转中介费+保管金转案场费
$data['custody_adjustment'] = $agent_fee + $case_fee + $custody_fee;//保管金调整 $data['custody_adjustment'] = $agent_fee + $case_fee + $custody_fee;//保管金调整
$data['custody_refund'] = $this->sumPayLogRefundByType(3, 0, 0);//保管金转定 $data['custody_refund'] = $this->sumPayLogRefundByType(3, 0, 0, $income_start, $income_end);//保管金转定
$data['custody_refund'] += $this->sumPayLogRefundByType(2, 0, 0);//保管金转定 $data['custody_refund'] += $this->sumPayLogRefundByType(2, 0, 0, $income_start, $income_end);//保管金转定
//意向金入账-意向金调整-意向金退款 //意向金入账-意向金调整-意向金退款
$data['total_custody_recorded'] = $data['custody_recorded'] - $data['custody_adjustment'] - $data['custody_refund']; //账上保管金 $data['total_custody_recorded'] = $data['custody_recorded'] - $data['custody_adjustment'] - $data['custody_refund']; //账上保管金
...@@ -4251,15 +4264,18 @@ class Finance extends Basic ...@@ -4251,15 +4264,18 @@ class Finance extends Basic
* *
* @param $type * @param $type
* @param int $is_open * @param int $is_open
* @param $income_time_start
* @param $income_time_end
* @return float|int|string * @return float|int|string
*/ */
private function sumPayLogBargainByType($type, $is_open = 0) { private function sumPayLogBargainByType($type, $is_open = 0, $income_time_start, $income_time_end) {
$m_pay = new OPayLogModel(); $m_pay = new OPayLogModel();
$where['b.is_open'] = $is_open; $where['b.is_open'] = $is_open;
$where['a.type'] = $type; $where['a.type'] = $type;
$where['b.status'] = ['in', '10,11,13']; $where['b.status'] = ['in', '10,11,13'];
$where['b.father_id'] = $where['a.is_del'] = 0; $where['b.father_id'] = $where['a.is_del'] = 0;
$where['a.income_time'] = ['between', [$income_time_start, $income_time_end]];
$price = $m_pay->sumBargainPrice('a.real_money', $where); //未开业中介费 $price = $m_pay->sumBargainPrice('a.real_money', $where); //未开业中介费
return empty($price) ? '' : $price; return empty($price) ? '' : $price;
} }
...@@ -4268,11 +4284,13 @@ class Finance extends Basic ...@@ -4268,11 +4284,13 @@ class Finance extends Basic
* 开业和未开业退款金额计算 * 开业和未开业退款金额计算
* *
* @param $type * @param $type
* @param int $is_open * @param $is_open
* @param int $is_bargain * @param $is_bargain
* @param $income_start
* @param $income_end
* @return float|int|string * @return float|int|string
*/ */
private function sumPayLogRefundByType($type, $is_open = 0, $is_bargain = 1) { private function sumPayLogRefundByType($type, $is_open, $is_bargain, $income_start, $income_end) {
$m_pay = new ORefundModel(); $m_pay = new ORefundModel();
if ($is_bargain) { if ($is_bargain) {
...@@ -4280,10 +4298,12 @@ class Finance extends Basic ...@@ -4280,10 +4298,12 @@ class Finance extends Basic
$where['a.type'] = $type; $where['a.type'] = $type;
$where['b.status'] = ['in', '10,11,13']; $where['b.status'] = ['in', '10,11,13'];
$where['b.father_id'] = $where['a.is_del'] = 0; $where['b.father_id'] = $where['a.is_del'] = 0;
$where['c.income_time'] = ['between', [$income_start, $income_end]];
$price = $m_pay->sumBargainPrice('a.refund_money', $where); //未开业中介费 $price = $m_pay->sumBargainPrice('a.refund_money', $where); //未开业中介费
} else { } else {
$where['type'] = $type; $where['a.type'] = $type;
$price = $m_pay->getRefundSum('refund_money', $where); $where['b.income_time'] = ['between', [$income_start, $income_end]];
$price = $m_pay->getRefundSumV2('a.refund_money', $where);
} }
return empty($price) ? '' : $price; return empty($price) ? '' : $price;
...@@ -4291,21 +4311,25 @@ class Finance extends Basic ...@@ -4291,21 +4311,25 @@ class Finance extends Basic
/** /**
* @param int $type * @param int $type
* @param int $is_adjustment 0调整前 1调整后 * @param int $is_adjustment 0调整前 1调整后
* @return float|int|string * @param $income_start
* @param $income_end
* @return float|int
*/ */
private function sumPayLogPriceByType(int $type, int $is_adjustment = 0) { private function sumPayLogPriceByType(int $type, int $is_adjustment, $income_start, $income_end) {
if ($is_adjustment) { if ($is_adjustment) {
$m_pay_adjustment = new OPayLogAdjustment(); $m_pay_adjustment = new OPayLogAdjustment();
$where['a.type'] = $type; $where['a.type'] = $type;
$where['b.source'] = 2; $where['b.source'] = 2;
$where['a.is_del'] = 0; $where['a.is_del'] = 0;
$where['b.is_del'] = 0; $where['b.is_del'] = 0;
$price = $m_pay_adjustment->sumMoney('a.money', $where, $is_adjustment); $where['b.income_time'] = ['between', [$income_start, $income_end]];
$price = $m_pay_adjustment->sumMoney('a.money', $where);
} else { } else {
$m_pay = new OPayLogModel(); $m_pay = new OPayLogModel();
$where['type'] = $type; $where['type'] = $type;
$where['is_del'] = 0; $where['is_del'] = 0;
$where['income_time'] = ['between', [$income_start, $income_end]];
$price = $m_pay->sumPayLog('real_money', $where); $price = $m_pay->sumPayLog('real_money', $where);
} }
return $price; return $price;
......
...@@ -282,6 +282,19 @@ class ORefundModel extends Model{ ...@@ -282,6 +282,19 @@ class ORefundModel extends Model{
} }
public function getRefundSumV2($field, $params)
{
if (!isset($params['is_del'])) {
$params['a.is_del'] = 0;
}
$data = $this->db_->alias('a')
->join('o_paylog b','a.pay_log_id=b.id')
->where($params)
->sum($field);
return $data;
}
/** /**
* @param $params * @param $params
* @return float|int * @return float|int
...@@ -320,6 +333,7 @@ class ORefundModel extends Model{ ...@@ -320,6 +333,7 @@ class ORefundModel extends Model{
public function sumBargainPrice($field, $where) { public function sumBargainPrice($field, $where) {
return $this->db_->alias('a') return $this->db_->alias('a')
->join('o_bargain b','a.order_id=b.order_id') ->join('o_bargain b','a.order_id=b.order_id')
->join('o_paylog c','a.pay_log_id=c.id')
->where($where) ->where($where)
->sum($field); ->sum($field);
} }
......
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