コード例 #1
0
        /// <summary>
        /// 处理余额私有方法
        /// </summary>
        /// <param name="shopId">店铺ID</param>
        /// <param name="money">金额</param>
        /// <param name="TradeType">类别</param>
        /// <param name="AccountNo">交易流水号</param>
        /// <param name="ChargeWay">备注</param>
        /// <param name="AccoutID">关联资金编号</param>
        public void UpdateAccount(long shopId, decimal money, ShopAccountType TradeType, string AccountNo, string ChargeWay, long detailID = 0)
        {
            lock (obj)
            {
                //处理余额
                var mShopAccountInfo = GetShopAccount(shopId);
                mShopAccountInfo.Balance += money;
                UpdateShopAccount(mShopAccountInfo);
                var isincome = true;
                if (TradeType == ShopAccountType.Refund || TradeType == ShopAccountType.MarketingServices || TradeType == ShopAccountType.WithDraw)
                {
                    isincome = false;
                }
                //处理充值记录
                ShopAccountItemInfo mShopAccountItemInfo = new ShopAccountItemInfo()
                {
                    AccountNo  = AccountNo,
                    AccoutID   = mShopAccountInfo.Id,
                    Amount     = Math.Abs(money),
                    Balance    = mShopAccountInfo.Balance,
                    CreateTime = DateTime.Now,
                    DetailId   = detailID.ToString(),
                    IsIncome   = isincome,
                    ReMark     = ChargeWay,
                    ShopId     = shopId,
                    ShopName   = mShopAccountInfo.ShopName,
                    TradeType  = TradeType
                };

                ///平台佣金退还
                if (TradeType == ShopAccountType.PlatCommissionRefund)
                {
                    var platAccount = GetPlatAccount();
                    platAccount.Balance -= money;
                    UpdatePlatAccount(platAccount);
                    var info = new PlatAccountItemInfo()
                    {
                        AccountNo  = AccountNo,
                        AccoutID   = platAccount.Id,
                        Amount     = Math.Abs(money),
                        Balance    = platAccount.Balance,
                        CreateTime = DateTime.Now,
                        DetailId   = detailID.ToString(),
                        IsIncome   = false,
                        ReMark     = ChargeWay,
                        TradeType  = PlatAccountType.PlatCommissionRefund
                    };
                    DbFactory.Default.Add(info);
                }
                AddShopAccountItem(mShopAccountItemInfo);
            }
        }
コード例 #2
0
        public bool ShopAccountRecord(long shopId, decimal amount, string remark, string detailId)
        {
            return(DbFactory.Default.InTransaction(() =>
            {
                var ShopAccount = DbFactory.Default.Get <ShopAccountInfo>().Where(a => a.ShopId == shopId).FirstOrDefault();
                ShopAccountItemInfo info = new ShopAccountItemInfo();
                info.IsIncome = false;
                info.ShopId = ShopAccount.ShopId;
                info.DetailId = detailId;
                info.ShopName = ShopAccount.ShopName;
                info.AccountNo = shopId + info.DetailId + new Random().Next(10000);
                info.ReMark = remark;
                info.TradeType = ShopAccountType.CashDeposit;
                info.CreateTime = DateTime.Now;
                info.Amount = amount;
                info.AccoutID = ShopAccount.Id;
                ShopAccount.Balance -= info.Amount; //总余额减钱
                info.Balance = ShopAccount.Balance; //变动后当前剩余金额

                DbFactory.Default.Add(info);
                DbFactory.Default.Update(ShopAccount);
            }));
        }
