From 2143b19d43cf8169427738747eef1ef09456fab5 Mon Sep 17 00:00:00 2001 From: qianhy Date: Tue, 10 Jan 2023 11:25:31 +0800 Subject: [PATCH] cost detail fixbug: business_id --- admin/controllers/items/Cost.php | 76 +++++++++++++++++++++++++++++++- admin/views/items/cost/get.php | 2 +- 2 files changed, 76 insertions(+), 2 deletions(-) diff --git a/admin/controllers/items/Cost.php b/admin/controllers/items/Cost.php index 9022e56a..3371c68a 100644 --- a/admin/controllers/items/Cost.php +++ b/admin/controllers/items/Cost.php @@ -133,7 +133,7 @@ class Cost extends HD_Controller{ 'cost_json' => $cost_json, 'srv_json' => $srv_json, 'row' => $row, - 'business_id' => 6 + 'business_id' => $info_json['business_id'] ? $info_json['business_id'] : 0 ]; $sum = $this->app_liche_orders_model->sum('total_price', ['o_id'=>$row['o_id'],'status'=>1,'pay_price <>'=>0]); $info['pay_price'] = $sum['total_price'] ? $sum['total_price'] : 0; @@ -275,4 +275,78 @@ class Cost extends HD_Controller{ $this->load->library('excel'); $this->excel->out_csv($data, $indexs, $fileName . "_" . date('YmdHis')); } + + public function export_(){ + $params = $this->input->get(); + $params['page'] = 1; + $params['size'] = 10000; + $data = $indexs = array(); + $fileName = '整车成本'; + $where = []; + $count = $this->items_cost_model->count($where); + if($count){ + $rows = $this->items_cost_model->select($where,'id desc',$params['page'],$params['size']); + $item_ids = implode(',',array_column($rows,'item_id')); + $map_item = $item_rows = []; + if($item_ids){ + $where = ["id in ($item_ids)" => null]; + $item_rows = $this->items_model->select($where,'','','','id,brand_id,s_id,v_id,vin'); + foreach ($item_rows as $item) { + $map_item[$item['id']] = $item; + } + } + //品牌车型 + $brand_arr = array_unique(array_column($item_rows, 'brand_id')); + $brands = $this->auto_brand_model->get_map_by_ids($brand_arr, 'id,name'); + //车系车型 + $series_arr = array_unique(array_column($item_rows, 's_id')); + $series = $this->auto_series_model->get_map_by_ids($series_arr, 'id,name'); + + //获取属性 + $v_arr = array_unique(array_column($item_rows, 'v_id')); + $cor_arr = array_unique(array_column($item_rows, 'cor_id')); + $incor_arr = array_unique(array_column($item_rows, 'incor_id')); + $attr_arr = array_merge($v_arr, $cor_arr, $incor_arr); + $attr = $this->auto_attr_model->get_map_by_ids($attr_arr, 'id,title'); + + foreach ($rows as $key => $val) { + $item = $map_item[$val['item_id']]; + $brand_name = isset($brands[$item['brand_id']]) ? $brands[$item['brand_id']][0]['name'] : ''; + $series_name = isset($series[$item['s_id']]) ? $series[$item['s_id']][0]['name'] : ''; + $v_name = isset($attr[$item['v_id']]) ? $attr[$item['v_id']][0]['title'] : ''; + $data[] = [ + 'id' => $val['id'], + 'title' => "{$brand_name} {$series_name} {$v_name}", + 'vin' => $item['vin'], + 'sale_price' => $val['sale_price'], + 'buy_price' => $val['buy_price'], + 'promotion_price' => $val['promotion_price'], + 'car_buy_price' => $val['car_buy_price'], + 'car_profit_price' => $val['car_profit_price'], + 'insurance_price' => $val['insurance_price'], + 'fee_carno_price' => $val['fee_carno_price'], + 'loan_price' => $val['loan_price'], + 'srv_price' => $val['srv_price'], + 'car_price' => $val['car_price'], + ]; + } + } + $indexs = [ + 'title' => '车辆', + 'vin' => '车架号', + 'sale_price' => '销售收入合计', + 'buy_price' => '采购及加装成本合计', + "promotion_price" => "促销成本合计", + "car_buy_price" => "整车采购成本", + "car_profit_price" => "整车采购毛利", + "insurance_price" => "保险收入合计", + "fee_carno_price" => "挂牌收入合计", + "loan_price" => "按揭收入合计", + "srv_price" => "水平业务总毛利 ", + "car_price" => "单车总毛利", + ]; + array_unshift($data, $indexs); + $this->load->library('excel'); + $this->excel->out_csv($data, $indexs, $fileName . "_" . date('YmdHis')); + } } \ No newline at end of file diff --git a/admin/views/items/cost/get.php b/admin/views/items/cost/get.php index 91161ba7..40583d2b 100644 --- a/admin/views/items/cost/get.php +++ b/admin/views/items/cost/get.php @@ -160,7 +160,7 @@ 商务政策 --> - + 商务政策