GoodsCommentLists.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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\adminapi\lists\goods;
  20. use app\adminapi\lists\BaseAdminDataLists;
  21. use app\common\lists\ListsExcelInterface;
  22. use app\common\model\GoodsComment;
  23. use app\common\service\FileService;
  24. use think\facade\Db;
  25. class GoodsCommentLists extends BaseAdminDataLists implements ListsExcelInterface
  26. {
  27. /**
  28. * @notes 设置搜索条件
  29. * @return array
  30. * @author ljj
  31. * @date 2021/8/12 5:01 下午
  32. */
  33. public function setSearch(): array
  34. {
  35. $where = [];
  36. if (isset($this->params['goods_info']) && !empty($this->params['goods_info'])) {
  37. $where[] = ['og.goods_name|g.code', 'like', '%'.$this->params['goods_info'].'%'];
  38. }
  39. if (isset($this->params['user_info']) && !empty($this->params['user_info'])) {
  40. $where[] = ['u.nickname|u.sn', 'like', '%'.$this->params['user_info'].'%'];
  41. }
  42. if (isset($this->params['reply_status'])) {
  43. switch ($this->params['reply_status']){
  44. case '0'://全部
  45. break;
  46. case '1'://待回复
  47. $where[]= ['gc.reply', 'exp', Db::raw('is null')];
  48. break;
  49. case '2'://已回复
  50. $where[]= ['gc.reply', 'exp', Db::raw('is not null')];
  51. break;
  52. }
  53. }
  54. if (isset($this->params['verify_status'])) {
  55. switch ($this->params['verify_status']){
  56. case '0'://全部
  57. break;
  58. case '1'://待审核
  59. $where[]= ['gc.status', '=', 0];
  60. break;
  61. case '2'://审核通过
  62. $where[]= ['gc.status', '=', 1];
  63. break;
  64. case '3'://审核拒绝
  65. $where[]= ['gc.status', '=', 2];
  66. break;
  67. }
  68. }
  69. if (isset($this->params['comment_type']) && $this->params['comment_type'] == 1) {
  70. $where[] = ['gc.virtual', 'null', null];
  71. }
  72. if (isset($this->params['comment_type']) && $this->params['comment_type'] == 2) {
  73. $where[] = ['gc.virtual', 'not null', null];
  74. }
  75. return $where;
  76. }
  77. /**
  78. * @notes 查看商品评价列表
  79. * @return array
  80. * @author ljj
  81. * @date 2021/8/12 5:01 下午
  82. */
  83. public function lists(): array
  84. {
  85. $lists = GoodsComment::alias('gc')
  86. ->leftjoin('user u', 'gc.user_id = u.id')
  87. ->leftjoin('order_goods og', 'gc.order_goods_id = og.id')
  88. ->leftjoin('goods g', 'g.id = og.goods_id')
  89. ->with('goods_comment_image')
  90. ->field('gc.id,u.avatar,u.nickname,u.sn as user_sn,og.goods_snap,og.goods_name,gc.goods_comment,gc.comment,gc.reply,gc.status,gc.create_time,gc.virtual,gc.spec_value_str')
  91. ->append(['comment_level','status_desc','reply_status_desc'])
  92. ->json(['goods_snap'])
  93. ->where($this->setSearch())
  94. ->whereBetweenTime('gc.create_time', (isset($this->params['start_time']) && !empty($this->params['start_time'])) ? $this->params['start_time'] : '1970-01-01', (isset($this->params['end_time']) && !empty($this->params['end_time'])) ? $this->params['end_time'] : time())
  95. ->limit($this->limitOffset, $this->limitLength)
  96. ->order('id','desc')
  97. ->select()
  98. ->toArray();
  99. if (empty($lists)) {
  100. return [];
  101. }
  102. foreach ($lists as &$list) {
  103. //处理用户头像路径
  104. if (empty($list['virtual'])) {
  105. // 真实评价
  106. $list['avatar'] = empty($list['avatar']) ? '' : FileService::getFileUrl($list['avatar']);
  107. //处理商品信息
  108. $list['goods_image'] = empty($list['goods_snap']->image) ? '' : FileService::getFileUrl($list['goods_snap']->image);
  109. $list['spec_value_str'] = $list['goods_snap']->spec_value_str ?? '';
  110. unset($list['goods_snap']);
  111. $list['comment_type_desc'] = '真实评价';
  112. } else {
  113. // 虚拟评价
  114. $virtual = json_decode($list['virtual'], true);
  115. $list['avatar'] = FileService::getFileUrl($virtual['avatar']);
  116. $list['nickname'] = $virtual['nickname'];
  117. $list['user_sn'] = $virtual['sn'];
  118. $list['goods_name'] = $virtual['goods_name'];
  119. $list['goods_image'] = FileService::getFileUrl($virtual['goods_image']);
  120. $list['comment_type_desc'] = '虚拟评价';
  121. }
  122. }
  123. return $lists;
  124. }
  125. /**
  126. * @notes 查看商品评价总数
  127. * @return int
  128. * @author ljj
  129. * @date 2021/8/12 5:01 下午
  130. */
  131. public function count(): int
  132. {
  133. return GoodsComment::alias('gc')
  134. ->leftjoin('user u', 'gc.user_id = u.id')
  135. ->leftjoin('order_goods og', 'gc.order_goods_id = og.id')
  136. ->leftjoin('goods g', 'g.id = og.goods_id')
  137. ->where($this->setSearch())
  138. ->whereBetweenTime('gc.create_time', (isset($this->params['start_time']) && !empty($this->params['start_time'])) ? $this->params['start_time'] : '1970-01-01', (isset($this->params['end_time']) && !empty($this->params['end_time'])) ? $this->params['end_time'] : time())
  139. ->count();
  140. }
  141. /**
  142. * @notes 设置导出字段
  143. * @return string[]
  144. * @author ljj
  145. * @date 2021/8/12 5:41 下午
  146. */
  147. public function setExcelFields(): array
  148. {
  149. return [
  150. // '数据库字段名(支持别名) => 'Excel表字段名'
  151. 'id' => 'ID',
  152. 'nickname' => '用户昵称',
  153. 'goods_name' => '商品名称',
  154. 'spec_value_str' => '商品规格',
  155. 'comment_level' => '评价等级',
  156. 'comment' => '买家评价',
  157. 'reply' => '商家回复',
  158. 'reply_status_desc' => '回复状态',
  159. 'status_desc' => '显示状态',
  160. 'create_time' => '评价时间',
  161. ];
  162. }
  163. /**
  164. * @notes 设置默认表名
  165. * @return string
  166. * @author ljj
  167. * @date 2021/8/12 5:41 下午
  168. */
  169. public function setFileName(): string
  170. {
  171. return '商品评价';
  172. }
  173. }