From 143c3b0fca1b3556977176abfba3c6c8f8907dee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9F=B3=E6=B8=85=E7=88=BD?= Date: Tue, 8 Apr 2025 10:42:18 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B5=81=E9=87=8F=E6=A0=87=E7=AD=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Server/application/plan/config/route.php | 5 ++ .../plan/controller/TrafficTag.php | 64 +++++++++++++++++++ Server/application/plan/model/TrafficTag.php | 56 ++++++++++++++++ 3 files changed, 125 insertions(+) create mode 100644 Server/application/plan/controller/TrafficTag.php create mode 100644 Server/application/plan/model/TrafficTag.php diff --git a/Server/application/plan/config/route.php b/Server/application/plan/config/route.php index f315dded..d6bee8cf 100644 --- a/Server/application/plan/config/route.php +++ b/Server/application/plan/config/route.php @@ -12,4 +12,9 @@ Route::group('v1/', function () { Route::get('', 'app\\plan\\controller\\Scene@index'); // 获取场景列表 Route::get(':id', 'app\\plan\\controller\\Scene@read'); // 获取场景详情 }); + + // 流量标签相关 + Route::group('traffic/tags', function () { + Route::get('', 'app\\plan\\controller\\TrafficTag@index'); // 获取标签列表 + }); })->middleware(['jwt']); \ No newline at end of file diff --git a/Server/application/plan/controller/TrafficTag.php b/Server/application/plan/controller/TrafficTag.php new file mode 100644 index 00000000..8f890d47 --- /dev/null +++ b/Server/application/plan/controller/TrafficTag.php @@ -0,0 +1,64 @@ +userInfo; + + // 获取查询条件 + $where = []; + + // 关键词搜索 + $keyword = Request::param('keyword', ''); + if (!empty($keyword)) { + $where[] = ['tagName', 'like', "%{$keyword}%"]; + } + + // 添加公司ID过滤条件 + $where[] = ['companyId', '=', $userInfo['companyId']]; + + // 获取分页参数 + $page = (int)Request::param('page', 1); + $limit = (int)Request::param('limit', 200); // 默认每页显示200条 + + // 获取排序参数 + $sort = Request::param('sort', 'id'); + $order = Request::param('order', 'desc'); + + // 查询列表 + $list = TrafficTagModel::getTagsByCompany($where, "{$sort} {$order}", $page, $limit); + + return json([ + 'code' => 200, + 'msg' => '获取成功', + 'data' => [ + 'total' => $list->total(), + 'list' => $list->items(), + 'page' => $page, + 'limit' => $limit + ] + ]); + } catch (\Exception $e) { + return json([ + 'code' => 500, + 'msg' => '获取失败:' . $e->getMessage() + ]); + } + } +} \ No newline at end of file diff --git a/Server/application/plan/model/TrafficTag.php b/Server/application/plan/model/TrafficTag.php new file mode 100644 index 00000000..3d427e0b --- /dev/null +++ b/Server/application/plan/model/TrafficTag.php @@ -0,0 +1,56 @@ + 'integer', + 'tagName' => 'string', + 'companyId' => 'integer', + 'createTime' => 'integer', + 'deleteTime' => 'integer' + ]; + + /** + * 获取标签列表,支持分页和搜索 + * + * @param array $where 查询条件 + * @param string $order 排序方式 + * @param int $page 页码 + * @param int $limit 每页数量 + * @return \think\Paginator 分页对象 + */ + public static function getTagsByCompany($where = [], $order = 'id desc', $page = 1, $limit = 200) + { + return self::where($where) + ->where('deleteTime', 0) // 只查询未删除的记录 + ->order($order) + ->paginate($limit, false, [ + 'page' => $page + ]); + } +} \ No newline at end of file