Comment.php 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. namespace app\api\controller\service;
  3. use app\common\controller\Api;
  4. use think\Db;
  5. use think\Exception;
  6. /**
  7. * 首页接口
  8. */
  9. class Comment extends Api
  10. {
  11. protected $noNeedLogin = ['getList','totalComment','commentLabel','getInfo'];
  12. protected $noNeedRight = ['*'];
  13. /**
  14. * 查询评论列表
  15. * @return void
  16. * @throws \think\db\exception\DataNotFoundException
  17. * @throws \think\db\exception\ModelNotFoundException
  18. * @throws \think\exception\DbException
  19. */
  20. public function getList()
  21. {
  22. if (!$this->request->isPost()) {
  23. $this->error('请求方式异常');
  24. }
  25. //$uid = $this->auth->isLogin()?$this->auth->id:'';
  26. $post = input('post.','','trim,strip_tags');
  27. $post['limit'] = 10;
  28. $post['page'] = input('page/d',1);
  29. $list = \app\api\model\service\Comment::searchComment($post);
  30. $this->success('信息列表返回成功',$list);
  31. }
  32. public function commentLabel()
  33. {
  34. $list = \app\api\model\service\CommentLabel::where(['state'=>1])->field('id,name')->select();
  35. $this->success('信息返回成功',$list);
  36. }
  37. /**
  38. * 统计评论数据
  39. * @return void
  40. */
  41. public function totalComment()
  42. {
  43. if (!$this->request->isPost()) {
  44. $this->error('请求方式异常');
  45. }
  46. $post = input('post.','','trim,strip_tags');
  47. $data = '';
  48. try{
  49. $data = \app\api\model\service\Comment::totalComment($post);
  50. } catch (Exception $e) {
  51. $this->error('获取统计信息失败',$e->getMessage());
  52. }
  53. $this->success('信息列表返回成功',$data);
  54. }
  55. public function commentAdd()
  56. {
  57. if (!$this->request->isPost()) {
  58. $this->error('请求方式异常');
  59. }
  60. $post = input('post.','','trim,strip_tags,htmlspecialchars,xss_clean');
  61. $post['user_id'] = $this->auth->id;
  62. Db::startTrans();
  63. try{
  64. \app\api\model\service\Comment::commentAdd($post);
  65. Db::commit();
  66. } catch (Exception $e) {
  67. Db::rollback();
  68. $this->error($e->getMessage());
  69. }
  70. $this->success('订单已评论');
  71. }
  72. public function getInfo()
  73. {
  74. if (!$this->request->isPost()) {
  75. $this->error('请求方式异常');
  76. }
  77. $id = input('order_id','');
  78. $comment = \app\api\model\service\Comment::where('order_id',$id)->field('score,comment_label_ids,comment_label,content,images')->find();
  79. $comment['images'] = $comment['images']?explode(',',$comment['images']):'';
  80. $this->success('信息返回成功',$comment);
  81. }
  82. }