public static void InitMemberAmount(this DbContext context, int memberId) { foreach (MemberAmountType item in Enum.GetValues(typeof(MemberAmountType))) { var model = new MemberAmount() { Amount = 0, AmountType = item, MemberId = memberId }; context.Set <MemberAmount>().Add(model); } }
public static MemberAmount GetSingleOrNewMemberAmount(this DbContext context, MemberAmountType amountType, int memberId) { var model = context.Set <MemberAmount>().Where(m => m.AmountType == amountType && m.MemberId == memberId).FirstOrDefault(); if (model == null) { model = new MemberAmount { Amount = 0, AmountType = amountType, MemberId = memberId }; context.AddToMemberAmount(model); } return(model); }
public static void SetMemberTradeForRefundSuccess(this DbContext db, MemberTradeForRefund model) { if (model.Status == MemberTradeForRefundStatus.退款中) { var amounts = db.GetMemberAmountList(model.MemberId); model.Status = MemberTradeForRefundStatus.成功; var totalFee = model.TotalFee; var amount = amounts.GetSingle(MemberAmountType.可用现金金额); long OriginalAmount = 0; if (amount != null) { OriginalAmount = amount.Amount; amount.Amount += totalFee; } else { amount = new MemberAmount(); amount.Amount = totalFee; amount.AmountType = MemberAmountType.可用现金金额; amount.MemberId = model.MemberId; db.AddToMemberAmount(amount); } amounts.Increase(MemberAmountType.累计充值金额, totalFee); var amountlog = new MemberAmountChangeLog(); amountlog.AddTime = DateTime.Now; amountlog.Amount = totalFee; amountlog.MemberId = model.MemberId; amountlog.Detail = "在线充值-可用现余额充值"; amountlog.NowAmount = OriginalAmount + totalFee; amountlog.OriginalAmount = OriginalAmount; amountlog.Title = "充值"; amountlog.Type = FinaceType.充值入账; db.AddToMemberAmountChangeLog(amountlog); #region 修改金额缓存 amounts.UpdateMemberAmountCache(); #endregion } }
public static MemberAmount AddToMemberAmount(this DbContext context, MemberAmount model) { context.Set <MemberAmount>().Add(model); return(model); }