Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
181 commits
Select commit Hold shift + click to select a range
b6f9b13
init
KieuTanTai Mar 29, 2025
5162fba
init
KieuTanTai Mar 29, 2025
335a104
auto bot commit
KieuTanTai Mar 29, 2025
bc092c2
add container
KieuTanTai Mar 30, 2025
eaf4ac2
add more container
KieuTanTai Mar 30, 2025
ccae6a7
add base for form detail_product, for cart
KieuTanTai Mar 31, 2025
9c220f8
config detail product
KieuTanTai Apr 2, 2025
9377679
add button change form for cart
KieuTanTai Apr 3, 2025
e64ecdf
add button change form for cart
KieuTanTai Apr 3, 2025
846497f
Create i
vhvkhangg Apr 5, 2025
7bcea38
Delete public/app/views directory
vhvkhangg Apr 5, 2025
cb274c6
Create i
vhvkhangg Apr 5, 2025
081cace
Create i
vhvkhangg Apr 5, 2025
103ea63
Create i
vhvkhangg Apr 5, 2025
15a0470
Create i
vhvkhangg Apr 5, 2025
b72fc71
Create i
vhvkhangg Apr 5, 2025
b1a3f2a
Create i
vhvkhangg Apr 5, 2025
6af15b9
temp
KieuTanTai Apr 5, 2025
c5d35a2
Giao Diện Admin, User, Order
vhvkhangg Apr 5, 2025
7c63abb
CSS
vhvkhangg Apr 5, 2025
2184b88
Images
vhvkhangg Apr 5, 2025
13c89c9
JS
vhvkhangg Apr 5, 2025
4ffb465
Delete app/views/admin.php
vhvkhangg Apr 5, 2025
d67a9a9
Sửa lỗi đường dẫn file JS
vhvkhangg Apr 5, 2025
5529212
Delete app/views/i
vhvkhangg Apr 5, 2025
1e16c9b
Delete public/uploads/i
vhvkhangg Apr 5, 2025
79255f1
Delete public/assets/css/i
vhvkhangg Apr 5, 2025
47eca39
Delete public/assets/fonts/i
vhvkhangg Apr 5, 2025
e80981f
Delete public/assets/js/i
vhvkhangg Apr 5, 2025
36b4ab2
Create i
vhvkhangg Apr 5, 2025
0656bde
Delete public/assets/fonts/i
vhvkhangg Apr 5, 2025
1717613
Delete public/assets/images/i
vhvkhangg Apr 5, 2025
d200149
Delete app/views/header1.php
vhvkhangg Apr 5, 2025
8602295
Add files via upload
vhvkhangg Apr 5, 2025
43359db
remove admin
KieuTanTai Apr 5, 2025
49c7f14
remove admin
KieuTanTai Apr 5, 2025
5d5f127
get Admin
KieuTanTai Apr 5, 2025
daa352c
Add files via upload
KieuNam3705 Apr 6, 2025
b679fdf
GH
Apr 6, 2025
884f3c9
update code
KieuTanTai Apr 8, 2025
820059c
rename id
KieuTanTai Apr 8, 2025
fcddd6d
add disable for detail product
KieuTanTai Apr 8, 2025
a3cbb99
test show more product
KieuTanTai Apr 10, 2025
4e68882
cau truc file mvc va product
Vhuu08092004 Apr 11, 2025
bb68a08
config product.js, page.js, interface.js, action.js, index.js, create…
KieuTanTai Apr 11, 2025
b1da706
fix bug js
KieuTanTai Apr 11, 2025
9c8922b
fix bug js
KieuTanTai Apr 12, 2025
bbe0901
fix db
KieuTanTai Apr 12, 2025
6d7cbca
fix db
KieuTanTai Apr 12, 2025
262f7d8
fix bug nav to homepage
KieuTanTai Apr 12, 2025
e81b960
add container for search result
KieuTanTai Apr 12, 2025
b39c527
api product va render product trong homepage
Vhuu08092004 Apr 12, 2025
a3574df
add auto gene product from db
KieuTanTai Apr 13, 2025
c934ad4
change db, add search container, fix show more product func
KieuTanTai Apr 13, 2025
04e4216
need to fix search, pages, product, action.js; add feature search, ad…
KieuTanTai Apr 13, 2025
5c73c0e
need to fix search, pages, product, action.js; add feature search, ad…
KieuTanTai Apr 13, 2025
6dab9ff
GH
Apr 13, 2025
dad8278
Create i
vhvkhangg Apr 14, 2025
952d491
Add files via upload
vhvkhangg Apr 14, 2025
9491d9f
Delete app/config/i
vhvkhangg Apr 14, 2025
2855a7f
Create i
vhvkhangg Apr 14, 2025
43de985
Thêm controller
vhvkhangg Apr 14, 2025
ae81dc8
Delete app/controller/user/i
vhvkhangg Apr 14, 2025
82688d1
Create i
vhvkhangg Apr 14, 2025
b15cc14
thêm model
vhvkhangg Apr 14, 2025
6784559
Delete app/model/i
vhvkhangg Apr 14, 2025
43f92fc
Merge branch 'VKhang' of https://github.com/KieuTanTai/ReworkWeb2 int…
Vhuu08092004 Apr 14, 2025
adc69e4
fix: database config
Vhuu08092004 Apr 14, 2025
b30654f
fix bug on cart form
KieuTanTai Apr 14, 2025
b081089
not know
KieuTanTai Apr 14, 2025
3ece856
fixing bug on cart func
KieuTanTai Apr 14, 2025
dec1629
GH
Apr 16, 2025
13d6c9e
Merge branch 'TLang' of https://github.com/KieuTanTai/ReworkWeb2 into…
Vhuu08092004 Apr 18, 2025
85dc2d4
Update login.php
KieuNam3705 Apr 18, 2025
7a6f974
Delete public/index.php
KieuNam3705 Apr 18, 2025
3ea2372
Delete public/register.php
KieuNam3705 Apr 18, 2025
2c197a3
Delete public/login.php
KieuNam3705 Apr 18, 2025
0fe7290
Delete public/assets/css directory
KieuNam3705 Apr 18, 2025
e40d68f
Add files via upload
KieuNam3705 Apr 18, 2025
3c1713e
app
KieuNam3705 Apr 18, 2025
e2b6def
api phienbansanpham
Vhuu08092004 Apr 18, 2025
e5ce664
2 api get id va getAll
Vhuu08092004 Apr 18, 2025
ac33eb3
Delete api directory
KieuNam3705 Apr 18, 2025
223acbf
Delete config directory
KieuNam3705 Apr 18, 2025
3231ff5
Delete controller directory
KieuNam3705 Apr 18, 2025
ca35f72
Delete model directory
KieuNam3705 Apr 18, 2025
c319df5
Delete views directory
KieuNam3705 Apr 18, 2025
26c3acf
Delete .env
KieuNam3705 Apr 18, 2025
f834584
Add files via upload
KieuNam3705 Apr 18, 2025
b29a4d5
public
KieuNam3705 Apr 18, 2025
483776a
Add files via upload
KieuNam3705 Apr 18, 2025
351e96e
Add files via upload
KieuNam3705 Apr 18, 2025
7d14a4e
temp push
KieuTanTai Apr 18, 2025
9fb186d
merge branch NKieu and fix conflict files
KieuTanTai Apr 18, 2025
41bd26a
temp push
KieuTanTai Apr 18, 2025
189fee8
fix detail product
Vhuu08092004 Apr 19, 2025
fdf5bd3
Merge branch 'TLang' of https://github.com/KieuTanTai/ReworkWeb2 into…
Vhuu08092004 Apr 19, 2025
b38ebdb
fix: sua tao san pham thanh cong
Vhuu08092004 Apr 19, 2025
b556047
just read zalo messages
KieuTanTai Apr 19, 2025
879c432
merge temp
KieuTanTai Apr 19, 2025
a2bf06a
Thêm model, controller cho order, thêm phân trang cho user
vhvkhangg Apr 20, 2025
3778fd4
Merge branch VKhang
KieuTanTai Apr 23, 2025
e641ea2
GH
Apr 23, 2025
7f961c1
fix bug on form borrow, form reservation, just show pending status on…
KieuTanTai Apr 23, 2025
049f7a7
pull code
KieuTanTai Apr 23, 2025
7bc7c41
add feature for detail, cart
KieuTanTai Apr 24, 2025
bee6380
fix bug on cart, change set item cart for local storage, add more get…
KieuTanTai Apr 24, 2025
aa1c007
add text for username on header
KieuTanTai Apr 24, 2025
7fbea9a
Up: Xem chi tiết đơn hàng
vhvkhangg Apr 25, 2025
31d1a3b
merge branch VKhang
KieuTanTai Apr 25, 2025
3679c9a
Add files via upload
KieuNam3705 Apr 25, 2025
2831063
Add files via upload
KieuNam3705 Apr 25, 2025
990be99
Add files via upload
KieuNam3705 Apr 25, 2025
968e9fe
Add files via upload
KieuNam3705 Apr 25, 2025
c0d2e19
add api
KieuTanTai Apr 25, 2025
4c56262
merge branch NKieu and fix conflict files
KieuTanTai Apr 25, 2025
e8f7c20
fix bug on cart, add form history order
KieuTanTai Apr 25, 2025
1424d9a
hard code detective!!!! change string url for Product.php func create…
KieuTanTai Apr 26, 2025
47bf0c5
hard code detective!!!! change string url for Product.php func create…
KieuTanTai Apr 26, 2025
077b93f
hard code detective!!!! change string url for Product.php func create…
KieuTanTai Apr 26, 2025
660bfa1
Up: Sửa phần cập nhật trạng thái đơn hàng
vhvkhangg Apr 28, 2025
7f7d1e7
fix:sidebar product
May 3, 2025
b1d6f9d
feat:them phan trang
May 4, 2025
c330cc0
Add files via upload
KieuNam3705 May 4, 2025
6b1a660
feat:them nut tat form
May 4, 2025
27e96a7
fix:khong hien thi hinh
May 5, 2025
563a5bf
feat: them phien ban san pham
Vhuu08092004 May 5, 2025
e4a8a63
fix:hien thi san pham moi nhat
May 5, 2025
5b14c84
Update: Sắp xếp đơn hàng giảm dần theo mã đơn hàng
vhvkhangg May 5, 2025
39d5f26
Add files via upload
KieuNam3705 May 6, 2025
feddbef
Delete controller directory
KieuNam3705 May 6, 2025
c8d6f52
Delete model directory
KieuNam3705 May 6, 2025
595e8e0
Delete views directory
KieuNam3705 May 6, 2025
d081347
Add files via upload
KieuNam3705 May 6, 2025
40faf97
merge VKhang
KieuTanTai May 7, 2025
b148b3a
merge NKieu
KieuTanTai May 7, 2025
2ef6a67
Fix:them phienbansanpham
May 7, 2025
7709442
Fix: Lọc đơn hàng
vhvkhangg May 9, 2025
ff1cb0a
Merge VKhang
KieuTanTai May 9, 2025
e8008b5
Add files via upload
Haohan2004 May 9, 2025
9f7edd1
tim theo phan loai
Haohan2004 May 9, 2025
42e04c2
fix:layout
May 10, 2025
9916ee1
Fix: Lọc đơn hàng, Update: Hiển thị chi tiết đơn hàng
vhvkhangg May 10, 2025
7426a12
Update: bỏ thông báo trong sidebar1.php
vhvkhangg May 10, 2025
086e179
feat: api thongke controller thongke
Vhuu08092004 May 10, 2025
7a19c3b
fix:giao dien thong ke
Haohan2004 May 11, 2025
06cffa1
Feat: Hiển thị giờ cho khách hàng, thêm regex cho ngày tham gia
vhvkhangg May 12, 2025
56ecdac
fix:thongke
May 12, 2025
6ce60e1
them:top 5 khach hang
May 13, 2025
6d8783e
feat: sua thong ke
Vhuu08092004 May 14, 2025
c83ca1f
Fix: Hiển thị khách hàng theo mã kh giảm dần
vhvkhangg May 14, 2025
28d4d5c
Merge branch 'VKhang' of https://github.com/KieuTanTai/ReworkWeb2 int…
Vhuu08092004 May 14, 2025
e4d4967
add image
KieuTanTai May 14, 2025
e2709aa
them:thongke
Haohan2004 May 14, 2025
f611215
fix bug on cart, add form history order, news, banners
KieuTanTai May 14, 2025
cebc075
add image
KieuTanTai May 14, 2025
9ebb104
fix history and tracking
KieuTanTai May 14, 2025
de0f324
fix history and tracking
KieuTanTai May 14, 2025
fbd4c54
Merge branch 'TLang' of https://github.com/KieuTanTai/ReworkWeb2 into…
Haohan2004 May 14, 2025
130aec5
fix text
KieuTanTai May 14, 2025
a576822
Merge branch 'TLang' of https://github.com/KieuTanTai/ReworkWeb2 into…
Haohan2004 May 14, 2025
cc1f342
fix bug image, fix bug cart
KieuTanTai May 14, 2025
f22f195
feat: sua limit thanh 5 them query trang thai la 3
Vhuu08092004 May 15, 2025
9fb35b2
Thêm regex cho lọc đơn hàng
vhvkhangg May 15, 2025
4f18695
merge VKhang
KieuTanTai May 15, 2025
65af934
Merge branch 'TLang' of https://github.com/KieuTanTai/ReworkWeb2 into…
Haohan2004 May 15, 2025
aecde60
fix:tim kiem khach hang
Haohan2004 May 15, 2025
aa391a6
fix:validdate
Haohan2004 May 15, 2025
bb6309f
Đổi Quản Lý Người Dùng thành Quản Lý Khách Hàng trong sidebar1.php
vhvkhangg May 16, 2025
4892bf5
fix bug history
KieuTanTai May 16, 2025
2b80cc3
Merge branch 'TLang' of https://github.com/KieuTanTai/ReworkWeb2 into…
KieuTanTai May 16, 2025
da52808
Merge branch 'TLang' of https://github.com/KieuTanTai/ReworkWeb2 into…
KieuTanTai May 16, 2025
f347c24
fix bug history
KieuTanTai May 16, 2025
e29367f
feat: them getkhachhang khong phan trang
Vhuu08092004 May 16, 2025
aa6ece2
Add files via upload
KieuNam3705 May 16, 2025
d28e580
Add files via upload
KieuNam3705 May 16, 2025
a0dcb50
Add files via upload
KieuNam3705 May 16, 2025
4318b89
Sửa lại những dòng bị xoá nhầm
vhvkhangg May 16, 2025
b174527
fix:them quay ve
May 16, 2025
c623fc9
sua chi tiet
May 16, 2025
f8eb8c6
Add files via upload
KieuNam3705 May 16, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
38 changes: 38 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Ignore các script Python tự động
auto_merge.py
auto_remove.py
auto_update.py
auto_commit.py

