Skip to content

Instantly share code, notes, and snippets.

@Vinh2uang
Last active December 8, 2024 17:07
Show Gist options
  • Save Vinh2uang/c2432cafe27eac1ade04cd8929dccc77 to your computer and use it in GitHub Desktop.
Save Vinh2uang/c2432cafe27eac1ade04cd8929dccc77 to your computer and use it in GitHub Desktop.
Cách tính tổng số tiền đã mua hàng trên Shopee
/*CÁCH DÙNG:
B1: Mở Google Chrome, truy cập và đăng nhập vào Shopee.vn
B2: Vào mục "Đơn Mua": https://shope.ee/7pHF2r5lo0
B3: Nhấn tổ hợp phím Ctrl+Shift+J để mở tab "Console"
B4: Copy toàn bộ Code ở dưới. Paste vào tab "Console". Sau đó nhấn "Enter".
B5: Ra 1 box nhỏ cạnh trang Shopee, các bạn kéo ra, copy và paste vào Excel hoặc Google Sheet để xem
Nguồn: @nttkq */
async function getOrders(offset, limit) {
let url = "https://shopee.vn/api/v4/order/get_all_order_and_checkout_list?limit=" + limit + "&offset=" + offset;
var ordersData = (await (await fetch(url)).json()).data.order_data;
var detailList = ordersData.details_list
if (detailList) {
return detailList;
} else {
return [];
}
}
function _VietNamCurrency(number) {
return new Intl.NumberFormat('vi-VN', { style: 'currency', currency: 'VND' }).format(number);
}
async function getAllOrders() {
const limit = 20;
let offset = 0;
let allOrders = [];
allOrders.push(
[
'Tên chung', 'Số lượng', 'Tổng tiền', 'Trạng thái', 'Tên shop', 'Chi tiết', 'Tiền gốc'
].join('\t')
)
let sum = 0;
let count = 0;
while (true) {
let data = await getOrders(offset, limit);
if (data.length == 0)
break;
for (const item of data) {
const infoCard = item.info_card;
const listType = item.list_type;
let strListType;
switch (listType) {
case 3: strListType = "Hoàn thành"; break;
case 4: strListType = "Đã hủy"; break;
case 7: strListType = "Vận chuyển"; break;
case 8: strListType = "Đang giao"; break;
case 9: strListType = "Chờ thanh toán"; break;
case 12: strListType = "Trả hàng"; break;
default: strListType = "Không rõ"; break;
}
const productCount = infoCard.product_count;
let subTotal = infoCard.subtotal / 1e5;
count += productCount;
const orderCard = infoCard.order_list_cards[0];
const shopName = orderCard.shop_info.username + " - " + orderCard.shop_info.shop_name;
const products = orderCard.product_info.item_groups;
const productSumary = products.map(product => product.items.map(item => item.name + "--amount: " + item.amount + "--price: " + _VietNamCurrency(item.item_price)).join(', ')).join('; ');
const name = products[0].items[0].name;
if (listType != 4 && listType != 12)
sum += subTotal;
else
subTotal = 0;
const subTotalNative = _VietNamCurrency(subTotal);
allOrders.push(
[
name, productCount, subTotalNative, strListType, shopName, productSumary, subTotal
].join('\t')
);
}
console.log('Colected: ' + offset);
offset += limit;
}
allOrders.push(
[
'Tổng cộng: ', count, _VietNamCurrency(sum)
].join('\t')
);
var text = allOrders.join('\r\n');
document.write('<textarea>' + text + '</textarea>');
}
getAllOrders();
@tmhoang2023
Copy link

bị lỗi rồi b ơi

@tmhoang2023
Copy link

@Vinh2uang
Copy link
Author

bị lỗi rồi b ơi
Mình có sữa lại rồi, bạn thêm bước
B5: Ra 1 box nhỏ cạnh trang Shopee, các bạn kéo ra, copy và paste vào Excel hoặc Google Sheet để xem nhé

@brockoala
Copy link

Mình đã sửa lại và nhờ chatgpt sửa thêm cho dễ đọc + paste được thẳng vào google sheets ở đây:
https://gist.github.com/brockoala/ae6b9f3e4042688576c65ce9a394f72a

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment