<?php if(!defined('IN_SDCMS')) exit;?>{include file="top.php"}
<title>{if !isempty($seotitle)}{$seotitle}{else}{$title}{/if}_{if $page>1}第{$page}页_{/if}{$catename}_{sdcms[web_name]}</title>
<meta name="keywords" content="{if !isempty($seokey)}{$seokey}{else}{$title}{/if}">
<meta name="description" content="{if !isempty($seodesc)}{$seodesc}{else}{$title}{/if}">
</head>

<body>

    {include file="head.php"}
    
    <div class="banner_inner" style="background:url({get_cate_self($mycatepic,$topid,'mycatepic',WEB_ROOT.'theme/20170105/images/b00.jpg')}) no-repeat center;">      
    </div>

    <div class="width container">
    	<div class="lefter">
        	<div class="left_title mts">
            	<h3>{get_catename($topid)}</h3>
                <p>{get_cate_self($mycateename,$topid,'mycateename','')}</p>
            </div>
            <div class="left_border">
                <ul>
                    {sdcms:rp top="0" table="sd_category" where="followid=$topid" order="catenum,cateid"}
                    {rp:eof}<li class="hover"><a href="{cateurl($topid)}">{get_catename($topid)}</a></li>{/rp:eof}
                    {php $sub_sonid=$rp[cateid]}
                    <li{is_active($rp[cateid],$parentid)}><a href="{cateurl($rp[cateid])}" title="{$rp[catename]}"><span class="am-icon-angle-right"></span>{$rp[catename]}</a></li>
                    {sdcms:rs top="0" table="sd_category" where="followid=$sub_sonid" order="catenum,cateid"}
                    <li class="small{is_active($rs[cateid],$parentid,' active')}"><a href="{cateurl($rs[cateid])}" title="{$rs[catename]}"{if $rs[isblank]==1} target="_blank"{/if}><span class="am-icon-angle-right"></span>{$rs[catename]}</a></li>
                    {/sdcms:rs}
                    {/sdcms:rp}
                </ul>
            </div>
            
            <div class="left_title mt20">
            	<h3>联系我们</h3>
                <p>Contact Us</p>
            </div>
            <div class="left_contact">
                {block("page_contact")}
            </div>
            
        </div>
        <div class="righter">
        	<div class="subject">
            	<div class="fl">{$catename}<span>{get_cate_self($mycateename,$topid,'mycateename','')}</span></div>
                <div class="fr">您的当前位置：<a href="{$webroot}">首页</a>{foreach $position as $rs} > <a href="{$rs['url']}" title="{$rs['url']}">{$rs['name']}</a>{/foreach}</div>
            </div>
        	<!---->
           <div class="news_show">
					<h1>{$title}</h1>
					<aside>日期：{date('Y-m-d',$createdate)}　人气：{$hits}</aside>
					<div class="intro">
                        {if $viewstate<100}
                            <div class="ui-card ui-m-40">
                                <div class="ui-card-header"><h5>友情提示</h5></div>
                                <div class="ui-card-body">
                                    <div class="ui-card-text ui-p-15">
                                    {if $viewstate==1}
                                        请先<a href="{N('login')}" class="ui-text-red ui-ml ui-mr">登录</a>或<a href="{N('reg')}" class="ui-text-red ui-ml ui-mr">注册</a>
                                    {/if}
                                    {if $viewstate==2}
                                        您的账户权限不足，无法查看！
                                    {/if}
                                    {if $viewstate==3}
                                        本文需要购买后才能继续阅读，价格：<span class="ui-text-red">{$price}</span> 元　 <a href="javascript:;" class="ui-modal-show" data-target="#mymodal-pay">【购买】</a>
                                    {/if}
                                    </div>
                                </div>
                            </div>
                        {else}
                            {$content}
                        {/if}
                        <div class="clear"></div>
                    </div>
                    {if $pagenum>1 && $view_lever==100}
                    <div class="ui-page ui-page-center ui-page-mid"><ul>{pagelist($page,$pagenum)}</ul></div>
                    {/if}
                    <div class="other">
                        <p>你觉得这篇文章怎么样？</p><a title="赞一下" class="digs" data-token="{$token}" data-url="{U('other/digs/','id='.$id.'&act=up','',1)}"><span class="ui-icon-like"></span><em>{$upnum}</em></a><a title="踩一下" class="digs" data-token="{$token}" data-url="{U('other/digs/','id='.$id.'&act=down','',1)}"><span class="ui-icon-unlike"></span><em>{$downnum}</em></a>
                    </div>
                    {if count($tagslist)>0}
                    <div class="tags ui-mt-20"><span class="ui-icon-tags"></span> 标签：{foreach $tagslist as $rs}<a href="{$rs['url']}" title="{$rs['name']}" target="_blank">{$rs['name']}</a>{/foreach}</div>
                    {/if}
				</div>
                {if count($tags)>0}
                <div class="h2"><span>相关内容</span></div>
                <ul class="like_news">
                	{sdcms:rs top="10" table="sd_content" where="$like" order="ontop desc,ordnum desc,id desc"}
           			{rs:eof}暂无资料{/rs:eof}
                	<li><span>[03-28]</span><a href="{$rs[link]}" title="{$rs[title]}"><em class="ui-icon-right"></em>{$rs[title]}</a></li>
                    {/sdcms:rs}
                </ul>
                {/if}
            </div>
            <!---->
        </div>
        <div class="clear"></div>
    </div>
    
    {include file="foot.php"}
 <div class="ui-modal" id="mymodal-pay">
	<div class="ui-modal-header">
		<div class="ui-modal-title">付款方式</div>
		<div class="ui-modal-close ui-rotate">×</div>
	</div>
	<div class="ui-modal-body">
		<form method="post" id="form_buy">
			<ul class="pay" id="orderpay" style="display:block;">
				{if USER_ID>0}<li><div><img src="{WEB_ROOT}api/pay/user/images/pay.png" data-config="user"><i class="ui-icon-check"></i></div></li>{/if}
				{if C('pay_alipay_open')==1}
				<li><div><img src="{WEB_ROOT}api/pay/alipay/images/pay.png" data-config="alipay"><i class="ui-icon-check"></i></div></li>
				{/if}
				{if C('pay_wxpay_open')==1}
				<li><div><img src="{WEB_ROOT}api/pay/wxpay/images/pay.png" data-config="wxpay"><i class="ui-icon-check"></i></div></li>
				{/if}
                {if C('pay_free_open')==1}
                <li><div><img src="{WEB_ROOT}api/pay/zfb/images/pay.png" data-config="zfb"><i class="ui-icon-check"></i></div></li>
                <li><div><img src="{WEB_ROOT}api/pay/weixin/images/pay.png" data-config="weixin"><i class="ui-icon-check"></i></div></li>
                {/if}
			</ul>
			<input type="hidden" name="payway" id="payway" value="" data-rule="支付方式:required;">
            <input type="hidden" name="token" value="{$token}">
			<button type="submit" class="ui-btn ui-btn-blue ui-btn-block ui-btn-big ui-mt-30">支付：{$price}元</button>
		</form>
	</div>
