@edutalk/promo-tool 0.0.0-stage → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +176 -2
- package/dist/index.d.ts +12 -0
- package/dist/index.js +6832 -0
- package/dist/index.umd.cjs +133 -0
- package/dist/style.css +2 -0
- package/dist/types/index.d.ts +88 -0
- package/dist/vue/PromoTool.vue.d.ts +22 -0
- package/package.json +60 -4
- package/supabase/schema.sql +64 -0
- package/supabase/schema_secure.sql +97 -0
package/README.md
CHANGED
|
@@ -1,3 +1,177 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @edutalk/promo-tool — Công cụ tính giá khuyến mại Edutalk
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Chuyển file Excel **"CÔNG CỤ TÍNH GIÁ KHUYẾN MẠI.xlsx"** thành module web & thư viện npm sẵn sàng nhúng vào hệ thống portal nội bộ (`noibo.edutalk.edu.vn`), hỗ trợ Vue 3, React hoặc Vanilla JS.
|
|
4
|
+
|
|
5
|
+
| Vai trò | Thấy gì | Làm gì |
|
|
6
|
+
|---|---|---|
|
|
7
|
+
| **Sale / TVV** | Tab *Tính giá*, *Bảng giá lộ trình* | Bấm chọn Nhãn → Chương trình → HTTT → Kỳ hạn → Bảo hành, tích chọn khóa (Online/Offline) → ra học phí cuối, quà tặng, trạng thái hợp lệ; *Sao chép báo giá* để gửi Zalo |
|
|
8
|
+
| **Admin** | Thêm tab *Quản trị dữ liệu gốc* | Sửa trực tiếp 14 bảng (giá gốc, voucher, CTKM, quà, Citime, lộ trình...), nhập lại từ Excel/JSON, *Lưu & áp dụng* |
|
|
9
|
+
|
|
10
|
+
Engine tính giá được đối chiếu với giá trị Excel đã tính sẵn: **574/574 ca khớp** (`npm test`).
|
|
11
|
+
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
## 1. Cài đặt vào dự án (Ví dụ: `noibo.edutalk.edu.vn`)
|
|
15
|
+
|
|
16
|
+
### Cách 1: Cài trực tiếp từ NPM (sau khi publish)
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
npm install @edutalk/promo-tool
|
|
20
|
+
# hoặc
|
|
21
|
+
yarn add @edutalk/promo-tool
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
### Cách 2: Cài từ file tarball / local (khi phát triển hoặc chưa publish)
|
|
25
|
+
|
|
26
|
+
Trong thư mục `ctkm-banggia`:
|
|
27
|
+
```bash
|
|
28
|
+
npm run build
|
|
29
|
+
npm pack
|
|
30
|
+
```
|
|
31
|
+
Lệnh trên tạo ra file `edutalk-promo-tool-1.0.0.tgz`.
|
|
32
|
+
|
|
33
|
+
Tại dự án `noibo.edutalk.edu.vn`:
|
|
34
|
+
```bash
|
|
35
|
+
npm install "F:/projects/ctkm-banggia/edutalk-promo-tool-1.0.0.tgz"
|
|
36
|
+
# hoặc cài dạng file link:
|
|
37
|
+
npm install "F:/projects/ctkm-banggia"
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
---
|
|
41
|
+
|
|
42
|
+
## 2. Cách sử dụng trong Vue 3
|
|
43
|
+
|
|
44
|
+
### Cách A: Dùng Component Vue `<PromoTool />` (Khuyên dùng)
|
|
45
|
+
|
|
46
|
+
```vue
|
|
47
|
+
<template>
|
|
48
|
+
<div class="p-4 bg-gray-50 min-h-screen">
|
|
49
|
+
<PromoTool :role="userRole" :store="store" :allowRoleSwitch="isDev" />
|
|
50
|
+
</div>
|
|
51
|
+
</template>
|
|
52
|
+
|
|
53
|
+
<script setup lang="ts">
|
|
54
|
+
import { computed } from 'vue';
|
|
55
|
+
import { PromoTool, localStore, seed, type UserRole } from '@edutalk/promo-tool';
|
|
56
|
+
import '@edutalk/promo-tool/style.css';
|
|
57
|
+
import { useAuthStore } from '@/stores/auth';
|
|
58
|
+
|
|
59
|
+
const authStore = useAuthStore();
|
|
60
|
+
const isDev = import.meta.env.DEV;
|
|
61
|
+
|
|
62
|
+
// Phân quyền: BOD/Admin nhận role 'admin', TVV/Sale nhận role 'sale'
|
|
63
|
+
const userRole = computed<UserRole>(() => {
|
|
64
|
+
return authStore.isBOD ? 'admin' : 'sale';
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
// Kho lưu trữ dữ liệu gốc:
|
|
68
|
+
// - localStore(seed): lưu localStorage trình duyệt
|
|
69
|
+
// - restStore('/api/promo-config', seed): gọi API backend
|
|
70
|
+
// - supabaseStore(supabaseClient, seed): lưu trên Supabase
|
|
71
|
+
const store = localStore(seed);
|
|
72
|
+
</script>
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
### Cách B: Dùng hàm `mountPromoTool` (Vanilla JS / DOM ref)
|
|
76
|
+
|
|
77
|
+
```vue
|
|
78
|
+
<template>
|
|
79
|
+
<div ref="containerRef" />
|
|
80
|
+
</template>
|
|
81
|
+
|
|
82
|
+
<script setup>
|
|
83
|
+
import { ref, onMounted, onBeforeUnmount } from 'vue';
|
|
84
|
+
import { mountPromoTool, localStore, seed } from '@edutalk/promo-tool';
|
|
85
|
+
import '@edutalk/promo-tool/style.css';
|
|
86
|
+
|
|
87
|
+
const containerRef = ref(null);
|
|
88
|
+
let instance = null;
|
|
89
|
+
|
|
90
|
+
onMounted(async () => {
|
|
91
|
+
instance = await mountPromoTool(containerRef.value, {
|
|
92
|
+
role: 'sale',
|
|
93
|
+
store: localStore(seed),
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
onBeforeUnmount(() => {
|
|
98
|
+
instance?.destroy();
|
|
99
|
+
});
|
|
100
|
+
</script>
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
---
|
|
104
|
+
|
|
105
|
+
## 3. Xuất bản Package lên NPM (`npm publish`)
|
|
106
|
+
|
|
107
|
+
1. Đăng nhập tài khoản npm tổ chức `@edutalk`:
|
|
108
|
+
```bash
|
|
109
|
+
npm login
|
|
110
|
+
```
|
|
111
|
+
2. Kiểm tra tài khoản đã đăng nhập:
|
|
112
|
+
```bash
|
|
113
|
+
npm whoami
|
|
114
|
+
```
|
|
115
|
+
3. Chạy test và build bundle:
|
|
116
|
+
```bash
|
|
117
|
+
npm run prepublishOnly
|
|
118
|
+
```
|
|
119
|
+
4. Xuất bản lên npm registry:
|
|
120
|
+
```bash
|
|
121
|
+
npm publish --access public
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
---
|
|
125
|
+
|
|
126
|
+
## 4. Các hàm & module được export từ package
|
|
127
|
+
|
|
128
|
+
- **UI & Components**:
|
|
129
|
+
- `PromoTool`: Vue 3 Single File Component
|
|
130
|
+
- `mountPromoTool(element, options)`: Gắn giao diện vào bất kỳ thẻ HTML nào
|
|
131
|
+
- **Stores**:
|
|
132
|
+
- `localStore(seed)`: Lưu trên trình duyệt (phù hợp demo/offline)
|
|
133
|
+
- `restStore(url, seed, options)`: Kết nối API backend riêng (GET trả JSON, PUT lưu JSON)
|
|
134
|
+
- `supabaseStore(supabase, seed, options)`: Kết nối qua Supabase DB
|
|
135
|
+
- **Dữ liệu gốc ban đầu**:
|
|
136
|
+
- `seed`: Đối tượng cấu hình 14 bảng mẫu từ file Excel
|
|
137
|
+
- **Engine tính giá thuần JS** (dùng được ở cả frontend và backend Node.js để kiểm tra tính hợp lệ):
|
|
138
|
+
- `quote(data, input)`: Báo giá 1 đơn hàng/combo
|
|
139
|
+
- `routeTable(data, options)`: Tính sẵn giá mọi lộ trình của một nhãn
|
|
140
|
+
- `coursesForLabel(data, label)`: Danh sách khóa học hợp lệ theo nhãn
|
|
141
|
+
- `termsFor(data, method)`: Danh sách kỳ hạn hợp lệ theo HTTT
|
|
142
|
+
- `validateData(data)`: Kiểm tra tính toàn vẹn của dữ liệu 14 bảng
|
|
143
|
+
- `normalizeData(data)`: Chuẩn hóa kiểu dữ liệu
|
|
144
|
+
|
|
145
|
+
---
|
|
146
|
+
|
|
147
|
+
## 5. Logic tính (đối chiếu 1:1 file Excel)
|
|
148
|
+
|
|
149
|
+
```
|
|
150
|
+
Giá sau KM = Tổng giá gốc − Tổng giá gốc × %CTKM − Hoàn tiền − Tổng voucher
|
|
151
|
+
Phí bảo hành = Giá tính BH × %BH (Giá tính BH = tổng giá gốc trừ các khóa bỏ tick "Tính BH")
|
|
152
|
+
Học phí cuối = Giá sau KM + Phí bảo hành
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
| Chương trình | % giảm lấy từ |
|
|
156
|
+
|---|---|
|
|
157
|
+
| Định kỳ (`DINH_KY`) | CTKM định kỳ theo số khóa + hoàn tiền + quà tặng |
|
|
158
|
+
| Định kỳ đặc biệt (`DAC_BIET`) | CTKM đặc biệt theo HTTT + kỳ hạn |
|
|
159
|
+
| Liên kết trường (`LKT`) | % của **chương trình nền** theo Nhóm LKT − mức cắt của Format (bảng *Format liên kết trường*). VD *LKT Thấp điểm* → % Thấp điểm − cắt; *LKT Toàn hệ thống* → % Định kỳ đặc biệt − cắt. Voucher cũng lấy theo chương trình nền. |
|
|
160
|
+
| Thấp điểm / VP mới / Vũ Đài Trí Tuệ (`MO_RONG`) | CTKM mở rộng; voucher lấy từ *Voucher theo CTKM* |
|
|
161
|
+
|
|
162
|
+
---
|
|
163
|
+
|
|
164
|
+
## 6. Lệnh phát triển nội bộ thư viện
|
|
165
|
+
|
|
166
|
+
```bash
|
|
167
|
+
# Chạy demo cục bộ
|
|
168
|
+
npm run dev
|
|
169
|
+
# hoặc
|
|
170
|
+
npm run serve
|
|
171
|
+
|
|
172
|
+
# Chạy kiểm thử đối chiếu Excel (574 ca)
|
|
173
|
+
npm test
|
|
174
|
+
|
|
175
|
+
# Đóng gói bản phân phối dist/
|
|
176
|
+
npm run build
|
|
177
|
+
```
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { default as PromoTool } from './vue/PromoTool.vue';
|
|
2
|
+
import { App } from 'vue';
|
|
3
|
+
export { mountPromoTool } from './ui/app.js';
|
|
4
|
+
export { PromoTool };
|
|
5
|
+
export { localStore, supabaseStore, restStore } from './store.js';
|
|
6
|
+
export { default as seed } from './data/seed.js';
|
|
7
|
+
export { STATUS_OK, quote, routeTable, coursesForLabel, termsFor, isFixedTerm, findProgram, findMethod, validateData, normalizeData, lktGroupsFor, lktFormatsFor, } from './engine/pricing.js';
|
|
8
|
+
export * from './types/index.js';
|
|
9
|
+
declare const _default: {
|
|
10
|
+
install(app: App): void;
|
|
11
|
+
};
|
|
12
|
+
export default _default;
|