Selaa lähdekoodia

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

- 在 EnumUtil 中增加对枚举字段值的空值检查,避免不必要的验证
- 在 ZeroUserRepository 中将 not null 检查改为 empty 检查,提高搜索准确性
shichen 10 kuukautta sitten
vanhempi
commit
79900148c8
2 muutettua tiedostoa jossa 6 lisäystä ja 4 poistoa
  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 93
         $where = [];
94 94
         
95 95
         // 状态条件 - 精确搜索
96
-        if (!is_null($param->status)) {
96
+        if (!empty($param->status)) {
97 97
             $where[] = ['status', '=', $param->status];
98 98
         }
99 99
         
100 100
         // 团队昵称条件 - 模糊搜索
101
-        if (!is_null($param->teamName)) {
101
+        if (!empty($param->teamName)) {
102 102
             $where[] = ['team_name', 'like', '%' . $param->teamName . '%'];
103 103
         }
104 104
         
105 105
         // 团队长uid条件 - 精确搜索
106
-        if (!is_null($param->account)) {
106
+        if (!empty($param->account)) {
107 107
             $userDao = new UserDao();
108 108
             $userWhere[] = ['account','like','%' . $param->account . '%'];
109 109
             $userData = $userDao->getWhere($userWhere,'uid');

+ 3 - 1
app/utils/EnumUtil.php

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