Comment.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2017~2021 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 app\store\controller\Controller;
  14. use app\store\model\Comment as CommentModel;
  15. /**
  16. * 商品评价管理
  17. * Class Comment
  18. * @package app\store\controller\goods
  19. */
  20. class Comment extends Controller
  21. {
  22. /**
  23. * 评价列表
  24. * @return array
  25. */
  26. public function list()
  27. {
  28. $model = new CommentModel;
  29. $list = $model->getList($this->request->param());
  30. return $this->renderSuccess(compact('list'));
  31. }
  32. /**
  33. * 评价详情
  34. * @param int $commentId
  35. * @return array|bool|string
  36. */
  37. public function detail(int $commentId)
  38. {
  39. // 评价详情
  40. $model = new CommentModel;
  41. $detail = $model->getDetail($commentId);
  42. return $this->renderSuccess(compact('detail'));
  43. }
  44. /**
  45. * 编辑评价
  46. * @param int $commentId
  47. * @return array
  48. */
  49. public function edit(int $commentId)
  50. {
  51. // 评价详情
  52. $model = CommentModel::detail($commentId);
  53. // 更新记录
  54. if ($model->edit($this->postForm())) {
  55. return $this->renderSuccess('更新成功');
  56. }
  57. return $this->renderError($model->getError() ?: '更新失败');
  58. }
  59. /**
  60. * 删除评价
  61. * @param int $commentId
  62. * @return array|bool
  63. */
  64. public function delete(int $commentId)
  65. {
  66. // 评价详情
  67. $model = CommentModel::detail($commentId);
  68. if (!$model->setDelete()) {
  69. return $this->renderError($model->getError() ?: '删除失败');
  70. }
  71. return $this->renderSuccess('删除成功');
  72. }
  73. }