2020-06-11 15:06:19 +08:00

164 lines
3.8 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//拓展Format函数以获取时间
Date.prototype.Format = function (fmt) { //author: meizz
var o = {
"M+": this.getMonth() + 1, //月份
"d+": this.getDate(), //日
"h+": this.getHours(), //小时
"m+": this.getMinutes(), //分
"s+": this.getSeconds(), //秒
"S": this.getMilliseconds() //毫秒
};
if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
for (var k in o)
if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
return fmt;
}
const cloud = require('wx-server-sdk')
cloud.init()
//开始审核
var startExamine = async (event) => {
//给发布人发消息说开始审核了
var userRes = await cloud.openapi.templateMessage.send({
touser: event.sendId,
data: {
keyword1: {
//姓名
value: event.sendName
},
keyword2: {
//类型
value: '发布商品'
},
keyword3: {
//申请时间
value: (new Date(new Date().getTime() + 1000 * 60 * 60 * 8)).Format("yyyy-MM-dd hh:mm:ss") //+8时差
},
keyword4: {
//审核内容
value: '商品名称、商品描述、商品图片'
},
keyword5: {
//信息概要
value: event.title
},
keyword6: {
//备注
value: '审核时长大约半天左右,请耐心等待。'
}
},
templateId: 'pRo9V3HgghrtyAKCKnQAmwyQysT1Yqr72iT4TdU6S7c',
formId: event.formId1,
}).then(res => {
return {
errCode: 200,
errMsg: 'ok'
};
}).catch(err => {
return {
errCode: 1071,
errMsg: '审核开始给用户发送消息失败',
err: err,
}
})
return userRes;
}
//审核结果
var passExamine = async (event) => {
//给被审核人发送消息说审核结果
var res = await cloud.openapi.subscribeMessage.send({
touser: event.sendId,
page: 'components/welcome/welcome',
data: {
// 审核类型
thing18: {
value: '上传物品'
},
// 审核结果
thing19: {
value: event.result
},
// 备注
thing17: {
value: event.remarks
},
},
templateId: 'PPngF-ljr1S6yixiorFJ4bj8t8mP5odUhHEnu_08Smw',
}).then(res => {
return {
errCode: 200,
errMsg: 'ok',
}
}).catch(err => {
return {
errCode: 1073,
errMsg: '审核结束时信息发送错误',
err: err,
}
})
return res;
}
exports.main = async (event, context) => {
// if(event.stats == 1) var res = await startExamine(event);
// else if(event.stats == 2) var res = await passExamine(event);
// return res;
return await passExamine(event)
}
/*
api说明
功能:用户点击上传,在这里给用户和管理员发信息审核开始,管理员审核完成在这里发结果信息
参数stats = 1 时
sendId 收件人openid
sendName :收件人姓名
title :商品标题
formId1
formId2
examineId被审核的商品id
stats = 2 时
sendId :同上
sendName :同上
result :结果 审核通过 或者 审核失败
remarks :备注 随便填
formId
备注stats = 1 的时候务必要给两个formId
注意:在前端写完界面之后要在这里加入跳转界面给管理员用。
作者RainSun
时间2019/05/01
更新:
参数:
sendId: 收件人openid
result :结果 审核通过 或者 审核失败
remarks :备注 随便填
时间2020/06/10
*/
/*
错误报告:
注:
err表示catch函数返回的错误msg就是问题描述
由于主要是返回给examine所以错误码都使用107靠msg以及err确认问题
正常:
code:200
msg:正常的返回值或者'ok'
审核开始给用户发送消息失败
code:107
msg:
err:
审核开始给管理员发送信息失败
code:107
msg:
err:
审核结束时信息发送错误
code:107
msg:
err:
*/