From b98e7bccd9de3b4d604c2492346e07786c9e68f1 Mon Sep 17 00:00:00 2001 From: vguanyiwgd Date: Tue, 9 Apr 2024 15:28:02 +0800 Subject: [PATCH] update Change-Id: I0902bd13d2f03b5da9ea78692aefe7765d7285c4 --- .../api/controllers/api/Dishes.php | 116 ++++++++++-------- 1 file changed, 62 insertions(+), 54 deletions(-) diff --git a/backstage/application/api/controllers/api/Dishes.php b/backstage/application/api/controllers/api/Dishes.php index 4fa859f..c50a819 100644 --- a/backstage/application/api/controllers/api/Dishes.php +++ b/backstage/application/api/controllers/api/Dishes.php @@ -758,23 +758,22 @@ class Dishes extends REST_Controller // 当前展示的日期 $currentDateInfo = ''; foreach($list as $item) { - if(!empty($date_get)){ - if($date_get == $item['dc_date']){ - $currentDateInfo = $item['dc_date']; - } - }else{ - $currentDateInfo = $list[0]['dc_date']; - } +// if(!empty($date_get)){ +// if($date_get == $item['dc_date']){ +// $currentDateInfo = $item['dc_date']; +// } +// }else{ +// $currentDateInfo = $list[0]['dc_date']; +// } $date_list[$item['dc_date']][] = $item; } + $date_key = array_keys($date_list); // 就是cp的id, 改为日期(当前日期) - if(empty($date_get)){ - $date_key = array_keys($date_list); - $date_get = $date_key ? $date_key[0] : ''; - } +// if(empty($date_get)){ +// $date_get = $date_key ? $date_key[0] : ''; +// } - $data['date'] = $date_get; if(!$dishes_typesInfo[$dining_hall_id]) $dishes_typesInfo[$dining_hall_id] = $this->Dishes_model->get_dishes_type($this->user->type_id, 1, $this->user->area_id, $dining_hall_id); $dishes_types = $dishes_typesInfo[$dining_hall_id]; @@ -794,13 +793,14 @@ class Dishes extends REST_Controller //print_r($userCartList);exit; // 遍历左侧日期cp - foreach ($date_list as $dc_date => $dateInfo){ - if($date_get != $dc_date){ + foreach ($date_list as $dc_date => $dateInfo) { + if (!empty($date_get) && $date_get != $dc_date) { + foreach ($dateInfo as $dateInfo_k => $dateInfo_v) { $date_id = $dateInfo_v['id']; $dishes_type_num = 0; - foreach($userCartList as $cItem) { - if($cItem['dining_hall_id'] == $dining_hall_id && $cItem['date_id'] == $date_id) { + foreach ($userCartList as $cItem) { + if ($cItem['dining_hall_id'] == $dining_hall_id && $cItem['date_id'] == $date_id) { $dishes_type_num += $cItem['num']; } } @@ -813,56 +813,64 @@ class Dishes extends REST_Controller ); continue; } - $dining_hall_ids = array_column($dining_halls, 'id'); - $key = array_search($dining_hall_id, $dining_hall_ids); - $dining_hall_info = array(); - if($key !== false){ - $dining_hall_info = (array)$dining_halls[$key]; + } + + $dining_hall_ids = array_column($dining_halls, 'id'); + $key = array_search($dining_hall_id, $dining_hall_ids); + $dining_hall_info = array(); + if($key !== false){ + $dining_hall_info = (array)$dining_halls[$key]; + } + + // 获取当前日期的dc_type有什么菜式 ------------------- + $t_meal_dates = $this->get_meal_dates($type, $dining_hall_id, $max_book_date); + $date_dish_list = $this->get_book_date($t_meal_dates); + + $meal_list = array(); + +// $date = strtotime($dc_date); +// $month = date('n', $date); +// $day = date('j', $date); +// $date_text = $month . '月' . $day . '日' . '(周' . cnWeek($date) . ')'; + foreach ($date_dish_list as $book_k => $book_v) { + $date_id = $book_v['id']; + +// if($book_v['dc_date'] == $dc_date){ + // 获取当天 + $dishes = $this->Dishes_model->get_dishes_by_type_id($date_id, '', $dining_hall_id, $this->user->type_id); + if(!empty($dishes) && empty($date_get)){ + $date_get = $book_v['dc_date']; + } + if(empty($dishes)){ + continue; } + $dishes = $this->sort_dishes($dishes, '' , $dining_hall_id, $date_id, 0); - // 获取当前日期的dc_type有什么菜式 ------------------- - $t_meal_dates = $this->get_meal_dates($type, $dining_hall_id, $max_book_date); - $date_dish_list = $this->get_book_date($t_meal_dates); + $explode = explode(')', $book_v['jcname']); + $meal_list[$explode[1]]['cs'] = $dishes; +// $date_dish_list[$book_k]['jcname'] = str_replace($date_text, '', $book_v['jcname']); - $meal_list = array(); + $dishes_type_num = 0; + foreach($userCartList as $cItem) { - $date = strtotime($dc_date); - $month = date('n', $date); - $day = date('j', $date); - $date_text = $month . '月' . $day . '日' . '(周' . cnWeek($date) . ')'; - foreach ($date_dish_list as $book_k => $book_v) { - $date_id = $book_v['id']; - - if($book_v['dc_date'] == $dc_date){ - // 获取当天 - $dishes = $this->Dishes_model->get_dishes_by_type_id($date_id, '', $dining_hall_id, $this->user->type_id); - - $dishes = $this->sort_dishes($dishes, '' , $dining_hall_id, $date_id, 0); - - $explode = explode(')', $book_v['jcname']); - $meal_list[$explode[1]]['cs'] = $dishes; - $date_dish_list[$book_k]['jcname'] = str_replace($date_text, '', $book_v['jcname']); - - $dishes_type_num = 0; - foreach($userCartList as $cItem) { - - if($cItem['dining_hall_id'] == $dining_hall_id && $cItem['date_id'] == $date_id) { - $dishes_type_num += $cItem['num']; - } - } - $cart_arr[$book_v['dc_date']] += $dishes_type_num; + if($cItem['dining_hall_id'] == $dining_hall_id && $cItem['date_id'] == $date_id) { + $dishes_type_num += $cItem['num']; } } - + $cart_arr[$book_v['dc_date']] += $dishes_type_num; +// } if(!empty($meal_list)){ - $jcmeal[$dc_date] = array( - 'cart_num' => $cart_arr[$dc_date], + $jcmeal[$book_v['dc_date']] = array( + 'cart_num' => $cart_arr[$book_v['dc_date']], 'meal_list' => $meal_list, - 'active' => $dc_date == $date_get ? 1 : 0 + 'active' => $book_v['dc_date'] == $date_get ? 1 : 0 ); } } + + $data['date'] = $date_get; + $data['jcdata'] = array( 'jcplace' => $dining_hall_info, 'jcdate' => $date_key,