first commit
This commit is contained in:
118
app/Controller/api/expose/v1/ToolsController.php
Normal file
118
app/Controller/api/expose/v1/ToolsController.php
Normal file
@ -0,0 +1,118 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller\api\expose\v1;
|
||||
|
||||
use App\Controller\AbstractController;
|
||||
use App\Model\AppKeywordsMonitor;
|
||||
use App\Model\AppKeywordsMonitorResult;
|
||||
use App\Model\AppKeywordsMonitorTask;
|
||||
use Hyperf\HttpServer\Annotation\Controller;
|
||||
use Hyperf\HttpServer\Annotation\RequestMapping;
|
||||
|
||||
#[Controller(prefix: "/api/expose/v1/tools")]
|
||||
class ToolsController extends AbstractController
|
||||
{
|
||||
/**
|
||||
* 获取关键词监控的关键词
|
||||
* @url /api/expose/v1/tools/get-query-keyword
|
||||
* @return \Psr\Http\Message\ResponseInterface
|
||||
*/
|
||||
#[RequestMapping(path:'get-query-keyword', methods:'get')]
|
||||
public function getQueryKeyword(): \Psr\Http\Message\ResponseInterface
|
||||
{
|
||||
$keyword = AppKeywordsMonitorTask::formatQuery(['created_at'])
|
||||
->where('queried_at', '<=', strtotime('-2 hours'))
|
||||
->where('is_delete', 0);
|
||||
|
||||
if ($keyword) {
|
||||
$query = $keyword->first()->toArray();
|
||||
return $this->response->json([
|
||||
'code' => 0,
|
||||
'data' => $query
|
||||
]);
|
||||
}
|
||||
|
||||
return $this->response->json([
|
||||
'code' => 0,
|
||||
'data' => ''
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 提交监控数据
|
||||
* @url /api/expose/v1/tools/submit-query-keyword
|
||||
* @return \Psr\Http\Message\ResponseInterface
|
||||
*/
|
||||
#[RequestMapping(path:'submit-query-keyword', methods:'post')]
|
||||
public function submitQueryKeyword(): \Psr\Http\Message\ResponseInterface
|
||||
{
|
||||
$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;
|
||||
}
|
||||
|
||||
$query = AppKeywordsMonitorResult::query()->where([
|
||||
['aid', $aid],
|
||||
['url', $value['mu']],
|
||||
['is_delete', 0],
|
||||
])->first()?->toArray();
|
||||
|
||||
// 如果这个负面存过了就不管了
|
||||
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]];
|
||||
}
|
||||
|
||||
return ['', ''];
|
||||
});
|
||||
|
||||
if (!$title || !$desc) {
|
||||
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->save();
|
||||
}
|
||||
|
||||
// 更新关键词最后查询时间
|
||||
$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([]);
|
||||
}
|
||||
}
|
70
app/Controller/api/v1/ArticlesController.php
Executable file
70
app/Controller/api/v1/ArticlesController.php
Executable file
@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller\api\v1;
|
||||
|
||||
use App\Controller\AbstractController;
|
||||
use App\FormModel\api\v1\ArticlesModel;
|
||||
use App\Helpers\AppHelper;
|
||||
use App\Model\AppArticle;
|
||||
use App\Model\AppBrand;
|
||||
use Hyperf\Collection\Collection;
|
||||
use Hyperf\HttpServer\Annotation\AutoController;
|
||||
use Hyperf\HttpServer\Annotation\Controller;
|
||||
use Hyperf\HttpServer\Annotation\RequestMapping;
|
||||
|
||||
#[Controller]
|
||||
class ArticlesController extends AbstractController
|
||||
{
|
||||
/**
|
||||
* 文章列表
|
||||
* @url /api/v1/articles
|
||||
* @return array
|
||||
*/
|
||||
#[RequestMapping(path:'', methods: 'get')]
|
||||
public function index(): array
|
||||
{
|
||||
$request = $this->request;
|
||||
$query = Model::query()->orderBy('id');
|
||||
$pagination = $query->paginate($request->input('limit', 10), page: $request->input('page'));
|
||||
$data = $query->get()->toArray();
|
||||
// $data['cover'] = AppHelper::setImageUrl($query['cover']);
|
||||
|
||||
foreach ($data as &$v) {
|
||||
$v['cover'] = AppHelper::setImageUrl($v['cover']);
|
||||
}
|
||||
return ['code' => 0, 'msg' => 'ok', 'count' => $pagination->total(), 'data' => $data];
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增/编辑文章
|
||||
* @url /api/v1/articles/save
|
||||
* @return array
|
||||
*/
|
||||
#[RequestMapping(path:'save', methods: 'post')]
|
||||
public function save(): array
|
||||
{
|
||||
$id = $this->request->input('id');
|
||||
$model = new ArticlesModel();
|
||||
if ($id) {
|
||||
$model->edit();
|
||||
} else {
|
||||
$model->create();
|
||||
}
|
||||
|
||||
return [
|
||||
'code' => 0,
|
||||
'message' => 'ok'
|
||||
];
|
||||
}
|
||||
|
||||
#[RequestMapping(path:'brand-search', methods: 'get')]
|
||||
public function brandSearch(): array
|
||||
{
|
||||
$input = $this->request->input('brand');
|
||||
$query = Model::query()->select(['name', 'cn_name', 'id'])->where('name', 'like', "%$input%")
|
||||
->orWhere('cn_name', 'like', "%$input%")
|
||||
->get()->toArray();
|
||||
|
||||
return ['code' => 0, 'msg' => 'ok', 'data' => $query];
|
||||
}
|
||||
}
|
33
app/Controller/api/v1/UserController.php
Executable file
33
app/Controller/api/v1/UserController.php
Executable file
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller\api\v1;
|
||||
|
||||
use App\Controller\AbstractController;
|
||||
use App\FormModel\api\v1\UserModel;
|
||||
use App\Request\Test;
|
||||
use Hyperf\HttpServer\Annotation\Controller;
|
||||
use Hyperf\HttpServer\Annotation\RequestMapping;
|
||||
|
||||
#[Controller]
|
||||
class UserController extends AbstractController
|
||||
{
|
||||
|
||||
#[RequestMapping(path: '/api/v1/user/register', methods: 'post')]
|
||||
public function register(Test $validator)
|
||||
{
|
||||
$validator = $validator->validated();
|
||||
$model = new UserModel();
|
||||
$model->register();
|
||||
return [];
|
||||
}
|
||||
|
||||
public function login()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function logout()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user