Browse Source

去掉页码判断和ID判断

dev
李可松 4 years ago
parent
commit
dac6aecf5a
  1. 12
      app/Http/Controllers/Api/NoticeController.php
  2. 17
      app/Http/Controllers/Api/UserFavController.php

12
app/Http/Controllers/Api/NoticeController.php

@ -14,12 +14,7 @@ class NoticeController extends Controller
// 公告列表 // 公告列表
public function index() public function index()
{ {
$page = request()->input('page');
if ($page && !ctype_digit($page)) {
return $this->error('页码错误');
}
$list = Notice::where('agent_id', $this->agent_id)
$list = Notice::query()->where('agent_id', $this->agent_id)
->select(['title', 'updated_at']) ->select(['title', 'updated_at'])
->orderBy('id', 'DESC') ->orderBy('id', 'DESC')
->simplePaginate(15); ->simplePaginate(15);
@ -28,10 +23,7 @@ class NoticeController extends Controller
public function show() public function show()
{ {
$id = request()->input('id');
if (!$id || !ctype_digit($id)) {
return $this->error('无效的ID');
}
$id = (int)request()->input('id');
$data = Notice::where('agent_id', $this->agent_id)->find($id); $data = Notice::where('agent_id', $this->agent_id)->find($id);
if (!$data) { if (!$data) {

17
app/Http/Controllers/Api/UserFavController.php

@ -6,15 +6,15 @@ use App\Http\Controllers\Controller;
use App\Models\AgentProduct; use App\Models\AgentProduct;
use App\Models\UserFav; use App\Models\UserFav;
/**
* 用户收藏
* Class UserFavController
* @package App\Http\Controllers\Api
*/
class UserFavController extends Controller class UserFavController extends Controller
{ {
public function index() public function index()
{ {
$page = request()->input('page');
if ($page && !ctype_digit($page)) {
return $this->error('页码错误');
}
$list = UserFav::query()->with([ $list = UserFav::query()->with([
'agentProduct' => fn($query) => $query->select('id', 'price', 'original_price'), 'agentProduct' => fn($query) => $query->select('id', 'price', 'original_price'),
'product' => fn($query) => $query->select('id', 'title', 'pictures'), 'product' => fn($query) => $query->select('id', 'title', 'pictures'),
@ -28,12 +28,9 @@ class UserFavController extends Controller
public function create() public function create()
{ {
$id = request()->input('id');
if (!$id || !ctype_digit($id)) {
return $this->error('无效的ID');
}
$id = (int)request()->input('id');
$agent_product = AgentProduct::find($id);
$agent_product = AgentProduct::where('user_id', $this->user_id)->find($id);
if (!$agent_product) { if (!$agent_product) {
return $this->error('产品不存在或已被删除'); return $this->error('产品不存在或已被删除');
} }

Loading…
Cancel
Save