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 @@
那,那是一封写给南部母亲的信。我茫然站在骑楼下,我又看到永远的樱子走到街心。其实雨下得并不大,却是一生一世中最大的一场雨。而那封信是这样写的,年轻的樱子知不知道呢?
-颜色:红色,尺码:M
-那,那是一封写给南部母亲的信。我茫然站在骑楼下,我又看到永远的樱子走到街心。其实雨下得并不大,却是一生一世中最大的一场雨。而那封信是这样写的,年轻的樱子知不知道呢?
-颜色:红色,尺码:M
-那,那是一封写给南部母亲的信。我茫然站在骑楼下,我又看到永远的樱子走到街心。其实雨下得并不大,却是一生一世中最大的一场雨。而那封信是这样写的,年轻的樱子知不知道呢?
-- 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 += ''+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 += '