fix - bug

This commit is contained in:
toom1996
2025-06-20 15:27:14 +08:00
parent b7fe1994f1
commit e25a4156c3
15 changed files with 112 additions and 286 deletions

View File

@ -47,6 +47,7 @@ class KeywordsController extends AbstractController
public function monitorInsert(): \Psr\Http\Message\ResponseInterface
{
$keyword = $this->request->post('keyword');
$ignoreUrl = $this->request->post('ignore_url');
$query = AppKeywordsMonitor::query()->where([
['keyword', $keyword],
@ -59,7 +60,9 @@ class KeywordsController extends AbstractController
$query = new AppKeywordsMonitor();
$query->keyword = $keyword;
$ignoreUrl = array_filter(array_unique(explode(PHP_EOL, $ignoreUrl)));
$query->ignore_url = json_encode($ignoreUrl);
$query->save();
foreach ($this->request->post('platform', []) as $platform) {
@ -83,11 +86,14 @@ class KeywordsController extends AbstractController
{
$id = $this->request->input('id');
$query = AppKeywordsMonitor::query()->where(['id' => $id])->first()->toArray();
$query = AppKeywordsMonitor::formatQuery(['ignore_url'])->where(['id' => $id])->first()->toArray();
if (!$query) {
return $this->response->json(['code' => 400, 'msg' => 'id 有误']);
}
if ($query['ignore_url']) {
$query['ignore_url'] = implode(PHP_EOL, $query['ignore_url']);
}
$query['platform'] = AppKeywordsMonitorTask::query()->select(['platform'])
->where([
['aid', $query['id']],
@ -109,6 +115,7 @@ class KeywordsController extends AbstractController
$id = $this->request->post('id');
$keyword = $this->request->post('keyword');
$platform = $this->request->post('platform', []);
$ignoreUrl = $this->request->post('ignore_url');
$query = AppKeywordsMonitor::find($id);
if (!$query) {
@ -116,6 +123,9 @@ class KeywordsController extends AbstractController
}
$query->keyword = $keyword;
$ignoreUrl = array_filter(array_unique(explode(PHP_EOL, $ignoreUrl)));
$query->ignore_url = json_encode($ignoreUrl);
$query->save();
// 先全部删掉
@ -163,20 +173,26 @@ class KeywordsController extends AbstractController
/**
* 导出关键词报表
* @url /admin/api/keywords/monitor/export-all
* @return \Psr\Http\Message\ResponseInterface
*/
#[RequestMapping(path: 'monitor/export-all', methods: 'get')]
public function monitorExportAll(): \Psr\Http\Message\ResponseInterface
public function monitorExportAll()
{
$res = AppKeywordsMonitorResult::query()->orderBy('aid', 'desc')->get()->toArray();
foreach ($res as &$v) {
$v['keyword'] = AppKeywordsMonitorTask::find($v['aid'])->keyword;
$v['screen_path'] = Config::DOMAIN . $v['screen_path'];
$v['screen_path'] = Config::getDomain() . $v['screen_path'];
}
// 百度PC非负率
$total = 20 * AppKeywordsMonitorTask::query()->where('platform', 1)->count();
$baiduRes = $res;
$percent = round(($total - count($baiduRes)) / $total, 2) * 100;
$fileName = date('Y-m-d') . '关键词监控结果';
return ExcelHelper::exportData($this->response, list: $res, header: [
return ExcelHelper::exportData($this->response, list: [
"百度PC端_$percent%" => $baiduRes
], header: [
['关键词', 'keyword', 'text'],
['标题', 'title', 'text'],
['排名', 'order', 'text'],