Comment.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. namespace app\store\controller\goods;
  3. use app\store\controller\Controller;
  4. use app\store\model\Comment as CommentModel;
  5. /**
  6. * 商品评价管理
  7. * Class Comment
  8. * @package app\store\controller\goods
  9. */
  10. class Comment extends Controller
  11. {
  12. /**
  13. * 评价列表
  14. * @return mixed
  15. * @throws \think\exception\DbException
  16. */
  17. public function index()
  18. {
  19. $model = new CommentModel;
  20. $list = $model->getList();
  21. return $this->fetch('index', compact('list'));
  22. }
  23. /**
  24. * 评价详情
  25. * @param $comment_id
  26. * @return array|mixed
  27. * @throws \think\exception\DbException
  28. */
  29. public function detail($comment_id)
  30. {
  31. // 评价详情
  32. $model = CommentModel::detail($comment_id);
  33. if (!$this->request->isAjax()) {
  34. return $this->fetch('detail', compact('model'));
  35. }
  36. // 更新记录
  37. if ($model->edit($this->postData('comment'))) {
  38. return $this->renderSuccess('更新成功', url('goods.comment/index'));
  39. }
  40. return $this->renderError($model->getError() ?: '更新失败');
  41. }
  42. /**
  43. * 删除评价
  44. * @param $comment_id
  45. * @return array
  46. * @throws \think\exception\DbException
  47. */
  48. public function delete($comment_id)
  49. {
  50. $model = CommentModel::get($comment_id);
  51. if (!$model->setDelete()) {
  52. return $this->renderError('删除失败');
  53. }
  54. return $this->renderSuccess('删除成功');
  55. }
  56. }