update
This commit is contained in:
@ -60,8 +60,8 @@ class KeywordsController extends AbstractController
|
||||
$query = new AppKeywordsMonitor();
|
||||
|
||||
$query->keyword = $keyword;
|
||||
$ignoreUrl = array_filter(array_unique(explode(PHP_EOL, $ignoreUrl)));
|
||||
|
||||
$ignoreUrl = array_filter(array_unique(explode(PHP_EOL, $ignoreUrl)));
|
||||
$query->ignore_url = json_encode($ignoreUrl);
|
||||
$query->save();
|
||||
|
||||
@ -131,7 +131,9 @@ class KeywordsController extends AbstractController
|
||||
// 先全部删掉
|
||||
AppKeywordsMonitorTask::query()->where(['aid' => $id])->update(['is_delete' => 1]);
|
||||
foreach ($platform as $platformItem) {
|
||||
$query = AppKeywordsMonitorTask::query()->where('aid', $id)->first();
|
||||
$query = AppKeywordsMonitorTask::query()->where([
|
||||
['aid', $id], ['platform', $platformItem]
|
||||
])->first();
|
||||
if ($query) {
|
||||
$query->is_delete = 0;
|
||||
$query->save();
|
||||
@ -140,6 +142,7 @@ class KeywordsController extends AbstractController
|
||||
$query->platform = $platformItem;
|
||||
$query->aid = $id;
|
||||
$query->keyword = $keyword;
|
||||
$query->page = 2; // 写死的只查前两页
|
||||
$query->save();
|
||||
}
|
||||
}
|
||||
@ -147,6 +150,23 @@ class KeywordsController extends AbstractController
|
||||
return $this->response->json(['code' => 0, 'msg' => 'ok', 'data' => $query]);
|
||||
}
|
||||
|
||||
// /admin/api/keywords/monitor/research
|
||||
|
||||
/**
|
||||
* 重查关键词
|
||||
* @url /admin/api/keywords/monitor/research
|
||||
* @return \Psr\Http\Message\ResponseInterface
|
||||
*/
|
||||
#[RequestMapping(path: 'monitor/research', methods: 'post')]
|
||||
public function monitorResearch(): \Psr\Http\Message\ResponseInterface
|
||||
{
|
||||
$id = $this->request->input('id');
|
||||
|
||||
$query = AppKeywordsMonitorTask::query()->where('aid', $id)->update(['queried_at' => 0]);
|
||||
|
||||
return $this->response->json(['code' => 0, 'msg' => 'ok', 'data' => $query]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除关键词
|
||||
* @url /admin/api/keywords/monitor/delete
|
||||
@ -177,27 +197,45 @@ class KeywordsController extends AbstractController
|
||||
#[RequestMapping(path: 'monitor/export-all', methods: 'get')]
|
||||
public function monitorExportAll()
|
||||
{
|
||||
$res = AppKeywordsMonitorResult::query()
|
||||
$baiduPCRes = AppKeywordsMonitorResult::query()
|
||||
->where('is_delete', 0)
|
||||
->where('platform', 1)
|
||||
->where('created_at', '>', date('Y-m-d H:i:s', strtotime('today')))
|
||||
->orderBy('aid', 'desc')
|
||||
->get()
|
||||
->toArray();
|
||||
|
||||
foreach ($res as &$v) {
|
||||
foreach ($baiduPCRes as &$v) {
|
||||
$v['keyword'] = AppKeywordsMonitorTask::find($v['aid'])->keyword;
|
||||
$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') . '关键词监控结果';
|
||||
$baiduWAPRes = AppKeywordsMonitorResult::query()
|
||||
->where('is_delete', 0)
|
||||
->where('platform', 2)
|
||||
->where('created_at', '>', date('Y-m-d H:i:s', strtotime('today')))
|
||||
->orderBy('aid', 'desc')
|
||||
->get()
|
||||
->toArray();
|
||||
|
||||
return ExcelHelper::exportData($this->response, list: [
|
||||
"百度PC端_$percent%" => $baiduRes
|
||||
], header: [
|
||||
foreach ($baiduWAPRes as &$v) {
|
||||
$v['keyword'] = AppKeywordsMonitorTask::find($v['aid'])->keyword;
|
||||
$v['screen_path'] = Config::getDomain() . $v['screen_path'];
|
||||
}
|
||||
|
||||
$fileName = date('Y-m-d') . '关键词监控结果';
|
||||
$exportList = [];
|
||||
// 百度PC非负率
|
||||
$total = AppKeywordsMonitorTask::query()->where('is_delete', 0)->where('platform', 1)->sum('length') ?: 1;
|
||||
$percent = round(($total - count($baiduPCRes)) / $total, 2) * 100;
|
||||
$exportList["百度PC端_$percent%"] = $baiduPCRes;
|
||||
|
||||
// 百度WAP非负率
|
||||
$total = AppKeywordsMonitorTask::query()->where('is_delete', 0)->where('platform', 2)->sum('length');
|
||||
$percent = round(($total - count($baiduWAPRes)) / $total, 2) * 100;
|
||||
$exportList["百度WAP端_$percent%"] = $baiduWAPRes;
|
||||
|
||||
return ExcelHelper::exportData($this->response, list: $exportList, header: [
|
||||
['关键词', 'keyword', 'text'],
|
||||
['标题', 'title', 'text'],
|
||||
['排名', 'order', 'text'],
|
||||
|
@ -6,6 +6,7 @@ use App\Controller\AbstractController;
|
||||
use App\Model\AppKeywordsMonitor;
|
||||
use App\Model\AppKeywordsMonitorResult;
|
||||
use App\Model\AppKeywordsMonitorTask;
|
||||
use Hyperf\DbConnection\Db;
|
||||
use Hyperf\HttpServer\Annotation\Controller;
|
||||
use Hyperf\HttpServer\Annotation\RequestMapping;
|
||||
|
||||
@ -21,6 +22,7 @@ class ToolsController extends AbstractController
|
||||
public function getQueryKeyword(): \Psr\Http\Message\ResponseInterface
|
||||
{
|
||||
$keyword = AppKeywordsMonitorTask::query()
|
||||
->where('id', 23)
|
||||
->where('queried_at', '<=', strtotime('-2 hours'))
|
||||
->where('is_delete', 0);
|
||||
|
||||
@ -50,74 +52,89 @@ class ToolsController extends AbstractController
|
||||
#[RequestMapping(path:'submit-query-keyword', methods:'post')]
|
||||
public function submitQueryKeyword(): \Psr\Http\Message\ResponseInterface
|
||||
{
|
||||
$requestData = $this->request->post();
|
||||
// Db::beginTransaction();
|
||||
try {
|
||||
$requestData = $this->request->post();
|
||||
|
||||
if (!isset($requestData['length']) || !isset($requestData['keyword_id']) || !$requestData['keyword_id'] || !$requestData['image_name'] || !$requestData['ip_info']) {
|
||||
return $this->response->json([
|
||||
'code' => 0,
|
||||
]);
|
||||
}
|
||||
|
||||
// 被查的关键词id
|
||||
$aid = $requestData['keyword_id'];
|
||||
|
||||
foreach ($requestData['items'] ?? [] as $key => $value) {
|
||||
// 非负面不存储
|
||||
if (!$value['matched'] || !$value['mu']) {
|
||||
continue;
|
||||
if (!isset($requestData['length']) || !isset($requestData['keyword_id']) || !$requestData['keyword_id'] || !$requestData['image_name'] || !$requestData['ip_info']) {
|
||||
return $this->response->json([
|
||||
'code' => 400,
|
||||
'msg' => '缺少参数'
|
||||
]);
|
||||
}
|
||||
|
||||
$query = AppKeywordsMonitorResult::query()->where([
|
||||
['aid', $aid],
|
||||
['url', $value['mu']],
|
||||
['is_delete', 0],
|
||||
['created_at', '>', date('Y-m-d H:i:s', strtotime('today'))]
|
||||
])->first()?->toArray();
|
||||
// 被查的关键词id
|
||||
$aid = $requestData['keyword_id'];
|
||||
|
||||
// 如果这个负面存过了就不管了
|
||||
if ($query) {
|
||||
continue;
|
||||
}
|
||||
|
||||
list($title, $desc) = call_user_func(function () use ($value) {
|
||||
$content = $value['content'];
|
||||
|
||||
$ex = explode(PHP_EOL . PHP_EOL, $content);
|
||||
if (count($ex) > 1) {
|
||||
return [$ex[0], $ex[1]];
|
||||
foreach ($requestData['items'] ?? [] as $key => $value) {
|
||||
// 非负面不存储
|
||||
if (!$value['matched'] || !$value['mu']) {
|
||||
continue;
|
||||
}
|
||||
|
||||
return ['', ''];
|
||||
});
|
||||
$query = AppKeywordsMonitorResult::query()->where([
|
||||
['aid', $aid],
|
||||
['url', $value['mu']],
|
||||
['is_delete', 0],
|
||||
['created_at', '>', date('Y-m-d H:i:s', strtotime('today'))]
|
||||
])->first()?->toArray();
|
||||
|
||||
if (!$title || !$desc) {
|
||||
continue;
|
||||
// 如果这个负面存过了就不管了
|
||||
if ($query) {
|
||||
echo '????@@@';
|
||||
continue;
|
||||
}
|
||||
|
||||
list($title, $desc) = call_user_func(function () use ($value) {
|
||||
$content = $value['content'];
|
||||
|
||||
$ex = explode(PHP_EOL . PHP_EOL, $content);
|
||||
if (count($ex) > 1) {
|
||||
return [$ex[0], $ex[1]];
|
||||
}
|
||||
|
||||
return ['', ''];
|
||||
});
|
||||
|
||||
if (!$title || !$desc) {
|
||||
echo '??????';
|
||||
continue;
|
||||
}
|
||||
|
||||
$query = new AppKeywordsMonitorResult();
|
||||
|
||||
$query->aid = $aid;
|
||||
$query->title = $title;
|
||||
$query->description = $desc;
|
||||
$query->url = $value['mu'];
|
||||
$query->order = $value['id'];
|
||||
$ipInfo = json_decode($requestData['ip_info'], true);
|
||||
$query->ip_address = $ipInfo['ip'];
|
||||
$query->ip_source = "{$ipInfo['country']}{$ipInfo['province']}{$ipInfo['city']}";
|
||||
$query->screen_path = $requestData['image_name'];
|
||||
$query->platform = $requestData['platform'];
|
||||
$query->save();
|
||||
}
|
||||
|
||||
$query = new AppKeywordsMonitorResult();
|
||||
|
||||
$query->aid = $aid;
|
||||
$query->title = $title;
|
||||
$query->description = $desc;
|
||||
$query->url = $value['mu'];
|
||||
$query->order = $value['id'];
|
||||
$ipInfo = json_decode($requestData['ip_info'], true);
|
||||
$query->ip_address = $ipInfo['ip'];
|
||||
$query->ip_source = "{$ipInfo['country']}{$ipInfo['province']}{$ipInfo['city']}";
|
||||
$query->screen_path = $requestData['image_name'];
|
||||
// 更新关键词最后查询时间
|
||||
$query = AppKeywordsMonitorTask::find($aid);
|
||||
$query->queried_at = time();
|
||||
$query->length = $requestData['length'] - 1; // 去掉相关搜索
|
||||
$query->save();
|
||||
|
||||
// 更新关键词最后查询时间
|
||||
$query = AppKeywordsMonitor::query()->where('id', $query->aid)->first();
|
||||
$query->queried_at = time();
|
||||
$query->save();
|
||||
|
||||
Db::commit();
|
||||
}catch (\Throwable $e) {
|
||||
var_dump($e->getMessage());
|
||||
// Db::rollBack();
|
||||
}
|
||||
|
||||
// 更新关键词最后查询时间
|
||||
$query = AppKeywordsMonitorTask::find($aid);
|
||||
$query->queried_at = time();
|
||||
$query->save();
|
||||
|
||||
// 更新关键词最后查询时间
|
||||
$query = AppKeywordsMonitor::query()->where('id', $query->aid)->first();
|
||||
$query->queried_at = time();
|
||||
$query->save();
|
||||
|
||||
return $this->response->json([]);
|
||||
return $this->response->json([
|
||||
'code' => 0,
|
||||
'msg' => 'ok'
|
||||
]);
|
||||
}
|
||||
}
|
@ -42,19 +42,27 @@ class ExcelHelper
|
||||
// 初始化
|
||||
$spreadsheet = new Spreadsheet();
|
||||
$sheet = $spreadsheet->getActiveSheet();
|
||||
// 写入头部
|
||||
$hk = 1;
|
||||
foreach ($header as $k => $v) {
|
||||
$sheet->setCellValue(Coordinate::stringFromColumnIndex($hk) . '1', $v[0]);
|
||||
$sheet->getStyle(Coordinate::stringFromColumnIndex($hk) . '1')->getFont()->setBold(true);
|
||||
$sheet->getColumnDimension(Coordinate::stringFromColumnIndex($hk))->setAutoSize(true);
|
||||
$hk += 1;
|
||||
}
|
||||
|
||||
// 开始写入内容
|
||||
$column = 2;
|
||||
$sheetIndex = 0;
|
||||
foreach ($list as $sheetTitle => $sheetListItem) {
|
||||
if ($sheetIndex > 0) {
|
||||
$spreadsheet->createSheet();
|
||||
$sheet = $spreadsheet->getSheet($sheetIndex);
|
||||
}
|
||||
$sheet->setTitle($sheetTitle);
|
||||
|
||||
// 从第几行开始写入
|
||||
$column = 2;
|
||||
// 写入头部
|
||||
$hk = 1;
|
||||
foreach ($header as $k => $v) {
|
||||
$sheet->setCellValue(Coordinate::stringFromColumnIndex($hk) . '1', $v[0]);
|
||||
$sheet->getStyle(Coordinate::stringFromColumnIndex($hk) . '1')->getFont()->setBold(true);
|
||||
$sheet->getColumnDimension(Coordinate::stringFromColumnIndex($hk))->setAutoSize(true);
|
||||
$hk += 1;
|
||||
}
|
||||
|
||||
$size = ceil(count($sheetListItem) / 500);
|
||||
for ($i = 0; $i < $size; $i++) {
|
||||
$buffer = array_slice($sheetListItem, $i * 500, 500);
|
||||
@ -75,6 +83,8 @@ class ExcelHelper
|
||||
unset($buffer[$k]);
|
||||
}
|
||||
}
|
||||
|
||||
$sheetIndex++;
|
||||
}
|
||||
// 清除之前的错误输出
|
||||
// ob_end_clean();
|
||||
|
@ -16,6 +16,8 @@ namespace App\Model;
|
||||
* @property int $queried_at
|
||||
* @property int $platform
|
||||
* @property int $aid
|
||||
* @property int $page
|
||||
* @property int $length
|
||||
*/
|
||||
class AppKeywordsMonitorTask extends Model
|
||||
{
|
||||
@ -32,5 +34,5 @@ class AppKeywordsMonitorTask extends Model
|
||||
/**
|
||||
* The attributes that should be cast to native types.
|
||||
*/
|
||||
protected array $casts = ['id' => 'integer', 'created_at' => 'datetime', 'updated_at' => 'datetime', 'deleted_at' => 'integer', 'is_delete' => 'integer', 'queried_at' => 'integer', 'platform' => 'integer', 'aid' => 'integer'];
|
||||
protected array $casts = ['id' => 'integer', 'created_at' => 'datetime', 'updated_at' => 'datetime', 'deleted_at' => 'integer', 'is_delete' => 'integer', 'queried_at' => 'integer', 'platform' => 'integer', 'aid' => 'integer', 'page' => 'integer', 'length' => 'integer'];
|
||||
}
|
||||
|
@ -70,6 +70,7 @@
|
||||
|
||||
<!-- 表格行工具栏 -->
|
||||
<script type="text/html" id="table-bar">
|
||||
<button class="pear-btn pear-btn-xs tool-btn" lay-event="research">重查</button>
|
||||
<button class="pear-btn pear-btn-xs tool-btn" lay-event="edit">编辑</button>
|
||||
<button class="pear-btn pear-btn-xs tool-btn" lay-event="delete">删除</button>
|
||||
</script>
|
||||
@ -83,6 +84,7 @@
|
||||
// 相关常量
|
||||
const PRIMARY_KEY = "id";
|
||||
|
||||
const RESEARCH_API = '/admin/api/keywords/monitor/research' // 重查关键词
|
||||
const DELETE_API = '/admin/api/keywords/monitor/delete' // 删除监控词
|
||||
const INDEX_API = '/admin/api/keywords/monitor'; // 表格数据
|
||||
const VIEW_API = "/admin/api/keywords/monitor/view"; // 编辑按钮 - 查看
|
||||
@ -147,9 +149,7 @@
|
||||
});
|
||||
}
|
||||
|
||||
// if (!count) {
|
||||
render();
|
||||
// }
|
||||
|
||||
// 编辑或删除行事件
|
||||
table.on("tool(data-table)", function (obj) {
|
||||
@ -190,6 +190,10 @@
|
||||
*/
|
||||
});
|
||||
}
|
||||
|
||||
if (obj.event === 'research') {
|
||||
research(obj)
|
||||
}
|
||||
});
|
||||
|
||||
// 表格顶部工具栏事件
|
||||
@ -259,6 +263,31 @@
|
||||
});
|
||||
}
|
||||
|
||||
let research = function (obj) {
|
||||
layer.confirm("确定重查?", {
|
||||
icon: 3,
|
||||
title: "提示"
|
||||
}, function (index) {
|
||||
layer.close(index);
|
||||
let loading = layer.load();
|
||||
layui.$.ajax({
|
||||
url: RESEARCH_API,
|
||||
type: "POST",
|
||||
dateType: "json",
|
||||
data: {
|
||||
id: obj.data.id
|
||||
},
|
||||
success: function (res) {
|
||||
layer.close(loading);
|
||||
if (res.code) {
|
||||
return layui.popup.failure(res.msg);
|
||||
}
|
||||
return layui.popup.success("操作成功", refreshTable);
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
// 删除一行
|
||||
let remove = function (obj) {
|
||||
return doRemove(obj.data[PRIMARY_KEY]);
|
||||
|
@ -21,6 +21,7 @@
|
||||
<label class="layui-form-label">监控平台</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="checkbox" name="platform[]" value="1" title="百度PC">
|
||||
<input type="checkbox" name="platform[]" value="2" title="百度WAP">
|
||||
{{-- <input type="checkbox" name="arr[1]" title="选项2" checked>--}}
|
||||
{{-- <input type="checkbox" name="arr[2]" title="选项3">--}}
|
||||
</div>
|
||||
|
Reference in New Issue
Block a user