コード例 #1
0
        public static bool AddIntegral(UserInfo user, int intOpType, double douOpValue, string strRemark)
        {
            bool result;

            if (douOpValue > 0.0)
            {
                AccountDetailInfo entity = new AccountDetailInfo
                {
                    UserID      = user.AutoID,
                    UserName    = user.UserName,
                    Unit        = "Integral",
                    Before      = (double)user.Integral,
                    OpValue     = douOpValue,
                    OpType      = intOpType,
                    After       = ((intOpType == 1) ? ((double)user.Integral + douOpValue) : ((double)user.Integral - douOpValue)),
                    Remark      = strRemark,
                    Operator    = user.UserName,
                    OperateDate = DateTime.Now
                };
                result = (AccountDetail.Add(entity) > 0);
            }
            else
            {
                result = false;
            }
            return(result);
        }
コード例 #2
0
ファイル: AccountDetail.cs プロジェクト: ngochoanhbr/dahuco
 protected void lnk_Delete_Click(object sender, System.EventArgs e)
 {
     if (!base.IsAuthorizedOp(ActionType.Delete.ToString()))
     {
         base.ShowAjaxMsg(this.UpdatePanel1, "Không có thẩm quyền");
     }
     else
     {
         int @int = WebUtils.GetInt((sender as LinkButton).CommandArgument);
         AccountDetailInfo dataById = SinGooCMS.BLL.AccountDetail.GetDataById(@int);
         if (dataById == null)
         {
             base.ShowAjaxMsg(this.UpdatePanel1, "Những thông tin này không được tìm thấy, các dữ liệu không tồn tại hoặc đã bị xóa");
         }
         else if (SinGooCMS.BLL.AccountDetail.Delete(@int))
         {
             this.BindData();
             PageBase.log.AddEvent(base.LoginAccount.AccountName, "删除会员[" + dataById.UserName + "]的账户明细成功");
             base.ShowAjaxMsg(this.UpdatePanel1, "Thao tác thành công");
         }
         else
         {
             base.ShowAjaxMsg(this.UpdatePanel1, "Thao tác thất bại");
         }
     }
 }
コード例 #3
0
        public JsonResult AccountDetail(string id)
        {
            string response = null;

//            response = new CommonApiController().ExtractXml(new ConstantValue().ACCOUNTQUERY, id);       //extract xml

            AccountDetailInfo <LinksItem> info = new AccountDetailInfo <LinksItem>();

            using (XmlReader reader = XmlReader.Create(new StringReader(response)))
            {
                if (reader.ReadToFollowing("ListID"))
                {
                    info.ID = reader.ReadElementContentAsString();
                }
                if (reader.ReadToFollowing("Name"))
                {
                    info.Name = reader.ReadElementContentAsString();
                }

                if (reader.ReadToFollowing("AccountType"))
                {
                    info.AccountType = reader.ReadElementContentAsString();
                }

                if (reader.ReadToFollowing("BankNumber"))
                {
                    info.BankNumber = reader.ReadElementContentAsString();
                }

                if (reader.ReadToFollowing("Balance"))
                {
                    info.Balance = reader.ReadElementContentAsDouble();
                }

                info._links = new LinksItem()
                {
                    Self = new LinksItemSub {
                        Href = Request.Path.ToString()
                    }
                };
            }

            var initLink = new AccountDetailInfo <BillEmbed <List <BillInfo> > >()
            {
                ID          = info.ID,
                Name        = info.Name,
                AccountType = info.AccountType,
                BankNumber  = info.BankNumber,
                Balance     = info.Balance,
                _links      = info._links,
                _embedded   = new BillEmbed <List <BillInfo> >()
                {
                    Bills = new BillsController().AccountBillXml(info.ID)
                }
            };


            return(Json(initLink));
        }
コード例 #4
0
        public static int Add(AccountDetailInfo entity)
        {
            int result;

            if (entity == null)
            {
                result = 0;
            }
            else
            {
                result = BizBase.dbo.InsertModel <AccountDetailInfo>(entity);
            }
            return(result);
        }
