From e3a43cbfff76cfc24de5f93bfb86ede08b35730b Mon Sep 17 00:00:00 2001 From: lcc <1127794702@qq.com> Date: Fri, 7 Jun 2024 15:43:13 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=8F=91=E7=A5=A8=E8=AF=86?= =?UTF-8?q?=E5=88=AB=E5=92=8C=E5=AE=9A=E4=BD=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- admin/controllers/Login.php | 7 +- api/controllers/wxapp/app/City.php | 4 +- api/controllers/wxapp/licheb/Cusorderdata.php | 40 +---- api/controllers/wxapp/licheb/Sign.php | 9 +- common/libraries/TcOrc.php | 166 +++++++++--------- .../libraries/receiver/Order_datas_entity.php | 30 ++++ 6 files changed, 136 insertions(+), 120 deletions(-) diff --git a/admin/controllers/Login.php b/admin/controllers/Login.php index 94e13fb6..0b3d1983 100644 --- a/admin/controllers/Login.php +++ b/admin/controllers/Login.php @@ -94,9 +94,10 @@ class Login extends CI_Controller 'login_ip' => $ip, ); $http_host = explode(':', $_SERVER['HTTP_HOST']); - $domain = explode('.', $http_host[0]); - array_shift($domain); - $domain = implode('.', $domain); + $domain = $http_host[0]; +// $domain = explode('.', $http_host[0]); +// array_shift($domain); +// $domain = implode('.', $domain); $this->input->set_cookie(LOGIN_COOKIE, $this->encryption->encrypt(json_encode($admin_info)), 86400 * 30, $domain); if ($log == 1) { $this->load->model('sys/sys_admin_log_model'); diff --git a/api/controllers/wxapp/app/City.php b/api/controllers/wxapp/app/City.php index 12682e20..dabf1bbd 100644 --- a/api/controllers/wxapp/app/City.php +++ b/api/controllers/wxapp/app/City.php @@ -137,9 +137,7 @@ class City extends Wxapp } break; default: - $province_ids = implode(',', $this->province_lists); - $where = ["province_id in ($province_ids)" => null]; - $res = $this->mdArea->select($where, null, null, null, 'distinct(province_id), province_name'); + $res = $this->mdArea->select([], null, null, null, 'distinct(province_id), province_name'); foreach ($res as $v) { $lists[] = ['id' => $v['province_id'], 'name' => $v['province_name']]; } diff --git a/api/controllers/wxapp/licheb/Cusorderdata.php b/api/controllers/wxapp/licheb/Cusorderdata.php index 6f68a8cf..73dcfc19 100644 --- a/api/controllers/wxapp/licheb/Cusorderdata.php +++ b/api/controllers/wxapp/licheb/Cusorderdata.php @@ -22,7 +22,7 @@ class Cusorderdata extends Wxapp $this->load->model('receiver/order/receiver_orders_model', 'orders_model'); $this->load->model('receiver/order/receiver_order_datas_model'); -// $this->load->library('receiver/order_datas_entity'); + $this->load->library('receiver/order_datas_entity'); $this->load->library('TcOrc'); } @@ -167,15 +167,9 @@ class Cusorderdata extends Wxapp $car_img = $this->input_param('car_img'); $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'); - $accident_img = $this->input_param('accident_img'); $delivery_ck_img = $this->input_param('delivery_ck_img'); - $wx_img = $this->input_param('wx_img'); - $mut_wx_img = $this->input_param('mut_wx_img'); - $destory_img = $this->input_param('destory_img'); $contract_img = $this->input_param('contract_img'); $pay_img = $this->input_param('pay_img'); $equity_ck_img = $this->input_param('equity_ck_img'); @@ -224,16 +218,10 @@ class Cusorderdata extends Wxapp return $res_data; } $update['business_licence'] = $business_licence; - } elseif (is_array($ins_imgs)) { - $update['ins_img'] = json_encode($ins_imgs, JSON_UNESCAPED_UNICODE); } elseif ($insurance_img) { $update['insurance_img'] = $insurance_img; } elseif ($business_img) { $update['business_img'] = $business_img; - } elseif ($accident_img) { - $update['accident_img'] = json_encode(['img' => $accident_img], JSON_UNESCAPED_UNICODE); - } elseif (is_array($other_imgs)) { - $update['other_img'] = json_encode($other_imgs, JSON_UNESCAPED_UNICODE); } else { if ($cardidb) { $key = 'cardidb'; @@ -253,23 +241,10 @@ class Cusorderdata extends Wxapp $key = 'delivery_ck_img'; $img = $delivery_ck_img; } - if ($wx_img) { - $key = 'wx_img'; - $img = $wx_img; - } - if ($mut_wx_img) { - $key = 'mut_wx_img'; - $img = $mut_wx_img; - } - if ($destory_img) { - $key = 'destory_img'; - $img = $destory_img; - } if ($contract_img) { $key = 'contract_img'; $img = $contract_img; } - if ($pay_img) { $key = 'pay_img'; $img = $pay_img; @@ -285,17 +260,18 @@ class Cusorderdata extends Wxapp if ($bill_img) { $key = 'bill_img'; $img = $bill_img; + //发票识别 + $result = $this->order_datas_entity->orc_bill_img($id, build_qiniu_image_url($bill_img)); + if (!$result['code']) { + throw new Exception($result['msg'], ERR_PARAMS_ERROR); + } + $jsondata['bill_info'] = $result['data']; + $update['jsondata'] = json_encode($jsondata, JSON_UNESCAPED_UNICODE); } $key && $update[$key] = $img; } $res = $this->receiver_order_datas_model->update($update, ['o_id' => $id]); if ($res) { -// if ($insurance_img || $business_img || $accident_img) { //保单识别图片保存数据 -// $res = $this->order_datas_entity->orc_ins_img_2($id); -// if (!$res && !$accident_img) {//意外险不需要识别成功 -// throw new Exception('图片识别失败,请重新上传', ERR_PARAMS_ERROR); -// } -// } throw new Exception('修改成功', API_CODE_SUCCESS); } else { throw new Exception('修改失败', ERR_PARAMS_ERROR); diff --git a/api/controllers/wxapp/licheb/Sign.php b/api/controllers/wxapp/licheb/Sign.php index f4ff7202..49f2fab2 100644 --- a/api/controllers/wxapp/licheb/Sign.php +++ b/api/controllers/wxapp/licheb/Sign.php @@ -5,7 +5,6 @@ require_once APPPATH . 'controllers/wxapp/Wxapp.php'; class Sign extends Wxapp { - function __construct($inputs, $app_key) { parent::__construct($inputs, $app_key); @@ -19,12 +18,19 @@ class Sign extends Wxapp $this->load->model("item/item_model"); $this->load->model('app/app_model'); $this->load->library('receiver/customers_entity'); + $this->load->helper('search'); } //商家签到页配置信息 protected function get_conf() { + $lat = $this->input_param('lat'); + $lng = $this->input_param('lng'); $biz = $this->biz_model->get(['id' => $this->get_biz_id()]); + $distance = get_distance($lat, $lng, $biz['lat'], $biz['lng']); + if ($distance > 100) { + throw new Exception('您未在门店的有效范围之内', ERR_PARAMS_ERROR); + } $area = $this->area_model->get(['city_id' => $biz['city_id']]); $where = [ 'status' => 1, @@ -133,7 +139,6 @@ class Sign extends Wxapp $biz = $this->biz_model->get(['id' => $biz_id]); $biz_user = $this->app_user_model->get(['id' => $biz_uid]); //计算距离 - $this->load->helper('search'); $distance = get_distance($lat, $lng, $biz['lat'], $biz['lng']); $sign_data['distance'] = $distance; if ($distance > 500) { diff --git a/common/libraries/TcOrc.php b/common/libraries/TcOrc.php index 9a179ef7..5ddb3cda 100644 --- a/common/libraries/TcOrc.php +++ b/common/libraries/TcOrc.php @@ -6,7 +6,7 @@ * Date: 2021-07-20 * Time: 16:49 */ -defined('BASEPATH') OR exit('No direct script access allowed'); +defined('BASEPATH') or exit('No direct script access allowed'); use TencentCloud\Common\Credential; use TencentCloud\Common\Profile\ClientProfile; @@ -18,151 +18,158 @@ use TencentCloud\Ocr\V20181119\Models\BizLicenseOCRRequest; use TencentCloud\Ocr\V20181119\Models\CarInvoiceOCRRequest; use TencentCloud\Ocr\V20181119\Models\VehicleLicenseOCRRequest; use TencentCloud\Ocr\V20181119\Models\VatInvoiceOCRRequest; -class TcOrc{ - + +class TcOrc +{ + private $accessKeyId; private $accessKeySecret; private $ci; private $dir; private $log_file = 'error.log'; + private $log_success_file = 'success.log'; private $is_dev = false; - public function __construct($accessKeyId='',$accessKeySecret=''){ - if($accessKeyId && $accessKeySecret){ + public function __construct($accessKeyId = '', $accessKeySecret = '') + { + if ($accessKeyId && $accessKeySecret) { $this->accessKeyId = $accessKeyId; $this->accessKeySecret = $accessKeySecret; - }else{ + } else { $this->accessKeyId = 'AKIDMXS7WhbEdlcCWZMs75mDNHuIPHsCF2Yn'; $this->accessKeySecret = 'zh8JDpAF3bOvCCvNYS5RXLs87pGQKxJO'; } - $this->ci = & get_instance(); + $this->ci = &get_instance(); $this->dir = 'tcorc'; - } + } /** * 身份证识别 * Desc: 腾讯官方地址:https://cloud.tencent.com/document/product/866/33524 - * @param $imageUrl string 身份证图片地址 + * @param $imageUrl string 身份证图片地址 * @param $CardSide string 省份证正反面 (FRONT 正面 BACK 反面) * @param return array 返回值参考官方文档 */ - public function IdentityCard($imageUrl,$CardSide='FRONT'){ + public function IdentityCard($imageUrl, $CardSide = 'FRONT') + { try { $cred = new Credential($this->accessKeyId, $this->accessKeySecret); $httpProfile = new HttpProfile(); $httpProfile->setEndpoint("ocr.tencentcloudapi.com"); - + $clientProfile = new ClientProfile(); $clientProfile->setHttpProfile($httpProfile); $client = new OcrClient($cred, "ap-guangzhou", $clientProfile); - + $req = new IDCardOCRRequest(); - + $params = array( "ImageUrl" => $imageUrl, "CardSide" => $CardSide ); $req->fromJsonString(json_encode($params)); - + $resp = $client->IDCardOCR($req); - - debug_log("function:".__FUNCTION__.$resp->toJsonString(),'success.log',$this->dir); - $result = json_decode($resp->toJsonString(),true); - if($result['Error']){ - return ['code'=>0,'msg'=>$result['Error']['Message']]; - }else{ - return ['code'=>1,'msg'=>'识别成功','data'=>$result]; + + debug_log("function:" . __FUNCTION__ . $resp->toJsonString(), $this->log_success_file, $this->dir); + $result = json_decode($resp->toJsonString(), true); + if ($result['Error']) { + return ['code' => 0, 'msg' => $result['Error']['Message']]; + } else { + return ['code' => 1, 'msg' => '识别成功', 'data' => $result]; } - } - catch(TencentCloudSDKException $e) { - debug_log($e,$this->log_file,$this->dir); - return ['code'=>0,'msg'=>'识别失败']; + } catch (TencentCloudSDKException $e) { + debug_log($e, $this->log_file, $this->dir); + return ['code' => 0, 'msg' => '识别失败']; } } + /** * 营业执照 * Desc: 腾讯官方地址:https://cloud.tencent.com/document/product/866/36215 * @param $imageUrl string 营业执照图片url * @param return array 返回值参考官方文档 */ - public function BizLicense($imageUrl){ + public function BizLicense($imageUrl) + { try { $cred = new Credential($this->accessKeyId, $this->accessKeySecret); $httpProfile = new HttpProfile(); $httpProfile->setEndpoint("ocr.tencentcloudapi.com"); - + $clientProfile = new ClientProfile(); $clientProfile->setHttpProfile($httpProfile); $client = new OcrClient($cred, "ap-guangzhou", $clientProfile); - + $req = new BizLicenseOCRRequest(); - + $params = array( "ImageUrl" => $imageUrl, ); $req->fromJsonString(json_encode($params)); - + $resp = $client->BizLicenseOCR($req); - - debug_log("function:".__FUNCTION__.$resp->toJsonString(),'success.log',$this->dir); - $result = json_decode($resp->toJsonString(),true); - if($result['Error']){ - return ['code'=>0,'msg'=>$result['Error']['Message']]; - }else{ - return ['code'=>1,'msg'=>'识别成功','data'=>$result]; + + debug_log("function:" . __FUNCTION__ . $resp->toJsonString(), $this->log_success_file, $this->dir); + $result = json_decode($resp->toJsonString(), true); + if ($result['Error']) { + return ['code' => 0, 'msg' => $result['Error']['Message']]; + } else { + return ['code' => 1, 'msg' => '识别成功', 'data' => $result]; } - } - catch(TencentCloudSDKException $e) { - debug_log($e,$this->log_file,$this->dir); - return ['code'=>0,'msg'=>'识别失败']; + } catch (TencentCloudSDKException $e) { + debug_log($e, $this->log_file, $this->dir); + return ['code' => 0, 'msg' => '识别失败']; } } /** * 购车发票识别 * Desc: 腾讯官方地址:https://cloud.tencent.com/document/product/866/37076 - * @param $imageUrl string 营业执照图片url + * @param $imageUrl string 购车发票图片url * @param return array 返回值参考官方文档 */ - public function CarInvoiceInfos($imageUrl){ + public function CarInvoiceInfos($imageUrl) + { try { $cred = new Credential($this->accessKeyId, $this->accessKeySecret); $httpProfile = new HttpProfile(); $httpProfile->setEndpoint("ocr.tencentcloudapi.com"); - + $clientProfile = new ClientProfile(); $clientProfile->setHttpProfile($httpProfile); $client = new OcrClient($cred, "ap-guangzhou", $clientProfile); - + $req = new CarInvoiceOCRRequest(); - + $params = array( "ImageUrl" => $imageUrl, ); $req->fromJsonString(json_encode($params)); - + $resp = $client->CarInvoiceOCR($req); - - debug_log("function:".__FUNCTION__.$resp->toJsonString(),'success.log',$this->dir); - $result = json_decode($resp->toJsonString(),true); - if($result['Error']){ - return ['code'=>0,'msg'=>$result['Error']['Message']]; - }else{ - return ['code'=>1,'msg'=>'图片识别成功','data'=>$result]; + debug_log("img:" . $imageUrl, 'success.log', $this->dir); + debug_log("function:" . __FUNCTION__ . $resp->toJsonString(), $this->log_success_file, $this->dir); + $result = json_decode($resp->toJsonString(), true); + if ($result['Error']) { + return ['code' => 0, 'msg' => $result['Error']['Message']]; + } else { + return ['code' => 1, 'msg' => '图片识别成功', 'data' => $result]; } - } - catch(TencentCloudSDKException $e) { - debug_log($e,$this->log_file,$this->dir); - return ['code'=>0,'msg'=>'图片识别失败']; + } catch (TencentCloudSDKException $e) { + debug_log($e->getMessage(), $this->log_file, $this->dir); + return ['code' => 0, 'msg' => '图片识别失败']; } } + /** * 行驶证识别 * Desc: 腾讯官方地址:https://cloud.tencent.com/document/product/866/36209 * @param $imageUrl string 行驶证照图片url * @param return array 返回值参考官方文档 */ - public function VehicleLicense($imageUrl){ + public function VehicleLicense($imageUrl) + { try { $cred = new Credential($this->accessKeyId, $this->accessKeySecret); $httpProfile = new HttpProfile(); @@ -181,17 +188,16 @@ class TcOrc{ $resp = $client->VehicleLicenseOCR($req); - debug_log("function:".__FUNCTION__.$resp->toJsonString(),'success.log',$this->dir); - $result = json_decode($resp->toJsonString(),true); - if($result['Error']){ - return ['code'=>0,'msg'=>$result['Error']['Message']]; - }else{ - return ['code'=>1,'msg'=>'图片识别成功','data'=>$result]; + debug_log("function:" . __FUNCTION__ . $resp->toJsonString(), 'success.log', $this->dir); + $result = json_decode($resp->toJsonString(), true); + if ($result['Error']) { + return ['code' => 0, 'msg' => $result['Error']['Message']]; + } else { + return ['code' => 1, 'msg' => '图片识别成功', 'data' => $result]; } - } - catch(TencentCloudSDKException $e) { - debug_log($e,$this->log_file,$this->dir); - return ['code'=>0,'msg'=>'图片识别失败']; + } catch (TencentCloudSDKException $e) { + debug_log($e, $this->log_file, $this->dir); + return ['code' => 0, 'msg' => '图片识别失败']; } } @@ -201,7 +207,8 @@ class TcOrc{ * @param $imageUrl string 增值税发票图片url * @param return array 返回值参考官方文档 */ - public function VatInvoice($imageUrl){ + public function VatInvoice($imageUrl) + { try { $cred = new Credential($this->accessKeyId, $this->accessKeySecret); $httpProfile = new HttpProfile(); @@ -220,17 +227,16 @@ class TcOrc{ $resp = $client->VatInvoiceOCR($req); - debug_log("function:".__FUNCTION__.$resp->toJsonString(),'success.log',$this->dir); - $result = json_decode($resp->toJsonString(),true); - if($result['Error']){ - return ['code'=>0,'msg'=>$result['Error']['Message']]; - }else{ - return ['code'=>1,'msg'=>'图片识别成功','data'=>$result]; + debug_log("function:" . __FUNCTION__ . $resp->toJsonString(), 'success.log', $this->dir); + $result = json_decode($resp->toJsonString(), true); + if ($result['Error']) { + return ['code' => 0, 'msg' => $result['Error']['Message']]; + } else { + return ['code' => 1, 'msg' => '图片识别成功', 'data' => $result]; } - } - catch(TencentCloudSDKException $e) { - debug_log($e,$this->log_file,$this->dir); - return ['code'=>0,'msg'=>'图片识别失败']; + } catch (TencentCloudSDKException $e) { + debug_log($e, $this->log_file, $this->dir); + return ['code' => 0, 'msg' => '图片识别失败']; } } } diff --git a/common/libraries/receiver/Order_datas_entity.php b/common/libraries/receiver/Order_datas_entity.php index d50d9097..68bb29ee 100644 --- a/common/libraries/receiver/Order_datas_entity.php +++ b/common/libraries/receiver/Order_datas_entity.php @@ -19,7 +19,9 @@ class Order_datas_entity public function __construct() { $this->ci = &get_instance(); + $this->ci->load->model('receiver/order/receiver_orders_model', 'orders_model'); $this->ci->load->model('receiver/order/receiver_order_datas_model'); + $this->ci->load->library('TcOrc'); } public function get_row($oid) @@ -54,4 +56,32 @@ class Order_datas_entity } return $result; } + + /** + * 识别发票 + * @param $oid + * @param $url + * @return array + */ + public function orc_bill_img($oid, $url) + { + $result = $this->ci->tcorc->CarInvoiceInfos($url); + if (!$result['code']) { + return ['code' => 0, 'msg' => $result['msg']]; + } + $data = $result['data']['CarInvoiceInfos']; + $bill_code = $bill_time = ''; + foreach ($data as $key => $val) { + if ($val['Name'] == '开票日期') { + $bill_time = $val['Value']; + } + if ($val['Name'] == '发票代码') { + $bill_code = $val['Value']; + } + } + if (!$bill_code) return ['code' => 0, 'msg' => '未识别到发票代码']; + //更新订单开票时间 + $bill_time && $this->ci->orders_model->update(['bill_time' => $bill_time], ['id' => $oid]); + return ['code' => 1, 'msg' => '识别成功', 'data' => $data]; + } }