bookdetail.js 658 B

1234567891011121314151617181920212223242526
  1. const {mysql} = require('../qcloud')
  2. module.exports = async (ctx) => {
  3. const {id} = ctx.request.query
  4. const detail = await mysql('books')
  5. .select('books.*', 'cSessionInfo.user_info')
  6. .join('cSessionInfo', 'books.openid', 'cSessionInfo.open_id')
  7. .where('id', id)
  8. .first()
  9. // console.log(detail)
  10. const info = JSON.parse(detail.user_info)
  11. ctx.state.data = Object.assign({}, detail, {
  12. tags: detail.tags.split(','),
  13. summary: detail.summary.split('\n'),
  14. user_info: {
  15. name: info.nickName,
  16. image: info.avatarUrl
  17. }
  18. })
  19. // 浏览量+1
  20. await mysql('books')
  21. .where('id', id)
  22. .increment('count', 1)
  23. }