update
This commit is contained in:
@ -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'
|
||||
]);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user