From e0dc63e1f48dbeefd8321a88f02c838c0fededed Mon Sep 17 00:00:00 2001 From: lccsw <805383944@qq.com> Date: Tue, 12 Apr 2022 11:34:39 +0800 Subject: [PATCH] edit-biz-settle --- admin/controllers/auto/Business.php | 32 +++++++++++++++++-- admin/controllers/biz/Settle.php | 34 ++++++++++++++++++++- admin/controllers/biz/store/Store.php | 2 ++ admin/views/auto/business/lists.php | 16 +++++++++- admin/views/biz/store/get_info.php | 9 +++++- api/controllers/plan/Biz.php | 8 ++--- api/controllers/wxapp/licheb/CusorderV2.php | 5 +++ 7 files changed, 94 insertions(+), 12 deletions(-) diff --git a/admin/controllers/auto/Business.php b/admin/controllers/auto/Business.php index abd3bc65..dff825c6 100644 --- a/admin/controllers/auto/Business.php +++ b/admin/controllers/auto/Business.php @@ -38,11 +38,16 @@ class Business extends HD_Controller{ } else{ $params['V_id'] = ''; } - if(strlen($params['status']) > 0){ + if(strlen($params['status'])){ $where['status'] = $params['status']; } else { $params['status'] = ''; } + if(strlen($params['if_effect'])){ + $where['if_effect'] = $params['if_effect']; + } else { + $params['if_effect'] = ''; + } if($params['city_id']){ $where['city_id'] = $params['city_id']; } else{ @@ -118,6 +123,7 @@ class Business extends HD_Controller{ 'month' => $month, 's_effect_time' => $v['s_effect_time'] ? date('Y-m-d',$v['s_effect_time']) : '', 'effect_status' => $v['if_effect'] ? '生效中' : '未生效', + 'if_effect' => $v['if_effect'], ); } } @@ -325,11 +331,31 @@ class Business extends HD_Controller{ $value = $this->input->post('value'); $status = $this->input->post('status'); + $upd = []; if('status' == $field){ $status = $value; + $upd = array('status' => $status); + } + + if($field == 'if_effect'){ + $upd['if_effect'] = $value; + if($value){ //生效 + $row = $this->auto_business_model->get(['id'=>$id]); + $where = [ + 'city_id' => $row['city_id'], + 'brand_id' => $row['brand_id'], + 's_id' => $row['s_id'], + 'v_id' => $row['v_id'], + 'status' => 1, + 's_effect_time>' => $row['s_effect_time'], + ]; + if($this->auto_business_model->count($where)){ + return $this->show_json(SYS_CODE_FAIL, '存在更新生效设置'); + } + unset($where['s_effect_time']); + $this->auto_business_model->update(['if_effect'=>0],$where); + } } - - $upd = array('status' => $status); if(is_numeric($id)){ $where = array('id' => $id); diff --git a/admin/controllers/biz/Settle.php b/admin/controllers/biz/Settle.php index 50d58ca3..dc03fe88 100644 --- a/admin/controllers/biz/Settle.php +++ b/admin/controllers/biz/Settle.php @@ -19,11 +19,13 @@ class Settle extends HD_Controller $this->load->model('auto/auto_business_model'); $this->load->model('items/items_model'); + $this->load->model('receiver/order/receiver_orders_v2_model'); $this->load->model('biz/biz_model'); $this->load->model('biz/biz_settle_model'); $this->load->model('biz/biz_settle_static_model'); $this->load->model('biz/biz_info_model'); + $this->load->model('biz/biz_trucking_model'); } public function index() @@ -399,9 +401,39 @@ class Settle extends HD_Controller } } } + $car_total = $this->biz_settle_model->count(['stic_id'=>$row['id']]); $biz_info = $this->biz_info_model->get(['biz_id'=>$row['biz_id']]); $type_config = $this->biz_type[$biz_info['type']]; - $price_need = $row['rent'] + $row['wat_ele'] + $row['employee_wage'] + $row['manager_wage'] + $row['commission'] + $row['price_trucking']; + $update = [ + 'rent' => $biz_info['rent'], + 'wat_ele' => $biz_info['wat_ele'], + 'manager_wage' => $biz_info['manager_wage'], + 'commission' => $biz_info['commission']*$car_total, + ]; + $employee_wage = $biz_info['num'] ? ceil($car_total/$biz['num']) : 0; + $update['employee_wage'] = $employee_wage; + + $settle_rows = $this->biz_settle_model->select(['stic_id'=>$row['id']],'id asc',0,0,'id,o_id'); + if(is_array($settle_rows)){ + $o_id_str = implode(',',array_column($settle_rows,'o_id')); + $order_rows = []; + if($o_id_str){ + $where = [ + "id in ($o_id_str)" => null + ]; + $order_rows = $this->receiver_orders_v2_model->map('id','brand_id',$where,0,0,'id,brand_id'); + } + foreach($settle_rows as $val){ + $auto_b_id = $order_rows[$val['o_id']] ? $order_rows[$val['o_id']] : 0; + $truck_row = $this->biz_trucking_model->get(['biz_id'=>$row['biz_id'],'auto_b_id'=>$auto_b_id,'status'=>1]); + $price = $truck_row ? $truck_row['money'] : 0; + $this->biz_settle_model->update(['price_trucking'=>$price],['id'=>$val['id']]); + } + } + $truck_sum = $this->biz_settle_model->sum('price_trucking',['stic_id' => $row['id']]); + $update['price_trucking'] = $truck_sum['price_trucking']; + + $price_need = $update['rent'] + $update['wat_ele'] + $update['employee_wage'] + $update['manager_wage'] + $update['commission'] + $update['price_trucking']; $price_ml = $row['price_total'] - $price_need - $all_other; $update['profix_liche'] = $price_ml*$type_config['liche']-$liche_other; $update['profix_partner'] = $price_ml*$type_config['partner']-$partner_other; diff --git a/admin/controllers/biz/store/Store.php b/admin/controllers/biz/store/Store.php index 9cdc9d2f..91a27523 100755 --- a/admin/controllers/biz/store/Store.php +++ b/admin/controllers/biz/store/Store.php @@ -1038,6 +1038,7 @@ class Store extends HD_Controller 'employee_wage' => $base_info['employee_wage'], 'manager_wage' => $base_info['manager_wage'], 'commission' => $base_info['commission'], + 'num' => $base_info['num'], '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'], @@ -1090,6 +1091,7 @@ class Store extends HD_Controller 'e_time' => $info['e_time'] ? strtotime($info['e_time']) : 0, 'type' => $info['type'], 'rate' => $info['rate'], + 'num' => $info['num'] ]; $this->biz_info_model->update($up_data, ['id' => $info['id']]); $b_ids = array_column($brands, 'id'); diff --git a/admin/views/auto/business/lists.php b/admin/views/auto/business/lists.php index 812cf267..78a61ede 100644 --- a/admin/views/auto/business/lists.php +++ b/admin/views/auto/business/lists.php @@ -24,7 +24,7 @@ -