public int AddDeduction(Deduction deduction) { string cmdText = "INSERT INTO Deduction(uid,realname,shopid,shopname,deductionname,deductionvalue,deductioncount,deductionbalance,remarks)VALUES(@uid,@realname,@shopid,@shopname,@deductionname,@deductionvalue,@deductioncount,@deductionbalance,@remarks);SELECT @@identity"; DbParameter[] cmdParameters = { DbHelper.MakeInParam("@uid", (DbType)SqlDbType.Int, 0, deduction.Uid)/**/, DbHelper.MakeInParam("@realname", (DbType)SqlDbType.NChar, 10, deduction.Realname)/**/, DbHelper.MakeInParam("@shopid", (DbType)SqlDbType.Int, 0, deduction.Shopid)/**/, DbHelper.MakeInParam("@shopname", (DbType)SqlDbType.NChar, 20, deduction.Shopname)/**/, DbHelper.MakeInParam("@deductionname", (DbType)SqlDbType.NChar, 100, deduction.Deductionname)/**/, DbHelper.MakeInParam("@deductionvalue", (DbType)SqlDbType.Decimal, 0, deduction.Deductionvalue)/**/, DbHelper.MakeInParam("@deductioncount", (DbType)SqlDbType.Int, 0, deduction.Deductioncount)/**/, DbHelper.MakeInParam("@deductionbalance", (DbType)SqlDbType.Decimal, 0, deduction.Deductionbalance)/**/, DbHelper.MakeInParam("@remarks", (DbType)SqlDbType.NChar, 100, deduction.Remarks)/**/ }; string s = DbHelper.ExecuteScalar(CommandType.Text, cmdText, cmdParameters).ToString(); int i = (string.IsNullOrEmpty(s) ? 0 : int.Parse(s)); return i; } public int AddDeduction(Deduction deduction, DbTransaction trans) { string cmdText = "INSERT INTO Deduction(uid,realname,shopid,shopname,deductionname,deductionvalue,deductioncount,deductionbalance,remarks)VALUES(@uid,@realname,@shopid,@shopname,@deductionname,@deductionvalue,@deductioncount,@deductionbalance,@remarks);SELECT @@identity"; DbParameter[] cmdParameters = { DbHelper.MakeInParam("@uid", (DbType)SqlDbType.Int, 0, deduction.Uid)/**/, DbHelper.MakeInParam("@realname", (DbType)SqlDbType.NChar, 10, deduction.Realname)/**/, DbHelper.MakeInParam("@shopid", (DbType)SqlDbType.Int, 0, deduction.Shopid)/**/, DbHelper.MakeInParam("@shopname", (DbType)SqlDbType.NChar, 20, deduction.Shopname)/**/, DbHelper.MakeInParam("@deductionname", (DbType)SqlDbType.NChar, 100, deduction.Deductionname)/**/, DbHelper.MakeInParam("@deductionvalue", (DbType)SqlDbType.Decimal, 0, deduction.Deductionvalue)/**/, DbHelper.MakeInParam("@deductioncount", (DbType)SqlDbType.Int, 0, deduction.Deductioncount)/**/, DbHelper.MakeInParam("@deductionbalance", (DbType)SqlDbType.Decimal, 0, deduction.Deductionbalance)/**/, DbHelper.MakeInParam("@remarks", (DbType)SqlDbType.NChar, 100, deduction.Remarks)/**/ }; string s = DbHelper.ExecuteScalar(trans, CommandType.Text, cmdText, cmdParameters).ToString(); int i = (string.IsNullOrEmpty(s) ? 0 : int.Parse(s)); return i; }
public void handler(IResponder responder) { int id = SJSRequest.GetInt("Id", 0); if (id <= 0) { responder.WriteErroredMsg("请求参数错误!"); return; } Booking booking = BookingManager.GetBooking(id); if (booking == null) { responder.WriteErroredMsg("不存在此预订,无法删除!"); return; } if (booking.Issettle) { responder.WriteErroredMsg("此预订已结算,无法删除!"); return; } using (DbTransaction trans = DbHelper.BeginTransaction()) { bool writeError = false; try { int rlt = BookingManager.DelBooking(id, trans); if (rlt <= 0) { writeError = true; trans.Rollback(); responder.WriteErroredMsg("删除预订失败,数据库更新不成功!"); return; } BookingshopManager.DelBookingshop(id, true, trans); IList<Bookingtrade> list = BookingtradeManager.GetBookingtrade(id, trans, true); foreach (Bookingtrade item in list) { User user = UserManager.GetUser(item.Uid, trans); user.Balance = user.Balance + item.Tradevalue * item.Tradecount; rlt = UserManager.UpdateUserBalance(item.Uid, -item.Tradevalue * item.Tradecount, trans); if (rlt <= 0) { writeError = true; trans.Rollback(); responder.WriteErroredMsg("返还余额失败,数据库更新不成功!"); return; } Deduction deduction = new Deduction(); deduction.Deductionbalance = user.Balance; deduction.Deductioncount = -item.Tradecount; deduction.Deductionname = string.Format("退订{0}(删除预订)", item.Tradename); deduction.Deductiontime = DateTime.Now; deduction.Deductionvalue = item.Tradevalue * item.Tradecount; deduction.Uid = item.Uid; deduction.Realname = item.Realname; deduction.Shopid = item.Shopid; deduction.Shopname = item.Shopname; deduction.Remarks = item.Remarks; rlt = DeductionManager.AddDeduction(deduction, trans); if (rlt <= 0) { writeError = true; trans.Rollback(); responder.WriteErroredMsg("扣款记录失败,数据库写入不成功!"); return; } rlt = BookingtradeManager.DelBookingtrade(item.Id, trans); if (rlt <= 0) { writeError = true; trans.Rollback(); responder.WriteErroredMsg("删除已预订列表失败,数据库更新不成功!"); return; } } trans.Commit(); } catch (Exception ex) { trans.Rollback(); if(writeError == false) responder.WriteErroredMsg("删除失败,程序异常!"); return; } } responder.WriteSuccessedMsg("预订、此预订接受预订的店铺列表和此预订的预订记录删除成功!"); }
public void handler(IResponder responder) { int bookingtradeid = SJSRequest.GetInt("Id", 0); int tradecount = SJSRequest.GetInt("Tradecount", 0); if (bookingtradeid <= 0) { responder.WriteErroredMsg("请求参数错误!"); return; } if (tradecount <= 0) { responder.WriteErroredMsg("取消数量应为正数!"); return; } Bookingtrade bookingtrade = BookingtradeManager.GetBookingtrade(bookingtradeid); if (bookingtrade == null) { responder.WriteErroredMsg("不存在此预订项,无法取消!"); return; } Booking booking = BookingManager.GetBooking(bookingtrade.Bookingid); if (booking == null) { responder.WriteErroredMsg("此预订不存在或已被删除,无法取消!"); return; } if (booking.Isbooking == false && User.IsAdministrator(PageUtils.Utype) == false) { responder.WriteErroredMsg("此预订已结束,无法取消!"); return; } int rlt = 0; using (DbTransaction trans = DbHelper.BeginTransaction()) { bool writeError = false; try { int hasCount = bookingtrade.Tradecount; bookingtrade.Tradecount = Math.Max(0, bookingtrade.Tradecount - tradecount); tradecount = hasCount - bookingtrade.Tradecount; if (bookingtrade.Uid != PageUtils.AccountID) { bookingtrade.Remarks += string.Format(" 由{0}退订{1}份", PageUtils.RealName, tradecount); } User user = UserManager.GetUser(bookingtrade.Uid, trans); rlt = UserManager.UpdateUserBalance(bookingtrade.Uid, -bookingtrade.Tradevalue * tradecount, trans); if (rlt <= 0) { writeError = true; trans.Rollback(); responder.WriteErroredMsg("返还余额失败,数据库更新不成功!"); return; } Deduction deduction = new Deduction(); deduction.Deductionbalance = user.Balance + bookingtrade.Tradevalue * tradecount; deduction.Deductioncount = -tradecount; deduction.Deductionname = string.Format("取消{0}", bookingtrade.Tradename); deduction.Deductiontime = DateTime.Now; deduction.Deductionvalue = bookingtrade.Tradevalue * tradecount; deduction.Uid = bookingtrade.Uid; deduction.Realname = bookingtrade.Realname; deduction.Shopid = bookingtrade.Shopid; deduction.Shopname = bookingtrade.Shopname; deduction.Remarks = bookingtrade.Remarks; rlt = DeductionManager.AddDeduction(deduction, trans); if (rlt <= 0) { writeError = true; trans.Rollback(); responder.WriteErroredMsg("返还余额失败,数据库更新不成功!"); return; } if (bookingtrade.Tradecount > 0) { rlt = BookingtradeManager.UpdateBookingtrade(bookingtrade, trans); } else { rlt = BookingtradeManager.DelBookingtrade(bookingtrade.Id, trans); } if (rlt <= 0) { writeError = true; trans.Rollback(); responder.WriteErroredMsg("取消预订失败,数据库更新不成功!"); return; } trans.Commit(); } catch (Exception ex) { trans.Rollback(); if (writeError == false) { responder.WriteErroredMsg("取消失败,程序异常!"); } return; } } responder.WriteSuccessedMsg(string.Format("成功取消{0}个预订", tradecount)); }
public void handler(IResponder responder) { Deduction deduction = new Deduction(); deduction.Uid = SJSRequest.GetInt("Uid", 0); deduction.Deductionname = SJSRequest.GetString("Deductionname"); deduction.Deductionvalue = SJSRequest.GetInt("Deductionvalue", 0); deduction.Remarks = SJSRequest.GetString("Remarks"); deduction.Shopid = 0; deduction.Shopname = "手动扣款"; deduction.Deductiontime = DateTime.Now; deduction.Deductioncount = 1; //deduction.Realname = SJSRequest.GetString("Realname"); //deduction.Deductionbalance = if (deduction.Uid <= 0) { responder.WriteErroredMsg("请求参数错误!"); return; } if (string.IsNullOrEmpty(deduction.Deductionname)) { responder.WriteErroredMsg("扣款项目不能为空!"); return; } if (deduction.Deductionvalue <= 0) { responder.WriteErroredMsg("扣款金额必须大于0!"); return; } using (DbTransaction trans = DbHelper.BeginTransaction()) { bool writeError = false; try { User user = UserManager.GetUser(deduction.Uid, trans); if (user == null) { writeError = true; trans.Rollback(); responder.WriteErroredMsg("不存在此用户,无法扣款!"); return; } deduction.Realname = user.Realname; deduction.Deductionbalance = user.Balance - deduction.Deductionvalue; int rlt = UserManager.UpdateUserBalance(user.Uid, deduction.Deductionvalue, trans); if (rlt <= 0) { writeError = true; trans.Rollback(); responder.WriteErroredMsg("扣除余额失败,无法扣款!"); return; } rlt = DeductionManager.AddDeduction(deduction, trans); if (rlt <= 0) { writeError = true; trans.Rollback(); responder.WriteErroredMsg("扣款记录失败,无法扣款!"); return; } trans.Commit(); } catch (Exception ex) { trans.Rollback(); if (writeError == false) { responder.WriteErroredMsg("扣款失败,程序异常"); } return; } } responder.WriteSuccessedMsg(string.Format("扣款成功,扣除金额:{0}元!", deduction.Deductionvalue)); }
public void handler(IResponder responder) { int withUid = SJSRequest.GetInt("WithUid", 0); Bookingtrade bookingtrade = new Bookingtrade(); bookingtrade.Tradeid = SJSRequest.GetInt("Tradeid", 0); bookingtrade.Bookingshopid = SJSRequest.GetInt("Id", 0); bookingtrade.Tradecount = SJSRequest.GetInt("Tradecount", 0); //bookingtrade.Remarks = SJSRequest.GetString("Remarks"); if (bookingtrade.Tradecount <= 0) { responder.WriteErroredMsg("预订数量只能是正数!"); return; } if (bookingtrade.Tradeid <= 0) { responder.WriteErroredMsg("菜单项请求参数错误!"); return; } if (bookingtrade.Bookingshopid <= 0) { responder.WriteErroredMsg("预订店铺记录请求参数错误!"); return; } Bookingshop bookingshop = BookingshopManager.GetBookingshop(bookingtrade.Bookingshopid); if (bookingshop == null) { responder.WriteErroredMsg("此店铺接受预订记录不存在,无法预订!"); return; } Booking booking = BookingManager.GetBooking(bookingshop.Bookingid); if (booking == null) { responder.WriteErroredMsg("此预订不存在,无法预订!"); return; } if (booking.Isbooking == false && User.IsAdministrator(PageUtils.Utype) == false) { responder.WriteErroredMsg("此预订已结束,无法预订!"); return; } Trade trade = TradeManager.GetTrade(bookingtrade.Tradeid); if (trade == null) { responder.WriteErroredMsg("不存在此菜单项,无法预订!"); return; } IList<Bookingtrade> confirmList = BookingtradeManager.GetBookingtrade(bookingshop.Id, trade.Id, true); Bookingtrade confirm = null; int uid = PageUtils.AccountID; string rname = PageUtils.RealName; for (int i = 0; i < confirmList.Count; i++) { if (withUid > 0 && withUid == confirmList[i].Uid) { confirm = confirmList[i]; break; } if (withUid <= 0 && uid == confirmList[i].Uid) { confirm = confirmList[i]; break; } } int rlt = 0; bool isAdd = false; using (DbTransaction trans = DbHelper.BeginTransaction()) { bool writeError = false; try { User user = null; Deduction deduction = new Deduction(); int addedCount = 0; if (confirm != null && (withUid <= 0 || withUid == confirm.Uid)) { addedCount = bookingtrade.Tradecount; user = UserManager.GetUser(confirm.Uid, trans); if (user == null) { writeError = true; trans.Rollback(); responder.WriteErroredMsg("不存在此用户,无法预订!"); return; } if (user.Enabled == false) { writeError = true; trans.Rollback(); responder.WriteErroredMsg(user.Realname + " 处于禁用状态,无法预订!"); return; } uid = user.Uid; rname = user.Realname; deduction.Deductionbalance = user.Balance - confirm.Tradevalue * addedCount; deduction.Deductioncount = addedCount; deduction.Deductionname = string.Format("预订{0}", confirm.Tradename); deduction.Deductiontime = DateTime.Now; deduction.Deductionvalue = -confirm.Tradevalue * addedCount; deduction.Uid = confirm.Uid; deduction.Realname = confirm.Realname; deduction.Shopid = confirm.Shopid; deduction.Shopname = confirm.Shopname; deduction.Remarks = confirm.Remarks; confirm.Tradecount += addedCount; bookingtrade = confirm; isAdd = false; } else { if (withUid > 0 && uid != withUid) user = UserManager.GetUser(withUid, trans); else user = UserManager.GetUser(uid, trans); if (user == null) { writeError = true; trans.Rollback(); responder.WriteErroredMsg("不存在此用户,无法预订!"); return; } if (user.Enabled == false) { writeError = true; trans.Rollback(); responder.WriteErroredMsg(user.Realname + " 处于禁用状态,无法预订!"); return; } if (withUid > 0) { bookingtrade.Proxyid = uid; bookingtrade.Proxyname = rname; bookingtrade.Remarks += string.Format("由 {0} 代订", rname.Trim()); } uid = user.Uid; rname = user.Realname; bookingtrade.Bookingid = booking.Id; bookingtrade.Bookingname = booking.Bookingname; bookingtrade.Handlerid = bookingshop.Uid; bookingtrade.Handlername = bookingshop.Realname; bookingtrade.Uid = uid; bookingtrade.Realname = rname; bookingtrade.Shopid = bookingshop.Shopid; bookingtrade.Shopname = bookingshop.Shopname; bookingtrade.Tradename = trade.Tradename; bookingtrade.Tradevalue = trade.Tradevalue; bookingtrade.Issettle = booking.Isbooking == false; bookingtrade.Bookinttime = DateTime.Now; if (booking.Bookingtime.Date.Equals(DateTime.Now.Date) == false) { bookingtrade.Bookinttime = new DateTime(booking.Bookingtime.Date.Ticks); bookingtrade.Bookinttime = bookingtrade.Bookinttime.AddHours(DateTime.Now.Hour).AddMinutes(DateTime.Now.Minute).AddSeconds(DateTime.Now.Second); } addedCount = bookingtrade.Tradecount; deduction.Deductionbalance = user.Balance - trade.Tradevalue * addedCount; deduction.Deductioncount = addedCount; deduction.Deductionname = string.Format("预订{0}", bookingtrade.Tradename); deduction.Deductiontime = DateTime.Now; deduction.Deductionvalue = -bookingtrade.Tradevalue * addedCount; deduction.Uid = bookingtrade.Uid; deduction.Realname = bookingtrade.Realname; deduction.Shopid = bookingtrade.Shopid; deduction.Shopname = bookingtrade.Shopname; deduction.Remarks = bookingtrade.Remarks; isAdd = true; } rlt = UserManager.UpdateUserBalance(uid, trade.Tradevalue * addedCount, trans); if (rlt <= 0) { writeError = true; trans.Rollback(); responder.WriteErroredMsg("扣除余额失败,数据库更新不成功!"); return; } rlt = DeductionManager.AddDeduction(deduction, trans); if (rlt <= 0) { writeError = true; trans.Rollback(); responder.WriteErroredMsg("扣款记录失败,数据库写入不成功!"); return; } if (isAdd) { rlt = BookingtradeManager.AddBookingtrade(bookingtrade, trans); } else { rlt = BookingtradeManager.UpdateBookingtrade(bookingtrade, trans); } trans.Commit(); } catch (Exception ex) { trans.Rollback(); if (writeError == false) { responder.WriteErroredMsg("预订失败,程序异常!"); } return; } } if (rlt <= 0) { if(isAdd) responder.WriteErroredMsg("预订失败,数据库写入不成功!"); else responder.WriteErroredMsg("预订失败,数据库更新不成功!"); return; } if (isAdd) responder.WriteSuccessedMsg("提交成功,预订项已添加!"); else responder.WriteSuccessedMsg("提交成功,预订项已更新!"); }
public void handler(IResponder responder) { int uid = SJSRequest.GetInt("Uid", 0); if (uid <= 0) { responder.WriteErroredMsg("请求参数错误!"); return; } User user; using (DbTransaction trans = DbHelper.BeginTransaction()) { bool writeError = false; try { user = UserManager.GetUser(uid, trans); if (user == null) { writeError = true; trans.Rollback(); responder.WriteErroredMsg("不存在此用户,无法返还现金!"); return; } if (user.Balance == 0) { writeError = true; trans.Rollback(); responder.WriteErroredMsg("返还失败,当前用户余额已为零!"); return; } if (user.Balance < 0) { writeError = true; trans.Rollback(); responder.WriteErroredMsg("返还失败,欠费用户无法返还现金!"); return; } int rlt = UserManager.UpdateUserBalance(user.Uid, user.Balance, trans); if (rlt <= 0) { writeError = true; trans.Rollback(); responder.WriteErroredMsg("返还失败,余额清零不成功!"); return; } Deduction deduction = new Deduction(); deduction.Deductionbalance = 0; deduction.Deductioncount = 1; deduction.Deductionname = "返还现金"; deduction.Deductiontime = DateTime.Now; deduction.Deductionvalue = user.Balance; deduction.Uid = user.Uid; deduction.Realname = user.Realname; deduction.Shopid = 0; deduction.Shopname = "余额清零"; deduction.Remarks = "余额清零"; rlt = DeductionManager.AddDeduction(deduction, trans); if (rlt <= 0) { writeError = true; trans.Rollback(); responder.WriteErroredMsg("返还失败,扣款记录不成功!"); return; } trans.Commit(); } catch (Exception ex) { trans.Rollback(); if (writeError == false) { responder.WriteErroredMsg("返还失败,程序异常"); } return; } } responder.WriteSuccessedMsg(string.Format("返还现金成功,应返还金额:{0}元!", user.Balance)); }
public static Deduction GetDeduction(IDataReader reader) { Deduction model = new Deduction(); model.Id = (reader["Id"] is DBNull ? Convert.ToInt32("0") : Convert.ToInt32(reader["Id"])); model.Uid = (reader["Uid"] is DBNull ? Convert.ToInt32("0") : Convert.ToInt32(reader["Uid"])); model.Realname = reader["Realname"].ToString(); model.Shopid = (reader["Shopid"] is DBNull ? Convert.ToInt32("0") : Convert.ToInt32(reader["Shopid"])); model.Shopname = reader["Shopname"].ToString(); model.Deductionname = reader["Deductionname"].ToString(); model.Deductionvalue = (reader["Deductionvalue"] is DBNull ? Convert.ToDouble("0") : Convert.ToDouble(reader["Deductionvalue"])); model.Deductioncount = (reader["Deductioncount"] is DBNull ? Convert.ToInt32("0") : Convert.ToInt32(reader["Deductioncount"])); model.Deductionbalance = (reader["Deductionbalance"] is DBNull ? Convert.ToDouble("0") : Convert.ToDouble(reader["Deductionbalance"])); model.Deductiontime = (reader["Deductiontime"] is DBNull ? Convert.ToDateTime("1900-01-01") : Convert.ToDateTime(reader["Deductiontime"])); model.Remarks = reader["Remarks"].ToString(); return model; }
public static int AddDeduction(Deduction deduction, DbTransaction trans) { return DatabaseProvider.GetInstance().AddDeduction(deduction, trans); }
/// <summary> /// 添加方法 /// </summary> public static int AddDeduction(Deduction deduction) { return DatabaseProvider.GetInstance().AddDeduction(deduction); }