Browse Source

订单列表订单状态

develop
李可松 4 years ago
parent
commit
c9e3562a9b
  1. 15
      app/Http/Controllers/Api/OrderController.php

15
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();

Loading…
Cancel
Save