# Ignore các file nhạy cảm
.env
config.ini
secrets.json
credentials.json
*.pem
*.key
*.crt
*.pfx

# Ignore thư mục node_modules, vendor, cache
node_modules/
vendor/
__pycache__/
.DS_Store
*.log
*.sqlite3
*.db

# Ignore thư mục hệ thống và IDE
.DS_Store
Thumbs.db
.vscode/
.idea/
*.log

# Ignore các file cá nhân
*.swp
*.swo
*.swn
*.bak

27 changes: 27 additions & 0 deletions app/api/colorAPi.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php
header('Content-Type: application/json');
require_once __DIR__ . '/../config/database.php'; // Kết nối DB
require_once __DIR__ . '/../model/Color.php'; // Model Color

$controller = new Color($conn); // Khởi tạo đối tượng Color với kết nối DB

$method = $_SERVER['REQUEST_METHOD'];

if ($method === 'GET') {
$result = $controller->getAllColor();

$colors = [];
while ($row = $result->fetch_assoc()) {
$colors[] = $row;
}

echo json_encode([
'status' => 'success',
'data' => $colors
]);
} else {
echo json_encode([
'status' => 'error',
'message' => 'Phương thức không được hỗ trợ.'
]);
}
91 changes: 91 additions & 0 deletions app/api/detailOrderAPi.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<?php
header('Content-Type: application/json');
require_once __DIR__ . '/../config/database.php';
require_once __DIR__ . '/../model/DetailOrder.php';

