Browse Source

同步线上版本

master
wanghongjun 4 months ago
parent
commit
9255c4f5eb
  1. 22
      app/controller/api/InvoiceIssuance.php
  2. 6
      app/controller/task/InvoiceIssuanceTask.php
  3. 213
      app/service/invoice/InvoiceIssuanceService.php
  4. 237
      app/service/webService/ChinaTaxes.php
  5. 2
      app/validate/InvoiceIssuanceValidate.php

22
app/controller/api/InvoiceIssuance.php

@ -77,24 +77,8 @@ class InvoiceIssuance extends Base
$param = $this->request->post();
validate(InvoiceIssuanceValidate::class)->scene('feePay')->check($param);
$tax_number = $param['tax_number'] ?? '';
if (!empty($tax_number)) {
$str = '0-9A-HJ-NPQRTUWXY';
$pattern = '/^[' . $str . ']{2}\d{6}[' . $str . ']{10}$/';
if (!preg_match($pattern, $tax_number)) {
throw new \Exception('纳税人编号格式错误');
}
}
$wechat_user_id = $this->request->wechat_user_id;
$res = InvoiceIssuanceService::validateFeePay(
$param['pucode'],
$param['expire_time'],
$param['project_id'],
$param['merge'],
$tax_number,
$wechat_user_id
);
$res = InvoiceIssuanceService::validateFeePay($param['pucode'],$param['expire_time'],$param['project_id']);
return $this->buildSuccess($res);
} catch (\Exception $e) {
@ -122,7 +106,7 @@ class InvoiceIssuance extends Base
$field = 'title,tax_number';
if (!$param['type']) {
$field .= ',address,telephone,bank_name,bank_account';
$field .= ',address,telephone,bank_name,bank_account';
}
$InvoiceHead = new InvoiceHead;
@ -212,7 +196,7 @@ class InvoiceIssuance extends Base
'expire_time' => strtotime($params['expire_time']),
];
$where = [['status', '<>', 3], ['delete_time', '=', 0]];
$where = [['status', 'in', [0,1,3]], ['delete_time', '=', 0]];
if ($id) {
$where[] = ['id', '!=', $id];
}

6
app/controller/task/InvoiceIssuanceTask.php

