Commit e359fc2f authored by hangjun83's avatar hangjun83

财务开票模块更新]

parent 5986df43
......@@ -23,6 +23,7 @@ class InvoiceService
$this->rhawnInvoiceRepository = app(RhawnInvoiceRepositoryEloquent::class);
$this->rhawnInvoiceItemsRepository = app(RhawnInvoiceItemsRepositoryEloquent::class);
$this->invoiceRecordRepository = $invoiceRecordRepository;
$this->mailService = app(MailService::class);
}
/**
......@@ -479,14 +480,7 @@ class InvoiceService
}
if($updateResult){
//获取发票地址
if(isset($updatedInvoiceResult['invoice_pdf_url']) && !empty($updatedInvoiceResult['invoice_pdf_url'])){
$pdf = $this->apiService->clientRequest('get',$updatedInvoiceResult['invoice_pdf_url'],null);
if($pdf){
$filename = $updatedInvoiceResult['invoice_number'].'_'.$updatedInvoiceResult['invoice_real_date'].'.pdf';
$path = config('filesystems.default.root').'public/finance/invoice/'.$updatedInvoiceResult['invoice_platform'].'/';
$result = Storage::put($path.$filename,$pdf);
}
}
$this->sendInvoiceEmail($updatedInvoiceResult);
}
}else{
$updateInvoice['invoice_status'] = 2;
......@@ -499,6 +493,47 @@ class InvoiceService
}
}
public function sendInvoiceEmail($invoiceParams)
{
//获取发票地址
if(isset($invoiceParams['invoice_pdf_url']) && !empty($invoiceParams['invoice_pdf_url'])){
$filename = $invoiceParams['platform_invoice_id'].'_'.$invoiceParams['invoice_number'].'_'.$invoiceParams['invoice_real_date'].'.pdf';
$path = config('filesystems.default.root').'public/finance/invoice/'.$invoiceParams['invoice_platform'].'/'.$invoiceParams['platform_invoice_id'].'/';
if(!Storage::exists($path.$filename)){
$pdf = $this->apiService->clientRequest('get',$invoiceParams['invoice_pdf_url'],[]);
if($pdf){
Storage::put($path.$filename,$pdf);
}
}
}
//生成download发票的url
$urlParams = [
'platform_invoice_id' => $invoiceParams['platform_invoice_id'],
'invoice_real_number' => $invoiceParams['invoice_real_number'],
'invoice_real_date' => $invoiceParams['invoice_real_date']
];
$token = base64_encode(hash_hmac("sha256", json_encode($urlParams), $invoiceParams['invoice_real_number'], true));
$downloadUrl = 'http://openapi.chem-site.com/finance/invoice/download?token='.$token;
$customerInfo = json_decode($invoiceParams['invoice_customer'],true);
$title = $customerInfo['cust_name'].'电子发票';
$platformName = $invoiceParams['invoice_platform'] == 'rhawn' ? '上海易恩化学技术有限公司' : '上海百舜生物科技有限公司';
$message = '尊敬的'.$customerInfo['cust_name'].','. $platformName . '给您开具了电子发票,请查收。';
$message .= "\r\n发票信息:\r\n";
$message .= "\r\n开票日期: ".date('Y-m-d H:i:s',$invoiceParams['invoice_real_date'])."\r\n";
$message .= "\r\n销方名称: ".$platformName."\r\n";
$message .= "\r\n购方名称: ".$customerInfo['cust_name']."\r\n";
$message .= "\r\n合计金额: ".bcmul($invoiceParams['invoice_money'],1,2)."\r\n";
$message .= "\r\n发票号码: ".$invoiceParams['invoice_real_number']."\r\n";
$message .= '电子发票下载地址 : '.$downloadUrl;
$this->mailService->sendMail($title, 'hangjun@rhawn.cn',$message);
}
public function getInvoicePdfDownloadUrl()
{
......
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