Browse Source

同步线上版本

master
wanghongjun 7 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(); $param = $this->request->post();
validate(InvoiceIssuanceValidate::class)->scene('feePay')->check($param); 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( $res = InvoiceIssuanceService::validateFeePay($param['pucode'],$param['expire_time'],$param['project_id']);
$param['pucode'],
$param['expire_time'],
$param['project_id'],
$param['merge'],
$tax_number,
$wechat_user_id
);
return $this->buildSuccess($res); return $this->buildSuccess($res);
} catch (\Exception $e) { } catch (\Exception $e) {
@ -122,7 +106,7 @@ class InvoiceIssuance extends Base
$field = 'title,tax_number'; $field = 'title,tax_number';
if (!$param['type']) { if (!$param['type']) {
$field .= ',address,telephone,bank_name,bank_account'; $field .= ',address,telephone,bank_name,bank_account';
} }
$InvoiceHead = new InvoiceHead; $InvoiceHead = new InvoiceHead;
@ -212,7 +196,7 @@ class InvoiceIssuance extends Base
'expire_time' => strtotime($params['expire_time']), 'expire_time' => strtotime($params['expire_time']),
]; ];
$where = [['status', '<>', 3], ['delete_time', '=', 0]]; $where = [['status', 'in', [0,1,3]], ['delete_time', '=', 0]];
if ($id) { if ($id) {
$where[] = ['id', '!=', $id]; $where[] = ['id', '!=', $id];
} }

6
app/controller/task/InvoiceIssuanceTask.php

