Explorar o código

入驻更新

获取用户管理的组织
RegMs If %!s(int64=4) %!d(string=hai) anos
pai
achega
70dcc2aa68

+ 6 - 0
cloudfunctions/listPublishers/config.json

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

+ 23 - 0
cloudfunctions/listPublishers/index.js

@@ -0,0 +1,23 @@
+// 云函数入口文件
+const cloud = require('wx-server-sdk')
+
+cloud.init()
+const db = cloud.database()
+
+// 云函数入口函数
+exports.main = async (event, context) => {
+  let {
+    OPENID
+  } = cloud.getWXContext()
+
+  if (event.type === 'manage') {
+    return await db.collection('manager').aggregate().match({
+      user_id: OPENID
+    }).lookup({
+      from: 'publisher',
+      localField: 'pub_id',
+      foreignField: '_id',
+      as: 'publisher'
+    }).end()
+  }
+}

+ 14 - 0
cloudfunctions/listPublishers/package.json

@@ -0,0 +1,14 @@
+{
+  "name": "listPublishers",
+  "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"
+  }
+}

+ 29 - 15
miniprogram/pages/user/user.js

@@ -9,8 +9,7 @@ Page({
   data: {
     userInfo: null,
     hasUserInfo: false,
-    publisherId: [],
-    publisherName: ""
+    pubInfo: []
   },
 
   // bindGetUserInfo: function (e) {
@@ -18,6 +17,30 @@ Page({
   //   this.onShow()
   // },
 
+  setUserInfo: function () {
+    this.setData({
+      userInfo: app.globalData.userInfo,
+      hasUserInfo: true
+    })
+    wx.cloud.callFunction({
+      name: 'listPublishers',
+      data: {
+        type: 'manage'
+      }
+    }).then(res => {
+      if (res.result.list !== undefined) {
+        this.setData({
+          pubInfo: res.result.list
+        })
+      } else {
+        wx.showToast({
+          title: res.result.errMsg,
+          icon: 'none'
+        })
+      }
+    })
+  },
+
   getUserProfile: function () {
     wx.getUserProfile({
       desc: '用于完善个人信息',
@@ -39,10 +62,7 @@ Page({
             data: app.globalData.userInfo
           })
         }
-        this.setData({
-          userInfo: app.globalData.userInfo,
-          hasUserInfo: true
-        })
+        this.setUserInfo()
       }
     })
   },
@@ -63,7 +83,7 @@ Page({
 
   publisherPage: function () {
     wx.navigateTo({
-      url: "/pages/publisherPage/publisherPage?id=" + this.data.publisherId[0],
+      url: "/pages/publisherPage/publisherPage?id=" + this.data.pubInfo[0].pub_id,
     })
   },
 
@@ -200,16 +220,10 @@ Page({
     // })
 
     if (app.globalData.hasUserInfo) {
-      this.setData({
-        userInfo: app.globalData.userInfo,
-        hasUserInfo: true
-      })
+      this.setUserInfo()
     } else {
       app.onUserInfoReady = () => {
-        this.setData({
-          userInfo: app.globalData.userInfo,
-          hasUserInfo: true
-        })
+        this.setUserInfo()
       }
     }
   },

+ 2 - 2
miniprogram/pages/user/user.wxml

@@ -5,7 +5,7 @@
   <view wx:if="{{hasUserInfo}}" class="nickname primary-text">{{userInfo.name}}</view>
   <view wx:else class="nickname"><button class="block-background-color" size="mini"
       bindtap="getUserProfile">微信登录</button></view>
-  <view class="location secondary-text">{{publisherId.length == 0 ? '尚未加入任何社团组织' : publisherName}}</view>
+  <view class="location secondary-text">{{pubInfo.length === 0 ? '尚未加入任何社团组织' : pubInfo[0].name}}</view>
 </view>
 
 <view class="mid" wx:if="{{hasUserInfo}}">
@@ -46,7 +46,7 @@
 </view>
 
 <view wx:if="{{hasUserInfo}}">
-  <view wx:if="{{publisherId.length == 0}}" class="publisher primary-background-color" hover-class="btn-hover"
+  <view wx:if="{{pubInfo.length === 0}}" class="publisher primary-background-color" hover-class="btn-hover"
     bindtap="publisherLogin">
     <text class="white-text-color">社团\n组织\n入驻</text>
   </view>