Browse Source

最新优化点

master
wanghongjun 9 months ago
parent
commit
f71220c854
  1. 1
      app/controller/task/InvoiceIssuanceTask.php
  2. 90
      app/service/invoice/InvoiceIssuanceService.php
  3. 20
      app/service/webService/ChinaTaxes.php

1
app/controller/task/InvoiceIssuanceTask.php

@ -26,6 +26,7 @@ class InvoiceIssuanceTask extends Base
$where = ['status' => 0, 'delete_time' => 0];
$InvoiceIssuanceData = (new InvoiceIssuanceModel())->where($where)->page(1, $this->limit)->select()->toArray();
foreach ($InvoiceIssuanceData as $InvoiceIssuanceValue) {
$InvoiceIssuanceValue['project_name'] = InvoiceIssuanceModel::$projectArr[$InvoiceIssuanceValue['project_id']] ?? '';
$result = (new InvoiceIssuanceService())->tempIssueAnInvoice($InvoiceIssuanceValue);
if ($result === true) {
$this->invoiceSuccess($InvoiceIssuanceValue);

90
app/service/invoice/InvoiceIssuanceService.php

@ -49,7 +49,7 @@ class InvoiceIssuanceService
$model = (new InvoiceIssuance());
$data = $model->where($where)
->field('id,project_id,invoice_head_id,amount,create_time,status,serial_number')
->field('id,project_id,invoice_head_id,amount,create_time,status,serial_number,expire_time')
->order('create_time desc')
->paginate($limit, false)
->each(function ($item, $key) {
@ -63,6 +63,7 @@ class InvoiceIssuanceService
}
$item->project_id = InvoiceIssuance::$projectArr[$item->project_id] ?? '';
$item->status_str = InvoiceIssuance::$statusArr[$item->status];
$item->expire_time = date("Y-m", $item->expire_time);
});
return $data->toArray();
}
@ -210,27 +211,51 @@ class InvoiceIssuanceService
$feeUsers['jfrq'] = $FeeComputeDetail['WaterPayDate'];
// 保存
$is_continue = false;// 是否跳过加工
$jsyj = 0; // 总金额
$ChinaTaxes = new ChinaTaxes($feeUsers, $invoiceDate);
$savingDetailedData = $ChinaTaxes->savingDetailedData();
if (!isset($savingDetailedData['sbpch'])) {
$VoucherData = $ChinaTaxes->queryIssuedPaymentVoucher($bdznsrsbh);
$bdzkjmxList = $VoucherData['bdzkjmxList'];
if (empty($bdzkjmxList)) {
throw new \Exception('未查询到待开具电子缴款凭证数据');
}
foreach ($bdzkjmxList as $bdzkjmxValue) {
foreach($bdzkjmxValue['bdzkjmxVO'] as $bdzkjmxVOValue) {
if ($bdzkjmxVOValue['yhbm'] == $pucode) {
$sbpch = $bdzkjmxVOValue['sbpch'];
$jsyj = $bdzkjmxVOValue['ydzse'];
$is_continue = true;
}
}
}
if (!$is_continue) throw new \Exception('未查询到用户开具电子缴款凭证数据');
} else {
// 批次号
$sbpch = $savingDetailedData['sbpch'];
}
// 批次号
$sbpch = $savingDetailedData['sbpch'];
(new InvoiceIssuanceData())->saveField($invoiceIssuance['id'], 'sbpch', $sbpch);
// 委托 - 加工数据
$realTimeProcessing = $ChinaTaxes->realTimeProcessing($sbpch);
$realTimeProcessing = ['code' => 0];
if (!$is_continue) {
$realTimeProcessing = $ChinaTaxes->realTimeProcessing($sbpch);
}
if ($realTimeProcessing['code'] == 200) {
if ($realTimeProcessing['code'] == 200 || $is_continue) {
// 处理加工成功返回数据
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'];
if (!$is_continue) {
if (!isset($realTimeProcessing['data']['mxGrid'])) {
throw new FuncException('加工数据有误');
}
$mxGrid = $realTimeProcessing['data']['mxGrid'];
if (isset($mxGrid['sbMxsjVOList'])) {
foreach ($mxGrid['sbMxsjVOList'] as $sbMxsjVOValue) {
if (isset($sbMxsjVOValue['jsyj'])) $jsyj += $sbMxsjVOValue['jsyj'];
}
}
}
@ -531,6 +556,7 @@ class InvoiceIssuanceService
if (!empty($r_data['ycms'])) {
(new InvoiceIssuanceData())->saveField($data['id'], 'ycms', $r_data['ycms']);
if (empty($r_data['sbpch'])) {
(new InvoiceIssuance())->where('id', $data['id'])->save(['status' => 2]);
// 第一次保存协议就失败
throw new \Exception($r_data['ycms']);
}
@ -575,6 +601,7 @@ class InvoiceIssuanceService
return true;
} catch (\Exception $e) {
(new InvoiceIssuanceData())->saveField($data['id'], 'ycms', $e->getMessage());
//echo $e->getMessage() . '<br>';
return false;
}
@ -674,7 +701,7 @@ class InvoiceIssuanceService
}
if (!$save) {
throw new FuncException('数据储存失败');
throw new FuncException('无新的结报数据');
}
$FinalReportData->saveAll($save);
@ -687,4 +714,37 @@ class InvoiceIssuanceService
return $e->getMessage();
}
}
/**
* 临时结报
* @param $frd_id
* @return bool|string
*/
public function tempFinalReport($frd_id)
{
try {
$FinalReportDate = new FinalReportDate();
$data = $FinalReportDate->where('id', $frd_id)->find();
if (!$data) {
throw new \Exception('参数有误');
}
$zje = FinalReportData::getFrdSumAmount($frd_id);
if ($zje <= 0) {
throw new \Exception('结报金额为0');
}
$result = $this->curl(['report_date' => $data['report_date'], 'zje' => $zje], 'apiFinalReport');
if ($result['code'] == 1) {
$update = [
'status' => 1,
'report_time' => time()
];
FinalReportDate::update($update, ['id' => $frd_id]);
} else {
throw new FuncException($result['msg'] ?? '结报失败');
}
return true;
} catch (\Exception $e) {
return $e->getMessage();
}
}
}

