From 083c51ed7eb0e98b6b4f6c27f654b13cdc0fcb8a Mon Sep 17 00:00:00 2001 From: apple Date: Wed, 29 Apr 2026 17:09:08 +0800 Subject: [PATCH] refactor(dao): remove BaseAuth search dependency Made-with: Cursor --- docs/license-replacement-test-record.md | 25 ++++++++ .../services/dao/SearchConditionBuilder.php | 59 +++++++++++++++++++ pro_v3.5.1/crmeb/traits/SearchDaoTrait.php | 4 +- 3 files changed, 86 insertions(+), 2 deletions(-) create mode 100644 pro_v3.5.1/app/services/dao/SearchConditionBuilder.php diff --git a/docs/license-replacement-test-record.md b/docs/license-replacement-test-record.md index 9c2ebff2..0a031140 100644 --- a/docs/license-replacement-test-record.md +++ b/docs/license-replacement-test-record.md @@ -91,3 +91,28 @@ - `app/services/out/OutAccountServices.php` 已移除 `crmeb\basic\BaseAuth` 依赖。 - `app/services/kefu/LoginServices.php` 未修改,保留到最后阶段处理。 - 外部账号手工接口回归需要在具备外部账号凭证的预发或生产验证窗口执行。 + +## 阶段 2:通用搜索条件构建 + +### 自动化检查 + +| 命令 | 结果 | 备注 | +|------|------|------| +| `php -l app/services/dao/SearchConditionBuilder.php` | 通过 | PHP 提示 `swoole_loader` 已加载,不影响语法检查结果。 | +| `php -l crmeb/traits/SearchDaoTrait.php` | 通过 | PHP 提示 `swoole_loader` 已加载,不影响语法检查结果。 | +| `php -r '...SearchConditionBuilder smoke...'` | 通过 | 验证搜索器字段进入 `withSearch`,普通表字段进入 where,非法字段和 `timeKey` 被过滤。 | + +### 手工回归记录 + +| 阶段 | 接口/命令 | 方法 | 身份 | 关键参数 | HTTP 状态 | 业务 `status` | 关键字段 | 结果 | 备注 | +|------|-----------|------|------|----------|-----------|---------------|----------|------|------| +| 2 | 商品列表筛选 | GET | admin | 关键词、分类、上下架、分页 | 待预发填写 | 待预发填写 | `list`、`count` | 待测 | 当前本地无完整接口运行环境。 | +| 2 | 订单列表筛选 | GET | admin | 订单号、用户、状态、时间范围、分页 | 待预发填写 | 待预发填写 | `list`、`count` | 待测 | 当前本地无完整接口运行环境。 | +| 2 | 用户列表筛选 | GET | admin | 手机号/昵称、等级/标签、状态、分页 | 待预发填写 | 待预发填写 | `list`、`count` | 待测 | 当前本地无完整接口运行环境。 | +| 2 | 非法字段请求 | GET | admin | 非法 where 字段 | 待预发填写 | 待预发填写 | 无 500 | 待测 | 当前本地无完整接口运行环境。 | + +### 阶段结论 + +- `crmeb/traits/SearchDaoTrait.php` 已移除 `crmeb\basic\BaseAuth` 依赖。 +- 企业微信 `app/dao/work/*Dao.php` 未修改,保留到最后阶段处理。 +- 常用列表接口手工回归需要在具备后台 token 的预发或生产验证窗口执行。 diff --git a/pro_v3.5.1/app/services/dao/SearchConditionBuilder.php b/pro_v3.5.1/app/services/dao/SearchConditionBuilder.php new file mode 100644 index 00000000..fd959fa4 --- /dev/null +++ b/pro_v3.5.1/app/services/dao/SearchConditionBuilder.php @@ -0,0 +1,59 @@ +getTableFields($model); + + $with = []; + $whereKey = []; + foreach ($whereKeys as $key) { + $key = (string)$key; + if ($key === 'timeKey') { + continue; + } + + if ($reflection->hasMethod('search' . Str::studly($key) . 'Attr')) { + $with[] = $key; + continue; + } + + if (!$fields || in_array($key, $fields, true)) { + $whereKey[] = $key; + } + } + + return [$with, $whereKey]; + } + + protected function getTableFields($model): array + { + try { + $model = is_object($model) ? $model : new $model(); + return $model->getTableFields(); + } catch (\Throwable $e) { + return []; + } + } +} diff --git a/pro_v3.5.1/crmeb/traits/SearchDaoTrait.php b/pro_v3.5.1/crmeb/traits/SearchDaoTrait.php index 75e4c985..a998ee21 100644 --- a/pro_v3.5.1/crmeb/traits/SearchDaoTrait.php +++ b/pro_v3.5.1/crmeb/traits/SearchDaoTrait.php @@ -5,8 +5,8 @@ namespace crmeb\traits; +use app\services\dao\SearchConditionBuilder; use app\dao\BaseDao; -use crmeb\basic\BaseAuth; use crmeb\basic\BaseModel; use think\db\exception\DataNotFoundException; use think\db\exception\DbException; @@ -28,7 +28,7 @@ trait SearchDaoTrait */ public function searchWhere(array $where, bool $authWhere = true) { - [$with, $whereKey] = app()->make(BaseAuth::class)->________(array_keys($where), $this->setModel()); + [$with, $whereKey] = app()->make(SearchConditionBuilder::class)->build(array_keys($where), $this->setModel()); $whereData = []; foreach ($whereKey as $key) { if (isset($where[$key]) && 'timeKey' !== $key) {