api接口已经完成,还有一部分的错误处理未完成
This commit is contained in:
parent
21d26a3d58
commit
e1972897ca
21
cloudfunctions/sM_addviewNum/index.js
Normal file
21
cloudfunctions/sM_addviewNum/index.js
Normal file
@ -0,0 +1,21 @@
|
||||
// 云函数入口文件
|
||||
const cloud = require('wx-server-sdk')
|
||||
|
||||
cloud.init()
|
||||
const db = cloud.database()
|
||||
// 云函数入口函数
|
||||
exports.main = async (event, context) => {
|
||||
const wxContext = cloud.getWXContext()
|
||||
await db.collection('sM_productInfo').doc(event.productId).update({
|
||||
data: {
|
||||
viewNum: db.command.inc(1)
|
||||
}
|
||||
})
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
功能说明:
|
||||
单纯的增加商品的浏览数,因为权限的问题放在云函数里,要不然就直接在小程序里写了
|
||||
因为就算没加上也无所谓,所以不返回任何值。
|
||||
*/
|
@ -1,5 +1,5 @@
|
||||
{
|
||||
"name": "sM_createProduct",
|
||||
"name": "addviewNum",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
@ -1,26 +1,55 @@
|
||||
// 云函数入口文件
|
||||
const cloud = require('wx-server-sdk')
|
||||
|
||||
//拓展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()
|
||||
const db = cloud.database()
|
||||
|
||||
//评论
|
||||
var comment = async (event) => {
|
||||
var res = await db.collection("sM_productInfo").doc(event.prodectId).update({
|
||||
var res = await db.collection("sM_productInfo").doc(event.productId).update({
|
||||
data:{
|
||||
comment: db.command.push({
|
||||
name:event.detailInfo.userName,
|
||||
avatar:event.detailInfo.avatar,
|
||||
userid:event.detailInfo._id,
|
||||
time: Date.now(),
|
||||
name:event.userInfo.userName,
|
||||
avatar:event.userInfo.avatar,
|
||||
userid:event.userInfo._id,
|
||||
time: (new Date(new Date().getTime() + 1000 * 60 * 60 * 8)).Format("yyyy-MM-dd hh:mm:ss"),
|
||||
msg: event.msg,
|
||||
reply: []
|
||||
})
|
||||
}
|
||||
}).then(res => {
|
||||
return res;
|
||||
if(res.stats.updated !== 1)
|
||||
return {
|
||||
errCode:301,
|
||||
errMsg:'评论添加失败(id错误)',
|
||||
id:event.productId
|
||||
};
|
||||
else return {
|
||||
errCode: 200,
|
||||
errMsg: 'ok',
|
||||
}
|
||||
}).catch(err => {
|
||||
return err;
|
||||
return {
|
||||
errCode: 302,
|
||||
errMsg: '评论添加失败',
|
||||
err: err,
|
||||
};
|
||||
})
|
||||
return res;
|
||||
}
|
||||
@ -28,57 +57,142 @@ var comment = async (event) => {
|
||||
//回复
|
||||
var reply = async(event) => {
|
||||
//取出原有的comment加以修改
|
||||
var oldInfo = await db.collection("sM_productInfo").doc(event.prodectId).get();
|
||||
var oldInfo = await db.collection("sM_productInfo").doc(event.productId).get();
|
||||
oldInfo.data.comment[event.replyNum].reply.push({
|
||||
name:event.detailInfo.userName,
|
||||
avatar: event.detailInfo.avatar,
|
||||
userId: event.detailInfo._id,
|
||||
name:event.userInfo.userName,
|
||||
avatar: event.userInfo.avatar,
|
||||
userId: event.userInfo._id,
|
||||
msg: event.msg,
|
||||
time: Date.now(),
|
||||
time: (new Date(new Date().getTime() + 1000 * 60 * 60 * 8)).Format("yyyy-MM-dd hh:mm:ss"),
|
||||
})
|
||||
//放回去
|
||||
await db.collection("sM_productInfo").doc(event.prodectId).update({
|
||||
var res = await db.collection("sM_productInfo").doc(event.productId).update({
|
||||
data:{
|
||||
comment: db.command.set(oldInfo.data.comment)
|
||||
}
|
||||
}).then(res => {
|
||||
if(res.stats.updated !== 1)
|
||||
return {
|
||||
errCode:303,
|
||||
errMsg:'回复添加失败(id错误)',
|
||||
id:event.productId
|
||||
};
|
||||
else return {
|
||||
errCode: 200,
|
||||
errMsg: 'ok',
|
||||
}
|
||||
}).catch(err => {
|
||||
return {
|
||||
errCode: 304,
|
||||
errMsg: '回复添加失败',
|
||||
err: err,
|
||||
};
|
||||
})
|
||||
return oldInfo.data;
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
//通知
|
||||
var notice = async (event) => {
|
||||
//取出,修改
|
||||
var userInfo = await db.collection('sM_userInfo').doc(event.replyId).get();
|
||||
//没有就初始化
|
||||
if(!userInfo.data.newMsg.reply) userInfo.data.newMsg.reply = [];
|
||||
userInfo.data.newMsg.reply.push({
|
||||
prodectId:event.prodectId,
|
||||
prodectName:event.prodectName,
|
||||
time: Date.now(),
|
||||
})
|
||||
//放回去
|
||||
await db.collection("sM_userInfo").doc(event.replyId).update({
|
||||
data:{
|
||||
newMsg: db.command.set(userInfo.data.newMsg)
|
||||
//commonMsg
|
||||
var res = await db.collection('sM_userInfo').doc(event.replyId).update({
|
||||
data: {
|
||||
commonMsg: db.command.push({
|
||||
productId:event.productId,
|
||||
productName:event.productName,
|
||||
time: (new Date(new Date().getTime() + 1000 * 60 * 60 * 8)).Format("yyyy-MM-dd hh:mm:ss"),
|
||||
iscomment:event.iscomment,
|
||||
stats:true
|
||||
})
|
||||
}
|
||||
}).then(res => {
|
||||
if(res.stats.updated !== 1)
|
||||
return {
|
||||
errCode:305,
|
||||
errMsg:'通知添加失败(id错误)',
|
||||
id:event.replyId
|
||||
};
|
||||
else return {
|
||||
errCode: 200,
|
||||
errMsg: 'ok',
|
||||
}
|
||||
}).catch(err => {
|
||||
return {
|
||||
errCode: 306,
|
||||
errMsg: '通知添加失败',
|
||||
err: err,
|
||||
};
|
||||
})
|
||||
return ;
|
||||
}
|
||||
|
||||
// 云函数入口函数
|
||||
exports.main = async (event, context) => {
|
||||
const wxContext = cloud.getWXContext()
|
||||
return res;
|
||||
}
|
||||
|
||||
// 云函数入口函数
|
||||
exports.main = async (event, context) => {
|
||||
if (event.iscomment) {
|
||||
var res = await comment(event);
|
||||
} else {
|
||||
var res = await reply(event);
|
||||
}
|
||||
notice(event);
|
||||
return res;
|
||||
// return {
|
||||
// event,
|
||||
// openid: wxContext.OPENID,
|
||||
// appid: wxContext.APPID,
|
||||
// unionid: wxContext.UNIONID,
|
||||
// }
|
||||
}
|
||||
if(res.errCode !== 200) return res;
|
||||
noticeRes = await notice(event);
|
||||
return noticeRes;
|
||||
}
|
||||
|
||||
/*
|
||||
api说明:
|
||||
参数:
|
||||
iscomment: true 是评论
|
||||
userInfo: 服务器返回的用户信息
|
||||
productId: 商品id
|
||||
msg: 评论内容
|
||||
iscomment: false 是回复
|
||||
userInfo: 同上
|
||||
productid: 同上
|
||||
msg: 评论内容
|
||||
replyNum: 回复的第几个评论
|
||||
replyId: 被回复的人的id
|
||||
productName: 商品名
|
||||
备注:回复的时候,直接在评论下边累加,方便前端for遍历,虽然看着有点难受,可能在后续版本改一下
|
||||
作者:RainSun
|
||||
时间:2019/05/01
|
||||
*/
|
||||
|
||||
/*
|
||||
错误报告:
|
||||
注:err表示catch函数返回的错误,msg就是问题描述
|
||||
|
||||
正常:
|
||||
code:200
|
||||
msg:正常的返回值或者'ok'
|
||||
|
||||
评论添加失败(id错误):
|
||||
code:301
|
||||
msg:
|
||||
id:
|
||||
|
||||
评论添加失败:
|
||||
code: 302
|
||||
msg:
|
||||
err:
|
||||
|
||||
回复添加失败(id错误):
|
||||
code: 303
|
||||
msg:
|
||||
id:
|
||||
|
||||
回复添加失败:
|
||||
code: 304
|
||||
msg:
|
||||
err:
|
||||
|
||||
通知添加失败(id错误):
|
||||
code:305
|
||||
msg:
|
||||
id:
|
||||
|
||||
通知添加失败:
|
||||
code:306
|
||||
msg:
|
||||
err:
|
||||
|
||||
*/
|
@ -1,60 +0,0 @@
|
||||
// 云函数入口文件
|
||||
const cloud = require('wx-server-sdk')
|
||||
|
||||
cloud.init()
|
||||
const db = cloud.database()
|
||||
|
||||
//新建商品,返回新商品id
|
||||
var addProduct = async (event, wxContext) => {
|
||||
var res = await db.collection("sM_productInfo").add({
|
||||
data: {
|
||||
userInfo: {
|
||||
name: event.detailInfo.userName,
|
||||
avatar: event.detailInfo.avatar,
|
||||
adds: event.adds,
|
||||
id: event.detailInfo._id,
|
||||
},
|
||||
time: Date.now(),
|
||||
productName: event.productName,
|
||||
details: event.details,
|
||||
price: event.price,
|
||||
isfree: event.isfree,
|
||||
tags: event.tags,
|
||||
viewNum: 0,
|
||||
wantUser: [],
|
||||
photos: event.photos,
|
||||
comment: [],
|
||||
warning: false,
|
||||
}
|
||||
}).then(res => {
|
||||
return res
|
||||
}).catch(err => {
|
||||
return err
|
||||
})
|
||||
return res._id;
|
||||
}
|
||||
|
||||
//把这个新商品id和名称push到用户信息里
|
||||
var rewriteUserInfo = async (id, wxContext,event) => {
|
||||
var res = await db.collection('sM_userInfo').doc(event.detailInfo._id).update({
|
||||
data: {
|
||||
issue: db.command.push({
|
||||
id:id,
|
||||
name: event.productName
|
||||
})
|
||||
}
|
||||
}).then(res => {
|
||||
return res;
|
||||
}).catch(err => {
|
||||
return err;
|
||||
})
|
||||
return res;
|
||||
}
|
||||
// 云函数入口函数
|
||||
exports.main = async (event, context) => {
|
||||
const wxContext = cloud.getWXContext()
|
||||
var newId = await addProduct(event, wxContext);
|
||||
await rewriteUserInfo(newId, wxContext, event);
|
||||
var res =await db.collection('sM_userInfo').doc(event.detailInfo._id).get();
|
||||
return res;
|
||||
}
|
7
cloudfunctions/sM_examine/config.json
Normal file
7
cloudfunctions/sM_examine/config.json
Normal file
@ -0,0 +1,7 @@
|
||||
{
|
||||
"permissions": {
|
||||
"openapi": [
|
||||
"templateMessage.send"
|
||||
]
|
||||
}
|
||||
}
|
341
cloudfunctions/sM_examine/index.js
Normal file
341
cloudfunctions/sM_examine/index.js
Normal file
@ -0,0 +1,341 @@
|
||||
// 云函数入口文件
|
||||
const cloud = require('wx-server-sdk')
|
||||
|
||||
cloud.init()
|
||||
const db = cloud.database()
|
||||
|
||||
//新建商品,返回新商品id
|
||||
var addProduct = async (event) => {
|
||||
//add成功就返回id 失败就可以catch到
|
||||
var res = await db.collection("sM_productInfo").add({
|
||||
data: {
|
||||
userName:event.userInfos.userName,
|
||||
userAvatarUrl: event.userInfos.avatarUrl,
|
||||
userId: event.userInfos._id,
|
||||
adds: event.adds,
|
||||
time: Date.now() + 60 * 60 * 8 , //+8h时差
|
||||
title: event.title,
|
||||
details: event.details,
|
||||
price: event.price,
|
||||
isfree: event.isfree,
|
||||
tag: event.tag,
|
||||
viewNum: 0,
|
||||
photos: event.photos,
|
||||
isSall:false,
|
||||
}
|
||||
}).then(res => {
|
||||
//获取id
|
||||
return {
|
||||
errCode: 200,
|
||||
errMsg: res._id,
|
||||
};
|
||||
}).catch(err => {
|
||||
//报错,然后再处理
|
||||
return {
|
||||
errCode: 101,
|
||||
errMsg: '创建新商品失败。',
|
||||
err: err,
|
||||
};
|
||||
})
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
//把这个新商品id和名称push到用户信息里
|
||||
var rewriteUserInfo = async (newId,event) => {
|
||||
var res = await db.collection('sM_userInfo').doc(event.userInfo._id).update({
|
||||
data: {
|
||||
issue: db.command.push({
|
||||
id:newId,
|
||||
title: event.title,
|
||||
details: event.details,
|
||||
})
|
||||
}
|
||||
}).then(res => {
|
||||
if(res.stats.updated === 0)
|
||||
return {
|
||||
errCode: 102,
|
||||
errMsg: '新商品id注入用户信息里时用户id错误。',
|
||||
userId: event.userInfo._id,
|
||||
};
|
||||
else
|
||||
return {
|
||||
errCode: 200,
|
||||
errMsg: res,
|
||||
};
|
||||
}).catch(err => {
|
||||
//报错
|
||||
return {
|
||||
errCode: 103,
|
||||
errMsg: '新商品id注入到用户信息里失败。',
|
||||
err: err,
|
||||
};
|
||||
})
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
//删除审核表里边的记录
|
||||
var deleteOldOne = async (id) => {
|
||||
var res = await db.collection('sM_examine').doc(id).remove().then(res => {
|
||||
if(res.stats.removed === 0) return {
|
||||
errCode: 104,
|
||||
errMsg: '删除审核表旧记录失败。(旧表id错误)',
|
||||
id:id
|
||||
};
|
||||
else return {
|
||||
errCode: 200,
|
||||
errMsg: 'ok',
|
||||
};
|
||||
}).catch(err => {
|
||||
return {
|
||||
errCode: 105,
|
||||
errMsg: '删除审核表旧记录失败。',
|
||||
err:err,
|
||||
};
|
||||
});
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
//用户点击发布,将信息推到审核表
|
||||
var update = async (event) => {
|
||||
var res = await db.collection('sM_examine').add({
|
||||
data: {
|
||||
userInfo: event.userInfos,
|
||||
title: event.title,
|
||||
details: event.details,
|
||||
adds: event.adds,
|
||||
tag: event.tag,
|
||||
price: event.price,
|
||||
isfree: event.isfree,
|
||||
photos: event.photos,
|
||||
}
|
||||
}).then(res => {
|
||||
return {
|
||||
errCode: 200,
|
||||
errMsg: res._id,
|
||||
};
|
||||
}).catch(err => {
|
||||
return {
|
||||
errCode: 106,
|
||||
errMsg: '上传到审核表失败',
|
||||
err:err,
|
||||
}
|
||||
})
|
||||
|
||||
//如果添加失败就直接返回
|
||||
if(res.errCode === 106) return res;
|
||||
|
||||
//发信息(预留错误码107:发送失败)
|
||||
var sendRes = await cloud.callFunction({
|
||||
name: 'sM_sendMsg',
|
||||
data: {
|
||||
stats: 1,
|
||||
sendId: event.userInfos._openid,
|
||||
sendName: event.userInfos.userName,
|
||||
title: event.title,
|
||||
formId1: event.formId1,
|
||||
formId2: event.formId2,
|
||||
examineId: res.errMsg,
|
||||
}
|
||||
}).then(res => {
|
||||
return res.result
|
||||
}).catch(err => {
|
||||
return {
|
||||
errCode: 107,
|
||||
errMsg: '用户点击发布函数调用错误',
|
||||
err: err,
|
||||
}
|
||||
})
|
||||
|
||||
return sendRes;
|
||||
}
|
||||
|
||||
//审核通过
|
||||
var pass = async (event) => {
|
||||
//删除审核表里的旧记录
|
||||
var delRes = await deleteOldOne(event.oldId);
|
||||
if(delRes.errCode !== 200) return delRes;
|
||||
|
||||
//向商品表里边添加记录
|
||||
var addRes = await addProduct(event);
|
||||
if(addRes.errCode === 101) return addRes;
|
||||
|
||||
//将这个表添加到用户个人信息里
|
||||
var reRes = await rewriteUserInfo(addRes.errMsg, event);
|
||||
if(reRes.errCode !== 200) return reRes;
|
||||
|
||||
//发信息(预留错误码107)
|
||||
var sendRes = await cloud.callFunction({
|
||||
name: 'sM_sendMsg',
|
||||
data: {
|
||||
stats: 2,
|
||||
sendId: event.userInfos._openid,
|
||||
sendName: event.userInfos.userName,
|
||||
result: "审核通过",
|
||||
remarks: event.remarks + "注:点击下方即可进入小程序",
|
||||
formId: event.formId,
|
||||
}
|
||||
}).then(res => {
|
||||
return res.result;
|
||||
}).catch(err => {
|
||||
return {
|
||||
errCode:107,
|
||||
errMsg: '审核通过信息发送函数调用错误',
|
||||
err: err,
|
||||
}
|
||||
})
|
||||
|
||||
return sendRes;
|
||||
}
|
||||
|
||||
//审核失败
|
||||
var fail = async(event) => {
|
||||
//删除审核表旧纪录
|
||||
var delRes = await deleteOldOne(event.oldId);
|
||||
if(delRes.errCode !== 200) return delRes;
|
||||
|
||||
//发信息(预留错误码107)
|
||||
var sendRes = await cloud.callFunction({
|
||||
name: 'sM_sendMsg',
|
||||
data: {
|
||||
stats: 2,
|
||||
sendId: event.userInfos._openid,
|
||||
sendName: event.userInfos.userName,
|
||||
result: "审核失败",
|
||||
remarks: event.remarks + "注:您的商品信息已被删除,请重新发布。",
|
||||
formId: event.formId,
|
||||
}
|
||||
}).then(res => {
|
||||
return res.result;
|
||||
}).catch(err => {
|
||||
return {
|
||||
errCode: 107,
|
||||
errMsg: '审核失败信息发送函数调用失败',
|
||||
err: err
|
||||
}
|
||||
})
|
||||
|
||||
return sendRes;
|
||||
}
|
||||
|
||||
// 云函数入口函数
|
||||
exports.main = async (event, context) => {
|
||||
//判断状态码
|
||||
if (event.stats == 1) var res = await update(event);
|
||||
else if (event.stats == 2) var res = await pass(event);
|
||||
else if (event.stats == 3) var res = await fail(event);
|
||||
else return {
|
||||
errCode: 108,
|
||||
errMsg: '未提交或非法的stats值。'
|
||||
};
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
/*
|
||||
功能简介:
|
||||
本页要完成审核和审核完成后的处理
|
||||
卖家点击发布,信息将由此页进入审核区,
|
||||
给调用sandMsg给双方同时发消息,
|
||||
管理员审核界面,
|
||||
点击通过,则传进来全部信息,,调用createproduct,备注写一个默认的,然后发信息
|
||||
点击失败,则传进来审核区的记录id,在这里删除,然后发信息
|
||||
*/
|
||||
|
||||
/*
|
||||
api说明:
|
||||
参数:stats = 1 用户点击发布时
|
||||
userInfos :数据库里边的用户完整信息
|
||||
title:商品名
|
||||
details:商品详细信息
|
||||
adds:地址
|
||||
tag:标签
|
||||
price:价格
|
||||
isfree:是否免费
|
||||
photos:照片地址数组
|
||||
formId1:
|
||||
formId2:
|
||||
stats = 2 管理员审核通过时
|
||||
userInfos :同上
|
||||
adds :同上
|
||||
title:商品名
|
||||
details:商品详细信息
|
||||
tag:标签
|
||||
price:价格
|
||||
isfree:是否免费
|
||||
photos:照片地址数组
|
||||
oldId:审核表里的数据的id(要把这个记录删除)
|
||||
remarks: 管理员发的备注信息。(默认在后边加上“注:点击下方即可进入小程序”)
|
||||
formId:
|
||||
stats = 3 管理员审核不通过时
|
||||
userInfos :同上
|
||||
oldId:审核表里的数据的id(要把这个记录删除)
|
||||
remarks: 管理员发的备注信息。(默认在后边加上“注:您的商品信息已被删除,请重新发布。”)
|
||||
formId:
|
||||
备注:stats = 1 的时候务必要给两个formId
|
||||
关联:审核之前之后都要再sendMsg里边发信息
|
||||
注意:需要获取oldId给发消息用,不过得等前端写完页面之后。
|
||||
作者:RainSun
|
||||
时间:2019/04/29
|
||||
*/
|
||||
/*
|
||||
日志:
|
||||
20190429:今天开始补完错误信息的返回。
|
||||
20190430:
|
||||
今天完成错误信息的返回,详情见下方错误报告。
|
||||
代码格式整理完成。
|
||||
|
||||
*/
|
||||
/*
|
||||
错误报告:
|
||||
注:err表示catch函数返回的错误,msg就是问题描述
|
||||
|
||||
正常:
|
||||
code:200
|
||||
msg:正常的返回值或者'ok'
|
||||
|
||||
创建新商品失败:
|
||||
code:101
|
||||
msg:
|
||||
err:
|
||||
|
||||
新商品id注入用户信息里时用户id错误:
|
||||
code:102
|
||||
msg:
|
||||
userId:
|
||||
|
||||
新商品id注入到用户信息里失败:
|
||||
code:103
|
||||
msg:
|
||||
err:
|
||||
|
||||
删除审核表旧记录失败。(旧表id错误):
|
||||
code:104
|
||||
msg:
|
||||
|
||||
删除审核表旧记录失败:
|
||||
code:105
|
||||
msg:
|
||||
err:
|
||||
|
||||
上传到审核表失败:
|
||||
code:106
|
||||
msg:
|
||||
err:
|
||||
|
||||
信息发送失败:
|
||||
code:107
|
||||
msg:
|
||||
err:
|
||||
40037: template_id不正确
|
||||
41028: form_id不正确,或者过期
|
||||
41029: form_id已被使用
|
||||
41030: page不正确
|
||||
45009: 接口调用超过限额(目前默认每个帐号日调用限额为100万)(PS:好希望我们的小程序能报这个错啊)
|
||||
|
||||
未提交或者非法的stats值:
|
||||
code:108
|
||||
msg:
|
||||
*/
|
14
cloudfunctions/sM_examine/package.json
Normal file
14
cloudfunctions/sM_examine/package.json
Normal file
@ -0,0 +1,14 @@
|
||||
{
|
||||
"name": "sM_examine",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"wx-server-sdk": "latest"
|
||||
}
|
||||
}
|
@ -14,4 +14,8 @@ exports.main = async (event, context) => {
|
||||
userInfo = userInfo.data;
|
||||
if(userInfo.length === 0) return {issign: false, userInfo: null};
|
||||
else return {isSign: true, userInfo: userInfo};
|
||||
}
|
||||
}
|
||||
/*
|
||||
功能说明:
|
||||
获取用户信息,因为是通过openId查找所以放在云函数里边。
|
||||
*/
|
128
cloudfunctions/sM_rewriteProduct/index.js
Normal file
128
cloudfunctions/sM_rewriteProduct/index.js
Normal file
@ -0,0 +1,128 @@
|
||||
//拓展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()
|
||||
const db = cloud.database();
|
||||
|
||||
//修改商品信息
|
||||
var rewriteProduct = async (event) => {
|
||||
//取出来
|
||||
var oldPInfo = await db.collection('sM_productInfo').doc(event.productId).get();
|
||||
//改信息
|
||||
if(event.isSall) {
|
||||
//卖出
|
||||
var stats = 2;
|
||||
oldPInfo.data.isSall = true;
|
||||
} else {
|
||||
//价格修改
|
||||
var stats = 1;
|
||||
if(event.newisFree) {
|
||||
oldPInfo.data.price = "免费";
|
||||
oldPInfo.data.isfree = true ;
|
||||
}else {
|
||||
oldPInfo.data.price = event.newPrice;
|
||||
oldPInfo.data.isfree = false;
|
||||
}
|
||||
}
|
||||
delete oldPInfo.data._id;
|
||||
//放回去
|
||||
var res = await db.collection('sM_productInfo').doc(event.productId).set({
|
||||
data: oldPInfo.data
|
||||
}).then(res => {
|
||||
if(res.stats.updated === 0) {
|
||||
return {
|
||||
errCode: 201,
|
||||
errMsg: '重写商品信息失败(id错误)',
|
||||
id: event.productId
|
||||
}
|
||||
} else return {
|
||||
errCode: 200,
|
||||
errMsg: 'ok'
|
||||
};
|
||||
}).catch(err => {
|
||||
return {
|
||||
errCode: 202,
|
||||
errMsg: '重写商品信息失败',
|
||||
err: err,
|
||||
}
|
||||
})
|
||||
if(res.errCode !== 200) return res;
|
||||
else return {
|
||||
errCode: 200,
|
||||
errMsg:{
|
||||
productInfo: oldPInfo.data,
|
||||
stats: stats,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//给想要的人发通知
|
||||
var sendMsg = async (productInfo,stats) => {
|
||||
var wantList = productInfo.wantUser;
|
||||
var length = wantList.length;
|
||||
for (var i = 0; i < length; i++) {
|
||||
await db.collection('sM_userInfo').doc(wantList[i]).update({
|
||||
data: {
|
||||
wantMsg: db.command.push({
|
||||
stats: stats,
|
||||
productName: productInfo.productName,
|
||||
productid: productInfo._id,
|
||||
time: (new Date(new Date().getTime() + 1000 * 60 * 60 * 8)).Format("yyyy-MM-dd hh:mm:ss") //+8时差,
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
// 云函数入口函数
|
||||
exports.main = async (event, context) => {
|
||||
var rewRes = await rewriteProduct(event);
|
||||
if(rewRes.errCode !== 200) return rewRes;
|
||||
await sendMsg(argument.productInfo,argument.stats);
|
||||
return rewRes;
|
||||
}
|
||||
|
||||
/*
|
||||
api说明:
|
||||
参数:
|
||||
productId:修改的产品id
|
||||
newPrice:新价格
|
||||
newisFree:是否免费
|
||||
isSall:是否已经卖出
|
||||
备注:isSall 和 newPrice,newisFree 二选一传参就行
|
||||
作者:RainSun
|
||||
时间:2019/05/01
|
||||
*/
|
||||
/*
|
||||
错误报告:
|
||||
注:err表示catch函数返回的错误,msg就是问题描述
|
||||
|
||||
正常:
|
||||
code:200
|
||||
msg:正常的返回值或者'ok'
|
||||
|
||||
创建新商品失败(id错误):
|
||||
code:201
|
||||
msg:
|
||||
id:
|
||||
|
||||
创建新商品失败:
|
||||
code: 202
|
||||
msg:
|
||||
err:
|
||||
*/
|
14
cloudfunctions/sM_rewriteProduct/package.json
Normal file
14
cloudfunctions/sM_rewriteProduct/package.json
Normal file
@ -0,0 +1,14 @@
|
||||
{
|
||||
"name": "sM_rewriteProduct",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"wx-server-sdk": "latest"
|
||||
}
|
||||
}
|
@ -7,38 +7,39 @@ const db = cloud.database()
|
||||
//100 时间排序
|
||||
var timeSort = (status) => {
|
||||
//101 正序 102 倒序
|
||||
if (status == 101) return db.collection('sM_productInfo').orderBy('time', 'asc').get();
|
||||
if (status == 101) return db.collection('sM_productInfo').where({issall:false}).orderBy('time', 'asc').get();
|
||||
else return db.collection('sM_productInfo').orderBy('time', 'desc').get();
|
||||
}
|
||||
|
||||
//200 浏览量排序
|
||||
var viewSort = (status) => {
|
||||
//201 正序 202 倒序
|
||||
if (status == 201) return db.collection('sM_productInfo').orderBy('viewNum', 'asc').get();
|
||||
if (status == 201) return db.collection('sM_productInfo').where({issall:false}).orderBy('viewNum', 'asc').get();
|
||||
else return db.collection('sM_productInfo').orderBy('viewNum', 'desc').get();
|
||||
}
|
||||
|
||||
//300 价格排序
|
||||
var priceSort = (status) => {
|
||||
//301 正序 302 倒序
|
||||
if (status == 301) return db.collection('sM_productInfo').orderBy('price', 'asc').get();
|
||||
if (status == 301) return db.collection('sM_productInfo').where({issall:false}).orderBy('price', 'asc').get();
|
||||
else return db.collection('sM_productInfo').orderBy('price', 'desc').get();
|
||||
}
|
||||
|
||||
//400 免费
|
||||
var freeSort = (status) => {
|
||||
//401 时间正序 402 时间倒序
|
||||
if (status == 401) return db.collection('sM_productInfo').where({isfree: true,}).orderBy('time', 'asc').get();
|
||||
else return db.collection('sM_productInfo').where({ isfree: true, }).orderBy('time', 'desc').get();
|
||||
if (status == 401) return db.collection('sM_productInfo').where({isfree: true,issall:false}).orderBy('time', 'asc').get();
|
||||
else return db.collection('sM_productInfo').where({ isfree: true, issall:false}).orderBy('time', 'desc').get();
|
||||
}
|
||||
|
||||
//500 模糊搜索(默认时间倒序)
|
||||
var fuzzySearch = (argument) => {
|
||||
return db.collection('sM_productInfo').where({
|
||||
productName: db.RegExp({ //使用正则表达式
|
||||
name: db.RegExp({ //使用正则表达式
|
||||
regexp: argument,
|
||||
options: 'i', //大小写不区分
|
||||
})
|
||||
}),
|
||||
issall:false
|
||||
}).orderBy('time', 'desc').get();
|
||||
}
|
||||
|
||||
@ -103,7 +104,8 @@ var tagClassify = async (status) => {
|
||||
//标签查询
|
||||
var tagSearch = (tag,type,order) => {
|
||||
return db.collection('sM_productInfo').where({
|
||||
tag:tag
|
||||
tag:tag,
|
||||
issall:false
|
||||
}).orderBy(type, order).get();
|
||||
}
|
||||
|
||||
|
7
cloudfunctions/sM_sendMsg/config.json
Normal file
7
cloudfunctions/sM_sendMsg/config.json
Normal file
@ -0,0 +1,7 @@
|
||||
{
|
||||
"permissions": {
|
||||
"openapi": [
|
||||
"templateMessage.send"
|
||||
]
|
||||
}
|
||||
}
|
193
cloudfunctions/sM_sendMsg/index.js
Normal file
193
cloudfunctions/sM_sendMsg/index.js
Normal file
@ -0,0 +1,193 @@
|
||||
//拓展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: 107,
|
||||
errMsg: '审核开始给用户发送消息失败',
|
||||
err: err,
|
||||
}
|
||||
})
|
||||
|
||||
if(userRes.errCode !== 200) return userRes;
|
||||
|
||||
//给管理员发消息说有东西等待审核
|
||||
var adminRes = await cloud.openapi.templateMessage.send({
|
||||
touser: 'otxHM4icvFkfMcaqxTH1zSNKhKVs',
|
||||
data: {
|
||||
keyword1: {
|
||||
//申请人
|
||||
value: event.sendName
|
||||
},
|
||||
keyword2: {
|
||||
//申请时间
|
||||
value: (new Date(new Date().getTime() + 1000 * 60 * 60 * 8)).Format("yyyy-MM-dd hh:mm:ss") //+8时差
|
||||
},
|
||||
keyword3: {
|
||||
//审核类型
|
||||
value: "发布商品"
|
||||
}
|
||||
},
|
||||
templateId: 'AhGvD5GBiM16D1dLnOxdUjTx0-NyID0HlbH904Lh8XM',
|
||||
formId: event.formId2,
|
||||
}).then(res => {
|
||||
return {
|
||||
errCode: 200,
|
||||
errMsg: 'ok'
|
||||
}
|
||||
}).catch(err => {
|
||||
return {
|
||||
errCode: 107,
|
||||
errMsg: '审核开始给管理员发送信息失败。',
|
||||
err: err,
|
||||
}
|
||||
})
|
||||
return adminRes;
|
||||
}
|
||||
|
||||
//审核结果
|
||||
var passExamine = async (event) => {
|
||||
//给被审核人发送消息说审核结果
|
||||
var res = await cloud.openapi.templateMessage.send({
|
||||
touser: event.sendId,
|
||||
data: {
|
||||
keyword1: {
|
||||
//申请人
|
||||
value: event.sendName
|
||||
},
|
||||
keyword2: {
|
||||
//申请内容
|
||||
value: "发布商品"
|
||||
},
|
||||
keyword3: {
|
||||
//审核结果
|
||||
value: event.result
|
||||
},
|
||||
keyword4: {
|
||||
//备注
|
||||
value: event.remarks
|
||||
}
|
||||
},
|
||||
templateId: 'ZSTBhVkZwfX2ZgDfiAL8uBMeuJ_zFJfJFch4zqzpBZ8',
|
||||
formId: event.formId,
|
||||
}).then(res => {
|
||||
return {
|
||||
errCode: 200,
|
||||
errMsg: 'ok',
|
||||
}
|
||||
}).catch(err => {
|
||||
return {
|
||||
errCode: 107,
|
||||
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;
|
||||
}
|
||||
|
||||
/*
|
||||
api说明:
|
||||
参数:stats = 1 时
|
||||
sendId :收件人openid
|
||||
sendName :收件人姓名
|
||||
title :商品标题
|
||||
formId1
|
||||
formId2
|
||||
examineId:被审核的商品id
|
||||
stats = 2 时
|
||||
sendId :同上
|
||||
sendName :同上
|
||||
result :结果 审核通过 或者 审核失败
|
||||
remarks :备注 随便填
|
||||
formId
|
||||
备注:stats = 1 的时候务必要给两个formId
|
||||
关联:用户点击上传,在这里发信息审核,审核完成在这里发结果信息
|
||||
注意:在前端写完界面之后要在这里加入跳转界面给管理员用。
|
||||
作者:RainSun
|
||||
*/
|
||||
/*
|
||||
错误报告:
|
||||
注:
|
||||
err表示catch函数返回的错误,msg就是问题描述
|
||||
由于主要是返回给examine所以错误码都使用107,靠msg以及err确认问题
|
||||
|
||||
正常:
|
||||
code:200
|
||||
msg:正常的返回值或者'ok'
|
||||
|
||||
审核开始给用户发送消息失败
|
||||
code:107
|
||||
msg:
|
||||
err:
|
||||
|
||||
审核开始给管理员发送信息失败
|
||||
code:107
|
||||
msg:
|
||||
err:
|
||||
|
||||
审核结束时信息发送错误
|
||||
code:107
|
||||
msg:
|
||||
err:
|
||||
|
||||
*/
|
14
cloudfunctions/sM_sendMsg/package.json
Normal file
14
cloudfunctions/sM_sendMsg/package.json
Normal file
@ -0,0 +1,14 @@
|
||||
{
|
||||
"name": "sM_sendMsg",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"wx-server-sdk": "latest"
|
||||
}
|
||||
}
|
46
cloudfunctions/sM_want/index.js
Normal file
46
cloudfunctions/sM_want/index.js
Normal file
@ -0,0 +1,46 @@
|
||||
// 云函数入口文件
|
||||
const cloud = require('wx-server-sdk')
|
||||
|
||||
cloud.init()
|
||||
const db = cloud.database();
|
||||
|
||||
//改商品信息
|
||||
var rewriteProduct = async(event) => {
|
||||
var res = db.collection('sM_productInfo').doc(event.productId).update({
|
||||
data: {
|
||||
wantUser: db.command.push(event.detailInfo._id)
|
||||
}
|
||||
}).then(res => {
|
||||
return res;
|
||||
}).catch(err => {
|
||||
return res;
|
||||
})
|
||||
return res;
|
||||
}
|
||||
|
||||
//改个人信息
|
||||
var rewriteUser = async(event) => {
|
||||
var res = db.collection('sM_userInfo').doc(event.detailInfo._id).update({
|
||||
data: {
|
||||
want: db.command.push({
|
||||
productId:event.productId,
|
||||
productName:event.productName
|
||||
})
|
||||
}
|
||||
}).then(res => {
|
||||
return res;
|
||||
}).catch(err => {
|
||||
return err;
|
||||
})
|
||||
return res;
|
||||
}
|
||||
|
||||
// 云函数入口函数
|
||||
exports.main = async (event, context) => {
|
||||
const wxContext = cloud.getWXContext()
|
||||
var res1 = await rewriteProduct(event);
|
||||
var res2 = await rewriteUser(event);
|
||||
if(res1.stats.updated === 1 && res2.stats.updated === 1)
|
||||
return true;
|
||||
else return false;
|
||||
}
|
14
cloudfunctions/sM_want/package.json
Normal file
14
cloudfunctions/sM_want/package.json
Normal file
@ -0,0 +1,14 @@
|
||||
{
|
||||
"name": "sM_want",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"wx-server-sdk": "latest"
|
||||
}
|
||||
}
|
@ -1,22 +1,3 @@
|
||||
wx.cloud.callFunction({
|
||||
name: 'sM_createProduct',
|
||||
data: {
|
||||
adds: '',
|
||||
productName: '',
|
||||
details: '',
|
||||
price: 0,
|
||||
isfree: true,
|
||||
tags: '',
|
||||
photos: ["", ""],
|
||||
detailInfo:detailInfo
|
||||
}
|
||||
}).then(res => {
|
||||
console.log(res);
|
||||
}).catch(err => {
|
||||
console.log(err);
|
||||
})
|
||||
|
||||
|
||||
wx.cloud.callFunction({
|
||||
name: 'sM_searchProductList',
|
||||
data: {
|
||||
@ -33,17 +14,10 @@ wx.cloud.callFunction({
|
||||
db.collection("sM_userInfo").add({
|
||||
data: {
|
||||
userName: userInfo.nickName,
|
||||
avatar: userInfo.avatarUrl,
|
||||
avatarUrl: userInfo.avatarUrl,
|
||||
phone: "15143211127",
|
||||
wxid: "15143211127",
|
||||
adds: "南区二舍",
|
||||
want: [],
|
||||
issue: [],
|
||||
newMsg: {
|
||||
want: [],
|
||||
reply: []
|
||||
},
|
||||
warning: [],
|
||||
}
|
||||
}).then(res => {
|
||||
console.log(res);
|
||||
@ -68,8 +42,8 @@ wx.cloud.callFunction({
|
||||
name: 'sM_comment',
|
||||
data: {
|
||||
iscomment:iscomment,
|
||||
detailInfo:detailInfo,
|
||||
prodectId:"96c1cbbe5cbfbcd80599b5253d4fe6ba",
|
||||
userInfo:detailInfo,
|
||||
productId:"96c1cbbe5cbfbcd80599b5253d4fe6ba",
|
||||
msg:"小东西真精致",
|
||||
}
|
||||
}).then(res => {
|
||||
@ -80,20 +54,109 @@ wx.cloud.callFunction({
|
||||
|
||||
|
||||
//comment 前端判断是回复还是评论
|
||||
var iscomment = false,replyName = "英树",replyNum = 1, replyId = 'ee3099285cc0247005d90def39a28f1b', prodectId = "96c1cbbe5cbfbcd80599b5253d4fe6ba", msg = '小东西真精致', prodectName = "大碗宽面";
|
||||
var iscomment = false,replyName = "英树",replyNum = 1, replyId = 'ee3099285cc0247005d90def39a28f1b', productId = "96c1cbbe5cbfbcd80599b5253d4fe6ba", msg = '小东西真精致', productName = "大碗宽面";
|
||||
wx.cloud.callFunction({
|
||||
name: 'sM_comment',
|
||||
data: {
|
||||
iscomment:iscomment,
|
||||
detailInfo:detailInfo,
|
||||
prodectId: prodectId,
|
||||
userInfo:detailInfo,
|
||||
productId: productId,
|
||||
msg:'@'+replyName+':'+msg,
|
||||
replyNum : replyNum,
|
||||
replyId : replyId,
|
||||
prodectName: prodectName,
|
||||
productName: productName,
|
||||
}
|
||||
}).then(res => {
|
||||
console.log(res.result) //新的当前商品信息
|
||||
}).catch(err => {
|
||||
console.log(err)
|
||||
})
|
||||
|
||||
//想要,先改商品信息,再改个人信息
|
||||
var productId = "96c1cbbe5cbfbcd80599b5253d4fe6ba", productName = "大碗宽面";
|
||||
wx.cloud.callFunction({
|
||||
name: 'sM_want',
|
||||
data: {
|
||||
detailInfo:detailInfo,
|
||||
productId: productId,
|
||||
productName: productName,
|
||||
}
|
||||
}).then(res => {
|
||||
console.log(res.result) //true就是成功了,false就是失败
|
||||
}).catch(err => {
|
||||
console.log(err)
|
||||
})
|
||||
|
||||
|
||||
var productId = "96c1cbbe5cbfbcd80599b5253d4fe6ba";
|
||||
wx.cloud.callFunction({
|
||||
name: 'sM_addviewNum',
|
||||
data: {
|
||||
productId: productId,
|
||||
}
|
||||
}).then(res => {
|
||||
console.log(res.result) //true就是成功了,false就是失败
|
||||
}).catch(err => {
|
||||
console.log(err)
|
||||
})
|
||||
|
||||
//修改商品信息,先改商品,然后再给want的人们发通知
|
||||
var productId = "96c1cbbe5cbfbcd80599b5253d4fe6ba",newPrice = 75,newisFree = false,isSall = false;
|
||||
wx.cloud.callFunction({
|
||||
name: 'sM_rewriteProduct',
|
||||
data: {
|
||||
productId: productId,
|
||||
newPrice:newPrice,
|
||||
newisFree:newisFree,
|
||||
isSall:isSall,
|
||||
}
|
||||
}).then(res => {
|
||||
console.log(res.result) //true就是成功了,false就是失败
|
||||
}).catch(err => {
|
||||
console.log(err)
|
||||
})
|
||||
|
||||
//先把接口写完再回来改调用
|
||||
//发布(开始审核)先调用creatProduct如果创建成功然后再那个函数里边调用这个
|
||||
//在data里边有一个id变量;前端写的时候要加一个是否要发布,获取一个id存着,然后一起发给这个函数
|
||||
if(this.data.id.length == 0) {
|
||||
this.data.id = e.detail.formId
|
||||
}else {
|
||||
var that = this;
|
||||
var sendId = 'otxHM4icvFkfMcaqxTH1zSNKhKVs',detail="巴拉巴拉",sendName= "赵英博";
|
||||
wx.cloud.callFunction({
|
||||
name: 'sM_sendMsg',
|
||||
data: {
|
||||
formId1: e.detail.formId,
|
||||
formId2: that.data.id,
|
||||
sendId: sendId,
|
||||
detail: detail,
|
||||
sendName: sendName,
|
||||
stats: 1 //开始
|
||||
}
|
||||
}).then(res => {
|
||||
console.log(res)
|
||||
that.data.id = null;
|
||||
}).catch(err => {
|
||||
console.log(err)
|
||||
})
|
||||
}
|
||||
|
||||
//审核结果
|
||||
var sendId = 'otxHM4icvFkfMcaqxTH1zSNKhKVs',sendName= "赵英博";
|
||||
wx.cloud.callFunction({
|
||||
name: 'sM_sendMsg',
|
||||
data: {
|
||||
formId: e.detail.formId,
|
||||
sendId: sendId, //给谁发
|
||||
sendName: sendName, //发给谁的名字
|
||||
result: "审核失败", //结果:通过或者失败
|
||||
remarks:"您的商品信息不够完整,请点击下方修改" ,//备注,随便写
|
||||
stats: 2 //结果
|
||||
}
|
||||
}).then(res => {
|
||||
console.log(res)
|
||||
that.data.id = null;
|
||||
}).catch(err => {
|
||||
console.log(err)
|
||||
})
|
@ -10,23 +10,7 @@ App({
|
||||
success(res) {
|
||||
userInfo = res.userInfo
|
||||
wx.setStorageSync('userInfo', res.userInfo);
|
||||
|
||||
wx.cloud.init({
|
||||
traceUser: true,
|
||||
})
|
||||
const db = wx.cloud.database();
|
||||
console.log(userInfo)
|
||||
//登录
|
||||
wx.cloud.callFunction({
|
||||
name: "sM_login"
|
||||
}).then(res => {
|
||||
console.log(res.result.userInfo[0])
|
||||
detailInfo = res.result.userInfo[0];
|
||||
|
||||
|
||||
}).catch(err => {
|
||||
console.log(err)
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@ -1,12 +1,13 @@
|
||||
{
|
||||
"pages": [
|
||||
"components/homePage/homePage"
|
||||
],
|
||||
"window": {
|
||||
"backgroundColor": "#F6F6F6",
|
||||
"backgroundTextStyle": "light",
|
||||
"navigationBarBackgroundColor": "#ffffff",
|
||||
"navigationBarTitleText": "二手交易",
|
||||
"navigationBarTextStyle": "black"
|
||||
}
|
||||
}
|
||||
{
|
||||
"pages": [
|
||||
"components/homePage/homePage"
|
||||
],
|
||||
"window": {
|
||||
"backgroundColor": "#F6F6F6",
|
||||
"backgroundTextStyle": "light",
|
||||
"navigationBarBackgroundColor": "#ffffff",
|
||||
"navigationBarTitleText": "二手交易",
|
||||
"navigationBarTextStyle": "black"
|
||||
},
|
||||
"sitemapLocation": "sitemap.json"
|
||||
}
|
@ -1,4 +1,5 @@
|
||||
// components/homePage/homePage.js
|
||||
var App = getApp();
|
||||
Page({
|
||||
|
||||
/**
|
||||
@ -6,67 +7,102 @@ Page({
|
||||
*/
|
||||
data: {
|
||||
canIUse: wx.canIUse('button.open-type.getUserInfo'),
|
||||
userInfo:null,
|
||||
userInfo: null,
|
||||
formId: null,
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面加载
|
||||
*/
|
||||
onLoad: function (options) {
|
||||
|
||||
|
||||
|
||||
onLoad: function(options) {
|
||||
wx.cloud.init({
|
||||
traceUser: true,
|
||||
})
|
||||
wx.cloud.callFunction({
|
||||
name: "sM_login"
|
||||
}).then(res => {
|
||||
// console.log(res.result.userInfo[0])
|
||||
this.data.userInfo = res.result.userInfo[0];
|
||||
console.log(this.data.userInfo)
|
||||
}).catch(err => {
|
||||
console.log(err)
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面初次渲染完成
|
||||
*/
|
||||
onReady: function () {
|
||||
onReady: function() {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面显示
|
||||
*/
|
||||
onShow: function () {
|
||||
onShow: function() {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面隐藏
|
||||
*/
|
||||
onHide: function () {
|
||||
onHide: function() {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面卸载
|
||||
*/
|
||||
onUnload: function () {
|
||||
onUnload: function() {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 页面相关事件处理函数--监听用户下拉动作
|
||||
*/
|
||||
onPullDownRefresh: function () {
|
||||
onPullDownRefresh: function() {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 页面上拉触底事件的处理函数
|
||||
*/
|
||||
onReachBottom: function () {
|
||||
onReachBottom: function() {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 用户点击右上角分享
|
||||
*/
|
||||
onShareAppMessage: function () {
|
||||
onShareAppMessage: function() {
|
||||
|
||||
},
|
||||
bindGetUserInfo(e) {
|
||||
|
||||
bindGetUserInfo: (e) => {
|
||||
console.log(e.detail.userInfo)
|
||||
}
|
||||
},
|
||||
|
||||
registerFormSubmit: function(e) {
|
||||
var that = this;
|
||||
var userInfo = this.data.userInfo
|
||||
wx.cloud.callFunction({
|
||||
name: 'sM_examine',
|
||||
data: {
|
||||
stats: 3,
|
||||
userInfos: userInfo,
|
||||
oldId: 'c8a75c29-7a45-49cc-a146-d4fefc4898a4',
|
||||
remarks: '信息不完整,图片不清晰。',
|
||||
formId:e.detail.formId,
|
||||
}
|
||||
}).then(res => {
|
||||
console.log(res)
|
||||
}).catch(err => {
|
||||
console.log(err)
|
||||
})
|
||||
console.log(e.detail.formId)
|
||||
},
|
||||
|
||||
verifyCancleAction: function() {
|
||||
|
||||
},
|
||||
})
|
@ -6,3 +6,4 @@
|
||||
授权登录
|
||||
</button>
|
||||
|
||||
<form bindsubmit='registerFormSubmit' report-submit='true'> <view class='buttons'> <button class='canclebtn' bindtap='verifyCancleAction'>取消</button> <button class='confirmbtn' form-type='submit'>确定</button> </view> </form>
|
7
miniprogram/sitemap.json
Normal file
7
miniprogram/sitemap.json
Normal file
@ -0,0 +1,7 @@
|
||||
{
|
||||
"desc": "关于本文件的更多信息,请参考文档 https://developers.weixin.qq.com/miniprogram/dev/framework/sitemap.html",
|
||||
"rules": [{
|
||||
"action": "allow",
|
||||
"page": "*"
|
||||
}]
|
||||
}
|
@ -11,6 +11,9 @@
|
||||
"appid": "wx0df150c438e4c8f0",
|
||||
"projectname": "schoolMarket",
|
||||
"libVersion": "2.2.5",
|
||||
"simulatorType": "wechat",
|
||||
"simulatorPluginLibVersion": {},
|
||||
"cloudfunctionTemplateRoot": "cloudfunctionTemplate",
|
||||
"condition": {
|
||||
"search": {
|
||||
"current": -1,
|
||||
|
Loading…
x
Reference in New Issue
Block a user