38 lines
1011 B
JavaScript
38 lines
1011 B
JavaScript
// 获取积分余额
|
|
module.exports = {
|
|
main: async (event) => {
|
|
let { data = {}, userInfo, util } = event;
|
|
let { db, _ } = util;
|
|
//默认积分500
|
|
let amount = 500;
|
|
|
|
const res = await db.collection('jjx-user-points').doc(userInfo.uid).get();
|
|
|
|
if (res.data.length === 0) {
|
|
// 新用户,自动赠送 500 积分
|
|
await db.collection('jjx-user-points').add({
|
|
_id: userInfo.uid,
|
|
balance: amount,
|
|
total_earned: amount,
|
|
total_spent: 0,
|
|
gift: amount,
|
|
update_time: new Date()
|
|
});
|
|
|
|
await db.collection('jjx-points-log').add({
|
|
user_id: userInfo.uid,
|
|
type: 'earn',
|
|
amount: amount,
|
|
balance_after: amount,
|
|
reason: '新用户注册赠送',
|
|
biz_type: 'gift',
|
|
_add_time: new Date()
|
|
});
|
|
|
|
return { code: 0, msg: 'ok', data: { balance: amount, total_earned: amount, total_spent: 0, gift: amount } };
|
|
}
|
|
|
|
return { code: 0, msg: 'ok', data: res.data[0] };
|
|
}
|
|
};
|