Comment.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2017~2024 https://www.yiovo.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
  8. // +----------------------------------------------------------------------
  9. // | Author: 萤火科技 <admin@yiovo.com>
  10. // +----------------------------------------------------------------------
  11. declare (strict_types=1);
  12. namespace app\store\controller\goods;
  13. use think\response\Json;
  14. use app\store\controller\Controller;
  15. use app\store\model\Comment as CommentModel;
  16. /**
  17. * 商品评价管理
  18. * Class Comment
  19. * @package app\store\controller\goods
  20. */
  21. class Comment extends Controller
  22. {
  23. /**
  24. * 评价列表
  25. * @return Json
  26. */
  27. public function list(): Json
  28. {
  29. $model = new CommentModel;
  30. $list = $model->getList($this->request->param());
  31. return $this->renderSuccess(compact('list'));
  32. }
  33. /**
  34. * 评价详情
  35. * @param int $commentId
  36. * @return Json
  37. */
  38. public function detail(int $commentId): Json
  39. {
  40. // 评价详情
  41. $model = new CommentModel;
  42. $detail = $model->getDetail($commentId);
  43. return $this->renderSuccess(compact('detail'));
  44. }
  45. /**
  46. * 编辑评价
  47. * @param int $commentId
  48. * @return Json
  49. */
  50. public function edit(int $commentId): Json
  51. {
  52. // 评价详情
  53. $model = CommentModel::detail($commentId);
  54. // 更新记录
  55. if ($model->edit($this->postForm())) {
  56. return $this->renderSuccess('更新成功');
  57. }
  58. return $this->renderError($model->getError() ?: '更新失败');
  59. }
  60. /**
  61. * 删除评价
  62. * @param int $commentId
  63. * @return Json
  64. */
  65. public function delete(int $commentId): Json
  66. {
  67. // 评价详情
  68. $model = CommentModel::detail($commentId);
  69. if (!$model->setDelete()) {
  70. return $this->renderError($model->getError() ?: '删除失败');
  71. }
  72. return $this->renderSuccess('删除成功');
  73. }
  74. }