nodebb-plugin-niki-loyalty 1.0.12 → 1.0.13
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 -21
- 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: 2500000,
|
|
12
12
|
coffeeCost: 250
|
|
13
13
|
};
|
|
14
14
|
|
|
15
|
-
// --- LOG
|
|
15
|
+
// --- LOG TUTMA YARDIMCILARI ---
|
|
16
16
|
async function addUserLog(uid, type, amount, desc) {
|
|
17
17
|
const logEntry = {
|
|
18
18
|
ts: Date.now(),
|
|
19
|
-
type: type,
|
|
19
|
+
type: type, // 'earn' (kazanç) veya 'spend' (harcama)
|
|
20
20
|
amt: amount,
|
|
21
21
|
txt: desc
|
|
22
22
|
};
|
|
23
|
-
//
|
|
23
|
+
// Öğrencinin listesine ekle (Son 50 işlem)
|
|
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
|
|
36
|
+
// Kasa defterine ekle (Son 100 işlem)
|
|
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 (Ders Çalışma Puanı)
|
|
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 (Öğrenci Cüzdanı ve Geçmişi)
|
|
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) // Geçmişi çek
|
|
73
73
|
]);
|
|
74
74
|
|
|
75
75
|
const currentPoints = parseInt(userData.niki_points) || 0;
|
|
@@ -82,20 +82,21 @@ Plugin.init = async function (params) {
|
|
|
82
82
|
dailyScore: dailyScore,
|
|
83
83
|
dailyCap: SETTINGS.dailyCap,
|
|
84
84
|
dailyPercent: dailyPercent,
|
|
85
|
-
history: (history || []).reverse() // En yeniden eskiye
|
|
85
|
+
history: (history || []).reverse() // En yeniden eskiye sırala
|
|
86
86
|
});
|
|
87
87
|
});
|
|
88
88
|
|
|
89
|
-
// 3. KASA GEÇMİŞİ (
|
|
89
|
+
// 3. KASA GEÇMİŞİ (Personel Dashboard İçin) - EKSİK OLAN BUYDU
|
|
90
90
|
router.get('/api/niki-loyalty/kasa-history', middleware.ensureLoggedIn, async (req, res) => {
|
|
91
91
|
const isAdmin = await user.isAdministrator(req.uid);
|
|
92
92
|
const isMod = await user.isGlobalModerator(req.uid);
|
|
93
93
|
|
|
94
94
|
if (!isAdmin && !isMod) return res.status(403).json([]);
|
|
95
95
|
|
|
96
|
+
// Veritabanından listeyi çek
|
|
96
97
|
const history = await db.getListRange('niki:kasa:history', 0, -1);
|
|
97
98
|
|
|
98
|
-
// Kullanıcı resimlerini de
|
|
99
|
+
// Kullanıcı resimlerini de ekleyerek zenginleştir
|
|
99
100
|
const enrichedHistory = await Promise.all((history || []).reverse().map(async (item) => {
|
|
100
101
|
const uData = await user.getUserFields(item.cuid, ['picture']);
|
|
101
102
|
item.picture = uData.picture;
|
|
@@ -105,7 +106,7 @@ Plugin.init = async function (params) {
|
|
|
105
106
|
res.json(enrichedHistory);
|
|
106
107
|
});
|
|
107
108
|
|
|
108
|
-
// 4. QR
|
|
109
|
+
// 4. QR TOKEN ÜRET (Öğrenci Butona Basınca)
|
|
109
110
|
router.post('/api/niki-loyalty/generate-qr', middleware.ensureLoggedIn, async (req, res) => {
|
|
110
111
|
const uid = req.uid;
|
|
111
112
|
const points = parseInt(await user.getUserField(uid, 'niki_points')) || 0;
|
|
@@ -114,12 +115,12 @@ Plugin.init = async function (params) {
|
|
|
114
115
|
|
|
115
116
|
const token = Math.random().toString(36).substring(2) + Date.now().toString(36);
|
|
116
117
|
await db.set(`niki:qr:${token}`, uid);
|
|
117
|
-
await db.expire(`niki:qr:${token}`, 120);
|
|
118
|
+
await db.expire(`niki:qr:${token}`, 120); // 2 dakika süre
|
|
118
119
|
|
|
119
120
|
return res.json({ success: true, token: token });
|
|
120
121
|
});
|
|
121
122
|
|
|
122
|
-
// 5. QR
|
|
123
|
+
// 5. QR OKUTMA (Personel Tarayınca)
|
|
123
124
|
router.post('/api/niki-loyalty/scan-qr', middleware.ensureLoggedIn, async (req, res) => {
|
|
124
125
|
const { token } = req.body;
|
|
125
126
|
|
|
@@ -128,25 +129,25 @@ Plugin.init = async function (params) {
|
|
|
128
129
|
if (!isAdmin && !isMod) return res.status(403).json({ success: false, message: 'Yetkisiz' });
|
|
129
130
|
|
|
130
131
|
const customerUid = await db.get(`niki:qr:${token}`);
|
|
131
|
-
if (!customerUid) return res.json({ success: false, message: 'Geçersiz
|
|
132
|
+
if (!customerUid) return res.json({ success: false, message: 'Kod Geçersiz veya Süresi Dolmuş' });
|
|
132
133
|
|
|
133
134
|
const pts = parseInt(await user.getUserField(customerUid, 'niki_points')) || 0;
|
|
134
135
|
if (pts < SETTINGS.coffeeCost) return res.json({ success: false, message: 'Yetersiz Bakiye' });
|
|
135
136
|
|
|
136
|
-
//
|
|
137
|
+
// İŞLEMİ YAP (Puan düş)
|
|
137
138
|
await user.decrementUserFieldBy(customerUid, 'niki_points', SETTINGS.coffeeCost);
|
|
138
139
|
await db.delete(`niki:qr:${token}`);
|
|
139
140
|
|
|
140
|
-
//
|
|
141
|
+
// LOGLARI KAYDET (Bu kısım önceden yoktu, o yüzden geçmiş boş geliyordu)
|
|
141
142
|
const customerData = await user.getUserFields(customerUid, ['username', 'picture']);
|
|
142
143
|
|
|
143
|
-
//
|
|
144
|
+
// 1. Öğrencinin Cüzdanına: "Kahve Keyfi -250"
|
|
144
145
|
await addUserLog(customerUid, 'spend', SETTINGS.coffeeCost, 'Kahve Keyfi ☕');
|
|
145
146
|
|
|
146
|
-
//
|
|
147
|
+
// 2. Kasa Defterine: "Ahmet'ten Ödeme Alındı"
|
|
147
148
|
await addKasaLog(req.uid, customerData.username, customerUid);
|
|
148
149
|
|
|
149
|
-
return res.json({ success: true, customer: customerData, message: '
|
|
150
|
+
return res.json({ success: true, customer: customerData, message: 'İşlem Başarılı!' });
|
|
150
151
|
});
|
|
151
152
|
|
|
152
153
|
// SAYFA ROTASI
|
|
@@ -154,7 +155,7 @@ Plugin.init = async function (params) {
|
|
|
154
155
|
const isAdmin = await user.isAdministrator(req.uid);
|
|
155
156
|
const isMod = await user.isGlobalModerator(req.uid);
|
|
156
157
|
if (!isAdmin && !isMod) return res.render('403', {});
|
|
157
|
-
res.render('niki-kasa', { title: 'Niki Kasa' });
|
|
158
|
+
res.render('niki-kasa', { title: 'Niki Kasa Terminali' });
|
|
158
159
|
});
|
|
159
160
|
};
|
|
160
161
|
|