135 lines
5.7 KiB
PHP
135 lines
5.7 KiB
PHP
<?php
|
|
defined('BASEPATH') or exit('No direct script access allowed');
|
|
require_once APPPATH . 'controllers/auto/BaseController.php';
|
|
|
|
class Subsidy extends BaseController
|
|
{
|
|
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->load->model('area_model');
|
|
$this->load->model('agent/auto_user_coupon_model');
|
|
$this->load->model('agent/receiver_order_subsidy_model');
|
|
$this->load->model('receiver/order/receiver_orders_model');
|
|
$this->load->model("biz/biz_model");
|
|
$this->load->model('auto/auto_brand_model');
|
|
$this->load->model('auto/auto_series_model');
|
|
$this->auto_brand_model->set_db('ssdb');
|
|
$this->auto_series_model->set_db('ssdb');
|
|
$this->biz_model->set_db('ssdb');
|
|
$this->receiver_orders_model->set_db('ssdb');
|
|
$this->load->library('TcOrc');
|
|
}
|
|
|
|
public function index_post()
|
|
{
|
|
try {
|
|
$params = $this->post();
|
|
$couponId = $params['couponId'];
|
|
/** @var AutoUserCouponEntity $userCoupon */
|
|
$userCoupon = $this->auto_user_coupon_model->get(['id' => $couponId, 'userId' => $this->userId], '', 'AutoUserCouponEntity');
|
|
if (!$userCoupon) {
|
|
throw new Exception('优惠券不存在');
|
|
}
|
|
$result = $userCoupon->useCoupon($params);
|
|
if (!$result->isSuccess()) {
|
|
throw new Exception($result->getMessage());
|
|
}
|
|
$reqData = $result->getData();
|
|
//识别发票
|
|
if ($params['businessImg'] && $reqData['orderId']) {
|
|
$url = build_qiniu_image_url($params['businessImg']);
|
|
$billTime = "";
|
|
$ocrResult = $this->tcorc->CarInvoiceInfos($url);
|
|
if ($ocrResult['code'] && $ocrResult['data']['CarInvoiceInfos']) {
|
|
$carInvoiceInfos = $ocrResult['data']['CarInvoiceInfos'];
|
|
foreach ($carInvoiceInfos as $item) {
|
|
if ($item['Name'] == '开票日期') {
|
|
$billTime = str_replace(['年', '月', '日'], ['-', '-', ''], $item['Value']);
|
|
break;
|
|
}
|
|
}
|
|
$billTime = date('Y-m-d', strtotime($billTime));
|
|
}
|
|
if ($billTime) {
|
|
$this->receiver_orders_model->update(['bill_time' => $billTime], ['id' => $reqData['orderId']]);
|
|
}
|
|
}
|
|
$this->return_response();
|
|
} catch (Exception $e) {
|
|
$this->return_json($e->getMessage());
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 修改审核资料
|
|
* @return void
|
|
*/
|
|
public function index_put()
|
|
{
|
|
$params = $this->input_param();
|
|
$row = $this->receiver_order_subsidy_model->get(['id' => $params['id'], 'userId' => $this->userId]);
|
|
if (!$row) {
|
|
$this->return_json("数据不存在");
|
|
}
|
|
$update = [
|
|
'billImg' => $params['billImg'] ?: '',
|
|
'businessImg' => $params['businessImg'] ?: '',
|
|
'contractImg' => $params['contractImg'] ?: '',
|
|
'ifcheck' => Receiver_order_subsidy_model::IF_CHECK_NO
|
|
];
|
|
$result = $this->receiver_order_subsidy_model->update($update, ['id' => $params['id']]);
|
|
if (!$result) {
|
|
$this->return_json("保存失败");
|
|
}
|
|
$this->return_response();
|
|
}
|
|
|
|
/**
|
|
* 补贴详情
|
|
* @return void
|
|
*/
|
|
public function detail_get()
|
|
{
|
|
$id = $this->input_param('id');
|
|
$row = $this->receiver_order_subsidy_model->get(['id' => $id, 'userId' => $this->userId]);
|
|
if (!$row) {
|
|
$this->return_json("参数错误");
|
|
}
|
|
$userCoupon = $this->auto_user_coupon_model->get(['couponId' => $row['couponId'], 'userId' => $this->userId]);
|
|
$order = $this->receiver_orders_model->get(['id' => $row['orderId']]);
|
|
$cityRow = $this->area_model->get(['city_id' => $row['cityId']]);
|
|
$rowBiz = $this->biz_model->get(array('id' => $row['bizId']));
|
|
$brand = $this->auto_brand_model->get(['id' => $row['brandId']], 'name');
|
|
$series = $this->auto_series_model->get(['id' => $row['seriesId']], 'name');
|
|
$contractFile = $insuranceFile = [];
|
|
if ($row['businessImg']) {
|
|
$insuranceFile[] = ['url' => $row['businessImg'] ? build_qiniu_image_url($row['businessImg']) : ''];
|
|
}
|
|
if ($row['contractImg']) {
|
|
$contractFile[] = ['url' => $row['contractImg'] ? build_qiniu_image_url($row['contractImg']) : ''];
|
|
}
|
|
$data = [
|
|
'mobile' => mobile_asterisk($userCoupon['mobile']),
|
|
'name' => $order['name'],
|
|
'city' => $cityRow['province_name'] . '/' . $cityRow['city_name'],
|
|
'cityId' => $row['cityId'],
|
|
'store' => $rowBiz['biz_name'],
|
|
'storeId' => $rowBiz['id'],
|
|
'model' => "{$brand['name']} {$series['name']}",
|
|
'brandId' => $row['brandId'],
|
|
'seriesId' => $row['seriesId'],
|
|
'invoiceFile' => [
|
|
['url' => $row['billImg'] ? build_qiniu_image_url($row['billImg']) : '']
|
|
],
|
|
'invoiceUrl' => $row['billImg'] ?: '',
|
|
'insuranceFile' => $insuranceFile,
|
|
'contractUtl' => $row['contractImg'] ?: '',
|
|
'contractFile' => $contractFile,
|
|
'insuranceUrl' => $row['businessImg'] ?: '',
|
|
'reason' => Receiver_order_subsidy_model::IF_CHECK_NO_PASS ? $row['reason'] : '',
|
|
];
|
|
$this->return_response($data);
|
|
}
|
|
} |