refactor(dao): remove BaseAuth search dependency
Made-with: Cursor
This commit is contained in:
@@ -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 的预发或生产验证窗口执行。
|
||||
|
||||
59
pro_v3.5.1/app/services/dao/SearchConditionBuilder.php
Normal file
59
pro_v3.5.1/app/services/dao/SearchConditionBuilder.php
Normal file
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: ScottPan Team
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\services\dao;
|
||||
|
||||
use think\helper\Str;
|
||||
|
||||
/**
|
||||
* 本项目自有搜索条件构建器,不依赖 CRMEB 商业授权基础类。
|
||||
*/
|
||||
class SearchConditionBuilder
|
||||
{
|
||||
/**
|
||||
* 根据模型搜索器和表字段拆分 withSearch 字段与普通 where 字段。
|
||||
*
|
||||
* @param array $whereKeys 请求条件 key 列表
|
||||
* @param string|object $model 模型类名或模型实例
|
||||
* @return array{0: array, 1: array}
|
||||
* @throws \ReflectionException
|
||||
*/
|
||||
public function build(array $whereKeys, $model): array
|
||||
{
|
||||
$modelClass = is_object($model) ? $model::class : $model;
|
||||
$reflection = new \ReflectionClass($modelClass);
|
||||
$fields = $this->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 [];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user