public void AccountSyncing(int userId) { using (var db = new YintaiHangzhouContext("YintaiHangzhouContext")) { var offlineAccount = db.UserAccounts.Where(ua => ua.AccountType == (int)AccountType.OfflineCoupon && ua.User_Id == userId && ua.Status != (int)DataStatus.Deleted).FirstOrDefault(); var account = db.UserAccounts.Where(ua => ua.AccountType == (int)AccountType.Coupon && ua.User_Id == userId && ua.Status != (int)DataStatus.Deleted).FirstOrDefault(); var sumCoupons = db.CouponHistories.Where(p => p.User_Id == userId && p.Status != (int)DataStatus.Deleted && p.ValidEndDate >= DateTime.Now && p.Status != (int)CouponStatus.Used).Count(); var sumStoreCoupons = db.StoreCoupons.Where(p => p.UserId == userId && p.Status != (int)DataStatus.Deleted && p.ValidEndDate >= DateTime.Now && p.Status != (int)CouponStatus.Used).Count(); if (offlineAccount != null) { offlineAccount.Amount = sumStoreCoupons; offlineAccount.UpdatedDate = DateTime.Now; db.Entry(offlineAccount).State = System.Data.EntityState.Modified; } else { db.UserAccounts.Add(new UserAccountEntity() { AccountType = (int)AccountType.OfflineCoupon, Amount = sumStoreCoupons, User_Id = userId, Status = (int)DataStatus.Normal, CreatedDate = DateTime.Now, CreatedUser = userId, UpdatedDate = DateTime.Now, UpdatedUser = userId }); } if (account != null) { account.Amount = sumCoupons + sumStoreCoupons; account.UpdatedDate = DateTime.Now; db.Entry(account).State = System.Data.EntityState.Modified; } else { db.UserAccounts.Add(new UserAccountEntity() { AccountType = (int)AccountType.Coupon, Amount = sumCoupons + sumStoreCoupons, User_Id = userId, Status = (int)DataStatus.Normal, CreatedDate = DateTime.Now, CreatedUser = userId, UpdatedDate = DateTime.Now, UpdatedUser = userId }); } db.SaveChanges(); } }
public void AccountSyncing(int userId) { using (var db = new YintaiHangzhouContext("YintaiHangzhouContext")) { var account = db.UserAccounts.Where(ua => ua.AccountType == (int)AccountType.FavorCount && ua.User_Id == userId && ua.Status != (int)DataStatus.Deleted).FirstOrDefault(); var favorites = db.Favorites.Where(p => p.User_Id == userId && p.Status != (int)DataStatus.Deleted).Count(); if (account != null) { account.Amount = favorites; account.UpdatedDate = DateTime.Now; db.Entry(account).State = System.Data.EntityState.Modified; db.SaveChanges(); } else { db.UserAccounts.Add(new UserAccountEntity() { AccountType = (int)AccountType.FavorCount, Amount = favorites, User_Id = userId, Status = (int)DataStatus.Normal, CreatedDate = DateTime.Now, CreatedUser = userId, UpdatedDate = DateTime.Now, UpdatedUser = userId }); } } }
private void updateILike(YintaiHangzhouContext db, int accountId) { var account = db.UserAccounts.Where(ua => ua.AccountType == (int)AccountType.IlikeCount && ua.User_Id == accountId && ua.Status != (int)DataStatus.Deleted).FirstOrDefault(); var likes = db.Likes.Where(p => p.LikeUserId == accountId && p.Status != (int)DataStatus.Deleted).Count(); if (account != null) { account.Amount = likes; account.UpdatedDate = DateTime.Now; db.Entry(account).State = System.Data.EntityState.Modified; db.SaveChanges(); } else { db.UserAccounts.Add(new UserAccountEntity() { AccountType = (int)AccountType.IlikeCount, Amount = likes, User_Id = accountId, Status = (int)DataStatus.Normal, CreatedDate = DateTime.Now, CreatedUser = accountId, UpdatedDate = DateTime.Now, UpdatedUser = accountId }); } }
public void AccountSyncing(int userId) { using (var db = new YintaiHangzhouContext("YintaiHangzhouContext")) { var account = db.UserAccounts.Where(ua => ua.AccountType == (int)AccountType.FavorCount && ua.User_Id == userId && ua.Status != (int)DataStatus.Deleted).FirstOrDefault(); var favorites = db.Favorites.Where(p => p.User_Id == userId && p.Status != (int)DataStatus.Deleted ).Count(); if (account != null) { account.Amount = favorites; account.UpdatedDate = DateTime.Now; db.Entry(account).State = System.Data.EntityState.Modified; } else { db.UserAccounts.Add(new UserAccountEntity() { AccountType = (int)AccountType.FavorCount, Amount = favorites, User_Id = userId, Status = (int)DataStatus.Normal, CreatedDate = DateTime.Now, CreatedUser = userId, UpdatedDate = DateTime.Now, UpdatedUser = userId }); } db.SaveChanges(); } }
public void Execute(IJobExecutionContext context) { ILog log = LogManager.GetLogger(this.GetType()); JobDataMap data = context.JobDetail.JobDataMap; var benchDate = data.ContainsKey("benchdate")?data.GetDateTime("benchdate"):DateTime.Today.AddDays(-1); int successCount = 0; int cursor = 0; int size = JobConfig.DEFAULT_PAGE_SIZE; Stopwatch sw = new Stopwatch(); sw.Start(); using (var db = new YintaiHangzhouContext("YintaiHangzhouContext")) { var prods = from r in db.UserAccounts where r.AccountType == (int)AccountType.Point && (from p in db.PointHistories where (p.CreatedDate>=benchDate || p.UpdatedDate>=benchDate) && p.User_Id == r.User_Id select p).Any() select r; int totalCount = prods.Count(); while (cursor < totalCount) { var linq = prods.OrderByDescending(p => p.Id).Skip(cursor).Take(size).ToList(); foreach (var l in linq) { var sumPoints = db.PointHistories.Where(p => p.User_Id == l.User_Id && p.Status != (int)DataStatus.Deleted).Sum(p => p.Amount); if (sumPoints == l.Amount) continue; l.Amount = sumPoints > 0 ? sumPoints : 0; l.UpdatedDate = DateTime.Now; db.Entry(l).State = System.Data.EntityState.Modified; db.SaveChanges(); successCount++; } cursor += size; } } sw.Stop(); log.Info(string.Format("{0} accounts in {1} => {2} docs/s", successCount, sw.Elapsed, successCount / sw.Elapsed.TotalSeconds)); }
protected override void QueueNotification(PushBroker push,IJobExecutionContext context) { ILog log = LogManager.GetLogger(typeof(ApnsNotificationCommonJob)); JobDataMap data = context.JobDetail.JobDataMap; var interval = data.GetIntValue("intervalofsec"); int cursor = 0; int size = JobConfig.DEFAULT_PAGE_SIZE; int successCount = 0; var benchDate = DateTime.Now.AddSeconds(-interval); Stopwatch sw = new Stopwatch(); sw.Start(); using (var db = new YintaiHangzhouContext("YintaiHangzhouContext")) { var prods = (from p in db.NotificationLogs where p.CreateDate>= benchDate && p.Status==(int)NotificationStatus.Default select p); if (prods != null) { int totalCount = prods.Count(); while (cursor < totalCount) { var linq = prods.OrderByDescending(p => p.Id).Skip(cursor).Take(size).ToList(); foreach (var l in linq) { try { if (l.SourceType.Value == (int)SourceType.PMessage) { var device = db.PMessages.Where(p => p.Id == l.SourceId) .Join(db.DeviceLogs, o => o.ToUser, i => i.User_Id, (o, i) => new { D = i,U=o }).FirstOrDefault(); if (device==null) continue; push.QueueNotification(new AppleNotification() .ForDeviceToken(device.D.DeviceToken) .WithAlert("新私信...") .WithBadge(1) .WithCustomItem("from", JsonConvert.SerializeObject(new { targettype = (int)PushSourceType.PMessage, targetvalue =device.U.FromUser})) .WithSound("sound.caf")); successCount++; l.NotifyDate = DateTime.Now; l.Status = (int)NotificationStatus.Notified; db.Entry(l).State = System.Data.EntityState.Modified; db.SaveChanges(); } else if (l.SourceType.Value == (int)SourceType.Comment) { // if it's comment, always notify all comments owners of this item var comment = db.Comments.Find(l.SourceId); if (comment == null) continue; var relatedComments = db.Comments.Where(c => c.SourceType == comment.SourceType && c.SourceId == comment.SourceId && c.User_Id != comment.User_Id) .Join(db.DeviceLogs.Where(d => d.User_Id > 0), o => o.User_Id, i => i.User_Id, (o, i) => new { Token = i.DeviceToken }).ToList(); if (comment.SourceType == (int)SourceType.Product) { var product = db.Products.Where(p => p.Id == comment.SourceId && p.RecommendUser != comment.User_Id) .Join(db.DeviceLogs.Where(d => d.User_Id > 0), o => o.CreatedUser, i => i.User_Id, (o, i) => new { Token = i.DeviceToken }).FirstOrDefault(); if (product != null) relatedComments.Add(new { Token = product.Token }); } else if (comment.SourceType == (int)SourceType.Promotion) { var promotion = db.Promotions.Where(p => p.Id == comment.SourceId && p.RecommendUser != comment.User_Id) .Join(db.DeviceLogs.Where(d => d.User_Id > 0), o => o.CreatedUser, i => i.User_Id, (o, i) => new { Token = i.DeviceToken }).FirstOrDefault(); if (promotion != null) relatedComments.Add(new { Token = promotion.Token }); } foreach (var device in relatedComments.Distinct()) { push.QueueNotification(new AppleNotification() .ForDeviceToken(device.Token) .WithAlert("新评论...") .WithBadge(1) .WithCustomItem("from", JsonConvert.SerializeObject(new { targettype = (int)PushSourceType.SelfComment, targetvalue = comment.SourceId })) .WithSound("sound.caf")); successCount++; } l.NotifyDate = DateTime.Now; l.Status = (int)NotificationStatus.Notified; db.Entry(l).State = System.Data.EntityState.Modified; db.SaveChanges(); } } catch (Exception ex) { log.Info(ex); } } cursor += size; } } } sw.Stop(); log.Info(string.Format("{0} notifications in {1} => {2} notis/s", successCount, sw.Elapsed, successCount / sw.Elapsed.TotalSeconds)); }
public void Execute(IJobExecutionContext context) { ILog log = LogManager.GetLogger(this.GetType()); JobDataMap data = context.JobDetail.JobDataMap; var interval = data.ContainsKey("interval") ? data.GetIntValue("interval") : 24 * 60; var benchDate = DateTime.Now.AddMinutes(-interval); var host = data.GetString("awshost"); var public_key = data.GetString("publickey"); var private_key = data.GetString("privatekey"); dynamic jsonResponse = null; AwsHelper.SendHttpMessage(host, new { benchdate = benchDate.ToUniversalTime() },public_key,private_key,r=>jsonResponse = r,null); if (jsonResponse == null ) { log.Info("request error!" ); return; } int successCount = 0; Stopwatch sw = new Stopwatch(); sw.Start(); using (var db = new YintaiHangzhouContext("YintaiHangzhouContext")) { foreach (var dynamicObject in jsonResponse.data) { try { string code = dynamicObject.code; int? status = dynamicObject.status; DateTime opeDate = dynamicObject.created_at; CouponStatus targetStatus = CouponStatus.Used; CouponActionType targetActionType = CouponActionType.Consume; if (status.HasValue && status.Value == -1) { targetStatus = CouponStatus.Normal; targetActionType = CouponActionType.Rebate; } switch ((int)dynamicObject.coupontype) { case 1: var coupon = db.StoreCoupons.Where(s => s.Code == code && s.Status != (int)CouponStatus.Deleted).FirstOrDefault(); if (coupon != null) { coupon.Status = (int)targetStatus; coupon.UpdateDate = opeDate.ToLocalTime(); coupon.UpdateUser = 0; db.Entry(coupon).State = EntityState.Modified; db.CouponLogs.Add(new CouponLogEntity() { ActionType = (int)targetActionType, BrandNo = dynamicObject.brandno, Code = code, ConsumeStoreNo = dynamicObject.storeno, CreateDate = opeDate.ToLocalTime(), CreateUser = 0, ReceiptNo = dynamicObject.receiptno, Type = 1 }); db.SaveChanges(); successCount++; } break; case 2: var coupon2 = db.CouponHistories.Where(s => s.CouponId == code && s.Status != (int)CouponStatus.Deleted).FirstOrDefault(); if (coupon2 != null) { coupon2.Status = (int)targetStatus; db.Entry(coupon2).State = EntityState.Modified; db.CouponLogs.Add(new CouponLogEntity() { ActionType = (int)targetActionType, BrandNo = dynamicObject.brandno, Code = code, ConsumeStoreNo = dynamicObject.storeno, CreateDate = opeDate.ToLocalTime(), CreateUser = 0, ReceiptNo = dynamicObject.receiptno, Type = 2 }); db.SaveChanges(); successCount++; } break; } } catch (Exception ex) { log.Error(ex); } } } sw.Stop(); log.Info(string.Format("{0} status logs in {1} => {2} docs/s", successCount, sw.Elapsed, successCount / sw.Elapsed.TotalSeconds)); }
public static void SyncOne(SALE_CODE section) { EnsureSectionContext(section); using (var db = new YintaiHangzhouContext("YintaiHangzhouContext")) { var sectionId = section.SID; var existBrand = db.Set<SectionEntity>().Where(b => b.ChannelSectionId == sectionId).FirstOrDefault(); var storeEntity = db.Set<StoreEntity>().Where(s => s.ExStoreId == section.SHOP_SID).FirstOrDefault(); if (existBrand == null) { db.Sections.Add(new SectionEntity() { ChannelSectionId = (int)section.SID, CreateDate = DateTime.Now, CreateUser = 0, Location = section.ADDRESS ?? string.Empty, Name = section.SALE_CODE_NAME ?? string.Empty, ContactPhone = string.Empty, StoreId = storeEntity.Id, Status = (int)DataStatus.Normal, UpdateDate = DateTime.Now, UpdateUser = 0 }); } else { existBrand.Name = section.SALE_CODE_NAME ?? string.Empty; existBrand.UpdateDate = section.OPT_UPDATE_TIME ?? DateTime.Now; existBrand.Location = section.ADDRESS ?? string.Empty; existBrand.StoreId = storeEntity.Id; db.Entry(existBrand).State = System.Data.EntityState.Modified; } db.SaveChanges(); } }
public void Execute(IJobExecutionContext context) { ILog log = LogManager.GetLogger(this.GetType()); JobDataMap data = context.JobDetail.JobDataMap; var totalCount = 0; var interval = data.ContainsKey("intervalOfHrs") ? data.GetInt("intervalOfHrs") : 1; if (!data.ContainsKey("benchtime")) { data.Put("benchtime", DateTime.Now.AddHours(-interval)); } else { data["benchtime"] = data.GetDateTimeValue("benchtime").AddHours(interval); } var benchTime = data.GetDateTime("benchtime"); Query(benchTime, orders => totalCount = orders.Count()); int cursor = 0; int successCount = 0; int size = JobConfig.DEFAULT_PAGE_SIZE; int lastCursor = 0; Stopwatch sw = new Stopwatch(); sw.Start(); while (cursor < totalCount) { List<OrderEntity> oneTimeList = null; Query(benchTime, orders => { oneTimeList = orders.Where(a => a.Id > lastCursor).OrderBy(a => a.Id).Take(size).ToList(); }); foreach (var order in oneTimeList) { try { using (var db = new YintaiHangzhouContext("YintaiHangzhouContext")) { order.Status = (int)OrderStatus.Void; order.UpdateDate = DateTime.Now; db.Entry(order).State = System.Data.EntityState.Modified; db.OrderLogs.Add(new OrderLogEntity() { CreateDate = DateTime.Now, CreateUser = 0, CustomerId = order.CreateUser, Operation="过期未支付,自动取消", OrderNo = order.OrderNo, Type=(int)OrderOpera.SystemVoid }); db.SaveChanges(); successCount++; } } catch (Exception ex) { log.Info(ex); } } cursor += size; if (oneTimeList != null && oneTimeList.Count > 0) lastCursor = oneTimeList.Max(o => o.Id); } sw.Stop(); log.Info(string.Format("total voiding orders:{0},{1} voided orders in {2} => {3} docs/s", totalCount, successCount, sw.Elapsed, successCount / sw.Elapsed.TotalSeconds)); }
public static bool SyncOne(PRO_PICTURE product) { if (!EnsureProductContext(product)) return false; var log = Log; //download remote picture string exPicDomain = ConfigurationManager.AppSettings["EXPIC_DOMAIN"]; var filePath = FetchRemotePic(string.Format("{0}/{1}",exPicDomain.TrimEnd('/'),Path.Combine(product.PRO_PICT_DIR,product.PRO_PICT_NAME))); //resize pics var file = new FileInfo(filePath); FileInfor uploadFile; var uploadResult = FileUploadServiceManager.UploadFile(file, "product", out uploadFile, string.Empty); if (uploadResult != FileMessage.Success) { log.Error(string.Format("upload file error:{0}", filePath)); File.Delete(filePath); return false; } using (var db = new YintaiHangzhouContext("YintaiHangzhouContext")) { var existPic = db.Set<ResourceEntity>().Where(r => r.ChannelPicId == product.SID).FirstOrDefault(); if (existPic == null) { var colorEntity = db.Set<ProductPropertyValueEntity>().Where(ppv => ppv.ChannelValueId == product.PRO_COLOR_SID) .Join(db.Set<ProductPropertyEntity>().Join(db.Set<ProductMapEntity>().Where(pm => pm.ChannelPId == product.PRODUCT_SID), o => o.ProductId, i => i.ProductId, (o, i) => o), o => o.PropertyId, i => i.Id, (o, i) => o).FirstOrDefault(); var existProduct = db.Set<ProductEntity>().Join(db.Set<ProductMapEntity>().Where(ep => ep.ChannelPId == product.PRODUCT_SID), o => o.Id, i => i.ProductId, (o, i) => o).FirstOrDefault(); db.Resources.Add(new ResourceEntity() { ColorId = colorEntity == null ? 0 : colorEntity.Id, SourceId = existProduct.Id, SourceType = (int)SourceType.Product, ContentSize = uploadFile.FileSize, CreatedDate = DateTime.Now, CreatedUser = 0, Domain = string.Empty, ExtName = uploadFile.FileExtName, Height = uploadFile.Height, IsDefault = product.PICTURE_MAST_BIT == 1 ? true : false, UpdatedDate = DateTime.Now, Name = uploadFile.FileName, Status = (product.DELETE_BIT??0)==0?(int)DataStatus.Normal:(int)DataStatus.Deleted, SortOrder = product.PICTURE_MAST_BIT ==1 ?100:(100 - (int)product.PRO_PICT_ORDER), Size = string.Format("{0}x{1}", uploadFile.Width, uploadFile.Height), Type = (int)uploadFile.ResourceType, Width = uploadFile.Width, ChannelPicId = (int)product.SID }); existProduct.IsHasImage = true; existProduct.UpdatedDate = DateTime.Now; db.Entry(existProduct).State = System.Data.EntityState.Modified; db.SaveChanges(); } else { if (product.DELETE_BIT.HasValue && product.DELETE_BIT.Value == 1) { existPic.Status = (int)DataStatus.Deleted; existPic.SortOrder = product.PICTURE_MAST_BIT == 1 ? 100 : (100 - (int)product.PRO_PICT_ORDER); existPic.UpdatedDate = DateTime.Now; db.Entry(existPic).State = System.Data.EntityState.Modified; db.SaveChanges(); } } } File.Delete(filePath); return true; }
public static void SyncOne(BRAND brand) { using (var db = new YintaiHangzhouContext("YintaiHangzhouContext")) { var existBrand = db.Set<BrandEntity>().Where(b => b.ChannelBrandId == brand.SID).FirstOrDefault(); if (existBrand == null) { db.Brands.Add(new BrandEntity() { ChannelBrandId = (int)brand.SID, CreatedDate = DateTime.Now, CreatedUser = 0, Name = brand.BRAND_NAME, EnglishName = brand.BRAND_NAME_SECOND, Logo = brand.PICTURE_URL??string.Empty, Status = brand.BRAND_ACTIVE_BIT, UpdatedDate = brand.OPT_UPDATE_TIME ?? DateTime.Now, UpdatedUser = 0, Description = brand.BRAND_STORY??string.Empty, Group = (brand.BRAND_GROUP_NUM??0).ToString(), WebSite = string.Empty }); } else { existBrand.Name = brand.BRAND_NAME; existBrand.EnglishName = brand.BRAND_NAME_SECOND; existBrand.Logo = brand.PICTURE_URL??string.Empty;; existBrand.Status = brand.BRAND_ACTIVE_BIT; existBrand.UpdatedUser = 0; existBrand.UpdatedDate = brand.OPT_UPDATE_TIME ?? DateTime.Now; existBrand.Description = brand.BRAND_STORY??string.Empty; existBrand.Group = (brand.BRAND_GROUP_NUM ?? 0).ToString(); db.Entry(existBrand).State = System.Data.EntityState.Modified; } db.SaveChanges(); } }
public static bool SyncOne(SUPPLY_MIN_PRICE product) { EnsureProductContext(product); if (!product.SHOP_SID.HasValue) return false; bool shouldSyncPic = false; using (var ts = new TransactionScope()) { using (var db = new YintaiHangzhouContext("YintaiHangzhouContext")) { var existProduct = db.Set<ProductMapEntity>().Where(b => b.ChannelPId == product.PRODUCT_SID).FirstOrDefault(); var tagEntity = db.Set<TagEntity>().Join(db.Set<CategoryMapEntity>().Where(cm => cm.ChannelCatId == product.PRO_CLASS_SID), o => o.Id, i => i.CatId, (o, i) => o) .FirstOrDefault(); var storeEntity = db.Set<StoreEntity>().Where(s => s.ExStoreId == product.SHOP_SID).FirstOrDefault(); if (storeEntity == null) { Log.Error(string.Format("product sid has no store:{0}", product.PRODUCT_SID)); return false; } var brandEntity = db.Set<BrandEntity>().Where(b => b.ChannelBrandId == product.BRAND_SID).FirstOrDefault(); if (brandEntity == null) { Log.Error(string.Format("product sid has no brand:{0}", product.PRODUCT_SID)); return false; } if (existProduct == null) { var newProduct = new ProductEntity() { CreatedDate = DateTime.Now, CreatedUser = DEFAULT_OWNER_ID, SkuCode = product.PRO_SKU, Brand_Id = brandEntity == null ? 0 : brandEntity.Id, Description = product.PRO_DESC ?? string.Empty, Is4Sale = false, Name = string.IsNullOrEmpty(product.PRODUCT_NAME)? string.Format("{0}-{1}", brandEntity.Name, product.PRO_SKU):product.PRODUCT_NAME, UnitPrice = product.ORIGINAL_PRICE ?? NULL_PRICE, RecommendedReason = product.PRO_DESC ?? string.Empty, RecommendUser = DEFAULT_OWNER_ID, SortOrder = 0, Status = ((product.PRO_SELLING??0)==1)?(int)DataStatus.Normal:(int)DataStatus.Default, Store_Id = storeEntity == null ? 0 : storeEntity.Id, Tag_Id = tagEntity == null ? int.Parse(DEFAULT_TAG_ID) : tagEntity.Id, Price = product.PROMOTION_PRICE ?? NULL_PRICE, UpdatedDate = DateTime.Now, UpdatedUser = DEFAULT_OWNER_ID, BarCode = product.BARCODE, Favorable = "1" }; db.Products.Add(newProduct); db.SaveChanges(); db.ProductMaps.Add(new ProductMapEntity() { Channel = "ERP", ChannelBrandId = (int)product.BRAND_SID, ChannelPId = (int)product.PRODUCT_SID, ChannelCatId = (int)(product.PRO_CLASS_SID??0m), ProductId = newProduct.Id, UpdateDate = DateTime.Now }); shouldSyncPic = true; } else { var existProductEntity = db.Set<ProductEntity>().Find(existProduct.ProductId); existProductEntity.BarCode = product.BARCODE; existProductEntity.UpdatedDate = DateTime.Now; existProductEntity.Store_Id = storeEntity == null ? 0 : storeEntity.Id; existProductEntity.Brand_Id = brandEntity == null ? 0 : brandEntity.Id; existProductEntity.Tag_Id = tagEntity == null ? int.Parse(DEFAULT_TAG_ID) : tagEntity.Id; existProductEntity.SkuCode = product.PRO_SKU; existProductEntity.Name = string.IsNullOrEmpty(product.PRODUCT_NAME) ? string.Format("{0}-{1}", brandEntity.Name, product.PRO_SKU) : product.PRODUCT_NAME; existProductEntity.UnitPrice = product.ORIGINAL_PRICE ?? NULL_PRICE; existProductEntity.Price = product.PROMOTION_PRICE ?? NULL_PRICE; existProductEntity.Description = product.PRO_DESC ?? string.Empty; existProductEntity.RecommendedReason = product.PRO_DESC ?? string.Empty; existProductEntity.Status = ((product.PRO_SELLING ?? 0) == 1) ? (int)DataStatus.Normal : (int)DataStatus.Default; if ((product.PRO_SELLING ?? 0) != 1) existProductEntity.Is4Sale = false; db.Entry(existProductEntity).State = System.Data.EntityState.Modified; } db.SaveChanges(); } ts.Complete(); } if (shouldSyncPic) { syncRelatedPics(product); } return true; }
public static void SyncOne(PRO_CLASS_DICT cat) { using (var db = new YintaiHangzhouContext("YintaiHangzhouContext")) { var existCat = db.Set<CategoryEntity>().Where(b => b.ExCatId == cat.SID).FirstOrDefault(); if (existCat == null) { db.Categories.Add(new CategoryEntity() { ExCatCode = cat.PRO_CLASS_NUM, ExCatId = (int)cat.SID, Name = cat.PRO_CLASS_DESC, Status = 1, UpdateDate = cat.OPT_UPDATE_TIME ?? DateTime.Now }); } else { existCat.ExCatCode = cat.PRO_CLASS_NUM; existCat.Name = cat.PRO_CLASS_DESC; existCat.UpdateDate = cat.OPT_UPDATE_TIME ?? DateTime.Now; db.Entry(existCat).State = System.Data.EntityState.Modified; } db.SaveChanges(); } }
public static void SyncOne(SUPPLY_MIN_PRICE_MX product) { if (!EnsureProductContext(product)) return; using (var ts = new TransactionScope()) { using (var db = new YintaiHangzhouContext("YintaiHangzhouContext")) { var existProduct = db.Set<ProductEntity>().Join(db.Set<ProductMapEntity>().Where(ep => ep.ChannelPId == product.PRODUCT_SID), o => o.Id, i => i.ProductId, (o, i) => o).FirstOrDefault(); var color = db.Set<ProductPropertyValueEntity>().Where(b => b.ChannelValueId == product.PRO_COLOR_SID) .Join(db.Set<ProductPropertyEntity>().Where(pp => pp.ProductId == existProduct.Id), o => o.PropertyId, i => i.Id, (o, i) => o).FirstOrDefault(); var size = db.Set<ProductPropertyValueEntity>().Where(b => b.ChannelValueId == product.PRO_STAN_SID) .Join(db.Set<ProductPropertyEntity>().Where(pp => pp.ProductId == existProduct.Id), o => o.PropertyId, i => i.Id, (o, i) => o).FirstOrDefault(); var inventory = db.Set<InventoryEntity>().Where(i => i.ChannelInventoryId == product.PRO_DETAIL_SID).FirstOrDefault(); int amount = (int)product.PRO_STOCK_SUM; bool no4sale = product.PRO_ACTIVE_BIT.GetValueOrDefault()==0; if (no4sale) amount = 0; if (inventory == null) { db.Inventories.Add(new InventoryEntity() { ProductId = existProduct.Id, PColorId = color.Id, PSizeId = size.Id, UpdateDate = DateTime.Now, UpdateUser = 0, Amount = amount, ChannelInventoryId = (int)product.PRO_DETAIL_SID }); } else { inventory.Amount = amount; inventory.UpdateDate = DateTime.Now; db.Entry(inventory).State = System.Data.EntityState.Modified; } //update product.is4sale if ((existProduct.Is4Sale ?? false) == false && !no4sale) { existProduct.Is4Sale = true; existProduct.UpdatedDate = DateTime.Now; db.Entry(existProduct).State = System.Data.EntityState.Modified; } db.SaveChanges(); } ts.Complete(); } }
public static void SyncOne(SHOP_INFO store) { using (var db = new YintaiHangzhouContext("YintaiHangzhouContext")) { var existStore = db.Set<StoreEntity>().Where(b => b.ExStoreId == store.SID).FirstOrDefault(); if (existStore == null) { db.Stores.Add(new StoreEntity() { CreatedDate = DateTime.Now, CreatedUser = 0, ExStoreId = (int)store.SID, Description = string.Empty, Location = store.SHOP_ADDR??string.Empty, Name = store.SHOP_NAME, RMAAddress = store.SHOP_ADDR, RMAPerson = store.REFUND_LINKER, RMAPhone = store.REFUND_TEL, RMAZipCode = store.POSTCODE.HasValue?store.POSTCODE.ToString():string.Empty, UpdatedDate = store.OPT_UPDATE_TIME ?? DateTime.Now, UpdatedUser = 0, Status = 1, Tel = store.LINKER_PHONE??string.Empty }); } else { existStore.RMAZipCode = store.POSTCODE.HasValue ? store.POSTCODE.ToString() : string.Empty; existStore.RMAPhone = store.REFUND_TEL; existStore.RMAAddress = store.SHOP_ADDR; existStore.RMAPerson = store.REFUND_LINKER; existStore.UpdatedDate = store.OPT_UPDATE_TIME ?? DateTime.Now; existStore.Location = store.SHOP_ADDR??string.Empty; existStore.Tel = store.LINKER_PHONE ?? string.Empty; existStore.Name = store.SHOP_NAME; db.Entry(existStore).State = System.Data.EntityState.Modified; } db.SaveChanges(); } }
public static bool OrderPaid2Erp(OrderTransactionEntity order,bool isOnlinePay = true) { string vipCard = string.Empty; var log = ServiceLocator.Current.Resolve<ILog>(); if (order.OutsiteType.HasValue && order.OutsiteType.Value == (int)OutsiteType.WX && !string.IsNullOrEmpty(order.OutsiteUId)) { try { AwsHelper.SendHttpMessage(string.Format("{0}card/find", ConfigManager.AwsHost), new { uid = order.OutsiteUId }, ConfigManager.AwsHttpPublicKey, ConfigManager.AwsHttpPrivateKey, r => vipCard = r.data, null); } catch (Exception ex) { log.Error(ex); } } bool isSuccess = false; if (order.OrderType == (int)PaidOrderType.Erp2) { isSuccess = Erp2ServiceHelper.SendHttpMessage(Erp2Config.PAY_URL, new { saleno = order.OrderNo, paymentcode = order.PaymentCode, transno = order.TransNo, vipno = vipCard }, null , null); } else { var paymentName = string.Empty; string dealCode = order.OrderNo; using (var db = new YintaiHangzhouContext("YintaiHangzhouContext")) { var paymentEntity = db.Set<PaymentMethodEntity>().Where(p => p.Code == order.PaymentCode).FirstOrDefault(); if (paymentEntity == null) { log.Error(string.Format("orderno :{1} not support payment code paid:{0}", order.PaymentCode, order.OrderNo)); return false; } paymentName = paymentEntity.Name; //渠道订单同步时传递的是渠道订单号 var channelOrder = db.Set<Map4Order>().FirstOrDefault(o=>o.OrderNo==dealCode); if (channelOrder != null && !string.IsNullOrEmpty(channelOrder.ChannelOrderCode)) { dealCode = channelOrder.ChannelOrderCode; } } var paidFunc = isOnlinePay ? "WebOrdersPaid" : "WebSalesPaid"; isSuccess = ErpServiceHelper.SendHttpMessage(ConfigManager.ErpBaseUrl, new { func = paidFunc, dealCode, PAY_TYPE = order.PaymentCode, PaymentName = paymentName, TRADE_NO = order.TransNo, CardNo = vipCard }, null , null); } if (isSuccess) { using (var db = new YintaiHangzhouContext("YintaiHangzhouContext")) { order.IsSynced = true; order.SyncDate = DateTime.Now; db.Entry(order).State = EntityState.Modified; db.SaveChanges(); } } return isSuccess; }
public static bool SyncOne(decimal pid, decimal sizeId,string sizeName, decimal colorId,string colorName) { if (!EnsureProductContext(pid)) return false; if (sizeId == 0 || colorId == 0) { Log.Error(string.Format("product sid:{0} with empty color sid or size sid",pid)); return false; } using (var db = new YintaiHangzhouContext("YintaiHangzhouContext")) { var product = db.Set<ProductMapEntity>().Where(p=>p.ChannelPId == pid).FirstOrDefault(); if (product == null) return false; ; var existColor = db.Set<ProductPropertyValueEntity>().Where(b =>b.ChannelValueId == colorId) .Join(db.Set<ProductPropertyEntity>().Where(pp=>pp.ProductId==product.ProductId),o=>o.PropertyId,i=>i.Id,(o,i)=>o) .FirstOrDefault(); if (existColor == null) { var colorEntity = db.Set<ProductPropertyEntity>().Where(p => p.ProductId == product.ProductId && p.IsColor.HasValue && p.IsColor.Value == true).FirstOrDefault(); if (colorEntity == null) { colorEntity = db.ProductProperties.Add(new ProductPropertyEntity() { IsColor = true, ChannelPropertyId = 0, ProductId = product.ProductId, PropertyDesc = "颜色", SortOrder = 0, Status = 1, UpdateDate = DateTime.Now, UpdateUser = 0 }); db.SaveChanges(); } db.ProductPropertyValues.Add(new ProductPropertyValueEntity() { ChannelValueId = (int)colorId, PropertyId = colorEntity.Id, CreateDate = DateTime.Now, Status =1, UpdateDate = DateTime.Now, ValueDesc = colorName }); } else { existColor.ValueDesc = colorName; existColor.UpdateDate = DateTime.Now; db.Entry(existColor).State = System.Data.EntityState.Modified; } var existSize = db.Set<ProductPropertyValueEntity>().Where(b => b.ChannelValueId == sizeId) .Join(db.Set<ProductPropertyEntity>().Where(pp => pp.ProductId == product.ProductId), o => o.PropertyId, i => i.Id, (o, i) => o).FirstOrDefault(); if (existSize == null) { var sizeEntity = db.Set<ProductPropertyEntity>().Where(p => p.ProductId == product.ProductId && p.IsSize.HasValue && p.IsSize.Value == true).FirstOrDefault(); if (sizeEntity == null) { sizeEntity = db.ProductProperties.Add(new ProductPropertyEntity() { IsSize = true, ChannelPropertyId = 0, ProductId = product.ProductId, PropertyDesc = "尺码", SortOrder = 0, Status = 1, UpdateDate = DateTime.Now, UpdateUser = 0 }); db.SaveChanges(); } db.ProductPropertyValues.Add(new ProductPropertyValueEntity() { ChannelValueId = (int)sizeId, PropertyId = sizeEntity.Id, CreateDate = DateTime.Now, Status = 1, UpdateDate = DateTime.Now, ValueDesc = sizeName }); } else { existSize.ValueDesc = sizeName; existSize.UpdateDate = DateTime.Now; db.Entry(existSize).State = System.Data.EntityState.Modified; } db.SaveChanges(); } return true; }