// 云函数入口文件
const cloud = require('wx-server-sdk')
cloud.init({ env:""})
const db=cloud.database();
const _=db.command;
const $=db.command.aggregate;
// 云函数入口函数
exports.main = async (event, context) => {
var type=event.type?event.type:""
// 获取销量排行榜
if(type=="top"){
return await db.collection("ktmall_product").where({
checked:true
}).orderBy("sales","desc").limit(6).get()
}
if(type=="banner"){
return await db.collection("ktmall_product").where({
checked:true,
recommend:true
}).orderBy("_updateTime","desc").limit(4).get()
}
if(type=="category"){
// 查询首页的所有分类的列表
return await db.collection("ktmall_classify").aggregate()
.lookup({
from:"ktmall_product",
let:{
class_id:"$_id",
class_name:"$name"
},
pipeline:$.pipeline()
.match(_.expr($.eq(["$parentid","$class_id"])))
.sort({
orderid:-1
})
.done(),
as:"prolist"
})
.end();
}
}
相似问题