public string DoTKAction(decimal tkmoney, int id) { string lycResult = ""; try { using (FamilyCaiWuDBEntities db2 = new FamilyCaiWuDBEntities()) { Apply_Sub s = db2.Apply_Sub.Where(c => c.ID == id).SingleOrDefault(); if (s == null) { throw new Exception("此记账信息已不存在,无法执行退款操作!"); } if (s.InOutType != "out" || s.CashOrBank != 1) { throw new Exception("此记账信息不是【银行支出记账】,无法执行退款操作!"); } if (s.UserBankID == null || s.UserBankID.Value == 0) { throw new Exception("此记账信息不是【银行记账】,无法执行退款操作!"); } if (tkmoney == s.iMoney) { throw new Exception("退款金额与原记账金额相同,请直接执行删除操作!"); } if (tkmoney > s.iMoney) { throw new Exception("退款金额大于原记账金额,无法执行退款操作!"); } //1. 修改原记账信息的 备注、记账金额字段 decimal newMoney = s.iMoney - tkmoney; s.CAdd = s.CAdd + ";原记账金额:" + s.iMoney + " 元,现在退款:" + tkmoney + " 元,最终记账金额是:" + newMoney + " 元;"; s.iMoney = newMoney; //2. 修改对应的银行余额信息 UserBank ub = db2.UserBanks.Where(c => c.ID == s.UserBankID.Value).SingleOrDefault(); if (ub == null) { throw new Exception("此记账信息中的银行信息已不存在,无法执行退款操作!"); } ub.NowMoney = ub.NowMoney + tkmoney; //3. 修改记账主信息的支出合计 Apply_Main m = db2.Apply_Main.Where(c => c.ID == s.ApplyMain_BillCode).SingleOrDefault(); if (m != null) { m.ApplyOutMoney = m.ApplyOutMoney - tkmoney; } db2.SaveChanges(); } lycResult = WebComm.ReturnAlertMessage(ActionReturnStatus.成功, "退款成功!", "ApplyInfoListNav", "", CallBackType.none, ""); } catch (Exception ex) { lycResult = WebComm.ReturnAlertMessage(ActionReturnStatus.失败, "退款失败!" + ex.Message, "", "", CallBackType.none, ""); } return(lycResult); }
/// <summary> /// 查询记账信息 /// </summary> /// <param name="userID">用户ID</param> /// <param name="startTime">记账开始时间</param> /// <param name="endTime">记账结束时间</param> /// <param name="flowTypeID">资金类型ID</param> /// <param name="feeitemID">费用科目类型ID</param> /// <returns></returns> public JsonResult GetApplyMainList(int userID, DateTime?startTime, DateTime?endTime, int flowTypeID = 0, int feeitemID = 0) { Thread.Sleep(500); LycJsonResult lycResult = new LycJsonResult(); try { using (FDB = new FamilyCaiWuDBEntities()) { IQueryable <Apply_Main> qam = FDB.Apply_Main.Where(c => c.ApplyUserID == userID); //筛选日期 if (startTime != null && endTime == null) { qam = qam.Where(c => c.ApplyDate >= startTime.Value); } else if (startTime == null && endTime != null) { qam = qam.Where(c => c.ApplyDate <= endTime.Value); } else if (startTime != null && endTime != null) { qam = qam.Where(c => c.ApplyDate >= startTime.Value && c.ApplyDate <= endTime.Value); } var result = qam.Select(c => new { ApplyMainID = c.ID, ApplyUserID = c.ApplyUserID, ApplyDate = "", ApplyDate_date = c.ApplyDate, ApplyInMoney = c.ApplyInMoney, ApplyOutMoney = c.ApplyOutMoney, iyear = c.iyear, imonth = c.imonth, iday = c.iday, iNowCashMoney = c.iNowCashMoney.Value }).ToList(); List <QueryApplyMainModel> list = new List <QueryApplyMainModel>(); for (int i = 0; i < result.Count; i++) { QueryApplyMainModel am = new QueryApplyMainModel(); var c = result[i]; am.ApplyMainID = c.ApplyMainID; am.ApplyUserID = c.ApplyUserID; am.ApplyDate = c.ApplyDate_date.ToString("yyyy-MM-dd"); am.ApplyInMoney = c.ApplyInMoney.ToString(); am.ApplyOutMoney = c.ApplyOutMoney.ToString(); am.iyear = c.iyear; am.imonth = c.imonth; am.iday = c.iday; am.iNowCashMoney = c.iNowCashMoney.ToString(); list.Add(am); } var totalObj = new { totalIn = result.Sum(c => c.ApplyInMoney).ToString(), totalOut = result.Sum(c => c.ApplyOutMoney).ToString() }; var jsonObj = new { totalObj = totalObj, info = list }; lycResult.Data = new JsonResultModel(true, "账单查询成功", jsonObj); } } catch { lycResult.Data = new JsonResultModel(false, "账单查询失败", null); } return(lycResult); }
public JsonResult GetApplySubList(int userID, int applyMainID = 0) { Thread.Sleep(500); LycJsonResult lycResult = new LycJsonResult(); try { using (FDB = new FamilyCaiWuDBEntities()) { //查询出用户的银行信息 List <UserBank> ubList = FDB.UserBanks.Where(c => c.UserID == userID).ToList(); var result = (from s in FDB.Apply_Sub join sc in FDB.Apply_Sub_CashChange on s.ID equals sc.Apply_Sub_ID into ssc from left1 in ssc.DefaultIfEmpty() where s.ApplyMain_BillCode == applyMainID select new { ApplySubID = s.ID, ApplyMainID = s.ApplyMain_BillCode, CashOrBank = s.CashOrBank, FlowTypeID = s.FlowTypeID, FlowTypeName = s.FlowTypeName, InoutType = s.InOutType, FeeItemID = s.FeeItemID == null ? 0 : s.FeeItemID.Value, FeeItemName = s.FeeItemName, iMoney = s.iMoney, UserBankID = s.UserBankID == null ? 0 : s.UserBankID.Value, BChange = s.BChange, InUserBankID = left1.InUserBankID == null ? 0 : left1.InUserBankID.Value, OutUserBankID = left1.OutUserBankID == null ? 0 : left1.OutUserBankID.Value, CAdd = s.CAdd, CreateDate_date = s.CreateDate.Value }).ToList(); List <QueryApplySubModel> list = new List <QueryApplySubModel>(); foreach (var s in result) { QueryApplySubModel asm = new QueryApplySubModel(); asm.CreateDate = s.CreateDate_date.ToString("yyyy-MM-dd"); asm.ApplySubID = s.ApplySubID; asm.ApplyMainID = s.ApplyMainID; asm.CashOrBank = s.CashOrBank; asm.FlowTypeID = s.FlowTypeID; asm.FlowTypeName = s.FlowTypeName; asm.InoutType = s.InoutType; asm.FeeItemID = s.FeeItemID; asm.FeeItemName = s.FeeItemName; asm.iMoney = s.iMoney.ToString(); asm.UserBankID = s.UserBankID; asm.UserBankName = ""; asm.BChange = s.BChange; asm.InUserBankID = s.InUserBankID; asm.InUserBankName = ""; asm.OutUserBankID = s.OutUserBankID; asm.OutUserBankName = ""; asm.CAdd = s.CAdd; foreach (var bank in ubList) { if (asm.UserBankID == bank.ID) { asm.UserBankName = bank.BankName; } if (asm.InUserBankID == bank.ID) { asm.InUserBankName = bank.BankName; } if (asm.OutUserBankID == bank.ID) { asm.OutUserBankName = bank.BankName; } } list.Add(asm); } lycResult.Data = new JsonResultModel(true, "账单明细成功!", list); } } catch { lycResult.Data = new JsonResultModel(false, "账单查询失败!", new object { }); } return(lycResult); }