$controller = new DetailOrder($conn);
$method = $_SERVER['REQUEST_METHOD'];

switch ($method) {
case 'GET':
// Lấy 1 detail (madonhang + maphienbansp)
if (isset($_GET['madonhang'], $_GET['maphienbansp'])) {
$d = $controller->getOne((int)$_GET['madonhang'], (int)$_GET['maphienbansp']);
if ($d) {
echo json_encode(['status'=>'success','data'=>$d]);
} else {
echo json_encode(['status'=>'error','message'=>'Không tìm thấy chi tiết đơn.']);
}
exit;
}
// Lấy theo mã đơn
if (isset($_GET['madonhang'])) {
$res = $controller->getByOrder((int)$_GET['madonhang']);
$rows = [];
while ($r = $res->fetch_assoc()) $rows[] = $r;
echo json_encode(['status'=>'success','data'=>$rows]);
exit;
}
// Lấy tất cả
$res = $controller->getAll();
$all = [];
while ($r = $res->fetch_assoc()) $all[] = $r;
echo json_encode(['status'=>'success','data'=>$all]);
break;

case 'POST':
$d = json_decode(file_get_contents('php://input'), true);
if ($d && isset($d['madonhang'], $d['maphienbansp'], $d['soluong'], $d['dongia'])) {
$controller->madonhang = (int)$d['madonhang'];
$controller->maphienbansp = (int)$d['maphienbansp'];
$controller->soluong = (int)$d['soluong'];
$controller->dongia = (int)$d['dongia'];

if ($controller->create()) {
echo json_encode(['status'=>'success','message'=>'Thêm chi tiết đơn thành công.']);
} else {
http_response_code(500);
echo json_encode(['status'=>'error','message'=>'Thêm thất bại.']);
}
} else {
echo json_encode(['status'=>'error','message'=>'Dữ liệu không hợp lệ.']);
}
break;

case 'PUT':
$d = json_decode(file_get_contents('php://input'), true);
if ($d && isset($d['madonhang'], $d['maphienbansp'], $d['soluong'], $d['dongia'])) {
$controller->madonhang = (int)$d['madonhang'];
$controller->maphienbansp = (int)$d['maphienbansp'];
$controller->soluong = (int)$d['soluong'];
$controller->dongia = (int)$d['dongia'];

if ($controller->update()) {
echo json_encode(['status'=>'success','message'=>'Cập nhật thành công.']);
} else {
http_response_code(500);
echo json_encode(['status'=>'error','message'=>'Cập nhật thất bại.']);
}
} else {
echo json_encode(['status'=>'error','message'=>'Thiếu dữ liệu cần thiết.']);
}
break;

case 'DELETE':
$d = json_decode(file_get_contents('php://input'), true);
if ($d && isset($d['madonhang'], $d['maphienbansp'])) {
if ($controller->delete((int)$d['madonhang'], (int)$d['maphienbansp'])) {
echo json_encode(['status'=>'success','message'=>'Xóa thành công.']);
} else {
http_response_code(500);
echo json_encode(['status'=>'error','message'=>'Xóa thất bại.']);
}
} else {
echo json_encode(['status'=>'error','message'=>'Thiếu khóa chính.']);
}
break;

default:
echo json_encode(['status'=>'error','message'=>'Phương thức không hỗ trợ.']);
break;
}
155 changes: 155 additions & 0 deletions app/api/orderAPi.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
<?php
header('Content-Type: application/json');
require_once __DIR__ . '/../config/database.php';
require_once __DIR__ . '/../model/Order.php';

