Files
liche/api/controllers/wxapp/licheb/Cusorderdata.php
T
2023-06-08 17:05:01 +08:00

380 lines
16 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
/**
* Created by PhpStorm.
* User: lcc
* Date: 2022/1/18
* Time: 17:13
*/
require_once APPPATH.'controllers/wxapp/Wxapp.php';
class Cusorderdata 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_v2_model','orders_model');
$this->load->model('receiver/order/receiver_order_status_model');
$this->load->model('receiver/order/receiver_order_datas_model');
$this->load->model('app/liche/app_liche_orders_model');
$this->load->library('receiver/order_datas_entity');
$this->load->library('TcOrc');
}
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){
$data['img_status'] = 1;
$row_data = $this->receiver_order_datas_model->get(['o_id'=>$id]);
$cardidb = $cardida = $business_licence = $register_img = $car_img = [];
if($row_data['car_img']){
$car_img = [
'value' => $row_data['car_img'],
'img' => build_qiniu_image_url($row_data['car_img'])
];
}
if($row_data['register_img']){
$register_img = [
'value' => $row_data['register_img'],
'img' => build_qiniu_image_url($row_data['register_img'])
];
}
$accident_img = $destory_img = $mut_wx_img = $wx_img = $delivery_ck_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,
'rebate' => $d_ins_info['rebate'] ? $d_ins_info['rebate'] : 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,
'rebate' => $d_ins_img['rebate'] ? $d_ins_img['rebate'] : 0,
'date' => $d_ins_img['date'] ? $d_ins_img['date'] : '',
];
}
$d_accident_img = json_decode($row_data['accident_img'],true);
if($d_accident_img){
$accident_img = [
'value' => $d_accident_img['img'],
'img' => build_qiniu_image_url($d_accident_img['img']),
'product' => $d_accident_img['product'] ? $d_accident_img['product'] : '',
'price' => $d_accident_img['price'] ? $d_accident_img['price'] : 0,
'rebate' => $d_accident_img['rebate'] ? $d_accident_img['rebate'] : 0,
'date' => $d_accident_img['date'] ? $d_accident_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);
}
}
if($row_data['delivery_ck_img']){
$delivery_ck_img = [
'value' => $row_data['delivery_ck_img'],
'img' => build_qiniu_image_url($row_data['delivery_ck_img'])
];
}
if($row_data['wx_img']){
$wx_img = [
'value' => $row_data['wx_img'],
'img' => build_qiniu_image_url($row_data['wx_img'])
];
}
if($row_data['mut_wx_img']){
$mut_wx_img = [
'value' => $row_data['mut_wx_img'],
'img' => build_qiniu_image_url($row_data['mut_wx_img'])
];
}
if($row_data['destory_img']){
$destory_img = [
'value' => $row_data['destory_img'],
'img' => build_qiniu_image_url($row_data['destory_img'])
];
}
$jsondata = json_decode($row_data['jsondata'],true);
$imgs = [
'cardida' => [],
'cardidb' => [],
'business_licence' => [],
'car_img' => $car_img,
'register_img' => $register_img,
'ins_img' => [],
'other_img' => [],
'insurance_img' => $insurance_img,
'business_img' => $business_img,
'accident_img' => $accident_img,
'bill_ck_img' => $bill_ck_img,
'wx_img' => $wx_img,
'mut_wx_img' => $mut_wx_img,
'destory_img' => $destory_img,
];
if($row['s_id']==1 || $row['s_id']==33){ //EX1 Pro和EX1需要上传交付确认书)
$imgs['delivery_ck_img'] = $delivery_ck_img;
}
$data['imgs'] = $imgs;
if($row['main_type']){
if($row_data['business_licence']){
$business_licence = [
'value' => $row_data['business_licence'],
'img' => build_qiniu_image_url($row_data['business_licence'])
];
}
$data['imgs']['business_licence'] = $business_licence;
}else{
if($row_data['cardida']){
$cardida = [
'value' => $row_data['cardida'],
'img' => build_qiniu_image_url($row_data['cardida'])
];
}
if($row_data['cardidb']){
$cardidb = [
'value' => $row_data['cardidb'],
'img' => build_qiniu_image_url($row_data['cardidb'])
];
}
$data['imgs']['cardida'] = $cardida;
$data['imgs']['cardidb'] = $cardidb;
}
if($row_data['ins_img']){
$ins_img = json_decode($row_data['ins_img'],true);
$imgs = [];
foreach ($ins_img as $item) {
$imgs[] = [
'value' => $item,
'img' => build_qiniu_image_url($item)
];
}
$data['imgs']['ins_img'] = $imgs;
}
if($row_data['other_img']){
$other_img = json_decode($row_data['other_img'],true);
$imgs = [];
foreach ($other_img as $item) {
$imgs[] = [
'value' => $item,
'img' => build_qiniu_image_url($item)
];
}
$data['imgs']['other_img'] = $imgs;
}
if($row_data['bill_img']){ //开票
$imgs = [];
$data['imgs']['bill_img'] = $imgs;
}
}else{
$data['img_status'] = 0;
}
return $data;
}
protected function put(){
$id = $this->input_param('id');
$row = $this->orders_model->get(['id'=>$id]);
if(!$row){
throw new Exception('参数错误', ERR_PARAMS_ERROR);
}
$info_json = json_decode($row['info_json'],true);
$data_row = $this->receiver_order_datas_model->get(['o_id'=>$id]);
$jsondata = json_decode($data_row['jsondata'],true);
if(!$data_row){
$this->receiver_order_datas_model->add(['o_id'=>$id]);
}
$cardida = $this->input_param('cardida');
$cardidb = $this->input_param('cardidb');
$car_img = $this->input_param('car_img');
$register_img = $this->input_param('register_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');
$update = [];
$update_order = [];
if($cardida){
$full_cardida = build_qiniu_image_url($cardida);
$result = $this->tcorc->IdentityCard($full_cardida);
if(!$result['code']){
$res_data['code'] = API_CODE_ORC_FAIL;
$res_data['data'] = [
['caridA' => false,'errmsg'=>$result['msg']],
['caridB' => true,'errmsg'=>''],
];
return $res_data;
}
$userinfo = $result['data'];
//校验订单客户和身份证姓名
if($userinfo['Name'] != $row['owner_name']){
$res_data['code'] = API_CODE_ORC_FAIL;
$res_data['data'] = [
['caridA' => false,'errmsg'=>'身份证姓名与客户不一致'],
['caridB' => true,'errmsg'=>''],
];
return $res_data;
}
//个人核对身份证
if($userinfo['IdNum'] != $info_json['c_owner_cardid']){
$res_data['code'] = API_CODE_ORC_FAIL;
$res_data['data'] = [
['caridA' => false,'errmsg'=>'身份证号码与客户不一致'],
['caridB' => true,'errmsg'=>''],
];
return $res_data;
}
$update['cardida'] = $cardida;
# 20230222 地址的值用身份证上面的地址
if ($address = $userinfo['Address']){
$info_json['c_address'] = $address;
$update_order['info_json'] = json_encode($info_json, JSON_UNESCAPED_UNICODE);
}
}elseif ($business_licence){
$full_business_licence = build_qiniu_image_url($business_licence);
$result = $this->tcorc->BizLicense($full_business_licence);
if(!$result['code']){
$res_data['code'] = API_CODE_ORC_FAIL;
$res_data['data'] = [
['business_licence' => false,'errmsg'=>$result['msg']],
];
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'] = json_encode(['img'=>$insurance_img],JSON_UNESCAPED_UNICODE);
} elseif($business_img){
$update['business_img'] = json_encode(['img'=>$business_img],JSON_UNESCAPED_UNICODE);
} 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';
$img = $cardidb;
}
if($car_img){ //图片识别行驶证
$key = 'car_img';
$img = $car_img;
$result = $this->tcorc->VehicleLicense(build_qiniu_image_url($car_img));
if (!$result['code']) {
throw new Exception('行驶证识别失败,请重新上传', ERR_PARAMS_ERROR);
}
$jsondata['car_info'] = $result['data']['FrontInfo'];
$update['jsondata'] = json_encode($jsondata,JSON_UNESCAPED_UNICODE);
}
if($register_img){
$key = 'register_img';
$img = $register_img;
}
if($delivery_ck_img){
$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;
}
$key && $update[$key] = $img;
}
$res = $this->receiver_order_datas_model->update($update,['o_id'=>$id]);
if($res){
# 20230222 地址的值用身份证上面的地址
if ($cardida && $update_order){
$this->orders_model->update($update_order, ['id' => $id]);
}
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);
}
}
if($update['car_img']){ //更新车牌号
$this->order_datas_entity->up_car_num($id);
}
throw new Exception('修改成功', API_CODE_SUCCESS);
}else{
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');
$rebate = $this->input_param('rebate');//保险返点
$data_row = $this->receiver_order_datas_model->get(['o_id'=>$id]);
if(!$data_row){
throw new Exception('数据不存在', ERR_PARAMS_ERROR);
}
!$rebate && $rebate = 0;
if($type==1){ //交强险图片
$jsondata = json_decode($data_row['insurance_img'],true);
$jsondata['product'] = $product;
$jsondata['price'] = $price;
$jsondata['rebate'] = $rebate;
$jsondata['date'] = $date;
$update['insurance_img'] = json_encode($jsondata,JSON_UNESCAPED_UNICODE);
}elseif($type==2){ //意外险图片
$jsondata = json_decode($data_row['accident_img'],true);
$jsondata['product'] = $product;
$jsondata['price'] = $price;
$jsondata['rebate'] = $rebate;
$jsondata['date'] = $date;
$update['accident_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['rebate'] = $rebate;
$jsondata['date'] = $date;
$update['business_img'] = json_encode($jsondata,JSON_UNESCAPED_UNICODE);
}
$this->receiver_order_datas_model->update($update,['id'=>$data_row['id']]);
throw new Exception('修改成功', API_CODE_SUCCESS);
}
}