コード例 #3
0
 /// <summary>
 /// 资金记录添加
 /// </summary>
 /// <param name="shopId"></param>
 /// <param name="money"></param>
 /// <param name="TradeType"></param>
 /// <param name="AccountNo"></param>
 /// <param name="ChargeWay"></param>
 /// <param name="detailID"></param>
 private static void updateAccount(long shopId, decimal money, Himall.CommonModel.ShopAccountType TradeType, string AccountNo, string ChargeWay, long detailID = 0)
 {
     lock (obj)
     {
         //处理余额
         var mShopAccountInfo = _iBillingService.GetShopAccount(shopId);
         //处理充值记录
         ShopAccountItemInfo mShopAccountItemInfo = new ShopAccountItemInfo()
         {
             AccountNo  = AccountNo,
             AccoutID   = mShopAccountInfo.Id,
             Amount     = money,
             Balance    = mShopAccountInfo.Balance,
             CreateTime = DateTime.Now,
             DetailId   = detailID.ToString(),
             IsIncome   = true,
             ReMark     = ChargeWay,
             ShopId     = shopId,
             ShopName   = mShopAccountInfo.ShopName,
             TradeType  = TradeType
         };
         _iBillingService.AddShopAccountItem(mShopAccountItemInfo);
     }
 }
コード例 #4
0
        public void OrderMarketService(int monthCount, long shopId, MarketType type)
        {
            if (shopId <= 0)
            {
                throw new HimallException("ShopId不能识别");
            }
            if (monthCount <= 0)
            {
                throw new HimallException("购买服务时长必须大于零");
            }
            var shop = Context.ShopInfo.FindById(shopId);

            if (shop == null || shopId <= 0)
            {
                throw new HimallException("ShopId不能识别");
            }
            var market    = Context.ActiveMarketServiceInfo.Where(a => a.ShopId == shopId && a.TypeId == type).FirstOrDefault();
            var price     = Context.MarketSettingInfo.Where(a => a.TypeId == type).Select(a => a.Price).FirstOrDefault();
            var StartTime = DateTime.Now;
            MarketServiceRecordInfo model = new MarketServiceRecordInfo();

            model.StartTime = StartTime;
            model.Price     = price * monthCount;
            var shopAccount = Context.ShopAccountInfo.Where(a => a.ShopId == shopId).FirstOrDefault(); //店铺帐户信息

            if (shopAccount.Balance < model.Price)                                                     //店铺余额不足以支付服务费用
            {
                throw new HimallException("您的店铺余额为:" + shopAccount.Balance + "元,不足以支付此次营销服务购买费用,请先充值。");
            }
            if (market != null)
            {
                var maxTime = market.MarketServiceRecordInfo.Max(a => a.EndTime);
                if (maxTime > DateTime.Now) //如果结束时间大于当前时间,续费从结束时间加上购买月数,否则从当前时间加上购买月数
                {
                    StartTime = maxTime;
                }
                model.StartTime = StartTime;
                model.BuyTime   = DateTime.Now;
                model.EndTime   = StartTime.AddMonths(monthCount);
                // model.MarketServiceId = market.Id;
                model.SettlementFlag = 1;
                market.MarketServiceRecordInfo.Add(model);
            }
            else
            {
                model.StartTime      = StartTime;
                model.EndTime        = StartTime.AddMonths(monthCount);
                model.SettlementFlag = 1;
                model.BuyTime        = DateTime.Now;
                ActiveMarketServiceInfo activeMarketServiceInfo = new Model.ActiveMarketServiceInfo();
                activeMarketServiceInfo.ShopId   = shopId;
                activeMarketServiceInfo.ShopName = shop.ShopName;
                activeMarketServiceInfo.TypeId   = type;
                activeMarketServiceInfo.MarketServiceRecordInfo.Add(model);
                Context.ActiveMarketServiceInfo.Add(activeMarketServiceInfo);
            }
            Context.SaveChanges();
            var ShopAccount          = Context.ShopAccountInfo.FirstOrDefault(a => a.ShopId == shopId);
            ShopAccountItemInfo info = new ShopAccountItemInfo();

            info.IsIncome        = false;
            info.ShopId          = shopId;
            info.DetailId        = model.Id.ToString();
            info.ShopName        = shop.ShopName;
            info.AccountNo       = shopId + info.DetailId + new Random().Next(10000);
            info.ReMark          = "店铺购买" + type.ToDescription() + "服务," + monthCount + "个月";
            info.TradeType       = CommonModel.ShopAccountType.MarketingServices;
            info.CreateTime      = DateTime.Now;
            info.Amount          = price * monthCount;
            info.AccoutID        = ShopAccount.Id;
            ShopAccount.Balance -= info.Amount;         //总余额减钱
            info.Balance         = ShopAccount.Balance; //变动后当前剩余金额
            Context.ShopAccountItemInfo.Add(info);
            var PlatAccount           = Context.PlatAccountInfo.FirstOrDefault();
            PlatAccountItemInfo pinfo = new PlatAccountItemInfo();

            pinfo.IsIncome       = true;
            pinfo.DetailId       = model.Id.ToString();
            pinfo.AccountNo      = info.AccountNo;
            pinfo.ReMark         = "店铺购买" + type.ToDescription() + "服务," + monthCount + "个月";
            pinfo.TradeType      = CommonModel.PlatAccountType.MarketingServices;
            pinfo.CreateTime     = DateTime.Now;
            pinfo.Amount         = price * monthCount;
            pinfo.AccoutID       = PlatAccount.Id;
            PlatAccount.Balance += info.Amount;  //总余额加钱

            pinfo.Balance = PlatAccount.Balance; //变动后当前剩余金额
            Context.PlatAccountItemInfo.Add(pinfo);
            Context.SaveChanges();
        }
