Comment.php 1.6 KB

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