예제 #1
0
 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);
     }
 }
예제 #2
0
        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);
        }
예제 #3
0
        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
            }
        }
예제 #4
0
 public static MemberAmount AddToMemberAmount(this DbContext context, MemberAmount model)
 {
     context.Set <MemberAmount>().Add(model);
     return(model);
 }