20
app/service/webService/ChinaTaxes.php

@ -132,13 +132,13 @@ class ChinaTaxes
'phjmxzDm' => '',// 增值税小规模纳税人减免性质代码
'ssjmxzDm' => '',// 税收减免性质代码
'wszmkjbz' => 'Y',// 完税证明开具标志为 Y 开具,N不开具
'xmmc' => '测试',// 项目名称
'xmbm' => 'T435',// 项目编码
'xmmc' => $this->puCodeUser['project_name'],// 项目名称
'xmbm' => $this->puCodeUser['serial_number'],// 项目编码
'username' => $userName,// 用户名称(同一个批次,同一个用户编号下,值相同)
'nbyhbm' => $this->puCodeUser['UserCode'],// 用户编号
'jldwmc' => '',// 单位
'sl' => '',// 数量
'zxbz1' => '',// 标准
'sl' => '1',// 数量
'zxbz1' => '1',// 标准
'skyhmc' => !empty($this->puCodeUser['BankName']) ? $this->puCodeUser['BankName'] : '',// 托收银行(同一个批次,同一个用户编号下,值相同)
'yhzh' => !empty($this->puCodeUser['BankAccountCode']) ? $this->puCodeUser['BankAccountCode'] : '',// 银行账号(同一个批次,同一个用户编号下,值相同)
'zsfsmc' => $this->puCodeUser['zsfsmc'],// 缴费方式(同一个批次,同一个用户编号下,值相同)
@ -170,9 +170,9 @@ class ChinaTaxes
$param = $this->getParamData('SSGZ_GZPT_SZQKL_WTDZDRJK', $body);
$res = $this->resultXml($param, 0);
if (!isset($res['sbpch'])) {
/*if (!isset($res['sbpch'])) {
throw new FuncException('未获取到批次号');
}
}*/
return $res;
}
@ -277,14 +277,14 @@ class ChinaTaxes
{
$body = [
'bdzmxList' => [
'bdznsrsbh' => $bdznsrsbh // 被代征人纳税人识别号
'bdzmxVO' => ['bdznsrsbh' => $bdznsrsbh] // 被代征人纳税人识别号
],
'skssqq' => $this->invoiceIssuance['skssqq'], // 税款所属期起,格式,年-月-日
'skssqz' => $this->invoiceIssuance['skssqz'], // 税款所属期止,格式,年-月-日
'my' => $this->my // 密钥,数字签名校验和资格校验
];
$param = $this->getParamData('SSGZ_GZPT_PZ_QUERYDKDZJKP', $body);
$param = $this->getParamData('SSGZ_GZPT_PZ_QUERYDKDZJKPZ', $body);
return $this->resultXml($param);
}
@ -721,7 +721,9 @@ xmlns:ns2="http://www.chinatax.gov.cn/dataspec/">';
$xmlData = $this->xmlDom($deData);
if (isset($xmlData['ns2:code']) && $xmlData['ns2:code'] != 200) {
throw new FuncException($xmlData['ns2:message']);
if ($xmlData['ns2:message'] != '已结报的属期,不允许导入') {
throw new FuncException($xmlData['ns2:message']);
}
}
$returnData = $this->delNs2Filed($xmlData);

Loading…
Cancel
Save