From 520542cbbf72576e8d6e7cb5ecf2f453014687e7 Mon Sep 17 00:00:00 2001
From: lccsw <805383944@qq.com>
Date: Wed, 6 Apr 2022 17:34:13 +0800
Subject: [PATCH] edit-admin-settle
---
admin/controllers/biz/Settle.php | 3 +-
admin/controllers/biz/store/Store.php | 5 +
admin/views/biz/store/get_info.php | 7 ++
api/controllers/plan/Biz.php | 143 +++++++++++++++-----------
4 files changed, 99 insertions(+), 59 deletions(-)
diff --git a/admin/controllers/biz/Settle.php b/admin/controllers/biz/Settle.php
index dd218a1a..50d58ca3 100644
--- a/admin/controllers/biz/Settle.php
+++ b/admin/controllers/biz/Settle.php
@@ -217,7 +217,7 @@ class Settle extends HD_Controller
$other_price,
$row['price_ml'],
$row['profix_liche'],
- $row['profix_partner'],
+ $row['profix_partner']+$row['profix_partner_oflow'],
$row['month_str']
];
}
@@ -361,6 +361,7 @@ class Settle extends HD_Controller
$temp['price_other'] = $v['price_other'] ? json_decode($v['price_other']) : [];
$temp['total_need'] = $v['rent'] + $v['wat_ele'] + $v['manager_wage'] + $v['employee_wage'] + $v['commission'] + $v['price_trucking'];
$temp['price_ml'] = $v['price_total'] - $temp['total_need'];
+ $temp['profix_partner'] = $v['profix_partner'] + $v['profix_partner_oflow'];
$lists[] = $temp;
}
}
diff --git a/admin/controllers/biz/store/Store.php b/admin/controllers/biz/store/Store.php
index 295d36fa..7ae61874 100755
--- a/admin/controllers/biz/store/Store.php
+++ b/admin/controllers/biz/store/Store.php
@@ -1040,6 +1040,7 @@ class Store extends HD_Controller
's_time' => $base_info['s_time'] ? date('Y-m-d',$base_info['s_time']) : '',
'e_time' => $base_info['e_time'] ? date('Y-m-d',$base_info['e_time']) : '',
'type' => $base_info['type'],
+ 'rate' => strlen($base_info['rate']) ? $base_info['rate'] : 0,
];
$brands = [];
$b_rows = $this->biz_trucking_model->select(['biz_id'=>$base_info['biz_id'],'status'=>1],'','','','auto_b_id,money');
@@ -1069,6 +1070,9 @@ class Store extends HD_Controller
if(!$this->biz_info_model->get(['id'=>$info['id']])){
return $this->show_json(SYS_CODE_FAIL, '错数错误!');
}
+ if($info['rate']<0||$info['rate']>100){
+ return $this->show_json(SYS_CODE_FAIL, '分佣比例请填写0~100');
+ }
$up_data = [
'name' => $info['name'],
'mobile' => $info['mobile'],
@@ -1082,6 +1086,7 @@ class Store extends HD_Controller
's_time' => $info['s_time'] ? strtotime($info['s_time']) : 0,
'e_time' => $info['e_time'] ? strtotime($info['e_time']) : 0,
'type' => $info['type'],
+ 'rate' => $info['rate'],
];
$this->biz_info_model->update($up_data,['id'=>$info['id']]);
$b_ids = array_column($brands,'id');
diff --git a/admin/views/biz/store/get_info.php b/admin/views/biz/store/get_info.php
index 061c3230..168c84ba 100644
--- a/admin/views/biz/store/get_info.php
+++ b/admin/views/biz/store/get_info.php
@@ -19,6 +19,13 @@
+
diff --git a/api/controllers/plan/Biz.php b/api/controllers/plan/Biz.php
index 52c5403a..e6e8ea47 100644
--- a/api/controllers/plan/Biz.php
+++ b/api/controllers/plan/Biz.php
@@ -17,6 +17,8 @@ class Biz extends HD_Controller
$this->load->model('biz/biz_settle_model');
$this->load->model('biz/biz_settle_static_model');
$this->load->model('biz/biz_trucking_model');
+
+ $this->load->library('receiver/orders_v2_entity');
}
public function settle(){
@@ -30,11 +32,13 @@ class Biz extends HD_Controller
$fields = "$t2.*,$t4.city_id";
$where = [
- "$t1.pid_status" => 5,
+ "$t1.pid_status" => 3,
"$t1.status" => 1,
- "$t2.status>=" => 0,
+ "$t2.status in (0,1)" => null,
+ "$t2.id>=" => Orders_v2_entity::V2_START_ID,
+ "$t2.bill_time !='0000-00-00 00:00:00'" => null,
"$t3.id is null" => null,
- "$t4.type" => 2
+ "$t4.type" => 2,
];
$this->db->from("$t1");
@@ -49,24 +53,24 @@ class Biz extends HD_Controller
$rows = $this->db->get()->result_array();
if($rows){
foreach($rows as $key=>$val){
- //获取创建订单当月商务政策
+ $info_json = json_decode($val['info_json'],true);
+ $money_json = json_decode($val['money_json'],true);
+ //获取创建订单时商务政策
+ $where = [
+ 'id' => $info_json['business_id'],
+ ];
+ $b_row_one = $this->auto_business_model->get($where);
+ //获取开票日期商务政策
$b_where = [
- 'city_id ' => $val['city_id'],
+ 'city_id' => $val['city_id'],
'brand_id' => $val['brand_id'],
's_id' => $val['s_id'],
'v_id' => $val['v_id'],
+ 'if_effect' => 1,
'status' => 1
];
- $b_where['year'] = date('Y',$val['c_time']);
- $b_where['month'] = intval(date('m',$val['c_time']));
- $b_row_one = $this->auto_business_model->get($b_where);
- //获取开票日期商务政策
- $b_row_two = $b_row_one;
- if(date('Y-m',strtotime($val['bill_time']))!=date('Y-m',$val['c_time'])) {
- $b_where['year'] = date('Y',strtotime($val['bill_time']));
- $b_where['month'] = intval(date('m',strtotime($val['bill_time'])));
- $b_row_two = $this->auto_business_model->get($b_where);
- }
+ $b_row_two = $this->auto_business_model->select($b_where,'id desc',1,1);
+ $b_row_two = $b_row_two[0];
$truck_row = $this->biz_trucking_model->get(['auto_b_id'=>$val['brand_id'],'biz_id'=>$val['biz_id'],'status'=>1]);
$price_trucking = $truck_row['money'] ? $truck_row['money'] : 0;
$add_data = [
@@ -77,10 +81,13 @@ class Biz extends HD_Controller
'profix_loan' => $b_row_two['profix_loan'] ? $b_row_two['profix_loan'] : 0,
'profix_carno' => $b_row_two['profix_carno'] ? $b_row_two['profix_carno'] : 0,
'price_trucking' => $price_trucking,
- 'year' => date('Y'),
- 'month' => intval(date('m')),
+ 'year' => date('Y',strtotime($val['bill_time'])),
+ 'month' => intval(date('m',strtotime($val['bill_time']))),
'c_time' => time()
];
+ if($money_json['price_car']>$b_row_one['price_floor']){
+ $add_data['oflow_profix_car'] = $money_json['price_car'] - $b_row_one['price_floor'];
+ }
$this->biz_settle_model->add($add_data);
}
}else{
@@ -91,68 +98,88 @@ class Biz extends HD_Controller
//统计前一个月利润
public function merage(){
$size = $this->input->get('size');
+ !$page && $page = 1;
!$size && $size = 5;
- $t1 = 'lc_biz_settle';
- $t2 = 'lc_biz_settle_static';
-
- $fields = "$t1.*";
$where = [
- "$t1.year" => date('Y',strtotime("last month")),
- "$t1.month" => intval(date('m',strtotime('last day of - 1 months'))),
- "$t2.id is null" => null
+ "year" => date('Y',strtotime("last month")),
+ "month" => intval(date('m',strtotime('last day of - 1 months'))),
+ "stic_id" => 0
];
-
- $this->db->from("$t1");
- $this->db->join("$t2", "$t2.biz_id=$t1.biz_id",'left');
-
- $this->db->select($fields);
- $this->db->where($where);
- $this->db->group_by("$t1.biz_id");
- $this->db->limit($size);
- $rows = $this->db->get()->result_array();
+ $rows = $this->biz_settle_model->select($where,'id asc',$page,$size);
if($rows){
foreach($rows as $key=>$val){
+ $biz_info = $this->biz_info_model->get(['biz_id'=>$val['biz_id']]);
$where = [
'biz_id' => $val['biz_id'],
'year' => $val['year'],
'month' => $val['month']
];
- if(!$this->biz_settle_static_model->get($where)){
- $biz = $this->biz_model->get(['id'=>$val['biz_id']]);
- $biz_info = $this->biz_info_model->get(['biz_id'=>$val['biz_id']]);
- $total_car = $this->biz_settle_model->count($where);
- $sum_car = $this->biz_settle_model->sum('profix_car',$where);
- $sum_insure = $this->biz_settle_model->sum('profix_insure',$where);
- $sum_loan = $this->biz_settle_model->sum('profix_loan',$where);
- $sum_carno = $this->biz_settle_model->sum('profix_carno',$where);
- $price_all = $sum_insn['profix_insure']+$sum_loan['profix_loan']+$sum_carno['profix_carno'];
- $sum_trucking = $this->biz_settle_model->sum('price_trucking',$where);
+ $static_row = $this->biz_settle_static_model->get($where);
+ $price_all = $val['profix_insure']+$val['profix_loan']+$val['profix_carno'];
+ if(!$static_row){
$data = [
'biz_id' => $val['biz_id'],
- 'profix_car' => $sum_car['profix_car'],
- 'profix_car_after' => sprintf("%.2f",$sum_car['profix_car']/1.13),
+ 'profix_car' => $val['profix_car'],
'price_all' => $price_all,
- 'price_trucking' => $sum_trucking['price_trucking'],
- 'rent' => $biz_info['rent'],
- 'wat_ele' => $biz_info['wat_ele'],
- 'employee_wage' => $biz_info['employee_wage'],
- 'manager_wage' => $biz_info['manager_wage'],
- 'commission' => $biz_info['commission'] * $total_car,
+ 'price_trucking' => $val['price_trucking'],
'year' => $val['year'],
'month' => $val['month'],
'c_time' => time()
];
- $data['price_total'] = $data['price_all']+$data['profix_car_after'];
- $type_config = $this->biz_type[$biz_info['type']];
- $price_need = $data['price_total'] - $data['rent'] - $data['wat_ele'] - $data['employee_wage'] - $data['manager_wage'] - $data['commission'] - $data['price_trucking'];
- $data['profix_liche'] = $price_need*$type_config['liche'];
- $data['profix_partner'] = $price_need*$type_config['partner'];
- $this->biz_settle_static_model->add($data);
+ $stic_id = $this->biz_settle_static_model->add($data);
+ if($stic_id){
+ $this->biz_settle_model->update(['stic_id'=>$stic_id],['id'=>$val['id']]);
+ }
+ }else{
+ $data = [
+ 'profix_car' => $static_row['profix_car'] + $val['profix_car'],
+ 'price_all' => $static_row['price_all'] + $price_all,
+ 'price_trucking' => $static_row['price_trucking'] + $val['price_trucking'],
+ ];
+ $res = $this->biz_settle_static_model->update($data,['id'=>$static_row['id']]);
+ if($res){
+ $this->biz_settle_model->update(['stic_id'=>$static_row['id']],['id'=>$val['id']]);
+ }
}
}
}else{
- echo 'finish';
+ //计算分润
+ $where = [
+ 'profix_car_after' => 0.00
+ ];
+ $rows = $this->biz_settle_static_model->select($where,'id asc',$page,$size);
+ if($rows){
+ foreach($rows as $val){
+ $biz_info = $this->biz_info_model->get(['biz_id'=>$val['biz_id']]);
+ $car_total = $this->biz_settle_model->count(['stic_id'=>$val['id']]);
+ $data = [
+ 'profix_car_after' => sprintf("%.2f",$val['profix_car']/1.13),
+ 'rent' => $biz_info['rent'],
+ 'wat_ele' => $biz_info['wat_ele'],
+ 'employee_wage' => $biz_info['employee_wage'],
+ 'manager_wage' => $biz_info['manager_wage'],
+ 'commission' => $biz_info['commission']*$car_total,
+ ];
+ $data['price_total'] = $val['price_all']+$data['profix_car_after'];
+ $price_need = $data['price_total'] - $data['rent'] - $data['wat_ele'] - $data['employee_wage'] - $data['manager_wage'] - $data['commission'] - $data['price_trucking'];
+ $partner_rate = $biz_info['rate']/100;
+ $liche_rate = (100-$biz_info['rate'])/100;
+
+ $data['profix_liche'] = $price_need*$liche_rate;
+ $data['profix_partner'] = $price_need*$partner_rate;
+
+ //超出裸车价部分
+ $overflow = $this->biz_settle_model->sum('oflow_profix_car',['stic_id'=>$val['id']]);
+ if($overflow['oflow_profix_car']){
+ $data['profix_partner_oflow'] = sprintf("%.2f",$overflow['oflow_profix_car']/1.13);
+ }
+
+ $this->biz_settle_static_model->update($data,['id'=>$val['id']]);
+ }
+ }else{
+ echo 'finish';
+ }
}
}
}