Browse Source

[server] booklist add user_info of nickName by mysql books and cSessionInfo tables for openid

charblus 5 years ago
parent
commit
d4337c20d0
2 changed files with 14 additions and 4 deletions
  1. 12 2
      server/controllers/booklist.js
  2. 2 2
      src/components/Card.vue

+ 12 - 2
server/controllers/booklist.js

@@ -1,8 +1,18 @@
 const { mysql } = require('../qcloud')
 
 module.exports = async (ctx) => {
-  const books = await mysql('books').select('*')
+  const books = await mysql('books')
+                      .select('books.*', 'cSessionInfo.user_info')
+                      .join('cSessionInfo', 'books.openid', 'cSessionInfo.open_id')
+                      .orderBy('books.id', 'desc')
   ctx.state.data = {
-    list: books
+    list: books.map(v => {
+      const info = JSON.parse(v.user_info)
+      return Object.assign({}, v, {
+        user_info: {
+          nickName: info.nickName
+        }
+      })
+    })
   }
 }

+ 2 - 2
src/components/Card.vue

@@ -22,8 +22,8 @@
       </div>
       <div class="row">
          <div class="right">
-           姓名
-           <!-- {{book.user_info.nickName}} -->
+           <!-- 捐赠人 -->
+           {{book.user_info.nickName}}
         </div>
         <div class="left">
          {{book.publisher}}