Comment.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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 array $commentIds id集
  62. * @param bool $state 为true表示通过 false表示不通过
  63. * @return array
  64. */
  65. public function state(array $commentIds, bool $state)
  66. {
  67. $model = new CommentModel;
  68. if (empty($commentIds)) {
  69. return $this->renderError('评论id不能为空');
  70. }
  71. if (!$model->setStatus($commentIds, $state)) {
  72. return $this->renderError($model->getError() ?: '操作失败');
  73. }
  74. return $this->renderSuccess('操作成功');
  75. }
  76. /**
  77. * 平台回复
  78. */
  79. public function reply(int $commentId) {
  80. // 评价详情
  81. $model = CommentModel::detail($commentId);
  82. $data = $this->postForm();
  83. if (empty($data['reply_content'])) {
  84. return $this->renderError("解释内容不能为空");
  85. }
  86. // 更新记录
  87. if ($model->reply($data)) {
  88. return $this->renderSuccess('更新成功');
  89. }
  90. return $this->renderError($model->getError() ?: '更新失败');
  91. }
  92. /**
  93. * 删除评价
  94. * @param int $commentId
  95. * @return array|bool
  96. */
  97. public function delete(int $commentId)
  98. {
  99. // 评价详情
  100. $model = CommentModel::detail($commentId);
  101. if (!$model->setDelete()) {
  102. return $this->renderError($model->getError() ?: '删除失败');
  103. }
  104. return $this->renderSuccess('删除成功');
  105. }
  106. /**
  107. * 导入评价
  108. */
  109. public function importFake(){
  110. $file = request()->file('file');
  111. if (empty($file)){
  112. return $this->renderError('请先上传导入的文件');
  113. }
  114. // 上传到本地服务器
  115. $filename = \think\facade\Filesystem::putFile('comment', $file);
  116. $res = (new CommentModel())->importFake($filename);
  117. if (!$res) {
  118. return $this->renderError("导入失败");
  119. }
  120. return $this->renderSuccess([],'导入成功');
  121. }
  122. }