88 lines
3.0 KiB
TypeScript
88 lines
3.0 KiB
TypeScript
import cloud from '@lafjs/cloud'
|
|
const db = cloud.database();
|
|
const CITY = {
|
|
"河北省": true, "山西省": true, "辽宁省": true, "吉林省": true, "黑龙江省": true, "江苏省": true,
|
|
"浙江省": true, "安徽省": true, "福建省": true, "江西省": true, "山东省": true, "河南省": true, "湖北省": true,
|
|
"湖南省": true, "广东省": true, "海南省": true, "四川省": true, "贵州省": true, "云南省": true, "陕西省": true,
|
|
"甘肃省": true, "青海省": true, "港澳台": true, "北京": true, "天津": true, "上海": true, "重庆": true,
|
|
"内蒙古": true, "广西": true, "西藏": true, "宁夏": true, "新疆": true, "其他": true
|
|
};
|
|
export default async function (ctx: FunctionContext) {
|
|
let uid=ctx.body.uid;
|
|
let res=await sortBattle(uid);
|
|
// for(var key in CITY){
|
|
// let res = await sortShengShi(key);
|
|
// }
|
|
return {code:1}
|
|
}
|
|
/**普通排行
|
|
* @param userCollec
|
|
*/
|
|
async function sortBattle(uid) {
|
|
let res = await db.collection("users").aggregate().project({
|
|
levelAmount: 1, // 1 表示包含该字段,其他字段默认排除
|
|
endLevelNum: 1,
|
|
username:1,
|
|
useravatar:1,
|
|
useravatarIcon:1,
|
|
isWhite:1
|
|
})//.addFields({ endLevelNum: { $toInt: "$endLevelNum" }}).addFields({
|
|
// totalLevel: { $add: ["$levelAmount", "$endLevelNum"] }})
|
|
.match({
|
|
isWhite: false
|
|
})
|
|
.sort({
|
|
levelAmount:-1,
|
|
endLevelNum:-1
|
|
//totalLevel: -1,
|
|
}).limit(1000).end();
|
|
const res1 = await db.collection("rank").where({ _id:"689db6c5cc79706182bd6a9f"})
|
|
.update({rank: JSON.stringify(res.data)});
|
|
let res2 = await db.collection("usersAd").aggregate().project({
|
|
levelAmount: 1, // 1 表示包含该字段,其他字段默认排除
|
|
endLevelNum: 1,
|
|
username: 1,
|
|
useravatar: 1,
|
|
useravatarIcon: 1,
|
|
isWhite: 1
|
|
})
|
|
// .addFields({ endLevelNum: { $toInt: "$endLevelNum" } }).addFields({
|
|
// totalLevel: { $add: ["$levelAmount", "$endLevelNum"] }
|
|
// })
|
|
.match({
|
|
isWhite: false
|
|
})
|
|
.sort({
|
|
levelAmount: -1,
|
|
endLevelNum: -1
|
|
//totalLevel: -1,
|
|
}).limit(1000).end();
|
|
const res3 = await db.collection("rank").where({ _id: "68e92b7835004ffb5ab9ee89" })
|
|
.update({ rank: JSON.stringify(res2.data) });
|
|
return true;
|
|
}
|
|
|
|
// /**省市地区排名前100名*/
|
|
// async function sortShengShi(address){
|
|
// let res = await db.collection("users").aggregate().project({
|
|
// addLevel:1,
|
|
// levelAmount:1, // 1 表示包含该字段,其他字段默认排除
|
|
// endLevelNum: 1,
|
|
// username:1,
|
|
// useravatar:1,
|
|
// useravatarIcon: 1,
|
|
// isWhite: 1,
|
|
// address:1,
|
|
// }).addFields({ endLevelNum: { $toInt: "$endLevelNum" } }).addFields({
|
|
// totalLevel: { $add: ["$levelAmount", "$endLevelNum"] }
|
|
// }).match({
|
|
// address:address,
|
|
// isWhite: false,
|
|
// addLevel: {$gte:5},
|
|
// })
|
|
// .sort({
|
|
// addLevel: -1,
|
|
// }).limit(100).end();
|
|
// const res3 = await db.collection("sRank").where({ name: address }).update({ totoal: res.data }, { upsert: true });
|
|
// return true;
|
|
// }
|