$controller = new Order($conn);
$method = $_SERVER['REQUEST_METHOD'];

switch ($method) {
case 'GET':
// -- Lấy đơn hàng theo ID: orderAPI.php?madonhang=123
if (isset($_GET['madonhang'])) {
$id = (int) $_GET['madonhang'];
$order = $controller->getOrderById($id);
if ($order) {
// đồng thời lấy chi tiết
$items = $controller->getOrderItems($id);
echo json_encode([
'status' => 'success',
'data' => [
'order' => $order,
'items' => $items
]
]);
} else {
echo json_encode([
'status' => 'error',
'message' => 'Không tìm thấy đơn hàng.'
]);
}
exit;
}

if (isset($_GET['makh'])) {
$makh = (int) $_GET['makh'];
$result = $controller->getByCustomer($makh);
$orders = [];
while ($row = $result->fetch_assoc()) {
$orders[] = $row;
}
echo json_encode([
'status' => 'success',
'data' => $orders
]);
exit;
}

// -- Phân trang: ?limit=10&offset=0
if (isset($_GET['limit'], $_GET['offset'])) {
$limit = (int) $_GET['limit'];
$offset = (int) $_GET['offset'];
$result = $controller->getOrdersPaginated($limit, $offset);
$total = $controller->getTotalOrdersCount();
$data = [];
while ($row = $result->fetch_assoc()) {
$data[] = $row;
}
echo json_encode([
'status' => 'success',
'total' => $total,
'data' => $data
]);
} else {
// -- Lấy tất cả
$result = $controller->getAll();
$data = [];
while ($row = $result->fetch_assoc()) {
$data[] = $row;
}
echo json_encode([
'status' => 'success',
'data' => $data
]);
}
break;

case 'POST':
// Tạo đơn hàng mới
$d = json_decode(file_get_contents('php://input'), true);
if ($d) {
$controller->makh = $d['makh'] ?? 0;
$controller->thoigian = $d['thoigian'] ?? date('Y-m-d H:i:s');
$controller->tongtien = $d['tongtien'] ?? 0;
$controller->diachi = $d['diachi'] ?? '';
// trạng thái mặc định = 1
if ($controller->create()) {
echo json_encode(['status' => 'success', 'message' => 'Tạo đơn hàng thành công.']);
} else {
http_response_code(500);
echo json_encode(['status' => 'error', 'message' => 'Tạo đơn hàng thất bại.']);
}
} else {
echo json_encode(['status' => 'error', 'message' => 'Dữ liệu không hợp lệ.']);
}
break;

case 'PUT':
// Cập nhật toàn bộ thông tin đơn (ngoại trừ items)
$d = json_decode(file_get_contents('php://input'), true);
if ($d && isset($d['madonhang'])) {
$controller->madonhang = $d['madonhang'];
$controller->makh = $d['makh'];
$controller->thoigian = $d['thoigian'];
$controller->tongtien = $d['tongtien'];
$controller->diachi = $d['diachi'];
$controller->trangthai = $d['trangthai'];
if ($controller->update()) {
echo json_encode(['status' => 'success', 'message' => 'Cập nhật đơn hàng thành công.']);
} else {
http_response_code(500);
echo json_encode(['status' => 'error', 'message' => 'Cập nhật đơn hàng thất bại.']);
}
} else {
echo json_encode(['status' => 'error', 'message' => 'Thiếu mã đơn hàng.']);
}
break;

case 'PATCH':
// Cập nhật trạng thái đơn
$d = json_decode(file_get_contents('php://input'), true);
if ($d && isset($d['madonhang'], $d['trangthai'])) {
if ($controller->updateOrderStatus((int) $d['madonhang'], (int) $d['trangthai'])) {
echo json_encode(['status' => 'success', 'message' => 'Cập nhật trạng thái thành công.']);
} else {
http_response_code(500);
echo json_encode(['status' => 'error', 'message' => 'Cập nhật trạng thái thất bại.']);
}
} else {
echo json_encode(['status' => 'error', 'message' => 'Thiếu thông tin trạng thái.']);
}
break;

case 'DELETE':
// Xóa đơn hàng
$d = json_decode(file_get_contents('php://input'), true);
if ($d && isset($d['madonhang'])) {
$tbl = $controller->getTableName();
$stmt = $conn->prepare("DELETE FROM {$tbl} WHERE madonhang = ?");
$stmt->bind_param('i', $d['madonhang']);
if ($stmt->execute()) {
echo json_encode(['status' => 'success', 'message' => 'Xóa đơn hàng thành công.']);
} else {
http_response_code(500);
echo json_encode(['status' => 'error', 'message' => 'Xóa đơn hàng thất bại.']);
}
$stmt->close();
} else {
echo json_encode(['status' => 'error', 'message' => 'Thiếu mã đơn hàng để xóa.']);
}
break;

default:
echo json_encode(['status' => 'error', 'message' => 'Phương thức không hỗ trợ.']);
break;
}
68 changes: 68 additions & 0 deletions app/api/phienbansoAPi.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php
header('Content-Type: application/json');
require_once __DIR__ . '/../controller/product/detailController.php';
$controller = new detailController();