</div>
{if $price>0}
<script src="{WEB_ROOT}public/js/jquery.qrcode.js"></script>  
<script>
function freshorder(orderId)
{
	var interval=setInterval(function()
	{
		$.ajax(
		{
			type:"post",
			cache:"false",
			url:"{U('user/ordercheck')}",
			data:"token={$token}&orderid="+orderId,
			success:function(d)
			{
				if(d=='1')
				{
					location.href='{THIS_LOCAL}';
				}
			}
		})
	},1000);
};
function userpay()
{
	$.ajax(
	{
		type:'post',
		url:'{U("user/buy","id=$id","",1)}',
		data:'token={$token}',
		dataType:'json',
		error:function(e){alert(e.responseText);},
		success:function(d)
		{
			if(d.state=='success')
			{
				sdcms.success(d.msg);
				setTimeout(function(){location.href='{THIS_LOCAL}';},1500);
			}
			else
			{
				sdcms.error(d.msg);
			}
		}
	})
}

$(function()
{
	$("#form_buy").form(
	{
		type:2,
		hide:2,
		align:'center',
		result:function(form)
		{
			var payway=$("#payway").val();
			if(payway=='user')
			{
				userpay();
				return;
			}
			else
			{
				$.ajax(
				{
					type:'post',
					url:'{U("user/order")}',
					data:'token={$token}&id={$id}',
					dataType:'json',
					error:function(e){alert(e.responseText);},
					success:function(d)
					{
						if(d.state=='success')
						{
							var orderid=d.msg;
							/////
							{if !ismobile()}
							if(payway=="wxpay" || payway=="weixin" || payway=="zfb")
							{
								var name=(payway=="zfb")?'支付宝':'微信';
								$.ajax(
								{
									type:'get',
									dataType:'json',
									url:'{WEB_ROOT}api/pay/'+payway+'/p/api.php?type=3&orderid='+orderid,
									error:function(e){alert(e.responseText);},
									success:function(d)
									{
										$(".ui-dialog").remove();
										if(d.state=='success')
										{
											$.dialog(
											{
												'title':name+"支付",
												'text':'<div class="ui-text-center"><div id="qrcode" style="width:300px;height:300px;margin:10px auto"></div><p>请打开【'+name+'】，使用【扫一扫】完成付款。</p></div>',
												'okval':'已完成支付',
												'ok':function(e)
												{
													location.href='{THIS_LOCAL}';
												}
											});
											$("#qrcode").qrcode({width:300,height:300,text:d.msg}); 
										}
										else
										{
											sdcms.error(d.msg);
										}
									}
								});
								freshorder(orderid);
								return false;
							}
							{/if}
							var root="p";
							{if ismobile()}
							var root="m";
							{/if}
							{if isweixin()}
							if(payway=='wxpay' || payway=='weixin')
							{
								var root='w';
							}
							{/if}
							location.href='{WEB_ROOT}api/pay/'+payway+'/'+root+'/api.php?type=3&orderid='+orderid;
							/////
						}
						else
						{
							sdcms.error(d.msg);
						}
					}
				})
				
			}
		}
	});
});
</script>
{/if}
    
</body>
</html>