diff --git a/app/controller/admin/WechatUser.php b/app/controller/admin/WechatUser.php index 07ec422..e803410 100644 --- a/app/controller/admin/WechatUser.php +++ b/app/controller/admin/WechatUser.php @@ -3,6 +3,8 @@ namespace app\controller\admin; use app\model\WechatUser as WechatUserModel; +use app\service\ExportService; +use app\service\user\UserService; use think\Response; class WechatUser extends Base @@ -41,4 +43,126 @@ class WechatUser extends Base 'count' => $listObj['total'] ]); } + + /** + * 下载导入模板 + * @return void + * @throws \PHPExcel_Exception + * @throws \PHPExcel_Reader_Exception + * @throws \PHPExcel_Writer_Exception + */ + public function exportTemplate() + { + $name = '导入用户信息模板'; + $header = ['手机号', '邮箱编号', '用户编号', '纳税人识别号', '抬头类型(单位、个人)']; + ExportService::excelExport($name, $header); + } + + /** + * 导入用户 + * @return Response + */ + public function importUser():Response + { + try { + $file = $this->request->file('file'); + if (empty($file)) { + throw new \Exception('没有上传的文件'); + } + + $max_size = '10'; + $mimetype = 'xls,xlsx'; + $fileInfo = []; + $fileInfo['name'] = $file->getOriginalName(); //上传文件名 + $fileInfo['type'] = $file->getOriginalMime(); //上传文件类型信息 + $fileInfo['tmp_name'] = $file->getPathname(); + $fileInfo['size'] = $file->getSize(); + + if ($fileInfo['size'] > $max_size) { + throw new \Exception('文件超过配置的最大值' . $max_size . 'M'); + } + + + $suffix = strtolower( + pathinfo($fileInfo['name'], PATHINFO_EXTENSION) + ); + $suffix = $suffix && preg_match('/^[a-zA-Z0-9]+$/', $suffix) + ? $suffix : 'file'; + $mimetypeArr = explode(',', strtolower($mimetype)); + $typeArr = explode('/', $fileInfo['type']); + + + //禁止上传PHP和HTML文件 + if ( + in_array($fileInfo['type'], ['text/x-php', 'text/html']) + || in_array($suffix, ['php', 'html', 'htm']) + ) { + throw new \Exception('该文件类型不可上传'); + } + //验证文件后缀 + if ((!in_array($suffix, $mimetypeArr) + || (stripos($typeArr[0] . '/', $mimetype) !== false + && !in_array($fileInfo['type'], $mimetypeArr) + && !in_array($typeArr[0] . '/*', $mimetypeArr) + )) + ) { + throw new \Exception('该文件类型不可上传'); + } + + switch($suffix){ + case 'xls': + $obj = \PHPExcel_IOFactory::createReader('Excel5'); + break; + case 'xlsx': + $obj = \PHPExcel_IOFactory::createReader('Excel2007'); + break; + default: + throw new \Exception('该文件类型不可上传'); + } + + $obj_PHPExcel = $obj->load($fileInfo['tmp_name']); + $excel_array = $obj_PHPExcel->getSheet(0)->toArray(); + array_shift($excel_array); + + foreach ($excel_array as $data) { + // 验证不能为空 + $is_empty = false; + foreach ($data as $value) { + if (empty($value)) { + $is_empty = true; + break; + } + } + if ($is_empty) { + continue; + } + $phone = $data[0]; + $email = $data[1]; + $pucode = $data[2]; + $taxId = $data[3]; + $type = $data[4]; + if (!preg_match('/^1[3-9]\d{9}$/', $phone)) { + continue; + } + if (filter_var($email, FILTER_VALIDATE_EMAIL) === false) { + continue; + } + $str = '0-9A-HJ-NPQRTUWXY'; + $pattern = '/^[' . $str . ']{2}\d{6}[' . $str . ']{10}$/'; + if (!preg_match($pattern, $taxId)) { + continue; + } + $typeArr = ['单位', '个人']; + if (!in_array($type, $typeArr)) { + continue; + } + $type = array_search($type, $typeArr); + UserService::addUser($phone, $email, $pucode, $taxId, $type); + } + + return $this->buildSuccess(); + } catch (\Exception $e) { + return $this->buildFailed(400, $e->getMessage()); + } + } } \ No newline at end of file diff --git a/app/controller/api/InvoiceIssuance.php b/app/controller/api/InvoiceIssuance.php index e2bbd11..f79d201 100644 --- a/app/controller/api/InvoiceIssuance.php +++ b/app/controller/api/InvoiceIssuance.php @@ -78,7 +78,13 @@ class InvoiceIssuance extends Base validate(InvoiceIssuanceValidate::class)->scene('feePay')->check($param); - $res = InvoiceIssuanceService::validateFeePay($param['pucode'],$param['expire_time'],$param['project_id']); + $res = InvoiceIssuanceService::validateFeePay( + $param['pucode'], + $param['expire_time'], + $param['project_id'], + $param['merge'], + $param['tax_number'] + ); return $this->buildSuccess($res); } catch (\Exception $e) { diff --git a/app/service/ExportService.php b/app/service/ExportService.php new file mode 100644 index 0000000..b10280c --- /dev/null +++ b/app/service/ExportService.php @@ -0,0 +1,77 @@ +getProperties(); + + $key = ord("A"); // 设置表头 + + foreach ($headArr as $v) { + + $colum = chr($key); + + $objPHPExcel->setActiveSheetIndex(0)->setCellValue($colum . '1', $v); + + $objPHPExcel->setActiveSheetIndex(0)->setCellValue($colum . '1', $v); + + $key += 1; + + } + + $column = 2; + + $objActSheet = $objPHPExcel->getActiveSheet(); + + foreach ($data as $key => $rows) { // 行写入 + + $span = ord("A"); + + foreach ($rows as $keyName => $value) { // 列写入 + + $objActSheet->setCellValue(chr($span) . $column, $value); + + $span++; + + } + + $column++; + + } + + $fileName = iconv("utf-8", "gb2312", $fileName); // 重命名表 + + $objPHPExcel->setActiveSheetIndex(0); // 设置活动单指数到第一个表,所以Excel打开这是第一个表 + + header('Content-Type: application/vnd.ms-excel'); + + header("Content-Disposition: attachment;filename=$fileName"); + + header('Cache-Control: max-age=0'); + + $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5'); + + $objWriter->save('php://output'); // 文件通过浏览器下载 + + exit(); + } + +} \ No newline at end of file diff --git a/app/service/invoice/InvoiceIssuanceService.php b/app/service/invoice/InvoiceIssuanceService.php index 74e0feb..cd3f03b 100644 --- a/app/service/invoice/InvoiceIssuanceService.php +++ b/app/service/invoice/InvoiceIssuanceService.php @@ -7,6 +7,7 @@ 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; @@ -82,10 +83,12 @@ class InvoiceIssuanceService * @param $pucode * @param $expire_time * @param $project_id + * @param string $merge 是否合并 + * @param string $tax_number * @return string[] * @throws FuncException */ - public static function validateFeePay($pucode, $expire_time, $project_id): array + public static function validateFeePay($pucode, $expire_time, $project_id, string $merge = '', string $tax_number = ''): array { $expire_date = date('Ym', strtotime($expire_time)); @@ -94,13 +97,36 @@ class InvoiceIssuanceService switch ($project_id) { case 1: case 2: + // 合并逻辑 + if ($merge == '1') { + if (empty($tax_number)) { + throw new FuncException('请填写纳税人编号'); + } - $ComputeDetail = self::getFeeComputeDetail($pucode, $expire_date); - if ($ComputeDetail['MsgID'] != 1) { - throw new FuncException($errorMsg); - } + $pucodeArr = UserService::getTaxUser($tax_number); + $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']]; + return ['amount' => $ComputeDetail['WaterAmount']]; + } default: throw new FuncException('尚未开发,请耐心等待!'); } @@ -217,34 +243,47 @@ class InvoiceIssuanceService $invoiceDate = $this->getInvoiceDate($invoiceIssuance['expire_time']); - $feeUsers = $this->getFeeUserData($pucode); - $bdznsrsbh = $this->getTaxNumber($invoiceIssuance['invoice_head_id']); // 被代征纳税人识别号 - $feeUsers['bdznsrsbh'] = $bdznsrsbh; + $puCodeUserData = []; + $pucodeArr = [$pucode]; + + if ($invoiceIssuance['merge'] == 1) { + $pucodeArr = UserService::getTaxUser($bdznsrsbh); + } + + // 多组用户编号 + 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); + } - // 获取用户应收费信息 - $FeeComputeDetail = self::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']; + $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($feeUsers, $invoiceDate); + $ChinaTaxes = new ChinaTaxes($puCodeUserData, $invoiceDate); $savingDetailedData = $ChinaTaxes->savingDetailedData(); if (!isset($savingDetailedData['sbpch'])) { $VoucherData = $ChinaTaxes->queryIssuedPaymentVoucher($bdznsrsbh); diff --git a/app/service/user/UserService.php b/app/service/user/UserService.php index 28cb378..34eec92 100644 --- a/app/service/user/UserService.php +++ b/app/service/user/UserService.php @@ -2,6 +2,8 @@ namespace app\service\user; +use app\model\InvoiceHead; +use app\model\WechatPucode; use app\model\WechatUser; use app\service\BaseService; @@ -50,4 +52,66 @@ class UserService extends BaseService $User = new WechatUser(); return $User->where('id', $id)->save($data); } + + public static function addUser( + int $phone, + string $email, + string $pucode, + string $tax_number, + int $type + ) + { + $query = WechatUser::where('phone', $phone)->find(); + if (!$query) { + + $save = [ + 'nick_name' => '导入用户', + 'phone' => $phone, + 'email' => $email + ]; + $id = (new WechatUser())->insertGetId($save); + + if ($id) { + + $codeSave = [ + 'wechat_user_id' => $id, + 'pucode' => $pucode, + 'create_time' => time() + ]; + (new WechatPucode())->save($codeSave); + + if ($codeSave) { + $headSave = [ + 'tax_number' => $tax_number, + ]; + $headQuery = InvoiceHead::where($headSave)->find(); + if (!$headQuery) { + $headSave['type'] = $type; + $headSave['phone'] = $phone; + $headSave['wechat_user_id'] = $id; + $headSave['create_time'] = time(); + (new InvoiceHead())->save($headSave); + } + } + } + + return 1; + } + return 0; + } + + public static function getTaxUser($tax_id) + { + $where = [ + 'tax_number' => $tax_id + ]; + $user_ids = InvoiceHead::where($where)->column('wechat_user_id'); + + if ($user_ids) { + + return WechatPucode::whereIn('wechat_user_id', $user_ids)->column('pucode'); + } + } + + } diff --git a/app/service/webService/ChinaTaxes.php b/app/service/webService/ChinaTaxes.php index 578585c..b8a5257 100644 --- a/app/service/webService/ChinaTaxes.php +++ b/app/service/webService/ChinaTaxes.php @@ -109,50 +109,101 @@ class ChinaTaxes */ public function savingDetailedData(): array { - $userName = !empty($this->puCodeUser['ContactName']) ? $this->puCodeUser['ContactName'] : $this->puCodeUser['UserName']; - $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' => '',// 备注信息(同一个批次,同一个用户编号下,值相同) - ]; + $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' => '', + // 备注信息(同一个批次,同一个用户编号下,值相同) + ]; + } $body = [ 'sbczlxDm' => 'insert', //申报操作类型代码,为”delete”,” insert” 或”update” @@ -212,15 +263,18 @@ class ChinaTaxes $body = [ 'sbpch' => $sbpch, // 批次号,详见备注 'bdzmxGrid' => [ - 'bdzmxlb' => [ - 'bdznsrsbh' => $bdznsrsbh, // 被代征人纳税人识别号 - 'yhbm' => $this->puCodeUser['UserCode'], // 用户编码 - ] + 'bdzmxlb' => [] ], '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); @@ -302,10 +356,10 @@ class ChinaTaxes 'sfxxList' => [ 'nsrlx' => '1' // 2 非自然人、1 自然人 ], - 'yhbh' => $this->puCodeUser['UserCode'], // 水司的用户编号 + 'yhbh' => $this->puCodeUser[0]['UserCode'], // 水司的用户编号 'nsrsbh' => $nsrsbh, // 传输类型为非自然人不可以为空 - 'nsrmc' => $this->puCodeUser['ContactName'], // 不可为空 - 'zjhm' => $this->puCodeUser['CertificateCode'], // 传输类型为自然人,不可以为空 + 'nsrmc' => $this->puCodeUser[0]['ContactName'], // 不可为空 + 'zjhm' => $this->puCodeUser[0]['CertificateCode'], // 传输类型为自然人,不可以为空 'zjlx' => '201', // 传输类型为自然人,不可以为空,添加证件类型代码 999 'gj' => '156', // 国籍 ]; @@ -331,17 +385,17 @@ class ChinaTaxes 'gzxxList' => [ 'gzxxVO' => [ 'nsrlx' => 1, // 2 非自然人、1 自然人 - 'yhbh' => $this->puCodeUser['UserCode'], // 水司的用户编号 + 'yhbh' => $this->puCodeUser[0]['UserCode'], // 水司的用户编号 'nsrsbh' => $nsrsbh, // 传输类型为单位不可以为空 - 'nsrmc' => $this->puCodeUser['ContactName'], // 不可为空 ? - 'zjhm' => $this->puCodeUser['CertificateCode'], // 传输类型为自然人,不可以为空 + 'nsrmc' => $this->puCodeUser[0]['ContactName'], // 不可为空 ? + 'zjhm' => $this->puCodeUser[0]['CertificateCode'], // 传输类型为自然人,不可以为空 'zjlx' => '201', // 传输类型为自然人,不可以为空,添加证件类型代码 999 'gj' => '156', // 国籍 - 'username' => $this->puCodeUser['UserName'], // 用户名称 - 'skyhmc' => $this->puCodeUser['BankName'], // 托收银行 - 'yhzh' => $this->puCodeUser['BankAccountCode'], // 银行账号 - 'lxdz' => $this->puCodeUser['MaillingAddress'], // 用户地址 - 'lxfs' => $this->puCodeUser['Telephone'], // 联系方式 + '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'], // 联系方式 'sbpch' => $sbpch, // 申报批次号 ], ], @@ -531,17 +585,22 @@ 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 + protected function bizXmlStr($body, int $type = 1, string $lastKey = ''): 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 .= "" . $this->bizXmlStr($value, $type) . ""; + $xml .= "" . $this->bizXmlStr($value, $type, $key) . ""; } else { - $xml .= "<$key>" . $this->bizXmlStr($value, $type) . ""; + $xml .= "<$key>" . $this->bizXmlStr($value, $type, $key) . ""; } } else { if ($type == 2) { @@ -561,13 +620,17 @@ xmlns:ns2="http://www.chinatax.gov.cn/dataspec/">'; */ protected function mxGrid($mxGrid): string { - $xmlStr = ''; + $xmlStr = ''; + foreach ($mxGrid as $data) { + $xmlStr .= ''; + foreach ($data as $key => $value) { - foreach ($mxGrid as $key => $value) { - $xmlStr .= "" . $value . ""; + $xmlStr .= "" . $value . ""; + } + $xmlStr .= ''; } - return $xmlStr . ''; + return $xmlStr; } /** diff --git a/app/validate/InvoiceIssuanceValidate.php b/app/validate/InvoiceIssuanceValidate.php index 2c5510c..ef24ea2 100644 --- a/app/validate/InvoiceIssuanceValidate.php +++ b/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'] + 'feePay' => ['pucode', 'expire_time', 'project_id', 'merge'] ]; } \ No newline at end of file diff --git a/composer.json b/composer.json index b1f97b1..2e020e2 100644 --- a/composer.json +++ b/composer.json @@ -24,7 +24,8 @@ "firebase/php-jwt": "^6.4", "ext-dom": "*", "endroid/qr-code": "^4.3", - "phpmailer/phpmailer": "^6.9" + "phpmailer/phpmailer": "^6.9", + "phpoffice/phpexcel": "^1.8" }, "require-dev": { "symfony/var-dumper": "^4.2",