public void Execute(User currentUser) { using (var tran = TransactionHelper.BeginTransaction()) { var liquidate = this.LiquidateService.GetById(LiquidateId); if (liquidate == null || liquidate.State != LiquidateStates.Processing) { throw new Exception("没有找到相关的清算记录"); } this.LiquidateService.Delete(liquidate); var ids = liquidate.DealIds.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries).Select(x => Convert.ToInt32(x)).ToList(); if (liquidate.Count != ShopDealLogService.UpdateLiquidateId(ids, 0, liquidate.LiquidateId, ShopId)) { throw new Exception("清算数据冲突"); } var dealLogIds = ShopDealLogService.GetAddins(ids.ToArray()); if (liquidate.Count != dealLogIds.Count) { throw new Exception("清算数据冲突"); } if (liquidate.Count != DealLogService.UpdateLiquidateId(dealLogIds, 0, liquidate.LiquidateId, ShopId)) { throw new Exception("清算数据冲突"); } tran.Commit(); } }
public void DoLiquidate(int shopid, List <int> ids) { var liquidate = this.LiquidateService.ReadyLiquidate(shopid, ids.ToArray()); if (liquidate.Count == 0) { throw new Exception("没有可以清算的交易"); } liquidate.DealIds = string.Join(",", ids.ToArray()); liquidate.ShopId = shopid; liquidate.State = LiquidateStates.Processing; this.LiquidateService.Insert(liquidate); if (liquidate.Count != ShopDealLogService.UpdateLiquidateId(ids, liquidate.LiquidateId, 0, shopid)) { throw new Exception("清算数据冲突"); } var dealLogIds = ShopDealLogService.GetAddins(ids.ToArray()); if (liquidate.Count != dealLogIds.Count) { throw new Exception("清算数据冲突"); } if (liquidate.Count != DealLogService.UpdateLiquidateId(dealLogIds, liquidate.LiquidateId, 0, shopid)) { throw new Exception("清算数据冲突"); } }
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(); } }
public void Apply() { var id = 0; if (!int.TryParse(this.SerialServerNo, out id)) { this.AddError(0, "nonfound", SerialServerNo); DisableApply = true; return; } ShopDealLog = ShopDealLogService.GetByAddin(id); if (ShopDealLog == null) { this.AddError(0, "nonfound", SerialServerNo); DisableApply = true; return; } if (ShopDealLog.State == DealLogStates.Normal_) { DisableApply = true; return; } State = ModelHelper.GetBoundText(ShopDealLog, x => x.State); var rollbackItem = RollbackService.GetByShopDealLogId(ShopDealLog.ShopDealLogId); if (rollbackItem != null) { AddError(0, "alreadyExisting", SerialServerNo); } else { RollbackShopDealLog item = new RollbackShopDealLog() { ShopDealLogId = ShopDealLog.ShopDealLogId, State = RollbackShopDealLogState.Processing, ShopId = ShopDealLog.ShopId, SubmitTime = DateTime.Now, }; RollbackService.Create(item); this.AddMessage("success", SerialServerNo); Amount = 0; AccountName = ""; PosName = ""; ShopName = ""; ShopDisplayName = ""; SubmitTime = null; DealType = ""; State = ""; SerialServerNo = ""; } }
public void Ready() { _hasError = true; Rollback = RollbackService.GetById(Id); State = ModelHelper.GetBoundText(Rollback, x => x.State); var currentUser = SecurityHelper.GetCurrentUser().CurrentUser; var shop = ShopService.GetById(Rollback.ShopId); var shopDealLog = ShopDealLogService.GetById(Rollback.ShopDealLogId); this.SubmitTime = Rollback.SubmitTime; this.DealSubmitTime = shopDealLog.SubmitTime; this.Amount = shopDealLog.Amount; this.AccountName = shopDealLog.AccountName; this.PosName = shopDealLog.SourcePosName; this.ShopName = shop.Name; this.ShopDisplayName = shop.DisplayName; SerialServerNo = shopDealLog.SerialServerNo; DealType = ModelHelper.GetBoundText(shopDealLog, x => DealType); _hasError = false; }
public SimpleAjaxResult Ready() { var user = this.SecurityHelper.GetCurrentUser().CurrentUser as ShopUser; var shopId = user.ShopId; foreach (var id in Ids) { using (var tran = TransactionHelper.BeginTransaction()) { var shopDealLog = ShopDealLogService.GetById(id); if (shopDealLog.State == DealLogStates.Normal_) { return(new SimpleAjaxResult("该交易已冲正")); } if (shopDealLog.ShopId != shopId) { return(new SimpleAjaxResult("只能提交自己商户的申请")); } var rollback = this.RollbackShopDealLogService.GetByShopDealLogId(shopDealLog.ShopDealLogId); if (rollback != null) { return(new SimpleAjaxResult("该交易取消请求已经存在")); } rollback = new RollbackShopDealLog { ShopDealLogId = shopDealLog.ShopDealLogId, ShopId = shopDealLog.ShopId, State = RollbackShopDealLogState.Processing, }; RollbackShopDealLogService.Create(rollback); tran.Commit(); } } return(new SimpleAjaxResult()); }
public void Ready() { DisableApply = true; var id = 0; if (!int.TryParse(this.SerialServerNo, out id)) { this.AddError(0, "nonfound", SerialServerNo); DisableApply = true; return; } ShopDealLog = ShopDealLogService.GetByAddin(id); if (ShopDealLog == null) { this.AddError(0, "nonfound", SerialServerNo); DisableApply = true; return; } State = ModelHelper.GetBoundText(ShopDealLog, x => x.State); Amount = ShopDealLog.Amount; PosName = ShopDealLog.SourcePosName; SubmitTime = ShopDealLog.SubmitTime; AccountName = ShopDealLog.AccountName; DealType = ModelHelper.GetBoundText(ShopDealLog, x => x.DealType); var shop = ShopService.GetById(ShopDealLog.ShopId); ShopDisplayName = shop.DisplayName; ShopName = shop.Name; var account = AccountService.GetById(ShopDealLog.AccountId); if (account.OwnerId.HasValue) { var owner = MembershipService.GetUserById(account.OwnerId.Value); if (owner != null) { OwnerMobile = owner.Mobile; OwnerDisplayName = owner.DisplayName; } } var accountShop = ShopService.GetById(account.ShopId); if (accountShop != null) { AccountShopName = accountShop.DisplayName; } var rollbackItem = RollbackService.GetByShopDealLogId(ShopDealLog.ShopDealLogId); if (rollbackItem != null) { if (rollbackItem.State == RollbackShopDealLogState.Processing) { ApplyState = "ÒѾÉêÇë"; } else { ApplyState = "ÒÑÉêÇë³É¹¦"; } } else { if (ShopDealLog.State != DealLogStates.Normal_) { ApplyState = "δÉêÇë"; } DisableApply = false; } }
public void Query() { var request = new ShopDealLogRequest(); if (State != ShopDealLogStates.All) { request.State = State; } request.SubmitDateMin = Data.Start; request.SubmitDateMax = Data.GetEnd(); request.AccountName = AccountName; if (Shop != Globals.All) { request.ShopId = Shop; } request.SerialNo = SerialNo; request.IsLiquidate = IsLiquidate; var user = SecurityHelper.GetCurrentUser().CurrentUser as ShopUser; if (user != null) { request.ShopId = user.ShopId; } if (AccountShop != Globals.All) { request.AccountShopId = AccountShop; } var query = ShopDealLogService.Query(request); this.List = query.ToList(this, x => new ListShopDealLog(x)); var shopIds = List.Select(x => x.InnerObject.ShopId).Distinct(); var shops = ShopService.Query(new ShopRequest() { ShopIds = shopIds.ToArray() }).ToList(); foreach (var log in List) { var shop = shops.FirstOrDefault(x => x.ShopId == log.InnerObject.ShopId); if (shop != null) { log.TempShop = shop; } } var dealLogIds = List.Select(x => x.InnerObject.Addin).Distinct(); var dealLogs = DealLogService.GetByIds(dealLogIds.ToArray()).ToList(); foreach (var log in List) { var shop = dealLogs.FirstOrDefault(x => x.DealLogId == log.InnerObject.Addin); if (shop != null) { log.DealLog = shop; } } // var q = (from x in ShopService.Query(new ShopRequest() { IsBuildIn = false, State = ShopStates.Normal }) select new IdNamePair { Key = x.ShopId, Name = x.FormatedName }).ToList(); q.Insert(0, new IdNamePair { Key = Ecard.Models.Shop.Default.ShopId, Name = Ecard.Models.Shop.Default.FormatedName }); this.AccountShop.Bind(q, true); }