$method = $_SERVER['REQUEST_METHOD'];

if ($method === 'GET') {
$params = $_GET;

// Nếu truyền đủ 4 tham số masp, mausac, ram, rom
if (isset($params['masp'], $params['mausac'], $params['ram'], $params['rom'])) {
$masp = (int)$params['masp'];
$mausac = (int)$params['mausac'];
$ram = (int)$params['ram'];
$rom = (int)$params['rom'];

$variantId = $controller->getVariantId($masp, $mausac, $ram, $rom);

if ($variantId !== null) {
echo json_encode([
'status' => 'success',
'data' => ['maphienbansp' => $variantId]
]);
} else {
echo json_encode([
'status' => 'error',
'message' => 'Không tìm thấy biến thể với thông tin đã cung cấp.'
]);
}
exit;
}

// Nếu chỉ có id
$id = isset($params['id']) ? (int)$params['id'] : null;
if ($id) {
$result = $controller->getDetailByProductId($id);
if ($result) {
echo json_encode([
'status' => 'success',
'data' => $result
]);
} else {
echo json_encode([
'status' => 'error',
'message' => 'Không tìm thấy sản phẩm với ID đã cho.'
]);
}
} else {
// Không param nào → lấy tất cả
$result = $controller->index();
echo json_encode([
'status' => 'success',
'data' => $result
]);
}
} elseif ($_SERVER['REQUEST_METHOD'] === 'POST'){
$controller->create();
} else {
echo json_encode([
'status' => 'error',
'message' => 'Phương thức không được hỗ trợ.'
]);
}



?>
Loading