public CashDepositsObligation GetCashDepositsObligation(long productId) { CashDepositsObligation cashDepositsObligation = new CashDepositsObligation() { IsCustomerSecurity = false, IsSevenDayNoReasonReturn = false, IsTimelyShip = false }; var productService = ServiceProvider.Instance <IProductService> .Create; var shopService = ServiceProvider.Instance <IShopService> .Create; var shopCategoryService = ServiceProvider.Instance <IShopCategoryService> .Create; var categoryService = ServiceProvider.Instance <ICategoryService> .Create; var product = productService.GetProduct(productId); var shop = shopService.GetShop(product.ShopId); //var cashDeposit = Context.CashDepositInfo.Where(item => item.ShopId == shop.Id).FirstOrDefault(); var cashDeposit = DbFactory.Default.Get <CashDepositInfo>().Where(item => item.ShopId == shop.Id).FirstOrDefault(); var categories = shopCategoryService.GetBusinessCategory(shop.Id).ToList(); var mainCategories = categories.Where(item => item.ParentCategoryId == 0).Select(item => item.Id).ToList(); //var cateCashDeposit = Context.CategoryCashDepositInfo.FindBy(item => mainCategories.Contains(item.CategoryId)).ToList(); var cateCashDeposit = DbFactory.Default.Get <CategoryCashDepositInfo>().Where(item => item.CategoryId.ExIn(mainCategories)).ToList(); if (cateCashDeposit.Count == 0) { return(cashDepositsObligation); } var needCashDeposit = cateCashDeposit.Max(item => item.NeedPayCashDeposit); //平台自营,商家缴纳足够保证金或者平台未取消其资质资格 if (shop.IsSelf || (cashDeposit != null && cashDeposit.CurrentBalance >= needCashDeposit) || (cashDeposit != null && cashDeposit.CurrentBalance < needCashDeposit && cashDeposit.EnableLabels == true)) { List <long> categoryIds = new List <long>(); categoryIds.Add(product.CategoryId); var mainCategory = categoryService.GetTopLevelCategories(categoryIds).FirstOrDefault(); if (mainCategory != null) { //var categoryCashDepositInfo = Context.CategoryCashDepositInfo.Where(item => item.CategoryId == mainCategory.Id).FirstOrDefault(); var categoryCashDepositInfo = DbFactory.Default.Get <CategoryCashDepositInfo>().Where(item => item.CategoryId == mainCategory.Id).FirstOrDefault(); if (categoryCashDepositInfo != null) { cashDepositsObligation.IsSevenDayNoReasonReturn = (bool)categoryCashDepositInfo.EnableNoReasonReturn; } } cashDepositsObligation.IsCustomerSecurity = true; var template = DbFactory.Default.Get <FreightTemplateInfo>(p => p.Id == product.FreightTemplateId).FirstOrDefault(); //设置了运费模板 if (template != null) { if (!string.IsNullOrEmpty(template.SendTime)) { cashDepositsObligation.IsTimelyShip = true; } } } return(cashDepositsObligation); }
public CashDepositsObligation GetCashDepositsObligation(long productId) { CashDepositsObligation cashDepositsObligation = new CashDepositsObligation() { IsCustomerSecurity = false, IsSevenDayNoReasonReturn = false, IsTimelyShip = false }; CashDepositsObligation enableNoReasonReturn = cashDepositsObligation; IProductService create = Instance <IProductService> .Create; IShopService shopService = Instance <IShopService> .Create; IShopCategoryService shopCategoryService = Instance <IShopCategoryService> .Create; ICategoryService categoryService = Instance <ICategoryService> .Create; ProductInfo product = create.GetProduct(productId); ShopInfo shop = shopService.GetShop(product.ShopId, false); CashDepositInfo cashDepositInfo = ( from item in context.CashDepositInfo where item.ShopId == shop.Id select item).FirstOrDefault(); List <CategoryInfo> list = shopCategoryService.GetBusinessCategory(shop.Id).ToList(); IEnumerable <long> parentCategoryId = from item in list where item.ParentCategoryId == 0 select item.Id; //decimal num = context.CategoryCashDepositInfo.FindBy((CategoryCashDepositInfo item) => parentCategoryId.Contains(item.CategoryId)).Max<CategoryCashDepositInfo, decimal>((CategoryCashDepositInfo item) => item.NeedPayCashDeposit); decimal num = 1; if (shop.IsSelf || cashDepositInfo != null && cashDepositInfo.CurrentBalance >= num || cashDepositInfo != null && cashDepositInfo.CurrentBalance < num && cashDepositInfo.EnableLabels) { List <long> nums = new List <long>() { product.CategoryId }; CategoryInfo categoryInfo = categoryService.GetTopLevelCategories(nums).FirstOrDefault(); CategoryCashDepositInfo categoryCashDepositInfo = ( from item in context.CategoryCashDepositInfo where item.CategoryId == categoryInfo.Id select item).FirstOrDefault(); enableNoReasonReturn.IsSevenDayNoReasonReturn = categoryCashDepositInfo.EnableNoReasonReturn; enableNoReasonReturn.IsCustomerSecurity = true; if (!string.IsNullOrEmpty(product.ChemCloud_FreightTemplate.SendTime)) { enableNoReasonReturn.IsTimelyShip = true; } } return(enableNoReasonReturn); }