public static string Empowers(string userlist, string relist) { try { BLL_UserBuyResources bll = new BLL_UserBuyResources(); List <Model_UserBuyResources> listModel = new List <Model_UserBuyResources>(); userlist = userlist.TrimEnd(','); relist = relist.TrimEnd(','); string _dSql = "delete UserBuyResources where BuyType = 'NBSQ' and UserId in ('" + userlist.Replace(",", "','") + "') and book_id in ('" + relist.Replace(",", "','") + "');"; foreach (string item in userlist.Split(',')) { if (!string.IsNullOrEmpty(item)) { foreach (string itemR in relist.Split(',')) { if (!string.IsNullOrEmpty(itemR)) { if (new BLL_UserBuyResources().GetRecordCount("UserId='" + item + "' and Book_id='" + itemR + "'") > 0) { } else { Model_UserBuyResources model = new Model_UserBuyResources(); model.UserBuyResources_ID = Guid.NewGuid().ToString(); model.UserId = item; model.Book_id = itemR; model.BuyType = "NBSQ";//内部授权 model.CreateTime = DateTime.Now; listModel.Add(model); } } } } } if (listModel.Count > 0) { //Rc.Common.DBUtility.DbHelperSQL.Query(_dSql); if (bll.AddUserBuyResources(listModel)) { return("1"); } else { return(""); } } else { return("1"); } } catch (Exception ex) { return("2"); } }
protected void btnBuy_Click(object sender, EventArgs e) { try { BLL_Bookshelves bll = new BLL_Bookshelves(); DataTable dt = bll.GetList("ResourceFolder_Id='" + ResourceFolder_ID + "'").Tables[0]; if (dt.Rows.Count > 0) { BookPrice = dt.Rows[0]["BookPrice"].ToString(); } if (BookPrice == "0.00") { #region 用户购买资源表 Model_UserBuyResources buyModel = new Model_UserBuyResources(); buyModel.UserBuyResources_ID = Guid.NewGuid().ToString(); buyModel.UserId = FloginUser.UserId; buyModel.Book_id = ResourceFolder_ID; buyModel.BookPrice = 0; buyModel.BuyType = UserOrder_PaytoolEnum.FREE.ToString(); buyModel.CreateTime = DateTime.Now; buyModel.CreateUser = FloginUser.UserId; if (new BLL_UserBuyResources().Add(buyModel)) { new Rc.Cloud.BLL.BLL_clsAuth().AddLogFromBS(Request.Url.ToString(), string.Format("免费资源。购买资源成功,购买人:{0},资源标识:{1}" , FloginUser.UserId, ResourceFolder_ID)); ClientScript.RegisterStartupScript(this.GetType(), "save", "<script type='text/javascript'>layer.msg('购买成功',{icon:1,time:1000},function(){window.location.href=window.location;});</script>"); } else { ClientScript.RegisterStartupScript(this.GetType(), "save", "<script type='text/javascript'>layer.msg('购买失败',{icon:2,time:2000});</script>"); return; } #endregion } else { if (Type == "1") { Response.Redirect("/student/Payment.aspx?orderType=2&rid=" + ResourceFolder_ID); } else { Response.Redirect("/teacher/Payment.aspx?orderType=1&rid=" + ResourceFolder_ID); } } } catch (Exception) { } }
public bool Add(Model_UserBuyResources model) { StringBuilder builder = new StringBuilder(); builder.Append("insert into UserBuyResources("); builder.Append("UserBuyResources_ID,UserId,Book_id,BookPrice,BuyType,CreateTime,CreateUser)"); builder.Append(" values ("); builder.Append("@UserBuyResources_ID,@UserId,@Book_id,@BookPrice,@BuyType,@CreateTime,@CreateUser)"); SqlParameter[] cmdParms = new SqlParameter[] { new SqlParameter("@UserBuyResources_ID", SqlDbType.Char, 0x24), new SqlParameter("@UserId", SqlDbType.Char, 0x24), new SqlParameter("@Book_id", SqlDbType.Char, 0x24), new SqlParameter("@BookPrice", SqlDbType.Decimal, 5), new SqlParameter("@BuyType", SqlDbType.VarChar, 20), new SqlParameter("@CreateTime", SqlDbType.DateTime), new SqlParameter("@CreateUser", SqlDbType.Char, 0x24) }; cmdParms[0].Value = model.UserBuyResources_ID; cmdParms[1].Value = model.UserId; cmdParms[2].Value = model.Book_id; cmdParms[3].Value = model.BookPrice; cmdParms[4].Value = model.BuyType; cmdParms[5].Value = model.CreateTime; cmdParms[6].Value = model.CreateUser; return(DbHelperSQL.ExecuteSql(builder.ToString(), cmdParms) > 0); }
public List <Model_UserBuyResources> DataTableToList(DataTable dt) { List <Model_UserBuyResources> list = new List <Model_UserBuyResources>(); int count = dt.Rows.Count; if (count > 0) { for (int i = 0; i < count; i++) { Model_UserBuyResources item = this.dal.DataRowToModel(dt.Rows[i]); if (item != null) { list.Add(item); } } } return(list); }
public bool Update(Model_UserBuyResources model) { StringBuilder builder = new StringBuilder(); builder.Append("update UserBuyResources set "); builder.Append("UserId=@UserId,"); builder.Append("Book_id=@Book_id,"); builder.Append("BookPrice=@BookPrice,"); builder.Append("BuyType=@BuyType,"); builder.Append("CreateTime=@CreateTime,"); builder.Append("CreateUser=@CreateUser"); builder.Append(" where UserBuyResources_ID=@UserBuyResources_ID "); SqlParameter[] cmdParms = new SqlParameter[] { new SqlParameter("@UserId", SqlDbType.Char, 0x24), new SqlParameter("@Book_id", SqlDbType.Char, 0x24), new SqlParameter("@BookPrice", SqlDbType.Decimal, 5), new SqlParameter("@BuyType", SqlDbType.VarChar, 20), new SqlParameter("@CreateTime", SqlDbType.DateTime), new SqlParameter("@CreateUser", SqlDbType.Char, 0x24), new SqlParameter("@UserBuyResources_ID", SqlDbType.Char, 0x24) }; cmdParms[0].Value = model.UserId; cmdParms[1].Value = model.Book_id; cmdParms[2].Value = model.BookPrice; cmdParms[3].Value = model.BuyType; cmdParms[4].Value = model.CreateTime; cmdParms[5].Value = model.CreateUser; cmdParms[6].Value = model.UserBuyResources_ID; return(DbHelperSQL.ExecuteSql(builder.ToString(), cmdParms) > 0); }
public bool UpdateAndAddUserBuyResources(Model_UserOrder modelUO, Model_UserBuyResources buyModel) { Dictionary <string, SqlParameter[]> dictionary = new Dictionary <string, SqlParameter[]>(); StringBuilder builder = new StringBuilder(); builder = new StringBuilder(); builder.Append("update UserOrder set "); builder.Append("UserOrder_Paytool=@UserOrder_Paytool,"); builder.Append("UsreOrder_Buyeremail=@UsreOrder_Buyeremail,"); builder.Append("UserOrder_Status=@UserOrder_Status,"); builder.Append("UserOrder_FinishTime=@UserOrder_FinishTime,"); builder.Append("trade_no=@trade_no,"); builder.Append("trade_status=@trade_status"); builder.Append(" where UserOrder_Id=@UserOrder_Id "); SqlParameter[] parameterArray = new SqlParameter[] { new SqlParameter("@UserOrder_Paytool", SqlDbType.VarChar, 50), new SqlParameter("@UsreOrder_Buyeremail", SqlDbType.VarChar, 100), new SqlParameter("@UserOrder_Status", SqlDbType.Int, 4), new SqlParameter("@UserOrder_FinishTime", SqlDbType.DateTime), new SqlParameter("@trade_no", SqlDbType.NVarChar, 100), new SqlParameter("@trade_status", SqlDbType.NVarChar, 50), new SqlParameter("@UserOrder_Id", SqlDbType.Char, 0x24) }; parameterArray[0].Value = modelUO.UserOrder_Paytool; parameterArray[1].Value = modelUO.UsreOrder_Buyeremail; parameterArray[2].Value = modelUO.UserOrder_Status; parameterArray[3].Value = modelUO.UserOrder_FinishTime; parameterArray[4].Value = modelUO.trade_no; parameterArray[5].Value = modelUO.trade_status; parameterArray[6].Value = modelUO.UserOrder_Id; dictionary.Add(builder.ToString(), parameterArray); builder = new StringBuilder(); builder.Append("insert into UserBuyResources("); builder.Append("UserBuyResources_ID,UserId,Book_id,BookPrice,BuyType,CreateTime,CreateUser)"); builder.Append(" values ("); builder.Append("@UserBuyResources_ID,@UserId,@Book_id,@BookPrice,@BuyType,@CreateTime,@CreateUser)"); SqlParameter[] parameterArray2 = new SqlParameter[] { new SqlParameter("@UserBuyResources_ID", SqlDbType.Char, 0x24), new SqlParameter("@UserId", SqlDbType.Char, 0x24), new SqlParameter("@Book_id", SqlDbType.Char, 0x24), new SqlParameter("@BookPrice", SqlDbType.Decimal, 5), new SqlParameter("@BuyType", SqlDbType.VarChar, 20), new SqlParameter("@CreateTime", SqlDbType.DateTime), new SqlParameter("@CreateUser", SqlDbType.Char, 0x24) }; parameterArray2[0].Value = buyModel.UserBuyResources_ID; parameterArray2[1].Value = buyModel.UserId; parameterArray2[2].Value = buyModel.Book_id; parameterArray2[3].Value = buyModel.BookPrice; parameterArray2[4].Value = buyModel.BuyType; parameterArray2[5].Value = buyModel.CreateTime; parameterArray2[6].Value = buyModel.CreateUser; dictionary.Add(builder.ToString(), parameterArray2); return(DbHelperSQL.ExecuteSqlTran(dictionary) > 0); }
public Model_UserBuyResources DataRowToModel(DataRow row) { Model_UserBuyResources resources = new Model_UserBuyResources(); if (row != null) { if (row["UserBuyResources_ID"] != null) { resources.UserBuyResources_ID = row["UserBuyResources_ID"].ToString(); } if (row["UserId"] != null) { resources.UserId = row["UserId"].ToString(); } if (row["Book_id"] != null) { resources.Book_id = row["Book_id"].ToString(); } if ((row["BookPrice"] != null) && (row["BookPrice"].ToString() != "")) { resources.BookPrice = new decimal?(decimal.Parse(row["BookPrice"].ToString())); } if (row["BuyType"] != null) { resources.BuyType = row["BuyType"].ToString(); } if ((row["CreateTime"] != null) && (row["CreateTime"].ToString() != "")) { resources.CreateTime = new DateTime?(DateTime.Parse(row["CreateTime"].ToString())); } if (row["CreateUser"] != null) { resources.CreateUser = row["CreateUser"].ToString(); } } return(resources); }
public bool UpdateAndAddUserBuyResources(Model_UserOrder model, Model_UserBuyResources buyModel) { return(this.dal.UpdateAndAddUserBuyResources(model, buyModel)); }
protected void Page_Load(object sender, EventArgs e) { SortedDictionary <string, string> sPara = GetRequestPost(); if (sPara.Count > 0)//判断是否有带返回参数 { Notify aliNotify = new Notify(); bool verifyResult = aliNotify.Verify(sPara, Request.Form["notify_id"], Request.Form["sign"]); if (verifyResult)//验证成功 { ///////////////////////////////////////////////////////////////////////////////////////////////////////////// //请在这里加上商户的业务逻辑程序代码 //——请根据您的业务逻辑来编写程序(以下代码仅作参考)—— //获取支付宝的通知返回参数,可参考技术文档中服务器异步通知参数列表 //商户订单号 string out_trade_no = Request.Form["out_trade_no"].Filter(); //支付宝交易号 string trade_no = Request.Form["trade_no"].Filter(); //交易状态 string trade_status = Request.Form["trade_status"].Filter(); //买家支付宝账号 string buyer_email = Request.Form["buyer_email"]; int orderStatus = 1;// (int)XHZ.Model.UOrderStatus.等待付款; if (trade_status.ToUpper() == "TRADE_FINISHED") { //判断该笔订单是否在商户网站中已经做过处理 //如果没有做过处理,根据订单号(out_trade_no)在商户网站的订单系统中查到该笔订单的详细,并执行商户的业务程序 //如果有做过处理,不执行商户的业务程序 //注意: //退款日期超过可退款期限后(如三个月可退款),支付宝系统发送该交易状态通知 orderStatus = (int)UOrderStatus.付款成功; } else if (trade_status.ToUpper() == "TRADE_SUCCESS") { //判断该笔订单是否在商户网站中已经做过处理 //如果没有做过处理,根据订单号(out_trade_no)在商户网站的订单系统中查到该笔订单的详细,并执行商户的业务程序 //如果有做过处理,不执行商户的业务程序 //注意: //付款完成后,支付宝系统发送该交易状态通知 orderStatus = (int)UOrderStatus.付款成功; } else { } //——请根据您的业务逻辑来编写程序(以上代码仅作参考)—— Rc.Web.Payment.Core.LogHandler.WriteLogForPay(out_trade_no, "付款成功", trade_no); #region 付款成功 异步更新订单表 author:Ethan Model_UserOrder model = new Model_UserOrder(); BLL_UserOrder bll = new BLL_UserOrder(); model = bll.GetModelByOrderNo(out_trade_no); if (orderStatus == (int)UOrderStatus.付款成功 && model.UserOrder_Status == (int)UOrderStatus.待付款) { model.UserOrder_Paytool = UserOrder_PaytoolEnum.ALIPAY.ToString(); model.UsreOrder_Buyeremail = buyer_email; model.trade_no = trade_no; model.trade_status = trade_status; model.UserOrder_Status = (int)UOrderStatus.完成; model.UserOrder_FinishTime = DateTime.Now; bool executeFlag = false; if (new BLL_UserBuyResources().GetRecordCount(string.Format("UserId='{0}' and Book_id='{1}' ", model.UserId, model.Book_Id)) == 0) { #region 用户购买资源表 Model_UserBuyResources buyModel = new Model_UserBuyResources(); buyModel.UserBuyResources_ID = Guid.NewGuid().ToString(); buyModel.UserId = model.UserId; buyModel.Book_id = model.Book_Id; buyModel.BookPrice = model.Book_Price; buyModel.BuyType = UserOrder_PaytoolEnum.ALIPAY.ToString(); buyModel.CreateTime = DateTime.Now; buyModel.CreateUser = "******"; #endregion executeFlag = bll.UpdateAndAddUserBuyResources(model, buyModel); } else { executeFlag = bll.Update(model); } if (executeFlag) { //try //{ // P_User userModel = new P_UserBLL().GetModel(model.user_id); // pfunction.SendSMS(userModel.moblie, "您的订单" + model.OrderNo + "已支付成功"); //} //catch //{ //} //if (new U_OrdersHandleBLL().GetRecordCount("OrderId='" + model.OrderId + "' and OperateUser='******'") == 0) //{ // pfunction.InsertOrderHandle(model.OrderId, "您已" + XHZ.Common.EnumService.GetDescription<UOrderStatus>(orderStatus), "支付接口异步回调"); //} new Rc.Cloud.BLL.BLL_clsAuth().AddLogFromBS(Request.Url.ToString(), string.Format("支付宝回调。购买资源成功,购买人:{0},资源标识:{1}" , model.UserId, model.Book_Id)); Response.Write("success"); //请不要修改或删除 } } #endregion ///////////////////////////////////////////////////////////////////////////////////////////////////////////// } else//验证失败 { Response.Write("fail"); } } else { Response.Write("无通知参数"); } }
protected void btnBePower_Click(object sender, EventArgs e) { BLL_UserBuyResources bll = new BLL_UserBuyResources(); List <Model_UserBuyResources> listModel = new List <Model_UserBuyResources>(); string _bid = Request["bid"]; string _IDs = hidUserIDs.Value.TrimEnd(','); string _dSql = "delete UserBuyResources where UserId in ('" + _IDs.Replace(",", "','") + "') and book_id ='" + _bid + "';"; int result = 0; foreach (string item in _IDs.Split(',')) { if (!string.IsNullOrEmpty(item)) { Model_UserBuyResources model = new Model_UserBuyResources(); model.UserBuyResources_ID = Guid.NewGuid().ToString(); model.UserId = item; model.Book_id = _bid; model.BuyType = UserOrder_PaytoolEnum.NBSQ.ToString();//内部授权 model.CreateTime = DateTime.Now; model.CreateUser = loginUser.SysUser_ID; listModel.Add(model); } } try { Rc.Common.DBUtility.DbHelperSQL.ExecuteSql(_dSql); foreach (var item in listModel) { bool flag = bll.Add(item); if (flag) { new Rc.Cloud.BLL.BLL_clsAuth().AddLogFromBS(Module_Id, string.Format("给老师授权成功,操作人:{0},资源标识:{1},老师标识:{2}" , loginUser.SysUser_ID, item.Book_id, item.UserId)); } else { new Rc.Cloud.BLL.BLL_clsAuth().AddLogErrorFromBS(Module_Id, string.Format("给老师授权失败,操作人:{0},资源标识:{1},老师标识:{2}" , loginUser.SysUser_ID, item.Book_id, item.UserId)); } result += flag == true ? 1 : 0; } if (result > 0) { ShowMsg(true, "操作成功!"); } else { ShowMsg(false, "操作失败!"); } } catch (Exception ex) { //记录错误日志 new Rc.Cloud.BLL.BLL_clsAuth().AddLogErrorFromBS(Module_Id, string.Format("给老师授权失败,操作人:{0},类:{1},方法{2},错误信息:{3}" , loginUser.SysUser_ID , ex.TargetSite.DeclaringType.ToString() , ex.TargetSite.Name.ToString() , ex.Message)); ShowMsg(false, "操作失败!"); return; } }
public override void ProcessNotify() { WxPayData notifyData = GetNotifyData(); //检查支付结果中transaction_id是否存在 if (!notifyData.IsSet("transaction_id")) { //若transaction_id不存在,则立即返回结果给微信支付后台 WxPayData res = new WxPayData(); res.SetValue("return_code", "FAIL"); res.SetValue("return_msg", "支付结果中微信订单号不存在"); Log.Error(this.GetType().ToString(), "The Pay result is error : " + res.ToXml()); page.Response.Write(res.ToXml()); page.Response.End(); } string transaction_id = notifyData.GetValue("transaction_id").ToString(); //查询订单,判断订单真实性 if (!QueryOrder(transaction_id)) { //若订单查询失败,则立即返回结果给微信支付后台 WxPayData res = new WxPayData(); res.SetValue("return_code", "FAIL"); res.SetValue("return_msg", "订单查询失败"); Log.Error(this.GetType().ToString(), "Order query failure : " + res.ToXml()); page.Response.Write(res.ToXml()); page.Response.End(); } //查询订单成功 else { Log.Info(this.GetType().ToString(), "订单支付成功,异步回调"); #region 支付成功,异步更新订单表2016-06-30TS Model_UserOrder model = new Model_UserOrder(); BLL_UserOrder bll = new BLL_UserOrder(); model = bll.GetModelByOrderNo(notifyData.GetValue("out_trade_no").ToString()); if (model.UserOrder_Status == (int)UOrderStatus.待付款 || string.IsNullOrEmpty(model.trade_no) || string.IsNullOrEmpty(model.trade_status)) { model.UserOrder_Paytool = UserOrder_PaytoolEnum.WXPAY.ToString(); model.UsreOrder_Buyeremail = notifyData.GetValue("openid").ToString(); model.trade_no = notifyData.GetValue("transaction_id").ToString(); model.trade_status = notifyData.GetValue("return_code").ToString(); model.UserOrder_Status = (int)UOrderStatus.完成; model.UserOrder_FinishTime = DateTime.Now; bool executeFlag = false; if (new BLL_UserBuyResources().GetRecordCount(string.Format("UserId='{0}' and Book_id='{1}' ", model.UserId, model.Book_Id)) == 0) { #region 用户购买资源表 Model_UserBuyResources buyModel = new Model_UserBuyResources(); buyModel.UserBuyResources_ID = Guid.NewGuid().ToString(); buyModel.UserId = model.UserId; buyModel.Book_id = model.Book_Id; buyModel.BookPrice = model.Book_Price; buyModel.BuyType = UserOrder_PaytoolEnum.WXPAY.ToString(); buyModel.CreateTime = DateTime.Now; buyModel.CreateUser = "******"; #endregion executeFlag = bll.UpdateAndAddUserBuyResources(model, buyModel); } else { executeFlag = bll.Update(model); } if (executeFlag) { new Rc.Cloud.BLL.BLL_clsAuth().AddLogFromBS(page.Request.Url.ToString(), string.Format("微信回调。购买资源成功,购买人:{0},资源标识:{1}" , model.UserId, model.Book_Id)); } } #endregion WxPayData res = new WxPayData(); res.SetValue("return_code", "SUCCESS"); res.SetValue("return_msg", "OK"); page.Response.Write(res.ToXml()); page.Response.End(); } }
public bool Add(Model_UserBuyResources model) { return(this.dal.Add(model)); }
public bool Update(Model_UserBuyResources model) { return(this.dal.Update(model)); }