diff --git a/admin/controllers/items/Cost.php b/admin/controllers/items/Cost.php index e47fec57..c86dbbac 100644 --- a/admin/controllers/items/Cost.php +++ b/admin/controllers/items/Cost.php @@ -14,6 +14,7 @@ class Cost extends HD_Controller{ $this->load->model('sys/sys_company_model'); $this->load->model('auto/auto_series_model'); $this->load->model('auto/auto_brand_model'); + $this->load->model('auto/auto_attr_model'); } public function index(){ $this->lists(); @@ -45,13 +46,21 @@ class Cost extends HD_Controller{ $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'] : ''; $lists[] = [ 'id' => $val['id'], - 'title' => "{$brand_name} {$series_name}", + 'title' => "{$brand_name} {$series_name} {$v_name}", 'vin' => $item['vin'], 'sale_price' => $val['sale_price'], 'buy_price' => $val['buy_price'], @@ -105,7 +114,7 @@ class Cost extends HD_Controller{ !$srv_json['other_in_price'] && $srv_json['other_in_price'] = 0; $info = [ 'bill_name' => $row['bill_name'], - 'bill_time' => $row['bill_time'], + 'bill_time' => date('Y-m-d',strtotime($row['bill_time'])), 'price' => $row['price'], 'bill_price' => $row['bill_price'], 'vin' => $item_row['vin'], @@ -123,10 +132,12 @@ class Cost extends HD_Controller{ 'row' => $row ]; //获取车信息 - $brand = $this->auto_brand_model->get(['id' => $order_row['brand_id']], 'name'); - $serie = $this->auto_series_model->get(['id' => $order_row['s_id']], 'name'); + $brand = $this->auto_brand_model->get(['id' => $item_row['brand_id']], 'name'); + $serie = $this->auto_series_model->get(['id' => $item_row['s_id']], 'name'); + $attr = $this->auto_attr_model->get(['id'=>$item_row['v_id']], 'title'); $info['brand_name'] = $brand['name']; $info['s_name'] = $serie['name']; + $info['v_name'] = $attr['title']; $this->data['info'] = $info; $this->data['_title'] = '编辑整车成本'; return $this->show_view('items/cost/get', true); @@ -165,6 +176,76 @@ class Cost extends HD_Controller{ } 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 798fa4c4..f66d2cdc 100644 --- a/admin/views/items/cost/get.php +++ b/admin/views/items/cost/get.php @@ -9,6 +9,12 @@ text-align: left; font-size: 1.6rem; } + .label-width{ + width: 150px; + } + .am-para-input{ + margin-left: 150px; + }
| 车辆 | +车辆 | 销售收入合计 | 采购及加装成本合计 | 促销成本合计 | 整车采购成本 | 整车采购毛利 | 保险收入合计 | +挂牌收入合计 | 按揭收入合计 | 水平业务总毛利 | 单车总毛利 | -操作 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| {{v.vin}} {{v.title}} |
+
+
+ {{v.vin}} {{v.title}} + + |
{{v.sale_price}} | +{{v.buy_price}} | {{v.promotion_price}} | {{v.car_buy_price}} | {{v.car_profit_price}} | @@ -93,9 +98,6 @@{{v.loan_price}} | {{v.srv_price}} | {{v.car_price}} | -- 查看 - |