Browse Source

feat(index): 新增首页统计数据接口

- 添加头部指引数据统计接口
- 实现AI平台收录统计接口
- 创建AI创作折线图数据接口
- 添加投喂任务线状图数据接口
- 配置相应路由规则及权限参数
master
zhangf@suq.cn 2 days ago
parent
commit
c79310cd43
  1. 29
      app/controller/IndexController.php
  2. 7
      app/route/route.php
  3. 113
      app/service/IndexService.php

29
app/controller/IndexController.php

@ -0,0 +1,29 @@
<?php
namespace app\controller;
use app\service\IndexService;
use support\Response;
class IndexController
{
public function head(IndexService $service): Response
{
return success($service->processStatistic());
}
public function aiStatistic(IndexService $service)
{
return success($service->aiStatistic());
}
public function createStatistic(IndexService $service)
{
return success($service->createStatistic());
}
public function feedStatistic(IndexService $service)
{
return success($service->feedStatistic());
}
}

7
app/route/route.php

@ -18,7 +18,14 @@ use Webman\Route;
Route::group('/service/v1', function () {
//控制台
Route::group('/statistic', function () {
//数量统计
Route::get('/head', [IndexController::class, 'head'])->setParams(['perm' => ['indexHead']]);
//ai平台统计
Route::get('/ai', [IndexController::class, 'aiStatistic'])->setParams(['perm' => ['indexAiStatistic']]);
//AI创作线状图
Route::get('/creation', [IndexController::class, 'createStatistic'])->setParams(['perm' => ['indexCreationStatistic']]);
//投喂线状图
Route::get('/feed', [IndexController::class, 'feedStatistic'])->setParams(['perm' => ['indexFeedStatistic']]);
});
//蒸馏词

113
app/service/IndexService.php

@ -0,0 +1,113 @@
<?php
namespace app\service;
use app\dao\AiCommandDao;
use app\dao\CreationArticleDao;
use app\dao\DistillationQuestionsDao;
use app\dao\DistillationWordDao;
use app\dao\EnterprisePortraitLibraryDao;
use plugin\piadmin\app\base\BaseService;
use plugin\piadmin\app\utils\RequestUtils;
class IndexService extends BaseService
{
protected $user;
protected $distillationWordDao;
protected $portraitLibraryDao;
protected $aiCommandDao;
protected $creationArticleDao;
protected $questionDao;
public function __construct()
{
$this->user = RequestUtils::getUserInfo();
$this->distillationWordDao = app()->make(DistillationWordDao::class);
$this->portraitLibraryDao = app()->make(EnterprisePortraitLibraryDao::class);
$this->aiCommandDao = app()->make(AICommandDao::class);
$this->creationArticleDao = app()->make(CreationArticleDao::class);
$this->questionDao = app()->make(DistillationQuestionsDao::class);
}
/**
* 头部指引
*/
public function processStatistic()
{
return [
//蒸馏词
'word' => $this->distillationWordDao->count(),
//图库
'library' => $this->portraitLibraryDao->count(),
//指令
'command' => $this->aiCommandDao->count(),
//AI创作
'ai' => $this->creationArticleDao->count(),
//授权账号
'account' => 0,
//投喂任务
'task' => 0,
//训练问题
'question' => $this->questionDao->count(),
//收录问题
'collect' => 0,
//媒体投喂
'media' => 0
];
}
/**
* AI收录统计
*/
public function aiStatistic()
{
return [
'deepseek' => 0,
'doubao' => 0,
'yuanbao' => 0,
'tongyiqianwen' => 0,
'wenxinyiyan' => 0,
'nami' => 0,
'kimi' => 0,
'zhipu' => 0
];
}
/**
* AI创作折线图
* 近五天
*/
public function createStatistic()
{
$dates = [];
for ($i = 0; $i < 5; $i++) {
$dates[]['date'] = date('Y-m-d', strtotime("-{$i} days"));
}
foreach ($dates as &$date) {
$begin = strtotime($date['date']);
$end = strtotime("+1 day", $begin);
$date['count'] = $this->creationArticleDao->count([
['create_time', 'between', [$begin, $end]],
]);
}
return $dates;
}
/**
* 投喂线状图
*/
public function feedStatistic()
{
$dates = [];
for ($i = 0; $i < 5; $i++) {
$dates[]['date'] = date('Y-m-d', strtotime("-{$i} days"));
}
foreach ($dates as &$date) {
// $begin = strtotime($date['date']);
// $end = strtotime("+1 day", $begin);
$date['count'] = 0;
}
return $dates;
}
}
Loading…
Cancel
Save