lam71lt
Member
Hệ thống này sẽ giúp bạn:
Thêm đơn hàng mới
Cập nhật trạng thái đơn hàng
Lọc đơn hàng theo khách hàng, trạng thái
Lưu lịch sử giao dịch
Lưu ý:
Nhấn Save Table để lưu.
Dùng SQL trên Supabase
sql
CopyEdit
INSERT INTO orders (customer_name, product, quantity, total_price, status)
VALUES ('Nguyễn Văn A', 'Laptop Dell', 2, 30000000, 'pending');
Dùng API Supabase
sh
CopyEdit
curl -X POST "" \
-H "apikey: YOUR_SUPABASE_KEY" \
-H "Content-Type: application/json" \
-d '{"customer_name": "Nguyễn Văn A", "product": "Laptop Dell", "quantity": 2, "total_price": 30000000, "status": "pending"}'
Lấy tất cả đơn hàng
sql
CopyEdit
SELECT * FROM orders;
Lọc đơn hàng đang giao (shipped)
sql
CopyEdit
SELECT * FROM orders WHERE status = 'shipped';
Dùng API Supabase
sh
CopyEdit
curl -X GET "" \
-H "apikey: YOUR_SUPABASE_KEY"
Chuyển trạng thái đơn hàng thành shipped
sql
CopyEdit
UPDATE orders
SET status = 'shipped'
WHERE id = 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx';
Dùng API
sh
CopyEdit
curl -X PATCH "" \
-H "apikey: YOUR_SUPABASE_KEY" \
-H "Content-Type: application/json" \
-d '{"status": "shipped"}'
Xóa đơn hàng bị hủy
sql
CopyEdit
DELETE FROM orders WHERE status = 'cancelled';
Cài thư viện
sh
CopyEdit
pip install supabase
Kết nối Supabase
python
CopyEdit
from supabase import create_client
url = ""
key = "YOUR_SUPABASE_KEY"
supabase = create_client(url, key)
# Lấy danh sách đơn hàng
data = supabase.table("orders").select("*").execute()
print(data)
Thêm đơn hàng bằng Python
python
CopyEdit
order = {
"customer_name": "Trần Thị B",
"product": "iPhone 15",
"quantity": 1,
"total_price": 25000000,
"status": "pending"
}
supabase.table("orders").insert(order).execute()
Cập nhật trạng thái đơn hàng
python
CopyEdit
supabase.table("orders").update({"status": "delivered"}).eq("id", "xxxxxxxx-xxxx").execute()
Hệ thống này giúp bạn:




1. Tạo Database Trên Supabase
Bước 1: Tạo Dự Án
- Truy cập , đăng nhập.
- Nhấn New Project, nhập thông tin, tạo mật khẩu database.
Bước 2: Tạo Bảng orders
- Vào Database → Tables → Create Table.
- Đặt tên bảng: orders.
- Thêm các cột:
- id → UUID (Primary Key, auto-generate)
- customer_name → TEXT (Tên khách hàng)
- product → TEXT (Tên sản phẩm)
- quantity → INTEGER (Số lượng)
- total_price → DECIMAL (Tổng tiền)
- status → TEXT (Trạng thái: pending, shipped, delivered, cancelled)
- created_at → TIMESTAMP (Mặc định: now())

- status nên có giá trị mặc định là pending.
- total_price = quantity × giá sản phẩm (có thể tính tự động trong backend).

2. Quản Lý Đơn Hàng
Thêm Đơn Hàng Mới

sql
CopyEdit
INSERT INTO orders (customer_name, product, quantity, total_price, status)
VALUES ('Nguyễn Văn A', 'Laptop Dell', 2, 30000000, 'pending');

sh
CopyEdit
curl -X POST "" \
-H "apikey: YOUR_SUPABASE_KEY" \
-H "Content-Type: application/json" \
-d '{"customer_name": "Nguyễn Văn A", "product": "Laptop Dell", "quantity": 2, "total_price": 30000000, "status": "pending"}'
Lấy Danh Sách Đơn Hàng

sql
CopyEdit
SELECT * FROM orders;

sql
CopyEdit
SELECT * FROM orders WHERE status = 'shipped';

sh
CopyEdit
curl -X GET "" \
-H "apikey: YOUR_SUPABASE_KEY"
Cập Nhật Trạng Thái Đơn Hàng

sql
CopyEdit
UPDATE orders
SET status = 'shipped'
WHERE id = 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx';

sh
CopyEdit
curl -X PATCH "" \
-H "apikey: YOUR_SUPABASE_KEY" \
-H "Content-Type: application/json" \
-d '{"status": "shipped"}'
Xóa Đơn Hàng

sql
CopyEdit
DELETE FROM orders WHERE status = 'cancelled';
3. Sử Dụng Supabase Trong Python

sh
CopyEdit
pip install supabase

python
CopyEdit
from supabase import create_client
url = ""
key = "YOUR_SUPABASE_KEY"
supabase = create_client(url, key)
# Lấy danh sách đơn hàng
data = supabase.table("orders").select("*").execute()
print(data)

python
CopyEdit
order = {
"customer_name": "Trần Thị B",
"product": "iPhone 15",
"quantity": 1,
"total_price": 25000000,
"status": "pending"
}
supabase.table("orders").insert(order).execute()

python
CopyEdit
supabase.table("orders").update({"status": "delivered"}).eq("id", "xxxxxxxx-xxxx").execute()
Kết Luận
Hệ thống này giúp bạn:
- Quản lý đơn hàng online nhanh chóng.
- Lưu trữ dữ liệu tập trung, dễ truy vấn.
- Kết nối với Python để tự động hóa.