diff --git a/application/index/controller/Goods.php b/application/index/controller/Goods.php index 131dd08ff9bf9dba6feca147be04fa51fa581a7b..830dbf595533d4d6ba3c9214e2e6c2d3f140dad6 100755 --- a/application/index/controller/Goods.php +++ b/application/index/controller/Goods.php @@ -12,6 +12,7 @@ namespace app\index\controller; use think\facade\Hook; use app\service\GoodsService; +use app\service\GoodsCommentsService; use app\service\SeoService; /** @@ -45,10 +46,10 @@ class Goods extends Common */ public function Index() { - $id = input('id'); + $goods_id = input('id'); $params = [ 'where' => [ - 'id' => $id, + 'id' => $goods_id, 'is_delete_time' => 0, ], 'is_photo' => true, @@ -61,17 +62,17 @@ class Goods extends Common return $this->fetch('/public/tips_error'); } else { // 当前登录用户是否已收藏 - $ret_favor = GoodsService::IsUserGoodsFavor(['goods_id'=>$id, 'user'=>$this->user]); + $ret_favor = GoodsService::IsUserGoodsFavor(['goods_id'=>$goods_id, 'user'=>$this->user]); $ret['data'][0]['is_favor'] = ($ret_favor['code'] == 0) ? $ret_favor['data'] : 0; // 商品评价总数 - $ret['data'][0]['comments_count'] = GoodsService::GoodsCommentsTotal($id); + $ret['data'][0]['comments_count'] = GoodsService::GoodsCommentsTotal($goods_id); // 商品收藏总数 - $ret['data'][0]['favor_count'] = GoodsService::GoodsFavorTotal(['goods_id'=>$id]); + $ret['data'][0]['favor_count'] = GoodsService::GoodsFavorTotal(['goods_id'=>$goods_id]); // 钩子 - $this->PluginsHook($id, $ret['data'][0]); + $this->PluginsHook($goods_id, $ret['data'][0]); // 商品数据 $this->assign('goods', $ret['data'][0]); @@ -88,13 +89,13 @@ class Goods extends Common } // 二维码 - $this->assign('qrcode_url', MyUrl('index/qrcode/index', ['content'=>urlencode(base64_encode(MyUrl('index/goods/index', ['id'=>$id], true, true)))])); + $this->assign('qrcode_url', MyUrl('index/qrcode/index', ['content'=>urlencode(base64_encode(MyUrl('index/goods/index', ['id'=>$goods_id], true, true)))])); // 商品访问统计 - GoodsService::GoodsAccessCountInc(['goods_id'=>$id]); + GoodsService::GoodsAccessCountInc(['goods_id'=>$goods_id]); // 用户商品浏览 - GoodsService::GoodsBrowseSave(['goods_id'=>$id, 'user'=>$this->user]); + GoodsService::GoodsBrowseSave(['goods_id'=>$goods_id, 'user'=>$this->user]); // 左侧商品 看了又看 $params = [ @@ -134,7 +135,8 @@ class Goods extends Common * @version 1.0.0 * @date 2019-04-22 * @desc description - * @param [array] $params [输入参数] + * @param [int] $goods_id [商品id] + * @param [array] $params [输入参数] */ private function PluginsHook($goods_id, &$goods) { @@ -259,4 +261,47 @@ class Goods extends Common $params = input('post.'); return GoodsService::GoodsSpecDetail($params); } + + /** + * 商品评论 + * @author Devil + * @blog http://gong.gg/ + * @version 1.0.0 + * @datetime 2019-05-13T21:47:41+0800 + */ + public function Comment() + { + // 参数 + $params = input(); + + // 分页 + $number = 10; + $page = max(1, isset($params['page']) ? intval($params['page']) : 1); + + // 条件 + $where = ['goods_id'=>$params['goods_id']]; + + // 获取总数 + $total = GoodsCommentsService::GoodsCommentsTotal($where); + $page_total = ceil($total/$number); + $start = intval(($page-1)*$number); + + // 获取列表 + $data_params = array( + 'm' => $start, + 'n' => $number, + 'where' => $where, + 'is_public' => 1, + ); + $data = GoodsCommentsService::GoodsCommentsList($data_params); + + // 返回数据 + $result = [ + 'number' => $number, + 'total' => $total, + 'page_total' => $page_total, + 'data' => $data['data'], + ]; + return DataReturn('请求成功', 0, $result); + } } diff --git a/application/index/view/default/goods/index.html b/application/index/view/default/goods/index.html index eff70b6cfcfb42429304af5a18612bcecbe4fa05..53e286af5f5e46b734f6bb3ee3eedf830cb90f2b 100755 --- a/application/index/view/default/goods/index.html +++ b/application/index/view/default/goods/index.html @@ -184,7 +184,7 @@
  • 浏览次数{{$goods.access_count}}
  • -
  • +
  • 累计评价{{$goods.comments_count}}
  • @@ -383,14 +383,14 @@ {{/if}} -
    +
    +
    {{if !empty($goods['attribute'])}} @@ -430,61 +431,13 @@
    -
    -
    - - - -
    -
    - -
    - 魔鬼 - 评论于 -
    -
    -
    -

    那,那是一封写给南部母亲的信。我茫然站在骑楼下,我又看到永远的樱子走到街心。其实雨下得并不大,却是一生一世中最大的一场雨。而那封信是这样写的,年轻的樱子知不知道呢?

    -

    颜色:红色,尺码:M

    -
    - 管理员回复: - 我打算在下个月和樱子结婚。 -
    -
    -
    -
    - - - -
    -
    - -
    - 魔鬼 - 评论于 -
    -
    -
    -

    那,那是一封写给南部母亲的信。我茫然站在骑楼下,我又看到永远的樱子走到街心。其实雨下得并不大,却是一生一世中最大的一场雨。而那封信是这样写的,年轻的樱子知不知道呢?

    -

    颜色:红色,尺码:M

    -
    -
    -
    - - - -
    -
    - -
    - 魔鬼 - 评论于 -
    -
    -
    -

    那,那是一封写给南部母亲的信。我茫然站在骑楼下,我又看到永远的樱子走到街心。其实雨下得并不大,却是一生一世中最大的一场雨。而那封信是这样写的,年轻的樱子知不知道呢?

    -
    -
    +
    +
    +
    +
    + + 没有评论数据 +
    diff --git a/application/plugins/newuserreduction/Hook.php b/application/plugins/newuserreduction/Hook.php index 8d447b952bdb1383c8a6d3261663a4dd73c059b3..fa277bf8ceeed5947cfe5a7a9e011be0cba37488 100755 --- a/application/plugins/newuserreduction/Hook.php +++ b/application/plugins/newuserreduction/Hook.php @@ -99,8 +99,14 @@ class Hook ]; // 金额 - $params['data']['base']['increase_price'] -= $price; - $params['data']['base']['actual_price'] -= $price; + if($params['data']['base']['increase_price'] > 0) + { + $params['data']['base']['increase_price'] -= $price; + } + if($params['data']['base']['actual_price'] > 0) + { + $params['data']['base']['actual_price'] -= $price; + } } return DataReturn('无需处理', 0); } else { diff --git a/application/service/GoodsCommentsService.php b/application/service/GoodsCommentsService.php index 20a38202c82d2137bf3ccb416094660f3644e3d9..8929287f24fbf7f584fdce2e8ccadbcf11187f9d 100644 --- a/application/service/GoodsCommentsService.php +++ b/application/service/GoodsCommentsService.php @@ -156,7 +156,21 @@ class GoodsCommentsService foreach($data as &$v) { // 用户信息 - $v['user'] = UserService::GetUserViewInfo($v['user_id']); + $user = UserService::GetUserViewInfo($v['user_id']); + if(!isset($params['is_public']) || $params['is_public'] == 1) + { + $v['user'] = [ + 'avatar' => $user['avatar'], + 'user_name_view' => ($v['is_anonymous'] == 1) ? '匿名' : substr($user['user_name_view'], 0, 3).'***'.substr($user['user_name_view'], -3), + ]; + } else { + $v['user'] = $user; + } + + + // 订单规格 + $spec = Db::name('OrderDetail')->where(['order_id'=>$v['order_id'], 'goods_id'=>$v['goods_id']])->value('spec'); + $v['spec'] = empty($spec) ? null : json_decode($spec); // 是否 $v['is_reply_text'] = isset($common_is_text_list[$v['is_reply']]) ? $common_is_text_list[$v['is_reply']]['name'] : ''; diff --git a/public/static/common/js/common.js b/public/static/common/js/common.js index 639acb89996bf808adb5efbe4aa17bc84c38b374..946cb90027a5d24053fcb643c93009fe68be4e8c 100755 --- a/public/static/common/js/common.js +++ b/public/static/common/js/common.js @@ -1194,6 +1194,66 @@ function MobileBrowserEnvironment() return null; } +/** + * [pagelibrary 分页按钮获取] + * @param {[int]} total [数据总条数] + * @param {[int]} number [页面数据显示条数] + * @param {[int]} page [当前页码数] + * @param {[int]} sub_number [按钮生成个数] + * @return {[string]} [html代码] + */ +function PageLibrary(total, number, page, sub_number) +{ + if((total || null) == null) return ''; + if((page || null) == null) page = 1; + if((number || null) == null) number = 15; + if((sub_number || null) == null) sub_number = 2; + + var page_total = Math.ceil(total/number); + if(page > page_total) page = page_total; + page = (page <= 0) ? 1 : parseInt(page); + + var html = '
    • 1) ? '' : 'class="am-disabled"'; + page_x = page-1; + html += '>«
    • '; + + var html_before = ''; + var html_after = ''; + var html_page = '
    • '+page+'
    • '; + if(sub_number > 0) + { + /* 前按钮 */ + if(page > 1) + { + total = (page-sub_number < 1) ? 1 : page-sub_number; + for(var i=page-1; i>=total; i--) + { + html_before = '
    • '+i+'
    • '+html_before; + } + } + + /* 后按钮 */ + if(page_total > page) + { + total = (page+sub_number > page_total) ? page_total : page+sub_number; + for(var i=page+1; i<=total; i++) + { + html_after += '
    • '+i+'
    • '; + + } + } + } + + html += html_before+html_page+html_after; + + html += ' 0 && page < page_total) ? '' : ' class="am-disabled"'; + page_y = page+1; + html += '>»
    '; + return html; +} + // 公共数据操作 $(function() { diff --git a/public/static/index/default/css/goods.css b/public/static/index/default/css/goods.css index 0311fff61ad60d7f691ee8951ad241d514b99245..af7330d79a0d2c5b34242e9cb128188a9b41fdd0 100755 --- a/public/static/index/default/css/goods.css +++ b/public/static/index/default/css/goods.css @@ -66,6 +66,8 @@ input{font-size:12px;font-size:100%;outline:none;line-height:normal;color:#444;} .goods-comment .am-comment-main { border: 1px solid #eee; } .goods-comment .comment-spec { margin-top: 5px; color: #B0B0B0; } .comment-reply { border-top: 1px dashed #eee; margin-top: 10px; padding-top: 10px; } +.goods-comment .am-comment .am-comment-hd { background: #fbfbfb; } +.goods-comment .am-comment .am-comment-main:after { border-right-color: #fbfbfb; } .comment-reply-title { color: #666; } .comment-reply-desc { color: #905602; } diff --git a/public/static/index/default/js/goods.js b/public/static/index/default/js/goods.js index 25905a1bf136092b3f610e236fdf354b2b76724b..0404e4b1067ee20aae8cfacef155e72659b71592 100755 --- a/public/static/index/default/js/goods.js +++ b/public/static/index/default/js/goods.js @@ -18,6 +18,82 @@ function poptit_close() } } +/** + * 评论记录ajax请求 + * @author Devil + * @blog http://gong.gg/ + * @version 1.0.0 + * @datetime 2019-05-13T21:39:55+0800 + * @param {[int]} page [分页值] + */ +function GoodsCommentsHtml(page) +{ + $('.goods-page-no-data').addClass('none'); + + $.ajax({ + url: $('.goods-comment').data('url'), + type:'POST', + data:{"goods_id": $('.goods-comment').data('goods-id'), "page": page}, + dataType:'json', + success:function(result) + { + if(result.code == 0) + { + var html = ''; + for(var i in result.data.data) + { + html += '
    '; + html += ''+result.data.data[i]['user']['user_name_view']+''; + html += '
    '; + html += '
    '; + html += '
    '; + html += ''+result.data.data[i]['user']['user_name_view']+''; + html += ' 评论于 '; + html += '
    '; + html += '
    '; + html += '
    '; + html += '

    '+result.data.data[i]['content']+'

    '; + + // 规格 + if((result.data.data[i]['spec'] || null) != null) + { + var spec_string = ''; + for(var s in result.data.data[i]['spec']) + { + if(s > 0) + { + spec_string += ' | '; + } + spec_string += result.data.data[i]['spec'][s]['type']+':'+result.data.data[i]['spec'][s]['value']; + } + html += '

    '+spec_string+'

    '; + } + + // 回复 + if(result.data.data[i]['is_reply'] == 1 && (result.data.data[i]['reply'] || null) != null) + { + html += '
    '; + html += '管理员回复:'; + html += ''+result.data.data[i]['reply']+''; + html += '
    '; + } + html += '
    '; + html += '
    '; + } + + $('.goods-comment-content').html(html); + $('.goods-page-container').html(PageLibrary(result.data.total, result.data.number, page, 2)); + } + + // 没有数据 + if($('.goods-comment-content article').length <= 0) + { + $('.goods-page-no-data').removeClass('none'); + } + } + }); +} + /** * 购买/加入购物车 * @author Devil @@ -513,6 +589,30 @@ $(function() { t.val((value <= 1) ? 1 : value); }); + // 评论 + GoodsCommentsHtml(1); + $(document).on('click', '.goods-page-container .pagelibrary a', function() + { + var page = $(this).data('page') || null; + if(page != null) + { + // 获取数据 + GoodsCommentsHtml(page); + + // 回到评论顶部位置 + var top = $('.introduce-main').offset().top; + $(window).smoothScroll({position: top}); + } + }); + + // 累计评价点击事件 + $('.tm-ind-panel .ind-panel-comment').on('click', function() + { + var top = $('.introduce-main').offset().top; + $(window).smoothScroll({position: top}); + $('.introduce-main .am-tabs').tabs('open', 1); + }); + }); // 浏览器窗口实时事件