Comment.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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\api\controller;
  13. use app\api\model\Comment as CommentModel;
  14. /**
  15. * 商品评价控制器
  16. * Class Comment
  17. * @package app\api\controller
  18. */
  19. class Comment extends Controller
  20. {
  21. /**
  22. * 商品评价列表
  23. * @param int $goodsId 商品ID
  24. * @param int|null $scoreType 评价评分
  25. * @return \think\response\Json
  26. * @throws \think\db\exception\DataNotFoundException
  27. * @throws \think\db\exception\DbException
  28. * @throws \think\db\exception\ModelNotFoundException
  29. */
  30. public function list(int $goodsId, int $scoreType = null)
  31. {
  32. // 评价列表
  33. $model = new CommentModel;
  34. $list = $model->getCommentList($goodsId, $scoreType);
  35. return $this->renderSuccess(compact('list'));
  36. }
  37. /**
  38. * 商品评分总数
  39. * @param int $goodsId
  40. * @return array|\think\response\Json
  41. * @throws \think\db\exception\DataNotFoundException
  42. * @throws \think\db\exception\DbException
  43. * @throws \think\db\exception\ModelNotFoundException
  44. */
  45. public function total(int $goodsId)
  46. {
  47. // 指定评分总数
  48. $model = new CommentModel;
  49. $total = $model->getTotal($goodsId);
  50. return $this->renderSuccess(compact('total'));
  51. }
  52. /**
  53. * 商品评价列表 (限制数量, 用于商品详情页展示)
  54. * @param int $goodsId
  55. * @param int $limit
  56. * @return array|\think\response\Json
  57. * @throws \think\db\exception\DataNotFoundException
  58. * @throws \think\db\exception\DbException
  59. * @throws \think\db\exception\ModelNotFoundException
  60. */
  61. public function listRows(int $goodsId, int $limit = 5)
  62. {
  63. // 评价列表
  64. $model = new CommentModel;
  65. $list = $model->listRows($goodsId, $limit);
  66. // 评价总数量
  67. $total = $model->rowsTotal($goodsId);
  68. return $this->renderSuccess(compact('list', 'total'));
  69. }
  70. }