@ -11,7 +11,7 @@ use think\Response;
class InvoiceIssuanceTask extends Base
{
protected $limit = 100;
protected $limit = 20;
/**
* 申请开票任务
@ -27,7 +27,7 @@ class InvoiceIssuanceTask extends Base
$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);
$result = (new InvoiceIssuanceService())->IssueAnInvoice($InvoiceIssuanceValue);
if ($result === true) {
$this->invoiceSuccess($InvoiceIssuanceValue);
}
@ -63,7 +63,7 @@ class InvoiceIssuanceTask extends Base
*/
public function runSummaryReport(): Response
{
$result = (new InvoiceIssuanceService())->tempSaveSummaryReport();
$result = (new InvoiceIssuanceService())->saveSummaryReport();
if ($result !== true) {
return $this->buildFailed('0', $result);
}

213
app/service/invoice/InvoiceIssuanceService.php

@ -7,7 +7,6 @@ use app\model\FinalReportDate;
use app\model\InvoiceHead;
use app\model\InvoiceIssuance;
use app\model\InvoiceIssuanceData;
use app\service\user\UserService;
use app\service\webService\ChinaTaxes;
use app\service\webService\FeeService;
use fast\FuncException;
@ -50,22 +49,22 @@ class InvoiceIssuanceService
$model = (new InvoiceIssuance());
$data = $model->where($where)
->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) {
$InvoiceHead = (new InvoiceHead)->find($item->invoice_head_id);
$item->serial_number = !empty($item->serial_number) ? $item->serial_number : $this->getSerialNumber();
$item->head_type = '';
$item->head_title = '';
if ($InvoiceHead) {
$item->head_type = InvoiceHead::$typeArr[$InvoiceHead['type']];
$item->head_title = $InvoiceHead['title'];
}
$item->project_id = InvoiceIssuance::$projectArr[$item->project_id] ?? '';
$item->status_str = InvoiceIssuance::$statusArr[$item->status];
$item->expire_time = date("Y-m", $item->expire_time);
});
->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) {
$InvoiceHead = (new InvoiceHead)->find($item->invoice_head_id);
$item->serial_number = !empty($item->serial_number) ? $item->serial_number : $this->getSerialNumber();
$item->head_type = '';
$item->head_title = '';
if ($InvoiceHead) {
$item->head_type = InvoiceHead::$typeArr[$InvoiceHead['type']];
$item->head_title = $InvoiceHead['title'];
}
$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();
}
@ -83,13 +82,10 @@ class InvoiceIssuanceService
* @param $pucode
* @param $expire_time
* @param $project_id
* @param string $merge 是否合并
* @param string $tax_number
* @param int $wechat_user_id
* @return string[]
* @throws FuncException
*/
public static function validateFeePay($pucode, $expire_time, $project_id, string $merge = '', string $tax_number = '', int $wechat_user_id = 0): array
public static function validateFeePay($pucode, $expire_time, $project_id): array
{
$expire_date = date('Ym', strtotime($expire_time));
@ -98,39 +94,13 @@ class InvoiceIssuanceService
switch ($project_id) {
case 1:
case 2:
// 合并逻辑
if ($merge == '1') {
if (empty($tax_number)) {
throw new FuncException('请填写纳税人编号');
}
$pucodeArr = UserService::getTaxUser($tax_number, $wechat_user_id);
if (empty($pucodeArr)) {
throw new FuncException('登录的用户id与纳税人编号不符,请重新输入');
}
$pucodeArr[] = $pucode;
$pucodeArr = array_unique($pucodeArr);
$amount = 0;
foreach ($pucodeArr as $newPuCode) {
$ComputeDetail = self::getFeeComputeDetail($newPuCode, $expire_date);
if ($ComputeDetail['MsgID'] != 1) {
throw new FuncException($errorMsg);
}
$amount = bcadd($amount, $ComputeDetail['WaterAmount'], 2);
}
return ['amount' => $amount];
} else {
$ComputeDetail = self::getFeeComputeDetail($pucode, $expire_date);
if ($ComputeDetail['MsgID'] != 1) {
throw new FuncException($errorMsg);
}
return ['amount' => $ComputeDetail['WaterAmount']];
$ComputeDetail = self::getFeeComputeDetail($pucode, $expire_date);
if ($ComputeDetail['MsgID'] != 1) {
throw new FuncException($errorMsg);
}
return ['amount' => $ComputeDetail['WaterAmount']];
default:
throw new FuncException('尚未开发,请耐心等待!');
}
@ -158,10 +128,10 @@ class InvoiceIssuanceService
unset($param['PaymentStatus']);
$data2 = $FeeService->getReadingDetail($param);
$data['ThisLastReadingTime'] = '';
if ($data2['MsgID'] != 1) {
if ($data2['MsgID'] == 1) {
$ThisReadingTime = $data2['ThisReadingTime'] ? self::optionReadingTime($data2['ThisReadingTime']) : '';
$LastReadingTime = $data2['LastReadingTime'] ? self::optionReadingTime($data2['LastReadingTime']) : '';
$data['ThisLastReadingTime'] = $ThisReadingTime . ' 至 ' . $LastReadingTime;
$data['ThisLastReadingTime'] = $LastReadingTime . ' 至 ' . $ThisReadingTime;
}
return $data;
@ -184,7 +154,7 @@ class InvoiceIssuanceService
* @param $expire_time
* @return array
*/
public function getInvoiceDate($expire_time): array
private function getInvoiceDate($expire_time): array
{
$expire_time = strtotime(date("Y-m",$expire_time));
return [
@ -247,90 +217,61 @@ class InvoiceIssuanceService
$invoiceDate = $this->getInvoiceDate($invoiceIssuance['expire_time']);
$feeUsers = $this->getFeeUserData($pucode);
$bdznsrsbh = $this->getTaxNumber($invoiceIssuance['invoice_head_id']); // 被代征纳税人识别号
$puCodeUserData = [];
$pucodeArr = [$pucode];
$feeUsers['bdznsrsbh'] = $bdznsrsbh;
if ($invoiceIssuance['merge'] != 1) {
$pucodeArr = UserService::getTaxUser($bdznsrsbh, $invoiceIssuance['wechat_user_id']);
$pucodeArr[] = $pucode;
$pucodeArr = array_unique($pucodeArr);
// 获取用户应收费信息
$FeeComputeDetail = self::getFeeComputeDetail($pucode, date("Ym", $invoiceIssuance['expire_time']));
if ($FeeComputeDetail['MsgID'] != 1) {
throw new FuncException($FeeComputeDetail);
}
// 多组用户编号
foreach ($pucodeArr as $valPucode) {
$feeUsers = $this->getFeeUserData($valPucode);
$feeUsers['bdznsrsbh'] = $bdznsrsbh;
// 获取用户应收费信息
$FeeComputeDetail = self::getFeeComputeDetail($valPucode, 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'];
$feeUsers['project_name'] = $invoiceIssuance['project_name'] ?? '';
$feeUsers['serial_number'] = $invoiceIssuance['serial_number'];
$feeUsers['WaterUsage'] = $FeeComputeDetail['WaterUsage'];
$feeUsers['WaterItem'] = $FeeComputeDetail['WaterItem'];
$feeUsers['WaterQty'] = $FeeComputeDetail['WaterQty'];
$feeUsers['WaterPrice'] = $FeeComputeDetail['WaterPrice'];
$feeUsers['ThisLastReadingTime'] = $FeeComputeDetail['ThisLastReadingTime'];
$puCodeUserData[] = $feeUsers;
}
$feeUsers['jsyj'] = $FeeComputeDetail['WaterAmount'];
$feeUsers['zsfsmc'] = $FeeComputeDetail['chargetype'];
$feeUsers['jfrq'] = $FeeComputeDetail['WaterPayDate'];
$feeUsers['project_name'] = $invoiceIssuance['project_name'] ?? '';
$feeUsers['serial_number'] = $invoiceIssuance['serial_number'];
$feeUsers['WaterUsage'] = $FeeComputeDetail['WaterUsage'];
$feeUsers['WaterItem'] = $FeeComputeDetail['WaterItem'];
$feeUsers['WaterQty'] = $FeeComputeDetail['WaterQty'];
$feeUsers['WaterPrice'] = $FeeComputeDetail['WaterPrice'];
$feeUsers['ThisLastReadingTime'] = $FeeComputeDetail['ThisLastReadingTime'];
// 保存
$is_continue = false;// 是否跳过加工
$jsyj = 0; // 总金额
$ChinaTaxes = new ChinaTaxes($puCodeUserData, $invoiceDate);
$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'];
// 已结包修改期属
if (isset($savingDetailedData['code']) && $savingDetailedData['code'] == '123456') {
$invoiceIssuance['expire_time'] = strtotime(date("Y-m"));
$invoiceDate = $this->getInvoiceDate($invoiceIssuance['expire_time']);
$ChinaTaxes = new ChinaTaxes($feeUsers, $invoiceDate);
$savingDetailedData = $ChinaTaxes->savingDetailedData();
}
// 批次号
$sbpch = $savingDetailedData['sbpch'];
(new InvoiceIssuanceData())->saveField($invoiceIssuance['id'], 'sbpch', $sbpch);
// 委托 - 加工数据
$realTimeProcessing = ['code' => 0];
if (!$is_continue) {
$realTimeProcessing = $ChinaTaxes->realTimeProcessing($sbpch);
}
$realTimeProcessing = $ChinaTaxes->realTimeProcessing($sbpch);
if ($realTimeProcessing['code'] == 200 || $is_continue) {
if ($realTimeProcessing['code'] == 200) {
// 处理加工成功返回数据
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'];
}
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'];
}
}
@ -369,7 +310,8 @@ class InvoiceIssuanceService
// 查询上传异常数据接口
$queryUploadErrorData = $ChinaTaxes->queryUploadErrorData($sbpch);
if (!isset($queryUploadErrorData['data']['mxGrid']['sbMxsjVOList']['ycms'])) {
if (!isset($queryUploadErrorData['mxGrid']['sbMxsjVOList']['ycms'])) {
throw new FuncException('异常信息返回有误');
}
// 查询待开具电子缴款
@ -382,16 +324,20 @@ class InvoiceIssuanceService
// 开票失败
(new InvoiceIssuance())->where('id', $invoiceIssuance['id'])->save(['status' => 2]);
//throw new FuncException('加工失败流程待定!');
return false;
}
return true;
} catch (\Exception $e) {
//dump($e,11);die;
(new InvoiceIssuanceData())->saveField($invoiceIssuance['id'], 'ycms', $e->getMessage());
// 未获取到批次号报错
if (empty($sbpch)) {
if ($e->getMessage() != '接入访问会话已经过期,请重新登录') {
(new InvoiceIssuance())->where('id', $invoiceIssuance['id'])->save(['status' => 0]);
}
$this->writeLog($e);
// 未获取到批次号报错
if (empty($sbpch)) {}
//$this->writeLog($e);
return $e->getMessage();
}
}
@ -418,7 +364,7 @@ class InvoiceIssuanceService
$identityCheck = $ChinaTaxes->identityCheck($bdznsrsbh);
if (isset($identityCheck['zt']) && $identityCheck['zt'] == 'N') {
throw new FuncException($identityCheck['Yy']);// 返回校验不通过原因
throw new FuncException($identityCheck['Yy']);// 返回校验不通过原因
}
// 代征明细数据虚拟户更正接口
@ -576,7 +522,7 @@ class InvoiceIssuanceService
*/
public function deCompress(array $data)
{
$java_decode_url = 'https://intp.xingtongworld.com/v1/tax/xt';
$java_decode_url = 'http://localhost:8080/v1/tax/xt';
// 初始化cURL会话
$ch = curl_init();
@ -601,7 +547,7 @@ class InvoiceIssuanceService
// 检查是否有错误发生
if (curl_errno($ch)) {
throw new FuncException('请求失败');
throw new FuncException('请求失败!!!');
}
// 关闭cURL会话
@ -631,8 +577,8 @@ 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]);
// 第一次保存协议就失败
(new InvoiceIssuance())->where('id', $data['id'])->save(['status' => 2]);
throw new \Exception($r_data['ycms']);
}
}
@ -676,8 +622,7 @@ class InvoiceIssuanceService
return true;
} catch (\Exception $e) {
(new InvoiceIssuanceData())->saveField($data['id'], 'ycms', $e->getMessage());
//echo $e->getMessage() . '<br>';
//dump($e->getMessage());
return false;
}
}

