-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuser-order.php
More file actions
270 lines (240 loc) · 10 KB
/
Copy pathuser-order.php
File metadata and controls
270 lines (240 loc) · 10 KB
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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
<?php
//require_once ("domain-pdo-connect.php");
require_once("pdo-connect.php");
if (isset($_GET["id"])):
$id = $_GET["id"]; //order id
$sqlOrder = "SELECT * FROM user_order WHERE id=?";//從訂單抓資料
$stmtOrder = $db_host->prepare($sqlOrder);
try {
$stmtOrder->execute([$id]);
$rowOrder = $stmtOrder->fetch(); //訂單資料
} catch (PDOException $e) {
echo "取得訂單資訊錯誤<br>";
echo $e->getMessage();
}
//status
$sqlStatusType = "SELECT * FROM order_status";
$stmtStatusType = $db_host->prepare($sqlStatusType);
try {
$stmtStatusType->execute();
$statusTypeRows = $stmtStatusType->fetchAll(PDO::FETCH_ASSOC);
$statusTypes = array_column($statusTypeRows, "name", "id");
} catch (PDOException $e) {
echo "預處理陳述式執行失敗! <br/>";
echo "Error: " . $e->getMessage() . "<br/>";
$db_host = NULL;
exit;
}
// 抓取 users 會員資料表
$id=$_GET["id"]; //user id
$sqlUser="SELECT * FROM users WHERE id=?";
$stmtUser=$db_host->prepare($sqlUser);
try{
$stmtUser->execute([$id]);
$rowUser=$stmtUser->fetch();//會員資料
}catch(PDOException $e){
echo $e->getMessage();
}
//抓取 user_order
$sqlOrderList = "SELECT * FROM user_order WHERE user_id=?";
$stmtOrderList = $db_host->prepare($sqlOrderList);
try {
$stmtOrderList->execute([$id]);
$rowOrderList = $stmtOrderList->fetchAll(PDO::FETCH_ASSOC);
$orderCount = $stmtOrderList->rowCount();
} catch (PDOException $e) {
echo $e->getMessage();
}
//選擇訂單總金額、產品名稱、產品價格、產品圖片從[order-detail]加入到[products]參考ON在order_detail.product_id = products.id
$sql = "SELECT order_detail.amount, products.name, products.price, products.img FROM order_detail
JOIN products ON order_detail.product_id = products.id
WHERE order_detail.order_id = ?";
$stmt = $db_host->prepare($sql);
try {
$stmt->execute([$id]);
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
// $rowOrder=$stmtOrder->fetch();
} catch (PDOException $e) {
echo "取得訂單細節錯誤<br>";
echo $e->getMessage();
}
//抓status的名稱
$sql = "SELECT order_status.name,order_status.id, user_order.status, user_order.id FROM user_order JOIN order_status ON user_order.status = order_status.id
WHERE user_order.id = ?";
$stmtOrderStatus = $db_host->prepare($sql);
try {
$stmtOrderStatus->execute([$id]);
$statusRow = $stmtOrderStatus->fetch(PDO::FETCH_ASSOC);
$statusRows = $stmtOrderStatus->fetchAll(PDO::FETCH_ASSOC);
// $rowOrder=$stmtOrder->fetch();
} catch (PDOException $e) {
echo "取得訂單細節錯誤<br>";
echo $e->getMessage();
}
//抓user_id的名稱
$sql = "SELECT user_order.user_id, user_order.id, users.name FROM user_order JOIN users ON user_order.user_id = users.id
WHERE user_order.id = ?";
$stmtOrderUser = $db_host->prepare($sql);
try {
$stmtOrderUser->execute([$id]);
$orderUserRow = $stmtOrderUser->fetch(PDO::FETCH_ASSOC);
// $rowOrder=$stmtOrder->fetch();
} catch (PDOException $e) {
echo "取得訂單細節錯誤<br>";
echo $e->getMessage();
}
endif;
//if結束
?>
<!doctype html>
<html lang="en">
<head>
<title><?= $rowUser["name"] ?> 訂單列表</title>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS v5.0.2 -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css"
integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<?php require_once("style.php") ?>
<style>
#showarea{
width: 100vw;
height: 100vh;
background: rgba(0, 0, 0, 0.678);
visibility:hidden;
position: absolute;
top:0;
left: 0;
z-index: 99999;
}
#showBox{
width: 300px;
max-height: 300px;
background:white;
border-radius: 10px;
padding: 20px;
display: flex;
flex-direction: column;
justify-content:end;
position: absolute;
top:50%;
left: 50%;
transform: translate(-50%, -50%);
}
.text{
font-weight: 600;
margin-bottom: 15px;
}
.closeBtn{
width: 60px;
height: 30px;
/*background:rgb(255, 217, 0);*/
/*color: white;*/
font-size: 14pt;
text-align: center;
line-height: 30px;
cursor: pointer;
transition: .4s;
}
</style>
</head>
<body>
<?php require_once("main-nav.php") ?>
<?php if (isset($_GET["id"])):?>
<div id="layoutSidenav_content">
<div class="container px-0">
<main class="main px-5">
<div class="container-fluid px-0">
<h1 class="mt-4"><?= $rowUser["name"] ?> 的訂單列表</h1>
<ol class="breadcrumb my-4 ">
<li class="breadcrumb-item"><a href="home.php">首頁</a></li>
<li class="breadcrumb-item"><a href="order-list.php">所有訂單</a></li>
<li class="breadcrumb-item active"><?= $rowUser["name"] ?>的訂單列表</li>
</ol>
</div>
<div class="card mb-4">
<div class="card-header">
<i class="fas fa-table me-1"></i>
<?= $rowUser["name"] ?> 的訂單列表
</div>
<div class="card-body">
<div class="py-2 d-flex justify-content-between">
<!-- <div>-->
<!-- 共 --><? //=$orderCount?><!-- 筆-->
<!-- </div>-->
<form action="user-order.php" method="get">
<div class="d-flex align-items-center">
<input type="hidden" name="id" value="<?= $id ?>">
<!-- 時間範圍-->
<!-- <input type="date" class="form-control me-2" name="start"-->
<!-- value="-->
<?php //if(isset($start))echo $start; ?><!--">-->
<!-- <div class="me-2">~</div>-->
<!-- <input type="date" class="form-control me-2" name="end"-->
<!-- value="--><?php //if(isset($end))echo $end; ?><!--">-->
<!-- 時間範圍end-->
<!-- 篩選-->
<!-- <button type="submit" class="btn btn-primary text-nowrap">篩選</button>-->
<!-- 篩選end-->
</div>
</form>
</div>
<table id="datatablesSimple" class="table table-bordered table-sm">
<thead>
<tr>
<th>編號</th>
<th>訂購時間</th>
<th>狀態</th>
</tr>
</thead>
<tbody>
<?php if ($orderCount > 0):
foreach ($rowOrderList as $value):
?>
<tr>
<td><a href="order-detail.php?id=<?= $value["id"] ?>"><b># <?= $value["id"] ?></b></a>
</td>
<td><?=$value["order_time"] ?></td>
<td title="狀態代碼: ( <?= $value["status"] ?> )"><?=$statusTypes[$value["status"]]?></td>
</tr>
<?php
endforeach;
else: ?>
<tr>
<td colspan="12">尚未有訂單</td>
</tr>
<?php endif; ?>
</tbody>
</table>
</div>
</div>
</div>
<?php require_once("JS.php") ?>
</div>
</div>
<?php else:?>
<!-- <script>alert("請選擇要查看的會員")</script>-->
<div id="showarea" style="visibility: visible">
<div id="showBox">
<div class="text">請先選擇會員,再檢視相關內容。</div>
<div onclick="openWindow()" class="btn-secondary rounded closeBtn" title="前往會員管理中心~">好的</div>
</div>
</div>
<div class="inline-block container text-center">
<img src="https://cdn.dribbble.com/users/6620596/screenshots/14792345/media/af61fa935b055891cb800a9e41ebb747.gif" height="300px" alt="">
<img src="https://i.pinimg.com/originals/f3/c6/35/f3c6352193fef0bfc80744b7e71fd693.gif" height="300px" alt="">
<img src="https://i.pinimg.com/originals/24/b4/64/24b4648fb7e2fadb24ee392f35d09a64.gif" height="300px" alt="">
<img src="https://c.tenor.com/TjoYVFvlODoAAAAC/typing-type.gif" height="300px" alt="">
<img src="https://c.tenor.com/0rd4t7lbGi8AAAAC/dog-working.gif" height="300px" alt="">
</div>
<script>
$("#showArea").attr("style","visibility:visible");
function openWindow() {
window.open("http://localhost/pj_maobook/user-list.php","_self");
}
</script>
<?php
endif; ?>
</body>
</html>