Files
spacestation/api/controllers/wxapp/licheb/Cusorderdata.php
T
2024-06-02 18:11:29 +08:00

347 lines
14 KiB
PHP

<?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_model', 'orders_model');
$this->load->model('receiver/order/receiver_order_datas_model');
// $this->load->library('receiver/order_datas_entity');
$this->load->library('TcOrc');
}
protected function get()
{
$id = $this->input_param('id');
$row = $this->orders_model->get(['id' => $id]);
$data = [];
$data['img_status'] = 1;
$row_data = $this->receiver_order_datas_model->get(['o_id' => $id]);
$cardidb = $cardida = $business_licence = $car_img = [];
if ($row_data['car_img']) {
$car_img = [
'value' => $row_data['car_img'],
'img' => build_qiniu_image_url($row_data['car_img'])
];
}
$bill_img = $car_auth_img = $equity_ck_img = $pay_img = $contract_img = $accident_img = $destory_img = $mut_wx_img = $wx_img = $delivery_ck_img = $bill_ck_img = $business_img = $insurance_img = [];
if ($row_data['insurance_img']) {
$insurance_img = [
'value' => $row_data['insurance_img'],
'img' => build_qiniu_image_url($row_data['insurance_img']),
];
}
if ($row_data['business_img']) {
$business_img = [
'value' => $row_data['business_img'],
'img' => build_qiniu_image_url($row_data['business_img']),
];
}
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['contract_img']) {
$contract_img = [
'value' => $row_data['contract_img'],
'img' => build_qiniu_image_url($row_data['contract_img'])
];
}
if ($row_data['pay_img']) {
$pay_img = [
'value' => $row_data['pay_img'],
'img' => build_qiniu_image_url($row_data['pay_img'])
];
}
if ($row_data['equity_ck_img']) {
$equity_ck_img = [
'value' => $row_data['equity_ck_img'],
'img' => build_qiniu_image_url($row_data['equity_ck_img'])
];
}
if ($row_data['car_auth_img']) {
$car_auth_img = [
'value' => $row_data['car_auth_img'],
'img' => build_qiniu_image_url($row_data['car_auth_img'])
];
}
if ($row_data['bill_img']) {
$bill_img = [
'value' => $row_data['bill_img'],
'img' => build_qiniu_image_url($row_data['bill_img'])
];
}
$imgs = [
'cardida' => [],
'cardidb' => [],
'business_licence' => [],
'car_img' => $car_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,
'pay_img' => $pay_img,
'contract_img' => $contract_img,
'equity_ck_img' => $equity_ck_img,
'bill_img' => $bill_img,
'car_auth_img' => $car_auth_img,
'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;
}
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);
}
$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');
$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');
$car_auth_img = $this->input_param('car_auth_img');
$bill_img = $this->input_param('bill_img');
$update = [];
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['name']) {
$res_data['code'] = API_CODE_ORC_FAIL;
$res_data['data'] = [
['caridA' => false, 'errmsg' => '身份证姓名与客户不一致'],
['caridB' => true, 'errmsg' => ''],
];
return $res_data;
}
//个人核对身份证
if ($userinfo['IdNum'] != $row['card_id']) {
$res_data['code'] = API_CODE_ORC_FAIL;
$res_data['data'] = [
['caridA' => false, 'errmsg' => '身份证号码与客户不一致'],
['caridB' => true, 'errmsg' => ''],
];
return $res_data;
}
$update['cardida'] = $cardida;
} 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'] = $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';
$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 ($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;
}
if ($contract_img) {
$key = 'contract_img';
$img = $contract_img;
}
if ($pay_img) {
$key = 'pay_img';
$img = $pay_img;
}
if ($equity_ck_img) {
$key = 'equity_ck_img';
$img = $equity_ck_img;
}
if ($car_auth_img) {
$key = 'car_auth_img';
$img = $car_auth_img;
}
if ($bill_img) {
$key = 'bill_img';
$img = $bill_img;
}
$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);
}
}
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);
}
}