4 changed files with 150 additions and 17 deletions
@ -0,0 +1,138 @@ |
|||
<?php |
|||
|
|||
namespace app\service\invoice; |
|||
|
|||
use app\service\webService\ChinaTaxes; |
|||
use fast\FuncException; |
|||
|
|||
class TempInvoiceService |
|||
{ |
|||
|
|||
|
|||
/** |
|||
* 开具完税证明 |
|||
* @param $invoiceIssuance // 开票信息 |
|||
* @return array |
|||
*/ |
|||
public function IssueAnInvoice($invoiceIssuance) |
|||
{ |
|||
$returnData = [ |
|||
'sbpch' => '', |
|||
'ycms' => '' |
|||
]; |
|||
try { |
|||
$InvoiceIssuanceService = new InvoiceIssuanceService(); |
|||
// 用户编码 |
|||
$pucode = $invoiceIssuance['pucode']; |
|||
|
|||
if (empty($invoiceIssuance['expire_time'])) { |
|||
throw new FuncException('申请日期不能为空'); |
|||
} |
|||
|
|||
$invoiceDate = $InvoiceIssuanceService->getInvoiceDate($invoiceIssuance['expire_time']); |
|||
|
|||
$feeUsers = $InvoiceIssuanceService->getFeeUserData($pucode); |
|||
|
|||
$bdznsrsbh = $InvoiceIssuanceService->getTaxNumber(0); // 被代征纳税人识别号 |
|||
|
|||
$feeUsers['bdznsrsbh'] = $bdznsrsbh; |
|||
|
|||
// 获取用户应收费信息 |
|||
$FeeComputeDetail = InvoiceIssuanceService::getFeeComputeDetail($pucode, date("Ym", $invoiceIssuance['expire_time'])); |
|||
if ($FeeComputeDetail['MsgID'] != 1) { |
|||
throw new FuncException($FeeComputeDetail); |
|||
} |
|||
|
|||
$feeUsers['jsyj'] = $FeeComputeDetail['WaterAmount']; |
|||
$feeUsers['zsfsmc'] = $FeeComputeDetail['chargetype']; |
|||
$feeUsers['jfrq'] = $FeeComputeDetail['WaterPayDate']; |
|||
|
|||
// 保存 |
|||
$ChinaTaxes = new ChinaTaxes($feeUsers, $invoiceDate); |
|||
$savingDetailedData = $ChinaTaxes->savingDetailedData(); |
|||
|
|||
// 批次号 |
|||
$sbpch = $savingDetailedData['sbpch']; |
|||
$returnData['sbpch'] = $sbpch; |
|||
|
|||
// 委托 - 加工数据 |
|||
$realTimeProcessing = $ChinaTaxes->realTimeProcessing($sbpch); |
|||
|
|||
if ($realTimeProcessing['code'] == 200) { |
|||
// 处理加工成功返回数据 |
|||
if (!isset($realTimeProcessing['data']['mxGrid'])) { |
|||
throw new FuncException('加工数据有误'); |
|||
} |
|||
$mxGrid = $realTimeProcessing['data']['mxGrid']; |
|||
|
|||
$jsyj = 0; // 总金额 |
|||
if (isset($mxGrid['sbMxsjVOList'])) { |
|||
foreach ($mxGrid['sbMxsjVOList'] as $sbMxsjVOValue) { |
|||
if (isset($sbMxsjVOValue['jsyj'])) $jsyj += $sbMxsjVOValue['jsyj']; |
|||
} |
|||
} |
|||
|
|||
// 加工成功 电子缴款申请 |
|||
$issueElectronic = $ChinaTaxes->issueElectronic($sbpch, $bdznsrsbh); |
|||
|
|||
if (!isset($issueElectronic['pzsqkjYcxxList']['pzsqkjYcxxVO']['assetID'])) { |
|||
throw new FuncException('文件唯一标识不存在'); |
|||
} |
|||
$assetID = $issueElectronic['pzsqkjYcxxList']['pzsqkjYcxxVO']['assetID']; // 文件唯一标识 |
|||
|
|||
// 查询电子缴款凭证上链信息 |
|||
$queryPaymentVoucher = $ChinaTaxes->queryPaymentVoucher($assetID); |
|||
|
|||
//$mmq = $queryPaymentVoucher['mmq']; |
|||
$meta = $queryPaymentVoucher['meta']; |
|||
$data = $queryPaymentVoucher['data']; |
|||
|
|||
// 拼接pdf |
|||
// 盖章 |
|||
$requestData = ['data' => $data, 'meta' => $meta]; |
|||
$deCompress = $InvoiceIssuanceService->deCompress($requestData); |
|||
if ($deCompress['status'] != 200) { |
|||
throw new FuncException('pdf数据解密失败'); |
|||
} |
|||
if (!isset($deCompress['data']['pdfdata'])) { |
|||
throw new FuncException('pdf文件合并失败'); |
|||
} |
|||
$pdfFilepath = $deCompress['data']['pdfdata'];//$this->savePdfFile($deCompress['data']['pdfdata']); |
|||
|
|||
$returnData['i_i_d_data'] = [ |
|||
'i_i_id' => $invoiceIssuance['id'], |
|||
'bdznsrsbh' => $bdznsrsbh, |
|||
'jsyj' => $jsyj, |
|||
'assetID' => $assetID, |
|||
'pdfFilepath' => $pdfFilepath, |
|||
]; |
|||
|
|||
$returnData['i_i_data'] = [ |
|||
'status' => 3, |
|||
'issuance_time' => time() |
|||
]; |
|||
} else if ($realTimeProcessing['code'] == 302) { |
|||
// 加工失败 |
|||
|
|||
// 查询上传异常数据接口 |
|||
$queryUploadErrorData = $ChinaTaxes->queryUploadErrorData($sbpch); |
|||
if (!isset($queryUploadErrorData['mxGrid']['sbMxsjVOList']['ycms'])) { |
|||
throw new FuncException('异常信息返回有误'); |
|||
} |
|||
// 查询待开具电子缴款 |
|||
$ChinaTaxes->queryIssuedPaymentVoucher($bdznsrsbh); |
|||
|
|||
// 保存用户异常状态 |
|||
$ycms = $queryUploadErrorData['mxGrid']['sbMxsjVOList']['ycms']; // 数据异常描述 |
|||
$returnData['ycms'] = $ycms; |
|||
|
|||
// 开票失败 |
|||
$returnData['i_i_data'] = ['status' => 2]; |
|||
//throw new FuncException('加工失败流程待定!'); |
|||
} |
|||
} catch (\Exception $e) { |
|||
$returnData['ycms'] = $e->getMessage(); |
|||
} |
|||
return $returnData; |
|||
} |
|||
} |
|||
Loading…
Reference in new issue