/
srvc_book_abstract.php
145 lines (122 loc) · 3.7 KB
/
srvc_book_abstract.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
<?php
require_once "srvc_book_common.php";
require_once "srvc_book_file.php";
function srvc_book_max_per_slot()
{
return 10;
}
function srvc_book_rticket_to_string($rticket)
{
$str = " " . $rticket->guid->to_string();
$str .= "-" . "$rticket->num" . "人";
$str .= "-" .
"$rticket->large_board" . "大" .
"$rticket->medium_board" . "中" .
"$rticket->small_board" . "小";
$str .= "-" . $rticket->visit_date;
$str .= "-" . minutes_to_clock_str($rticket->visit_mins_slot);
return $str;
}
// lock one day
function srvc_book_block($vdate)
{
$err = impl_book_lock_date($vdate);
return $err;
}
function srvc_book_unblock($vdate)
{
$err = impl_book_unlock_date($vdate);
return $err;
}
function srvc_book_is_blocked($vdate)
{
$err = impl_book_date_is_locked($vdate);
return $err;
}
// lock one slot
function srvc_book_block_timeslot($vdate, $timeslot)
{
$err = impl_book_lock_timeslot($vdate, $timeslot);
return $err;
}
function srvc_book_unblock_timeslot($vdate, $timeslot)
{
$err = impl_book_unlock_timeslot($vdate, $timeslot);
return $err;
}
define("HOUR_BUFFER_4_BOOK_WEEKDAY", 2);
define("HOUR_BUFFER_4_BOOK_WEEKEND", 0);
function srvc_book_is_timeslot_blocked($vdate, $timeslot)
{
$cur_date = date("Ymd", time());
if ($cur_date - $vdate > 0)
{
// before today
return true;
}
else if ($cur_date == $vdate)
{
$dayOfWeek = date("N", time());
$hour_buffer = ($dayOfWeek == 6 || $dayOfWeek == 7) ? HOUR_BUFFER_4_BOOK_WEEKEND : HOUR_BUFFER_4_BOOK_WEEKDAY;
// only the hours after HOUR_BUFFER_4_BOOK is available
$bar_time = time() + SEC_PER_HOUR * $hour_buffer;
$bar_timeslot = date("H", $bar_time) * MIN_PER_HOUR + date("i", $bar_time);
if ($bar_timeslot - $timeslot > 0)
{
return true;
}
}
$err = impl_book_timeslot_is_locked($vdate, $timeslot);
return $err;
}
// query
function srvc_book_query_block($next_n_days, &$result_arr)
{
if ($next_n_days >= 0)
{
return impl_book_query_lock(1, $next_n_days, $result_arr);
}
return BOOK_CODE_ERR_INVALID;
}
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 srvc_book_query_schedule($next_n_days, &$result_arr)
{
if ($next_n_days >= 0)
{
return impl_book_query_schedule(1, $next_n_days, $result_arr);
}
return BOOK_CODE_ERR_INVALID;
}
?>