万能表单+ajax+JQuery实现网站文章包月

mac2024-05-10  8

在单篇文章购买的基础上改进,修改为付费购买实现文章包月阅读。 在之前的基础上新增一个表单,用来控制文章购买时间及金额。 前端内容页代码块

<%csharp%> string chanid = ""; <%/csharp%> <%set DataTable pingjyiuDt=NetWingGetAnyTable("select channel_id from dt_article where id="+{model.id}+"")%> <%loop pingjyiuDr pingjyiuDt%> <%csharp%> chanid = {pingjyiuDr[channel_id]}; <%/csharp%> <%/loop%> <script type="text/javascript"> <%csharp%> DTcms.Model.users muc=GetUserInfo(); if(muc==null) { <%/csharp%> $('#centent').html('<div></div>'); layer.confirm('请先登陆,再继续阅读文章!', { btn: ['确定'] //按钮 }, function(){ location.href = '/login.aspx'; }); <%csharp%> }else { <%/csharp%> var userid=<%=muc.id%>; var wzid=<%=model.id%>; var title="<%=model.title%>"; $.ajax({ url: '/dev/ClickLoad.ashx', type: 'POST', dataType: 'json', data: { action: 'GetContent', userid:userid , wzid: wzid, title:title, }, success: function(d) { if(d.code==0){ $('#centent').html(d.content); }else{ $('#centent').html('<div></div>'); layer.msg(d.msg, function(){ $('#centent').html('<div class="goumai">'+ '<a href="javascript:;" οnclick="goumai()">点击购买</a>'+ '</div>'); }); } }, error: function(e) {} }) <%csharp%> } <%/csharp%> </script> <!--点击购买按钮弹窗--> <script> function goumai(){ layer.open({ type: 1, title: false, closeBtn: 0, shadeClose: true, skin: 'yourclass', content: $("#goumaiye") }); } </script> <div id="goumaiye" style="display: none; width: 320px;height: 440px; padding: 15px 15px;"> <div class="zffs1"> <p>选择时间:</p> <%set DataTable baoyueDt=NetWingGetAnyTable("select top 4 * from nw_customform_user_paytime")%> <%loop baoyueDr baoyueDt%> <a href="javascript:;" onclick="jine(this,{baoyueDr[id]})" id="gmshz{baoyueDr[id]}" class="check-btn" name="gmshz"> <p id="moth{baoyueDr[id]}" name="moth">{baoyueDr[moth]}</p> <span id="money{baoyueDr[id]}" name="money">{baoyueDr[money]}</span> <input type="text" value="{baoyueDr[moth]}" id="sj{baoyueDr[id]}" style="display: none;"> <input type="text" value="{baoyueDr[money]}" id="je{baoyueDr[id]}" style="display: none;"/> </a> <%/loop%> </div> <input type="text" value="" id="goidbi" style="display: none;"/> <input type="text" value="" id="moths" style="display: none;"/> <script type="application/javascript"> function jine(obj,kid){ $('.check-btn').removeClass('border-red'); $(obj).addClass('border-red'); var radio =document.getElementById("je"+kid).value; var gmtimelong =document.getElementById("sj"+kid).value; document.getElementById("goidbi").value =radio; document.getElementById("moths").value =gmtimelong; } </script> <div class="zfjr1" id="method"> <p>选择支付方式:</p> <%set DataTable list1=get_payment_list(0, "is_lock=0 and is_mobile!=2")%> <%loop dr1 list1%> <%set (decimal){poundage_amount}=get_payment_poundage_amount({strtoint({dr1[id]})})%> <div class="wrapper"> <div class="redio-box"> <input type="radio" id="boy{dr1[id]}" value="{dr1[id]}" name="zffs" /><span></span> </div> <label for="boy{dr1[id]}">{dr1[title]}</label> </div> <%/loop%> </div> <div class="zftj"> <input type="submit" name="btnSubmit" value="立即支付" onclick="tijiaozf()" id="btnSubmit" class="btn"> </div> <div class="yqts"> <p>友情提示:</p> <span>如果您有需要在实行购买,一经购买,无法退款,望周知</span> </div> <div class="zhifu_box" style="display: none;"> <div class="zhifu"> <div id="field_tab_content" class="tab-content" style=""> <%csharp%> int uesid = 0; <%/csharp%> <%set DTcms.Model.users vfm=GetUserInfo()%> <%if(vfm!=null)%> <%csharp%> uesid=vfm.id;//cs代码变量赋值 <%/csharp%> <%else%> <%/if%> <%csharp%> string actions =""; string wzid =""; string title = ""; <%/csharp%> <%set DataTable pingjyiuuDt=NetWingGetAnyTable("select * from dt_article art,dt_article_attribute_value val where art.id=val.article_id and art.id="+{model.id}+"")%> <%loop pingjyiuuDr pingjyiuuDt%> <%csharp%> actions={pingjyiuuDr[channel_id]}; wzid={pingjyiuuDr[id]}; title = {pingjyiuuDr[title]}; <%/csharp%> <%/loop%> <!--数字开始--> <dl> <dt>文章标题</dt> <dd> <input class="wzbt" name="field_control_title" type ="text" id="field_control_title" value="{title}" readonly="readonly"> </dd> </dl> <!--日期时间开始--> <%csharp%> string time=DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); <%/csharp%> <dl> <dt>购买时间</dt> <dd> <input class="gmsj" name="field_control_time" type="text" value="{time}" id="field_control_time" readonly="readonly"> </dd> </dl> </div> </div> </div> </div> <!--点击购买按钮弹窗 end--> <script type="text/javascript"> function tijiaozf() { var wzid = {wzid};//文章ID var wztitle = document.getElementById("field_control_title").value;//文章标题 var gmtime = document.getElementById("field_control_time").value;//购买时间 var method = $('input[name="zffs"]:checked').val();//支付方式 var moneyyi = document.getElementById("goidbi").value;//支付金额 var money = (moneyyi * 1); if (wzid == "" || wztitle == "") { alert("没有获取到文章信息!"); } else if (money <= 0) { alert("金额不能小于等于0!"); } else { $.ajax({ type: 'POST', url: '/dev_m/nw_customform_user_ffwz.ashx', data: { "action": 'zhifu', "wzid": wzid, "wztitle": wztitle, "gmtime": gmtime, "method": method, "money": money, "uesid": {uesid}, }, dataType: 'json', beforeSend: function () { }, complete: function () { }, success: function (d) { if(d.code==0){ layer.msg(d.msg, function () { window.location.href = d.url; }); }else{ } } }); } } </script>

业务逻辑处理

<%@ WebHandler Language="C#" Class="DTcms.Web.dev.ClickLoad" %> using System; using System.Collections.Generic; using System.Web; using System.IO; using System.Text; using System.Data; using System.Data.Sql; using System.Data.SqlClient; using DTcms.Common; using DTcms.DBUtility; using NetWing.Common.Data.SQLServer; using NetWing.Common.Request; using NetWing.Common; namespace DTcms.Web.dev { /// <summary> /// dev 的摘要说明 /// </summary> public class ClickLoad : IHttpHandler { public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; string action = context.Request["action"]; if (string.IsNullOrEmpty(action)) { context.Response.Write("{\"code\":1000, \"msg\":\"请求失败,参数有误!\"}"); return; } switch (action) { case "GetContent": //获得要购买的文章 GetContent(context); break; } } #region 购买文章 public void GetContent(HttpContext context) { string userid = context.Request["userid"]; string wzid = context.Request["wzid"]; string title = context.Request["title"]; if (string.IsNullOrEmpty(userid) || string.IsNullOrEmpty(wzid)) { context.Response.Write("{\"code\":1000, \"msg\":\"请求失败,参数有误!\"}"); return; } //根据文章id查询主表文章信息 string dtA = (string)SqlEasy.ExecuteScalar("select content from dt_article where id=" + wzid); //根据用户id和文章id查询万能表单的数据信息 DataRow drw = SqlEasy.ExecuteDataRow("select * from nw_customform_user_ffwz where userid=" + userid + " and wzid=" + wzid); string chanid = "0";//购买的频道id //根据点击的文章id查询该文章的频道id string chinid = " select * FROM dt_article where id=" + wzid + ""; DataRow chiniddr = SqlEasy.ExecuteDataRow(chinid); string chinnel_id = "0"; if (!string.IsNullOrEmpty(chiniddr.ToString())) { chinnel_id = chiniddr["channel_id"].ToString(); } if (drw==null) { int code = SqlEasy.ExecuteNonQuery("INSERT INTO nw_customform_user_ffwz (userid,wzid,channe_id,statu,add_time,number,title) VALUES (" + userid + "," + wzid + "," + chinnel_id + ",0,'" + DateTime.Now + "',1,'" + title + "')"); if (code > 0) { context.Response.Write("{\"code\":0, \"msg\":\"请求成功!\",\"content\":\"" + dtA + "\"}"); } else { context.Response.Write("{\"code\":200, \"msg\":\"网络繁忙,请重新刷新网页!\",\"content\":\"" + dtA + "\"}"); } } else { chanid = drw["channe_id"].ToString();//购买的频道id #region 支付状态等于0并且浏览次数小于0就将浏览次数加一 if (int.Parse(drw["statu"].ToString()) == 0&&int.Parse(drw["number"].ToString())<0) { int number = int.Parse(drw["number"].ToString()) + 1; int code = SqlEasy.ExecuteNonQuery("update nw_customform_user_ffwz set number=" + number + " where id=" + drw["id"].ToString()); if (code > 0) { context.Response.Write("{\"code\":0, \"msg\":\"请求成功!\",\"content\":\"" + dtA + "\"}"); } else { context.Response.Write("{\"code\":200, \"msg\":\"网络繁忙,请重新刷新网页!\",\"content\":\"" + dtA + "\"}"); } } else if (chanid == chinnel_id)//当前文章的频道id等于万能表单里的频道id { DataRow a= SqlEasy.ExecuteDataRow("select * from nw_customform_user_ffwz where channe_id=" + chinnel_id + " and statu=1 and userid=" + userid + ""); if (a == null) { context.Response.Write("{\"code\":200, \"msg\":\"购买后才能查看!\"}"); } else { DateTime dqtime = DateTime.Now; if (dqtime> DateTime.Parse(a["time"].ToString()) && dqtime<DateTime.Parse(a["qxtime"].ToString())) { context.Response.Write("{\"code\":0, \"msg\":\"请求成功!\",\"content\":\"" + dtA + "\"}"); } else { context.Response.Write("{\"code\":200, \"msg\":\"购买后才能查看!\"}"); } } } else { context.Response.Write("{\"code\":200, \"msg\":\"购买后才能查看!\"}"); } #endregion } } #endregion public bool IsReusable { get { return false; } } } }
最新回复(0)