0
0

booklist.js 669 B

12345678910111213141516171819202122232425
  1. const { mysql } = require('../qcloud')
  2. module.exports = async (ctx) => {
  3. const {page} = ctx.request.query
  4. const size = 10
  5. const books = await mysql('books')
  6. .select('books.*', 'cSessionInfo.user_info')
  7. .join('cSessionInfo', 'books.openid', 'cSessionInfo.open_id')
  8. .limit(size)
  9. .offset(Number(page) * size)
  10. .orderBy('books.id', 'desc')
  11. ctx.state.data = {
  12. list: books.map(v => {
  13. const info = JSON.parse(v.user_info)
  14. return Object.assign({}, v, {
  15. user_info: {
  16. nickName: info.nickName
  17. }
  18. })
  19. })
  20. }
  21. }