截流自动化的商城平台
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

CommentLogic.php 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <?php
  2. namespace app\shop\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.shop_id', '=', $get['shop_id']],
  13. ['gc.del', '=', 0],
  14. ];
  15. if($get['type'] == 0) { // 待回复
  16. $where[] = ['reply', '=', ''];
  17. }else{ // 已回复
  18. $where[] = ['reply', '<>', ''];
  19. }
  20. // 评价信息
  21. if(isset($get['search_word']) && !empty($get['search_word'])) {
  22. switch($get['search_type']) {
  23. case 'name':
  24. $where[] = ['g.name', 'like', '%'. trim($get['search_word']) . '%'];
  25. break;
  26. case 'sn':
  27. $where[] = ['u.sn', '=', trim($get['search_word'])];
  28. break;
  29. case 'nickname':
  30. $where[] = ['u.nickname', '=', trim($get['search_word'])];
  31. break;
  32. }
  33. }
  34. // 评价等级
  35. if(isset($get['goods_comment']) && !empty($get['goods_comment'])) {
  36. switch ($get['goods_comment']) {
  37. case 1:
  38. $where[] = ['gc.goods_comment', '>', 3];
  39. break;
  40. case 2:
  41. $where[] = ['gc.goods_comment', '=', 3];
  42. break;
  43. case 3:
  44. $where[] = ['gc.goods_comment', '<', 3];
  45. break;
  46. }
  47. }
  48. // 显示状态
  49. if(isset($get['status']) && !empty($get['status'])) {
  50. switch ($get['status']) {
  51. case 1:
  52. $where[] = ['gc.status', '=', 1];
  53. break;
  54. case 2: // 隐藏状态 前端不使用0的原因:empty()时0会被认为false
  55. $where[] = ['gc.status', '=', 0];
  56. break;
  57. }
  58. }
  59. // 日期范围
  60. if(isset($get['start_end']) && !empty($get['start_end'])) {
  61. $arr = explode('~', $get['start_end']);
  62. $start_time = strtotime($arr[0]);
  63. $end_time = strtotime($arr[1]);
  64. $where[] = ['gc.create_time', '>=', $start_time];
  65. $where[] = ['gc.create_time', '<=', $end_time];
  66. }
  67. $lists = GoodsComment::alias('gc')
  68. ->with(['goods_comment_image'])
  69. ->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')
  70. ->leftJoin('user u', 'u.id=gc.user_id')
  71. ->leftJoin('goods g', 'g.id=gc.goods_id')
  72. ->leftJoin('goods_item gi', 'gi.id=gc.item_id')
  73. ->where($where)
  74. ->order('gc.create_time', 'desc')
  75. ->page($get['page'], $get['limit'])
  76. ->select()
  77. ->toArray();
  78. $count = GoodsComment::alias('gc')
  79. ->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')
  80. ->leftJoin('user u', 'u.id=gc.user_id')
  81. ->leftJoin('goods g', 'g.id=gc.goods_id')
  82. ->leftJoin('goods_item gi', 'gi.id=gc.item_id')
  83. ->where($where)
  84. ->count();
  85. $levelArr = UserLevel::where('del', 0)->column('name', 'id');
  86. foreach($lists as &$item) {
  87. // 类型
  88. $item['type'] = $get['type'];
  89. // 头像
  90. $item['avatar'] = UrlServer::getFileUrl($item['avatar']);
  91. // 会员等级
  92. $item['levelName'] = $levelArr[$item['level']] ?? '无等级';
  93. // 评价图片
  94. $item['comment_image'] = array_column($item['goods_comment_image'], 'uri');
  95. foreach($item['comment_image'] as $key => $subItem) {
  96. $item['comment_image'][$key] = UrlServer::getFileUrl($subItem);
  97. }
  98. $item['goods_image'] = UrlServer::getFileUrl($item['goods_image']);
  99. $item['item_image'] = empty($item['item_image']) ? '' : UrlServer::getFileUrl($item['item_image']);
  100. }
  101. return [
  102. 'count' => $count,
  103. 'lists' => $lists
  104. ];
  105. }
  106. public static function reply($post)
  107. {
  108. try{
  109. GoodsComment::where('id', $post['id'])->update([
  110. 'reply' => trim($post['reply']),
  111. 'update_time' => time()
  112. ]);
  113. return true;
  114. }catch(\Exception $e) {
  115. self::$error = $e->getMessage();
  116. return false;
  117. }
  118. }
  119. }