Skip to content

Commit

Permalink
积分功能v2版本
Browse files Browse the repository at this point in the history
  • Loading branch information
CavinCao committed Apr 23, 2020
1 parent 831149c commit 5f1cd31
Show file tree
Hide file tree
Showing 6 changed files with 316 additions and 65 deletions.
112 changes: 110 additions & 2 deletions cloudfunctions/memberService/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,97 @@ exports.main = async (event, context) => {
case 'addShareDetail': {
return addShareDetail(event)
}
case 'addSignAgain':{
return addSignAgain(event)
}
default: break
}
}

async function addSignAgain(event)
{
try {
const wxContext = cloud.getWXContext()
let memberInfos = await db.collection('mini_member').where({
openId: wxContext.OPENID
}).get();

const tasks = []
let pointCount = 1

if (memberInfos.data.length === 0) {
let task1 = db.collection('mini_member').add({
data: {
openId: wxContext.OPENID,
totalSignedCount: 1,//累计签到数
continueSignedCount: 1,//持续签到
totalPoints: 1,//积分
lastSignedDate: "",//最后一次签到日期
level: 1,//会员等级(预留)
unreadMessgeCount: 0,//未读消息(预留)
modifyTime: new Date().getTime(),
avatarUrl: event.info.avatarUrl,//头像
nickName: event.info.nickName,//昵称
sighRightCount:_.inc(-1),
applyStatus: 0//申请状态 0:默认 1:申请中 2:申请通过 3:申请驳回
}
})
tasks.push(task1)
}
else {
let memberInfo = memberInfos.data[0]
let continueSignedCount = memberInfo.continueSignedCount + 1

pointCount = continueSignedCount
if (continueSignedCount > 30) {
pointCount = 30
}

let task2 = db.collection('mini_member').doc(memberInfo._id).update({
data: {
totalSignedCount: _.inc(1),
continueSignedCount: continueSignedCount,
totalPoints: _.inc(pointCount),
sighRightCount:_.inc(-1),
modifyTime: new Date().getTime()
}
});
tasks.push(task2)
}

//签到明细
let task3 = db.collection('mini_sign_detail').add({
data: {
openId: wxContext.OPENID,
year: event.info.year.toString(),
month: event.info.month.toString(),
day: event.info.day.toString(),
createTime: new Date().getTime()
}
})
tasks.push(task3)

//积分明细
let task5 = db.collection('mini_point_detail').add({
data: {
openId: wxContext.OPENID,
operateType: 0,//0:获得 1:使用 2:过期
count: pointCount,
desc: "签到得积分",
date: (new Date()).toFormat("YYYY-MM-DD HH24:MI:SS"),
createTime: new Date().getTime()
}
})
tasks.push(task5)
await Promise.all(tasks)
return true
}
catch (e) {
console.error(e)
return false
}
}

/**
* 新增签到
* @param {} event
Expand Down Expand Up @@ -163,6 +250,8 @@ async function addPoints(event) {
let pointCount = 0;
let desc = ""
let operateType = 0
let sighRight=false
let highRight=false

switch (event.taskType) {
case 'taskVideo': {
Expand All @@ -181,6 +270,20 @@ async function addPoints(event) {
operateType = 1
break
}
case 'forgetSignRight':{
pointCount = -200
desc = "漏签到补签权益"
operateType = 1
sighRight=true
break
}
case 'highNicknameRight':{
pointCount = -10000
desc = "昵称永久高亮"
operateType = 1
highRight=true
break
}
default: break
}

Expand All @@ -201,17 +304,22 @@ async function addPoints(event) {
modifyTime: new Date().getTime(),
avatarUrl: event.info.avatarUrl,//头像
nickName: event.info.nickName,//昵称
applyStatus: 0//申请状态 0:默认 1:申请中 2:申请通过 3:申请驳回
applyStatus: 0,//申请状态 0:默认 1:申请中 2:申请通过 3:申请驳回
sighRightCount:sighRight?1:0,
highRight:highRight
}
})
tasks.push(task1)
}
else {
let sighRightCount=sighRight?1:0
let memberInfo = memberInfos.data[0]
let task2 = db.collection('mini_member').doc(memberInfo._id).update({
data: {
totalPoints: _.inc(pointCount),
modifyTime: new Date().getTime()
modifyTime: new Date().getTime(),
sighRightCount:_.inc(sighRightCount),
highRight:highRight?true:memberInfo.highRight
}
});
tasks.push(task2)
Expand Down
92 changes: 47 additions & 45 deletions miniprogram/pages/mine/mine.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Page({
showRedDot: '',
signedDays: 0,//连续签到天数
signed: 0,
signedRightCount: 0,
applyStatus: 0,
showVIPModal: false,
signBtnTxt: "每日签到",
Expand Down Expand Up @@ -168,7 +169,7 @@ Page({
*/
btnSigned: async function (e) {
wx.navigateTo({
url: '../mine/sign/sign?signedDays=' + this.data.signedDays + '&signed=' + this.data.signed
url: '../mine/sign/sign?signedDays=' + this.data.signedDays + '&signed=' + this.data.signed + '&signedRightCount=' + this.data.signedRightCount
})
},

Expand Down Expand Up @@ -272,55 +273,55 @@ Page({
})
},

