Browse Source

refactor(app): 优化枚举值验证和用户搜索逻辑

- 在 EnumUtil 中增加对枚举字段值的空值检查,避免不必要的验证
- 在 ZeroUserRepository 中将 not null 检查改为 empty 检查,提高搜索准确性
shichen 10 months ago
parent
commit
79900148c8
2 changed files with 6 additions and 4 deletions
  1. 3 3
      app/common/repositories/user/ZeroUserRepository.php
  2. 3 1
      app/utils/EnumUtil.php

+ 3 - 3
app/common/repositories/user/ZeroUserRepository.php

@@ -93,17 +93,17 @@ class ZeroUserRepository extends BaseRepository
93
         $where = [];
93
         $where = [];
94
         
94
         
95
         // 状态条件 - 精确搜索
95
         // 状态条件 - 精确搜索
96
-        if (!is_null($param->status)) {
96
+        if (!empty($param->status)) {
97
             $where[] = ['status', '=', $param->status];
97
             $where[] = ['status', '=', $param->status];
98
         }
98
         }
99
         
99
         
100
         // 团队昵称条件 - 模糊搜索
100
         // 团队昵称条件 - 模糊搜索
101
-        if (!is_null($param->teamName)) {
101
+        if (!empty($param->teamName)) {
102
             $where[] = ['team_name', 'like', '%' . $param->teamName . '%'];
102
             $where[] = ['team_name', 'like', '%' . $param->teamName . '%'];
103
         }
103
         }
104
         
104
         
105
         // 团队长uid条件 - 精确搜索
105
         // 团队长uid条件 - 精确搜索
106
-        if (!is_null($param->account)) {
106
+        if (!empty($param->account)) {
107
             $userDao = new UserDao();
107
             $userDao = new UserDao();
108
             $userWhere[] = ['account','like','%' . $param->account . '%'];
108
             $userWhere[] = ['account','like','%' . $param->account . '%'];
109
             $userData = $userDao->getWhere($userWhere,'uid');
109
             $userData = $userDao->getWhere($userWhere,'uid');

+ 3 - 1
app/utils/EnumUtil.php

@@ -31,8 +31,10 @@ class EnumUtil
31
                 }
31
                 }
32
 
32
 
33
                 $fieldName = self::constToFieldName($constName);
33
                 $fieldName = self::constToFieldName($constName);
34
-
35
                 if (array_key_exists($fieldName, $requestData)) {
34
                 if (array_key_exists($fieldName, $requestData)) {
35
+                    if (empty($requestData[$fieldName])) {
36
+                        continue;
37
+                    }
36
                     $result = self::validateEnumValue($requestData[$fieldName], $enumValues, $constName);
38
                     $result = self::validateEnumValue($requestData[$fieldName], $enumValues, $constName);
37
                     if (!$result['valid']) {
39
                     if (!$result['valid']) {
38
                         $errors[] = $result['error'];
40
                         $errors[] = $result['error'];