load->model('receiver/order/receiver_orders_model','orders_model'); $this->load->model('receiver/order/receiver_order_contracts_model','contracts_model'); $this->load->model('receiver/order/receiver_order_agents_model','agents_model'); $this->load->model('receiver/order/receiver_order_loans_model','loans_model'); $this->load->model('receiver/order/receiver_order_ckcars_model','ckcars_model'); $this->load->model('receiver/order/receiver_order_deliverys_model','deliverys_model'); $this->load->model('receiver/order/receiver_order_oplogs_model'); $this->load->model('receiver/receiver_fine_model'); $this->load->model('receiver/receiver_service_package_model','package_model'); $this->load->model('receiver/receiver_services_model','services_model'); $this->load->model('auto/auto_series_model'); $this->load->model('auto/auto_brand_model'); $this->load->model('auto/auto_attr_model'); $this->load->model("biz/biz_model"); $this->load->model('area_model'); $this->load->model("sys/sys_company_model"); $this->load->model("items/items_model"); $this->load->model('app/liche/app_liche_orders_model'); $wxapp = $this->input->get('wxapp'); $this->folder = $wxapp ? 'protocol' : 'html2pdf'; } //整车合同 public function car(){ $id = $this->input->get('id'); $row = $this->orders_model->get(['id'=>$id]); $contract = $this->contracts_model->get(['o_id'=>$id,'type'=>0]); if($row){ $money_json = json_decode($row['money_json'],true); $money_json['price_discount'] && $row['price'] = $row['price'] - $money_json['price_discount']; $brand = $this->auto_brand_model->get(['id'=>$row['brand_id']],'name'); $series = $this->auto_series_model->get(['id'=>$row['s_id']],'name'); $version = $this->auto_attr_model->get(['id'=>$row['v_id']],'title'); $color = $this->auto_attr_model->get(['id'=>$row['cor_id']],'title'); $incolor = $this->auto_attr_model->get(['id'=>$row['incor_id']],'title'); $row['version'] = $version['title'] ? $version['title'] : ''; $row['color'] = $color['title'] ? $color['title'] : ''; $row['incolor'] = $incolor['title'] ? $incolor['title'] : ''; $row['brand_name'] = $brand['name']; $row['series_name'] = $series['name']; //获取门店信息 $biz = $this->biz_model->get(['id'=>$row['biz_id']]); if($this->order_row['brand_id']==5){ //品牌哪吒 销售公司改为泉州狸车 $biz['company_id'] = 2; } $city = $this->area_model->get(['county_id'=>$biz['county_id']],'city_name,county_name'); $row['address'] = $city['city_name'].$city['county_name'].'  '.$biz['address'] .'  '. $biz['biz_name']; $company = $this->sys_company_model->get(['id'=>$biz['company_id']]); $row['company'] = $company; if($row['s_id']==24){ //零跑T03 $row['give_time'] = 60; }elseif($row['s_id']==25){ //零跑C11 $row['give_time'] = 120; }else{ //其它车型 $row['give_time'] = 45; } //获取精品 $fine_title = '无'; if($row['fine_ids']){ $fine_rows = $this->receiver_fine_model->select(["id in ({$row['fine_ids']})"=>null],'','','','title'); $fine_title = implode(',',array_column($fine_rows,'title')); } $row['fine_title'] = $fine_title; } $row['info_json'] = json_decode($row['info_json'],true); $row['price_rmb'] = num_to_rmb($row['price']); $row['cid'] = $contract['cid']; $row['day'] = $contract ? date('Y年m月d日',$contract['c_time']):date('Y年m月d日'); $row['dep_price'] = number_format($row['deposit'],2); //定金 $this->load->view("wxapp/licheb/{$this->folder}/car",$row); } //代理合同 public function agent(){ $id = $this->input->get('id'); $row = $this->orders_model->get(['id'=>$id]); $contract = $this->contracts_model->get(['o_id'=>$id,'type'=>1]); $srv_price = 0; $services = []; if($row){ $money_json = json_decode($row['money_json'],true); $jsondata = json_decode($row['jsondata'],true); //获取门店信息 $biz = $this->biz_model->get(['id'=>$row['biz_id']]); if($biz['srv_company_id']){ $row['company'] = $this->sys_company_model->get(['id'=>$biz['srv_company_id']]); }else{ $row['company'] = $this->sys_company_model->get(["title like '%服务%'"=>null,'status'=>1]); } if($row['srv_ids']){ $money_json = json_decode($row['money_json'],true); $service_rows = $this->services_model->select(["id in ({$row['srv_ids']})"=>null],'','','','id,title,field_name'); foreach($service_rows as $key=>$val){ $field_arr = explode('.',$val['field_name']); if(isset($money_json[$field_arr[1]])){ //保险费不收 $services[] = [ 'id' => $val['id'], 'title' => $val['title'], 'money' => $money_json[$field_arr[1]] ]; } } $srv_id_arr = explode(',',$row['srv_ids']); } if($jsondata['if_fine']){ //选择精品包 $fine_price = $money_json['price_fine_discount'] ? $money_json['price_fine'] - $money_json['price_fine_discount'] : $money_json['price_fine']; $services[] = [ 'id' => '', 'title' => '精品尊享包', 'money' => $fine_price ]; } $this->load->library('receiver/orders_entity'); $srv_price = $this->orders_entity->order_srv_money($row['id']); } $row['services'] = $services; $row['srv_price'] = $srv_price; $row['info_json'] = json_decode($row['info_json'],true); $row['day'] = $contract ? date('Y年m月d日',$contract['c_time']):date('Y年m月d日'); $row['cid'] = $contract['cid']; $this->load->view("wxapp/licheb/{$this->folder}/agent",$row); } //车辆信息确认单 public function car_ck(){ $id = $this->input->get('id'); $row = $this->orders_model->get(['id'=>$id]); if($row){ $brand = $this->auto_brand_model->get(['id'=>$row['brand_id']],'name'); $series = $this->auto_series_model->get(['id'=>$row['s_id']],'name'); $version = $this->auto_attr_model->get(['id'=>$row['v_id']],'title'); $color = $this->auto_attr_model->get(['id'=>$row['cor_id']],'title'); $incolor = $this->auto_attr_model->get(['id'=>$row['incor_id']],'title'); $row['brand_name'] = $brand['name'].$series['name'].' '.$version['title']." {$color['title']}(内饰{$incolor['title']})"; //获取门店信息 $biz = $this->biz_model->get(['id'=>$row['biz_id']]); if($this->order_row['brand_id']==5){ //品牌哪吒 销售公司改为泉州狸车 $biz['company_id'] = 2; } $company = $this->sys_company_model->get(['id'=>$biz['company_id']]); $row['company'] = $company; } $contract = $this->contracts_model->get(['o_id'=>$id,'type'=>2]); $items = $this->items_model->get(['id'=>$row['item_id']],'vin'); $row['info_json'] = json_decode($row['info_json'],true); $row['day'] = $contract ? date('Y年m月d日',$contract['c_time']):date('Y年m月d日'); $row['cid'] = $contract['cid']; $row['vin'] = $items['vin']; $this->load->view("wxapp/licheb/{$this->folder}/car_ck",$row); } //车辆交接信息 public function car_fh(){ $this->load->model('app/licheb/app_licheb_users_model'); $id = $this->input->get('id'); $row = $this->orders_model->get(['id'=>$id]); $agent = $this->agents_model->get(['o_id'=>$id]); $contract = $this->contracts_model->get(['o_id'=>$id,'type'=>3]); $items = $this->items_model->get(['id'=>$row['item_id']],'vin'); $srv_price = 0; if($row){ $money_json = json_decode($row['money_json'],true); $money_json['price_discount'] && $row['price'] = $row['price'] - $money_json['price_discount']; //贷款 if(!$row['payway']){ $row['loan'] = $this->loans_model->get(['o_id'=>$id]); } $brand = $this->auto_brand_model->get(['id'=>$row['brand_id']],'name'); $series = $this->auto_series_model->get(['id'=>$row['s_id']],'name'); $row['info_json'] = $info_json = json_decode($row['info_json'],true); $version = $this->auto_attr_model->get(['id'=>$row['v_id']],'title'); $color = $this->auto_attr_model->get(['id'=>$row['cor_id']],'title'); $incolor = $this->auto_attr_model->get(['id'=>$row['incor_id']],'title'); $row['version'] = $version['title'] ? $version['title'] : ''; $row['color'] = $color['title'] ? $color['title'] : ''; $row['incolor'] = $incolor['title'] ? $incolor['title'] : ''; $row['brand_name'] = $brand['name']; $row['series_name'] = $series['name']; $row['cardid'] = $info_json['cardid']; //获取门店信息 $biz = $this->biz_model->get(['id'=>$row['biz_id']]); if($this->order_row['brand_id']==5){ //品牌哪吒 销售公司改为泉州狸车 $biz['company_id'] = 2; } $company = $this->sys_company_model->get(['id'=>$biz['company_id']]); $row['company'] = $company; $where = [ 'o_id' => $row['id'], 'status' => 1, 'type in (1,2,4,5)' => null ]; $pay = $this->app_liche_orders_model->sum('total_price',$where); //尾款 $p_row = $this->app_liche_orders_model->get(['o_id'=>$row['id'],'pid'=>0,'status>='=>0],'id'); $where = [ 'o_id' => $row['id'], 'status' => 1, 'type' => 3, 'pid!=' => $p_row['id'] ]; $last_pay = $this->app_liche_orders_model->sum('total_price',$where); $row['pay_price'] = $pay['total_price'] + $last_pay['total_price']; $this->load->library('receiver/orders_entity'); $srv_price = $this->orders_entity->order_srv_money($row['id']); $row['delivery'] = $this->deliverys_model->get(['o_id'=>$row['id']],'info,tool,remark'); } $row['srv_price'] = $srv_price; $row['agent'] = $agent; $row['day'] = $contract ? date('Y年m月d日',$contract['c_time']):date('Y年m月d日'); $row['cid'] = $contract['cid']; $row['vin'] = $items['vin']; $this->load->view("wxapp/licheb/{$this->folder}/car_fh",$row); } //车辆买卖合同补充协议书 public function car_sp(){ $id = $this->input->get('id'); $row = $this->orders_model->get(['id'=>$id]); $row['old_contract'] = $this->contracts_model->get(['o_id'=>$id,'type'=>0]); //买卖合同 $contract = $this->contracts_model->get(['o_id'=>$id,'type'=>4]); if($row){ $money_json = json_decode($row['money_json'],true); $money_json['price_discount'] && $row['price'] = $row['price'] - $money_json['price_discount']; $brand = $this->auto_brand_model->get(['id'=>$row['brand_id']],'name'); $series = $this->auto_series_model->get(['id'=>$row['s_id']],'name'); $version = $this->auto_attr_model->get(['id'=>$row['v_id']],'title'); $color = $this->auto_attr_model->get(['id'=>$row['cor_id']],'title'); $incolor = $this->auto_attr_model->get(['id'=>$row['incor_id']],'title'); $row['version'] = $version['title'] ? $version['title'] : ''; $row['color'] = $color['title'] ? $color['title'] : ''; $row['incolor'] = $incolor['title'] ? $incolor['title'] : ''; $row['brand_name'] = $brand['name']; $row['series_name'] = $series['name']; //获取门店信息 $biz = $this->biz_model->get(['id'=>$row['biz_id']]); if($this->order_row['brand_id']==5){ //品牌哪吒 销售公司改为泉州狸车 $biz['company_id'] = 2; } $city = $this->area_model->get(['county_id'=>$biz['county_id']],'city_name,county_name'); $row['address'] = $city['city_name'].$city['county_name'].'  '.$biz['address'] .'  '. $biz['biz_name']; $company = $this->sys_company_model->get(['id'=>$biz['company_id']]); $row['company'] = $company; //获取选择代办包 $srv_total = count(explode(',',$row['srv_ids'])); if($srv_total==4){ $row['give_time'] = 30; }elseif($srv_total==3){ $row['give_time'] = 45; }else{ $row['give_time'] = 60; } } //修改信息 $opt_row = $this->receiver_order_oplogs_model->select(['order_id'=>$row['id'],'type'=>3],'id desc',1,1);//最后修改日志 $opt_row = json_decode($opt_row[0]['log_json'],true); $opt_money_json = json_decode($opt_row['money_json'],true); $opt_money_json['price_discount'] && $opt_row['price'] - $opt_money_json['price_discount']; $money_json = json_decode($row['money_json'],true); $money_json['price_discount'] && $row['price'] - $money_json['price_discount']; $b_price = num_to_rmb($row['price']); $price = number_format($row['price'],2); $logs = []; if($opt_row){ $diff_key_arr = ['s_id','v_id','cor_id','incor_id']; $diff_price = $diff_car = false; foreach($diff_key_arr as $item){ if($opt_row[$item]!=$row[$item]){ $diff_car = true; break; } } if($money_json['price_discount']!=$opt_money_json['price_discount'] || $row['price']!=$opt_row['price']){ $diff_price = true; } if($diff_car){ $brand = $this->auto_brand_model->get(['id'=>$row['brand_id']],'name'); $series = $this->auto_series_model->get(['id'=>$row['s_id']],'name'); $old_brand = $this->auto_brand_model->get(['id'=>$opt_row['brand_id']],'name'); $old_series = $this->auto_series_model->get(['id'=>$opt_row['s_id']],'name'); $attr_arr = [ $row['v_id'],$row['cor_id'],$row['incor_id'],$opt_row['v_id'],$opt_row['cor_id'],$opt_row['incor_id'] ]; $attr_str = implode(',',array_filter($attr_arr)); $where = [ "id in ({$attr_str})" => null ]; $attr_rows = $this->auto_attr_model->map('id','',$where); $version = $attr_rows[$row['v_id']] ? $attr_rows[$row['v_id']][0]['title'] : ''; $cor = $attr_rows[$row['cor_id']] ? $attr_rows[$row['cor_id']][0]['title'] : ''; $incor = $attr_rows[$row['incor_id']] ? $attr_rows[$row['incor_id']][0]['title'] : ''; $old_version = $attr_rows[$opt_row['v_id']] ? $attr_rows[$opt_row['v_id']][0]['title'] : ''; $old_cor = $attr_rows[$opt_row['cor_id']] ? $attr_rows[$opt_row['cor_id']][0]['title'] : ''; $old_incor = $attr_rows[$opt_row['incor_id']] ? $attr_rows[$opt_row['incor_id']][0]['title'] : ''; $new_car = "{$brand['name']}{$series['name']}{$version}{$cor}(内饰{$incor})"; $old_car = "{$old_brand['name']}{$old_series['name']}{$old_version}{$old_cor}(内饰{$old_incor})"; $logs[0] = "购买车型由 {$old_car} 变更为 {$new_car}"; } if($diff_price){ $old_price = number_format($opt_row['price'],2); $logs[] = "车辆单价由 {$old_price} 变更为 {$price} 车辆总价:{$price}元, {$b_price}"; } if($row['payway']!=$opt_row['payway']){ $old_payway = $opt_row['payway'] ? '一次性付款' : '分期付款'; $payway = $row['payway'] ? '一次性付款' : '分期付款'; $logs[] = "付款方式由 {$old_payway} 变更为 {$payway}"; } } $row['logs'] = $logs; $row['info_json'] = json_decode($row['info_json'],true); $row['price_rmb'] = num_to_rmb($row['price']); $row['cid'] = $contract['cid']; $row['day'] = $contract ? date('Y年m月d日',$contract['c_time']):date('Y年m月d日'); $row['dep_price'] = number_format($row['deposit'],2); //定金 $this->load->view("wxapp/licheb/{$this->folder}/car_sp",$row); } //委托服务补充协议书 public function agent_sp(){ $id = $this->input->get('id'); $row = $this->orders_model->get(['id'=>$id]); $row['old_contract'] = $this->contracts_model->get(['o_id'=>$id,'type'=>1]); $contract = $this->contracts_model->get(['o_id'=>$id,'type'=>5]); $srv_price = 0; $old_services = $services = '无'; if($row){ //获取修改前数据 $opt_row = $this->receiver_order_oplogs_model->select(['order_id'=>$row['id'],'type'=>3],'id desc',1,1);//最后修改日志 $opt_row = json_decode($opt_row[0]['log_json'],true); $old_jsondata = json_decode($opt_row['jsondata'],true); $money_json = json_decode($row['money_json'],true); $jsondata = json_decode($row['jsondata'],true); //获取门店信息 $biz = $this->biz_model->get(['id'=>$row['biz_id']]); if($biz['srv_company_id']){ $row['company'] = $this->sys_company_model->get(['id'=>$biz['srv_company_id']]); }else{ $row['company'] = $this->sys_company_model->get(["title like '%服务%'"=>null,'status'=>1]); } if($row['srv_ids']){ $service_rows = $this->services_model->select(["id in ({$row['srv_ids']})"=>null],'','','','title'); $service_array = array_column($service_rows,'title'); } $jsondata['if_fine'] && $service_array[]='精品尊享包'; $services = implode(',',$service_array); if($opt_row['srv_ids']){ $service_rows = $this->services_model->select(["id in ({$opt_row['srv_ids']})"=>null],'','','','title'); $old_service_array = array_column($service_rows,'title'); } $old_jsondata['if_fine'] && $old_service_array[]='精品尊享包'; $old_services = implode(',',$old_service_array); $this->load->library('receiver/orders_entity'); $srv_price = $this->orders_entity->order_srv_money($row['id']); } $row['services'] = $services; $row['old_services'] = $old_services; $row['srv_price'] = $srv_price; $row['info_json'] = json_decode($row['info_json'],true); $row['day'] = $contract ? date('Y年m月d日',$contract['c_time']):date('Y年m月d日'); $row['cid'] = $contract['cid']; $this->load->view("wxapp/licheb/{$this->folder}/agent_sp",$row); } }