242 lines
9.1 KiB
PHP
242 lines
9.1 KiB
PHP
<?php
|
|
defined('BASEPATH') OR exit('No direct script access allowed');
|
|
|
|
class Toole extends CI_Controller {
|
|
|
|
public function __construct(){
|
|
parent::__construct();
|
|
$this->load->model('receiver/order/receiver_orders_model','orders_model');
|
|
$this->load->model('receiver/order/receiver_order_signs_model','order_signs_model');
|
|
$this->load->model('receiver/order/receiver_order_loans_model','order_loans_model');
|
|
$this->load->model('receiver/order/receiver_order_ckcars_model','order_ckcars_model');
|
|
$this->load->model('receiver/order/receiver_order_bills_model','order_bills_model');
|
|
$this->load->model('receiver/order/receiver_order_agents_model','order_agents_model');
|
|
$this->load->model('receiver/order/receiver_order_deliverys_model','order_deliverys_model');
|
|
$this->load->model('receiver/order/receiver_order_contracts_model','order_contracts_model');
|
|
}
|
|
|
|
public function index(){
|
|
$data['mobile'] = $mobile = $this->input->get('mobile');
|
|
if($mobile){
|
|
$data['status_name'] = $this->orders_model->get_status();
|
|
$data['lists'] = $this->orders_model->select(['mobile'=>$mobile],'id desc',0,0,'id,name,mobile,status');
|
|
}
|
|
$this->load->view('/h5/toole/index',$data);
|
|
}
|
|
public function detail(){
|
|
$id = $this->input->get('id');
|
|
$row = $this->orders_model->get(['id'=>$id]);
|
|
if($row['status']>=2){
|
|
$ckcar = $this->order_ckcars_model->get(['o_id'=>$id],'status');
|
|
$row['ckcar_status'] = $ckcar['status'];
|
|
}
|
|
if($row['status']>=3){
|
|
$bill = $this->order_bills_model->get(['o_id'=>$id],'status');
|
|
$row['bill_status'] = $bill['status'];
|
|
}
|
|
if($row['status']>=4){
|
|
$agent = $this->order_agents_model->get(['o_id'=>$id],'status');
|
|
$row['agent_status'] = $agent['status'];
|
|
}
|
|
$data['row'] = $row;
|
|
$this->load->view('/h5/toole/detail',$data);
|
|
}
|
|
|
|
//一键完成分期
|
|
public function fh_loan(){
|
|
$id = $this->input->post('id');
|
|
$row = $this->orders_model->get(['id'=>$id]);
|
|
if(!$row){
|
|
$this->show_json(0,'参数错误');
|
|
}
|
|
if($row['status']!=1){
|
|
$this->show_json(0,'该订单未到分期状态');
|
|
}
|
|
$result = $this->order_loans_model->update(['status'=>1],['o_id'=>$row['id']]);
|
|
if($result){
|
|
$this->orders_model->update(['status'=>2],['id'=>$row['id']]);
|
|
$ckcar = $this->order_ckcars_model->get(['o_id'=>$row['id']]);
|
|
$replace = [
|
|
'o_id' => $row['id'],
|
|
'status' => 0,
|
|
'c_time' => time()
|
|
];
|
|
$ckcar && $replace['id'] = $ckcar['id'];
|
|
$this->order_ckcars_model->replace($replace);
|
|
$this->show_json(1,'修改成功');
|
|
}else{
|
|
$this->show_json(0,'修改失败');
|
|
}
|
|
}
|
|
//一键完成配车
|
|
public function fh_ckcar(){
|
|
$this->load->model("items/items_model");
|
|
$id = $this->input->post('id');
|
|
$row = $this->orders_model->get(['id'=>$id]);
|
|
if(!$row){
|
|
$this->show_json(0,'参数错误');
|
|
}
|
|
if($row['status']>=3){
|
|
$this->show_json(0,'用户确认,不能修改');
|
|
}
|
|
$where = [
|
|
's_id' => $row['s_id'],
|
|
'v_id' => $row['v_id'],
|
|
'cor_id' => $row['cor_id'],
|
|
'incor_id' => $row['incor_id'],
|
|
];
|
|
$item = $this->items_model->get($where);
|
|
if(!$item){
|
|
unset($where['incor_id']);
|
|
$item = $this->items_model->get($where);
|
|
if(!$item){
|
|
unset($where['cor_id']);
|
|
$item = $this->items_model->get($where);
|
|
if(!$item){
|
|
unset($where['v_id']);
|
|
$item = $this->items_model->get($where);
|
|
}
|
|
}
|
|
}
|
|
if(!$item){
|
|
$this->show_json(0,'未找到车辆信息');
|
|
}
|
|
$item_id = $item['id'];
|
|
$this->orders_model->update(['item_id'=>$item_id],['id'=>$id]);
|
|
$ckcars = $this->order_ckcars_model->get(['o_id'=>$id]);
|
|
if(!$ckcars){
|
|
$add_data = [
|
|
'o_id' => $id,
|
|
'status' => 1,
|
|
'c_time' => time()
|
|
];
|
|
$result = $this->order_ckcars_model->add($add_data);
|
|
}else{
|
|
$result = $this->order_ckcars_model->update(['status'=>1],['id'=>$ckcars['id']]);
|
|
}
|
|
if($result){
|
|
$this->show_json(1,'修改成功');
|
|
}else{
|
|
$this->show_json(0,'修改失败');
|
|
}
|
|
}
|
|
//一键完成开票信息
|
|
public function fh_bill(){
|
|
$id = $this->input->post('id');
|
|
$row = $this->orders_model->get(['id'=>$id]);
|
|
if(!$row){
|
|
$this->show_json(0,'参数错误');
|
|
}
|
|
if($row['status']!=3){
|
|
$this->show_json(0,'修改失败,该订单不处于开票阶段');
|
|
}
|
|
$result = $this->order_bills_model->update(['status'=>2,'file'=>'liche/2021/08/1337ff6686152d45/f30b803379255919.jpeg'],['o_id'=>$id]);
|
|
$this->orders_model->update(['status'=>4],['id'=>$row['id']]);
|
|
if(!$this->order_agents_model->get(['o_id'=>$id])){
|
|
$this->order_agents_model->add(['o_id'=>$id,'c_time'=>time]);
|
|
}
|
|
$this->show_json(1,'修改成功');
|
|
|
|
}
|
|
//一键完成代办信息
|
|
public function fh_agent(){
|
|
$id = $this->input->post('id');
|
|
$row = $this->orders_model->get(['id'=>$id]);
|
|
if(!$row){
|
|
$this->show_json(0,'参数错误');
|
|
}
|
|
if($row['status']!=4){
|
|
$this->show_json(0,'修改失败,该订单不处于代办阶段');
|
|
}
|
|
$agent = $this->order_agents_model->get(['o_id'=>$id]);
|
|
$up_data = [
|
|
'car_num' => '闽DXXXXXX',
|
|
'car_img' => 'liche/2021/08/4e3bbf015016a9be/6ae15d0a363cc527.jpeg',
|
|
'ins_img' => json_encode(['liche/2021/08/538fbf6c419d5958/5e4b8a5af1fbd4b6.jpeg']),
|
|
'ins_time' => '2022-12-12',
|
|
'status' => 1,
|
|
];
|
|
if($agent){
|
|
$this->order_agents_model->update($up_data,['o_id'=>$id]);
|
|
}else{
|
|
$up_data['o_id'] = $row['id'];
|
|
$up_data['c_time'] = time();
|
|
$this->order_agents_model->add($add_data);
|
|
}
|
|
$this->orders_model->update(['status'=>5],['id'=>$id]);
|
|
if(!$this->order_deliverys_model->count(['o_id'=>$id])){
|
|
$this->order_deliverys_model->add(['o_id'=>$id,'c_time'=>time]);
|
|
}
|
|
$this->show_json(1,'修改成功');
|
|
}
|
|
//重新生成pdf文件
|
|
public function pdf(){
|
|
$type = $this->input->get('type');
|
|
$this->load->view('/h5/toole/pdf',$data);
|
|
}
|
|
|
|
public function c_pdf(){
|
|
$params = $this->input->post();
|
|
if(!$params['oid']){
|
|
$this->show_json(0,'请填写订单id');
|
|
}
|
|
if(!$params['type']){
|
|
$this->show_json(0,'请选择合同类型');
|
|
}
|
|
if (false === strpos($_SERVER['HTTP_HOST'], 'dev')) { //不是dev判断订单是否存在
|
|
$row = $this->orders_model->get(['id'=>$params['oid']]);
|
|
if(!$row){
|
|
$this->show_json(0,'订单不存在');
|
|
}
|
|
}
|
|
$url = 'https://api.liche.cn/wxapp/licheb/protocol/';
|
|
if($params['type']==1){ //买卖合同
|
|
$url.="car?id=".$params['oid'];
|
|
}elseif($params['type']==2){ //服务协议
|
|
$url.="agent?id=".$params['oid'];
|
|
}elseif($params['type']==3){
|
|
$url.="car_ck?id=".$params['oid'];
|
|
}elseif($params['type']==4){
|
|
$url.="car_sp?id=".$params['oid'];
|
|
}elseif($params['type']==5){
|
|
$url.="agent_sp?id=".$params['oid'];
|
|
}else{
|
|
$this->show_json(0,'参数错误,未知合同类型');
|
|
}
|
|
$this->load->library('pdf');
|
|
$pdf = new Pdf();
|
|
$save_path = 'data/contracts/'.date('Ymd');
|
|
$filename = time().'.pdf';
|
|
$res = $pdf -> html2pdf($url,FCPATH.$save_path,$filename);
|
|
if(!$res){
|
|
$this->show_json(0,'创建pdf文件失败');
|
|
}
|
|
$data['pdf_url'] = http_host_com('home').'/'.$save_path.'/'.$filename;
|
|
$imgs = $pdf->pdf2img($data['pdf_url']);//pdf文件转图片
|
|
$full_imgs = [];
|
|
if($imgs){
|
|
$this->load->library('qiniu');
|
|
//上传七牛并保存
|
|
foreach($imgs as $key=>$val){
|
|
$file_name = md5($val).'.jpg';
|
|
$img_res = $this->qiniu->fetch($val,$file_name);
|
|
if($img_res){
|
|
$imgs[$key] = $img_res['file'];
|
|
$full_imgs[$key] = $img_res['url'];
|
|
}
|
|
}
|
|
}
|
|
$data['imgs'] = $imgs;
|
|
$data['full_imgs'] = $full_imgs;
|
|
$this->show_json(1,'创建成功',$data);
|
|
}
|
|
|
|
private function show_json($code,$msg,$info=[]){
|
|
$data['code'] = $code;
|
|
$data['msg'] = $msg;
|
|
$data['data'] = $info;
|
|
die(json_encode($data,JSON_UNESCAPED_UNICODE));
|
|
}
|
|
|
|
}
|