fix - bug
This commit is contained in:
@ -3,10 +3,13 @@
|
|||||||
namespace App\Constants;
|
namespace App\Constants;
|
||||||
|
|
||||||
use Hyperf\Constants\AbstractConstants;
|
use Hyperf\Constants\AbstractConstants;
|
||||||
|
use function Hyperf\Support\env;
|
||||||
|
|
||||||
#[Constants]
|
#[Constants]
|
||||||
class Config extends AbstractConstants
|
class Config extends AbstractConstants
|
||||||
{
|
{
|
||||||
//以下为图片业务自定义常量
|
public static function getDomain()
|
||||||
public const DOMAIN = "https://seo.23cm.cn";
|
{
|
||||||
|
return env('APP_DOMAIN', '');
|
||||||
|
}
|
||||||
}
|
}
|
@ -100,7 +100,7 @@ class UploadController extends AbstractController
|
|||||||
'errno' => 0,
|
'errno' => 0,
|
||||||
'msg' => '上传成功!!',
|
'msg' => '上传成功!!',
|
||||||
'data' => [
|
'data' => [
|
||||||
'url' => Config::DOMAIN . $url,
|
'url' => Config::getDomain() . $url,
|
||||||
]
|
]
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
@ -152,7 +152,7 @@ class UploadController extends AbstractController
|
|||||||
'errno' => 0,
|
'errno' => 0,
|
||||||
'msg' => '上传成功~~',
|
'msg' => '上传成功~~',
|
||||||
'data' => [
|
'data' => [
|
||||||
'url' => Config::DOMAIN . $url,
|
'url' => Config::getDomain() . $url,
|
||||||
'file_name' => $url
|
'file_name' => $url
|
||||||
]
|
]
|
||||||
]);
|
]);
|
||||||
|
@ -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
|
public function monitorInsert(): \Psr\Http\Message\ResponseInterface
|
||||||
{
|
{
|
||||||
$keyword = $this->request->post('keyword');
|
$keyword = $this->request->post('keyword');
|
||||||
|
$ignoreUrl = $this->request->post('ignore_url');
|
||||||
|
|
||||||
$query = AppKeywordsMonitor::query()->where([
|
$query = AppKeywordsMonitor::query()->where([
|
||||||
['keyword', $keyword],
|
['keyword', $keyword],
|
||||||
@ -59,7 +60,9 @@ class KeywordsController extends AbstractController
|
|||||||
$query = new AppKeywordsMonitor();
|
$query = new AppKeywordsMonitor();
|
||||||
|
|
||||||
$query->keyword = $keyword;
|
$query->keyword = $keyword;
|
||||||
|
$ignoreUrl = array_filter(array_unique(explode(PHP_EOL, $ignoreUrl)));
|
||||||
|
|
||||||
|
$query->ignore_url = json_encode($ignoreUrl);
|
||||||
$query->save();
|
$query->save();
|
||||||
|
|
||||||
foreach ($this->request->post('platform', []) as $platform) {
|
foreach ($this->request->post('platform', []) as $platform) {
|
||||||
@ -83,11 +86,14 @@ class KeywordsController extends AbstractController
|
|||||||
{
|
{
|
||||||
$id = $this->request->input('id');
|
$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) {
|
if (!$query) {
|
||||||
return $this->response->json(['code' => 400, 'msg' => 'id 有误']);
|
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'])
|
$query['platform'] = AppKeywordsMonitorTask::query()->select(['platform'])
|
||||||
->where([
|
->where([
|
||||||
['aid', $query['id']],
|
['aid', $query['id']],
|
||||||
@ -109,6 +115,7 @@ class KeywordsController extends AbstractController
|
|||||||
$id = $this->request->post('id');
|
$id = $this->request->post('id');
|
||||||
$keyword = $this->request->post('keyword');
|
$keyword = $this->request->post('keyword');
|
||||||
$platform = $this->request->post('platform', []);
|
$platform = $this->request->post('platform', []);
|
||||||
|
$ignoreUrl = $this->request->post('ignore_url');
|
||||||
|
|
||||||
$query = AppKeywordsMonitor::find($id);
|
$query = AppKeywordsMonitor::find($id);
|
||||||
if (!$query) {
|
if (!$query) {
|
||||||
@ -116,6 +123,9 @@ class KeywordsController extends AbstractController
|
|||||||
}
|
}
|
||||||
|
|
||||||
$query->keyword = $keyword;
|
$query->keyword = $keyword;
|
||||||
|
$ignoreUrl = array_filter(array_unique(explode(PHP_EOL, $ignoreUrl)));
|
||||||
|
|
||||||
|
$query->ignore_url = json_encode($ignoreUrl);
|
||||||
$query->save();
|
$query->save();
|
||||||
|
|
||||||
// 先全部删掉
|
// 先全部删掉
|
||||||
@ -163,20 +173,26 @@ class KeywordsController extends AbstractController
|
|||||||
/**
|
/**
|
||||||
* 导出关键词报表
|
* 导出关键词报表
|
||||||
* @url /admin/api/keywords/monitor/export-all
|
* @url /admin/api/keywords/monitor/export-all
|
||||||
* @return \Psr\Http\Message\ResponseInterface
|
|
||||||
*/
|
*/
|
||||||
#[RequestMapping(path: 'monitor/export-all', methods: 'get')]
|
#[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();
|
$res = AppKeywordsMonitorResult::query()->orderBy('aid', 'desc')->get()->toArray();
|
||||||
|
|
||||||
foreach ($res as &$v) {
|
foreach ($res as &$v) {
|
||||||
$v['keyword'] = AppKeywordsMonitorTask::find($v['aid'])->keyword;
|
$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') . '关键词监控结果';
|
$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'],
|
['关键词', 'keyword', 'text'],
|
||||||
['标题', 'title', 'text'],
|
['标题', 'title', 'text'],
|
||||||
['排名', 'order', 'text'],
|
['排名', 'order', 'text'],
|
||||||
|
@ -25,6 +25,7 @@ class NewsController extends AbstractController
|
|||||||
public function index(): array
|
public function index(): array
|
||||||
{
|
{
|
||||||
$createdFilter = $this->request->query('created_at', [date('Y-m-d', strtotime('-1 month')), date('Y-m-d', time())]);
|
$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) {
|
foreach ($createdFilter as $index => &$item) {
|
||||||
if ($index == 0) {
|
if ($index == 0) {
|
||||||
$item = strtotime($item . ' 00:00:00');
|
$item = strtotime($item . ' 00:00:00');
|
||||||
@ -37,7 +38,9 @@ class NewsController extends AbstractController
|
|||||||
|
|
||||||
$ids = [];
|
$ids = [];
|
||||||
$query = AppNews::query()
|
$query = AppNews::query()
|
||||||
|
->where('is_delete', 0)
|
||||||
->select(['id'])
|
->select(['id'])
|
||||||
|
->when($title, fn($q) => $q->where('title', 'like', "%{$title}%"))
|
||||||
->whereBetween('created_at', $createdFilter)
|
->whereBetween('created_at', $createdFilter)
|
||||||
->orderBy('id', 'desc');
|
->orderBy('id', 'desc');
|
||||||
$pagination = $query->paginate($this->request->input('limit', 10), page: $this->request->input('page'));
|
$pagination = $query->paginate($this->request->input('limit', 10), page: $this->request->input('page'));
|
||||||
@ -88,4 +91,19 @@ class NewsController extends AbstractController
|
|||||||
$model->insert();
|
$model->insert();
|
||||||
return $this->response->json(['code' => 0, 'msg' => 'ok']);
|
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']);
|
|
||||||
}
|
|
||||||
}
|
|
@ -20,12 +20,16 @@ class ToolsController extends AbstractController
|
|||||||
#[RequestMapping(path:'get-query-keyword', methods:'get')]
|
#[RequestMapping(path:'get-query-keyword', methods:'get')]
|
||||||
public function getQueryKeyword(): \Psr\Http\Message\ResponseInterface
|
public function getQueryKeyword(): \Psr\Http\Message\ResponseInterface
|
||||||
{
|
{
|
||||||
$keyword = AppKeywordsMonitorTask::formatQuery(['created_at'])
|
$keyword = AppKeywordsMonitorTask::query()
|
||||||
->where('queried_at', '<=', strtotime('-2 hours'))
|
->where('queried_at', '<=', strtotime('-2 hours'))
|
||||||
->where('is_delete', 0);
|
->where('is_delete', 0);
|
||||||
|
|
||||||
if ($keyword) {
|
if ($keyword) {
|
||||||
$query = $keyword->first()?->toArray();
|
$query = $keyword->first()?->toArray();
|
||||||
|
if ($query) {
|
||||||
|
$ignoreUrl = AppKeywordsMonitor::formatQuery([])->where('id', $query['aid'])->first()?->toArray()['ignore_url'] ?? [];
|
||||||
|
$query['ignore_url'] = $ignoreUrl;
|
||||||
|
}
|
||||||
return $this->response->json([
|
return $this->response->json([
|
||||||
'code' => 0,
|
'code' => 0,
|
||||||
'data' => $query
|
'data' => $query
|
||||||
|
@ -31,7 +31,7 @@ class ExcelHelper
|
|||||||
* @throws \PhpOffice\PhpSpreadsheet\Exception
|
* @throws \PhpOffice\PhpSpreadsheet\Exception
|
||||||
* @throws \PhpOffice\PhpSpreadsheet\Writer\Exception
|
* @throws \PhpOffice\PhpSpreadsheet\Writer\Exception
|
||||||
*/
|
*/
|
||||||
public static function exportData(ResponseInterface $response, $list = [], $header = [], $filename = '', $suffix = 'xlsx', $path = '')
|
public static function exportData(ResponseInterface $response, array $list = [], $header = [], $filename = '', $suffix = 'xlsx', $path = '')
|
||||||
{
|
{
|
||||||
if (!is_array($list) || !is_array($header)) {
|
if (!is_array($list) || !is_array($header)) {
|
||||||
return false;
|
return false;
|
||||||
@ -53,27 +53,29 @@ class ExcelHelper
|
|||||||
|
|
||||||
// 开始写入内容
|
// 开始写入内容
|
||||||
$column = 2;
|
$column = 2;
|
||||||
$size = ceil(count($list) / 500);
|
foreach ($list as $sheetTitle => $sheetListItem) {
|
||||||
for ($i = 0; $i < $size; $i++) {
|
$sheet->setTitle($sheetTitle);
|
||||||
$buffer = array_slice($list, $i * 500, 500);
|
$size = ceil(count($sheetListItem) / 500);
|
||||||
|
for ($i = 0; $i < $size; $i++) {
|
||||||
|
$buffer = array_slice($sheetListItem, $i * 500, 500);
|
||||||
|
|
||||||
foreach ($buffer as $k => $row) {
|
foreach ($buffer as $k => $row) {
|
||||||
$span = 1;
|
$span = 1;
|
||||||
|
|
||||||
foreach ($header as $key => $value) {
|
foreach ($header as $key => $value) {
|
||||||
// 解析字段
|
// 解析字段
|
||||||
$realData = self::formatting($header[$key], trim(self::formattingField($row, $value[1])), $row);
|
$realData = self::formatting($header[$key], trim(self::formattingField($row, $value[1])), $row);
|
||||||
// 写入excel
|
// 写入excel
|
||||||
$sheet->setCellValueExplicit(Coordinate::stringFromColumnIndex($span) . $column, $realData, DataType::TYPE_STRING);
|
$sheet->setCellValueExplicit(Coordinate::stringFromColumnIndex($span) . $column, $realData, DataType::TYPE_STRING);
|
||||||
// $sheet->setCellValue(Coordinate::stringFromColumnIndex($span) . $column, $realData);
|
// $sheet->setCellValue(Coordinate::stringFromColumnIndex($span) . $column, $realData);
|
||||||
$span++;
|
$span++;
|
||||||
|
}
|
||||||
|
|
||||||
|
$column++;
|
||||||
|
unset($buffer[$k]);
|
||||||
}
|
}
|
||||||
|
|
||||||
$column++;
|
|
||||||
unset($buffer[$k]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 清除之前的错误输出
|
// 清除之前的错误输出
|
||||||
// ob_end_clean();
|
// ob_end_clean();
|
||||||
ob_start();
|
ob_start();
|
||||||
|
@ -13,8 +13,9 @@ namespace App\Model;
|
|||||||
* @property \Carbon\Carbon $updated_at
|
* @property \Carbon\Carbon $updated_at
|
||||||
* @property int $deleted_at
|
* @property int $deleted_at
|
||||||
* @property int $is_delete
|
* @property int $is_delete
|
||||||
* @property int $queried_at
|
|
||||||
* @property int $platform
|
* @property int $platform
|
||||||
|
* @property string $ignore_url
|
||||||
|
* @property-read string $queried_at
|
||||||
*/
|
*/
|
||||||
class AppKeywordsMonitor extends Model
|
class AppKeywordsMonitor extends Model
|
||||||
{
|
{
|
||||||
@ -40,4 +41,11 @@ class AppKeywordsMonitor extends Model
|
|||||||
}
|
}
|
||||||
return date('Y-m-d H:i:s', intval($value)) ?: '未查询';
|
return date('Y-m-d H:i:s', intval($value)) ?: '未查询';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getIgnoreUrlAttribute($value)
|
||||||
|
{
|
||||||
|
return $this->format('ignore_url', function (bool $isFormat) use ($value) {
|
||||||
|
return $isFormat ? (($value && is_string($value)) ? json_decode($value, true) : []) : $value;
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,6 @@ namespace App\Model;
|
|||||||
* @property string $keywords
|
* @property string $keywords
|
||||||
* @property string $content
|
* @property string $content
|
||||||
* @property string $description
|
* @property string $description
|
||||||
* @property \Carbon\Carbon $created_at
|
|
||||||
* @property int $created_by
|
* @property int $created_by
|
||||||
* @property \Carbon\Carbon $updated_at
|
* @property \Carbon\Carbon $updated_at
|
||||||
* @property int $updated_by
|
* @property int $updated_by
|
||||||
@ -21,6 +20,8 @@ namespace App\Model;
|
|||||||
* @property int $platform
|
* @property int $platform
|
||||||
* @property int $is_record
|
* @property int $is_record
|
||||||
* @property string $cover
|
* @property string $cover
|
||||||
|
* @property int $is_delete
|
||||||
|
* @property-read mixed $created_at
|
||||||
*/
|
*/
|
||||||
class AppNews extends Model
|
class AppNews extends Model
|
||||||
{
|
{
|
||||||
@ -37,7 +38,7 @@ class AppNews extends Model
|
|||||||
/**
|
/**
|
||||||
* The attributes that should be cast to native types.
|
* The attributes that should be cast to native types.
|
||||||
*/
|
*/
|
||||||
protected array $casts = ['id' => 'integer', 'created_at' => 'datetime', 'created_by' => 'integer', 'updated_at' => 'datetime', 'updated_by' => 'integer', 'deleted_at' => 'integer', 'deleted_by' => 'integer', 'platform' => 'integer', 'is_record' => 'integer'];
|
protected array $casts = ['id' => 'integer', 'created_at' => 'datetime', 'created_by' => 'integer', 'updated_at' => 'datetime', 'updated_by' => 'integer', 'deleted_at' => 'integer', 'deleted_by' => 'integer', 'platform' => 'integer', 'is_record' => 'integer', 'is_delete' => 'integer'];
|
||||||
|
|
||||||
protected ?string $dateFormat = 'U';
|
protected ?string $dateFormat = 'U';
|
||||||
|
|
||||||
|
@ -17,9 +17,14 @@ class NewsService extends BaseService
|
|||||||
*/
|
*/
|
||||||
public function view($id): array
|
public function view($id): array
|
||||||
{
|
{
|
||||||
$query = AppNews::find($id)->toArray();
|
$query = AppNews::query()->where('id', $id)->where('is_delete', 0)->first()?->toArray();
|
||||||
|
|
||||||
|
if (!$query) {
|
||||||
|
return $this->getResponse()->setCode(404)->send();
|
||||||
|
}
|
||||||
// 相关文章
|
// 相关文章
|
||||||
$query['about'] = AppNews::formatQuery(['created_at'])
|
$query['about'] = AppNews::formatQuery(['created_at'])
|
||||||
|
->where('is_delete', 0)
|
||||||
->select(['title', 'id'])
|
->select(['title', 'id'])
|
||||||
->limit(10)
|
->limit(10)
|
||||||
->orderBy('id', 'desc')
|
->orderBy('id', 'desc')
|
||||||
@ -27,9 +32,9 @@ class NewsService extends BaseService
|
|||||||
->toArray();
|
->toArray();
|
||||||
|
|
||||||
// 上一篇文章
|
// 上一篇文章
|
||||||
$query['prevNews'] = AppNews::find($id - 1, ['title', 'id'])?->toArray();
|
$query['prevNews'] = AppNews::query()->where('id', '<', $id)->select(['title', 'id'])->where('is_delete', 0)->orderBy('id', 'desc')->first();
|
||||||
// 下一篇文章
|
// 下一篇文章
|
||||||
$query['nextNews'] = AppNews::find($id + 1, ['title', 'id'])?->toArray();
|
$query['nextNews'] = AppNews::query()->where('id', '>', $id)->select(['title', 'id'])->where('is_delete', 0)->first();
|
||||||
|
|
||||||
return $this->getResponse()->setData($query)->setCode(0)->send();
|
return $this->getResponse()->setData($query)->setCode(0)->send();
|
||||||
}
|
}
|
||||||
@ -41,9 +46,10 @@ class NewsService extends BaseService
|
|||||||
* @param int $page
|
* @param int $page
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function index(int $limit = 10, int $page = 1): array
|
public function index(int $limit = 30, int $page = 1): array
|
||||||
{
|
{
|
||||||
$query = AppNews::formatQuery(['created_at'])
|
$query = AppNews::formatQuery(['created_at'])
|
||||||
|
->where('is_delete', 0)
|
||||||
->select(['id'])
|
->select(['id'])
|
||||||
->orderBy('id', 'desc');;
|
->orderBy('id', 'desc');;
|
||||||
$pagination = $query->paginate($limit, page: $page);
|
$pagination = $query->paginate($limit, page: $page);
|
||||||
|
@ -14,9 +14,9 @@ use function Hyperf\Support\env;
|
|||||||
return [
|
return [
|
||||||
'default' => [
|
'default' => [
|
||||||
'driver' => env('DB_DRIVER', 'mysql'),
|
'driver' => env('DB_DRIVER', 'mysql'),
|
||||||
'host' => env('DB_HOST', '192.168.23.15'),
|
'host' => env('DB_HOST', '127.0.0.1'),
|
||||||
'port' => env('DB_PORT', 3306),
|
'port' => env('DB_PORT', 3306),
|
||||||
'database' => env('DB_DATABASE', 'seo'),
|
'database' => env('DB_DATABASE', 'database'),
|
||||||
'username' => env('DB_USERNAME', 'root'),
|
'username' => env('DB_USERNAME', 'root'),
|
||||||
'password' => env('DB_PASSWORD', 'root'),
|
'password' => env('DB_PASSWORD', 'root'),
|
||||||
'charset' => env('DB_CHARSET', 'utf8mb4'),
|
'charset' => env('DB_CHARSET', 'utf8mb4'),
|
||||||
|
@ -60,7 +60,7 @@ return [
|
|||||||
Constant::OPTION_BUFFER_OUTPUT_SIZE => 2 * 1024 * 1024,
|
Constant::OPTION_BUFFER_OUTPUT_SIZE => 2 * 1024 * 1024,
|
||||||
Constant::OPTION_UPLOAD_MAX_FILESIZE => 10 * 1024 * 1024, // 最大上传限制
|
Constant::OPTION_UPLOAD_MAX_FILESIZE => 10 * 1024 * 1024, // 最大上传限制
|
||||||
// 静态资源
|
// 静态资源
|
||||||
'document_root' => BASE_PATH . '/public',
|
'document_root' => BASE_PATH,
|
||||||
'enable_static_handler' => true,
|
'enable_static_handler' => true,
|
||||||
],
|
],
|
||||||
'callbacks' => [
|
'callbacks' => [
|
||||||
|
@ -25,7 +25,12 @@
|
|||||||
{{-- <input type="checkbox" name="arr[2]" title="选项3">--}}
|
{{-- <input type="checkbox" name="arr[2]" title="选项3">--}}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="layui-form-item">
|
||||||
|
<label class="layui-form-label">排除的链接(我们自己做的)</label>
|
||||||
|
<div class="layui-input-block">
|
||||||
|
<textarea name="ignore_url" required lay-verify="required" placeholder="请输入" class="layui-textarea"></textarea>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<div class="layui-form-item">
|
<div class="layui-form-item">
|
||||||
<div class="button-container">
|
<div class="button-container">
|
||||||
<button type="submit" class="pear-btn pear-btn-primary pear-btn-md" lay-submit="" lay-filter="save">
|
<button type="submit" class="pear-btn pear-btn-primary pear-btn-md" lay-submit="" lay-filter="save">
|
||||||
|
@ -1,19 +1,3 @@
|
|||||||
<?php
|
|
||||||
$articleModule = array_map(fn($case) => [
|
|
||||||
'label' => ucfirst($case->toString()),
|
|
||||||
'value' => $case->value,
|
|
||||||
], \App\Enums\ArticleModuleEnum::cases());
|
|
||||||
|
|
||||||
$articlePublishedStatus = array_map(fn($case) => [
|
|
||||||
'label' => ucfirst($case->toString()),
|
|
||||||
'value' => $case->value,
|
|
||||||
], \App\Enums\ArticlePublishedStatusEnum::cases());
|
|
||||||
|
|
||||||
$articleLocation = array_map(fn($case) => [
|
|
||||||
'label' => ucfirst($case->toString()),
|
|
||||||
'value' => $case->value,
|
|
||||||
], \App\Enums\LocationEnum::cases());
|
|
||||||
?>
|
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="zh-cn">
|
<html lang="zh-cn">
|
||||||
<head>
|
<head>
|
||||||
@ -32,7 +16,7 @@ $articleLocation = array_map(fn($case) => [
|
|||||||
<div class="layui-form-item">
|
<div class="layui-form-item">
|
||||||
<label class="layui-form-label">文章标题</label>
|
<label class="layui-form-label">文章标题</label>
|
||||||
<div class="layui-input-block">
|
<div class="layui-input-block">
|
||||||
<input type="text" name="mobile" value="" class="layui-input">
|
<input type="text" name="title" value="" class="layui-input">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -98,8 +82,6 @@ $articleLocation = array_map(fn($case) => [
|
|||||||
|
|
||||||
// 相关常量
|
// 相关常量
|
||||||
const PRIMARY_KEY = "id";
|
const PRIMARY_KEY = "id";
|
||||||
const UPDATE_API = "/admin/update";
|
|
||||||
const DELETE_API = "/admin/delete";
|
|
||||||
|
|
||||||
// ----------------------
|
// ----------------------
|
||||||
const UPDATE_URL = "/articles/update";
|
const UPDATE_URL = "/articles/update";
|
||||||
@ -115,6 +97,7 @@ $articleLocation = array_map(fn($case) => [
|
|||||||
const VIEW_API = "/admin/news/view";
|
const VIEW_API = "/admin/news/view";
|
||||||
const INSERT_API = "/admin/api/news/insert";
|
const INSERT_API = "/admin/api/news/insert";
|
||||||
const INSERT_URL = "/admin/news/insert";
|
const INSERT_URL = "/admin/news/insert";
|
||||||
|
const DELETE_API = "/admin/api/news/delete";
|
||||||
|
|
||||||
// 字段 创建时间 created_at
|
// 字段 创建时间 created_at
|
||||||
layui.use(["laydate"], function () {
|
layui.use(["laydate"], function () {
|
||||||
@ -198,41 +181,7 @@ $articleLocation = array_map(fn($case) => [
|
|||||||
edit(obj);
|
edit(obj);
|
||||||
}
|
}
|
||||||
if (obj.event === "delete") {
|
if (obj.event === "delete") {
|
||||||
alert('未生效');
|
deleteNews(obj);
|
||||||
} else if (obj.event === "publish") {
|
|
||||||
console.log(obj.data.aid)
|
|
||||||
layer.confirm('确定发布吗?', function (index) {
|
|
||||||
// obj.del(); // 删除对应行(tr)的 DOM 结构,并更新缓存
|
|
||||||
// layer.close(index);
|
|
||||||
let loading = layer.load();
|
|
||||||
$.ajax({
|
|
||||||
url: PUBLISH_API,
|
|
||||||
data: {
|
|
||||||
aid: obj.data.aid
|
|
||||||
},
|
|
||||||
dataType: "json",
|
|
||||||
type: "post",
|
|
||||||
success: (res) => {
|
|
||||||
layer.close(index);
|
|
||||||
if (res.code) {
|
|
||||||
return layui.popup.failure(res.msg);
|
|
||||||
}
|
|
||||||
return layui.popup.success("操作成功", refreshTable);
|
|
||||||
},
|
|
||||||
error: function () {
|
|
||||||
return layui.popup.failure("操作失败");
|
|
||||||
},
|
|
||||||
complete: function () {
|
|
||||||
layer.close(loading);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
// 向后端发送删除请求,执行完毕后,可通过 reloadData 方法完成数据重载
|
|
||||||
/*
|
|
||||||
table.reloadData(id, {
|
|
||||||
scrollPos: 'fixed' // 保持滚动条位置不变 - v2.7.3 新增
|
|
||||||
});
|
|
||||||
*/
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -300,36 +249,22 @@ $articleLocation = array_map(fn($case) => [
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// 删除一行
|
|
||||||
let remove = function (obj) {
|
|
||||||
return doRemove(obj.data[PRIMARY_KEY]);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 删除多行
|
|
||||||
let batchRemove = function (obj) {
|
|
||||||
let checkIds = common.checkField(obj, PRIMARY_KEY);
|
|
||||||
if (checkIds === "") {
|
|
||||||
layui.popup.warning("未选中数据");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
doRemove(checkIds.split(","));
|
|
||||||
}
|
|
||||||
|
|
||||||
// 执行删除
|
// 执行删除
|
||||||
let doRemove = function (ids) {
|
let deleteNews = function (obj) {
|
||||||
let data = {};
|
console.log(obj)
|
||||||
data[PRIMARY_KEY] = ids;
|
|
||||||
layer.confirm("确定删除?", {
|
layer.confirm("确定删除?", {
|
||||||
icon: 3,
|
icon: 3,
|
||||||
title: "提示"
|
title: "提示"
|
||||||
}, function (index) {
|
}, function (index) {
|
||||||
layer.close(index);
|
layer.close(index);
|
||||||
let loading = layer.load();
|
let loading = layer.load();
|
||||||
$.ajax({
|
layui.$.ajax({
|
||||||
url: DELETE_API,
|
url: DELETE_API,
|
||||||
data: data,
|
type: "POST",
|
||||||
dataType: "json",
|
dateType: "json",
|
||||||
type: "post",
|
data: {
|
||||||
|
id: obj.data.id
|
||||||
|
},
|
||||||
success: function (res) {
|
success: function (res) {
|
||||||
layer.close(loading);
|
layer.close(loading);
|
||||||
if (res.code) {
|
if (res.code) {
|
||||||
|
Reference in New Issue
Block a user