From 4658c3c7890900838ebb874acc257350e91dd2b8 Mon Sep 17 00:00:00 2001 From: wanghongjun <1445693971@qq.com> Date: Wed, 10 Dec 2025 14:12:37 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AF=BC=E5=85=A5=E7=94=A8=E6=88=B7=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E7=A8=8E=E5=8F=B7=E8=BA=AB=E4=BB=BD=E8=AF=81=E5=8F=B7?= =?UTF-8?q?=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/command/ExportExcel.php | 63 +++++++++++++++++++++++++---- app/controller/admin/WechatUser.php | 24 +++++++---- 2 files changed, 71 insertions(+), 16 deletions(-) diff --git a/app/command/ExportExcel.php b/app/command/ExportExcel.php index 985d49c..e7bbab7 100644 --- a/app/command/ExportExcel.php +++ b/app/command/ExportExcel.php @@ -3,6 +3,9 @@ declare (strict_types = 1); namespace app\command; +use app\model\InvoiceHead; +use app\model\WechatPucode; +use app\service\invoice\InvoiceIssuanceService; use app\service\user\UserService; use app\service\webService\FeeService; use think\console\Command; @@ -27,6 +30,7 @@ class ExportExcel extends Command set_time_limit(0); // 无时间限制 ini_set('memory_limit', '512M'); // 增加内存限制 $this->runData(); + //$this->runHeadData(); // 指令输出 $output->writeln('exportexcel'); } @@ -80,20 +84,28 @@ class ExportExcel extends Command continue; } } - if ($taxId) { -// $str = '0-9A-HJ-NPQRTUWXY'; -// $pattern = '/^[' . $str . ']{2}\d{6}[' . $str . ']{10}$/'; -// if (!preg_match($pattern, $taxId)) { -// $error_array[] = "第{$key}行:纳税人编号格式不符合"; -// continue; -// } - } $typeArr = ['单位', '个人']; if (!in_array($type, $typeArr)) { $error_array[] = "第{$key}行:抬头类型不符合"; continue; } $type = array_search($type, $typeArr); + if ($taxId) { + if ($type === 1) { + $str = '0-9A-HJ-NPQRTUWXY'; + $pattern = '/^[' . $str . ']{2}\d{6}[' . $str . ']{10}$/'; + if (!preg_match($pattern, $taxId)) { + $error_array[] = "第{$key}行:纳税人编号格式不符合"; + continue; + } + } else { + $pattern = '/^\d{15}$|^\d{17}[\dXx]$/'; + if (!preg_match($pattern, $taxId)) { + $error_array[] = "第{$key}行:纳税人编号格式不符合"; + continue; + } + } + } UserService::addUser((int)$phone, $email, $pucode, $taxId, (int)$type); } @@ -101,4 +113,39 @@ class ExportExcel extends Command \think\facade\Log::info(json_encode($error_array)); } } + + protected function runHeadData() + { + $data = InvoiceHead::where('pucode','=','')->select()->toArray(); + foreach ($data as $item) { + + $wechatPucode = WechatPucode::where('wechat_user_id',$item['wechat_user_id'])->select()->toArray(); + foreach ($wechatPucode as $pucodeItem) { + + $pucode = $pucodeItem['pucode']; + try { + $feeUserInfo = (new InvoiceIssuanceService())->getFeeUserData($pucode); + } catch (\Exception $e) { + // 不存在跳过 + continue; + } + $CertificateCode = $feeUserInfo['CertificateCode'] ?? ''; + $UserName = $feeUserInfo['UserName'] ?? ''; + if (empty($UserName) && empty($CertificateCode)) { + continue; + } + // 存在更新pucode + if ($CertificateCode == $item['tax_number'] || $UserName == $item['title']) { + $save = ['pucode' => $pucode]; + if (empty($item['tax_number'])) { + $save['tax_number'] = $CertificateCode; + } + if (empty($item['title'])) { + $save['title'] = $UserName; + } + InvoiceHead::update($save,['id' => $item['id']]); + } + } + } + } } diff --git a/app/controller/admin/WechatUser.php b/app/controller/admin/WechatUser.php index c479c84..7676606 100644 --- a/app/controller/admin/WechatUser.php +++ b/app/controller/admin/WechatUser.php @@ -163,20 +163,28 @@ class WechatUser extends Base continue; } } - if ($taxId) { - $str = '0-9A-HJ-NPQRTUWXY'; - $pattern = '/^[' . $str . ']{2}\d{6}[' . $str . ']{10}$/'; - if (!preg_match($pattern, $taxId)) { - $error_array[] = "第{$key}行:纳税人编号格式不符合"; - continue; - } - } $typeArr = ['单位', '个人']; if (!in_array($type, $typeArr)) { $error_array[] = "第{$key}行:抬头类型不符合"; continue; } $type = array_search($type, $typeArr); + if ($taxId) { + if ($type === 1) { + $str = '0-9A-HJ-NPQRTUWXY'; + $pattern = '/^[' . $str . ']{2}\d{6}[' . $str . ']{10}$/'; + if (!preg_match($pattern, $taxId)) { + $error_array[] = "第{$key}行:纳税人编号格式不符合"; + continue; + } + } else { + $pattern = '/^\d{15}$|^\d{17}[\dXx]$/'; + if (!preg_match($pattern, $taxId)) { + $error_array[] = "第{$key}行:纳税人编号格式不符合"; + continue; + } + } + } UserService::addUser($phone, $email, $pucode, $taxId, $type); }