38 lines
1.1 KiB
TypeScript
38 lines
1.1 KiB
TypeScript
import cloud from '@lafjs/cloud'
|
|
const db = cloud.database();
|
|
export default async function (ctx: FunctionContext) {
|
|
let otherUid = ctx.body.otherUid;
|
|
let uid = ctx.body.uid;
|
|
let dbname = "users";
|
|
const gameName = ctx.body.gameName;
|
|
if (gameName == "iaa") {
|
|
dbname = "usersAd";
|
|
}
|
|
if (!uid) {
|
|
return { code: 0, data: null, msg: "参数错误" };
|
|
}
|
|
let shareLv = Number(ctx.body.shareLv);
|
|
if (!shareLv) {
|
|
return { code: 0, data: null, msg: "参数错误" };
|
|
}
|
|
let res = await db.collection(dbname).where({ _id: uid }).getOne();
|
|
if (res.data == null) {
|
|
return { code: 0, data: null, msg: "未获取到玩家数据" };
|
|
}
|
|
let share = res.data.shareLv;
|
|
if (share) {
|
|
share = JSON.parse(share);
|
|
} else {
|
|
share = [];
|
|
}
|
|
if (share.length > 0) {
|
|
if (share[0].lv < shareLv) {
|
|
share = [{ id: otherUid, lv: shareLv }];
|
|
}
|
|
} else {
|
|
share = [{ id: otherUid, lv: shareLv }];
|
|
}
|
|
db.collection(dbname).where({ _id: uid }).update({ shareLv: JSON.stringify(share) });
|
|
return { code: 1, data: share, msg: "成功" }
|
|
}
|