Browse Source

$order->info排序

master
李可松 4 years ago
parent
commit
77e5cf60a1
  1. 27
      app/Http/Controllers/Api/OrderController.php

27
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);
}

Loading…
Cancel
Save