From 77e5cf60a1dd114bc9be5c6854235d27484197a6 Mon Sep 17 00:00:00 2001 From: liapples Date: Wed, 29 Sep 2021 16:54:32 +0800 Subject: [PATCH] =?UTF-8?q?$order->info=E6=8E=92=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Controllers/Api/OrderController.php | 27 +++++++++++++++++--- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/app/Http/Controllers/Api/OrderController.php b/app/Http/Controllers/Api/OrderController.php index 85b5808..a5e0525 100644 --- a/app/Http/Controllers/Api/OrderController.php +++ b/app/Http/Controllers/Api/OrderController.php @@ -194,13 +194,14 @@ class OrderController extends Controller switch ($ap->product->type) { case 0: case 2: - case 3: - case 4: - case 5: if (empty($formData['departure_time']) || !strtotime($formData['departure_time'])) { return $this->error('请选择出发时间'); } - $order_info['出发时间'] = $formData['departure_time']; //出发时间 + //旅游线路->出发时间;景区->入园时间 + $key = [0 => '出发时间', 2 => '入园时间']; + if (isset($key[$ap->product->type])) { + $order_info[$key[$ap->product->type]] = $formData['departure_time']; + } break; case 1: if (empty($formData['check_in_time']) || !strtotime($formData['check_in_time'])) { @@ -575,6 +576,24 @@ class OrderController extends Controller ->where(['agent_id' => $this->agent_id, 'agent_product_id' => $order->agent_product_id,]) ->get(['tag']); + //info数组排序 + if (!empty($order->info) && is_array($order->info)) { + $info = $order->info; + uksort($info, function ($a1, $a2) use ($info) { + $sort = ['入住时间' => 1, '离店时间' => 2, '到店时间' => 3, '出发时间' => 4, '入园时间' => 4]; //这些字段排在最前 + if (isset($sort[$a1]) && !isset($sort[$a2])) { + return -1; + } else if (!isset($sort[$a1]) && isset($sort[$a2])) { + return 1; + } else if (isset($sort[$a1]) && isset($sort[$a2])) { + return $sort[$a1] > $sort[$a2] ? 1 : -1; + } else if (isset($info[$a1]['sort'], $info[$a2]['sort'])) { + return $info[$a1]['sort'] > $info[$a2]['sort'] ? 1 : -1; + } + return 0; + }); + $order->info = $info; + } return $this->success($order); }