/// <summary> /// 删除自动调价设置 /// </summary> /// <param name="searchDto"></param> /// <returns></returns> public Jinher.AMP.BTP.Deploy.CustomDTO.ResultDTO DeleteExt(System.Guid id) { if (id == Guid.Empty) { return(new Jinher.AMP.BTP.Deploy.CustomDTO.ResultDTO { isSuccess = false, Message = "参数错误" }); } ContextSession contextSession = ContextFactory.CurrentThreadContext; var supplierMain = CommodityPriceFloat.FindByID(id); if (supplierMain != null) { supplierMain.IsDel = true; contextSession.SaveObject(supplierMain); } try { contextSession.SaveChanges(); } catch (Exception ex) { LogHelper.Error("CommodityPriceFloatBP.DeleteExt 异常", ex); return(new Jinher.AMP.BTP.Deploy.CustomDTO.ResultDTO { isSuccess = false, Message = ex.Message }); } return(new Jinher.AMP.BTP.Deploy.CustomDTO.ResultDTO { isSuccess = true }); }
/// <summary> /// 获取自动调价设置数据 /// </summary> /// <param name="searchDto"></param> /// <returns></returns> public Jinher.AMP.BTP.Deploy.CustomDTO.ResultDTO <Jinher.AMP.BTP.Deploy.CustomDTO.CommodityPriceFloatList <CommodityPriceFloatListDto> > GetDataListExt(System.Guid appId) { try { var query = CommodityPriceFloat.ObjectSet().Where(_ => !_.IsDel && _.EsAppId == appId); var count = query.Count(); var data = query.OrderByDescending(q => q.SubTime).Select(_ => new CommodityPriceFloatListDto { Id = _.Id, EsAppId = _.EsAppId, AppIds = _.AppIds, FloatPrice = _.FloatPrice }).ToList(); var malls = MallApply.GetTGQuery(appId).Select(_ => new { _.AppId, _.AppName }).ToList(); data.ForEach(_ => { if (!string.IsNullOrEmpty(_.AppIds)) { List <string> appNames = new List <string>(); foreach (var dAppId in _.AppIds.Split(',')) { var mall = malls.Find(m => m.AppId == new Guid(dAppId)); if (mall != null) { appNames.Add(mall.AppName); } } _.AppNames = string.Join("、", appNames); } else { _.AppNames = "未指定店铺"; } }); return(new ResultDTO <CommodityPriceFloatList <CommodityPriceFloatListDto> > { isSuccess = true, Data = new CommodityPriceFloatList <CommodityPriceFloatListDto> { List = data, Count = count } }); } catch (Exception ex) { LogHelper.Error("CommodityPriceFloatBP.GetDataListExt 异常", ex); return(new ResultDTO <CommodityPriceFloatList <CommodityPriceFloatListDto> > { isSuccess = false, Message = ex.Message }); } }
/// <summary> /// 获取商城下所有的app信息 /// </summary> /// <param name="searchDto"></param> /// <returns></returns> public List <Guid> GetAppsExt(Guid appId) { try { var appIds = CommodityPriceFloat.ObjectSet().Where(p => !p.IsDel && p.EsAppId == appId && !string.IsNullOrEmpty(p.AppIds)).Select(_ => _.AppIds).ToList(); return(appIds.SelectMany(_ => _.Split(',')).Distinct().Select(_ => new Guid(_)).ToList()); } catch (Exception ex) { LogHelper.Error("CommodityPriceFloatBP.GetAppsExt 异常", ex); return(new List <Guid>()); } }
/// <summary> /// 获取浮动价格(当进价大于等于售价时售价调整为进价+浮动价格) /// </summary> /// <returns></returns> public static decimal GetFloatPrice() { try { var floatPrice = CommodityPriceFloat.ObjectSet() .Where(p => p.EsAppId == new Guid("8B4D3317-6562-4D51-BEF1-0C05694AC3A6") && !p.IsDel) .OrderByDescending(p => p.ModifiedOn) .Select(p => p.FloatPrice) .FirstOrDefault(); floatPrice = floatPrice > 0 ? floatPrice : new decimal(0.60); return(floatPrice); } catch (Exception ex) { LogHelper.Error(ex.ToString()); } return(new decimal(0.60)); }
/// <summary> /// 添加自动调价设置 /// </summary> /// <param name="searchDto"></param> /// <returns></returns> public Jinher.AMP.BTP.Deploy.CustomDTO.ResultDTO AddExt(Jinher.AMP.BTP.Deploy.CommodityPriceFloatDTO dto) { ContextSession contextSession = ContextFactory.CurrentThreadContext; try { var entity = CommodityPriceFloat.CreateCommodityPriceFloat(); entity.EsAppId = dto.EsAppId; entity.AppIds = dto.AppIds; entity.FloatPrice = dto.FloatPrice; contextSession.SaveObject(entity); contextSession.SaveChanges(); } catch (Exception ex) { LogHelper.Error("CommodityPriceFloatBP.AddExt 异常", ex); return(new Jinher.AMP.BTP.Deploy.CustomDTO.ResultDTO { isSuccess = false, Message = ex.Message }); } return(new Jinher.AMP.BTP.Deploy.CustomDTO.ResultDTO { isSuccess = true }); }
public static void AutoSettingCommodityPrice() { LogHelper.Info("Jobs.AutoSettingCommodityPrice Begin......................................................"); try { ContextSession contextSession = ContextFactory.CurrentThreadContext; var apps = CommodityPriceFloat.ObjectSet().Where(p => !p.IsDel && p.EsAppId == YJB.Deploy.CustomDTO.YJBConsts.YJAppId).ToList(); LogHelper.Info("Begin update price, AppIds:" + JsonHelper.JsonSerializer(apps.Select(_ => _.AppIds))); var appIds = apps.SelectMany(_ => _.AppIds.Split(',')).Select(_ => new Guid(_)); LogHelper.Info("Begin update price, AppGuidIds:" + JsonHelper.JsonSerializer(appIds)); var commodityQuery = Commodity.ObjectSet().Where(_ => appIds.Contains(_.AppId)); var commoditys = commodityQuery.Where(_ => _.CostPrice >= _.Price).ToList(); var commodityIds = commoditys.Select(_ => _.Id).ToList(); var commodityStocks = CommodityStock.ObjectSet().Where(_ => commodityQuery.Any(c => c.Id == _.CommodityId) && _.CostPrice >= _.Price).ToList(); List <Guid> updateCommodityIds = new List <Guid>(); LogHelper.Info("Begin Commodity.........." + commoditys.Count + "............................................"); foreach (var com in commoditys) { LogHelper.Info("Begin update price, CommodityId:" + com.Id + ", AppId:" + com.AppId); var priceFloat = apps.Find(_ => _.AppIds.Split(',').Select(appId => new Guid(appId)).Contains(com.AppId)); if (com.CostPrice >= com.Price) { LogHelper.Info("CostPrice:" + com.CostPrice + ", FloatPrice:" + priceFloat.FloatPrice); com.Price = (com.CostPrice ?? 0) + priceFloat.FloatPrice; com.EntityState = EntityState.Modified; contextSession.SaveObject(com); } // stock var stocks = commodityStocks.Where(_ => _.CommodityId == com.Id).ToList(); foreach (var stock in stocks) { stock.Price = (stock.CostPrice ?? 0) + priceFloat.FloatPrice; stock.EntityState = EntityState.Modified; contextSession.SaveObject(stock); } updateCommodityIds.Add(com.Id); // 保存到商品明细报表 if (updateCommodityIds.Count >= 100) { SaveCommodityChange(updateCommodityIds, contextSession); contextSession.SaveChanges(); updateCommodityIds = new List <Guid>(); } } // 商品表价格没问题,但是SKU表价格有问题的商品 var otherCommodityIds = commodityStocks.Select(_ => _.CommodityId).Distinct().Except(commodityIds).ToList(); var otherCommodities = Commodity.ObjectSet().Where(_ => otherCommodityIds.Contains(_.Id)).ToList(); LogHelper.Info("Begin CommodityStock.........." + otherCommodities.Count + "............................................"); foreach (var com in otherCommodities) { LogHelper.Info("Begin update price, CommodityId:" + com.Id + ", AppId:" + com.AppId); var priceFloat = apps.Find(_ => _.AppIds.Split(',').Select(appId => new Guid(appId)).Contains(com.AppId)); // stock var stocks = commodityStocks.Where(_ => _.CommodityId == com.Id).ToList(); foreach (var stock in stocks) { stock.Price = (stock.CostPrice ?? 0) + priceFloat.FloatPrice; stock.EntityState = EntityState.Modified; contextSession.SaveObject(stock); } updateCommodityIds.Add(com.Id); // 保存到商品明细报表 if (updateCommodityIds.Count >= 100) { SaveCommodityChange(updateCommodityIds, contextSession); contextSession.SaveChanges(); updateCommodityIds = new List <Guid>(); } } SaveCommodityChange(updateCommodityIds, contextSession); contextSession.SaveChanges(); } catch (Exception ex) { LogHelper.Error("Jobs.AutoSettingCommodityPrice 异常", ex); } LogHelper.Info("Jobs.AutoSettingCommodityPrice End......................................................"); }