diff --git a/app/Http/Controllers/Api/OrderController.php b/app/Http/Controllers/Api/OrderController.php index e7065d4..fd84711 100644 --- a/app/Http/Controllers/Api/OrderController.php +++ b/app/Http/Controllers/Api/OrderController.php @@ -34,19 +34,22 @@ class OrderController extends Controller $formData = $request->only(['page', 'status']); $request->validate([ 'page' => 'regex:/^\d+$/', - 'status' => 'nullable|integer' + 'status' => 'nullable|regex:/^\d+(,\d+)*$/' ], [ 'page.regex' => '页码错误', - 'status.integer' => '订单状态错误' + 'status.regex' => '订单状态错误' ]); + $order_list = Order::where('user_id', $this->user_id); if (isset($formData['status'])) { - $where['status'] = $formData['status']; + if (preg_match('/^\d+$/', $formData['status'])) { + $order_list = $order_list->where('status', $formData['status']); + } else { + $order_list = $order_list->whereIn('status', explode(',', $formData['status'])); + } } - $where['user_id'] = $this->user_id; - $order_list = Order::where($where) - ->select('id', 'agent_product_id', 'product_id', 'title', 'picture', 'price', 'num', 'status', 'created_at') + $order_list = $order_list->select('id', 'agent_product_id', 'product_id', 'title', 'picture', 'price', 'num', 'status', 'created_at') ->orderBy('id', 'DESC') ->simplePaginate(15) ->toArray();