public void CloseOrder(Order order) { DecreaseStockWhen DecreaseStockWhen = (DecreaseStockWhen)(Enum.Parse(typeof(DecreaseStockWhen), SettingManager.GetSettingValueForTenant(ShopSettings.General.DecreaseStockWhen, order.TenantId))); order.OrderStatus = OrderStatus.Close; //Increase stock if (DecreaseStockWhen == DecreaseStockWhen.Create) { foreach (OrderItem orderItem in order.OrderItems) { orderItem.Specification.Stock += orderItem.Count; } } CurrentUnitOfWork.SaveChanges(); if (order is ChannelAgencyApplyOrder) { ChannelAgencyManager.DeleteChannelAgencyApply(order.Id); } }
public void HandleEvent(OrderPayedEventData eventData) { if (eventData.Order is ProductOrder) { ProductOrder order = eventData.Order as ProductOrder; DecreaseStockWhen DecreaseStockWhen = (DecreaseStockWhen)(Enum.Parse(typeof(DecreaseStockWhen), SettingManager.GetSettingValueForTenant(ShopSettings.General.DecreaseStockWhen, eventData.Order.TenantId))); foreach (OrderItem orderItem in order.OrderItems) { //Decreate stock if (DecreaseStockWhen == DecreaseStockWhen.Pay) { ProductManager.DecreaseStock(orderItem.Specification, orderItem.Count); } //Increse sale ProductManager.IncreaseSale(orderItem.Specification, orderItem.Count); if (!string.IsNullOrEmpty(orderItem.Specification.Product.MasterQrcode)) { //Send masterQrcode AsyncHelper.RunSync(async() => { string accessToken = await WechatCommonManager.GetAccessTokenAsync(order.TenantId); string openid = WechatUserManager.GetOpenid(order.GetUserIdentifier()); if (!string.IsNullOrEmpty(openid)) { CustomerServiceMessageHelper.SendImage(accessToken, openid, orderItem.Specification.Product.MasterQrcode); } }); } } } }
public async Task <ProductOrder> CreateOrder(ProductBoughtContext boughtContext) { foreach (BoughtItem boughtItem in boughtContext.BoughtItems) { boughtItem.Specification = SpecificationRepository.Get(boughtItem.SpecificationId); boughtItem.ProductId = boughtItem.Specification.ProductId; ProductManager.CheckStock(boughtItem.Specification, boughtItem.Count); if (boughtItem.CartItemId.HasValue) { ShopCartManager.RemoveItem(boughtItem.CartItemId.Value); } DecreaseStockWhen decreaseStockWhen = (DecreaseStockWhen)(Enum.Parse(typeof(DecreaseStockWhen), SettingManager.GetSettingValueForTenant(ShopSettings.General.DecreaseStockWhen, InfrastructureSession.TenantId.Value))); if (decreaseStockWhen == DecreaseStockWhen.Create) { ProductManager.DecreaseStock(boughtItem.Specification, boughtItem.Count); } } ProductOrder order = await Create(boughtContext); return(order); }