コード例 #5
0
 /// <summary>
 /// 店铺流水
 /// </summary>
 /// <param name="item"></param>
 public void AddShopAccountItem(ShopAccountItemInfo model)
 {
     DbFactory.Default.Add(model);
 }
コード例 #6
0
ファイル: MarketService.cs プロジェクト: sky63886/Himall3.3
        public void OrderMarketService(int monthCount, long shopId, MarketType type)
        {
            if (shopId <= 0)
            {
                throw new HimallException("ShopId不能识别");
            }
            if (monthCount <= 0)
            {
                throw new HimallException("购买服务时长必须大于零");
            }
            var shop = DbFactory.Default.Get <ShopInfo>().Where(p => p.Id == shopId).FirstOrDefault();

            if (shop == null || shopId <= 0)
            {
                throw new HimallException("ShopId不能识别");
            }

            var price     = DbFactory.Default.Get <MarketSettingInfo>().Where(a => a.TypeId == type).Select(a => a.Price).FirstOrDefault <decimal>();
            var StartTime = DateTime.Now;
            MarketServiceRecordInfo model = new MarketServiceRecordInfo();

            model.StartTime = StartTime;
            model.Price     = price * monthCount;
            var shopAccount = DbFactory.Default.Get <ShopAccountInfo>().Where(a => a.ShopId == shopId).FirstOrDefault();//店铺帐户信息

            #region 它下面会取几次只,如为空会报异常,默认存入0的初始值
            if (shopAccount == null)
            {
                shopAccount                   = new ShopAccountInfo();
                shopAccount.ShopId            = shopId;
                shopAccount.ShopName          = shop.ShopName;
                shopAccount.Balance           = 0;
                shopAccount.PendingSettlement = 0;
                shopAccount.Settled           = 0;
                shopAccount.ReMark            = string.Empty;
                DbFactory.Default.Add(shopAccount);
            }
            #endregion

            if (shopAccount.Balance < model.Price) //店铺余额不足以支付服务费用
            {
                throw new HimallException("您的店铺余额为:" + shopAccount.Balance + "元,不足以支付此次营销服务购买费用,请先充值。");
            }

            DbFactory.Default.InTransaction(() =>
            {
                var market = DbFactory.Default.Get <ActiveMarketServiceInfo>().Where(a => a.ShopId == shopId && a.TypeId == type).FirstOrDefault();
                if (market != null)
                {
                    var maxTime = MarketApplication.GetServiceEndTime(market.Id);
                    if (maxTime > DateTime.Now) //如果结束时间大于当前时间,续费从结束时间加上购买月数,否则从当前时间加上购买月数
                    {
                        StartTime = maxTime;
                    }
                    model.StartTime = StartTime;
                    model.BuyTime   = DateTime.Now;
                    model.EndTime   = StartTime.AddMonths(monthCount);
                    // model.MarketServiceId = market.Id;
                    model.SettlementFlag  = 1;
                    model.MarketServiceId = market.Id;

                    DbFactory.Default.Add(model);
                }
                else
                {
                    model.StartTime      = StartTime;
                    model.EndTime        = StartTime.AddMonths(monthCount);
                    model.SettlementFlag = 1;
                    model.BuyTime        = DateTime.Now;

                    ActiveMarketServiceInfo activeMarketServiceInfo = new ActiveMarketServiceInfo();
                    activeMarketServiceInfo.ShopId   = shopId;
                    activeMarketServiceInfo.ShopName = shop.ShopName;
                    activeMarketServiceInfo.TypeId   = type;
                    DbFactory.Default.Add(activeMarketServiceInfo);

                    model.MarketServiceId = activeMarketServiceInfo.Id;
                    DbFactory.Default.Add(model);
                }

                var ShopAccount          = DbFactory.Default.Get <ShopAccountInfo>().Where(a => a.ShopId == shopId).FirstOrDefault();
                ShopAccountItemInfo info = new ShopAccountItemInfo();
                info.IsIncome            = false;
                info.ShopId          = shopId;
                info.DetailId        = model.Id.ToString();
                info.ShopName        = shop.ShopName;
                info.AccountNo       = shopId + info.DetailId + new Random().Next(10000);
                info.ReMark          = "店铺购买" + type.ToDescription() + "服务," + monthCount + "个月";
                info.TradeType       = ShopAccountType.MarketingServices;
                info.CreateTime      = DateTime.Now;
                info.Amount          = price * monthCount;
                info.AccoutID        = ShopAccount.Id;
                ShopAccount.Balance -= info.Amount;         //总余额减钱
                info.Balance         = ShopAccount.Balance; //变动后当前剩余金额

                DbFactory.Default.Add(info);
                DbFactory.Default.Update(ShopAccount);

                var platAccount = DbFactory.Default.Get <PlatAccountInfo>().FirstOrDefault();
                var pinfo       = new PlatAccountItemInfo
                {
                    IsIncome   = true,
                    DetailId   = model.Id.ToString(),
                    AccountNo  = info.AccountNo,
                    ReMark     = "店铺购买" + type.ToDescription() + "服务," + monthCount + "个月",
                    TradeType  = PlatAccountType.MarketingServices,
                    CreateTime = DateTime.Now,
                    Amount     = price * monthCount,
                    AccoutID   = platAccount.Id
                };
                platAccount.Balance += info.Amount;         //总余额加钱
                pinfo.Balance        = platAccount.Balance; //变动后当前剩余金额
                DbFactory.Default.Add(pinfo);
                DbFactory.Default.Update(platAccount);
            });
        }
