From d2f5b5fce1f1fe5b43a8e1da440392f9a54bee7f Mon Sep 17 00:00:00 2001
From: lccsw <805383944@qq.com>
Date: Tue, 2 Aug 2022 17:32:47 +0800
Subject: [PATCH] edit-api-licheb_imgs
---
admin/controllers/receiver/orderv2/Orders.php | 60 +++++++++++++
admin/views/receiver/orderv2/get/index.php | 44 ++++++++++
api/controllers/wxapp/licheb/CusorderV2.php | 14 ++-
api/controllers/wxapp/licheb/Cusorderdata.php | 81 ++++++++++++++++--
.../libraries/receiver/Order_datas_entity.php | 85 ++++++++++++++++---
5 files changed, 263 insertions(+), 21 deletions(-)
diff --git a/admin/controllers/receiver/orderv2/Orders.php b/admin/controllers/receiver/orderv2/Orders.php
index 928c2dbf..0d96faef 100644
--- a/admin/controllers/receiver/orderv2/Orders.php
+++ b/admin/controllers/receiver/orderv2/Orders.php
@@ -239,6 +239,12 @@ class Orders extends HD_Controller
$row['imgs_status'] = $this->order_datas_entity->data_ckinfo($img_data,$row['main_type']);
//获取开票
+ $bill_ck_img = json_decode($img_data['bill_ck_img'],true);
+ if($bill_ck_img){
+ foreach ($bill_ck_img as $key => $value) {
+ $bill_ck_img[$key] = build_qiniu_image_url($value);
+ }
+ }
$bill = $this->order_bills_model->get(['o_id' => $row['id']], 'status,file');
$bill_status = $this->receiver_order_status_model->get(['o_id'=>$row['id'],'pid_status'=>3,'status'=>1]); //是否已开票
$bill['file'] = $bill['file'] ? build_qiniu_image_url($bill['file']) : '';
@@ -246,6 +252,8 @@ class Orders extends HD_Controller
$bill['cardidA'] = $img_data['cardida'];
$bill['cardidB'] = $img_data['cardidb'];
$bill['business_licence'] = $img_data['business_licence'];
+ $bill['bill_ck_img'] = $bill_ck_img;
+
$bill['status'] = $bill_status ? 1 : 0;
$companys = $this->sys_company_model->select(['status' => 1, 'wx_mchid!=' => ''], 'id desc', '', '', 'id,short');
$row['companys'] = $companys;
@@ -1237,4 +1245,56 @@ class Orders extends HD_Controller
$this->data['id'] = $id;
return $this->show_view('receiver/orderv2/edit_srv');
}
+
+ public function edit_bill_img(){
+ $id = $this->input->post('id');
+ $file = $this->input->post('value');
+ if(!$file || !$id){
+ $this->show_json(SYS_CODE_FAIL,'参数错误');
+ }
+ $re_data = $this->receiver_order_datas_model->get(['o_id'=>$id]);
+ $bill_ck_img = [];
+ if(!$re_data){
+ $re_data_id = $this->receiver_order_datas_model->add(['c_time'=>time(),'o_id'=>$id]);
+ }else{
+ $re_data_id = $re_data['id'];
+ $bill_ck_img = json_decode($re_data['bill_ck_img'],true);
+ }
+
+ if(strpos($file,'.pdf') !== false){
+ $this->load->library('pdf');
+ $pdf_url = build_qiniu_image_url($file);
+ $pdf_imgs = $this->pdf->pdf2img($pdf_url);
+ if($pdf_imgs){
+ $bill_ck_img = $this->up_qiniu($pdf_imgs);
+ }else{
+ return $this->show_json(SYS_CODE_FAIL, 'pdf识别失败');
+ }
+ }else{
+ $bill_ck_img[] = $file;
+ }
+ $update = [
+ 'bill_ck_img' => json_encode($bill_ck_img,JSON_UNESCAPED_UNICODE)
+ ];
+ $res = $this->receiver_order_datas_model->update($update,['id'=>$re_data_id]);
+ if($res){
+ return $this->show_json(SYS_CODE_SUCCESS, '保存成功');
+ }else{
+ return $this->show_json(SYS_CODE_FAIL, '保存失败');
+ }
+ }
+
+ //图片上传七牛
+ private function up_qiniu($imgs){
+ $this->load->library('qiniu');
+ //上传七牛并保存
+ foreach($imgs as $key=>$val){
+ $file_name = date('Ym')."/".md5($val).'.jpg';
+ $result = $this->qiniu->fetch($val,$file_name);
+ if($result){
+ $imgs[$key] = $result['file'];
+ }
+ }
+ return $imgs;
+ }
}
diff --git a/admin/views/receiver/orderv2/get/index.php b/admin/views/receiver/orderv2/get/index.php
index 85e0aa21..b2739f6d 100644
--- a/admin/views/receiver/orderv2/get/index.php
+++ b/admin/views/receiver/orderv2/get/index.php
@@ -312,6 +312,29 @@
+
@@ -706,4 +729,25 @@
}
}, 'json');
}
+ function edit_bill_img(obj) {
+ var loading = layer.msg('上传中', {
+ icon: 16
+ ,shade: 0.3
+ ,time: false
+ });
+ var value = $(obj).val();
+ $.post("/receiver/orderv2/orders/edit_bill_img", {
+ 'id': =$info['id']?>,
+ 'value': value,
+ }, function (data) {
+ layer.closeAll()
+ if (data.code) {
+ layer.msg(data.msg, {time: 2000, icon: 1}, function () {
+ $.form.reload();
+ });
+ } else {
+ layer.msg(data.msg, {icon: 2});
+ }
+ }, 'json');
+ }
diff --git a/api/controllers/wxapp/licheb/CusorderV2.php b/api/controllers/wxapp/licheb/CusorderV2.php
index 8099118b..bd73fe12 100644
--- a/api/controllers/wxapp/licheb/CusorderV2.php
+++ b/api/controllers/wxapp/licheb/CusorderV2.php
@@ -940,9 +940,19 @@ class CusorderV2 extends Wxapp
//订单列表头部
protected function get_tabs()
{
+ $where = [
+ 'status' => 0,
+ 'biz_id' => $this->biz_id,
+ ];
+ $d_count = $this->orders_model->count($where);
+ $where = [
+ 'status' => 1,
+ 'biz_id' => $this->biz_id,
+ ];
+ $f_count = $this->orders_model->count($where);
$lists = [
- ['key' => 11, 'name' => '进行中'],
- ['key' => 12, 'name' => '已完成'],
+ ['key' => 11, 'name' => "进行中({$d_count})"],
+ ['key' => 12, 'name' => "已完成({$f_count})"],
];
$data['filters'] = [
'type' => [
diff --git a/api/controllers/wxapp/licheb/Cusorderdata.php b/api/controllers/wxapp/licheb/Cusorderdata.php
index 1d949dc7..254772b3 100644
--- a/api/controllers/wxapp/licheb/Cusorderdata.php
+++ b/api/controllers/wxapp/licheb/Cusorderdata.php
@@ -28,6 +28,7 @@ class Cusorderdata extends Wxapp{
protected function get(){
$id = $this->input_param('id');
//$row = $this->receiver_order_status_model->get(['o_id'=>$id,'status'=>1,'pid_status'=>0]);
+ $row = $this->orders_model->get(['id'=>$id]);
$is_pay = $this->app_liche_orders_model->count(['o_id'=>$id,'status'=>1]);
$data = [];
if($is_pay){
@@ -46,6 +47,33 @@ class Cusorderdata extends Wxapp{
'img' => build_qiniu_image_url($row_data['register_img'])
];
}
+ $bill_ck_img = $business_img = $insurance_img = [];
+ $d_ins_info = json_decode($row_data['insurance_img'],true);
+ if($d_ins_info){
+ $insurance_img = [
+ 'value' => $d_ins_info['img'],
+ 'img' => build_qiniu_image_url($d_ins_info['img']),
+ 'product' => $d_ins_info['product'] ? $d_ins_info['product'] : '',
+ 'price' => $d_ins_info['price'] ? $d_ins_info['price'] : 0,
+ 'date' => $d_ins_info['date'] ? $d_ins_info['date'] : '',
+ ];
+ }
+ $d_ins_img = json_decode($row_data['business_img'],true);
+ if($d_ins_img){
+ $business_img = [
+ 'value' => $d_ins_img['img'],
+ 'img' => build_qiniu_image_url($d_ins_img['img']),
+ 'product' => $d_ins_img['product'] ? $d_ins_img['product'] : '',
+ 'price' => $d_ins_img['price'] ? $d_ins_img['price'] : 0,
+ 'date' => $d_ins_img['date'] ? $d_ins_img['date'] : '',
+ ];
+ }
+ $bill_img_json = json_decode($row_data['bill_ck_img'],true);
+ if($bill_img_json){
+ foreach ($bill_img_json as $item) {
+ $bill_ck_img[] = build_qiniu_image_url($item);
+ }
+ }
$data['imgs'] = [
'cardida' => [],
'cardidb' => [],
@@ -53,7 +81,10 @@ class Cusorderdata extends Wxapp{
'car_img' => $car_img,
'register_img' => $register_img,
'ins_img' => [],
- 'other_img' => []
+ 'other_img' => [],
+ 'insurance_img' => $insurance_img,
+ 'business_img' => $business_img,
+ 'bill_ck_img' => $bill_ck_img
];
if($row['main_type']){
@@ -132,6 +163,8 @@ class Cusorderdata extends Wxapp{
$business_licence = $this->input_param('business_licence');
$ins_imgs = $this->input_param('ins_imgs');
$other_imgs = $this->input_param('other_imgs');
+ $insurance_img = $this->input_param('insurance_img');
+ $business_img = $this->input_param('business_img');
$update = [];
if($cardida){
$full_cardida = build_qiniu_image_url($cardida);
@@ -176,10 +209,13 @@ class Cusorderdata extends Wxapp{
return $res_data;
}
$update['business_licence'] = $business_licence;
- }elseif($ins_imgs){
- //图片识别
+ }elseif(is_array($ins_imgs)){
$update['ins_img'] = json_encode($ins_imgs,JSON_UNESCAPED_UNICODE);
- }elseif($other_imgs){
+ } elseif($insurance_img){
+ $update['insurance_img'] = json_encode(['img'=>$insurance_img],JSON_UNESCAPED_UNICODE);
+ } elseif($business_img){
+ $update['business_img'] = json_encode(['img'=>$business_img],JSON_UNESCAPED_UNICODE);
+ }elseif(is_array($other_imgs)){
$update['other_img'] = json_encode($other_imgs,JSON_UNESCAPED_UNICODE);
}else{
if($cardidb){
@@ -204,8 +240,11 @@ class Cusorderdata extends Wxapp{
}
$res = $this->receiver_order_datas_model->update($update,['o_id'=>$id]);
if($res){
- if($update['ins_img']){ //保单识别图片保存数据
- $this->order_datas_entity->orc_ins_img($id);
+ if($insurance_img || $business_img){ //保单识别图片保存数据
+ $res = $this->order_datas_entity->orc_ins_img_2($id);
+ if(!$res){
+ throw new Exception('图片识别失败,请重新上传', ERR_PARAMS_ERROR);
+ }
}
if($update['car_img']){ //更新车牌号
$this->order_datas_entity->up_car_num($id);
@@ -215,4 +254,34 @@ class Cusorderdata extends Wxapp{
throw new Exception('修改失败', ERR_PARAMS_ERROR);
}
}
+
+ public function put_info(){
+ $id = $this->input_param('id');
+ $type = $this->input_param('type');
+ $product = $this->input_param('product');
+ $price = $this->input_param('price');
+ $date = $this->input_param('date');
+ $data_row = $this->receiver_order_datas_model->get(['o_id'=>$id]);
+ if(!$data_row){
+ throw new Exception('数据不存在', ERR_PARAMS_ERROR);
+ }
+ if($type){ //交强险图片
+ $jsondata = json_decode($data_row['insurance_img'],true);
+ $jsondata['product'] = $product;
+ $jsondata['price'] = $price;
+ $jsondata['date'] = $date;
+ $update['insurance_img'] = json_encode($jsondata,JSON_UNESCAPED_UNICODE);
+ }else{ //商业险图片
+ if($price<1000){
+ throw new Exception('金额有误,请重新填写', ERR_PARAMS_ERROR);
+ }
+ $jsondata = json_decode($data_row['business_img'],true);
+ $jsondata['product'] = $product;
+ $jsondata['price'] = $price;
+ $jsondata['date'] = $date;
+ $update['business_img'] = json_encode($jsondata,JSON_UNESCAPED_UNICODE);
+ }
+ $res = $this->receiver_order_datas_model->update($update,['id'=>$data_row['id']]);
+ throw new Exception('修改成功', API_CODE_SUCCESS);
+ }
}
diff --git a/common/libraries/receiver/Order_datas_entity.php b/common/libraries/receiver/Order_datas_entity.php
index c293b39f..6219e13a 100644
--- a/common/libraries/receiver/Order_datas_entity.php
+++ b/common/libraries/receiver/Order_datas_entity.php
@@ -32,21 +32,19 @@ class Order_datas_entity{
'ins_img' => ['text'=>'未传','type'=>4,'color'=>self::COLOR_UN_UPLOAD], //保单证
'other_img' => ['text'=>'未传','type'=>5,'color'=>self::COLOR_UN_UPLOAD], //交车合照
];
-// $where = ['cf_id'=>$o_data['id'],'app_id'=>2,'type in (1,2,3,4,5)'=>null,'datatype'=>'img'];
-// $check_data = $this->ci->app_checkdata_model->map('type','',$where,'','','','id,cf_id,type,ifcheck');
foreach ($result as $key=>$item) {
- if($o_data[$key]){
- $result[$key]['text'] = '已传';
- $result[$key]['color'] = self::COLOR_IS_UPLOAD;
-// if($check_data[$item['type']][0]['ifcheck']==1){
-// $result[$key]['text'] = '已通过';
-// $result[$key]['color'] = self::COLOR_CHECK;
-// }
-// if($check_data[$item['type']][0]['ifcheck']==-1){
-// $result[$key]['text'] = '未通过';
-// $result[$key]['color'] = self::COLOR_UN_CHECK;
-// }
+ if($key=='ins_img'){
+ if($o_data['ins_img'] || $o_data['insurance_img'] || $o_data['business_img']){
+ $result[$key]['text'] = '已传';
+ $result[$key]['color'] = self::COLOR_IS_UPLOAD;
+ }
+ }else{
+ if($o_data[$key]){
+ $result[$key]['text'] = '已传';
+ $result[$key]['color'] = self::COLOR_IS_UPLOAD;
+ }
}
+
}
return $result;
}
@@ -222,6 +220,67 @@ class Order_datas_entity{
return $res;
}
+ /**
+ * 识别保单图片
+ * @param $oid
+ * @return false
+ */
+ public function orc_ins_img_2($oid){
+ $row = $this->ci->receiver_order_datas_model->get(['o_id'=>$oid]);
+ $insurance_img = json_decode($row['insurance_img'],true);
+ $business_img = json_decode($row['business_img'],true);
+ $jsondata = json_decode($row['jsondata'],true);
+ $ins_info = $jsondata['ins_info'] ? $jsondata['ins_info'] : [];
+ if($insurance_img['img']){
+ $url = build_qiniu_image_url($insurance_img['img']);
+ $ins_key = md5($url);
+ if(!$ins_info[$ins_key]){
+ $result = $this->ci->qiniuorc->car_insure($url);
+ if ($result['code']) {
+ $ins_info[$ins_key]['msg'] = $result['msg'];
+ $ins_info[$ins_key]['data'] = $result['data'];
+ $ins_info[$ins_key]['img_url'] = $url;
+ $jsondata['ins_info'] = $ins_info;
+ $insurance_img['price'] = floatval($result['data']['合计保费']);
+ $insurance_img['date'] = $result['data']['投保确认时间'];
+ $insurance_img['product'] = $result['data']['保险公司'];
+ }else{
+ $ins_info[$ins_key]['msg'] = $result['msg'];
+ $ins_info[$ins_key]['img_url'] = $url;
+ return false;
+ }
+ }
+ }
+ if($business_img['img']){
+ $url = build_qiniu_image_url($business_img['img']);
+ $ins_key = md5($url);
+ if(!$ins_info[$ins_key]){
+ $result = $this->ci->qiniuorc->car_insure($url);
+ if ($result['code']) {
+ $ins_info[$ins_key]['msg'] = $result['msg'];
+ $ins_info[$ins_key]['data'] = $result['data'];
+ $ins_info[$ins_key]['img_url'] = $url;
+ $jsondata['ins_info'] = $ins_info;
+ $business_img['price'] = floatval($result['data']['合计保费']);
+ $business_img['date'] = $result['data']['投保确认时间'];
+ $business_img['product'] = $result['data']['保险公司'];
+ }else{
+ $ins_info[$ins_key]['msg'] = $result['msg'];
+ $ins_info[$ins_key]['img_url'] = $url;
+ return false;
+ }
+ }
+ }
+ $update = [
+ 'jsondata' => json_encode($jsondata,JSON_UNESCAPED_UNICODE),
+ 'insurance_img' => json_encode($insurance_img,JSON_UNESCAPED_UNICODE),
+ 'business_img' => json_encode($business_img,JSON_UNESCAPED_UNICODE),
+ ];
+ $res = $this->ci->receiver_order_datas_model->update($update,['id'=>$row['id']]);
+
+ return $res;
+ }
+
/**
* 更新车牌号
* @return void