Commit c3d63752 authored by hangjun83's avatar hangjun83

财务开票模块更新

parent d60851ca
......@@ -44,4 +44,10 @@ class InvoiceRecordRepositoryEloquent extends BaseRepository implements InvoiceR
return $result;
}
public function getInvoiceRecordByRealNumber($realNumber)
{
$result = $this->getList(['invoice_real_number' => $realNumber]);
return $result;
}
}
......@@ -27,7 +27,7 @@ class RhawnInvoiceRepositoryEloquent extends BaseRepository implements RhawnInvo
{
$invoice = $this->where('soi_id',$id)->get()->toArray();
if($invoice){
return $invoice;
return current($invoice);
}
return null;
}
......
......@@ -38,14 +38,11 @@ class BaiwangApiService extends PlatformAbstractService
}
}
public function queryOrder($params = [])
public function queryOrder($params)
{
try{
if($this->checkPlatformStatus()){
$queryParams = [
'qyId' => '23020214385104316',
'ddlsh' => '15382750'
];
$queryParams = $params;
$response = $this->sendPost($this->getPlatformApiUrl().'/cloud/queryOrder',$queryParams);
return $this->response($response);
}
......@@ -66,9 +63,7 @@ class BaiwangApiService extends PlatformAbstractService
if($this->checkPlatformStatus()){
$requestParams = $params;
$response = $this->sendPost($this->getPlatformApiUrl().'/cloud/applyElecInvoice',$requestParams);
$token = $this->response($response);
return $token['data'];
return $this->response($response);
}
}catch(\Throwable $exception){
......@@ -85,14 +80,9 @@ class BaiwangApiService extends PlatformAbstractService
{
try{
if($this->checkPlatformStatus()){
$tokenParams = [
'accessId' => $this->platformInfo['platform_params']['prod_accessId'],
'accessSecret' => $this->platformInfo['platform_params']['prod_accessSecret']
];
$response = $this->getPostClient($this->getPlatformApiUrl().'/openApi/v1/token',$tokenParams);
$token = $this->apiResponse($response);
return $token['data'];
$requestParams = $params;
$response = $this->getPostClient($this->getPlatformApiUrl().'/cloud/elecInvoiceCancel',$requestParams);
return $this->response($response);
}
}catch(\Exception $exception){
......@@ -107,21 +97,6 @@ class BaiwangApiService extends PlatformAbstractService
*/
public function cancelElecRedInvoice($params)
{
try{
if($this->checkPlatformStatus()){
$tokenParams = [
'accessId' => $this->platformInfo['platform_params']['prod_accessId'],
'accessSecret' => $this->platformInfo['platform_params']['prod_accessSecret']
];
$response = $this->getPostClient($this->getPlatformApiUrl().'/openApi/v1/token',$tokenParams);
$token = $this->apiResponse($response);
return $token['data'];
}
}catch(\Exception $exception){
return $this->exception($exception);
}
}
/**
......@@ -131,21 +106,6 @@ class BaiwangApiService extends PlatformAbstractService
*/
public function queryRedInvoiceConfirmState($params)
{
try{
if($this->checkPlatformStatus()){
$tokenParams = [
'accessId' => $this->platformInfo['platform_params']['prod_accessId'],
'accessSecret' => $this->platformInfo['platform_params']['prod_accessSecret']
];
$response = $this->getPostClient($this->getPlatformApiUrl().'/openApi/v1/token',$tokenParams);
$token = $this->apiResponse($response);
return $token['data'];
}
}catch(\Exception $exception){
return $this->exception($exception);
}
}
......@@ -158,14 +118,9 @@ class BaiwangApiService extends PlatformAbstractService
{
try{
if($this->checkPlatformStatus()){
$tokenParams = [
'accessId' => $this->platformInfo['platform_params']['prod_accessId'],
'accessSecret' => $this->platformInfo['platform_params']['prod_accessSecret']
];
$response = $this->getPostClient($this->getPlatformApiUrl().'/openApi/v1/token',$tokenParams);
$token = $this->apiResponse($response);
return $token['data'];
$requestParams = $params;
$response = $this->getPostClient($this->getPlatformApiUrl().'/cloud/invoiceDownload',$requestParams);
return $this->response($response);
}
}catch(\Exception $exception){
......@@ -206,9 +161,6 @@ class BaiwangApiService extends PlatformAbstractService
$options['body'] = $this->requestParamsEncode($paramsBody);
var_dump($this->requestParamsEncode($paramsBody));
exit;
list($url,$method) = explode($this->platformInfo['platform_url'],$uri);
// auth签名
$header = array_merge($header,$this->authHeaders($method));
......
<?php
/*
* This file is part of the Jiannei/lumen-api-starter.
*
* (c) Jiannei <longjian.huang@foxmail.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace App\Finance\Services;
use App\Finance\Repositories\Contracts\InvoiceRecordRepository;
......@@ -231,7 +222,53 @@ class InvoiceService
public function cancelBlueInvoice()
{
if(!isset($invoiceParams['invoice_platform']) || empty($invoiceParams['invoice_platform'])){
throw new \Exception('开票平台不存在',502);
}
if(!isset($invoiceParams['invoice_real_number']) || empty($invoiceParams['invoice_real_number'])){
throw new \Exception('发票号码不存在',502);
}
if(!isset($invoiceParams['invoice_cancel_by']) || empty($invoiceParams['invoice_cancel_by'])){
throw new \Exception('发票作废人不存在',502);
}
if(!isset($invoiceParams['invoice_platform']) || empty($invoiceParams['invoice_platform'])){
throw new \Exception('开票平台不存在',502);
}
if(!in_array($invoiceParams['invoice_platform'],['rhawn','bhua'])){
throw new \Exception('开票平台不在允许范围内',502);
}
//查询发票号码对应的数据
$invoiceInfo = $this->invoiceRecordRepository->getInvoiceRecordByRealNumber($invoiceParams['invoice_real_number']);
if(!$invoiceInfo){
throw new \Exception('发票数据不存在',502);
}
if($invoiceInfo['invoice_status'] != 1){
throw new \Exception('该发票不是确认状态,无法作废',502);
}
$platformInfo = $this->apiService->getPlatformInfo()['platform_params'][$invoiceParams['invoice_platform']];
$cancelInvoiceParams = [];
$cancelInvoiceParams['qyId'] = $platformInfo['qyid'];
$cancelInvoiceParams['ddlsh'] = $invoiceInfo['invoice_number'];
$cancelInvoiceParams['dlzh'] = $platformInfo['nsrsbh'];
$cancelInvoiceParams['zfr'] = $invoiceParams['invoice_real_number'];
//记录请求参数
$this->apiService->storePlatformDataEntries('invoice_cancel_'.$invoiceInfo['invoice_number'].'_'.$invoiceInfo['invoice_real_number'],$cancelInvoiceParams);
$response = $this->apiService->cancelElecInvoice($cancelInvoiceParams);
if($response){
$this->invoiceRecordRepository->saveInvoice([
'invoice_number' => $invoiceInfo['invoice_number'],
'invoice_status' => 2
]);
return true;
}
throw new \Exception('发票作废失败',502);
}
public function confirmRedInvoice()
......
......@@ -29,6 +29,18 @@ class InvoiceController extends Controller
}
}
public function cancelInvoice(Request $request)
{
$requestParams = $this->formatKeysfromArray($request->all(),'toUnderScore');
try{
$result = $this->invoiceService->cancelBlueInvoice($requestParams);
return Response::success($result,'发票作废申请成功');
}catch(\Throwable $exception){
return $this->returnErrorExecptionResponse($exception,$exception->getMessage());
}
}
public function baiwangInvoiceCallBack(Request $request)
{
$requestContent = $request->getContent();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment