diff --git a/admin/controllers/items/Cost.php b/admin/controllers/items/Cost.php
new file mode 100644
index 00000000..e47fec57
--- /dev/null
+++ b/admin/controllers/items/Cost.php
@@ -0,0 +1,170 @@
+load->model('items/items_cost_model');
+ $this->load->model('auto/auto_brand_model', 'mdAutoBrand');
+ $this->load->model('receiver/order/receiver_orders_v2_model');
+ $this->load->model('receiver/order/receiver_order_agents_model', 'order_agents_model');
+ $this->load->model('items/items_model');
+ $this->load->model("biz/biz_model");
+ $this->load->model('app/licheb/app_licheb_users_model');
+ $this->load->model('sys/sys_company_model');
+ $this->load->model('auto/auto_series_model');
+ $this->load->model('auto/auto_brand_model');
+ }
+ public function index(){
+ $this->lists();
+ }
+
+ public function lists(){
+ $params = $this->input->get();
+ $page = $params['page'] = $params['page'] ? intval($params['page']) : 1;
+ $size = $params['size'] = $params['size'] ? intval($params['size']) : 20;
+ $autoList = array();
+ $where = [];
+ $count = $this->items_cost_model->count($where);
+ $lists = [];
+ if($count){
+ $rows = $this->items_cost_model->select($where,'id desc',$page,$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');
+
+ 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'] : '';
+ $lists[] = [
+ 'id' => $val['id'],
+ 'title' => "{$brand_name} {$series_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'],
+ ];
+ }
+ }
+ $autoList[1] = $this->mdAutoBrand->select(array('status' => 1), 'id desc', 0, 0, 'id,name');
+ $this->data['lists'] = $lists;
+ $this->data['pager'] = array('count' => ceil($count / $size), 'curr' => $page, 'totle' => $count);
+ $this->data['autoList'] = $autoList;
+ $this->data['params'] = $params;
+ $this->data['_title'] = '整车成本';
+ return $this->show_view('items/cost/lists', true);
+ }
+
+ public function get(){
+ $id = $this->input->get('id');
+ $row = $this->items_cost_model->get(['id'=>$id]);
+ if(!$row){
+ return $this->show_json(SYS_CODE_FAIL,'参数错误');
+ }
+ $order_row = $this->receiver_orders_v2_model->get(['id'=>$row['o_id']]);
+ $item_row = $this->items_model->get(['id'=>$row['item_id']]);
+ $biz = $this->biz_model->get(['id'=>$order_row['biz_id']]);
+ $admin = $this->app_licheb_users_model->get(['id'=>$order_row['admin_id']]);
+ $company = $this->sys_company_model->get(['id'=>$item_row['company_id']]);
+ $promotion_json = json_decode($row['promotion_json'],true);
+ !$promotion_json['sale_price'] && $promotion_json['sale_price'] = 0;
+ !$promotion_json['other'] && $promotion_json['other'] = 0;
+ !$promotion_json['subsidy'] && $promotion_json['subsidy'] = 0;
+ $cost_json = json_decode($row['cost_json'],true);
+ !$cost_json['select_price'] && $cost_json['select_price'] = 0;
+ !$cost_json['labor_price'] && $cost_json['labor_price'] = 0;
+ $srv_json = json_decode($row['srv_json'],true);
+ !$srv_json['interest_price'] && $srv_json['interest_price'] = 0;
+ !$srv_json['commission_price'] && $srv_json['commission_price'] = 0;
+ !$srv_json['back_price'] && $srv_json['back_price'] = 0;
+ !$srv_json['loan_offset_price'] && $srv_json['loan_offset_price'] = 0;
+ !$srv_json['loan_subsidy_price'] && $srv_json['loan_subsidy_price'] = 0;
+ !$srv_json['loan_in_price'] && $srv_json['loan_in_price'] = 0;
+ !$srv_json['loan_out_price'] && $srv_json['loan_out_price'] = 0;
+ !$srv_json['other_out_price'] && $srv_json['other_out_price'] = 0;
+ !$srv_json['other_in_price'] && $srv_json['other_in_price'] = 0;
+ $info = [
+ 'bill_name' => $row['bill_name'],
+ 'bill_time' => $row['bill_time'],
+ 'price' => $row['price'],
+ 'bill_price' => $row['bill_price'],
+ 'vin' => $item_row['vin'],
+ 'ori_price' => $item_row['ori_price'],
+ 'buy_price' => $item_row['buy_price'],
+ 'company_name' => $company['short'],
+ 'name' => $order_row['name']."({$order_row['mobile']})",
+ 'biz_type' => $this->biz_model->type_ary($biz['type']),
+ 'biz_name' => $biz['biz_name'],
+ 'admin_name' => $admin['uname'],
+ 'order_time' => date('Y-m-d H:i:s',$order_row['c_time']),
+ 'promotion_json' => $promotion_json,
+ 'cost_json' => $cost_json,
+ 'srv_json' => $srv_json,
+ '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');
+ $info['brand_name'] = $brand['name'];
+ $info['s_name'] = $serie['name'];
+ $this->data['info'] = $info;
+ $this->data['_title'] = '编辑整车成本';
+ return $this->show_view('items/cost/get', true);
+ }
+
+ public function add(){
+
+ }
+
+ public function edit(){
+ $post_data = $this->input->post();
+ $row = $this->items_cost_model->get(['id'=>$post_data['id']]);
+ if(!$row){
+ return $this->show_json(SYS_CODE_FAIL,'参数错误');
+ }
+ $data = [
+ 'cost_json' => json_encode($post_data['cost_json'],JSON_UNESCAPED_UNICODE),
+ 'promotion_json' => json_encode($post_data['promotion_json'],JSON_UNESCAPED_UNICODE),
+ 'srv_json' => json_encode($post_data['srv_json'],JSON_UNESCAPED_UNICODE),
+ ];
+ $res = $this->items_cost_model->update($data,['id'=>$row['id']]);
+ if(is_numeric($res)){
+ $this->items_cost_model->update_total($row['id']);
+ return $this->show_json(SYS_CODE_SUCCESS,'保存成功');
+ }else{
+ return $this->show_json(SYS_CODE_FAIL,'保存失败');
+ }
+ }
+
+ public function del(){
+
+ }
+
+ public function batch(){
+
+ }
+
+ public function export(){
+
+ }
+}
\ No newline at end of file
diff --git a/admin/views/items/cost/get.php b/admin/views/items/cost/get.php
new file mode 100644
index 00000000..798fa4c4
--- /dev/null
+++ b/admin/views/items/cost/get.php
@@ -0,0 +1,512 @@
+
+
+
\ No newline at end of file
diff --git a/admin/views/items/cost/lists.php b/admin/views/items/cost/lists.php
new file mode 100644
index 00000000..073201a9
--- /dev/null
+++ b/admin/views/items/cost/lists.php
@@ -0,0 +1,178 @@
+
+
+
+
共有= $pager['totle'] ?>条数据
+
+
+
+ 车辆
+ 销售收入合计
+ 采购及加装成本合计
+ 促销成本合计
+ 整车采购成本
+ 整车采购毛利
+ 保险收入合计
+ 按揭收入合计
+ 水平业务总毛利
+ 单车总毛利
+ 操作
+
+
+
+
+
+ {{v.vin}} {{v.title}}
+ {{v.sale_price}}
+ {{v.promotion_price}}
+ {{v.car_buy_price}}
+ {{v.car_profit_price}}
+ {{v.insurance_price}}
+ {{v.fee_carno_price}}
+ {{v.loan_price}}
+ {{v.srv_price}}
+ {{v.car_price}}
+
+ 查看
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/admin/views/items/goods/edit.php b/admin/views/items/goods/edit.php
index 7fca909a..8555c4a8 100644
--- a/admin/views/items/goods/edit.php
+++ b/admin/views/items/goods/edit.php
@@ -197,6 +197,12 @@
+
+
+
diff --git a/api/controllers/plan/Order.php b/api/controllers/plan/Order.php
index 42c628b9..cada47bc 100644
--- a/api/controllers/plan/Order.php
+++ b/api/controllers/plan/Order.php
@@ -17,126 +17,7 @@ class Order extends CI_Controller{
$this->load->model('app/liche/app_liche_orders_model');
$this->load->library('receiver/order_datas_entity');
- }
-
- public function index(){
-// $size = $this->input->get('size');
-// !$size && $size = 5;
-//
-// $t1 = 'lc_receiver_orders';
-// $t2 = 'lc_receiver_orders_v2';
-//
-// $fields = "$t1.*";
-// $where = [
-// "$t1.status>=" => 0,
-// "$t2.id is null" => null
-// ];
-//
-// $this->db->from("$t1");
-// $this->db->join("$t2", "$t2.id=$t1.id",'left');
-//
-// $this->db->select($fields);
-// $this->db->where($where);
-// $this->db->order_by("$t1.id asc");
-// $this->db->limit($size);
-// $rows = $this->db->get()->result_array();
-// if($rows){
-// foreach($rows as $key=>$val){
-// echo "执行old_id:{$val['id']} ";
-// if($val['status']==7){
-// $status = 2;
-// }elseif($val['status']==6){
-// $status = 1;
-// }else{
-// $status = 0;
-// }
-// $money_json = json_decode($val['money_json'],true);
-// !$money_json['price_book'] && $money_json['price_book'] = $val['deposit'];
-// $data = [
-// 'id' => $val['id'],
-// 'sid' => $val['sid'],
-// 'clue_id' => $val['clue_id'],
-// 'customer_id' => $val['rid'],
-// 'name' => $val['name'],
-// 'mobile' => $val['mobile'],
-// 'main_type' => $val['main_type'],
-// 'payway' => $val['payway'],
-// 'finance_id' => $val['finance_id'],
-// 'srv_ids' => $val['srv_ids'],
-// 'fines' => $val['fine_ids'],
-// 'brand_id' => $val['brand_id'],
-// 's_id' => $val['s_id'],
-// 'v_id' => $val['v_id'],
-// 'cor_id' => $val['cor_id'],
-// 'incor_id' => $val['incor_id'],
-// 'item_id' => $val['item_id'],
-// 'biz_id' => $val['biz_id'],
-// 'sale_id' => $val['admin_id'],
-// 'info_json' => $val['info_json'],
-// 'car_json' => $val['car_json'],
-// 'money_json' => $val['money_json'],
-// 'jsondata' => $val['jsondata'],
-// 'delry_time' => $val['delry_time'],
-// 'order_time' => $val['order_time'],
-// 'bill_time' => $val['bill_time'],
-// 'c_time' => $val['c_time'],
-// 'u_time' => $val['u_time'],
-// 'status' => $status
-// ];
-// $res = $this->receiver_orders_v2_model->add($data);
-// if($res){
-// echo "执行成功:{$val['id']} ";
-// }else{
-// echo "执行失败:{$val['id']} ";
-// }
-// }
-//
-// $where = [
-// "$t1.status>=" => 0,
-// "$t2.id is null" => null
-// ];
-//
-// $this->db->from("$t1");
-// $this->db->join("$t2", "$t2.id=$t1.id",'left');
-//
-// $this->db->select($fields);
-// $this->db->where($where);
-// $res = $this->db->count_all_results();
-// echo "剩余:{$res} ";
-// }
- }
-
- public function up_pay_status(){
-// $page = $this->input->get('page');
-// $size = $this->input->get('size');
-// !$page && $page = 1;
-// !$size && $size = 20;
-//
-// $where = [
-// 'id>=' => 10000,
-// 'status>=' => 0
-// ];
-// $rows = $this->receiver_orders_v2_model->select($where,'id asc',$page,$size);
-// if($rows){
-// foreach($rows as $key => $val){
-// $if_pay = $this->app_liche_orders_model->count(['o_id'=>$val['id'],'status'=>1]);
-// $s_row = $this->receiver_order_status_model->count(['o_id'=>$val['id'],'pid_status'=>0,'status'=>1]);
-// if($if_pay && !$s_row){
-// $data = [
-// 'o_id' => $val['id'],
-// 'pid_status' => 0,
-// 'status' => 1,
-// 'c_time' => time()
-// ];
-// $res = $this->receiver_order_status_model->add($data);
-// echo "update o_id:{$val['id']} ";
-// }else{
-// echo "undo o_id:{$val['id']} ";
-// }
-// }
-// }else{
-// echo 'finish';
-// }
+ $this->load->library('receiver/orders_v2_entity');
}
//更新旧订单数据状态
@@ -172,51 +53,6 @@ class Order extends CI_Controller{
echo "no data";
}
}
-
- public function up_order_time(){
-// $size = $this->input->get('size');
-// !$size && $size = 20;
-//
-// $t1 = 'lc_receiver_order_status';
-// $t2 = 'lc_receiver_orders_v2';
-//
-// $fields = "$t2.*";
-// $where = [
-// "$t1.pid_status" => 0,
-// "$t1.status" => 1,
-// "$t2.id>=" => 10000,
-// "$t2.order_time" => '0000-00-00 00:00:00',
-// ];
-//
-// $this->db->from("$t1");
-// $this->db->join("$t2", "$t2.id=$t1.o_id",'left');
-//
-// $this->db->select($fields);
-// $this->db->where($where);
-// $this->db->order_by("$t1.id asc");
-// $this->db->limit($size);
-// $rows = $this->db->get()->result_array();
-// if($rows){
-// foreach($rows as $key=>$val){
-// $where = [
-// 'o_id'=>$val['id'],
-// 'status'=>1,
-// "pay_time <>" => '0000-00-00 00:00:00',
-// ];
-// $pay_row = $this->app_liche_orders_model->select($where,'pay_time asc',1,1);
-// if($pay_row){
-// $order_time = $pay_row[0]['pay_time'];
-// $res = $this->receiver_orders_v2_model->update(['order_time'=>$order_time],['id'=>$val['id']]);
-// echo "订单id:{$val['id']},更新{$res} ";
-// }else{
-// echo "订单id:{$val['id']},未找到支付订单 ";
-// }
-// }
-// }else{
-// echo "no data";
-// }
-
- }
//过期未支付订单
public function out_time(){
@@ -254,97 +90,6 @@ class Order extends CI_Controller{
}
}
- //更新bd
- public function car_img(){
-// $oid = $this->input->get('oid');
-// $page = $this->input->get('page');
-// $size = $this->input->get('size');
-// !$page && $page = 1;
-// !$size && $size = 10;
-// $where = [
-// "ins_img <> ''" => null,
-// "o_id>=" => 1000,
-// ];
-// $oid && $where['o_id'] = $oid;
-// $rows = $this->receiver_order_datas_model->select($where,'id asc',$page,$size);
-// if($rows){
-// foreach ($rows as $item) {
-// $res = $this->order_datas_entity->orc_ins_img($item['o_id']);
-// echo "{$item['o_id']}执行结果:{$res}";
-// }
-// }else{
-// echo "no data";
-// }
- }
- //车型车牌号码
- public function up_num(){
-// $oid = $this->input->get('oid');
-// $page = $this->input->get('page');
-// $size = $this->input->get('size');
-// !$page && $page = 1;
-// !$size && $size = 10;
-// $where = [
-// "car_img <> ''" => null,
-// "o_id>=" => 1000,
-// ];
-// $oid && $where['o_id'] = $oid;
-// $rows = $this->receiver_order_datas_model->select($where,'id asc',$page,$size);
-// if($rows){
-// foreach ($rows as $item) {
-// $res = $this->order_datas_entity->up_car_num($item['o_id']);
-// echo "{$item['o_id']}执行结果:{$res}";
-// }
-// }else{
-// echo "no data";
-// }
- }
- //更新交付截止时间
- public function up_otime(){
-// $this->load->model('auto/auto_business_model');
-// $page = $this->input->get('page');
-// $size = $this->input->get('size');
-// !$page && $page = 1;
-// !$size && $size = 20;
-//
-// $where = [
-// 'id>=' => 10000,
-// ];
-// $rows = $this->receiver_orders_v2_model->select($where,'id asc',$page,$size);
-// if($rows){
-// foreach($rows as $key => $val){
-// $car_json = json_decode($val['car_json'],true);
-// $info_json = json_decode($val['info_json'],true);
-// $business_id = $info_json['business_id'];
-// $over_time = '0000-00-00 00:00:00';
-// if($business_id){
-// $business_row = $this->auto_business_model->get(['id'=>$business_id]);
-//
-// if($business_row['delivery_day']){
-// $contract = $this->receiver_order_contracts_model->get(['o_id' => $val['id'],'type in (0,1)' => null]);
-// $s_time = $contract ? $contract['c_time'] : $val['c_time'];
-// $over_time = date('Y-m-d H:i:s',$s_time+$business_row['delivery_day']*24*60*60); //交付截止时间
-// }
-//
-// $car_json['delivery_day'] = $business_row['delivery_day'];
-// }
-// $update = [
-// 'car_json' => json_encode($car_json,JSON_UNESCAPED_UNICODE)
-// ];
-// $over_time && $update['over_time'] = $over_time;
-// if($val['main_type']==1){
-// $update['owner_name'] = $info_json['c_company'];
-// }
-// if($update){
-// $this->receiver_orders_v2_model->update($update,['id'=>$val['id']]);
-// echo "update id:".$val['id']." ";
-// }else{
-// echo "not update id:".$val['id']." ";
-// }
-// }
-// }else{
-// echo 'finish';
-// }
- }
//更新保险图片
public function up_ins_img(){
@@ -566,4 +311,184 @@ class Order extends CI_Controller{
echo json_encode($res, JSON_UNESCAPED_UNICODE);
}
}
+
+ /**
+ * 添加成本数据
+ * @return void
+ */
+ public function cost(){
+ $this->load->model('receiver/order/receiver_order_bills_model', 'order_bills_model');
+ $this->load->model('receiver/order/receiver_order_loans_model','order_loans_model');
+ $this->load->model('receiver/order/receiver_order_datas_model');
+ $this->load->model("biz/biz_model");
+ $this->load->model('biz/biz_settle_srv_model');
+ $this->load->model('auto/auto_business_model');
+ $this->load->model('items/items_cost_model');
+ $page = $this->input->get('page');
+ $size = $this->input->get('size');
+ $id = $this->input->get('id');
+ !$page && $page = 1;
+ !$size && $size = 5;
+ $where = [
+ 'status' => 1,
+// 'bill_time>=' => '2022-12-07 00:00:00',
+ 'id not in (select o_id from lc_items_cost)' => null
+ ];
+ $where['id'] = $id;
+ $rows = $this->receiver_orders_v2_model->select($where,'',$page,$size);
+ if($rows){
+ foreach ($rows as $item) {
+ $biz = $this->biz_model->get(['id'=>$item['biz_id']]);
+ $money_json = json_decode($item['money_json'],true);
+ $info_json = json_decode($item['info_json'],true);
+ $bill_time_month = date('Y-m-d',strtotime($item['bill_time']));
+ $add_data = [
+ 'o_id' => $item['id'],
+ 'price' => $this->orders_v2_entity->total_price($item['id'],$item['money_json']),
+ 'c_time' => time()
+ ];
+ $item['item_id'] && $add_data['item_id'] = $item['item_id'];
+ $bill_info = $this->order_bills_model->bill_info($item['id']);
+ $bill_info['销货单位名称'] && $add_data['bill_name'] = $bill_info['销货单位名称'];
+ $bill_info['开票日期'] && $add_data['bill_time'] = $bill_info['开票日期'];
+ $bill_info['价税合计(小写)'] && $add_data['bill_price'] = str_replace('¥','',$bill_info['价税合计(小写)']);
+ $srv_json = [];
+ //精品
+ $srv_json['price_fine_select'] = $money_json['price_fine_select'] ? $money_json['price_fine_select'] : 0;
+ //保险
+ $img_data = $this->receiver_order_datas_model->get(['o_id'=>$item['id'],'status>='=>0]);
+ $insurance_img = json_decode($img_data['insurance_img'],true);
+ $business_img = json_decode($img_data['business_img'],true);
+ $srv_json['insurance_price'] = $insurance_img['price'] ? $insurance_img['price'] : '';
+ $srv_json['insurance_product'] = $insurance_img['product'] ? $insurance_img['product'] : '';
+ $srv_json['business_price'] = $business_img['price'] ? $business_img['price'] : '';
+ $srv_json['business_product'] = $business_img['product'] ? $business_img['product'] : '';
+ //获取创建订单时商务政策
+ $where = [
+ 'id' => $info_json['business_id'],
+ ];
+ $b_row_one = $this->auto_business_model->get($where);
+ $srv_json['price_floor'] = $b_row_one['price_floor'] ? $b_row_one['price_floor'] : 0;
+ $srv_json['profix_car'] = $biz['type']==2 ? $b_row_one['proxy_profix_car'] : $b_row_one['profix_car'];
+ $srv_json['insurance_ins_price'] = $srv_json['insurance_fd'] = 0;
+ if($insurance_img){//强险
+ $time = strtotime($insurance_img['date']);
+ $where = [
+ 'biz_id' => $item['biz_id'],
+ 'title' => $insurance_img['product'],
+ 'type' => 2,
+ "json_extract(jsondata, '$.type') = '2'" => null,
+ "json_extract(jsondata, '$.s_time') >= '{$time}'" => null,
+ "json_extract(jsondata, '$.e_time') <= '{$time}'" => null
+ ];
+ $fd_row = $this->biz_settle_srv_model->get($where);
+ if(!$fd_row){
+ $where = [
+ 'biz_id' => $item['biz_id'],
+ 'title' => $insurance_img['product'],
+ 'type' => 2,
+ 'is_def' => 1,
+ "json_extract(jsondata, '$.type') = '2'" => null,
+ ];
+ $fd_row = $this->biz_settle_srv_model->get($where);
+ }
+ $fd_jsondata = json_decode($fd_row['jsondata'],true);
+ $srv_json['insurance_fd'] = $fd_jsondata['rebate'] ? $fd_jsondata['rebate'] : 0;
+ $qx_fd = $fd_jsondata['rebate']/100;
+ $srv_json['insurance_ins_price'] = floatval($insurance_img['price']) * $qx_fd;
+ }
+ $srv_json['business_ins_price'] = $srv_json['business_fd'] = 0;
+ if($business_img){//商业险
+ $time = strtotime($business_img['date']);
+ $where = [
+ 'biz_id' => $item['biz_id'],
+ 'title' => $business_img['product'],
+ 'type' => 2,
+ "json_extract(jsondata, '$.type') = '1'" => null,
+ "json_extract(jsondata, '$.s_time') >= '{$time}'" => null,
+ "json_extract(jsondata, '$.e_time') <= '{$time}'" => null
+ ];
+ $bis_fd_row = $this->biz_settle_srv_model->get($where);
+ if(!$bis_fd_row){
+ $where = [
+ 'biz_id' => $item['biz_id'],
+ 'title' => $business_img['product'],
+ 'type' => 2,
+ 'is_def' => 1,
+ "json_extract(jsondata, '$.type') = '1'" => null,
+ ];
+ $bis_fd_row = $this->biz_settle_srv_model->get($where);
+ }
+ $bis_fd_jsondata = json_decode($bis_fd_row['jsondata'],true);
+ $srv_json['business_fd'] = $bis_fd_jsondata['rebate'] ? $bis_fd_jsondata['rebate'] : 0;
+ $bis_fd = $bis_fd_jsondata['rebate']/100;
+ $srv_json['business_ins_price'] = floatval($business_img['price'])*$bis_fd;
+ }
+ //挂牌
+ $srv_json['fee_carno'] = $money_json['fee_carno'] ? $money_json['fee_carno'] : 0;
+ $srv_json['cb_fee_carno'] = 0;
+ if($money_json['fee_carno']>0){
+ $where = [
+ 'biz_id' => $item['biz_id'],
+ 'type' => 1,
+ 'status' => 1,
+ 's_effect_time>=' => date('Y-m-01',strtotime($item['bill_time'])),
+ 's_effect_time<=' => date('Y-m-t',strtotime($item['bill_time'])),
+ ];
+ $free_row = $this->biz_settle_srv_model->get($where);
+ if(!$free_row){
+ $free_row = $this->biz_settle_srv_model->get(['biz_id'=>$item['biz_id'],'is_def'=>1,'status'=>1,'type'=>1]);
+ }
+ $free_jsondata = json_decode($free_row['jsondata'],true);
+ $srv_json['cb_fee_carno'] = $free_jsondata['price'] ? $free_jsondata['price'] : 0;
+ }
+ //贷款信息
+ $srv_json['loan_product'] = '';
+ $srv_json['loan_srv_price'] = $srv_json['loan_num'] = $srv_json['loan_price'] = 0;
+ if($money_json['price_loan']>0){
+ $srv_json['loan_price'] = $money_json['price_loan'];
+ $loan_row = $this->order_loans_model->get(['o_id'=>$item['id']]);
+ $finance_id = $item['finance_id'];
+ $srv_json['loan_product'] = $loan_row['title'];
+ $srv_json['loan_num'] = $finance_num = $loan_row['num'] ? $loan_row['num'] : 0;
+ $where = [
+ 'biz_id' => $item['biz_id'],
+ 'type' => 3,
+ 's_effect_time' => $bill_time_month,
+ "json_extract(jsondata, '$.finance_id') = '{$finance_id}'" => null,
+ "json_extract(jsondata, '$.finance_num') = '{$finance_num}'" => null,
+ ];
+ $fd_row = $this->biz_settle_srv_model->get($where);
+ if(!$fd_row){
+ $fd_row = $this->biz_settle_srv_model->get(['biz_id'=>$item['biz_id'],'is_def'=>1,'status'=>1,'type'=>3]);
+ }
+ $fd_jsondata = json_decode($fd_row['jsondata'],true);
+ $loan_fd = $fd_jsondata['rebate'] ? $fd_jsondata['rebate']/100:0;
+ $profix_loan = $money_json['price_loan']*$loan_fd;
+ //获取贷款手续费
+ $srv_loan = 0;
+ $s_json = json_decode($item['srv_ids'],true);
+ if($s_json){
+ foreach ($s_json as $v2) {
+ if($v2['key']=='price_finance'){
+ $srv_loan = $v2['price'];
+ break;
+ }
+ }
+ }
+ $srv_json['loan_srv_price'] = $profix_loan + $srv_loan;
+ }
+ $add_data['srv_json'] = json_encode($srv_json,JSON_UNESCAPED_UNICODE);
+ $id = $this->items_cost_model->add($add_data);
+ if(is_numeric($id)){
+ $this->items_cost_model->update_total($id);
+ echo "添加成功订单id:{$item['id']} ";
+ }else{
+ echo "添加失败订单id:{$item['id']} ";
+ }
+ }
+ }else{
+ echo "数据不存在";
+ }
+ }
}
diff --git a/common/libraries/receiver/Orders_v2_entity.php b/common/libraries/receiver/Orders_v2_entity.php
index 32ee463a..cd7449d3 100644
--- a/common/libraries/receiver/Orders_v2_entity.php
+++ b/common/libraries/receiver/Orders_v2_entity.php
@@ -156,18 +156,12 @@ class Orders_v2_entity{
$user = $this->ci->app_liche_users_model->get(['mobile'=>$this->order_row['owner_mobile']]);
return $user;
}
- /**
- * 获取订单服务费
- * @param $oid int 订单id
- * @param $res_type string 返回数据格式
- * @param $is_fines int(0否 1是) 是否包含精品选装
- * @return int
- */
+
/**
* 获取订单服务费
* @param $oid int 订单id
* @param $res_type string 返回数据格式
- * @param $is_fines int
+ * @param $is_fines int(0否 1是) 是否包含精品选装
* @return array|int|mixed
*/
public function order_srv_money($oid,$res_type = '',$is_fines=1){
diff --git a/common/models/items/Items_cost_model.php b/common/models/items/Items_cost_model.php
new file mode 100644
index 00000000..0631fb8e
--- /dev/null
+++ b/common/models/items/Items_cost_model.php
@@ -0,0 +1,66 @@
+table_name, 'default');
+ }
+
+ /**
+ * 更新合计数据
+ * @param $id
+ * @return bool
+ */
+ public function update_total($id){
+ $this->load->model('items/items_model');
+ $row = $this->get(['id'=>$id]);
+ if($row){
+ $item_row = $this->items_model->get(['id'=>$row['item_id']]);
+ $cost_json = json_decode($row['cost_json'],true);
+ $promotion_json = json_decode($row['promotion_json'],true);
+ $srv_json = json_decode($row['srv_json'],true);
+ //【销售收入合计】(实际售价+选装实收)
+ $sale_price = $row['price'] + $srv_json['price_fine_select'];
+ //【采购及加装成本合计】(采购成本 + 选装成本 + 选装工时费 )
+ $buy_price = $item_row['buy_price'] + $cost_json['select_price'] + $srv_json['labor_price'];
+ //【促销成本合计】(销售佣金+其他)
+ $promotion_price = $promotion_json['sale_price'] + $promotion_json['other'];
+ //【整车采购成本】(采购成本-厂家补贴)
+ $car_buy_price = $item_row['buy_price'] - $promotion_json['factory_price'];
+ //【整车采购毛利】(销售收入合计 - 整车采购成本 - 促销成本合计 - 选装金额 -选装工时费)
+ $car_profit_price = $sale_price - $car_buy_price - $promotion_price - $cost_json['select_price'] - $cost_json['labor_price'];
+ //【保险收入合计】
+ $insurance_price = $srv_json['business_ins_price']+$srv_json['insurance_ins_price']-$srv_json['back_price'];
+ //【挂牌收入合计】
+ $fee_carno_price = $srv_json['fee_carno'] - $srv_json['cb_fee_carno'];
+ //【按揭收入合计】(按揭综合服务费+按揭解抵服务费+利息补贴收入+金融公司手续费收入+其他收入-其他支出)
+ $loan_price = $srv_json['loan_srv_price']+$srv_json['loan_offset_price']+$srv_json['loan_subsidy_price']+$srv_json['commission_price']+$srv_json['loan_in_price']-$srv_json['loan_out_price'];
+ //【水平业务总毛利】(保险收入合计+挂牌收入合计+按揭收入合计+其他收入-其他支出)
+ $srv_price = $insurance_price+$fee_carno_price+$loan_price+$srv_json['other_in_price']-$srv_json['other_out_price'];
+ //【直营店单车毛利/代理店单车毛利/合伙店采购毛利】(根据门店类型取, 商务政策分润 - 选装金额 - 选装工时费 - 促销成本 + 水平业务总毛利 + (实际售价入 - 商务政策底价))
+ $car_price = $srv_json['profix_car']-$cost_json['select_price']-$cost_json['labor_price'] - $promotion_price + $srv_price + ($row['price']-$srv_json['price_floor']);
+ //【品牌单车总毛利】(单车总毛利 - 直营店单车毛利/代理店单车毛利/合伙店采购毛利)
+
+ $data = [
+ 'sale_price' => $sale_price,
+ 'buy_price' => $buy_price,
+ 'promotion_price' => $promotion_price,
+ 'car_buy_price' => $car_buy_price,
+ 'car_profit_price' => $car_profit_price,
+ 'insurance_price' => $insurance_price,
+ 'fee_carno_price' => $fee_carno_price,
+ 'loan_price' => $loan_price,
+ 'srv_price' => $srv_price,
+ 'car_price' => $car_price,
+ ];
+ $this->update($data,['id'=>$id]);
+ return true;
+ }else{
+ return false;
+ }
+ }
+}
diff --git a/common/models/receiver/order/Receiver_order_bills_model.php b/common/models/receiver/order/Receiver_order_bills_model.php
index 8f34ba27..27b76b25 100644
--- a/common/models/receiver/order/Receiver_order_bills_model.php
+++ b/common/models/receiver/order/Receiver_order_bills_model.php
@@ -51,4 +51,20 @@ class Receiver_order_bills_model extends HD_Model
public function get_status(){
return $this->status_arr;
}
+
+ /**
+ * 获取发票信息
+ * @return array
+ */
+ public function bill_info($oid){
+ $res = [];
+ $row = $this->get(['o_id'=>$oid],'jsondata');
+ $jsondata = json_decode($row['jsondata'],true);
+ if($jsondata['infos']){
+ foreach ($jsondata['infos'] as $key => $val) {
+ $res[$val['Name']] = $val['Value'];
+ }
+ }
+ return $res;
+ }
}