public ActionResult Cashback(int id) { string cardId = Request.Form["CardId"]; string recash = Request.Form["Recash"]; string point = Request.Form["Point"]; string gavePoint = Request.Form["GavePoint"]; try { ConsumeOrders cos = new ConsumeOrders(); MemCardsBLL mcll = new MemCardsBLL(); ConsumeOrdersBLL coll = new ConsumeOrdersBLL(); cos.CO_GavePoint = Convert.ToInt32(gavePoint); cos.CO_Recash = (float)Convert.ToDouble(recash); cos.MC_CardID = cardId; MemCards mc = mcll.SelectWhere(m => m.MC_CardID == cardId).FirstOrDefault(); using (TransactionScope ts = new TransactionScope()) { //添加消费记录 coll.Add(cos); coll.SaveChanges(); //更新用户卡信息 mc.MC_Point = Convert.ToInt32(point); mcll.SaveChanges(); ts.Complete(); } return Json(new { result = "ok", data = point }); } catch { return Json(new { result = "error", data = "系统异常,兑换失败!" }); } }
public ActionResult ExchangeInfo() { string row = Request.Form["rows"]; Users user = Session["user"] as Users; JavaScriptSerializer serializer = new JavaScriptSerializer(); List<ExchangLogs> logList = serializer.Deserialize<List<ExchangLogs>>(row); List<ExchangGifts> giftList = serializer.Deserialize<List<ExchangGifts>>(row); try { ExchangLogs el = new ExchangLogs(); MemCardsBLL mcBll = new MemCardsBLL(); ExchangLogsBLL elBll = new ExchangLogsBLL(); ExchangGiftsBLL exBll = new ExchangGiftsBLL(); //事务处理,优点:确保数据统一完整;缺点:锁表 using (TransactionScope ts = new TransactionScope()) { string idorm = Request.Form["idorm"]; MemCards mc = mcBll.SelectWhere(s => s.MC_CardID == idorm || s.MC_Mobile == idorm).FirstOrDefault(); double percent = (double)mc.CardLevels.CL_Percent; double sum = 0; int total = (int)mc.MC_Point; for (int i = 0; i < logList.Count; i++) { int point = Convert.ToInt32(giftList[i].EG_Point); int number = Convert.ToInt32(logList[i].EL_Number); //添加兑换记录表 el.S_ID = user.S_ID; el.U_ID = user.U_ID; el.MC_ID = mc.MC_ID; el.MC_CardID = idorm; el.MC_Name = mc.MC_Name; el.EG_ID = giftList[i].EG_ID; el.EG_GiftCode = logList[i].EG_GiftCode; el.EG_GiftName = logList[i].EG_GiftName; el.EL_Number = number; el.EL_Point = point * number; el.EL_CreateTime = DateTime.Now; elBll.Add(el); sum += (double)point * number * percent; //更新礼品表 int eId = Convert.ToInt32(logList[i].EG_ID); ExchangGifts eGift = exBll.SelectWhere(m => m.EG_ID == eId).FirstOrDefault(); eGift.EG_ExchangNum = number + eGift.EG_ExchangNum; } if (total >= Math.Ceiling(sum)) { //更新会员表 int subpoint = (int)(mc.MC_Point - sum); mc.MC_Point = subpoint; //保存 mcBll.SaveChanges(); elBll.SaveChanges(); exBll.SaveChanges(); ts.Complete(); return Json(new { result = "ok", data = subpoint }); } return Json(new { result = "no", data = "可兑换积分不足" + Math.Ceiling(sum) + "!" }); } } catch { return Json(new { result = "error" }); } }
/// <summary> /// 查询推荐会员姓名 /// </summary> public ActionResult GetNamebyCardID(string MC_CardID) { MemCardsBLL bll = new MemCardsBLL(); string mcList = bll.SelectWhere(m => m.MC_CardID == MC_CardID).Select(m => m.MC_Name).FirstOrDefault(); return Content(mcList); }
public ActionResult Transfer(string TL_FromMC_CardID, string TL_ToMC_CardID, int TL_TransferMoney, string TL_Remark) { MemCardsBLL mcBll = new MemCardsBLL(); TransferLogsBLL tfBll = new TransferLogsBLL(); TransferLogs tf = new TransferLogs(); MemCards mcTo = new MemCards(); MemCards mcFrom = new MemCards(); try { MemCards uTo = mcBll.GetExchange(TL_ToMC_CardID); MemCards uFrom = mcBll.GetExchange(TL_FromMC_CardID); Users user = Session["user"] as Users; using (TransactionScope ts = new TransactionScope()) { //修改转出卡号信息 mcTo.MC_ID = uFrom.MC_ID; mcTo.MC_Point = uFrom.MC_Point - TL_TransferMoney; //修改转入卡号信息 mcFrom.MC_ID = uTo.MC_ID; mcFrom.MC_Point = uTo.MC_Point + TL_TransferMoney; mcBll.Edit(mcFrom, "MC_Point"); mcBll.Edit(mcTo, "MC_Point"); mcBll.SaveChanges(); //转账信息表添加数据 tf.S_ID = user.S_ID; tf.U_ID = user.U_ID; tf.TL_FromMC_ID = mcBll.SelectWhere(m => m.MC_CardID == TL_FromMC_CardID).Select(m => m.MC_ID).FirstOrDefault(); tf.TL_FromMC_CardID = TL_FromMC_CardID; tf.TL_ToMC_ID = mcBll.SelectWhere(m => m.MC_CardID == TL_ToMC_CardID).Select(m => m.MC_ID).FirstOrDefault(); tf.TL_ToMC_CardID = TL_ToMC_CardID; tf.TL_TransferMoney = TL_TransferMoney; tf.TL_Remark = TL_Remark; tf.TL_CreateTime = DateTime.Now; tfBll.Add(tf); tfBll.SaveChanges(); ts.Complete(); } return Json(new { result = "ok" }); } catch { return Json(new { result = "error" }); } }
/// <summary> /// 获取当前输入会员信息 /// </summary> public ActionResult GetMemByCardID(string FromCardID, string ToCardID) { MemCardsBLL bll = new MemCardsBLL(); Users u = Session["user"] as Users; var mcList = bll.SelectWhere(m => (m.S_ID == u.S_ID) && (m.MC_State != 4) && (m.MC_CardID == ToCardID)); if (!mcList.Any()) return Content("NO"); if (!bll.GetState(ToCardID)) return Content("NOState"); if (!bll.GetLevels(FromCardID, ToCardID)) return Content("NOLevels"); var cards = mcList.Select(m => new { m.MC_CardID, m.MC_Name, m.MC_ID, m.MC_Point, m.MC_TotalMoney }).FirstOrDefault(); return Json(cards, JsonRequestBehavior.AllowGet); }