237
app/service/webService/ChinaTaxes.php

@ -52,7 +52,9 @@ class ChinaTaxes
protected function getAccessToken()
{
$tax_key = 'tax_access_token';
$tax_access_token = Cache::get($tax_key);
if ($tax_access_token) {
$this->accessToken = $tax_access_token;
} else {
@ -68,6 +70,7 @@ class ChinaTaxes
];
$result = $this->json_curl(json_encode($param));
if (isset($result['error'])) {
throw new FuncException($result['error']['message']);
}
@ -77,7 +80,7 @@ class ChinaTaxes
}
$this->accessToken = $result['result']['accessToken'];
Cache::set($tax_key, $this->accessToken, 28680);
Cache::set($tax_key, $this->accessToken, 3600);
}
}
@ -109,101 +112,50 @@ class ChinaTaxes
*/
public function savingDetailedData(): array
{
$puCodeUser = $this->puCodeUser;
$mxGrid = [];
foreach ($puCodeUser as $data) {
$userName = !empty($data['ContactName']) ? $data['ContactName']
: $data['UserName'];
$zxbz1 = strpos($data['WaterUsage'], '居民') !== false ? '0.59'
: '0.27';
$mxGrid[] = [
'bdznsrsbh' => $data['bdznsrsbh'],
// 被代征纳税人识别号 *
'bdznsrmc' => $userName,
// 被代征纳税人名称 *
'gjhdqszDm' => '156',
// 国家或地区数字代码
'sfzjlxDm' => '201',
// 身份证件类型代码
'zjhm' => !empty($data['CertificateCode'])
? $data['CertificateCode'] : '',
// 证件号码 *
'hyDm' => '6490',
// 行业代码
'zsxmDm' => '30433',
// 征收项目代码
'zspmDm' => '304331300',
// 征收品目代码
'zszmDm' => '',
// 征收子目代码
'jsyj' => $data['jsyj'],
// 计税依据,保留两位小数
'sl1' => '',
// 税率,可手工填写,不填则默认系统自动计算,保留两位小数
'ynse' => '',
// 应纳税额,可手工填写,不填则默认系统自动计算,保留两位小数
'ydzse' => '',
// 应代征税额,可手工填写,不填则默认系统自动计算,保留两位小数
'yjse' => '',
// 已缴税额,可手工填写,不填则默认系统自动计算,保留两位小数
'ydzse1' => '',
// 已代征税额,可手工填写,不填则默认系统自动计算,保留两位小数
'jmse' => '',
// 减免税额,可手工填写,不填则默认系统自动计算,保留两位小数
'phjmse' => '',
// 增值税小规模纳税人减征额
'phjzbl' => '',
// 增值税小规模纳税人减征比例
'phjmxzDm' => '',
// 增值税小规模纳税人减免性质代码
'ssjmxzDm' => '',
// 税收减免性质代码
'wszmkjbz' => 'Y',
// 完税证明开具标志为 Y 开具,N不开具
'xmmc' => $data['project_name'],
// 项目名称
'xmbm' => substr(time(), 1, 9),
// 项目编码
'username' => $userName,
// 用户名称(同一个批次,同一个用户编号下,值相同)
'nbyhbm' => $data['UserCode'],
// 用户编号
'jldwmc' => '立方米',
// 单位
'sl' => $data['WaterQty'] ?? '',
// 数量
'zxbz1' => $zxbz1,
// 标准
'skyhmc' => !empty($data['BankName']) ? $data['BankName']
: '',
// 托收银行(同一个批次,同一个用户编号下,值相同)
'yhzh' => !empty($data['BankAccountCode'])
? $data['BankAccountCode'] : '',
// 银行账号(同一个批次,同一个用户编号下,值相同)
'zsfsmc' => $data['zsfsmc'],
// 缴费方式(同一个批次,同一个用户编号下,值相同)
'tjsd' => $data['ThisLastReadingTime'],
// 收费时段(同一个批次,同一个用户编号下,值相同)
'jfyj1' => $data['jsyj'],
// 计费依据(同一个批次,同一个用户编号下,值相同)
'yhje' => '0.00',
// 优惠金额
'hjje' => $data['jsyj'],
// 合计金额
'jfrq' => $data['jfrq'],
// 缴费时间(同一个批次,同一个用户编号下,值相同)
'lxfs' => !empty($data['CellPhone']) ? $data['CellPhone']
: '',
// 联系方式(同一个批次,同一个用户编号下,值相同)
'lxdz' => !empty($data['WaterUseAddress'])
? $data['WaterUseAddress'] : '',
// 送票地址(同一个批次,同一个用户编号下,值相同)
'remark' => '无',
// 备注(同一个批次,同一个用户编号下,值相同)
'bz' => '',
// 备注信息(同一个批次,同一个用户编号下,值相同)
];
}
$userName = !empty($this->puCodeUser['UserName']) ? $this->puCodeUser['UserName'] : $this->puCodeUser['ContactName'];
$zxbz1 = strpos($this->puCodeUser['WaterUsage'], '居民') !== false ? '0.59' : '0.27';
$mxGrid = [
'bdznsrsbh' => $this->puCodeUser['bdznsrsbh'],// 被代征纳税人识别号 *
'bdznsrmc' => $userName,// 被代征纳税人名称 *
'gjhdqszDm' => '156',// 国家或地区数字代码
'sfzjlxDm' => '201',// 身份证件类型代码
'zjhm' => !empty($this->puCodeUser['CertificateCode']) ? $this->puCodeUser['CertificateCode'] : '',// 证件号码 *
'hyDm' => '6490',// 行业代码
'zsxmDm' => '30433',// 征收项目代码
'zspmDm' => '304331300',// 征收品目代码
'zszmDm' => '',// 征收子目代码
'jsyj' => $this->puCodeUser['jsyj'],// 计税依据,保留两位小数
'sl1' => '',// 税率,可手工填写,不填则默认系统自动计算,保留两位小数
'ynse' => '',// 应纳税额,可手工填写,不填则默认系统自动计算,保留两位小数
'ydzse' => '',// 应代征税额,可手工填写,不填则默认系统自动计算,保留两位小数
'yjse' => '',// 已缴税额,可手工填写,不填则默认系统自动计算,保留两位小数
'ydzse1' => '',// 已代征税额,可手工填写,不填则默认系统自动计算,保留两位小数
'jmse' => '',// 减免税额,可手工填写,不填则默认系统自动计算,保留两位小数
'phjmse' => '',// 增值税小规模纳税人减征额
'phjzbl' => '',// 增值税小规模纳税人减征比例
'phjmxzDm' => '',// 增值税小规模纳税人减免性质代码
'ssjmxzDm' => '',// 税收减免性质代码
'wszmkjbz' => 'Y',// 完税证明开具标志为 Y 开具,N不开具
'xmmc' => $this->puCodeUser['project_name'],// 项目名称
'xmbm' => substr(time(),1, 9),// 项目编码
'username' => $userName,// 用户名称(同一个批次,同一个用户编号下,值相同)
'nbyhbm' => $this->puCodeUser['UserCode'],// 用户编号
'jldwmc' => '立方米',// 单位
'sl' => $this->puCodeUser['WaterQty'] ?? '',// 数量
'zxbz1' => $zxbz1,// 标准
'skyhmc' => !empty($this->puCodeUser['BankName']) ? $this->puCodeUser['BankName'] : '',// 托收银行(同一个批次,同一个用户编号下,值相同)
'yhzh' => !empty($this->puCodeUser['BankAccountCode']) ? $this->puCodeUser['BankAccountCode'] : '',// 银行账号(同一个批次,同一个用户编号下,值相同)
'zsfsmc' => $this->puCodeUser['zsfsmc'],// 缴费方式(同一个批次,同一个用户编号下,值相同)
'tjsd' => $this->puCodeUser['ThisLastReadingTime'],// 收费时段(同一个批次,同一个用户编号下,值相同)
'jfyj1' => $this->puCodeUser['jsyj'],// 计费依据(同一个批次,同一个用户编号下,值相同)
'yhje' => '0.00',// 优惠金额
'hjje' => $this->puCodeUser['jsyj'],// 合计金额
'jfrq' => $this->puCodeUser['jfrq'],// 缴费时间(同一个批次,同一个用户编号下,值相同)
'lxfs' => !empty($this->puCodeUser['CellPhone']) ? $this->puCodeUser['CellPhone'] : '',// 联系方式(同一个批次,同一个用户编号下,值相同)
'lxdz' => !empty($this->puCodeUser['WaterUseAddress']) ? $this->puCodeUser['WaterUseAddress'] : '',// 送票地址(同一个批次,同一个用户编号下,值相同)
'remark' => '无',// 备注(同一个批次,同一个用户编号下,值相同)
'bz' => '',// 备注信息(同一个批次,同一个用户编号下,值相同)
];
$body = [
'sbczlxDm' => 'insert', //申报操作类型代码,为”delete”,” insert” 或”update”
@ -222,9 +174,12 @@ class ChinaTaxes
$param = $this->getParamData('SSGZ_GZPT_SZQKL_WTDZDRJK', $body);
$res = $this->resultXml($param, 0);
/*if (!isset($res['sbpch'])) {
if (isset($res['code']) && $res['code'] == '123456') {
return $res;
}
if (!isset($res['sbpch'])) {
throw new FuncException('未获取到批次号');
}*/
}
return $res;
}
@ -263,18 +218,15 @@ class ChinaTaxes
$body = [
'sbpch' => $sbpch, // 批次号,详见备注
'bdzmxGrid' => [
'bdzmxlb' => []
'bdzmxlb' => [
'bdznsrsbh' => $bdznsrsbh, // 被代征人纳税人识别号
'yhbm' => $this->puCodeUser['UserCode'], // 用户编码
]
],
'skssqq' => $this->invoiceIssuance['skssqq'], // 税款所属期起,格式,年-月-日
'skssqz' => $this->invoiceIssuance['skssqz'], // 税款所属期止,格式,年-月-日
'my' => $this->my // 密钥,数字签名校验和资格校验
];
foreach ($this->puCodeUser as $value) {
$body['bdzmxGrid']['bdzmxlb'][] = [
'bdznsrsbh' => $bdznsrsbh, // 被代征人纳税人识别号
'yhbm' => $value['UserCode'] // 用户编码
];
}
$param = $this->getParamData('SSGZ_GZPT_PZ_SQKJDZJKPZ', $body);
@ -318,10 +270,8 @@ class ChinaTaxes
];
$param = $this->getParamData('SSGZ_GZPT_SZQKL_DW_DZSCMXYC_QUERY', $body);
$this->xmlKey = '03';
return $this->resultXml($param, 3);
return $this->resultXml($param, 0);
}
/**
@ -334,14 +284,14 @@ class ChinaTaxes
{
$body = [
'bdzmxList' => [
'bdzmxVO' => ['bdznsrsbh' => $bdznsrsbh] // 被代征人纳税人识别号
'bdznsrsbh' => $bdznsrsbh // 被代征人纳税人识别号
],
'skssqq' => $this->invoiceIssuance['skssqq'], // 税款所属期起,格式,年-月-日
'skssqz' => $this->invoiceIssuance['skssqz'], // 税款所属期止,格式,年-月-日
'my' => $this->my // 密钥,数字签名校验和资格校验
];
$param = $this->getParamData('SSGZ_GZPT_PZ_QUERYDKDZJKPZ', $body);
$param = $this->getParamData('SSGZ_GZPT_PZ_QUERYDKDZJKP', $body);
return $this->resultXml($param);
}
@ -358,10 +308,10 @@ class ChinaTaxes
'sfxxList' => [
'nsrlx' => '1' // 2 非自然人、1 自然人
],
'yhbh' => $this->puCodeUser[0]['UserCode'], // 水司的用户编号
'yhbh' => $this->puCodeUser['UserCode'], // 水司的用户编号
'nsrsbh' => $nsrsbh, // 传输类型为非自然人不可以为空
'nsrmc' => $this->puCodeUser[0]['ContactName'], // 不可为空
'zjhm' => $this->puCodeUser[0]['CertificateCode'], // 传输类型为自然人,不可以为空
'nsrmc' => $this->puCodeUser['ContactName'], // 不可为空
'zjhm' => $this->puCodeUser['CertificateCode'], // 传输类型为自然人,不可以为空
'zjlx' => '201', // 传输类型为自然人,不可以为空,添加证件类型代码 999
'gj' => '156', // 国籍
];
@ -387,17 +337,17 @@ class ChinaTaxes
'gzxxList' => [
'gzxxVO' => [
'nsrlx' => 1, // 2 非自然人、1 自然人
'yhbh' => $this->puCodeUser[0]['UserCode'], // 水司的用户编号
'yhbh' => $this->puCodeUser['UserCode'], // 水司的用户编号
'nsrsbh' => $nsrsbh, // 传输类型为单位不可以为空
'nsrmc' => $this->puCodeUser[0]['ContactName'], // 不可为空 ?
'zjhm' => $this->puCodeUser[0]['CertificateCode'], // 传输类型为自然人,不可以为空
'nsrmc' => $this->puCodeUser['ContactName'], // 不可为空 ?
'zjhm' => $this->puCodeUser['CertificateCode'], // 传输类型为自然人,不可以为空
'zjlx' => '201', // 传输类型为自然人,不可以为空,添加证件类型代码 999
'gj' => '156', // 国籍
'username' => $this->puCodeUser[0]['UserName'], // 用户名称
'skyhmc' => $this->puCodeUser[0]['BankName'], // 托收银行
'yhzh' => $this->puCodeUser[0]['BankAccountCode'], // 银行账号
'lxdz' => $this->puCodeUser[0]['MaillingAddress'], // 用户地址
'lxfs' => $this->puCodeUser[0]['Telephone'], // 联系方式
'username' => $this->puCodeUser['UserName'], // 用户名称
'skyhmc' => $this->puCodeUser['BankName'], // 托收银行
'yhzh' => $this->puCodeUser['BankAccountCode'], // 银行账号
'lxdz' => $this->puCodeUser['MaillingAddress'], // 用户地址
'lxfs' => $this->puCodeUser['Telephone'], // 联系方式
'sbpch' => $sbpch, // 申报批次号
],
],
@ -587,22 +537,17 @@ xmlns:ns2="http://www.chinatax.gov.cn/dataspec/">';
* 循环处理bizXml数据
* @param $body
* @param int $type
* @param string $lastKey
* @return string
*/
protected function bizXmlStr($body, int $type = 1, string $lastKey = ''): string
protected function bizXmlStr($body, int $type = 1): string
{
$xml = '';
foreach ($body as $key => $value) {
if (is_numeric($key) && !empty($lastKey)) {
$xml .= $this->bizXmlStr($value, $type, $lastKey);
continue;
}
if (is_array($value)) {
if ($type == 2) {
$xml .= "<ns2:{$key}>" . $this->bizXmlStr($value, $type, $key) . "</ns2:{$key}>";
$xml .= "<ns2:{$key}>" . $this->bizXmlStr($value, $type) . "</ns2:{$key}>";
} else {
$xml .= "<$key>" . $this->bizXmlStr($value, $type, $key) . "</$key>";
$xml .= "<$key>" . $this->bizXmlStr($value, $type) . "</$key>";
}
} else {
if ($type == 2) {
@ -622,17 +567,13 @@ xmlns:ns2="http://www.chinatax.gov.cn/dataspec/">';
*/
protected function mxGrid($mxGrid): string
{
$xmlStr = '';
foreach ($mxGrid as $data) {
$xmlStr .= '<ns2:sbMxsjVOList>';
foreach ($data as $key => $value) {
$xmlStr = '<ns2:sbMxsjVOList>';
$xmlStr .= "<ns2:{$key}>" . $value . "</ns2:{$key}>";
}
$xmlStr .= '</ns2:sbMxsjVOList>';
foreach ($mxGrid as $key => $value) {
$xmlStr .= "<ns2:{$key}>" . $value . "</ns2:{$key}>";
}
return $xmlStr;
return $xmlStr . '</ns2:sbMxsjVOList>';
}
/**
@ -666,7 +607,7 @@ xmlns:ns2="http://www.chinatax.gov.cn/dataspec/">';
// 检查是否有错误发生
if (curl_errno($ch)) {
throw new FuncException('请求失败');
throw new FuncException('请求失败');
}
// 关闭cURL会话
@ -681,7 +622,7 @@ xmlns:ns2="http://www.chinatax.gov.cn/dataspec/">';
*/
protected function getReqId(): string
{
return md5(time() . rand(0, 9));
return md5(time() . rand(0000, 9999));
}
/**
@ -767,18 +708,13 @@ xmlns:ns2="http://www.chinatax.gov.cn/dataspec/">';
if (isset($result['error']['message'])) {
throw new FuncException($result['error']['message']);
}
throw new FuncException('请求失败');
throw new FuncException('请求失败!!');
}
$data = $this->xmlDom($result['result']);
if (isset($data['code']) && $data['code'] != 200) {
if ($data['code'] == 302) {
if ($type == 1) {
return $data;
}
} else {
throw new FuncException($data['message']);
}
if ($type == 3 && $data['code'] == 302) return $data;
throw new FuncException($data['message']);
} else if ($type == 1) {
if (isset($data[$key])) {
$data['zipBaseData'] = $this->deCompressXml($data[$key]);
@ -791,10 +727,11 @@ xmlns:ns2="http://www.chinatax.gov.cn/dataspec/">';
if ($deData) {
$xmlData = $this->xmlDom($deData);
if (isset($xmlData['ns2:message']) && $xmlData['ns2:message'] == '已结报的属期,不允许导入') {
return ['code' => '123456'];
}
if (isset($xmlData['ns2:code']) && $xmlData['ns2:code'] != 200) {
if ($xmlData['ns2:message'] != '已结报的属期,不允许导入') {
throw new FuncException($xmlData['ns2:message']);
}
throw new FuncException($xmlData['ns2:message']);
}
$returnData = $this->delNs2Filed($xmlData);

2
app/validate/InvoiceIssuanceValidate.php

@ -43,7 +43,7 @@ class InvoiceIssuanceValidate extends Validate
'add' => ['project_id', 'merge', 'pucode', 'expire_time', 'mobile', 'email', 'amount'],
'edit' => ['project_id', 'merge', 'pucode', 'expire_time', 'mobile', 'email', 'amount', 'id'],
'delete' => ['id'],
'feePay' => ['pucode', 'expire_time', 'project_id', 'merge']
'feePay' => ['pucode', 'expire_time', 'project_id']
];
}
Loading…
Cancel
Save