/**
/**
* 正式提交
*/
submitApplyVip: async function (accept, templateId, that) {
try {
submitApplyVip: async function (accept, templateId, that) {
try {

wx.showLoading({
title: '提交中...',
})
console.info(app.globalData.userInfo)
let info = {
nickName: app.globalData.userInfo.nickName,
avatarUrl: app.globalData.userInfo.avatarUrl,
accept: accept,
templateId: templateId
}
let res = await api.applyVip(info)
console.info(res)
if (res.result) {
wx.showToast({
title: "申请成功,等待审批",
icon: "none",
duration: 3000
});
this.setData({
showVIPModal: false,
applyStatus: 1
wx.showLoading({
title: '提交中...',
})
console.info(app.globalData.userInfo)
let info = {
nickName: app.globalData.userInfo.nickName,
avatarUrl: app.globalData.userInfo.avatarUrl,
accept: accept,
templateId: templateId
}
let res = await api.applyVip(info)
console.info(res)
if (res.result) {
wx.showToast({
title: "申请成功,等待审批",
icon: "none",
duration: 3000
});
this.setData({
showVIPModal: false,
applyStatus: 1
})
}
else {
wx.showToast({
title: "程序出错啦",
icon: "none",
duration: 3000
});
}

wx.hideLoading()
}
else {
catch (err) {
wx.showToast({
title: "程序出错啦",
icon: "none",
duration: 3000
});
title: '程序有一点点小异常,操作失败啦',
icon: 'none',
duration: 1500
})
console.info(err)
wx.hideLoading()
}

wx.hideLoading()
}
catch (err) {
wx.showToast({
title: '程序有一点点小异常,操作失败啦',
icon: 'none',
duration: 1500
})
console.info(err)
wx.hideLoading()
}
},
},


/**
Expand All @@ -329,7 +330,7 @@ submitApplyVip: async function (accept, templateId, that) {
*/
applyVip: async function (e) {
let that = this
let tempalteId='DI_AuJDmFXnNuME1vpX_hY2yw1pR6kFXPZ7ZAQ0uLOY'
let tempalteId = 'DI_AuJDmFXnNuME1vpX_hY2yw1pR6kFXPZ7ZAQ0uLOY'
wx.requestSubscribeMessage({
tmplIds: [tempalteId],
success(res) {
Expand Down Expand Up @@ -367,7 +368,8 @@ submitApplyVip: async function (accept, templateId, that) {
signBtnTxt: util.formatTime(new Date()) == memberInfo.lastSignedDate ? "今日已签到" : "每日签到",
vipDesc: Number(memberInfo.level) > 1 ? "VIP用户" : "点击申请VIP",
isVip: Number(memberInfo.level) > 1,
applyStatus: memberInfo.applyStatus
applyStatus: memberInfo.applyStatus,
signedRightCount: memberInfo.sighRightCount == undefined ? 0 : memberInfo.sighRightCount
})
}
}
Expand Down
73 changes: 64 additions & 9 deletions miniprogram/pages/mine/point/point.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ Page({
applyStatus: 0,
showLogin: false,
showPointDescModal: false,//积分说明弹窗
highLighted:false,
highLightBtnTxt:"立即兑换",
highLighted: false,
highLightBtnTxt: "立即兑换",
shareList: [{ nickName: "待邀请", bgUrl: "bg-gary", icon: "cuIcon-friendadd", style: "" }, { nickName: "待邀请", bgUrl: "bg-gary", icon: "cuIcon-friendadd" }, { nickName: "待邀请", bgUrl: "bg-gary", icon: "cuIcon-friendadd" }, { nickName: "待邀请", bgUrl: "bg-gary", icon: "cuIcon-friendadd" }, { nickName: "待邀请", bgUrl: "bg-gary", icon: "cuIcon-friendadd" }]
},

Expand Down Expand Up @@ -71,17 +71,17 @@ Page({
}

let shareList = await api.getShareDetailList(app.globalData.openid, util.formatTime(new Date()))
let defaultShareList=that.data.shareList
let defaultShareList = that.data.shareList
console.info(shareList)
if (shareList.data.length > 0) {
let i=0
let i = 0
shareList.data.forEach(item => {
defaultShareList[i].nickName=item.nickName
defaultShareList[i].bgUrl=""
defaultShareList[i].icon=""
defaultShareList[i].style="background-image:url("+item.avatarUrl+");"
defaultShareList[i].nickName = item.nickName
defaultShareList[i].bgUrl = ""
defaultShareList[i].icon = ""
defaultShareList[i].style = "background-image:url(" + item.avatarUrl + ");"
i++
});
});

that.setData({
shareList: defaultShareList
Expand Down Expand Up @@ -322,4 +322,59 @@ Page({
delta: 1
})
},

/**
* 兑换漏签权益
* @param {*} e
*/
clickForgetRight: function (e) {
let that = this
if (that.data.totalPoints < 200) {
wx.showToast({
title: "很抱歉,您的积分不够",
icon: "none",
duration: 4000
});
return;
}

wx.showModal({
title: '提示',
content: '是否确认兑换?',
success(res) {
if (res.confirm) {
wx.showLoading({
title: '处理中...',
})
let info = {
nickName: app.globalData.userInfo.nickName,
avatarUrl: app.globalData.userInfo.avatarUrl,
}
api.addPoints("forgetSignRight", info).then((res) => {
console.info(res)
if (res.result) {
that.setData({
totalPoints: Number(that.data.totalPoints) - 200
})
wx.showToast({
title: "兑换成功",
icon: "none",
duration: 3000
});
}
else {
wx.showToast({
title: "程序有些小异常",
icon: "none",
duration: 3000
});
}
wx.hideLoading()
})
} else if (res.cancel) {
console.log('用户点击取消')
}
}
})
}
})
Loading

0 comments on commit 5f1cd31

Please sign in to comment.