Files
gaofeng 6d9aee81aa 提交
2026-05-12 18:27:28 +08:00

93 lines
2.7 KiB
PHP

<?php
namespace app\home\controller;
use api\Httpcurl;
use think\exception\HttpResponseException;
use think\facade\Config;
use think\facade\Log;
use think\facade\Request;
use think\Response;
class Invoice extends Base
{
public function initialize()
{
parent::initialize();
if (!$this->_userId) {
throw new HttpResponseException(Response::create($this->error('请先登录', url('user/index'))));
}
}
/**个人中心
*/
public function index()
{
//获取用户的登记信息
$order_sn = Request::instance()->param('order_sn');
if (empty($order_sn)) {
return $this->error('参数错误');
}
$base_url = config('app.order_url');
$order_url = $base_url . 'getOrder';
$response = Httpcurl::request($order_url, 'post', ['order_sn' => $order_sn, 'model' => MODEL]);
if ($response[3]) {
return $this->error('异常错误,请重新提交');
}
$pay_result = json_decode($response[0], true);
if (empty($pay_result)) {
return $this->error('异常错误,请重新提交');
}
Log::info(json_encode($pay_result));
if (!$pay_result['code']) {
return $this->error($pay_result['msg']);
}
$data = $pay_result['data'];
if (empty($data)) {
return $this->error('无此数据');
}
$total_price = $data['total_price'] ? $data['total_price'] : $data['origin_price'];
$data['total_price'] = ($total_price / 100) . "";
return view('', [
'data' => $data,
]);
}
public function add_invoice()
{
$res = [
'status' => 0,
'msg' => '操作失败,请重新填写'
];
unset($_REQUEST['s']);
$_REQUEST['invoiceType'] = INCOICETYPE;
$_REQUEST['model'] = MODEL;
$_REQUEST['principals'] = config('app.principals');
$_REQUEST['uid'] = $this->_userId;
$base_url = config('app.order_url');
$order_url = $base_url . 'add_invoice';
$response = Httpcurl::request($order_url, 'post', $_REQUEST);
if ($response[3]) {
return json($res);
}
$pay_result = json_decode($response[0], true);
Log::info(json_encode($pay_result));
if (empty($pay_result)) {
return json($res);
}
if (!$pay_result['code']) {
$res['msg'] = $pay_result['msg'];
return json($res);
}
$res['status'] = 1;
$res['msg'] = $pay_result['msg'];
$res['url'] = url('user/index')->build();
return json($res);
}
}