コード例 #5
0
ファイル: AccountJob.cs プロジェクト: Shikyoh/HSWB2B2C
        private void CalculationMoney(DateTime startDate, DateTime endDate)
        {
            DateTime?finishDate;

            string[] str;
            Entities entity = new Entities();
            var      list   = (
                from p in entity.OrderInfo
                join o in entity.OrderRefundInfo on p.Id equals o.OrderId
                join x in entity.OrderItemInfo on o.OrderId equals x.OrderId
                where (int)p.OrderStatus == 5 && (o.ManagerConfirmDate >= startDate) && (o.ManagerConfirmDate < endDate) && (int)o.ManagerConfirmStatus == 7
                select new { Order = p, OrderRefund = o, OrderItem = x }).Distinct().ToList();
            var collection = (
                from p in entity.OrderInfo
                join o in entity.OrderItemInfo on p.Id equals o.OrderId
                where (int)p.OrderStatus == 5 && (p.FinishDate >= startDate) && (p.FinishDate < endDate)
                select new { Order = p, OrderItem = o }).ToList();
            List <long> nums = new List <long>();

            nums.AddRange(
                from c in list
                select c.Order.ShopId);
            nums.AddRange(
                from c in collection
                select c.Order.ShopId);
            nums = nums.Distinct <long>().ToList();
            using (TransactionScope transactionScope = new TransactionScope())
            {
                try
                {
                    foreach (long num in nums)
                    {
                        List <OrderInfo> orderInfos = (
                            from c in collection
                            where c.Order.ShopId == num
                            select c.Order).Distinct <OrderInfo>().ToList();
                        decimal num1 = orderInfos.Sum <OrderInfo>((OrderInfo c) => c.ProductTotalAmount) - orderInfos.Sum <OrderInfo>((OrderInfo c) => c.DiscountAmount);
                        decimal num2 = orderInfos.Sum <OrderInfo>((OrderInfo c) => c.Freight);
                        decimal num3 = CalculationTotalCommission((
                                                                      from c in collection
                                                                      where c.Order.ShopId == num
                                                                      select c.OrderItem).Distinct <OrderItemInfo>().ToList());
                        decimal num4 = CalculationTotalRefundCommission((
                                                                            from c in list
                                                                            where c.OrderRefund.ShopId == num
                                                                            select c.OrderItem).Distinct <OrderItemInfo>().ToList());
                        decimal num5 = (
                            from c in list
                            where c.OrderRefund.ShopId == num
                            select c.OrderRefund).Distinct <OrderRefundInfo>().Sum <OrderRefundInfo>((OrderRefundInfo c) => c.Amount);
                        decimal     num6        = (((num1 + num2) - num3) - num5) + num4;
                        AccountInfo accountInfo = new AccountInfo()
                        {
                            ShopId   = num,
                            ShopName = (
                                from c in entity.ShopInfo
                                where c.Id == num
                                select c).FirstOrDefault().ShopName,
                            AccountDate             = DateTime.Now,
                            StartDate               = startDate,
                            EndDate                 = endDate.AddSeconds(-1),
                            Status                  = AccountInfo.AccountStatus.UnAccount,
                            ProductActualPaidAmount = num1,
                            FreightAmount           = num2,
                            CommissionAmount        = num3,
                            RefundCommissionAmount  = num4,
                            RefundAmount            = num5,
                            PeriodSettlement        = num6,
                            Remark                  = string.Empty
                        };
                        entity.AccountInfo.Add(accountInfo);
                        foreach (OrderInfo orderInfo in (
                                     from c in list
                                     where c.Order.ShopId == num
                                     select c.Order).Distinct <OrderInfo>().ToList())
                        {
                            AccountDetailInfo accountDetailInfo = new AccountDetailInfo()
                            {
                                Himall_Accounts = accountInfo,
                                ShopId          = orderInfo.ShopId
                            };
                            finishDate                  = orderInfo.FinishDate;
                            accountDetailInfo.Date      = finishDate.Value;
                            accountDetailInfo.OrderType = AccountDetailInfo.EnumOrderType.ReturnOrder;
                            accountDetailInfo.OrderId   = orderInfo.Id;
                            accountDetailInfo.ProductActualPaidAmount = orderInfo.ProductTotalAmount - orderInfo.DiscountAmount;
                            accountDetailInfo.FreightAmount           = orderInfo.Freight;
                            accountDetailInfo.CommissionAmount        = CalculationTotalCommission((
                                                                                                       from c in list
                                                                                                       where c.OrderRefund.OrderId == orderInfo.Id
                                                                                                       select c.OrderItem).Distinct <OrderItemInfo>().ToList());
                            accountDetailInfo.RefundCommisAmount = CalculationTotalRefundCommission((
                                                                                                        from c in list
                                                                                                        where c.OrderRefund.OrderId == orderInfo.Id
                                                                                                        select c.OrderItem).Distinct <OrderItemInfo>().ToList());
                            accountDetailInfo.RefundTotalAmount = (
                                from c in list
                                where c.OrderRefund.OrderId == orderInfo.Id
                                select c.OrderRefund).Distinct <OrderRefundInfo>().Sum <OrderRefundInfo>((OrderRefundInfo c) => c.Amount);
                            accountDetailInfo.OrderDate         = orderInfo.OrderDate;
                            accountDetailInfo.OrderRefundsDates = string.Join <DateTime>(";", (
                                                                                             from c in list
                                                                                             where c.OrderRefund.OrderId == orderInfo.Id
                                                                                             select c.OrderRefund.ManagerConfirmDate).Distinct <DateTime>());
                            entity.AccountDetailInfo.Add(accountDetailInfo);
                        }
                        foreach (OrderInfo orderInfo1 in orderInfos)
                        {
                            AccountDetailInfo value = new AccountDetailInfo()
                            {
                                Himall_Accounts = accountInfo,
                                ShopId          = orderInfo1.ShopId
                            };
                            finishDate      = orderInfo1.FinishDate;
                            value.Date      = finishDate.Value;
                            value.OrderType = AccountDetailInfo.EnumOrderType.FinishedOrder;
                            value.OrderId   = orderInfo1.Id;
                            value.ProductActualPaidAmount = orderInfo1.ProductTotalAmount - orderInfo1.DiscountAmount;
                            value.FreightAmount           = orderInfo1.Freight;
                            value.CommissionAmount        = CalculationTotalCommission((
                                                                                           from c in collection
                                                                                           where c.Order.Id == orderInfo1.Id
                                                                                           select c.OrderItem).Distinct <OrderItemInfo>().ToList());
                            value.RefundCommisAmount = new decimal(0);
                            value.RefundTotalAmount  = new decimal(0);
                            value.OrderDate          = orderInfo1.OrderDate;
                            value.OrderRefundsDates  = string.Empty;
                            entity.AccountDetailInfo.Add(value);
                        }
                    }
                    entity.SaveChanges();
                    transactionScope.Complete();
                }
                catch (Exception exception1)
                {
                    Exception exception = exception1;
                    str = new string[] { "CalculationMoney :startDate=", startDate.ToString(), " endDate=", endDate.ToString(), "/r/n", exception.Message };
                    Log.Error(string.Concat(str));
                }
            }
            try
            {
                var list1 = (
                    from b in entity.ActiveMarketServiceInfo
                    join c in entity.MarketServiceRecordInfo on b.Id equals c.MarketServiceId
                    join d in nums on b.ShopId equals d
                    join aa in entity.MarketSettingInfo on b.TypeId equals aa.TypeId
                    where c.SettlementFlag == 0
                    select new { ShopId = b.ShopId, TypeId = b.TypeId, Price = ((c.EndTime.Year * 12 + c.EndTime.Month - (c.StartTime.Year * 12 + c.StartTime.Month)) * aa.Price), MSRecordId = c.Id, StartTime = c.StartTime, EndTime = c.EndTime }).ToList();
                List <AccountInfo> accountInfos = (
                    from e in entity.AccountInfo
                    where e.StartDate == startDate
                    select e).ToList();
                IEnumerable <long> nums1 = (
                    from e in list1
                    select e.ShopId).Distinct <long>();
                foreach (AccountInfo periodSettlement in accountInfos)
                {
                    var shopId =
                        from e in list1
                        where e.ShopId == periodSettlement.ShopId
                        select e;
                    foreach (var variable in shopId)
                    {
                        periodSettlement.PeriodSettlement     = periodSettlement.PeriodSettlement - variable.Price;
                        periodSettlement.AdvancePaymentAmount = periodSettlement.AdvancePaymentAmount + variable.Price;
                        DbSet <AccountMetaInfo> accountMetaInfo  = entity.AccountMetaInfo;
                        AccountMetaInfo         accountMetaInfo1 = new AccountMetaInfo()
                        {
                            AccountId        = periodSettlement.Id,
                            MetaKey          = variable.TypeId.ToDescription(),
                            MetaValue        = variable.Price.ToString("f2"),
                            ServiceStartTime = variable.StartTime,
                            ServiceEndTime   = variable.EndTime
                        };
                        accountMetaInfo.Add(accountMetaInfo1);
                    }
                }
                var collection1 = (
                    from a in entity.MarketServiceRecordInfo
                    join b in entity.ActiveMarketServiceInfo on a.MarketServiceId equals b.Id
                    join c in nums1 on b.ShopId equals c
                    where a.SettlementFlag == 0
                    select new { Shopid = b.ShopId, TypeId = b.TypeId, Msrecordid = a.Id }).ToList();
                foreach (var variable1 in collection1)
                {
                    MarketServiceRecordInfo marketServiceRecordInfo = entity.MarketServiceRecordInfo.FirstOrDefault((MarketServiceRecordInfo e) => e.Id == variable1.Msrecordid);
                    marketServiceRecordInfo.SettlementFlag = 1;
                }
                entity.SaveChanges();
            }
            catch (Exception exception3)
            {
                Exception exception2 = exception3;
                str = new string[] { "CalculationMoney 服务费:startDate=", startDate.ToString(), " endDate=", endDate.ToString(), "/r/n", exception2.Message };
                Log.Error(string.Concat(str));
            }
        }
