(orderType)
| 43 | }; |
| 44 | |
| 45 | async function getStatistics(orderType) { |
| 46 | let pulling = true; |
| 47 | let offset = 0; |
| 48 | let limit = 10; |
| 49 | |
| 50 | let totalDiscount = 0; |
| 51 | let totalSpent = 0; |
| 52 | let totalItems = 0; |
| 53 | let totalOrders = 0; |
| 54 | let totalShip = 0; |
| 55 | let totalShipDiscount = 0; |
| 56 | let shopeeVouchers = 0; |
| 57 | let shopVouchers = 0; |
| 58 | let allOrders = []; |
| 59 | |
| 60 | while (pulling) { |
| 61 | setLoadingText("Đang tải đơn hàng thứ " + (offset + 1) + "..."); |
| 62 | let res = await fetch( |
| 63 | `https://shopee.vn/api/v4/order/get_order_list?limit=${limit}&list_type=${orderType}&offset=${offset}` |
| 64 | ); |
| 65 | let json = await res.json(); |
| 66 | if (json?.error) throw Error("Error: " + json.error); |
| 67 | |
| 68 | let orders = json.data.details_list; |
| 69 | for (let i = 0; i < orders.length; i++) { |
| 70 | setLoadingText("Đang tải đơn hàng thứ " + (offset + i + 1) + "..."); |
| 71 | |
| 72 | let order = orders[i]; |
| 73 | let totalPrice = 0; |
| 74 | order.info_card.order_list_cards[0].product_info.item_groups.forEach( |
| 75 | (item_group) => { |
| 76 | item_group.items.forEach((item) => { |
| 77 | totalPrice += item.order_price * item.amount; |
| 78 | }); |
| 79 | } |
| 80 | ); |
| 81 | console.log(totalPrice, order.info_card.final_total); |
| 82 | totalDiscount += |
| 83 | (totalPrice - order.info_card.final_total) / 1e5 || 0; |
| 84 | totalSpent += order.info_card.final_total / 1e5; |
| 85 | totalItems += order.info_card.product_count; |
| 86 | |
| 87 | let orderId = order.info_card.order_id; |
| 88 | let detail = await getOrderDetail(orderId); |
| 89 | orders[i].detail = detail.json; |
| 90 | totalShip += detail.shippingSpent / 1e5; |
| 91 | shopeeVouchers += detail.shopee_voucher / 1e5; |
| 92 | shopVouchers += detail.shop_voucher / 1e5; |
| 93 | totalShipDiscount += detail.shipping_discount / 1e5; |
| 94 | |
| 95 | totalOrders++; |
| 96 | } |
| 97 | |
| 98 | allOrders.push(...orders); |
| 99 | pulling = orders.length >= limit; |
| 100 | offset += limit; |
| 101 | } |
| 102 |
no test coverage detected