异步获取评论

php

	/**
	 * [getGoodsVote 异步获取商品评价]
	 * @Author:hkz
	 * @DateTime:2016-12-08
	 * @return [type] [description]
	 */
	public function getGoodsVote(){
	    $vote_model = M('vote');
		$goods_id = I('get.goods_id',0)+0;
    	$f='tb1.id,tb1.spec_info,tb1.store_eval,tb1.points,tb1.rank,tb1.content,tb1.img,tb1.posttime,tb2.nickname,tb2.head_url,tb2.level';
		$w['tb1.goods_id'] = array('eq',$goods_id);
		$w['tb1.is_show'] = array('eq',1);
		$w['tb1.is_del'] = array('eq',0);
		$w['show_start_time'] = array('lt',time());
		$vote_num = $vote_model->alias('tb1')->where($w)->count();
		if(I('get.type')=='pic'){
			$w['tb1.img'] = array('neq','');
		}
		$w1['goods_id'] = array('eq',$goods_id);
		$w1['is_show'] = array('eq',1);
		$w1['is_del'] = array('eq',0);
		$w1['img'] = array('neq','');
		$w1['show_start_time'] = array('lt',time());
		$img_count = $vote_model->where($w1)->count();

		$count = $vote_model->alias('tb1')->where($w)->count();
		$page = new \Think\Page($count,5);
		$comment_list = $vote_model->alias('tb1')->join('left join '.C('WillshopDatabase').'.member as tb2 on tb1.member_id=tb2.id')->where($w)->order('posttime desc')->field($f)->limit($page->firstRow.','.$page->listRows)->order('posttime desc')->select();
		foreach($comment_list as $ka=>$va){
			$comment_list[$ka]['img'] = !empty($va['img'])?explode(',',$va['img']):'';//分解小图
			$comment_list[$ka]['nickname'] = mb_substr($va['nickname'],0,1,'utf-8').'***'.mb_substr($va['nickname'],-1,1,'utf-8');//组合昵称
			if(substr($va['head_url'],0,4)=='http'){
				$comment_list[$ka]['head_url'] = $va['head_url'];
			}else{
				$comment_list[$ka]['head_url'] = C('ImageHostName').'/'.$va['head_url'];
			}
			if($va['points']==5){
				$comment_list[$ka]['remark']='非常满意';
			}elseif($va['points']==4){
				$comment_list[$ka]['remark']='满意';
			}elseif($va['points']==3){
				$comment_list[$ka]['remark']='一般';
			}elseif($va['points']==2){
				$comment_list[$ka]['remark']='不满意';
			}elseif($va['points']==1){
				$comment_list[$ka]['remark']='非常不满意';
			}else{
				$comment_list[$ka]['remark']='未知';
			}	
		}
		$comment['comment_page'] = $page->show();//评论分页
		$comment['comment_img_count'] = $img_count;//评论分页
		$comment['comment_total'] = $count;//评论总条数
		$comment['rank'] = $this->getCommentRank($goods_id);//获取评价等级
		$this->assign('comment_list',$comment_list);
		$this->assign('comment',$comment);
		$this->assign('vote_num',$vote_num);
		$content = $this->fetch('ajax_get_vote');
		echo $content;exit;
	}

html

<!--商品评价-->
<notempty name="comment_list">
<input type="hidden" id="vote_type" value="<{$Think.get.type}>">
<input type="hidden" id="vote_page" value="<{$Think.get.p}>">
<div class="goods-evaluation">
	<div class="evaluation">
		<div class="pingfen">
			<div class="p"><span class="b"><{$comment.rank.good_rank_percent}></span>%</div>
			<div class="t">商品满意度</div>
		</div>
		<div class="ping-fen-bar-box">
			<div class="ping-fen-bar">
				<span class="t">好评(<{$comment.rank.good_rank_percent}>%)</span>
				<div class="bar"><span class="lang" style="width: <{$comment.rank.good_rank_percent}>%;"></span></div>
			</div>
			<div class="ping-fen-bar">
				<span class="t">中评(<{$comment.rank.medium_rank_percent}>%)</span>
				<div class="bar"><span class="lang" style="width: <{$comment.rank.medium_rank_percent}>%;"></span></div>
			</div>
			<div class="ping-fen-bar ping-fen-bar-last">
				<span class="t">差评(<{$comment.rank.bad_rank_percent}>%)</span>
				<div class="bar"><span class="lang" style="width: <{$comment.rank.bad_rank_percent}>%;"></span></div>
			</div>
		</div>
		<div class="virtual-line"></div>
