edit-admin-order_filter

This commit is contained in:
lccsw
2022-04-26 11:33:14 +08:00
parent 9eb0b90d4e
commit d524851e6c
4 changed files with 142 additions and 3 deletions
+32 -1
View File
@@ -689,6 +689,7 @@ class Orders extends HD_Controller
return $this->show_json(SYS_CODE_FAIL, '参数错误!');
}
$agent = $this->order_agents_model->get(['o_id' => $row['id']]);
$jsondata = json_decode($agent['jsondata'],true);
$update = [];
$update['car_num'] = $params['car_num'];
$update['ins_time'] = $params['ins_time'] ? date('Y-m-d H:i:s', strtotime($params['ins_time'])) : '0000-00-00 00:00:00';
@@ -701,12 +702,42 @@ class Orders extends HD_Controller
$jsondata['ins_risk'] = $params['ins_risk'];
$jsondata['business_risk'] = $params['business_risk'];
$jsondata['register_img'] = $params['register_img'];
$update['jsondata'] = json_encode($jsondata, JSON_UNESCAPED_UNICODE);
if ($params['bx_imgs']) {
$this->load->library('qiniuorc');
$imgs = explode(',', $params['bx_imgs']);
$update['ins_img'] = json_encode($imgs, JSON_UNESCAPED_UNICODE);
$old_ins_img = json_encode(json_decode($agent['ins_img'],true),JSON_UNESCAPED_UNICODE);
if($update['ins_img']!=$old_ins_img && is_array($imgs)){
//图片识别
foreach ($imgs as $key => $val) {
$url = build_qiniu_image_url($val);
$res = $this->qiniuorc->car_insure($url);
if($res['code']){
$company = $res['data']['保险公司'];
if(count($res['data']['投保险种'])>3){ //商业
$business_risk = (float)$res['data']['合计保费'];
}else{ //交强险
$ins_risk = (float)$res['data']['合计保费'];
}
$json_orc_ins[] = $res['data'];
}
}
}
if(!$params['company'] && $company){
$jsondata['company'] = $company;
}
if(!$params['ins_risk'] && $ins_risk){
$jsondata['ins_risk'] = $ins_risk;
}
if(!$params['business_risk'] && $business_risk){
$jsondata['business_risk'] = $business_risk;
}
$jsondata['ins_orc'] = $json_orc_ins;
}else{
$update['ins_img'] = null;
}
$update['jsondata'] = json_encode($jsondata, JSON_UNESCAPED_UNICODE);
if ($agent) {
if($agent['status']<0 && $row['status']>=4){
$update['status'] = 0;
@@ -67,6 +67,9 @@ class Orders extends HD_Controller
if($key2){
$where_s = [];
$key==1 && $where_s["{$t1}.payway"] = 0;//分期
if(strlen($key) && !$key && $key2==1){ //已下定过滤退款
$where_s["{$t1}.status <>"] = 2;
}
if($key==4){ //交付需要开票后才显示
$where_s["{$t1}.id in (select o_id from lc_receiver_order_status where pid_status=3 and status=1)"] = null;
}
+2 -2
View File
@@ -185,8 +185,8 @@ class Ordersv2List
{$this->t1}.cor_id,{$this->t1}.incor_id,{$this->t1}.money_json,{$this->t1}.payway,{$this->t1}.status,{$this->t1}.c_time,
{$this->t1}.biz_id,{$this->t1}.bill_time,{$this->t1}.customer_id,{$this->t1}.owner_name,{$this->t1}.owner_mobile,{$this->t1}.main_type,{$this->t1}.info_json,
{$this->t1}.order_time,{$this->t1}.bill_time,{$this->t1}.item_id";
if ($params['status_pid'] == 3 && strlen($params['status'])) { //开票
if (strlen($params['status_pid']) && $params['status'] == 1) { //付款-已下定
$where["{$this->t1}.status <> 2"] = null;
}
if ($params['status_pid'] == 4) { //交付需要开票后才显示
$where["{$this->t1}.id in (select o_id from lc_receiver_order_status where pid_status=3 and status=1)"] = null;
+105
View File
@@ -0,0 +1,105 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
require_once COMMPATH.'third_party/Qiniu/autoload.php';
class Qiniuorc{
private $token = '';
private $log_file = 'qiniu_orc.log';
const CAR_URL = 'http://ocr-car-bd.qiniuapi.com/ocr/car_bd';
public function __construct($config = []){
$CI = & get_instance();
if(!$config){
$CI->config->load('qiniu', true, true);
$qiniu_config = $CI->config->item('qiniu');
$this->config = $qiniu_config['img'];
}
}
/**
* 保险单识别
* @param $img_url 图片url地址
* @return array
*/
public function car_insure($img_url){
// $img_url = "https://img.liche.cn/liche/liche/202204/p_c7ea3a764339e41539625e33f3f2ac37.jpg";
$file_base64 = $this->imgtobase64($img_url);
$body=json_encode(['image'=>$file_base64]);
$url = self::CAR_URL;
$host="ocr-car-bd.qiniuapi.com";
$method='POST';
$header = $this->header($url,$method,$body);
$header['Content-type']= 'application/json';
$header['Host']= $host;
$head=[];
foreach($header as $k=>$v){
$head[]=$k.':'.$v;
}
$result=$this->post_json_data($url,$body,$head);
$data = json_decode($result,true);
if(!$data['errorcode'] && $data['items']['保险公司']!='None'){
$res = ['code' => 1 ,'msg' => '识别成功','data'=>$data['items']];
}else{
$msg = $data['errorcode'] ? $data['errormsg'] : '';
debug_log("识别图片地址:".$img_url,$this->log_file);
debug_log("识别结果:".json_encode($data,JSON_UNESCAPED_UNICODE),$this->log_file);
$res = ['code' => 0 ,'msg'=>'识别失败:'.$msg];
}
return $res;
}
private function header($url,$method,$body,$contentType = "application/json"){
// 需要填写你的 Access Key 和 Secret Key
$accessKey = $this->config['access_key'];
$secretKey = $this->config['secret_key'];
// 构建鉴权对象
$auth = new \Qiniu\Auth($accessKey, $secretKey);
$header=$auth->authorizationV2($url,$method,$body,$contentType);
return $header;
}
function post_json_data($url, $data_string,$aHeader,$timeout=300) {
if(!$aHeader){
$length=strlen($data_string);
$aHeader= array('Content-type:application/json', 'Content-length:'.$length);
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
//设置头文件的信息作为数据流输出
//curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $aHeader);
// post数据
curl_setopt($ch, CURLOPT_POST, true);
// post的变量
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
$file_contents = curl_exec($ch);
curl_close($ch);
return $file_contents;
}
/**
* 把网络图片图片转成base64
* @param $url 图片url地址
* @return void
*/
public function imgtobase64($url){
$stream_opts = [
"ssl" => [
"verify_peer"=>false,
"verify_peer_name"=>false,
]
];
$img = file_get_contents($url,false,stream_context_create($stream_opts));
$temp_path = FCPATH.'temp/'.time().rand(100000,999999).'jpg';
file_put_contents($temp_path,$img);
$base64 = '';
if($fp = fopen($temp_path,"rb", 0)) {
$gambar = fread($fp,filesize($temp_path));
fclose($fp);
$base64 = chunk_split(base64_encode($gambar));
}
@unlink($temp_path);
return $base64;
}
}