fix - bug

This commit is contained in:
toom1996
2025-06-20 15:27:14 +08:00
parent b7fe1994f1
commit e25a4156c3
15 changed files with 112 additions and 286 deletions

View File

@ -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']);
}
}