diff --git a/api/controllers/wxapp/liche/Contract.php b/api/controllers/wxapp/liche/Contract.php index 227dd73d..f08379d1 100644 --- a/api/controllers/wxapp/liche/Contract.php +++ b/api/controllers/wxapp/liche/Contract.php @@ -30,6 +30,7 @@ class Contract extends Wxapp{ $this->load->model("sys/sys_company_model"); $this->load->model('app/liche/app_liche_orders_model'); $this->load->library('receiver/orders_entity'); + $this->load->library('receiver/order_datas_entity'); } protected function get(){ @@ -342,4 +343,29 @@ class Contract extends Wxapp{ } return $imgs; } + //车辆确认 + protected function get_finsh(){ + $id = $this->input_param('id'); + + //生成交车确认pdf + $res = $this->order_datas_entity->fill_finsh_pdf($id); + if(!$res['code']){ + throw new Exception($res['msg'], API_CODE_INVILD_PARAM); + } + $contract = $this->contracts_model->get(['type'=>6,'o_id'=>$id]); + if(!$contract){ + throw new Exception('参数错误', API_CODE_INVILD_PARAM); + } + $imgs_arr = json_decode($contract['imgs'],true); + $imgs = []; + if($imgs_arr){ + foreach($imgs_arr as $key => $val){ + $imgs[] = build_qiniu_image_url($val); + } + } + $data = [ + 'imgs' => $imgs, + ]; + return $data; + } } diff --git a/api/controllers/wxapp/liche/Order.php b/api/controllers/wxapp/liche/Order.php index d6ac5106..f2c786bf 100644 --- a/api/controllers/wxapp/liche/Order.php +++ b/api/controllers/wxapp/liche/Order.php @@ -256,6 +256,7 @@ class Order extends Wxapp{ 'agree' => $agree, 'show_agree' => $show_agree, 'ckcar_status' => $ckcar_status, //是否显示确认车辆 + 'need_sign' => $order['brand_id'] == 1 ? true : false, 'version' => $attrs[$val['v_id']] ? $attrs[$val['v_id']][0]['title'] : '', 'color' => $attrs[$val['cor_id']] ? $attrs[$val['cor_id']][0]['title'] : '', 'in_color' => $attrs[$val['incor_id']] ? $attrs[$val['incor_id']][0]['title'].'内饰' : '', diff --git a/api/controllers/wxapp/liche/Protocol.php b/api/controllers/wxapp/liche/Protocol.php index 9c33a107..a8b33d0f 100755 --- a/api/controllers/wxapp/liche/Protocol.php +++ b/api/controllers/wxapp/liche/Protocol.php @@ -211,6 +211,7 @@ require_once APPPATH.'controllers/wxapp/Wxapp.php'; protected function post_ckcar(){ $oid = $this->input_param('oid'); + $img = $this->input_param('img'); $row = $this->receiver_orders_v2_model->get(['id'=>$oid]); if(!$row ){ throw new Exception('参数错误', API_CODE_INVILD_PARAM); @@ -252,6 +253,10 @@ require_once APPPATH.'controllers/wxapp/Wxapp.php'; $this->receiver_orders_v2_model->update(['status'=>1,'ck_time'=>date('Y-m-d H:i:s')],['id'=>$row['id']]); //完成分销 $this->deal_entity->deal_log_finish($row['id']); + if($img){ //签名 + $this->load->library('receiver/order_datas_entity'); + $req = $this->order_datas_entity->sign_finsh_pdf($oid,$img); + } throw new Exception('操作成功', API_CODE_SUCCESS); }else{ throw new Exception('保存失败', API_CODE_FAIL); diff --git a/common/libraries/receiver/Order_datas_entity.php b/common/libraries/receiver/Order_datas_entity.php index fbcf5f3a..3ec0aa42 100644 --- a/common/libraries/receiver/Order_datas_entity.php +++ b/common/libraries/receiver/Order_datas_entity.php @@ -8,6 +8,11 @@ class Order_datas_entity{ private $ci; + private $wd_config = [ //网点配置 + 350100 => ['name'=>'福州狸车销售有限公司','code'=>'FJ0011'], + 350200 => ['name'=>'厦门狸车销售有限公司','code'=>'FJ0007'], + 350500 => ['name'=>'泉州狸车销售有限公司','code'=>'FJ0009'], + ]; const COLOR_UN_UPLOAD = '#f9394d'; //未传 const COLOR_IS_UPLOAD = '#fd9737'; //已传 const COLOR_UN_CHECK = '#f9394d'; //未通过 @@ -16,11 +21,26 @@ class Order_datas_entity{ public function __construct(){ $this->ci = & get_instance(); + $this->ci->load->model('receiver/order/receiver_orders_v2_model'); + $this->ci->load->model('receiver/order/receiver_order_contracts_model','order_contracts_model'); $this->ci->load->model('receiver/order/receiver_order_datas_model'); $this->ci->load->model('receiver/order/receiver_order_agents_model'); + $this->ci->load->model('app/app_checkdata_model'); + $this->ci->load->model('app/licheb/app_licheb_users_model'); + $this->ci->load->model('app/licheb/app_licheb_channel_biz_model'); + + $this->ci->load->model("biz/biz_model"); + + $this->ci->load->model('auto/auto_brand_model'); + $this->ci->load->model('auto/auto_series_model'); + $this->ci->load->model('auto/auto_attr_model'); + $this->ci->load->model("items/items_model"); + $this->ci->load->library('TcOrc'); $this->ci->load->library('qiniuorc'); + $this->ci->load->library('pdftk'); + $this->ci->load->library('pdf'); } public function data_status($o_data){ @@ -315,4 +335,123 @@ class Order_datas_entity{ } return $res; } + /** + * 生成确认交车合同 + * @param $oid + * @return array + */ + public function fill_finsh_pdf($oid){ + $order = $this->ci->receiver_orders_v2_model->get(['id'=>$oid]); + if(!$order){ + return ['code'=>0,'msg'=>'参数错误']; + } + $biz = $this->ci->biz_model->get(['id'=>$this->order_row['biz_id']],'city_id'); + $wd = $this->wd_config[$biz['city_id']] ? $this->wd_config[$biz['city_id']] : $this->wd_config['350200']; + //车辆信息 + $brand = $this->ci->auto_brand_model->get(['id'=>$order['brand_id']],'name'); + $series = $this->ci->auto_series_model->get(['id'=>$order['s_id']],'name'); + $version = $this->ci->auto_attr_model->get(['id'=>$order['v_id']],'title'); + $color = $this->ci->auto_attr_model->get(['id'=>$order['cor_id']],'title'); + $_version = $version['title'] ? $version['title'] : ''; + $item = $this->ci->items_model->get(['id'=>$order['item_id']],'vin'); + $sale_row = $this->ci->app_licheb_users_model->get(['id'=>$order['sale_id']],'uname'); + $qd_biz_row = $this->ci->app_licheb_channel_biz_model->select(['biz_id'=>$order['biz_id']],'c_time desc',1,1,'id,uid'); + $qd_row = $this->ci->app_licheb_users_model->get(['id'=>$qd_biz_row[0]['uid']],'uname'); + + if(in_array($order['v_id'],[173,176,327,330])){ + $fill_2 = "/"; + }else{ + $fill_2 = "√"; + } + $fill_data = [ + 'code_name' => $wd['name'], + 'code' => $wd['code'], + 'car' => "{$brand['name']} {$series['name']} $_version", + 'name' => $order['owner_name'], + 'color' => $color['title'] ? $color['title'] : '', + 'vin' => $item['vin'] ? $item['vin'] : '', + 'sale_name' => $sale_row['uname'] ? $sale_row['uname'] : '', + 'channel_name' => $qd_row['uname'] ? $qd_row['uname'] : '', + 'time' => date('Y-m-d'), + 'fill_2' => $fill_2 + ]; + $pdf_path = 'pdf/finish_tpl.pdf'; + $save_path = "pdf/{$order['sid']}/finish.pdf"; + $req = $this->ci->pdftk->esign_fill_pdf($pdf_path,$save_path,$fill_data); + if(!$req['code']){ + return ['code'=>0,'msg'=>$req['msg']]; + } + $where = [ + 'o_id' => $oid, + 'type' => 6 + ]; + $row = $this->ci->order_contracts_model->get($where); + $up_data = [ + 'file' => $req['data']['file_path'] ? $req['data']['file_path'] : '', + ]; + //pdf转图片 + if($up_data['file']){ + $pdf_url = http_host_com('api').'/'.$up_data['file']; + $imgs = $this->ci->pdf->pdf2img($pdf_url); + if($imgs){ + $up_data['imgs'] = json_encode($imgs,JSON_UNESCAPED_UNICODE); + } + } + if($row){ + $result = $this->ci->order_contracts_model->update($up_data,['id'=>$row['id']]); + }else{ + $up_data['o_id'] = $oid; + $up_data['type'] = 6; + $up_data['c_time'] = time(); + $result = $this->ci->order_contracts_model->add($up_data); + } + if($result){ + return ['code'=>1,'msg'=>'保存成功']; + }else{ + return ['code'=>0,'msg'=>'保存失败']; + } + } + + public function sign_finsh_pdf($oid,$sign_img){ + $where = [ + 'o_id' => $oid, + 'type' => 6 + ]; + $row = $this->ci->order_contracts_model->get($where); + $imgs = json_decode($row['imgs'],true); + $jsondata = json_decode($row['jsondata'],true); + if(!$row || !$imgs){ + return ['code'=>0,'msg'=>'数据不存在']; + } + $origin_img = $imgs['0']; + $this->ci->load->library('receiver/sign_entity'); + $res = $this->ci->sign_entity->merge_img($origin_img,$sign_img,300,1250); + if(!$res){ + return ['code'=>0,'msg'=>'图片合并失败']; + } + $img_url = http_host_com('api').'/'.$res; + $this->ci->load->library('qiniu'); + $file_name = md5($img_url).'.jpg'; + $result = $this->ci->qiniu->fetch($img_url,$file_name); + if(!$result['file']){ + $imgs[0] = $img_url; + }else{ + @unlink(FCPATH.$res); + $imgs[0] = build_qiniu_image_url($result['file']); + $this->ci->receiver_order_datas_model->update(['delivery_ck_img'=>$result['file']],['o_id'=>$oid]); + } + $jsondata['sign_img'] = $sign_img; + $update = [ + 'imgs' => json_encode($imgs,JSON_UNESCAPED_UNICODE), + 'jsondata' => json_encode($jsondata,JSON_UNESCAPED_UNICODE), + 'status' => 1, + 'sign_time' => date('Y-m-d H:i:s') + ]; + $result = $this->ci->order_contracts_model->update($update,['id'=>$row['id']]); + if($result){ + return ['code'=>1,'msg'=>'保存成功']; + }else{ + return ['code'=>0,'msg'=>'保存失败']; + } + } } diff --git a/www/api/pdf/finish_tpl.pdf b/www/api/pdf/finish_tpl.pdf new file mode 100755 index 00000000..f10e0f8c Binary files /dev/null and b/www/api/pdf/finish_tpl.pdf differ