<!-- 		<div class="user-add-jifen">
			<div class="t">获得认真评价积分:</div>
			<div class="user-box">
				<foreach name="comment.high_points" item="va">
					<div class="user mt10">1.<span class="name"><{$va.nickname}></span><span class="jifen">+<{$va.get_points}></span></div>
				</foreach>
			</div>
		</div> -->
	</div>
	<div class="leixing">
		<a class="all_vote <if condition="$Think.get.type neq pic">hot</if>" href="javascript:void(0)">全部评价(<{$vote_num}>)</a>
		<a class="vote_img <if condition="$Think.get.type eq pic">hot</if>" href="javascript:void(0)">晒图(<{$comment.comment_img_count}>)</a>
	</div>
	<div class="user-pingjia-box">
		<foreach name="comment_list" item="va">
			<div class="user-pingjia">
				<div class="head">
					<img class="p" src="<{$va.head_url}>" onerror="this.src='__PUBLIC__/default/images/error.jpg'"/>
					<div class="t"><span class="name"><{$va.nickname}></span><span class="h">(<{:getLevelName($va['level'])}>)</span></div>
				</div>
				<div class="context">
					<{$va.content}>
					<notempty name="va.img">
						<div class="p pr">
							<foreach name="va.img" item="vb">
								<img class="s" src="<{:C('ImageHostName')}><{$vb}>">
							</foreach>
							<img class="b" />
						</div>
					</notempty>
					<notempty name="va.store_eval">
						<div class="seller-return">卖家回复:<{$va.store_eval}></div>
					</notempty>
				</div>
				<div class="manyi">
					<div class="stars">
					<div class="star-default">
					<for start="0" end="5">
						<if condition="$va.points gt $i">
							<div class="star-liang star-liang1"></div>
						</if>
					</for>
					</div><{$va.remark}></div>
					<div class="time"><{$va.posttime|date="Y-m-d H:i:s",###}></div>
					<div class="spec"><{$va.spec_info}></div>
				</div>
			</div>
		</foreach>
	</div>
</div>
<div class="pagination n tr">
	<{$comment.comment_page}>
</div>
<else/>
<div class="empty management">
	<div class="empty-img"></div>
	<p class="empty-content">暂无记录~</p>
</div>
</notempty>
<script>
	$('.pagination a').click(function(){
		$('.pagination a').attr('href','javacript:void(0)');
		var num  = $(this).html();
		var now_p = 1;
		if($('#vote_page').val()>1){
			now_p = $('#vote_page').val();
		}
		if($(this).is('.next')){
			num = Number(now_p) + 1;
		}else if($(this).is('.prev')){
			num = Number(now_p) - 1;
		}else if($(this).is('.first')){
			num = 1;
		}else if($(this).html().indexOf("...")>=0){
			num = parseInt($(this).html().replace("...",''));
		}else if($(this).is('.end')){
			num = $('.pagination .num:last').html();
		}
		var goods_id = $('#goods_id').val();
		var type = $('#vote_type').val();
		layer.load(2);
		$.get("<{:U('Goods/getGoodsVote')}>",{goods_id:goods_id,p:num,type:type},function (data){
			layer.closeAll("loading");
			$('#tab-content2').html(data);
		})
	})

	$('.vote_img').click(function (){
		var goods_id = $('#goods_id').val();
		layer.load(2);
		$.get("<{:U('Goods/getGoodsVote')}>",{goods_id:goods_id,type:'pic'},function (data){
			layer.closeAll("loading");
			$('#tab-content2').html(data);
		})
	})

	$('.all_vote').click(function (){
		var goods_id = $('#goods_id').val();
		layer.load(2);
		$.get("<{:U('Goods/getGoodsVote')}>",{goods_id:goods_id},function (data){
			layer.closeAll("loading");
			$('#tab-content2').html(data);
		})
	})
</script>
<!--商品评价end-->

jq:

//异步获取评论
$('.lab2').click(function (){
	var goods_id = $('#goods_id').val();
	layer.load(2);
	$.get($('#voteurl').val(),{goods_id:goods_id},function (data){
		layer.closeAll("loading");
		$('#tab-content2').html(data);
	})
})

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值