-
Notifications
You must be signed in to change notification settings - Fork 0
/
endPlay.php
233 lines (210 loc) · 5.97 KB
/
endPlay.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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
<?php
require "_core.php";
if(!isset($_GET["i"], $_GET["j"], $_GET["id"])) {
header("Location: index.php");
// exit("error: no required params!");
exit();
}
// endPlay.php?i=11&j=3&id=2
// $clauses = [
// "planID"=>$_GET["id"],
// "planIndexID"=>$_GET["j"],
// ];
// $last_order = $db->selectRaw("SELECT * FROM ".$db->db.".`orders` WHERE `planID` = ".$_GET["id"]. " AND `planIndexID` = ".$_GET["j"]." AND `endTime` IS NULL ORDER BY `id` DESC");
$last_order = $db->selectRaw("SELECT * FROM ".$db->db.".`orders` WHERE `planID` = ".$_GET["id"]. " AND `planIndexID` = ".$_GET["j"]." AND `status` = 1 ORDER BY `id` DESC");
if($last_order == null || $last_order == []) {
header("Location: index.php");
// exit("Not found!");
exit();
}
else {
$play = $db->select("plays", ["id"=>$last_order["playID"]]);
if($play == null || $play == []) {
exit("error: cannot find this play!");
}
$playID = $play["id"];
}
// print_r($play);
// print "<hr>";
// print $playID."\n";
$sumPrice = 0;
$orders = $db->selects("orders", ["playID"=>$playID]);
// print_r($orders);
foreach($orders as $i=>$order) {
if($order["endTime"] == null || $order["endTime"] == "") {
$endTime = mytime();
// $db->update("orders", ["id"=>$order["id"]], ["endTime"=>$endTime]);
$orders[$i]["endTime"] = $endTime;
$orders[$i]["endTimeNow"] = true;
}
$timeDiff = $orders[$i]["endTime"] - $order["startTime"];
$timeMin = ceil($timeDiff / 60);
$price = $timeMin * $orders[$i]["planPrice"];
$sumPrice+= $price;
$orders[$i]["price"] = $price;
$orders[$i]["timeDiff"] = $timeDiff;
$orders[$i]["timeMin"] = $timeMin;
}
// print_r($play);
$foods = $db->selects("orders_food", ["playID"=>$play["id"]]);
?>
<title>سیستم گیم نت</title>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="style.css">
<a href="index.php">
برگشت به اتاق فرمان
</a>
<br>
<h3>
مشخصه مشتری/سیستم
</h3>
<br>
<?php
// print_r($orders);
?>
<?php foreach($orders as $order) { ?>
<table width="100%" dir="rtl" border="1">
<tr>
<td width="100">سیستم</td>
<td>
<?php
if($order["planID"] == 1) {
$order["planIDName"] = "معمولی";
$order["planIndexIDName"] = $order["planIndexID"];
}
else if($order["planID"] == 2) {
$order["planIDName"] = "آنلاین";
$order["planIndexIDName"] = 8 + $order["planIndexID"];
}
else if($order["planID"] == 3) {
$order["planIDName"] = "VIP";
$order["planIndexIDName"] = 11 + $order["planIndexID"];
}
?>
سیستم <?= $order["planIndexIDName"] ?> <?= $order["planIDName"]?> (<?= $order["planDaste"] ?> دسته)
<!-- <br> -->
<a style="text-decoration: none;float:left; width: auto;padding: 2px;border-radius: 4px;background-color: green;color: white;" href="deleteOrder.php?i=<?= $_GET["i"] ?>&j=<?= $_GET["j"] ?>&id=<?= $order["id"] ?>&playId=<?= $_GET["id"] ?>">حذف</a>
</td>
</tr>
<tr>
<td width="100">شروع</td>
<td><?= jdate('Y/m/d - H:i:s', $order["startTime"]) ?></td>
</tr>
<tr>
<td width="100">پایان</td>
<?php
// var_dump($order["endTime"]);
?>
<td>
<?= jdate('Y/m/d - H:i:s', $order["endTime"]) ?>
<?php
if(isset($order["endTimeNow"])) { ?>
(تا کنون)
<?php } ?>
</td>
</tr>
<tr>
<td width="100">زمان به دقیقه</td>
<td><?= $order["timeMin"] ?> دقیقه</td>
</tr>
<tr>
<td width="100">قیمت پلن</td>
<td><?= $order["planPrice"] ?> تومان</td>
</tr>
<tr>
<td width="100">قیمت</td>
<td><?= $order["price"] ?> تومان</td>
</tr>
</table>
<br>
<?php } ?>
<hr>
<?php
$sumFood = 0;
?>
<?php if(is_array($foods) and count($foods) > 0) { ?>
<table border="1" width="100%">
<tr>
<td>نام</td>
<td>تعداد</td>
<td>قیمت فی</td>
<td>قیمت</td>
</tr>
<?php foreach($foods as $food) { ?>
<?php
$_food = $db->select("foods", ["id"=>$food["foodID"]]);
// print_r($food);
// print_r($_food);
$food["count"] = (int) $food["count"];
$food["price"] = (int) $food["price"];
$food["priceAll"] = (int) ($food["count"] * $food["price"]);
$sumFood += $food["priceAll"];
?>
<tr>
<td><?= $_food["name"];?></td>
<td><?= $food["count"];?></td>
<td><?= number_format($food["price"]) ?></td>
<td>
<?= number_format($food["priceAll"]) ?>
<a style="text-decoration: none;float:left; width: auto;padding: 2px;border-radius: 4px;background-color: green;color: white;" href="deleteFoodInOrder.php?i=<?= $_GET["i"] ?>&j=<?= $_GET["j"] ?>&id=<?= $order["id"] ?>&playId=<?= $_GET["id"] ?>&k=<?= $food["id"] ?>">حذف</a>
</td>
</tr>
<?php } ?>
</table>
<?php } else { ?>
<center>
هیچ خریدی از بوفه انجام نشده است!
</center>
<?php } ?>
<br>
<b>
قیمت سیستم ها:
</b>
<?= number_format($sumPrice) ?> تومان
<br>
<b>
قیمت بوفه:
</b>
<?= number_format($sumFood) ?> تومان
<br>
<b>
قیمت سیستم و بوفه:
</b>
<?= number_format($sumPrice + $sumFood) ?> تومان
<br>
<b>
قیمت پیش پرداخت:
</b>
<?= number_format($play["prePayment"]) ?> تومان
<br>
<span style="background:yellow;padding:4px;">
<b>
قیمت نهایی:
</b>
<?= number_format($sumPrice + $sumFood - $play["prePayment"]) ?> تومان
</span>
<br>
<br>
<form action="" method="POST">
<button name="submit">تمام کردن سفارش و حذف</button>
</form>
<?php
if(isset($_POST["submit"])) {
// print_r($_POST);
foreach($orders as $i=>$order) {
$db->delete("orders", ["id"=>$order["id"]]);
}
$clauses = [
"id"=>$playID
];
$values = [
"pending"=>0,
"price"=>$sumPrice + $sumFood, //rand(500,80000),
];
$db->update("plays", $clauses, $values);
$db->delete("orders", ["playID"=>$play["id"]]);
$db->delete("orders_food", ["playID"=>$play["id"]]);
$db->delete("plays", ["id"=>$play["id"]]);
header("Location: index.php");
}
?>