コード例 #7
0
 /// <summary>
 /// 店铺流水
 /// </summary>
 /// <param name="item"></param>
 public void AddShopAccountItem(ShopAccountItemInfo model)
 {
     Context.ShopAccountItemInfo.Add(model);
     Context.SaveChanges();
 }
コード例 #8
0
ファイル: Settlement.cs プロジェクト: dingxinliang/TestHPYL
        public void AutoSettlement()
        {
            //using (TransactionScope transaction = new TransactionScope())
            //{
            try
            {
                Himall.Entity.Entities entity = new Entities();
                var checkDate = DateTime.MinValue;
                Log.Debug("AccountJob : start");
                // var settings = new SiteSettingService().GetSiteSettings();
                var settings = new SiteSettingService().GetSiteSettingsByObjectCache();
                if (settings.WeekSettlement < 1)
                {
                    Log.Error("结算周期设置不正确! ");
                    return;
                }
                var account = entity.AccountInfo.OrderByDescending(a => a.Id).FirstOrDefault();
                if (account == null)
                {
                    //第一笔结算数据
                    checkDate = GetDate(entity, checkDate).Date;
                }
                else
                {
                    checkDate = account.EndDate.Date;//上一次结束日期(2015-11-23 00:00:00),作为开始时间
                }
                if (checkDate.Equals(DateTime.MinValue))
                {
                    return;
                }

                DateTime startDate = checkDate.Date;
                DateTime endDate   = startDate.AddDays(settings.WeekSettlement);
                Log.Debug("AccountJob:endDate" + endDate + "DateTime:" + DateTime.Now.Date + "result:" + (endDate < DateTime.Now.Date));
                while (endDate < DateTime.Now)
                {
                    //结算日期内的待结算预约单 不计算开始时间,防止漏单
                    var pendingSetllementData = entity.PendingSettlementOrdersInfo.Where(c => c.OrderFinshTime < endDate).OrderByDescending(c => c.OrderFinshTime).ToList();
                    Log.Debug("Count:" + pendingSetllementData.Count());
                    var accountInfo = new AccountInfo();
                    accountInfo.ShopId                  = 0;
                    accountInfo.ShopName                = "系统定时任务结算";
                    accountInfo.AccountDate             = DateTime.Now;
                    accountInfo.StartDate               = startDate;
                    accountInfo.EndDate                 = endDate;
                    accountInfo.Status                  = AccountInfo.AccountStatus.Accounted;
                    accountInfo.ProductActualPaidAmount = pendingSetllementData.Sum(a => a.ProductsAmount);
                    accountInfo.FreightAmount           = pendingSetllementData.Sum(b => b.FreightAmount);
                    accountInfo.CommissionAmount        = pendingSetllementData.Sum(c => c.PlatCommission);
                    accountInfo.RefundCommissionAmount  = pendingSetllementData.Sum(d => d.PlatCommissionReturn);
                    accountInfo.RefundAmount            = pendingSetllementData.Sum(e => e.RefundAmount);
                    accountInfo.AdvancePaymentAmount    = 0;
                    accountInfo.Brokerage               = pendingSetllementData.Sum(f => f.DistributorCommission);
                    accountInfo.ReturnBrokerage         = pendingSetllementData.Sum(g => g.DistributorCommissionReturn);
                    accountInfo.PeriodSettlement        = pendingSetllementData.Sum(h => h.SettlementAmount);
                    //结算主表汇总数据

                    foreach (var item in pendingSetllementData)
                    {
                        var accountDetail = new AccountDetailInfo
                        {
                            //AccountId = result.Id,
                            ShopId                  = item.ShopId,
                            ShopName                = item.ShopName,
                            OrderType               = Himall.Model.AccountDetailInfo.EnumOrderType.FinishedOrder,
                            Date                    = DateTime.Now,
                            OrderFinshDate          = item.OrderFinshTime,
                            OrderId                 = item.OrderId,
                            ProductActualPaidAmount = item.ProductsAmount,
                            FreightAmount           = item.FreightAmount,
                            CommissionAmount        = item.PlatCommission,
                            RefundCommisAmount      = item.PlatCommissionReturn,
                            OrderRefundsDates       = "",
                            RefundTotalAmount       = item.RefundAmount,
                            OrderAmount             = item.OrderAmount,
                            BrokerageAmount         = item.DistributorCommission,
                            ReturnBrokerageAmount   = item.DistributorCommissionReturn,
                            SettlementAmount        = item.SettlementAmount,
                            PaymentTypeName         = item.PaymentTypeName
                        };
                        accountInfo.Himall_AccountDetails.Add(accountDetail);
                        //var detail = entity.AccountDetailInfo.Add(accountDetail);
                    }
                    entity.AccountInfo.Add(accountInfo);

                    entity.SaveChanges();
                    Random r = new Random();

                    var plat = entity.PlatAccountInfo.FirstOrDefault();//平台账户
                    //写平台资金明细表
                    var platAccountItem = new PlatAccountItemInfo();
                    platAccountItem.AccoutID   = plat.Id;
                    platAccountItem.CreateTime = DateTime.Now;
                    platAccountItem.AccountNo  = string.Format("{0:yyyyMMddHHmmssfff}{1}", DateTime.Now, r.Next(1000, 9999));
                    platAccountItem.Amount     = accountInfo.CommissionAmount - accountInfo.RefundCommissionAmount; //平台佣金-平台佣金退还
                    platAccountItem.Balance    = plat.Balance + platAccountItem.Amount;                             //账户余额+平台佣金-平台佣金退还
                    platAccountItem.TradeType  = PlatAccountType.SettlementIncome;
                    platAccountItem.IsIncome   = true;
                    platAccountItem.ReMark     = DateTime.Now + "平台结算" + accountInfo.Id;
                    platAccountItem.DetailId   = accountInfo.Id.ToString();
                    entity.PlatAccountItemInfo.Add(platAccountItem);

                    if (plat != null)
                    {
                        //平台账户总金额(加这次平台的佣金)
                        plat.Balance += platAccountItem.Amount;                 //平台佣金-平台佣金退还
                        //平台待结算金额
                        plat.PendingSettlement -= accountInfo.PeriodSettlement; //本次结算的总金额。//platAccountItem.Amount;//平台佣金-平台佣金退还
                        //平台已结算金额
                        plat.Settled += accountInfo.PeriodSettlement;           //本次结算的总金额。//platAccountItem.Amount;//平台佣金-平台佣金退还
                    }


                    var shoppendingSetllement = pendingSetllementData.GroupBy(a => a.ShopId).ToList();


                    foreach (var item in shoppendingSetllement)
                    {
                        //商户资金明细表
                        var shopAccount = entity.ShopAccountInfo.Where(a => a.ShopId == item.Key).FirstOrDefault();

                        var shopAccountItemInfo = new ShopAccountItemInfo();
                        shopAccountItemInfo.AccoutID        = shopAccount.Id;
                        shopAccountItemInfo.AccountNo       = string.Format("{0:yyyyMMddHHmmssfff}{1}", DateTime.Now, r.Next(1000, 9999));
                        shopAccountItemInfo.ShopId          = shopAccount.ShopId;
                        shopAccountItemInfo.ShopName        = shopAccount.ShopName;
                        shopAccountItemInfo.CreateTime      = DateTime.Now;
                        shopAccountItemInfo.Amount          = item.Sum(a => a.SettlementAmount);                 //结算金额
                        shopAccountItemInfo.Balance         = shopAccount.Balance + shopAccountItemInfo.Amount;; //账户余额+结算金额
                        shopAccountItemInfo.TradeType       = ShopAccountType.SettlementIncome;
                        shopAccountItemInfo.IsIncome        = true;
                        shopAccountItemInfo.ReMark          = "诊所结算明细" + accountInfo.Id;;
                        shopAccountItemInfo.DetailId        = accountInfo.Id.ToString();
                        shopAccountItemInfo.SettlementCycle = settings.WeekSettlement;
                        entity.ShopAccountItemInfo.Add(shopAccountItemInfo);

                        if (shopAccount != null)
                        {
                            shopAccount.Balance           += shopAccountItemInfo.Amount; //结算金额
                            shopAccount.PendingSettlement -= shopAccountItemInfo.Amount;
                            shopAccount.Settled           += shopAccountItemInfo.Amount; //平台佣金-平台佣金退还
                        }
                    }
                    entity.PendingSettlementOrdersInfo.RemoveRange(pendingSetllementData);//结算完了删除已结算数据
                    entity.SaveChanges();
                    //transaction.Complete();

                    account = entity.AccountInfo.Where(c => c.StartDate >= startDate).OrderByDescending(c => c.EndDate).FirstOrDefault();
                    if (account != null)
                    {
                        checkDate = account.EndDate.Date;//上一次结束日期(2015-11-23 00:00:00),作为开始时间
                    }
                    else
                    {
                        checkDate = startDate.AddDays(settings.WeekSettlement);
                    }
                    startDate = checkDate.Date;
                    endDate   = startDate.AddDays(settings.WeekSettlement);
                }
            }
            catch (System.Data.Entity.Validation.DbEntityValidationException ex)
            {
                Log.Error("AccountJob : " + ex.Message);
            }
            catch (Exception ex)
            {
                Log.Error("AccountJob : " + ex.Message);
            }
        }