【四】鸡汤来咯开发学习笔记-80

前端 · 2024-09-02

1.写入当点击广告时,获取新的数据,给getshop传入ad

const clickAdSoup=()=>{
    if(readNumber<=0) return showToast("鸡汤没有啦")
    readNumber.value--
    getSoup("ad")
}

2.当getshoup获取到ad

其中[...listData.value,...data];是展开就有点像i=i+1这种,就是以前数据和现在数据都展开然后再融合到一起,一起显示

db.collection("soup-today").where(`user_id == "${currentUser}"`).update({
              soup_list:listData.value
        })

1这上面部分就是把新得到的数据和老数据一起写入soup-today,再获取广告奖励时,会跳过这些

if(type=="ad"){
      let {result:{errCode,data}}= await db.collection("soup-chicken").aggregate()
      .match({
            status:1,
            is_delete:dbCmd.neq(true),
            _id:dbCmd.nin(readSoup)
      
      })
      
      .lookup({
            from:"uni-id-users",
            let:{
                uid:'$user_id'
            },
            pipeline:$.pipeline().match(dbCmd.expr($.eq(['$_id','$$uid']))).project({username:1,avatar:1}).done(),
            as:'userInfo'
      })
      .sample({
            size:5
      })
      .limit(5)
      .project({
            collect_count:1,
            comment_count:1,
            content:1,
            from:1,
            like_count:1,
            soup_type:1,
            view_count:1,
            userInfo:$.arrayElemAt(['$userInfo',0])
      })
      .end()
      if(errCode!=0) return showToast("信息有误,重新刷新","none");
      if(data.length==0)  return getSoup("random")
      data[0].is_read=true;    
      listData.value=[...listData.value,...data];
      db.collection("soup-today").where(`user_id == "${currentUser}"`).update({
          soup_list:listData.value
    })


Theme Jasmine by Kent Liao