Example #1
0
        public void Ready()
        {
            LiquidateId = Id;
            _hasError   = true;
            Liquidate   = LiquidateService.GetById(Id);
            State       = ModelHelper.GetBoundText(Liquidate, x => x.State);
            var currentUser = SecurityHelper.GetCurrentUser().CurrentUser;
            var shop        = ShopService.GetById(Liquidate.ShopId);

            var rate = shop.ShopDealLogChargeRate ?? HostSite.ShopDealLogChargeRate;

            RateAmount   = (Liquidate.DealAmount * rate);
            Amount       = (Liquidate.DealAmount - Liquidate.CancelAmount) - RateAmount;
            Formula      = string.Format("({0} - {1}) - {0} * {2}", Liquidate.DealAmount, Liquidate.CancelAmount, rate.ToString("P"));
            DealAmount   = Liquidate.DealAmount;
            CancelAmount = Liquidate.CancelAmount;
            Count        = Liquidate.Count;

            var ids = Liquidate.DealIds.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries).Select(x => Convert.ToInt32(x)).ToArray();

            Items = new ItemList <ListShopDealLog>(this.ShopDealLogService.GetByIds(ids).Select(x => new ListShopDealLog(x)));

            CashAmount = CashDealLogService.GetSummary(currentUser.UserId);


            var dealways = from x in DealWayService.Query()
                           where new ApplyToModel(x.ApplyTo).EnabledShopDealAccount
                           select new IdNamePair {
                Key = x.DealWayId, Name = x.DisplayName
            };

            this.DealWay.Bind(dealways);
            this.DealWay.IsReadOnly = this.Liquidate.State == LiquidateStates.Done;
            _hasError = false;
        }
Example #2
0
        public void Execute(User currentUser)
        {
            var serialNo = SerialNoHelper.Create();

            using (var tran = TransactionHelper.BeginTransaction())
            {
                var liquidate = this.LiquidateService.GetById(LiquidateId);
                if (liquidate == null || liquidate.State != LiquidateStates.Processing)
                {
                    throw new Exception("没有找到相关的清算记录");
                }
                liquidate.State = LiquidateStates.Done;
                LiquidateService.Update(liquidate);

                var shop       = ShopService.GetById(ShopId);
                var rate       = shop.ShopDealLogChargeRate ?? HostSite.ShopDealLogChargeRate;
                var rateAmount = (liquidate.DealAmount * rate);
                var amount     = liquidate.DealAmount - liquidate.CancelAmount;

                var systemDealLog = new SystemDealLog(serialNo, currentUser)
                {
                    Addin     = liquidate.LiquidateId.ToString(),
                    Amount    = -amount,
                    DealType  = SystemDealLogTypes.ShopDealLogDone,
                    DealWayId = DealWayId,
                };
                SystemDealLogService.Create(systemDealLog);

                shop.Amount -= amount;
                var shopDealLog = new ShopDealLog(serialNo, DealTypes.ShopDealLogDone, -amount, null, null, null, shop,
                                                  systemDealLog.SystemDealLogId);
                ShopDealLogService.Create(shopDealLog);

                systemDealLog = new SystemDealLog(serialNo, currentUser)
                {
                    Addin     = liquidate.LiquidateId.ToString(),
                    Amount    = rateAmount,
                    DealType  = SystemDealLogTypes.ShopDealLogCharging,
                    DealWayId = DealWayId,
                };
                SystemDealLogService.Create(systemDealLog);

                shop.RechargingAmount += rateAmount;
                shopDealLog            = new ShopDealLog(serialNo, DealTypes.ShopDealLogDone, rateAmount, null, null, null, shop,
                                                         systemDealLog.SystemDealLogId);
                ShopDealLogService.Create(shopDealLog);

                var dealWay = DealWayService.GetById(this.DealWayId);
                if (dealWay.IsCash)
                {
                    CashDealLogService.Create(new CashDealLog(amount - rateAmount, currentUser.UserId, currentUser.UserId, CashDealLogTypes.ShopDealLogDone));
                }
                ShopService.Update(shop);
                tran.Commit();
            }
        }
Example #3
0
        public SimpleAjaxResult Ready()
        {
            var user      = this.SecurityHelper.GetCurrentUser().CurrentUser as ShopUser;
            var liquidate = LiquidateService.GetById(Id);

            try
            {
                var cmd = new DeleteLiquidateCommand(this.Id, liquidate.ShopId);
                UnityContainer.BuildUp(cmd);
                cmd.Execute(user);
                return(new SimpleAjaxResult());
            }
            catch (Exception ex)
            {
                return(new SimpleAjaxResult(ex.Message));
            }
        }