Skip to content

Commit 35522b6

Browse files
committed
fix rating
1 parent 60d06f8 commit 35522b6

File tree

3 files changed

+24
-10
lines changed

3 files changed

+24
-10
lines changed

Controller/Customer/Customer_c.php

+12-4
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,23 @@ public function Customer() {
3232
if (isset($_GET['ido'])) {
3333
$order_id = $_GET['ido'];
3434
$checkfb = $this->customer->checkFeedback($order_id);
35+
3536
}
3637
if (isset($_POST['submit'])) {
37-
$rate = $_POST['score'];
38-
$feedback = htmlspecialchars($_POST['feedback']);
38+
$ido = $_POST['order_id'];
3939
$user_id = $_POST['submit'];
4040
$customer_id = $_SESSION['id_cus'];
41+
$rate = $_POST['score'];
42+
$feedback = htmlspecialchars($_POST['feedback']);
43+
$check = $this->customer->checkFeedback($ido);
44+
45+
if (count($check) == 0) {
46+
$add = $this->customer->addFeedback($ido, $user_id, $customer_id, $rate, $feedback);
4147

42-
$add = $this->customer->addFeedback($user_id, $customer_id, $rate, $feedback);
43-
header("refresh: 0;");
48+
header("refresh: 0;");
49+
}else{
50+
echo "<script>alert('Quý khách chỉ có thể đánh giá 1 lần ở mỗi đơn hàng!')</script>";
51+
}
4452
}
4553
include_once 'View/profile.php';
4654
}

Model/Customer/Customer_m.php

+7-4
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,15 @@ protected function getCustomerOrderDetail($id) {
103103
return $result;
104104
}
105105

106-
protected function addFeedback($user_id, $customer_id, $rate, $feedback) {
106+
protected function addFeedback($order_id, $user_id, $customer_id, $rate, $feedback) {
107107

108-
$sql = "INSERT INTO tbl_feedback(user_id, customer_id, rate, feedback) VALUES
109-
(:user_id, :customer_id, :rate, :feedback)";
108+
$sql = "INSERT INTO tbl_feedback(order_id, user_id, customer_id, rate, feedback) VALUES
109+
(:order_id, :user_id, :customer_id, :rate, :feedback)";
110110

111111
$pre = $this->pdo->prepare($sql);
112112

113+
$pre->bindParam(':order_id', $order_id);
114+
113115
$pre->bindParam(':user_id', $user_id);
114116

115117
$pre->bindParam(':customer_id', $customer_id);
@@ -178,6 +180,7 @@ protected function getUserFeedback($id, $row) {
178180
$from = ($pages - 1) * $row;
179181

180182
$sql = "SELECT
183+
tbl_feedback.customer_id as 'idc',
181184
tbl_customer.name,
182185
tbl_customer.avatar,
183186
tbl_feedback.rate,
@@ -186,7 +189,7 @@ protected function getUserFeedback($id, $row) {
186189
FROM
187190
tbl_feedback, tbl_customer
188191
WHERE
189-
tbl_feedback.customer_id = tbl_customer.id and tbl_feedback.user_id = 2
192+
tbl_feedback.customer_id = tbl_customer.id and tbl_feedback.user_id = :id
190193
ORDER BY
191194
tbl_feedback.create_at DESC
192195
LIMIT

View/customer/rate.php

+5-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
$count = count($user_feedback); // Đếm số bản ghi trả ra
33
$sum_count = $count_feedback;
44
$pages = ceil($sum_count / 3);
5+
$ido = $_GET['ido'];
56
?>
67
<div class="col-md-9 col-9" style="background-color: #fff; padding-left: 30px;border-radius: 0.25rem; margin: 50px 0 0px 0;float: left;height: 100%">
78
<div class="title-info" style="border-bottom: 1px solid #efefef; width: 100%; height:80px;">
@@ -37,12 +38,14 @@
3738
</div>
3839

3940
<div class="rate text-center" style="width: 50%; float: left;height: 100%;">
41+
4042
<?php
4143
if (count($checkfb) == 0) {
4244
?>
4345
<form action="" method="POST">
4446
<div id="half" style="margin-bottom: 10px;"></div>
4547
<textarea rows="5" cols="50" name="feedback"></textarea>
48+
<input type="hidden" name="order_id" value="<?php if(isset($_GET['ido'])){echo $_GET['ido'];} ?>">
4649
<br>
4750
<button type="submit" name="submit" value="<?php if(isset($_GET['idu'])){echo $_GET['idu'];} ?>" class="btn waves-effect waves-light btn-warning" style='float: right;margin-top: 10px; margin-right: 50px;'>Gửi</button>
4851
</form>
@@ -67,7 +70,7 @@
6770
<?php
6871
}else{
6972
?>
70-
<img src="assets/images/customer/<?php echo $nameFolder ?>/<?php echo $value['avatar'] ?> ?>" alt="user-image" class="rounded-circle" style="width: 40px; height: 40px;" id='load_ava'>
73+
<img src="assets/images/customer/<?php echo $value['idc'] ?>/<?php echo $value['avatar'] ?> ?>" alt="user-image" class="rounded-circle" style="width: 40px; height: 40px;" id='load_ava'>
7174
<?php
7275
}
7376
?>
@@ -93,7 +96,7 @@
9396
<?php
9497
for ($i = 1; $i <= $pages; $i++) {
9598
?>
96-
<li class="page-item <?php if($i == $_GET['pages']){ echo 'active';} ?>"><a href="index.php?page=profile&method=rate&idu=<?php echo $user['id'] ?>&pages=<?php echo $i; ?>" class="page-link"><?php echo $i; ?></a></li>
99+
<li class="page-item <?php if($i == $_GET['pages']){ echo 'active';} ?>"><a href="index.php?page=profile&method=rate&idu=<?php echo $user['id'] ?>&ido=<?php echo $ido; ?>&pages=<?php echo $i; ?>" class="page-link"><?php echo $i; ?></a></li>
97100
<?php
98101
}
99102
?>

0 commit comments

Comments
 (0)