first commit
This commit is contained in:
59
app/Controller/admin/api/SpiderArticleController.php
Executable file
59
app/Controller/admin/api/SpiderArticleController.php
Executable file
@ -0,0 +1,59 @@
|
||||
<?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