public void TestShopSaleReadProperly() { //SETUP var options = SqliteInMemory.CreateOptions <CompanyDbContext>(); using (var context = new CompanyDbContext(options, new FakeGetClaimsProvider("accessKey*"))) { context.Database.EnsureCreated(); var company = Company.AddTenantToDatabaseWithSaveChanges("TestCompany", PaidForModules.None, context); var shop = RetailOutlet.AddTenantToDatabaseWithSaveChanges("TestShop", company, context); var shopStock = new ShopStock { Name = "dress", RetailPrice = 12, NumInStock = 2, Shop = shop }; context.Add(shopStock); context.SaveChanges(); //ATTEMPT var status = ShopSale.CreateSellAndUpdateStock(1, shopStock.ShopStockId, context); status.IsValid.ShouldBeTrue(status.GetAllErrors()); context.Add(status.Result); context.SaveChanges(); //VERIFY var salesNotFiltered = context.ShopSales.IgnoreQueryFilters() .Include(x => x.StockItem).ThenInclude(x => x.Shop) .ToList(); salesNotFiltered.Count.ShouldEqual(1); salesNotFiltered.First().StockItem.ShouldNotBeNull(); salesNotFiltered.First().StockItem.Shop.ShouldNotBeNull(); } }
private ShopSale SetSalfInfoByOrderId(ShopSale shopSale, Order order) { // 统计下单会员自身业绩数据 shopSale.TotalOrderCount += 1; // 总订单数加1 shopSale.TotalPaymentAmount += order.PaymentAmount; shopSale.TotalPriceAmount += order.TotalAmount; shopSale.TotalProductCount += order.TotalCount; shopSale.TotalExpressAmount += order.OrderExtension.OrderAmount.ExpressAmount; shopSale.TotalFeeAmount += order.OrderExtension.OrderAmount.FeeAmount; //总服务费 var priceStyleConfigs = Resolve <IAutoConfigService>().GetList <PriceStyleConfig>(r => r.Status == Status.Normal); foreach (var priceStyle in priceStyleConfigs) { var productSkuItems = order.OrderExtension.ProductSkuItems.Where(r => r.PriceStyleId == priceStyle.Id); if (productSkuItems != null && productSkuItems.Count() > 0) { // 所有商城的下单商品 var priceStyleProducts = order.Products.Where(r => productSkuItems.Select(e => e.ProductSkuId).Contains(r.SkuId)); if (priceStyleProducts.Count() <= 0) { continue; } var priceStyleSale = shopSale.PriceStyleSales.FirstOrDefault(r => r.PriceStyleId == priceStyle.Id); if (priceStyleSale == null) { priceStyleSale = new PriceStyleSale { PriceStyleId = priceStyle.Id }; shopSale.PriceStyleSales.Add(priceStyleSale); } shopSale.PriceStyleSales.Foreach(e => { if (e.PriceStyleId == priceStyle.Id) { e.PriceStyleName = priceStyle.Name; e.OrderCount += 1; // 订单数加1 e.ProductCount += priceStyleProducts.Sum(r => r.Count); // 商品总数 e.PriceAmount += priceStyleProducts.Sum(r => r.TotalAmount); // 价格统计 e.FenRunAmount += priceStyleProducts.Sum(r => r.FenRunAmount); // 分润统计 e.PaymentAmount += priceStyleProducts.Sum(r => r.PaymentAmount); // 支付金额统计 e.FeeAmount += priceStyleProducts.Sum(r => r.OrderProductExtension.OrderAmount.FeeAmount); //服务费统计 shopSale.TotalFenRunAmount += priceStyleProducts.Sum(r => r.FenRunAmount); // 分润费用 } }); } } return(shopSale); }
/// <summary> /// 新增数据,并返回自增ID /// </summary> /// <param name="model">实体类</param> /// <returns></returns> public int InsertIdentity(ShopSale model) { return(CreateDao().InsertIdentity(model)); }
/// <summary> /// 更新数据 /// </summary> /// <param name="model">实体类</param> /// <param name="whereString">可选,更新条件</param> /// <returns></returns> public bool Update(ShopSale model, string whereString = null) { return(CreateDao().Update(model, whereString)); }
/// <summary> /// 新增数据 /// </summary> /// <param name="model">实体类</param> /// <returns></returns> public bool Insert(ShopSale model) { return(CreateDao().Insert(model)); }