function srvc_book_reserve($guid, $guest_num, $visit_date, $visit_slot_in_mins, $small_board, $medium_board, $large_board, &$trade_token) { $rticket = new ReservationTicket($guid, $guest_num, $visit_date, $visit_slot_in_mins, $small_board, $medium_board, $large_board); $trade_token = $rticket->trade_token; if (!$rticket->is_valid()) { return BOOK_CODE_ERR_INVALID; } $err = impl_book_do_reserve($rticket, srvc_book_max_per_slot()); if (IS_BOOK_OK($err)) { $subject = "[Too塗预约单]"; $subject .= srvc_book_rticket_to_string($rticket); email_send_to_many(array(TOO_WX_MAIL_ADMIN_Y, TOO_WX_MAIL_ADMIN_W), $subject, json_encode($rticket->to_array()), notify_email(TOO_HOST_URL)); } return $err; }
function impl_book_query_schedule($prev_n, $next_n, &$result_arr) { $begin_day = time() - $prev_n * SEC_PER_DAY; for ($k = 0; $k < $prev_n + $next_n; $k++) { $cur = $begin_day + $k * SEC_PER_DAY; $subdir = date("Ymd", $cur); $dir = __impl_book_file_dir_4_name($subdir); if (!is_dir($dir)) { continue; } $dh = opendir($dir); if ($dh == false) { continue; } // all slots in one array $all_slots = array(); while (($fname = readdir($dh)) != false) { $fpath = $dir . "/" . $fname; // skip folders if (is_dir($fpath)) { continue; } // file-name without ext $minutes_slot = pathinfo($fpath, PATHINFO_FILENAME); $visit_clock = minutes_to_clock_str($minutes_slot); // read from file $json_str = file_get_contents($fpath); // decode and check $json = json_decode($json_str, true); if ($json == null || !is_array($json) || !array_key_exists(KEY_FILE_JSON_RTICKET_COUNT, $json) || !array_key_exists(KEY_FILE_JSON_RTICKET_LIST, $json)) { continue; } // total guest number $count_rtickets = $json[KEY_FILE_JSON_RTICKET_COUNT]; if ($count_rtickets <= 0) { continue; } // put all reservations of this slot in one array $slot_inf = array(); // go through each reservation $arr_rtickets = $json[KEY_FILE_JSON_RTICKET_LIST]; foreach ($arr_rtickets as $arr_rt) { $rticket = new ReservationTicket(null, 0, "", ""); if (!$rticket->from_array($arr_rt)) { continue; } $guid = $rticket->guid; $guid_str = $guid->to_string(); $guest_num = $rticket->num; $ttoken = $rticket->trade_token; $small_b = $rticket->small_board; $medium_b = $rticket->medium_board; $large_b = $rticket->large_board; // e.g. [N] ==> #2, PHONE_138xxxxxxxx $slot_inf[] = array("GUEST_NUM" => $guest_num, "GUID_STR" => $guid_str, "BOARD_S" => $small_b, "BOARD_M" => $medium_b, "BOARD_L" => $large_b, "T_TOKEN" => $ttoken); } // e.g. 15:30 ==> [ xxx ] $all_slots[] = array("CLOCK" => $visit_clock, "COUNT" => $count_rtickets, "VISITORs" => $slot_inf); } closedir($dh); // e.g. 20160210 ==> [ xxx ] $result_arr[] = array("DATE" => $subdir, "SLOTS" => $all_slots); } return BOOK_CODE_OK; }