218 lines
6.8 KiB
PHP
218 lines
6.8 KiB
PHP
<?php
|
|
|
|
namespace app\home\controller;
|
|
|
|
use api\Httpcurl;
|
|
use think\facade\Log;
|
|
use think\facade\View;
|
|
use think\facade\Session;
|
|
|
|
use think\facade\Request;
|
|
use think\Url;
|
|
|
|
class Multiple extends Base
|
|
{
|
|
|
|
|
|
public function _initialize()
|
|
{
|
|
parent::_initialize();
|
|
|
|
if (!Session::has('userinfo') || Session::get('userinfo')['id'] <= 0) {
|
|
$this->redirect('login/index');
|
|
}
|
|
}
|
|
|
|
/**个人中心
|
|
*/
|
|
public function index()
|
|
{
|
|
//获取用户的登记信息
|
|
$id = Request::instance()->param('id');
|
|
|
|
if (empty($id)) {
|
|
return $this->error('参数错误');
|
|
}
|
|
$datas = base64_decode($id);
|
|
$order_sns = explode('-', $datas);
|
|
//判断是否有重复订单
|
|
if (count($order_sns) != count(array_unique($order_sns))) {
|
|
return $this->error('有重复订单,请删除后重新提交');
|
|
}
|
|
$real_ordersn = [];
|
|
$total_price = 0;
|
|
$base_url = config('app.order_url');
|
|
$evus_order_url = config('app.get_evus_detail_url');
|
|
$order_url = config('app.get_order_detail_url');
|
|
$invoice_url = $base_url . 'getInvoice';
|
|
$type = Request::instance()->param('type', 'evus');
|
|
foreach ($order_sns as $da) {
|
|
//获取信息
|
|
if ($type == 'evus') {
|
|
$response = Httpcurl::request($evus_order_url, 'post', [
|
|
'order_sn' => $da,
|
|
'model' => MODEL
|
|
]);
|
|
} else {
|
|
$response = Httpcurl::request($order_url, 'post', [
|
|
'order_sn' => $da,
|
|
'model' => ESTA_MODEL
|
|
]);
|
|
}
|
|
|
|
$data = json_decode($response[0], true);
|
|
if (empty($data)) {
|
|
continue;
|
|
}
|
|
//查询是否已经开票了
|
|
$invoice = Httpcurl::request($invoice_url, 'post', [
|
|
'order_sn' => $da,
|
|
'invoiceType' => INCOICETYPE,
|
|
'model' => MODEL
|
|
]);
|
|
if ($invoice[3]) {
|
|
$res['msg'] = '参数错误';
|
|
return json($res);
|
|
}
|
|
$order = json_decode($invoice[0], true);
|
|
Log::info(json_encode($order));
|
|
if (empty($order)) {
|
|
$res['msg'] = '系统错误,请联系管理员!';
|
|
return json($res);
|
|
}
|
|
if (!$order['code']) {
|
|
$res['msg'] = $order['msg'];
|
|
return json($res);
|
|
}
|
|
if (!empty($order['data'])) {
|
|
$res['msg'] = '订单号:' . $da . '已经开票';
|
|
return json($res);
|
|
}
|
|
$real_ordersn[] = $da;
|
|
$total_price += $data['data']['total_price'];
|
|
}
|
|
$data['total_price'] = ($total_price / 100) . "元";
|
|
$data['order_sn'] = implode(',', $real_ordersn);
|
|
View::assign('data', $data);
|
|
View::assign('type', $type);
|
|
return View::fetch();
|
|
}
|
|
|
|
|
|
public function add_invoice()
|
|
{
|
|
$res = [
|
|
'status' => 0,
|
|
'msg' => '操作失败,请重新填写'
|
|
];
|
|
unset($_REQUEST['s']);
|
|
$type = $_REQUEST['type'];
|
|
if ($_REQUEST['type'] == 'evus') {
|
|
$_REQUEST['type'] = 1;
|
|
} else {
|
|
$_REQUEST['type'] = 6;
|
|
}
|
|
$_REQUEST['uid'] = $this->_userId;
|
|
if (empty($_REQUEST['order_sn'])) {
|
|
$res['msg'] = '请选择订单';
|
|
return json($res);
|
|
}
|
|
if (strpos($_REQUEST['tax_number'], " ")) {
|
|
$res['msg'] = '税号包含空格,请删除后重新填写';
|
|
return json($res);
|
|
}
|
|
$order_sns = explode(',', $_REQUEST['order_sn']);
|
|
//判断是否有重复订单
|
|
if (count($order_sns) != count(array_unique($order_sns))) {
|
|
$res['msg'] = '有重复订单,请删除后重新提交';
|
|
return json($res);
|
|
}
|
|
$real_ordersn = [];
|
|
$total_price = 0;
|
|
|
|
$base_url = config('app.order_url');
|
|
$evus_order_url = config('app.get_evus_detail_url');
|
|
$order_url = config('app.get_order_detail_url');
|
|
$invoice_url = $base_url . 'getInvoice';
|
|
foreach ($order_sns as $da) {
|
|
//获取信息
|
|
if ($type == 'evus') {
|
|
$response = Httpcurl::request($evus_order_url, 'post', [
|
|
'order_sn' => $da,
|
|
'model' => MODEL
|
|
]);
|
|
} else {
|
|
$response = Httpcurl::request($order_url, 'post', [
|
|
'order_sn' => $da,
|
|
'model' => ESTA_MODEL
|
|
]);
|
|
}
|
|
$data = json_decode($response[0], true);
|
|
if (empty($data)) {
|
|
$res['msg'] = '未找到订单信息';
|
|
return json($res);
|
|
}
|
|
//判断是否已经开票了
|
|
$invoice = Httpcurl::request($invoice_url, 'post', [
|
|
'order_sn' => $da,
|
|
'invoiceType' => INCOICETYPE,
|
|
'model' => MODEL
|
|
]);
|
|
if ($invoice[3]) {
|
|
$res['msg'] = '参数错误';
|
|
return json($res);
|
|
}
|
|
$order = json_decode($invoice[0], true);
|
|
if (empty($order)) {
|
|
$res['msg'] = '系统错误,请联系管理员!';
|
|
return json($res);
|
|
}
|
|
if (!$order['code']) {
|
|
$res['msg'] = $order['msg'];
|
|
return json($res);
|
|
}
|
|
if (!empty($order['data'])) {
|
|
$res['msg'] = '订单号:' . $da . '已经开票';
|
|
return json($res);
|
|
}
|
|
$real_ordersn[] = $da;
|
|
$total_price += $data['data']['total_price'];
|
|
}
|
|
|
|
if (empty($real_ordersn)) {
|
|
$res['msg'] = '暂无开票订单';
|
|
return json($res);
|
|
}
|
|
$_REQUEST['invoiceType'] = INCOICETYPE;
|
|
$_REQUEST['model'] = MODEL;
|
|
$_REQUEST['principals'] = config('app.principals');
|
|
$_REQUEST['title'] = trim($_REQUEST['title']);
|
|
$_REQUEST['money'] = $total_price;
|
|
$_REQUEST['multiple'] = md5(implode(',', $real_ordersn));
|
|
|
|
$order_urls = $base_url . 'addMultiple';
|
|
$response = Httpcurl::request($order_urls, 'post', $_REQUEST);
|
|
|
|
if ($response[3]) {
|
|
return json($res);
|
|
}
|
|
$pay_result = json_decode($response[0], true);
|
|
if (empty($pay_result)) {
|
|
return json($res);
|
|
}
|
|
if (!$pay_result['code']) {
|
|
$res['msg'] = $pay_result['msg'];
|
|
return json($res);
|
|
}
|
|
|
|
$res = [
|
|
'status' => 1,
|
|
'msg' => '操作成功',
|
|
'url' => url('home/user/order')->build()
|
|
];
|
|
return json($res);
|
|
}
|
|
|
|
}
|
|
|