46 lines
1.2 KiB
TypeScript
46 lines
1.2 KiB
TypeScript
import cloud from '@lafjs/cloud'
|
|
const db=cloud.database();
|
|
import Utils from "@/Utils";
|
|
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:"未获取到玩家数据"};
|
|
}
|
|
const token1 = ctx.body.token;
|
|
if (res.data && res.data.token) {
|
|
let istoken = Utils.checkToken(token1, res.data.token);
|
|
if (!istoken) {
|
|
return { code: 0, data: null, msg: "token校验失败" };
|
|
}
|
|
}
|
|
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:"成功"}
|
|
}
|