fix - bug
This commit is contained in:
@ -3,10 +3,13 @@
|
||||
namespace App\Constants;
|
||||
|
||||
use Hyperf\Constants\AbstractConstants;
|
||||
use function Hyperf\Support\env;
|
||||
|
||||
#[Constants]
|
||||
class Config extends AbstractConstants
|
||||
{
|
||||
//以下为图片业务自定义常量
|
||||
public const DOMAIN = "https://seo.23cm.cn";
|
||||
public static function getDomain()
|
||||
{
|
||||
return env('APP_DOMAIN', '');
|
||||
}
|
||||
}
|
@ -100,7 +100,7 @@ class UploadController extends AbstractController
|
||||
'errno' => 0,
|
||||
'msg' => '上传成功!!',
|
||||
'data' => [
|
||||
'url' => Config::DOMAIN . $url,
|
||||
'url' => Config::getDomain() . $url,
|
||||
]
|
||||
]);
|
||||
}
|
||||
@ -152,7 +152,7 @@ class UploadController extends AbstractController
|
||||
'errno' => 0,
|
||||
'msg' => '上传成功~~',
|
||||
'data' => [
|
||||
'url' => Config::DOMAIN . $url,
|
||||
'url' => Config::getDomain() . $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
|
||||
{
|
||||
$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']);
|
||||
}
|
||||
}
|
@ -20,12 +20,16 @@ class ToolsController extends AbstractController
|
||||
#[RequestMapping(path:'get-query-keyword', methods:'get')]
|
||||
public function getQueryKeyword(): \Psr\Http\Message\ResponseInterface
|
||||
{
|
||||
$keyword = AppKeywordsMonitorTask::formatQuery(['created_at'])
|
||||
$keyword = AppKeywordsMonitorTask::query()
|
||||
->where('queried_at', '<=', strtotime('-2 hours'))
|
||||
->where('is_delete', 0);
|
||||
|
||||
if ($keyword) {
|
||||
$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([
|
||||
'code' => 0,
|
||||
'data' => $query
|
||||
|
@ -31,7 +31,7 @@ class ExcelHelper
|
||||
* @throws \PhpOffice\PhpSpreadsheet\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)) {
|
||||
return false;
|
||||
@ -53,27 +53,29 @@ class ExcelHelper
|
||||
|
||||
// 开始写入内容
|
||||
$column = 2;
|
||||
$size = ceil(count($list) / 500);
|
||||
for ($i = 0; $i < $size; $i++) {
|
||||
$buffer = array_slice($list, $i * 500, 500);
|
||||
foreach ($list as $sheetTitle => $sheetListItem) {
|
||||
$sheet->setTitle($sheetTitle);
|
||||
$size = ceil(count($sheetListItem) / 500);
|
||||
for ($i = 0; $i < $size; $i++) {
|
||||
$buffer = array_slice($sheetListItem, $i * 500, 500);
|
||||
|
||||
foreach ($buffer as $k => $row) {
|
||||
$span = 1;
|
||||
foreach ($buffer as $k => $row) {
|
||||
$span = 1;
|
||||
|
||||
foreach ($header as $key => $value) {
|
||||
// 解析字段
|
||||
$realData = self::formatting($header[$key], trim(self::formattingField($row, $value[1])), $row);
|
||||
// 写入excel
|
||||
$sheet->setCellValueExplicit(Coordinate::stringFromColumnIndex($span) . $column, $realData, DataType::TYPE_STRING);
|
||||
// $sheet->setCellValue(Coordinate::stringFromColumnIndex($span) . $column, $realData);
|
||||
$span++;
|
||||
foreach ($header as $key => $value) {
|
||||
// 解析字段
|
||||
$realData = self::formatting($header[$key], trim(self::formattingField($row, $value[1])), $row);
|
||||
// 写入excel
|
||||
$sheet->setCellValueExplicit(Coordinate::stringFromColumnIndex($span) . $column, $realData, DataType::TYPE_STRING);
|
||||
// $sheet->setCellValue(Coordinate::stringFromColumnIndex($span) . $column, $realData);
|
||||
$span++;
|
||||
}
|
||||
|
||||
$column++;
|
||||
unset($buffer[$k]);
|
||||
}
|
||||
|
||||
$column++;
|
||||
unset($buffer[$k]);
|
||||
}
|
||||
}
|
||||
|
||||
// 清除之前的错误输出
|
||||
// ob_end_clean();
|
||||
ob_start();
|
||||
|
@ -13,8 +13,9 @@ namespace App\Model;
|
||||
* @property \Carbon\Carbon $updated_at
|
||||
* @property int $deleted_at
|
||||
* @property int $is_delete
|
||||
* @property int $queried_at
|
||||
* @property int $platform
|
||||
* @property string $ignore_url
|
||||
* @property-read string $queried_at
|
||||
*/
|
||||
class AppKeywordsMonitor extends Model
|
||||
{
|
||||
@ -40,4 +41,11 @@ class AppKeywordsMonitor extends Model
|
||||
}
|
||||
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 $content
|
||||
* @property string $description
|
||||
* @property \Carbon\Carbon $created_at
|
||||
* @property int $created_by
|
||||
* @property \Carbon\Carbon $updated_at
|
||||
* @property int $updated_by
|
||||
@ -21,6 +20,8 @@ namespace App\Model;
|
||||
* @property int $platform
|
||||
* @property int $is_record
|
||||
* @property string $cover
|
||||
* @property int $is_delete
|
||||
* @property-read mixed $created_at
|
||||
*/
|
||||
class AppNews extends Model
|
||||
{
|
||||
@ -37,7 +38,7 @@ class AppNews extends Model
|
||||
/**
|
||||
* 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';
|
||||
|
||||
|
@ -17,9 +17,14 @@ class NewsService extends BaseService
|
||||
*/
|
||||
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'])
|
||||
->where('is_delete', 0)
|
||||
->select(['title', 'id'])
|
||||
->limit(10)
|
||||
->orderBy('id', 'desc')
|
||||
@ -27,9 +32,9 @@ class NewsService extends BaseService
|
||||
->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();
|
||||
}
|
||||
@ -41,9 +46,10 @@ class NewsService extends BaseService
|
||||
* @param int $page
|
||||
* @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'])
|
||||
->where('is_delete', 0)
|
||||
->select(['id'])
|
||||
->orderBy('id', 'desc');;
|
||||
$pagination = $query->paginate($limit, page: $page);
|
||||
|
Reference in New Issue
Block a user