@ -11,7 +11,7 @@ use think\Response;
class InvoiceIssuanceTask extends Base 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(); $InvoiceIssuanceData = (new InvoiceIssuanceModel())->where($where)->page(1, $this->limit)->select()->toArray();
foreach ($InvoiceIssuanceData as $InvoiceIssuanceValue) { foreach ($InvoiceIssuanceData as $InvoiceIssuanceValue) {
$InvoiceIssuanceValue['project_name'] = InvoiceIssuanceModel::$projectArr[$InvoiceIssuanceValue['project_id']] ?? ''; $InvoiceIssuanceValue['project_name'] = InvoiceIssuanceModel::$projectArr[$InvoiceIssuanceValue['project_id']] ?? '';
$result = (new InvoiceIssuanceService())->tempIssueAnInvoice($InvoiceIssuanceValue); $result = (new InvoiceIssuanceService())->IssueAnInvoice($InvoiceIssuanceValue);
if ($result === true) { if ($result === true) {
$this->invoiceSuccess($InvoiceIssuanceValue); $this->invoiceSuccess($InvoiceIssuanceValue);
} }
@ -63,7 +63,7 @@ class InvoiceIssuanceTask extends Base
*/ */
public function runSummaryReport(): Response public function runSummaryReport(): Response
{ {
$result = (new InvoiceIssuanceService())->tempSaveSummaryReport(); $result = (new InvoiceIssuanceService())->saveSummaryReport();
if ($result !== true) { if ($result !== true) {
return $this->buildFailed('0', $result); 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\InvoiceHead;
use app\model\InvoiceIssuance; use app\model\InvoiceIssuance;
use app\model\InvoiceIssuanceData; use app\model\InvoiceIssuanceData;
use app\service\user\UserService;
use app\service\webService\ChinaTaxes; use app\service\webService\ChinaTaxes;
use app\service\webService\FeeService; use app\service\webService\FeeService;
use fast\FuncException; use fast\FuncException;
@ -50,22 +49,22 @@ class InvoiceIssuanceService
$model = (new InvoiceIssuance()); $model = (new InvoiceIssuance());
$data = $model->where($where) $data = $model->where($where)
->field('id,project_id,invoice_head_id,amount,create_time,status,serial_number,expire_time') ->field('id,project_id,invoice_head_id,amount,create_time,status,serial_number,expire_time')
->order('create_time desc') ->order('create_time desc')
->paginate($limit, false) ->paginate($limit, false)
->each(function ($item, $key) { ->each(function ($item, $key) {
$InvoiceHead = (new InvoiceHead)->find($item->invoice_head_id); $InvoiceHead = (new InvoiceHead)->find($item->invoice_head_id);
$item->serial_number = !empty($item->serial_number) ? $item->serial_number : $this->getSerialNumber(); $item->serial_number = !empty($item->serial_number) ? $item->serial_number : $this->getSerialNumber();
$item->head_type = ''; $item->head_type = '';
$item->head_title = ''; $item->head_title = '';
if ($InvoiceHead) { if ($InvoiceHead) {
$item->head_type = InvoiceHead::$typeArr[$InvoiceHead['type']]; $item->head_type = InvoiceHead::$typeArr[$InvoiceHead['type']];
$item->head_title = $InvoiceHead['title']; $item->head_title = $InvoiceHead['title'];
} }
$item->project_id = InvoiceIssuance::$projectArr[$item->project_id] ?? ''; $item->project_id = InvoiceIssuance::$projectArr[$item->project_id] ?? '';
$item->status_str = InvoiceIssuance::$statusArr[$item->status]; $item->status_str = InvoiceIssuance::$statusArr[$item->status];
$item->expire_time = date("Y-m", $item->expire_time); $item->expire_time = date("Y-m", $item->expire_time);
}); });
return $data->toArray(); return $data->toArray();
} }
@ -83,13 +82,10 @@ class InvoiceIssuanceService
* @param $pucode * @param $pucode
* @param $expire_time * @param $expire_time
* @param $project_id * @param $project_id
* @param string $merge 是否合并
* @param string $tax_number
* @param int $wechat_user_id
* @return string[] * @return string[]
* @throws FuncException * @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)); $expire_date = date('Ym', strtotime($expire_time));
@ -98,39 +94,13 @@ class InvoiceIssuanceService
switch ($project_id) { switch ($project_id) {
case 1: case 1:
case 2: 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: default:
throw new FuncException('尚未开发,请耐心等待!'); throw new FuncException('尚未开发,请耐心等待!');
} }
@ -158,10 +128,10 @@ class InvoiceIssuanceService
unset($param['PaymentStatus']); unset($param['PaymentStatus']);
$data2 = $FeeService->getReadingDetail($param); $data2 = $FeeService->getReadingDetail($param);
$data['ThisLastReadingTime'] = ''; $data['ThisLastReadingTime'] = '';
if ($data2['MsgID'] != 1) { if ($data2['MsgID'] == 1) {
$ThisReadingTime = $data2['ThisReadingTime'] ? self::optionReadingTime($data2['ThisReadingTime']) : ''; $ThisReadingTime = $data2['ThisReadingTime'] ? self::optionReadingTime($data2['ThisReadingTime']) : '';
$LastReadingTime = $data2['LastReadingTime'] ? self::optionReadingTime($data2['LastReadingTime']) : ''; $LastReadingTime = $data2['LastReadingTime'] ? self::optionReadingTime($data2['LastReadingTime']) : '';
$data['ThisLastReadingTime'] = $ThisReadingTime . ' 至 ' . $LastReadingTime; $data['ThisLastReadingTime'] = $LastReadingTime . ' 至 ' . $ThisReadingTime;
} }
return $data; return $data;
@ -184,7 +154,7 @@ class InvoiceIssuanceService
* @param $expire_time * @param $expire_time
* @return array * @return array
*/ */
public function getInvoiceDate($expire_time): array private function getInvoiceDate($expire_time): array
{ {
$expire_time = strtotime(date("Y-m",$expire_time)); $expire_time = strtotime(date("Y-m",$expire_time));
return [ return [
@ -247,90 +217,61 @@ class InvoiceIssuanceService
$invoiceDate = $this->getInvoiceDate($invoiceIssuance['expire_time']); $invoiceDate = $this->getInvoiceDate($invoiceIssuance['expire_time']);
$feeUsers = $this->getFeeUserData($pucode);
$bdznsrsbh = $this->getTaxNumber($invoiceIssuance['invoice_head_id']); // 被代征纳税人识别号 $bdznsrsbh = $this->getTaxNumber($invoiceIssuance['invoice_head_id']); // 被代征纳税人识别号
$puCodeUserData = []; $feeUsers['bdznsrsbh'] = $bdznsrsbh;
$pucodeArr = [$pucode];
if ($invoiceIssuance['merge'] != 1) { // 获取用户应收费信息
$pucodeArr = UserService::getTaxUser($bdznsrsbh, $invoiceIssuance['wechat_user_id']); $FeeComputeDetail = self::getFeeComputeDetail($pucode, date("Ym", $invoiceIssuance['expire_time']));
$pucodeArr[] = $pucode; if ($FeeComputeDetail['MsgID'] != 1) {
$pucodeArr = array_unique($pucodeArr); throw new FuncException($FeeComputeDetail);
} }
// 多组用户编号 $feeUsers['jsyj'] = $FeeComputeDetail['WaterAmount'];
foreach ($pucodeArr as $valPucode) { $feeUsers['zsfsmc'] = $FeeComputeDetail['chargetype'];
$feeUsers['jfrq'] = $FeeComputeDetail['WaterPayDate'];
$feeUsers = $this->getFeeUserData($valPucode); $feeUsers['project_name'] = $invoiceIssuance['project_name'] ?? '';
$feeUsers['bdznsrsbh'] = $bdznsrsbh; $feeUsers['serial_number'] = $invoiceIssuance['serial_number'];
$feeUsers['WaterUsage'] = $FeeComputeDetail['WaterUsage'];
// 获取用户应收费信息 $feeUsers['WaterItem'] = $FeeComputeDetail['WaterItem'];
$FeeComputeDetail = self::getFeeComputeDetail($valPucode, date("Ym", $invoiceIssuance['expire_time'])); $feeUsers['WaterQty'] = $FeeComputeDetail['WaterQty'];
if ($FeeComputeDetail['MsgID'] != 1) { $feeUsers['WaterPrice'] = $FeeComputeDetail['WaterPrice'];
throw new FuncException($FeeComputeDetail); $feeUsers['ThisLastReadingTime'] = $FeeComputeDetail['ThisLastReadingTime'];
}
$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;
}
// 保存 // 保存
$is_continue = false;// 是否跳过加工 $ChinaTaxes = new ChinaTaxes($feeUsers, $invoiceDate);
$jsyj = 0; // 总金额
$ChinaTaxes = new ChinaTaxes($puCodeUserData, $invoiceDate);
$savingDetailedData = $ChinaTaxes->savingDetailedData(); $savingDetailedData = $ChinaTaxes->savingDetailedData();
if (!isset($savingDetailedData['sbpch'])) {
$VoucherData = $ChinaTaxes->queryIssuedPaymentVoucher($bdznsrsbh); // 已结包修改期属
$bdzkjmxList = $VoucherData['bdzkjmxList']; if (isset($savingDetailedData['code']) && $savingDetailedData['code'] == '123456') {
if (empty($bdzkjmxList)) {
throw new \Exception('未查询到待开具电子缴款凭证数据'); $invoiceIssuance['expire_time'] = strtotime(date("Y-m"));
} $invoiceDate = $this->getInvoiceDate($invoiceIssuance['expire_time']);
foreach ($bdzkjmxList as $bdzkjmxValue) { $ChinaTaxes = new ChinaTaxes($feeUsers, $invoiceDate);
foreach($bdzkjmxValue['bdzkjmxVO'] as $bdzkjmxVOValue) { $savingDetailedData = $ChinaTaxes->savingDetailedData();
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); (new InvoiceIssuanceData())->saveField($invoiceIssuance['id'], 'sbpch', $sbpch);
// 委托 - 加工数据 // 委托 - 加工数据
$realTimeProcessing = ['code' => 0]; $realTimeProcessing = $ChinaTaxes->realTimeProcessing($sbpch);
if (!$is_continue) {
$realTimeProcessing = $ChinaTaxes->realTimeProcessing($sbpch);
}
if ($realTimeProcessing['code'] == 200 || $is_continue) { if ($realTimeProcessing['code'] == 200) {
// 处理加工成功返回数据 // 处理加工成功返回数据
if (!$is_continue) { if (!isset($realTimeProcessing['data']['mxGrid'])) {
if (!isset($realTimeProcessing['data']['mxGrid'])) { throw new FuncException('加工数据有误');
throw new FuncException('加工数据有误'); }
} $mxGrid = $realTimeProcessing['data']['mxGrid'];
$mxGrid = $realTimeProcessing['data']['mxGrid'];
if (isset($mxGrid['sbMxsjVOList'])) { $jsyj = 0; // 总金额
foreach ($mxGrid['sbMxsjVOList'] as $sbMxsjVOValue) { if (isset($mxGrid['sbMxsjVOList'])) {
if (isset($sbMxsjVOValue['jsyj'])) $jsyj += $sbMxsjVOValue['jsyj']; foreach ($mxGrid['sbMxsjVOList'] as $sbMxsjVOValue) {
} if (isset($sbMxsjVOValue['jsyj'])) $jsyj += $sbMxsjVOValue['jsyj'];
} }
} }
@ -369,7 +310,8 @@ class InvoiceIssuanceService
// 查询上传异常数据接口 // 查询上传异常数据接口
$queryUploadErrorData = $ChinaTaxes->queryUploadErrorData($sbpch); $queryUploadErrorData = $ChinaTaxes->queryUploadErrorData($sbpch);
if (!isset($queryUploadErrorData['data']['mxGrid']['sbMxsjVOList']['ycms'])) {
if (!isset($queryUploadErrorData['mxGrid']['sbMxsjVOList']['ycms'])) {
throw new FuncException('异常信息返回有误'); throw new FuncException('异常信息返回有误');
} }
// 查询待开具电子缴款 // 查询待开具电子缴款
@ -382,16 +324,20 @@ class InvoiceIssuanceService
// 开票失败 // 开票失败
(new InvoiceIssuance())->where('id', $invoiceIssuance['id'])->save(['status' => 2]); (new InvoiceIssuance())->where('id', $invoiceIssuance['id'])->save(['status' => 2]);
//throw new FuncException('加工失败流程待定!'); //throw new FuncException('加工失败流程待定!');
return false;
} }
return true; return true;
} catch (\Exception $e) { } catch (\Exception $e) {
//dump($e,11);die;
(new InvoiceIssuanceData())->saveField($invoiceIssuance['id'], 'ycms', $e->getMessage()); (new InvoiceIssuanceData())->saveField($invoiceIssuance['id'], 'ycms', $e->getMessage());
// 未获取到批次号报错 if ($e->getMessage() != '接入访问会话已经过期,请重新登录') {
if (empty($sbpch)) { (new InvoiceIssuance())->where('id', $invoiceIssuance['id'])->save(['status' => 0]);
} }
$this->writeLog($e); // 未获取到批次号报错
if (empty($sbpch)) {}
//$this->writeLog($e);
return $e->getMessage(); return $e->getMessage();
} }
} }
@ -418,7 +364,7 @@ class InvoiceIssuanceService
$identityCheck = $ChinaTaxes->identityCheck($bdznsrsbh); $identityCheck = $ChinaTaxes->identityCheck($bdznsrsbh);
if (isset($identityCheck['zt']) && $identityCheck['zt'] == 'N') { 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) 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会话 // 初始化cURL会话
$ch = curl_init(); $ch = curl_init();
@ -601,7 +547,7 @@ class InvoiceIssuanceService
// 检查是否有错误发生 // 检查是否有错误发生
if (curl_errno($ch)) { if (curl_errno($ch)) {
throw new FuncException('请求失败'); throw new FuncException('请求失败!!!');
} }
// 关闭cURL会话 // 关闭cURL会话
@ -631,8 +577,8 @@ class InvoiceIssuanceService
if (!empty($r_data['ycms'])) { if (!empty($r_data['ycms'])) {
(new InvoiceIssuanceData())->saveField($data['id'], 'ycms', $r_data['ycms']); (new InvoiceIssuanceData())->saveField($data['id'], 'ycms', $r_data['ycms']);
if (empty($r_data['sbpch'])) { 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']); throw new \Exception($r_data['ycms']);
} }
} }
@ -676,8 +622,7 @@ class InvoiceIssuanceService
return true; return true;
} catch (\Exception $e) { } catch (\Exception $e) {
(new InvoiceIssuanceData())->saveField($data['id'], 'ycms', $e->getMessage()); //dump($e->getMessage());
//echo $e->getMessage() . '<br>';
return false; return false;
} }
} }

237
app/service/webService/ChinaTaxes.php

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