commentlist.js 735 B

1234567891011121314151617181920212223242526
  1. const { mysql } = require('../qcloud')
  2. module.exports = async (ctx) => {
  3. const {bookid, openid} = ctx.request.query
  4. const mysqlSelect = mysql('comments')
  5. .select('comments.*', 'cSessionInfo.user_info')
  6. .join('cSessionInfo', 'comments.openid', 'cSessionInfo.open_id')
  7. let comments
  8. if (bookid) {
  9. // 图书详情的评论列表
  10. comments = await mysqlSelect.where('bookid', bookid)
  11. } else if (openid) {
  12. // 根据个人的openid筛选
  13. comments = await mysqlSelect.where('openid', openid)
  14. }
  15. ctx.state.data = {
  16. list: comments.map(v => {
  17. const info = JSON.parse(v.user_info)
  18. return Object.assign({}, v, {
  19. title: info.nickName,
  20. image: info.avatarUrl
  21. })
  22. })
  23. }
  24. }