コード例 #6
0
        private void CalculationMoney(string orderIds)
        {
            SiteSettingsInfo siteSettings = (new SiteSettingService()).GetSiteSettings();

            char[]             chrArray  = new char[] { ',' };
            IEnumerable <long> numsOrder =
                from item in orderIds.Split(chrArray)
                select long.Parse(item);

            DateTime?finishDate;

            string[] str;
            Entities entity = new Entities();
            var      list   = (
                from p in entity.OrderInfo
                join o in entity.OrderRefundInfo on p.Id equals o.OrderId
                join x in entity.OrderItemInfo on o.OrderId equals x.OrderId
                where numsOrder.Contains(p.Id) && (int)o.ManagerConfirmStatus == 7
                select new { Order = p, OrderRefund = o, OrderItem = x }).Distinct().ToList();
            var collection = (
                from p in entity.OrderInfo
                join o in entity.OrderItemInfo on p.Id equals o.OrderId
                where numsOrder.Contains(p.Id)
                select new { Order = p, OrderItem = o }).ToList();
            List <long> nums = new List <long>();

            nums.AddRange(
                from c in list
                select c.Order.ShopId);
            nums.AddRange(
                from c in collection
                select c.Order.ShopId);
            nums = nums.Distinct <long>().ToList();
            using (TransactionScope transactionScope = new TransactionScope())
            {
                try
                {
                    foreach (long num in nums)
                    {
                        List <OrderInfo> orderInfos = (
                            from c in collection
                            where c.Order.ShopId == num
                            select c.Order).Distinct <OrderInfo>().ToList();
                        decimal num1 = orderInfos.Sum <OrderInfo>((OrderInfo c) => c.ProductTotalAmount) - orderInfos.Sum <OrderInfo>((OrderInfo c) => c.DiscountAmount);
                        decimal num2 = orderInfos.Sum <OrderInfo>((OrderInfo c) => c.Freight);
                        decimal num3 = CalculationTotalCommission((
                                                                      from c in collection
                                                                      where c.Order.ShopId == num
                                                                      select c.OrderItem).Distinct <OrderItemInfo>().ToList());
                        decimal num4 = CalculationTotalRefundCommission((
                                                                            from c in list
                                                                            where c.OrderRefund.ShopId == num
                                                                            select c.OrderItem).Distinct <OrderItemInfo>().ToList());
                        decimal num5 = (
                            from c in list
                            where c.OrderRefund.ShopId == num
                            select c.OrderRefund).Distinct <OrderRefundInfo>().Sum <OrderRefundInfo>((OrderRefundInfo c) => c.Amount);
                        decimal     num6        = (((num1 + num2) - num3) - num5) + num4;
                        AccountInfo accountInfo = new AccountInfo()
                        {
                            ShopId   = num,
                            ShopName = (
                                from c in entity.ShopInfo
                                where c.Id == num
                                select c).FirstOrDefault().ShopName,
                            AccountDate             = DateTime.Now,
                            FinishDate              = DateTime.Now,
                            StartDate               = DateTime.Now.Date.AddDays(-siteSettings.WeekSettlement),
                            EndDate                 = DateTime.Now.Date,
                            Status                  = AccountInfo.AccountStatus.UnAccount,
                            ProductActualPaidAmount = num1,
                            FreightAmount           = num2,
                            CommissionAmount        = num3,
                            RefundCommissionAmount  = num4,
                            RefundAmount            = num5,
                            PeriodSettlement        = num6,
                            Remark                  = string.Empty
                        };
                        entity.AccountInfo.Add(accountInfo);
                        foreach (OrderInfo orderInfo in (
                                     from c in list
                                     where c.Order.ShopId == num
                                     select c.Order).Distinct <OrderInfo>().ToList())
                        {
                            AccountDetailInfo accountDetailInfo = new AccountDetailInfo()
                            {
                                Himall_Accounts = accountInfo,
                                ShopId          = orderInfo.ShopId
                            };
                            finishDate                  = orderInfo.FinishDate;
                            accountDetailInfo.Date      = finishDate.Value;
                            accountDetailInfo.OrderType = AccountDetailInfo.EnumOrderType.ReturnOrder;
                            accountDetailInfo.OrderId   = orderInfo.Id;
                            accountDetailInfo.ProductActualPaidAmount = orderInfo.ProductTotalAmount - orderInfo.DiscountAmount;
                            accountDetailInfo.FreightAmount           = orderInfo.Freight;
                            accountDetailInfo.CommissionAmount        = CalculationTotalCommission((
                                                                                                       from c in list
                                                                                                       where c.OrderRefund.OrderId == orderInfo.Id
                                                                                                       select c.OrderItem).Distinct <OrderItemInfo>().ToList());
                            accountDetailInfo.RefundCommisAmount = CalculationTotalRefundCommission((
                                                                                                        from c in list
                                                                                                        where c.OrderRefund.OrderId == orderInfo.Id
                                                                                                        select c.OrderItem).Distinct <OrderItemInfo>().ToList());
                            accountDetailInfo.RefundTotalAmount = (
                                from c in list
                                where c.OrderRefund.OrderId == orderInfo.Id
                                select c.OrderRefund).Distinct <OrderRefundInfo>().Sum <OrderRefundInfo>((OrderRefundInfo c) => c.Amount);
                            accountDetailInfo.OrderDate         = orderInfo.OrderDate;
                            accountDetailInfo.OrderRefundsDates = string.Join <DateTime>(";", (
                                                                                             from c in list
                                                                                             where c.OrderRefund.OrderId == orderInfo.Id
                                                                                             select c.OrderRefund.ManagerConfirmDate).Distinct <DateTime>());
                            entity.AccountDetailInfo.Add(accountDetailInfo);
                            UpateAccountType(orderInfo.Id);
                        }
                        foreach (OrderInfo orderInfo1 in orderInfos)
                        {
                            AccountDetailInfo value = new AccountDetailInfo()
                            {
                                Himall_Accounts = accountInfo,
                                ShopId          = orderInfo1.ShopId
                            };
                            finishDate      = orderInfo1.FinishDate;
                            value.Date      = finishDate.Value;
                            value.OrderType = AccountDetailInfo.EnumOrderType.FinishedOrder;
                            value.OrderId   = orderInfo1.Id;
                            value.ProductActualPaidAmount = orderInfo1.ProductTotalAmount - orderInfo1.DiscountAmount;
                            value.FreightAmount           = orderInfo1.Freight;
                            value.CommissionAmount        = CalculationTotalCommission((
                                                                                           from c in collection
                                                                                           where c.Order.Id == orderInfo1.Id
                                                                                           select c.OrderItem).Distinct <OrderItemInfo>().ToList());
                            value.RefundCommisAmount = new decimal(0);
                            value.RefundTotalAmount  = new decimal(0);
                            value.OrderDate          = orderInfo1.OrderDate;
                            value.OrderRefundsDates  = string.Empty;
                            entity.AccountDetailInfo.Add(value);
                            UpateAccountType(orderInfo1.Id);
                        }
                    }
                    entity.SaveChanges();
                    transactionScope.Complete();
                }
                catch (Exception exception1)
                {
                    Exception exception = exception1;
                    str = new string[] { "CalculationMoney :startDate=", DateTime.Now.Date.AddDays(-siteSettings.WeekSettlement).ToString(), " endDate=", DateTime.Now.Date.ToString(), "/r/n", exception.Message };
                    Log.Error(string.Concat(str));
                }
            }
        }
コード例 #7
0
 public static bool Update(AccountDetailInfo entity)
 {
     return(entity != null && BizBase.dbo.UpdateModel <AccountDetailInfo>(entity));
 }
コード例 #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);
            }
        }