222 lines
9.1 KiB
PHP
222 lines
9.1 KiB
PHP
<?php
|
|
defined('WXAPP_APP') OR exit('No direct script access allowed');
|
|
|
|
/**
|
|
* Created by Vim
|
|
* User: lcc
|
|
* Date: 2021/07/12
|
|
* Time: 16:08
|
|
*/
|
|
require_once APPPATH.'controllers/wxapp/Wxapp.php';
|
|
class Contract extends Wxapp{
|
|
|
|
function __construct($inputs, $app_key){
|
|
parent::__construct($inputs, $app_key);
|
|
|
|
$this->login_white = array();//登录白名单
|
|
$this->check_status = array();//用户状态校验
|
|
$this->check_mobile = array();//需要手机号
|
|
$this->check_headimg =array();//授权微信信息
|
|
$this->load->model('receiver/order/receiver_orders_model','orders_model');
|
|
$this->load->model('receiver/order/receiver_order_signs_model','signs_model');
|
|
$this->load->model('receiver/order/receiver_order_contracts_model','contracts_model');
|
|
$this->load->model('receiver/order/receiver_order_ckcars_model','ckcars_model');
|
|
$this->load->model('receiver/order/receiver_order_bills_model','bills_model');
|
|
$this->load->model('receiver/order/receiver_order_deliverys_model','deliverys_model');
|
|
}
|
|
|
|
protected function get(){
|
|
$id = $this->input_param('id');
|
|
$type = $this->input_param('type');
|
|
!strlen($type) && $type = 0;
|
|
|
|
$row = $this->orders_model->get(['id'=>$id,'mobile'=>$this->session['mobile']]);
|
|
$type_arr = $this->contracts_model->get_types();
|
|
if(!$row || !$type_arr[$type]){
|
|
throw new Exception('参数错误', API_CODE_INVILD_PARAM);
|
|
}
|
|
$contract = $this->contracts_model->get(['type'=>$type,'o_id'=>$id]);
|
|
|
|
$this->load->library('receiver/orders_entity');
|
|
$this->load->library('pdf');
|
|
|
|
list($h5_url,$title) = $this->orders_entity->get_contract_h5($id,$type,1);
|
|
list($pdf2img_url,$title) = $this->orders_entity->get_contract_h5($id,$type);
|
|
if(!$contract){
|
|
$cid = create_order_no(350200,$this->app_key,2);
|
|
$add_data = [
|
|
'cid' => $cid,
|
|
'o_id' => $id,
|
|
'type' => $type,
|
|
'c_time' => time()
|
|
];
|
|
$con_id = $this->contracts_model->add($add_data);
|
|
if(!$con_id){
|
|
throw new Exception('创建合同失败', API_CODE_INVILD_PARAM);
|
|
}
|
|
//html转pdf
|
|
$save_path = 'data/contracts/'.date('Ymd');
|
|
$filename = $cid.'.pdf';
|
|
$c_res = $this->pdf->html2pdf($pdf2img_url,FCPATH.$save_path,$filename);
|
|
$update = [
|
|
'file' => $save_path.'/'.$filename
|
|
];
|
|
$this->contracts_model->update($update,['id'=>$con_id]);
|
|
}else{
|
|
if(!$contract['status'] && date('Ymd')!=date('Ymd',$contract['c_time'])){ //更新合同文件日期
|
|
//html转pdf
|
|
@unlink(FCPATH.$contract['file']);
|
|
$save_path = 'data/contracts/'.date('Ymd');
|
|
$filename = $contract['cid'].'.pdf';
|
|
$c_res = $this->pdf->html2pdf($h5_url,FCPATH.$save_path,$filename);
|
|
$update = [
|
|
'file' => $save_path.'/'.$filename,
|
|
'c_time' => time()
|
|
];
|
|
$this->contracts_model->update($update,['id'=>$contract['id']]);
|
|
}
|
|
}
|
|
|
|
$data = [
|
|
'title' => $title,
|
|
'url' => $h5_url,
|
|
'img' => 'https://qs.haodian.cn/wechat_app/liche/mine/he-demo-2.jpg',
|
|
];
|
|
return $data;
|
|
}
|
|
|
|
protected function post(){
|
|
$id = $this->input_param('id');
|
|
$type = $this->input_param('type');
|
|
$img = $this->input_param('img');
|
|
|
|
$row = $this->contracts_model->get(['type'=>$type,'o_id'=>$id]);
|
|
|
|
if(!$row['file'] || !$img){
|
|
throw new Exception('参数错误', API_CODE_INVILD_PARAM);
|
|
}
|
|
if($row['status']==1){
|
|
throw new Exception('已签名', API_CODE_INVILD_PARAM);
|
|
}
|
|
//pdf转图片
|
|
$pdf_url = http_host_com('api').'/'.$row['file'];
|
|
$this->load->library('pdf');
|
|
$pdf = new Pdf(true);
|
|
$imgs = $pdf->pdf2img($pdf_url);
|
|
if(!$imgs){
|
|
throw new Exception('签名失败,图片转换失败', API_CODE_INVILD_PARAM);
|
|
}
|
|
|
|
$this->load->library('receiver/sign_entity');
|
|
switch($type){
|
|
case 0: //整车
|
|
$sign_img = array_pop($imgs);
|
|
$res = $this->sign_entity->merge($sign_img,$img,1050,200,300);
|
|
if(!$res){
|
|
throw new Exception('签名失败', API_CODE_INVILD_PARAM);
|
|
}
|
|
$imgs[] = http_host_com('api').'/'.$res;
|
|
$imgs = $this->up_qiniu($imgs,$res);
|
|
$update = [
|
|
'imgs' => json_encode($imgs,JSON_UNESCAPED_UNICODE),
|
|
'sign_time' => date('Y-m-d H:i:s'),
|
|
'status' => 1
|
|
];
|
|
$result = $this->contracts_model->update($update,['id'=>$row['id']]);
|
|
if($result){
|
|
throw new Exception('签名成功', API_CODE_SUCCESS);
|
|
}else{
|
|
throw new Exception('签名失败', API_CODE_INVILD_PARAM);
|
|
}
|
|
break;
|
|
case 1: //协议
|
|
$sign_img = array_pop($imgs);
|
|
$res = $this->sign_entity->merge($sign_img,$img,1050,1550,300);
|
|
if(!$res){
|
|
throw new Exception('签名失败', API_CODE_INVILD_PARAM);
|
|
}
|
|
$imgs[] = http_host_com('api').'/'.$res;
|
|
$imgs = $this->up_qiniu($imgs,$res);
|
|
$update = [
|
|
'imgs' => json_encode($imgs,JSON_UNESCAPED_UNICODE),
|
|
'sign_time' => date('Y-m-d H:i:s'),
|
|
'status' => 1
|
|
];
|
|
$result = $this->contracts_model->update($update,['id'=>$row['id']]);
|
|
if($result){
|
|
$this->signs_model->update(['status'=>1],['o_id'=>$id]);
|
|
//生成定金订单
|
|
$this->load->library('receiver/orders_entity');
|
|
$this->orders_entity->c_order($id,$this->app_id,$this->session);
|
|
throw new Exception('签名成功', API_CODE_SUCCESS);
|
|
}else{
|
|
throw new Exception('签名失败', API_CODE_INVILD_PARAM);
|
|
}
|
|
break;
|
|
case 2: //确认信息
|
|
$sign_img = array_pop($imgs);
|
|
$res = $this->sign_entity->merge($sign_img,$img,1050,400,300);
|
|
if(!$res){
|
|
throw new Exception('签名失败', API_CODE_INVILD_PARAM);
|
|
}
|
|
$imgs[] = http_host_com('api').'/'.$res;
|
|
$imgs = $this->up_qiniu($imgs,$res);
|
|
$update = [
|
|
'imgs' => json_encode($imgs,JSON_UNESCAPED_UNICODE),
|
|
'sign_time' => date('Y-m-d H:i:s'),
|
|
'status' => 1
|
|
];
|
|
$result = $this->contracts_model->update($update,['id'=>$row['id']]);
|
|
if($result){
|
|
$this->ckcars_model->update(['status'=>2],['o_id'=>$id]);
|
|
$this->orders_model->update(['status'=>3],['id'=>$id]);
|
|
$this->bills_model->add(['o_id'=>$id,'c_time'=>time()]);
|
|
throw new Exception('签名成功', API_CODE_SUCCESS);
|
|
}else{
|
|
throw new Exception('签名失败', API_CODE_INVILD_PARAM);
|
|
}
|
|
break;
|
|
case 3: //车辆交接
|
|
$sign_img = array_pop($imgs);
|
|
$res = $this->sign_entity->merge($sign_img,$img,300,1400,'','',false);
|
|
if(!$res){
|
|
throw new Exception('签名失败', API_CODE_INVILD_PARAM);
|
|
}
|
|
$imgs[] = http_host_com('api').'/'.$res;
|
|
$imgs = $this->up_qiniu($imgs,$res);
|
|
$update = [
|
|
'imgs' => json_encode($imgs,JSON_UNESCAPED_UNICODE),
|
|
'sign_time' => date('Y-m-d H:i:s'),
|
|
'status' => 1
|
|
];
|
|
$result = $this->contracts_model->update($update,['id'=>$row['id']]);
|
|
if($result){
|
|
$this->deliverys_model->update(['status'=>1],['o_id'=>$id]);
|
|
throw new Exception('签名成功', API_CODE_SUCCESS);
|
|
}else{
|
|
throw new Exception('签名失败', API_CODE_INVILD_PARAM);
|
|
}
|
|
break;
|
|
default:
|
|
throw new Exception('未知签名类型', API_CODE_INVILD_PARAM);
|
|
}
|
|
}
|
|
|
|
//图片上传七牛
|
|
private function up_qiniu($imgs,$file){
|
|
$this->load->library('qiniu');
|
|
//上传七牛并保存
|
|
foreach($imgs as $key=>$val){
|
|
$file_name = md5($val).'.jpg';
|
|
$result = $this->qiniu->fetch($val,$file_name);
|
|
if($result){
|
|
$imgs[$key] = $result['file'];
|
|
if (strpos($val, $file) !== false) {
|
|
@unlink(FCPATH.$file);
|
|
}
|
|
}
|
|
}
|
|
return $imgs;
|
|
}
|
|
}
|