fix - bug
This commit is contained in:
@ -1,113 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller\admin\api;
|
||||
|
||||
use App\Controller\AbstractController;
|
||||
use App\Enums\ArticlePublishedStatusEnum;
|
||||
use App\FormModel\admin\articles\ModifyModel;
|
||||
use App\Helpers\AppHelper;
|
||||
use App\Model\AppArticle;
|
||||
use App\Model\AppBrand;
|
||||
use App\Model\AppNews;
|
||||
use Hyperf\HttpServer\Annotation\Controller;
|
||||
use Hyperf\HttpServer\Annotation\RequestMapping;
|
||||
|
||||
#[Controller(prefix: 'admin/api')]
|
||||
class ArticleController extends AbstractController
|
||||
{
|
||||
/**
|
||||
* 文章列表
|
||||
* @url /admin/api/article
|
||||
* @return array
|
||||
*/
|
||||
#[RequestMapping(path:'articles', methods: 'get')]
|
||||
public function index(): array
|
||||
{
|
||||
$publishedStatus = $this->request->query('published_status', '');
|
||||
$createdFilter = $this->request->query('created_at', [date('Y-m-d', strtotime('-1 month')), date('Y-m-d', time())]);
|
||||
foreach ($createdFilter as $index => &$item) {
|
||||
if ($index == 0) {
|
||||
$item = strtotime($item . ' 00:00:00');
|
||||
}
|
||||
|
||||
if ($index == 1) {
|
||||
$item = strtotime($item . ' 23:59:59');
|
||||
}
|
||||
}
|
||||
|
||||
$query = AppNews::formatQuery(['module', 'published_status', 'location'])
|
||||
->select(['id'])
|
||||
->when($publishedStatus !== '', fn($q) => $q->where('published_status', $publishedStatus))
|
||||
->whereBetween('created_at', $createdFilter)
|
||||
->orderBy('created_at', 'desc');
|
||||
$pagination = $query->paginate($this->request->input('limit', 10), page: $this->request->input('page'));
|
||||
foreach ($pagination->items() as $item) {
|
||||
$ids[] = $item->id;
|
||||
}
|
||||
|
||||
$value = AppNews::find($ids, ['aid', 'title', 'module', 'published_status', 'location'])->toArray();
|
||||
return ['code' => 0, 'msg' => 'ok', 'count' => $pagination->total(), 'data' => $value];
|
||||
}
|
||||
|
||||
// /**
|
||||
// * 新增/编辑文章
|
||||
// * @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 = AppBrand::query()->select(['name', 'cn_name', 'id'])->where('name', 'like', "%$input%")
|
||||
->orWhere('cn_name', 'like', "%$input%")
|
||||
->get()->toArray();
|
||||
|
||||
return ['code' => 0, 'msg' => 'ok', 'data' => $query];
|
||||
}
|
||||
|
||||
#[RequestMapping(path:'view', methods: 'get')]
|
||||
public function view(): \Psr\Http\Message\ResponseInterface
|
||||
{
|
||||
$query = AppNews::formatQuery(['images', 'brand_name', 'translate_title'])
|
||||
->select(['brand as brand_name', 'brand', 'images', 'id', 'title', 'title as translate_title', 'cover', 'aid', 'location'])
|
||||
->where('aid', $this->request->query('id'));
|
||||
|
||||
return $this->response->json(['code' => 0, 'msg' => 'ok', 'data' => $query->first()]);
|
||||
}
|
||||
|
||||
#[RequestMapping(path:'publish', methods: 'post')]
|
||||
public function publish()
|
||||
{
|
||||
$query = AppArticle::where('aid', $this->request->post('aid'))->first();
|
||||
$query->published_status = ArticlePublishedStatusEnum::TRUE->value;
|
||||
$query->published_at = time();
|
||||
$query->save();
|
||||
return $this->response->json(['code' => 0, 'msg' => 'ok']);
|
||||
}
|
||||
|
||||
#[RequestMapping(path:'update', methods: 'post')]
|
||||
public function update()
|
||||
{
|
||||
$model = new ModifyModel();
|
||||
$model->setAttributes($this->request->post());
|
||||
$model->update();
|
||||
return $this->response->json(['code' => 0, 'msg' => 'ok']);
|
||||
}
|
||||
}
|
@ -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'],
|
||||
|
@ -25,6 +25,7 @@ class NewsController extends AbstractController
|
||||
public function index(): array
|
||||
{
|
||||
$createdFilter = $this->request->query('created_at', [date('Y-m-d', strtotime('-1 month')), date('Y-m-d', time())]);
|
||||
$title = $this->request->input('title', '');
|
||||
foreach ($createdFilter as $index => &$item) {
|
||||
if ($index == 0) {
|
||||
$item = strtotime($item . ' 00:00:00');
|
||||
@ -37,7 +38,9 @@ class NewsController extends AbstractController
|
||||
|
||||
$ids = [];
|
||||
$query = AppNews::query()
|
||||
->where('is_delete', 0)
|
||||
->select(['id'])
|
||||
->when($title, fn($q) => $q->where('title', 'like', "%{$title}%"))
|
||||
->whereBetween('created_at', $createdFilter)
|
||||
->orderBy('id', 'desc');
|
||||
$pagination = $query->paginate($this->request->input('limit', 10), page: $this->request->input('page'));
|
||||
@ -88,4 +91,19 @@ class NewsController extends AbstractController
|
||||
$model->insert();
|
||||
return $this->response->json(['code' => 0, 'msg' => 'ok']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除新新闻接口
|
||||
* @url /admin/api/news/delete
|
||||
*/
|
||||
#[RequestMapping(path:'delete', methods: 'post')]
|
||||
public function delete(): \Psr\Http\Message\ResponseInterface
|
||||
{
|
||||
$id = $this->request->post('id');
|
||||
$query = AppNews::find($id);
|
||||
$query->is_delete = 1;
|
||||
$query->deleted_at = time();
|
||||
$query->save();
|
||||
return $this->response->json(['code' => 0, 'msg' => 'ok']);
|
||||
}
|
||||
}
|
@ -1,59 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller\admin\api;
|
||||
|
||||
use App\Controller\AbstractController;
|
||||
use App\Enums\SpiderArticlePublishedStatusEnum;
|
||||
use App\FormModel\spiderArticle\ReviewModel;
|
||||
use App\Model\AppSpiderArticle;
|
||||
use Hyperf\HttpServer\Annotation\Controller;
|
||||
use Hyperf\HttpServer\Annotation\RequestMapping;
|
||||
|
||||
|
||||
#[Controller(prefix: 'admin/api/spider-article')]
|
||||
class SpiderArticleController extends AbstractController
|
||||
{
|
||||
#[RequestMapping(path: '', methods: 'get')]
|
||||
public function index(): array
|
||||
{
|
||||
$createdFilter = $this->request->query('created_at', [date('Y-m-d', strtotime('-1 month')), date('Y-m-d', time())]);
|
||||
foreach ($createdFilter as $index => &$item) {
|
||||
if ($index == 0) {
|
||||
$item = strtotime($item . ' 00:00:00');
|
||||
}
|
||||
|
||||
if ($index == 1) {
|
||||
$item = strtotime($item . ' 23:59:59');
|
||||
}
|
||||
}
|
||||
$titleFilter = $this->request->query('title');
|
||||
$publishedStatus = $this->request->query('published_status', SpiderArticlePublishedStatusEnum::FALSE);
|
||||
$request = $this->request;
|
||||
$query = AppSpiderArticle::formatQuery(['created_at', 'module', 'published_status'])
|
||||
->select(['id', 'title', 'created_at', 'module', 'source_url', 'published_status'])
|
||||
->when($publishedStatus !== null, fn($q) => $q->where('published_status', $publishedStatus))
|
||||
->when($titleFilter, fn($q) => $q->where('title', 'like', "%{$titleFilter}%"))
|
||||
->when($this->request->query('module', '') !== '', fn($q) => $q->where('module', $this->request->query('module')))
|
||||
->whereBetween('created_at', $createdFilter)
|
||||
->orderBy('created_at', 'desc');
|
||||
$pagination = $query->paginate($request->input('limit', 10), page: $request->input('page'));
|
||||
|
||||
return ['code' => 0, 'msg' => 'ok', 'count' => $pagination->total(), 'data' => $pagination->items()];
|
||||
}
|
||||
|
||||
#[RequestMapping(path: 'view', methods: 'get')]
|
||||
public function view(): \Psr\Http\Message\ResponseInterface
|
||||
{
|
||||
$query = AppSpiderArticle::formatQuery(['images', 'module', 'brand'])->find($this->request->query('id'));
|
||||
|
||||
return $this->response->json(['code' => 0, 'msg' => 'ok', 'data' => $query->toArray()]);
|
||||
}
|
||||
|
||||
#[RequestMapping(path: 'pre-publish', methods: 'post')]
|
||||
public function prePublish(): \Psr\Http\Message\ResponseInterface
|
||||
{
|
||||
$prePublishModel = new ReviewModel();
|
||||
$prePublishModel->prePublish($this->request->post('id'));
|
||||
return $this->response->json(['code' => 0, 'msg' => 'ok']);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user