CommentGoodsLists.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | likeshop100%开源免费商用商城系统
  4. // +----------------------------------------------------------------------
  5. // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
  6. // | 开源版本可自由商用,可去除界面版权logo
  7. // | 商业版本务必购买商业授权,以免引起法律纠纷
  8. // | 禁止对系统程序代码以任何目的,任何形式的再发布
  9. // | gitee下载:https://gitee.com/likeshop_gitee
  10. // | github下载:https://github.com/likeshop-github
  11. // | 访问官网:https://www.likeshop.cn
  12. // | 访问社区:https://home.likeshop.cn
  13. // | 访问手册:http://doc.likeshop.cn
  14. // | 微信公众号:likeshop技术社区
  15. // | likeshop团队 版权所有 拥有最终解释权
  16. // +----------------------------------------------------------------------
  17. // | author: likeshopTeam
  18. // +----------------------------------------------------------------------
  19. namespace app\shopapi\lists;
  20. use app\common\enum\OrderEnum;
  21. use app\common\enum\YesNoEnum;
  22. use app\common\lists\ListsExtendInterface;
  23. use app\common\model\GoodsComment;
  24. use app\common\model\GoodsItem;
  25. use app\common\model\Order;
  26. use app\common\model\OrderGoods;
  27. use app\common\service\FileService;
  28. class CommentGoodsLists extends BaseShopDataLists implements ListsExtendInterface
  29. {
  30. public function extend()
  31. {
  32. $waitWhere = [
  33. ['o.user_id', '=', $this->userId],
  34. ['o.order_status', '=', 3],
  35. ['og.is_comment', '=', YesNoEnum::NO],
  36. ];
  37. $wait = OrderGoods::alias('og')
  38. ->leftJoin('order o', 'o.id = og.order_id')
  39. ->where($waitWhere)
  40. ->count();
  41. $finishWhere = [
  42. ['o.user_id', '=', $this->userId],
  43. ['o.order_status', '=', 3],
  44. ['og.is_comment', '=', YesNoEnum::YES],
  45. ];
  46. $finish = OrderGoods::alias('og')
  47. ->leftJoin('order o', 'o.id = og.order_id')
  48. ->where($finishWhere)
  49. ->count();
  50. return [
  51. 'wait' => $wait,
  52. 'finish' => $finish
  53. ];
  54. }
  55. /**
  56. * @notes 设置搜索条件
  57. * @return array
  58. * @author ljj
  59. * @date 2021/8/9 2:47 下午
  60. */
  61. public function setSearch()
  62. {
  63. $where= [];
  64. $where[] = ['o.user_id', '=', $this->userId];
  65. $where[] = ['o.order_status', '=', 3];
  66. if (!isset($this->params['type']) || $this->params['type'] == '') {
  67. $where[] = ['og.is_comment','=',0];
  68. return $where;
  69. }
  70. $where[] = ['og.is_comment','=',$this->params['type']];
  71. return $where;
  72. }
  73. /**
  74. * @notes 查看评价商品列表
  75. * @return array
  76. * @throws \think\db\exception\DataNotFoundException
  77. * @throws \think\db\exception\DbException
  78. * @throws \think\db\exception\ModelNotFoundException
  79. * @author ljj
  80. * @date 2021/8/9 2:47 下午
  81. */
  82. public function lists(): array
  83. {
  84. $lists = Order::alias('o')
  85. ->join('order_goods og', 'og.order_id = o.id')
  86. ->join('goods g', 'og.goods_id = g.id')
  87. ->leftjoin('goods_comment gc','og.id = gc.order_goods_id')
  88. ->field('og.id,og.goods_id,og.item_id,g.image as goods_image,g.name as goods_name,og.goods_price,og.goods_num,og.is_comment')
  89. ->where($this->setSearch())
  90. ->limit($this->limitOffset, $this->limitLength)
  91. ->order(['gc.create_time'=>'desc','og.id'=>'desc'])
  92. ->group('og.id')
  93. ->select()->toarray();
  94. foreach ($lists as $key =>$list) {
  95. //处理商品图片路径
  96. $lists[$key]['goods_image'] = empty($list['goods_image']) ? '' : FileService::getFileUrl($list['goods_image']);
  97. // 商品规格
  98. $lists[$key]['spec_value_str'] = GoodsItem::where('id', $list['item_id'])->value('spec_value_str');
  99. //获取商品评价
  100. $lists[$key]['goods_comment'] = [];
  101. if ($list['is_comment'] == 0) {
  102. continue;
  103. }
  104. $lists[$key]['goods_comment'] = GoodsComment::where(['user_id'=>$this->userId,'order_goods_id'=>$list['id']])
  105. ->field('id,goods_comment,comment,create_time,reply')
  106. ->with('goods_comment_image')
  107. ->find();
  108. if (empty($lists[$key]['goods_comment'])) {
  109. unset($lists[$key]);
  110. }
  111. }
  112. return array_values($lists);
  113. }
  114. /**
  115. * @notes 查看评价商品总数
  116. * @return int
  117. * @author ljj
  118. * @date 2021/8/9 2:47 下午
  119. */
  120. public function count(): int
  121. {
  122. return Order::alias('o')
  123. ->join('order_goods og', 'og.order_id = o.id')
  124. ->join('goods g', 'og.item_id = g.id')
  125. ->where($this->setSearch())
  126. ->limit($this->limitOffset, $this->limitLength)
  127. ->count();
  128. }
  129. }