截流自动化的商城平台
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. <?php
  2. namespace app\admin\logic\goods;
  3. use app\common\basics\Logic;
  4. use app\common\model\goods\GoodsComment;
  5. use app\common\model\user\UserLevel;
  6. use app\common\server\UrlServer;
  7. class CommentLogic extends Logic
  8. {
  9. public static function lists($get)
  10. {
  11. $where = [
  12. ['gc.del', '=', 0],
  13. ];
  14. if($get['type'] == 0) { // 待回复
  15. $where[] = ['reply', '=', ''];
  16. }else{ // 已回复
  17. $where[] = ['reply', '<>', ''];
  18. }
  19. // 商家名称
  20. if(isset($get['shop_name']) && !empty($get['shop_name'])) {
  21. $where[] = ['s.name', 'like', '%'. trim($get['shop_name']) . '%'];
  22. }
  23. // 评价信息
  24. if(isset($get['search_word']) && !empty($get['search_word'])) {
  25. switch($get['search_type']) {
  26. case 'name':
  27. $where[] = ['g.name', 'like', '%'. trim($get['search_word']) . '%'];
  28. break;
  29. case 'sn':
  30. $where[] = ['u.sn', '=', trim($get['search_word'])];
  31. break;
  32. case 'nickname':
  33. $where[] = ['u.nickname', '=', trim($get['search_word'])];
  34. break;
  35. }
  36. }
  37. // 评价等级
  38. if(isset($get['goods_comment']) && !empty($get['goods_comment'])) {
  39. switch ($get['goods_comment']) {
  40. case 1:
  41. $where[] = ['gc.goods_comment', '>', 3];
  42. break;
  43. case 2:
  44. $where[] = ['gc.goods_comment', '=', 3];
  45. break;
  46. case 3:
  47. $where[] = ['gc.goods_comment', '<', 3];
  48. break;
  49. }
  50. }
  51. // 显示状态
  52. if(isset($get['status']) && !empty($get['status'])) {
  53. switch ($get['status']) {
  54. case 1:
  55. $where[] = ['gc.status', '=', 1];
  56. break;
  57. case 2: // 隐藏状态 前端不使用0的原因:empty()时0会被认为false
  58. $where[] = ['gc.status', '=', 0];
  59. break;
  60. }
  61. }
  62. // 日期范围
  63. if(isset($get['start_end']) && !empty($get['start_end'])) {
  64. $arr = explode('~', $get['start_end']);
  65. $start_time = strtotime($arr[0]);
  66. $end_time = strtotime($arr[1]);
  67. $where[] = ['gc.create_time', '>=', $start_time];
  68. $where[] = ['gc.create_time', '<=', $end_time];
  69. }
  70. $lists = GoodsComment::alias('gc')
  71. ->with(['goods_comment_image'])
  72. ->field('gc.id,gc.goods_comment,gc.goods_comment as goods_comment_desc,gc.comment,gc.reply,gc.status,gc.status as status_desc,gc.create_time,u.sn,u.nickname,u.avatar,u.level,g.name as goods_name,g.image as goods_image,gi.image as item_image,gi.spec_value_str,s.id as shop_id,s.name as shop_name,s.type as shop_type,s.logo as shop_logo')
  73. ->leftJoin('user u', 'u.id=gc.user_id')
  74. ->leftJoin('goods g', 'g.id=gc.goods_id')
  75. ->leftJoin('goods_item gi', 'gi.id=gc.item_id')
  76. ->leftJoin('shop s', 's.id=gc.shop_id')
  77. ->where($where)
  78. ->order('gc.create_time', 'desc')
  79. ->page($get['page'], $get['limit'])
  80. ->select()
  81. ->toArray();
  82. $count = GoodsComment::alias('gc')
  83. ->field('gc.id,gc.goods_comment,gc.goods_comment as goods_comment_desc,gc.comment,gc.reply,gc.status,gc.status as status_desc,gc.create_time,u.sn,u.nickname,u.avatar,u.level,g.name as goods_name,g.image as goods_image,gi.image as item_image,gi.spec_value_str')
  84. ->leftJoin('user u', 'u.id=gc.user_id')
  85. ->leftJoin('goods g', 'g.id=gc.goods_id')
  86. ->leftJoin('goods_item gi', 'gi.id=gc.item_id')
  87. ->leftJoin('shop s', 's.id=gc.shop_id')
  88. ->where($where)
  89. ->count();
  90. $levelArr = UserLevel::where('del', 0)->column('name', 'id');
  91. $shopTypeArr = [1=>'官方自营', 2=>'入驻商家'];
  92. foreach($lists as &$item) {
  93. // 头像
  94. $item['type'] = $get['type'];
  95. // 头像
  96. $item['avatar'] = UrlServer::getFileUrl($item['avatar']);
  97. // 商家图标
  98. $item['shop_logo'] = empty($item['shop_logo']) ? '' : UrlServer::getFileUrl($item['shop_logo']);
  99. $item['goods_image'] = empty($item['goods_image']) ? '' : UrlServer::getFileUrl($item['goods_image']);
  100. $item['item_image'] = empty($item['item_image']) ? '' : UrlServer::getFileUrl($item['item_image']);
  101. // 会员等级
  102. $item['levelName'] = $levelArr[$item['level']] ?? '无等级';
  103. // 评价图片
  104. $item['comment_image'] = array_column($item['goods_comment_image'], 'uri');
  105. foreach($item['comment_image'] as $key => $subItem) {
  106. $item['comment_image'][$key] = UrlServer::getFileUrl($subItem);
  107. }
  108. // 商家类型
  109. $item['shop_type_desc'] = $shopTypeArr[$item['shop_type']];
  110. }
  111. return [
  112. 'count' => $count,
  113. 'lists' => $lists
  114. ];
  115. }
  116. public static function changeStatus($post)
  117. {
  118. try{
  119. $goodsComment = GoodsComment::where('id', $post['id'])->findOrEmpty();
  120. if($goodsComment->isEmpty()) {
  121. throw new \think\Exception('评论不存在');
  122. }
  123. $goodsComment->status = $goodsComment->status ? 0 : 1;
  124. $goodsComment->update_time = time();
  125. $goodsComment->save();
  126. return true;
  127. }catch(\Exception $e) {
  128. self::$error = $e->getMessage();
  129. return false;
  130. }
  131. }
  132. public static function del($post)
  133. {
  134. try{
  135. $goodsComment = GoodsComment::where('id', $post['id'])->findOrEmpty();
  136. if($goodsComment->isEmpty()) {
  137. throw new \think\Exception('评论不存在');
  138. }
  139. $goodsComment->del = 1;
  140. $goodsComment->update_time = time();
  141. $goodsComment->save();
  142. return true;
  143. }catch(\Exception $e) {
  144. self::$error = $e->getMessage();
  145. return false;
  146. }
  147. }
  148. }