GoodsReviewsLists.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. namespace app\api\lists;
  3. use app\common\model\goods_category\GoodsCategory;
  4. use app\common\lists\ListsSearchInterface;
  5. use app\common\model\reviews\GoodsReviews;
  6. /**
  7. * GoodsReviewsLists
  8. * Class GoodsReviewsLists
  9. * @package app\api\lists\GoodsReviewsLists
  10. */
  11. class GoodsReviewsLists extends BaseApiDataLists implements ListsSearchInterface
  12. {
  13. /**
  14. * @notes 设置搜索条件
  15. * @return \string[][]
  16. * @date 2024/07/07 18:23
  17. */
  18. public function setSearch(): array
  19. {
  20. return [
  21. 'goods_id','user_id','review_status','goods_category_id'
  22. ];
  23. }
  24. public function queryWhere()
  25. {
  26. $where = [];
  27. $where[] = ['goods_category_id','=',!empty($this->params['category_id'])?$this->params['category_id']:'9999999'];
  28. $where[] = ['review_status','=',1];
  29. return $where;
  30. }
  31. /**
  32. * @notes 获取列表
  33. * @return array
  34. * @throws \think\db\exception\DataNotFoundException
  35. * @throws \think\db\exception\DbException
  36. * @throws \think\db\exception\ModelNotFoundException
  37. * @author whitef
  38. * @date 2024/07/07 18:23
  39. */
  40. public function lists(): array
  41. {
  42. $lists = GoodsReviews::where($this->searchWhere)
  43. ->where($this->queryWhere())
  44. ->limit($this->limitOffset, $this->limitLength)
  45. ->field(['id','rating','comment','review_image','create_time'])
  46. ->order('create_time desc')
  47. ->select()
  48. ->toArray();
  49. return $lists;
  50. }
  51. /**
  52. * @notes 获取数量
  53. * @return int
  54. * @author whitef
  55. * @date 2024/07/07 18:23
  56. */
  57. public function count(): int
  58. {
  59. return GoodsReviews::where($this->searchWhere)->where($this->queryWhere())->count();
  60. }
  61. }