279 lines
9.0 KiB
PHP
279 lines
9.0 KiB
PHP
<?php
|
|
|
|
namespace app\home\controller;
|
|
|
|
use api\Httpcurl;
|
|
use think\exception\HttpResponseException;
|
|
use think\facade\Log;
|
|
use think\facade\Request;
|
|
use think\facade\Session;
|
|
use think\facade\View;
|
|
use think\Response;
|
|
|
|
class User extends Base
|
|
{
|
|
private $userinfo;
|
|
private static $follow_status = [
|
|
'0' => '未跟进',
|
|
'1' => '跟进中',
|
|
'3' => '已完成',
|
|
];
|
|
|
|
public function initialize()
|
|
{
|
|
parent::initialize();
|
|
if (!Session::has('user') || Session::get('user')['id'] <= 0) {
|
|
throw new HttpResponseException(redirect(url('home/login/index')->build()));
|
|
}
|
|
$this->userinfo = Session::get('user');
|
|
View::assign('userinfo', $this->userinfo);
|
|
View::assign('is_user_center', true);
|
|
}
|
|
|
|
/**个人中心
|
|
*/
|
|
public function order()
|
|
{
|
|
$paystatus = Request::instance()->param('paystatus', '');
|
|
$paystatus = $paystatus ? $paystatus : 'pay';
|
|
if (!in_array($paystatus, ['pay', 'nopay'])) {
|
|
return $this->error('参数错误');
|
|
}
|
|
$list = Httpcurl::request(GET_ORDER_URL, 'post', [
|
|
'model' => MODEL,
|
|
'user_id' => $this->_userId,
|
|
'invoiceType' => INCOICETYPE,
|
|
'pay_status' => $paystatus,
|
|
]);
|
|
$result = json_decode($list[0], true);
|
|
Log::info(json_encode($result));
|
|
if (empty($result)) {
|
|
return $this->error('获取订单失败');
|
|
}
|
|
if (!$result['code']) {
|
|
return $this->error('获取订单失败');
|
|
}
|
|
return view('', [
|
|
'paystauts' => $paystatus,
|
|
'data' => $result['data'],
|
|
]);
|
|
}
|
|
public function orderEsta()
|
|
{
|
|
$paystatus = Request::instance()->param('paystatus', '');
|
|
$paystatus = $paystatus ? $paystatus : 'pay';
|
|
if (!in_array($paystatus, ['pay', 'nopay'])) {
|
|
return $this->error('参数错误');
|
|
}
|
|
$list = Httpcurl::request(GET_ORDER_URL, 'post', [
|
|
'model' => ESTA_MODEL,
|
|
'user_id' => $this->_userId,
|
|
'invoiceType' => ESTA_INCOICETYPE,
|
|
'pay_status' => $paystatus,
|
|
]);
|
|
$result = json_decode($list[0], true);
|
|
Log::info(json_encode($result));
|
|
if (empty($result)) {
|
|
return $this->error('获取订单失败');
|
|
}
|
|
if (!$result['code']) {
|
|
return $this->error('获取订单失败');
|
|
}
|
|
return view('', [
|
|
'paystauts' => $paystatus,
|
|
'data' => $result['data'],
|
|
]);
|
|
|
|
}
|
|
public function invoice()
|
|
{
|
|
return View::fetch();
|
|
}
|
|
public function multiple()
|
|
{
|
|
return View::fetch();
|
|
}
|
|
|
|
public function logout()
|
|
{
|
|
Session::delete('user');
|
|
return redirect(url('home/index/index')->build());
|
|
}
|
|
|
|
public function checkInvoice()
|
|
{
|
|
$res = [
|
|
'status' => 0,
|
|
'msg' => '操作失败'
|
|
];
|
|
$passport_number = Request::instance()->param('passport_number');
|
|
$order_sn = Request::instance()->param('order_sn');
|
|
$last_name = Request::instance()->param('last_name');
|
|
$first_name = Request::instance()->param('first_name');
|
|
if (empty($passport_number) || empty($order_sn) || empty($last_name) || empty($first_name)) {
|
|
$res['msg'] = '参数错误';
|
|
return json($res);
|
|
}
|
|
$base_url = config('app.order_url');
|
|
|
|
$order_url = $base_url . 'checkInvoice';
|
|
$response = Httpcurl::request($order_url, 'post', [
|
|
'passport_number' => trim($passport_number),
|
|
'order_sn' => trim($order_sn),
|
|
'last_name' => trim($last_name),
|
|
'first_name' => trim($first_name),
|
|
'model' => MODEL
|
|
]);
|
|
if ($response[3]) {
|
|
$res['msg'] = '参数错误';
|
|
return json($res);
|
|
}
|
|
$data = json_decode($response[0], true);
|
|
Log::info(json_encode($data));
|
|
if (empty($data)) {
|
|
$res['msg'] = '系统错误,请联系管理员!';
|
|
return json($res);
|
|
}
|
|
if (!$data['code']) {
|
|
$res['msg'] = "暂无订单信息";
|
|
return json($res);
|
|
}
|
|
$invoice_url = $base_url . 'getInvoice';
|
|
//判断是否已经开票了
|
|
$response = Httpcurl::request($invoice_url, 'post', [
|
|
'order_sn' => $order_sn,
|
|
'invoiceType' => INCOICETYPE,
|
|
'model' => MODEL
|
|
]);
|
|
if ($response[3]) {
|
|
$res['msg'] = '参数错误';
|
|
return json($res);
|
|
}
|
|
$order = json_decode($response[0], true);
|
|
Log::info(json_encode($order));
|
|
if (empty($order)) {
|
|
$res['msg'] = '系统错误,请联系管理员!';
|
|
return json($res);
|
|
}
|
|
if (!$order['code']) {
|
|
return json($res);
|
|
}
|
|
if (!empty($order['data'])) {
|
|
$res['msg'] = '发票已受理,请勿重复提交';
|
|
return json($res);
|
|
}
|
|
$res = [
|
|
'status' => 1,
|
|
'msg' => '操作成功',
|
|
'url' => url('home/invoice/index', ['order_sn' => $order_sn])->build()
|
|
];
|
|
return json($res);
|
|
|
|
}
|
|
|
|
public function checkMultiple()
|
|
{
|
|
$res = [
|
|
'status' => 0,
|
|
'msg' => '操作失败'
|
|
];
|
|
$datas = Request::instance()->param('datas');
|
|
if (empty($datas)) {
|
|
$res['msg'] = '参数错误';
|
|
return json($res);
|
|
}
|
|
$datas = json_decode(html_entity_decode(stripslashes($datas)), true);
|
|
if (empty($datas)) {
|
|
$res['msg'] = '数据错误';
|
|
return json($res);
|
|
}
|
|
$order_sns = array_column($datas, 'order_sn');
|
|
//判断是否有重复订单
|
|
if (count($order_sns) != count(array_unique($order_sns))) {
|
|
$res['msg'] = '有重复订单,请删除后重新提交';
|
|
return json($res);
|
|
}
|
|
$base_url = config('app.order_url');
|
|
|
|
$order_url = $base_url . 'checkInvoice';
|
|
$invoice_url = $base_url . 'getInvoice';
|
|
foreach ($datas as $da) {
|
|
//获取信息
|
|
$response = Httpcurl::request($order_url, 'post', [
|
|
'passport_number' => trim($da['passport_number']),
|
|
'order_sn' => trim($da['order_sn']),
|
|
'last_name' => trim($da['last_name']),
|
|
'first_name' => trim($da['first_name']),
|
|
'model' => MODEL
|
|
]);
|
|
if ($response[3]) {
|
|
$res['msg'] = '参数错误';
|
|
return json($res);
|
|
}
|
|
$data = json_decode($response[0], true);
|
|
Log::info(json_encode($data));
|
|
if (empty($data)) {
|
|
$res['msg'] = '未查到订单信息';
|
|
return json($res);
|
|
}
|
|
//查询是否已经开票了
|
|
$response = Httpcurl::request($invoice_url, 'post', [
|
|
'order_sn' => trim($da['order_sn']),
|
|
'invoiceType' => INCOICETYPE,
|
|
'model' => MODEL
|
|
]);
|
|
if ($response[3]) {
|
|
$res['msg'] = '参数错误';
|
|
return json($res);
|
|
}
|
|
$order = json_decode($response[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['order_sn'] . '已经开票';
|
|
return json($res);
|
|
}
|
|
}
|
|
$order_sns = implode('-', $order_sns);
|
|
|
|
$res = [
|
|
'status' => 1,
|
|
'msg' => '操作成功',
|
|
'url' => url('home/multiple/index', ['id' => base64_encode($order_sns)])->build()
|
|
];
|
|
return json($res);
|
|
|
|
}
|
|
|
|
public function pay()
|
|
{
|
|
$order_sn = Request::instance()->param('order_sn');
|
|
if (empty($order_sn)) {
|
|
return $this->error('参数错误');
|
|
}
|
|
$order_url = config('app.get_evus_detail_url');
|
|
$response = Httpcurl::request($order_url, 'post', ['order_sn' => $order_sn, 'model' => MODEL]);
|
|
if ($response[3]) {
|
|
return $this->error("订单不存在,请重新提交", url('visa/index'));
|
|
}
|
|
$pay_result = json_decode($response[0], true);
|
|
Log::info(json_encode($pay_result));
|
|
if (empty($pay_result)) {
|
|
return $this->error("订单不存在,请重新提交", url('visa/index'));
|
|
}
|
|
if (!$pay_result['code']) {
|
|
return $this->error($pay_result['msg'], url('visa/index'));
|
|
}
|
|
return redirect(url('home/pay/index', ['order_sn' => $pay_result['data']['order_sn']])->build());
|
|
|
|
}
|
|
}
|
|
|