nodebb-plugin-niki-loyalty 1.0.13 → 1.0.16
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/library.js +22 -20
- package/package.json +1 -1
package/library.js
CHANGED
|
@@ -8,19 +8,19 @@ const Plugin = {};
|
|
|
8
8
|
|
|
9
9
|
const SETTINGS = {
|
|
10
10
|
pointsPerHeartbeat: 5,
|
|
11
|
-
dailyCap:
|
|
11
|
+
dailyCap: 250,
|
|
12
12
|
coffeeCost: 250
|
|
13
13
|
};
|
|
14
14
|
|
|
15
|
-
// --- LOG
|
|
15
|
+
// --- LOG FONKSİYONLARI ---
|
|
16
16
|
async function addUserLog(uid, type, amount, desc) {
|
|
17
17
|
const logEntry = {
|
|
18
18
|
ts: Date.now(),
|
|
19
|
-
type: type, // 'earn'
|
|
19
|
+
type: type, // 'earn' veya 'spend'
|
|
20
20
|
amt: amount,
|
|
21
21
|
txt: desc
|
|
22
22
|
};
|
|
23
|
-
//
|
|
23
|
+
// Öğrenci geçmişine ekle
|
|
24
24
|
await db.listAppend(`niki:activity:${uid}`, logEntry);
|
|
25
25
|
await db.listTrim(`niki:activity:${uid}`, -50, -1);
|
|
26
26
|
}
|
|
@@ -33,7 +33,7 @@ async function addKasaLog(staffUid, customerName, customerUid) {
|
|
|
33
33
|
cuid: customerUid,
|
|
34
34
|
amt: SETTINGS.coffeeCost
|
|
35
35
|
};
|
|
36
|
-
// Kasa defterine ekle
|
|
36
|
+
// Kasa defterine ekle
|
|
37
37
|
await db.listAppend('niki:kasa:history', logEntry);
|
|
38
38
|
await db.listTrim('niki:kasa:history', -100, -1);
|
|
39
39
|
}
|
|
@@ -42,7 +42,7 @@ Plugin.init = async function (params) {
|
|
|
42
42
|
const router = params.router;
|
|
43
43
|
const middleware = params.middleware;
|
|
44
44
|
|
|
45
|
-
// 1. HEARTBEAT (
|
|
45
|
+
// 1. HEARTBEAT (Puan Kazanma)
|
|
46
46
|
router.post('/api/niki-loyalty/heartbeat', middleware.ensureLoggedIn, async (req, res) => {
|
|
47
47
|
const uid = req.uid;
|
|
48
48
|
const today = new Date().toISOString().slice(0, 10).replace(/-/g, '');
|
|
@@ -61,7 +61,7 @@ Plugin.init = async function (params) {
|
|
|
61
61
|
return res.json({ earned: true, points: SETTINGS.pointsPerHeartbeat, total: newBalance });
|
|
62
62
|
});
|
|
63
63
|
|
|
64
|
-
// 2. WALLET DATA (
|
|
64
|
+
// 2. WALLET DATA (Cüzdan + Geçmiş)
|
|
65
65
|
router.get('/api/niki-loyalty/wallet-data', middleware.ensureLoggedIn, async (req, res) => {
|
|
66
66
|
const uid = req.uid;
|
|
67
67
|
const today = new Date().toISOString().slice(0, 10).replace(/-/g, '');
|
|
@@ -69,7 +69,7 @@ Plugin.init = async function (params) {
|
|
|
69
69
|
const [userData, dailyData, history] = await Promise.all([
|
|
70
70
|
user.getUserFields(uid, ['niki_points']),
|
|
71
71
|
db.getObject(`niki:daily:${uid}:${today}`),
|
|
72
|
-
db.getListRange(`niki:activity:${uid}`, 0, -1)
|
|
72
|
+
db.getListRange(`niki:activity:${uid}`, 0, -1)
|
|
73
73
|
]);
|
|
74
74
|
|
|
75
75
|
const currentPoints = parseInt(userData.niki_points) || 0;
|
|
@@ -82,11 +82,12 @@ Plugin.init = async function (params) {
|
|
|
82
82
|
dailyScore: dailyScore,
|
|
83
83
|
dailyCap: SETTINGS.dailyCap,
|
|
84
84
|
dailyPercent: dailyPercent,
|
|
85
|
-
history: (history || []).reverse()
|
|
85
|
+
history: (history || []).reverse()
|
|
86
86
|
});
|
|
87
87
|
});
|
|
88
88
|
|
|
89
|
-
//
|
|
89
|
+
// --- İŞTE EKSİK OLAN KISIM BURASIYDI ---
|
|
90
|
+
// 3. KASA GEÇMİŞİ (Personel Ekranı İçin)
|
|
90
91
|
router.get('/api/niki-loyalty/kasa-history', middleware.ensureLoggedIn, async (req, res) => {
|
|
91
92
|
const isAdmin = await user.isAdministrator(req.uid);
|
|
92
93
|
const isMod = await user.isGlobalModerator(req.uid);
|
|
@@ -105,8 +106,9 @@ Plugin.init = async function (params) {
|
|
|
105
106
|
|
|
106
107
|
res.json(enrichedHistory);
|
|
107
108
|
});
|
|
109
|
+
// ---------------------------------------
|
|
108
110
|
|
|
109
|
-
// 4. QR
|
|
111
|
+
// 4. QR OLUŞTUR
|
|
110
112
|
router.post('/api/niki-loyalty/generate-qr', middleware.ensureLoggedIn, async (req, res) => {
|
|
111
113
|
const uid = req.uid;
|
|
112
114
|
const points = parseInt(await user.getUserField(uid, 'niki_points')) || 0;
|
|
@@ -115,12 +117,12 @@ Plugin.init = async function (params) {
|
|
|
115
117
|
|
|
116
118
|
const token = Math.random().toString(36).substring(2) + Date.now().toString(36);
|
|
117
119
|
await db.set(`niki:qr:${token}`, uid);
|
|
118
|
-
await db.expire(`niki:qr:${token}`, 120);
|
|
120
|
+
await db.expire(`niki:qr:${token}`, 120);
|
|
119
121
|
|
|
120
122
|
return res.json({ success: true, token: token });
|
|
121
123
|
});
|
|
122
124
|
|
|
123
|
-
// 5. QR
|
|
125
|
+
// 5. QR OKUT (Ödeme Alma)
|
|
124
126
|
router.post('/api/niki-loyalty/scan-qr', middleware.ensureLoggedIn, async (req, res) => {
|
|
125
127
|
const { token } = req.body;
|
|
126
128
|
|
|
@@ -129,25 +131,25 @@ Plugin.init = async function (params) {
|
|
|
129
131
|
if (!isAdmin && !isMod) return res.status(403).json({ success: false, message: 'Yetkisiz' });
|
|
130
132
|
|
|
131
133
|
const customerUid = await db.get(`niki:qr:${token}`);
|
|
132
|
-
if (!customerUid) return res.json({ success: false, message: '
|
|
134
|
+
if (!customerUid) return res.json({ success: false, message: 'Geçersiz Kod' });
|
|
133
135
|
|
|
134
136
|
const pts = parseInt(await user.getUserField(customerUid, 'niki_points')) || 0;
|
|
135
137
|
if (pts < SETTINGS.coffeeCost) return res.json({ success: false, message: 'Yetersiz Bakiye' });
|
|
136
138
|
|
|
137
|
-
//
|
|
139
|
+
// İŞLEM
|
|
138
140
|
await user.decrementUserFieldBy(customerUid, 'niki_points', SETTINGS.coffeeCost);
|
|
139
141
|
await db.delete(`niki:qr:${token}`);
|
|
140
142
|
|
|
141
|
-
// LOGLARI KAYDET
|
|
143
|
+
// LOGLARI KAYDET
|
|
142
144
|
const customerData = await user.getUserFields(customerUid, ['username', 'picture']);
|
|
143
145
|
|
|
144
|
-
//
|
|
146
|
+
// Cüzdan için: "Kahve Keyfi"
|
|
145
147
|
await addUserLog(customerUid, 'spend', SETTINGS.coffeeCost, 'Kahve Keyfi ☕');
|
|
146
148
|
|
|
147
|
-
//
|
|
149
|
+
// Kasa için: Kayıt
|
|
148
150
|
await addKasaLog(req.uid, customerData.username, customerUid);
|
|
149
151
|
|
|
150
|
-
return res.json({ success: true, customer: customerData, message: '
|
|
152
|
+
return res.json({ success: true, customer: customerData, message: 'Onaylandı!' });
|
|
151
153
|
});
|
|
152
154
|
|
|
153
155
|
// SAYFA ROTASI
|
|
@@ -155,7 +157,7 @@ Plugin.init = async function (params) {
|
|
|
155
157
|
const isAdmin = await user.isAdministrator(req.uid);
|
|
156
158
|
const isMod = await user.isGlobalModerator(req.uid);
|
|
157
159
|
if (!isAdmin && !isMod) return res.render('403', {});
|
|
158
|
-
res.render('niki-kasa', { title: 'Niki Kasa
|
|
160
|
+
res.render('niki-kasa', { title: 'Niki Kasa' });
|
|
159
161
|
});
|
|
160
162
|
};
|
|
161
163
|
|