Browse Source

ADD

添加信息提问功能
RegMs If 4 năm trước cách đây
mục cha
commit
72f0dd617e

+ 1 - 1
cloudfunctions/createMessage/index.js

@@ -6,7 +6,7 @@ const db = cloud.database()
 
 // 云函数入口函数
 exports.main = async (event, context) => {
-  let {
+  const {
     OPENID
   } = cloud.getWXContext()
 

+ 1 - 1
cloudfunctions/createPublisher/index.js

@@ -6,7 +6,7 @@ const db = cloud.database()
 
 // 云函数入口函数
 exports.main = async (event, context) => {
-  let {
+  const {
     OPENID
   } = cloud.getWXContext()
 

+ 6 - 0
cloudfunctions/createQuestion/config.json

@@ -0,0 +1,6 @@
+{
+  "permissions": {
+    "openapi": [
+    ]
+  }
+}

+ 37 - 0
cloudfunctions/createQuestion/index.js

@@ -0,0 +1,37 @@
+// 云函数入口文件
+const cloud = require('wx-server-sdk')
+
+cloud.init()
+const db = cloud.database()
+
+// 云函数入口函数
+exports.main = async (event, context) => {
+  const {
+    OPENID
+  } = cloud.getWXContext()
+
+  try {
+    await db.collection('message')
+      .doc(event.msg_id)
+      .get()
+  } catch (err) {
+    return {
+      errMsg: '信息不存在'
+    }
+  }
+
+  const question = await db.collection('question')
+    .add({
+      data: {
+        user_id: OPENID,
+        msg_id: event.msg_id || '',
+        question: event.question || '',
+        q_time: new Date(),
+        answer: '',
+        a_time: new Date(),
+        rank: 0
+      }
+    })
+
+  return question
+}

+ 14 - 0
cloudfunctions/createQuestion/package.json

@@ -0,0 +1,14 @@
+{
+  "name": "createQuestion",
+  "version": "1.0.0",
+  "description": "",
+  "main": "index.js",
+  "scripts": {
+    "test": "echo \"Error: no test specified\" && exit 1"
+  },
+  "author": "",
+  "license": "ISC",
+  "dependencies": {
+    "wx-server-sdk": "~2.4.0"
+  }
+}

+ 2 - 2
cloudfunctions/createUser/index.js

@@ -6,7 +6,7 @@ const db = cloud.database()
 
 // 云函数入口函数
 exports.main = async (event, context) => {
-  let {
+  const {
     OPENID
   } = cloud.getWXContext()
 
@@ -25,7 +25,7 @@ exports.main = async (event, context) => {
       })
   } catch (err) {
     return {
-      errMsg: 'user exists'
+      errMsg: '用户已存在'
     }
   }
 }

+ 26 - 30
cloudfunctions/getMessage/index.js

@@ -6,40 +6,36 @@ const db = cloud.database()
 
 // 云函数入口函数
 exports.main = async (event, context) => {
-  let {
+  const {
     OPENID
   } = cloud.getWXContext()
 
-  try {
-    const message = await db.collection('message')
-      .aggregate()
-      .match({
-        _id: event.msg_id
-      })
-      .lookup({
-        from: 'publisher',
-        localField: 'pub_id',
-        foreignField: '_id',
-        as: 'publisher'
-      })
-      .end()
-    if (message.list.length !== 1) {
-      throw 'error'
-    }
-
-    await db.collection('read')
-      .add({
-        data: {
-          user_id: OPENID,
-          msg_id: event.msg_id || '',
-          read_time: new Date()
-        }
-      })
-
-    return message
-  } catch (err) {
+  const message = await db.collection('message')
+    .aggregate()
+    .match({
+      _id: event.msg_id
+    })
+    .lookup({
+      from: 'publisher',
+      localField: 'pub_id',
+      foreignField: '_id',
+      as: 'publisher'
+    })
+    .end()
+  if (message.list.length !== 1) {
     return {
-      errMsg: 'no such message'
+      errMsg: '信息不存在'
     }
   }
+
+  await db.collection('read')
+    .add({
+      data: {
+        user_id: OPENID,
+        msg_id: event.msg_id || '',
+        read_time: new Date()
+      }
+    })
+
+  return message
 }

+ 2 - 2
cloudfunctions/getPublisher/index.js

@@ -6,7 +6,7 @@ const db = cloud.database()
 
 // 云函数入口函数
 exports.main = async (event, context) => {
-  let {
+  const {
     OPENID
   } = cloud.getWXContext()
 
@@ -16,7 +16,7 @@ exports.main = async (event, context) => {
       .get()
   } catch (err) {
     return {
-      errMsg: 'no such publisher'
+      errMsg: '社团组织不存在'
     }
   }
 }

+ 2 - 2
cloudfunctions/getUser/index.js

@@ -6,7 +6,7 @@ const db = cloud.database()
 
 // 云函数入口函数
 exports.main = async (event, context) => {
-  let {
+  const {
     OPENID
   } = cloud.getWXContext()
 
@@ -16,7 +16,7 @@ exports.main = async (event, context) => {
       .get()
   } catch (err) {
     return {
-      errMsg: 'no such user'
+      errMsg: '用户不存在'
     }
   }
 }

+ 1 - 1
cloudfunctions/listMessages/index.js

@@ -6,7 +6,7 @@ const db = cloud.database()
 
 // 云函数入口函数
 exports.main = async (event, context) => {
-  let {
+  const {
     OPENID
   } = cloud.getWXContext()
 

+ 1 - 1
cloudfunctions/listPublishers/index.js

@@ -6,7 +6,7 @@ const db = cloud.database()
 
 // 云函数入口函数
 exports.main = async (event, context) => {
-  let {
+  const {
     OPENID
   } = cloud.getWXContext()
 

+ 2 - 2
cloudfunctions/updateUser/index.js

@@ -6,7 +6,7 @@ const db = cloud.database()
 
 // 云函数入口函数
 exports.main = async (event, context) => {
-  let {
+  const {
     OPENID
   } = cloud.getWXContext()
 
@@ -22,7 +22,7 @@ exports.main = async (event, context) => {
       })
   } catch (err) {
     return {
-      errMsg: 'no such user'
+      errMsg: '用户不存在'
     }
   }
 }

+ 2 - 2
miniprogram/components/itemCard/itemCard.wxml

@@ -17,8 +17,8 @@
   <imagePicker wx:if="{{item.poster !== ''}}" value="{{[item.poster]}}" max="1" image-width="698" image-height="330"
     readonly />
   <imagePicker wx:if="{{item.poster === '' && item.photo.length !== 0}}" value="{{item.photo}}" max="1"
-    image-width="{{item.photo.length == 1 ? 698 : item.photo.length <= 4 ? 330 : 220}}"
-    image-height="{{item.photo.length == 1 ? 698 : item.photo.length <= 4 ? 330 : 220}}" readonly />
+    image-width="{{item.photo.length === 1 ? 698 : item.photo.length <= 4 ? 330 : 220}}"
+    image-height="{{item.photo.length === 1 ? 698 : item.photo.length <= 4 ? 330 : 220}}" readonly />
   <view class="bottom-line">
     <view class="tags primary-text-color">
       <text style="font-size: 25rpx; margin: 0rpx 30rpx;" wx:for="{{item.tag}}" wx:for-item="tag" wx:key="_id"

+ 54 - 34
miniprogram/pages/activity/activity.js

@@ -87,41 +87,61 @@ Page({
         icon: "none"
       })
     } else {
-      const db = wx.cloud.database()
-      db.collection("qaData").where({
-        _openid: app.globalData.openId,
-        activityId: this.data.activityInfo._id
-      }).get({
-        success: function (res) {
-          console.log(res)
-          if (res.data.length >= 10) {
-            wx.showToast({
-              title: "为防止刷屏,每人每消息至多提问10条",
-              icon: "none"
-            })
-          } else {
-            db.collection("qaData").add({
-              data: {
-                activityId: this.data.activityInfo._id,
-                publisherId: this.data.activityInfo.publisherId,
-                answer: "",
-                answerTime: "",
-                question: this.data.commentText,
-                questionTime: new Date(),
-                rank: ""
-              },
-              success: function () {
-                this.setData({
-                  commentText: ""
-                })
-                wx.showToast({
-                  title: "提问成功"
-                })
-              }.bind(this)
-            })
-          }
-        }.bind(this)
+      wx.showLoading({
+        title: '发送中',
       })
+      wx.cloud.callFunction({
+        name: 'createQuestion',
+        data: {
+          msg_id: this.data.activityInfo._id,
+          question: this.data.commentText
+        }
+      }).then(res => {
+        wx.hideLoading()
+        wx.showToast({
+          title: '发送成功,请等待回复',
+          icon: 'none'
+        })
+        this.setData({
+          commentText: ''
+        })
+      })
+
+      // const db = wx.cloud.database()
+      // db.collection("qaData").where({
+      //   _openid: app.globalData.openId,
+      //   activityId: this.data.activityInfo._id
+      // }).get({
+      //   success: function (res) {
+      //     console.log(res)
+      //     if (res.data.length >= 10) {
+      //       wx.showToast({
+      //         title: "为防止刷屏,每人每消息至多提问10条",
+      //         icon: "none"
+      //       })
+      //     } else {
+      //       db.collection("qaData").add({
+      //         data: {
+      //           activityId: this.data.activityInfo._id,
+      //           publisherId: this.data.activityInfo.publisherId,
+      //           answer: "",
+      //           answerTime: "",
+      //           question: this.data.commentText,
+      //           questionTime: new Date(),
+      //           rank: ""
+      //         },
+      //         success: function () {
+      //           this.setData({
+      //             commentText: ""
+      //           })
+      //           wx.showToast({
+      //             title: "提问成功"
+      //           })
+      //         }.bind(this)
+      //       })
+      //     }
+      //   }.bind(this)
+      // })
     }
   },