当前位置:网站首页>点赞的云函数
点赞的云函数
2022-07-01 04:48:00 【JSONP$】
// 云函数入口文件
const cloud = require('wx-server-sdk')
cloud.init({
env: cloud.DYNAMIC_CURRENT_ENV
})
const db = cloud.database()
const formatTime = date => {
const year = date.getFullYear()
const month = date.getMonth() + 1
const day = date.getDate()
const hour = date.getHours()
const minute = date.getMinutes()
const second = date.getSeconds()
return `${
[year, month, day].map(formatNumber).join('-')} ${
[hour, minute, second].map(formatNumber).join(':')}`
}
const formatNumber = n => {
n = n.toString()
return n[1] ? n : `0${
n}`
}
// 云函数入口函数
exports.main = async (event, context) => {
const wxContext = cloud.getWXContext()
let dz = db.collection('movie_zan_collect')
let {
total} = await new Promise( (resolve, reject)=>{
dz.where({
member_openid: wxContext.OPENID,movie_id: event.movieId }).count().then( res=>{
resolve(res)
})
})
let data = {
member_openid: wxContext.OPENID,
movie_id:event.movieId,
like:event.like,
collection:event.collection,
_updateTime:formatTime(new Date()),
}
if( total == 0 ){
console.log(data)
data._createTime = formatTime(new Date())
return await dz.add({
data }).then( res=>{
console.log('新增成功->', res)
return res
}).catch( err=>{
console.log('新增失败',err)
})
}else{
return await dz.where({
member_openid: wxContext.OPENID,movie_id: event.movieId }).update({
data }).then( res=>{
console.log('更新成功->', res)
return res
}).catch( err=>{
console.log('更新失败',err)
})
}
}
多研究研究
再来看另一个接口
// 云函数入口文件
const cloud = require('wx-server-sdk')
cloud.init({
env: cloud.DYNAMIC_CURRENT_ENV
})
const db = cloud.database()
// 云函数入口函数
exports.main = async (event, context) => {
const wxContext = cloud.getWXContext()
return db.collection('movie_zan_collect').where({
movie_id:event.movieId,
member_openid:wxContext.OPENID
}).get()
}
实现这个逻辑,需要两个接口
边栏推荐
- VIM easy to use tutorial
- How to do the performance pressure test of "Health Code"
- Measurement of quadrature axis and direct axis inductance of three-phase permanent magnet synchronous motor
- Solve the problem that the external chain file of Qiankun sub application cannot be obtained
- Dataloader的使用
- LM小型可编程控制器软件(基于CoDeSys)笔记十九:报错does not match the profile of the target
- [difficult] sqlserver2008r2, can you recover only some files when recovering the database?
- PR 2021 quick start tutorial, learn about the and functions of the timeline panel
- LeetCode_ 35 (search insertion position)
- Neural network convolution layer
猜你喜欢
Daily algorithm & interview questions, 28 days of special training in large factories - the 13th day (array)
Sorting out 49 reports of knowledge map industry conference | AI sees the future with wisdom
分布式全局唯一ID解决方案详解
[pat (basic level) practice] - [simple simulation] 1064 friends
Shell之一键自动部署Redis任意版本
C#读写应用程序配置文件App.exe.config,并在界面上显示
Common methods in transforms
2022.2.7-2.13 AI industry weekly (issue 84): family responsibilities
Neural network convolution layer
Pytoch (I) -- basic grammar
随机推荐
Solve the problem that the external chain file of Qiankun sub application cannot be obtained
Leecode records the number of good segmentation of 1525 strings
LeetCode_ 35 (search insertion position)
Leecode question brushing record 1310 subarray XOR query
分布式数据库数据一致性的原理、与技术实现方案
Shell analysis server log command collection
【硬十宝典目录】——转载自“硬件十万个为什么”(持续更新中~~)
Pytoch (II) -- activation function, loss function and its gradient
CF1638E. Colorful operations Kodori tree + differential tree array
最长递增子序列及最优解、动物总重量问题
STM32 光敏电阻传感器&两路AD采集
Neural network convolution layer
Dual contractual learning: text classification via label aware data augmentation reading notes
Use and modification of prior network model
I also gave you the MySQL interview questions of Boda factory. If you need to come in and take your own
缓冲流与转换流
Take a cold bath
Strategic suggestions and future development trend of global and Chinese vibration isolator market investment report 2022 Edition
无器械健身
js解决浮点数相乘精度丢失问题