From 292571bb9cc829e4d12c5782cf15ccfbadd082bb Mon Sep 17 00:00:00 2001 From: wanghongjun <1445693971@qq.com> Date: Fri, 25 Apr 2025 10:56:51 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AF=BC=E5=85=A5=E7=94=A8=E6=88=B7=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controller/admin/WechatUser.php | 31 ++++++++++++++++++++++++++--- app/service/user/UserService.php | 2 +- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/app/controller/admin/WechatUser.php b/app/controller/admin/WechatUser.php index 5fd4406..2751d20 100644 --- a/app/controller/admin/WechatUser.php +++ b/app/controller/admin/WechatUser.php @@ -5,6 +5,7 @@ namespace app\controller\admin; use app\model\WechatUser as WechatUserModel; use app\service\ExportService; use app\service\user\UserService; +use app\service\webService\FeeService; use think\Response; class WechatUser extends Base @@ -71,6 +72,7 @@ class WechatUser extends Base } $max_size = '10'; + $size = ((int)$max_size * 1024 * 1024); $mimetype = 'xls,xlsx'; $fileInfo = []; $fileInfo['name'] = $file->getOriginalName(); //上传文件名 @@ -78,8 +80,8 @@ class WechatUser extends Base $fileInfo['tmp_name'] = $file->getPathname(); $fileInfo['size'] = $file->getSize(); - if ($fileInfo['size'] > $max_size) { - throw new \Exception('文件超过配置的最大值' . $max_size . 'M'); + if ($fileInfo['size'] > $size) { + throw new \Exception('文件超过配置的最大值' . $size . 'M'); } @@ -124,7 +126,9 @@ class WechatUser extends Base $excel_array = $obj_PHPExcel->getSheet(0)->toArray(); array_shift($excel_array); - foreach ($excel_array as $data) { + $error_array = []; + foreach ($excel_array as $key => $data) { + $key = $key + 1; // 验证不能为空 $is_empty = false; foreach ($data as $value) { @@ -142,24 +146,45 @@ class WechatUser extends Base $taxId = $data[3]; $type = $data[4]; if (!preg_match('/^1[3-9]\d{9}$/', $phone)) { + $error_array[] = "第{$key}行:手机号格式不符合"; continue; } + + $FeeService = new FeeService($pucode); + $feeUserInfo = $FeeService->getUsers(); + + if ($feeUserInfo['UserCode'] != $pucode) { + $error_array[] = "第{$key}行:用户编号不存在"; + continue; + } + if ($feeUserInfo['CellPhone'] != $phone) { + $error_array[] = "第{$key}行:手机号或用户编号错误"; + continue; + } + if (filter_var($email, FILTER_VALIDATE_EMAIL) === false) { + $error_array[] = "第{$key}行:邮箱格式不符合"; continue; } $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); UserService::addUser($phone, $email, $pucode, $taxId, $type); } + if (!empty($error_array)) { + throw new \Exception(implode('\n', $error_array)); + } + return $this->buildSuccess(); } catch (\Exception $e) { return $this->buildFailed(400, $e->getMessage()); diff --git a/app/service/user/UserService.php b/app/service/user/UserService.php index 34eec92..278c49b 100644 --- a/app/service/user/UserService.php +++ b/app/service/user/UserService.php @@ -65,7 +65,7 @@ class UserService extends BaseService if (!$query) { $save = [ - 'nick_name' => '导入用户', + 'nickname' => '导入用户', 'phone' => $phone, 'email' => $email ];