Commit 6a98f56d authored by hangjun83's avatar hangjun83

财务开票模块更新

parent f5cbe331
......@@ -198,7 +198,7 @@ class InvoiceService
$applyInvoiceItems['spmc'] = $item['item_name'];
$applyInvoiceItems['spbm'] = '1070214010000000000';//$item['p_code'];
$applyInvoiceItems['ggxh'] = $item['item_spec'];
$applyInvoiceItems['dw'] = 'EA';
$applyInvoiceItems['dw'] = $item['item_unit'];
$applyInvoiceItems['je'] = bcmul($item['item_price'],1,2);
$applyInvoiceItems['sl'] = $item['item_nums'];
$applyInvoiceItems['dj'] = bcdiv($applyInvoiceItems['je'],$applyInvoiceItems['sl'],2);
......@@ -286,17 +286,10 @@ class InvoiceService
public function confirmRedInvoice()
{
}
public function cancelRedInvoice()
{
}
public function downloadInvioce($invoiceNumber)
{
}
public function queryInvoiceInfo($invoiceParams)
......@@ -479,8 +472,13 @@ class InvoiceService
$updateResult = $this->rhawnInvoiceRepository->updateInvoiceById($updatedInvoiceResult['platform_invoice_id'], $updateParams);
}
if($updateResult){
//获取发票地址
$this->sendInvoiceEmail($updatedInvoiceResult);
//塞入队列
$this->apiService->pushQueue([
'params' => $updatedInvoiceResult,
'consumer' => __CLASS__,
'method' => 'sendInvoiceEmail'
],'invoiceEmailPush');
//$this->sendInvoiceEmail($updatedInvoiceResult);
$this->apiService->removePlatformDataEntries('invoice_callBack_'.$invoiceResponse['ddlsh'].'_applyInvoice');
}
}
......@@ -544,7 +542,6 @@ class InvoiceService
//$html = file_get_contents(resource_path('views/emails/invoice.blade.php'));
//查询购买方邮箱
$cusInfo = $this->rhawnInvoiceRepository->queryCustomerInfoByInvoiceId($invoiceParams['platform_invoice_id']);
if($cusInfo){
$cusInfo = current($cusInfo);
......@@ -572,7 +569,25 @@ class InvoiceService
/*if($token != $params['token']){
throw new \Exception('电子发票无效无法提供下载',502);
}*/
$downloadUrl = $this->getDownloadUrl($invoiceInfo);
return [ 'path' => $downloadUrl['downloadUrl'], 'filename' => $downloadUrl['filename']];
}
private function saveInvoicePdf($path,$pdfUrl)
{
$cmd = 'chmod -R 777 storage/';
trim(shell_exec("$cmd 2>&1"));
if(!Storage::exists($path)){
$pdf = $this->apiService->clientRequest('get',$pdfUrl,[]);
if($pdf){
Storage::put($path, $pdf);
}
}
}
private function getDownloadUrl($invoiceInfo)
{
if(empty($invoiceInfo['invoice_pdf_url'])){
$invoiceResponse = $this->queryInvoiceInfo([
'invoice_platform' => $invoiceInfo['invoice_platform'],
......@@ -590,24 +605,24 @@ class InvoiceService
$this->saveInvoicePdf($path.$filename, $invoiceInfo['invoice_pdf_url']);
$downloadUrl = $invoiceInfo['invoice_platform'] == 'rhawn' ? 'http://download.rhawn.cn/' : 'http://download.chem-mall.com';
return [ 'path' => $downloadUrl.$path.$filename, 'filename' => $filename];
return [ 'downloadUrl' => $downloadUrl.$path.$filename, 'path' => $path, 'filename' => $filename ];
}
public function saveInvoicePdf($path,$pdfUrl)
public function getInvoicePdfDownloadUrl($params)
{
$cmd = 'chmod -R 777 storage/';
trim(shell_exec("$cmd 2>&1"));
if(!Storage::exists($path)){
$pdf = $this->apiService->clientRequest('get',$pdfUrl,[]);
if($pdf){
Storage::put($path, $pdf);
}
if(empty($params)){
return false;
}
}
$invoiceInfo = $this->invoiceRecordRepository->getInvoiceRecordByRealNumber($params['invoice_real_number']);
if(!$invoiceInfo){
throw new \Exception('没有对应的电子发票提供下载',502);
}
$invoiceInfo = current($invoiceInfo);
public function getInvoicePdfDownloadUrl()
{
$downloadUrl = $this->getDownloadUrl($invoiceInfo);
return $downloadUrl;
}
}
......@@ -96,4 +96,23 @@ class InvoiceController extends Controller
}
}
public function downloadInvoice(Request $request)
{
$requestParams = $this->formatKeysfromArray($request->all(),'toUnderScore');
try{
$result = $this->invoiceService->getInvoicePdfDownloadUrl($requestParams);
$headers = [
'Content-Type: application/pdf',
];
//下载电子发票
header('Content-Type: application/octet-stream');
header("Content-Transfer-Encoding: utf-8");
header("Content-disposition: attachment; filename=\"" . basename($result['filename']) . "\"");
readfile($result['path']);
}catch(\Throwable $exception){
return $this->returnErrorExecptionResponse($exception,$exception->getMessage());
}
}
}
......@@ -20,6 +20,7 @@ $api->version('v1', function($api) {
$api->group(['namespace'=>'App\Http\Controllers\V1\Finance','middleware' => ['throttle:60,1','apiAuth'], 'providers' => 'jwt'], function($api) {
$api->post('/finance/invoice/applyInvoice', ['permission' => 'finance.applyInvoice', 'uses'=>'InvoiceController@applyInvoice']);
$api->post('/finance/invoice/downloadInvoice', ['permission' => 'finance.downloadInvoice', 'uses'=>'InvoiceController@downloadInvoice']);
});
});
......
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