Exemple #1
0
        public string Verification(PromotionEntity promotionEntity)
        {
            if (promotionEntity == null)
            {
                return("活动不存在");
            }

            if (promotionEntity.StartDate > DateTime.Now)
            {
                return("活动还没有开始");
            }

            if (promotionEntity.EndDate < DateTime.Now)
            {
                return("活动已经结束");
            }

            if (promotionEntity.PublicationLimit != null && promotionEntity.PublicationLimit > 0)
            {
                //验证优惠券领取数
                var c = _couponService.GetCouponCount(promotionEntity.Id, SourceType.Promotion);
                if (promotionEntity.PublicationLimit <= c)
                {
                    return("活动优惠码已售罄");
                }
            }

            return(null);
        }
Exemple #2
0
        /// <summary>
        /// 添加购物车
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="sku"></param>
        /// <param name="qty"></param>
        /// <param name="language"></param>
        /// <param name="exchangeRate"></param>
        /// <param name="currentSalesTerritory"></param>
        /// <returns></returns>
        public bool AddItemByUserId(int userId, string sku, int qty, int language, decimal exchangeRate, int currentSalesTerritory)
        {
            bool isOk = false;

            var entity = this.CheckProductParams(userId, sku, qty, language, currentSalesTerritory);
            //TODO:如果sku存在则更新数量
            var             promotions = promotionDal.GetAvaliablePromotionEntities(new[] { sku }).Where(d => d.PromotionType != 2);
            PromotionEntity promotion  = null;

            if (promotions != null && promotions.Any())
            {
                promotion = promotions.FirstOrDefault();
            }


            var skuQty = cartDal.IsExistSku(userId, sku, currentSalesTerritory);

            if ((qty + skuQty) > (entity.Qty))
            {
                throw new SFO2OException("您要订购的商品库存量不足");
            }

            bool isExist = skuQty > 0;

            if (isExist)
            {
                isOk = cartDal.UpdateQty(userId, sku, qty, currentSalesTerritory, promotion, true);
            }
            else
            {
                isOk = cartDal.AddSkuInfo(userId, qty, exchangeRate, entity, promotion);
            }
            return(isOk);
        }
Exemple #3
0
        public ActionResult CreatePromotionResource([FetchProduct(KeyName = "sid")] PromotionEntity productEntity)
        {
            var vo = new ResourceViewModel();

            vo.SourceId   = productEntity.Id;
            vo.SourceType = (int)SourceType.Product;

            return(Create(vo));
        }
Exemple #4
0
        /// <summary>
        /// 得到促销商品
        /// </summary>
        public virtual ActionResult Promotion(long productId)
        {
            var query = PromotionEntity.GetUsedQuery(new [] { productId });

            query.Query <PromotionEntity>();
            var infos = this.GetEntities <PromotionEntity>(query);

            return(View("_Promotion", infos?.FirstOrDefault()));
        }
        private void ApplayPromotion(CartItemEntity cartItemAdded, PromotionEntity promotionRelated, int promotionApplies)
        {
            if (cartItemAdded.Promotion == null)
            {
                cartItemAdded.Promotion = Mapper.Map <CartItemPromotion>(promotionRelated);
            }

            var discountPerApply = GetDiscountPerApply(promotionRelated, cartItemAdded);

            cartItemAdded.Promotion.Discount = Math.Round(promotionApplies * discountPerApply, 2);
        }
        private int PromotionApplies(CartItemEntity cartItem, PromotionEntity promotionRelated)
        {
            var quantity = cartItem.Quantity / (cartItem.IsWeighable ? cartItem.Size : 1);
            var applies  = quantity / promotionRelated.TriggeringQuantity;

            if (applies > 1 && !promotionRelated.IsReApply)
            {
                return(1);
            }
            return(applies);
        }
Exemple #7
0
        public PromotionViewModel PromotionViewMapping(PromotionEntity source)
        {
            if (source == null)
            {
                return(null);
            }

            var resouces = ResourceViewMapping(GetListResourceEntities(SourceType.Promotion, source.Id)).ToList();

            return(PromotionViewMapping(source, resouces));
        }
Exemple #8
0
        /// <summary>
        /// 更新qty信息
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="sku"></param>
        /// <param name="qty"></param>
        /// <param name="language"></param>
        /// <param name="exchangeRate"></param>
        /// <param name="currentSalesTerritory"></param>
        /// <returns></returns>
        public bool UpdateQtyByUserId(int userId, string sku, int qty, int language, decimal exchangeRate, int currentSalesTerritory)
        {
            var             entity     = this.CheckProductParams(userId, sku, qty, language, currentSalesTerritory);
            var             promotions = promotionDal.GetAvaliablePromotionEntities(new[] { sku });
            PromotionEntity promotion  = null;

            if (promotions != null && promotions.Any())
            {
                promotion = promotions.FirstOrDefault();
            }
            return(cartDal.UpdateQty(userId, sku, qty, currentSalesTerritory, promotion));
        }
Exemple #9
0
        /// <summary>
        /// 检查 entity 为 null的情况
        /// </summary>
        /// <param name="source"></param>
        /// <returns></returns>
        private static PromotionEntity PromotionEntityCheck(PromotionEntity source)
        {
            source.Description = CheckString(source.Description);
            source.Name        = CheckString(source.Name);

            source.StartDate   = EntityDateTime(source.StartDate);
            source.EndDate     = EntityDateTime(source.EndDate);
            source.UpdatedDate = EntityDateTime(source.UpdatedDate);
            source.CreatedDate = EntityDateTime(source.CreatedDate);

            return(source);
        }
Exemple #10
0
        public ActionResult Edit(int?id, [FetchPromotion(KeyName = "id")] PromotionEntity entity)
        {
            if (id == null || entity == null)
            {
                ModelState.AddModelError("", "参数验证失败.");
                return(View());
            }

            var vo = MappingManager.PromotionViewMapping(entity);

            return(View(vo));
        }
Exemple #11
0
 public void LoadData(PromotionEntity p)
 {
     if (!IsPostBack)
     {
         promotionID.Value        = p.ID;
         title.Value              = p.Title;
         shortdescription.Value   = p.ShortDiscription;
         discription.Value        = p.Discription;
         ddlStatus.SelectedValue  = p.StatusID.ToString();
         UploadedImage.DefaultUrl = p.Image;
         UploadedImage.DataBind();
     }
 }
Exemple #12
0
        private static PromotionViewModel PromotionViewMapping(PromotionEntity source, List <ResourceViewModel> resourceViewModels)
        {
            if (source == null)
            {
                return(null);
            }

            var target = Mapper.Map <PromotionEntity, PromotionViewModel>(source);

            target.Resources = resourceViewModels;

            return(target);
        }
Exemple #13
0
        PromotionEntity GetPromotion()
        {
            PromotionEntity p = new PromotionEntity();

            p.ID               = promotionID.Value;
            p.Title            = title.Value;
            p.ShortDiscription = shortdescription.Value;
            p.Discription      = discription.Value;
            p.Image            = UploadedImage.GetUrl();
            p.Status           = StatusBus.Instance.GetStatus(int.Parse(ddlStatus.SelectedValue));
            p.CreatedDate      = DateTime.Now;
            p.CreatedBy        = UserBus.Instance.GetUser(User.Identity.Name);
            return(p);
        }
Exemple #14
0
        /// <summary>
        /// 更新已存在的产品数量
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="sku"></param>
        /// <param name="qty"></param>
        /// <param name="salesTerritory"></param>
        /// <returns></returns>
        public bool UpdateQty(int userId, string sku, int qty, int salesTerritory, PromotionEntity promotion, bool isSum = false)
        {
            //TODO:更新购物车的促销价格
            string sqlSum = @"UPDATE  [ShoppingCart]
                            SET     
                           [Quantity] = Quantity+@Quantity 
                          ,[LastTime] = @LastTime
                          ,[SortTime] = @SortTime
                          ,[IsChecked] = 1
                            {0}
                    WHERE [UserId]=@UserId and ( [CountryId]=@CountryId or CountryId=3 ) and [Sku]=@Sku ";
            string sql    = @"UPDATE  [ShoppingCart]
                            SET     
                           [Quantity] = @Quantity 
                          ,[LastTime] = @LastTime
                          ,[SortTime] = @SortTime
                             {0}
                    WHERE [UserId]=@UserId and ( [CountryId]=@CountryId or CountryId=3 ) and [Sku]=@Sku ";

            try
            {
                var parameters = DbSFO2ORead.CreateParameterCollection();
                parameters.Append("@UserId", userId);
                parameters.Append("@CountryId", salesTerritory);
                parameters.Append("@Sku", sku);
                parameters.Append("@Quantity", qty);
                parameters.Append("@LastTime", DateTime.Now);
                parameters.Append("@SortTime", DateTime.Now);
                //if (promotion != null)
                //{
                //sqlSum = string.Format(sqlSum, ",DiscountPrice=@DiscountPrice");
                //sql = string.Format(sql, ",DiscountPrice=@DiscountPrice");
                //parameters.Append("@DiscountPrice", promotion.DiscountPrice);
                //}
                //else
                //{
                sqlSum = string.Format(sqlSum, " ");
                sql    = string.Format(sql, " ");
                //}


                return(DbSFO2OMain.ExecuteSqlNonQuery(isSum ? sqlSum : sql, parameters) > 0);
            }
            catch (Exception ex)
            {
                LogHelper.Error(ex);
                return(false);
            }
        }
Exemple #15
0
        /// <summary>
        /// 得到促销商品
        /// </summary>
        /// <param name="productIds"></param>
        protected virtual IList <PromotionEntity> GetPromotions(long[] productIds)
        {
            if (productIds == null)
            {
                return(null);
            }
            var query = PromotionEntity.GetUsedQuery(productIds);

            query.Query <PromotionEntity>()
            .Select(it => new object[]
            {
                it.Id, it.Product.Id, it.OrderLimitCount, it.Cities, it.PayTypes, it.Price
            });
            return(Repository.GetEntities <PromotionEntity>(query));
        }
Exemple #16
0
        /// <summary>
        /// 获取促销价格逻辑
        /// </summary>
        /// <param name="promotionEntity"></param>
        /// <param name="originalPrice"></param>
        /// <param name="exchangeRate"></param>
        /// <returns></returns>
        public static decimal GetSalePrice(this PromotionEntity promotionEntity, decimal originalPrice, decimal?exchangeRate = null)
        {
            var rtnValue = originalPrice;

            if (promotionEntity != null)
            {
                rtnValue = promotionEntity.DiscountPrice;
            }

            if (exchangeRate != null)
            {
                rtnValue = rtnValue * exchangeRate.Value;
            }

            return(rtnValue.ToNumberRound());
        }
Exemple #17
0
        public JsonResult Delete([FetchPromotion(KeyName = "id")] PromotionEntity entity)
        {
            try
            {
                entity.UpdatedDate = DateTime.Now;
                entity.UpdatedUser = CurrentUser.CustomerId;
                entity.Status      = (int)DataStatus.Deleted;

                this._promotionRepository.Update(entity);
                return(SuccessResponse());
            }
            catch (Exception ex)
            {
                Log.Error(ex);
                return(FailResponse());
            }
        }
        protected override void InternalExecute()
        {
            DateTime notifyDate = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day);
            DateTime filterDate = notifyDate.AddDays(1);
            var      newPros    = (from pro in _dbContext.Promotions
                                   where pro.StartDate >= filterDate
                                   orderby pro.UpdatedDate descending
                                   select pro).Take <PromotionEntity>(1);

            if (newPros == null)
            {
                return;
            }
            PromotionEntity pros = newPros.FirstOrDefault();

            pros.Description = pros.Description ?? string.Empty;
            pros.Description = pros.Description.Trim().Length < 1 ? NotificationSetting.Current.DefaultMessage : pros.Description.Trim();
            var devices = (from device in _dbContext.DeviceLogs
                           where !(from nf in _dbContext.NotificationLogs
                                   where nf.NotifyDate >= notifyDate
                                   select nf.DeviceToken).Contains(device.DeviceToken)
                           &&
                           device.Status == 1
                           orderby device.CreatedDate ascending
                           select device).Take(500);

            //var devices = new string[] { @"d4e0f45464ec2d0f8c9f6bb28efe36e2431e01d06c53c24800d81338f5191de8",
            //  @"a10c54e8827052b77cd377db98ef739617032710b9378d95ccb847e39bf2562a" };
            foreach (var device in devices)
            {
                ApnsService.QueueNotification(new JdSoft.Apple.Apns.Notifications.Notification()
                {
                    DeviceToken = device.DeviceToken,
                    Payload     = new JdSoft.Apple.Apns.Notifications.NotificationPayload
                    {
                        Alert = new JdSoft.Apple.Apns.Notifications.NotificationAlert()
                        {
                            Body = pros.Description
                        },
                        Sound = "default",
                        Badge = 1
                    }
                });
            }
        }
Exemple #19
0
        public int TotalItemCostWithOrWithoutPromotion(PromotionEntity objPromotion, int itemId, int itemCount)
        {
            ShoppingItemProcessor objShoppingItemProcessor = new ShoppingItemProcessor();
            ShoppingItemEntity    objShoppingItem          = objShoppingItemProcessor.GetShoppingItems().Where(x => x.ItemId == itemId).ToList()[0];
            int promoTotalCost                = 0;
            int itemNotEligibleForDiscount    = itemCount;// if promocode is not applicable
            int itemEligibleForPromotionCount = 0;
            int totalCost = 0;

            if (objPromotion != null)
            {
                var objPromotionShopItem = objPromotion.LstPromotionItems.Where(x => x.ItemId == itemId).ToList()[0];
                itemNotEligibleForDiscount    = itemCount % objPromotionShopItem.ItemCountForPromotion;
                itemEligibleForPromotionCount = itemCount - itemNotEligibleForDiscount;
                if (itemEligibleForPromotionCount > 0)
                {
                    promoTotalCost = (itemEligibleForPromotionCount / objPromotionShopItem.ItemCountForPromotion) * objPromotion.DiscountedCost;
                }
            }
            totalCost = (itemNotEligibleForDiscount * objShoppingItem.ItemCost) + promoTotalCost;
            return(totalCost);
        }
Exemple #20
0
 private static PromotionItem GetPromotionItem(PromotionEntity p, decimal exchangeRate)
 {
     if (p == null)
     {
         return(null);
     }
     else
     {
         return(new PromotionItem()
         {
             Sku = p.Sku,
             PromotionId = p.PromotionId,
             DiscountPrice = p.DiscountPrice,
             DiscountPriceExchanged = p.DiscountPrice * exchangeRate,
             DiscountRate = p.DiscountRate,
             EndTime = p.EndTime,
             PromotionLable = p.PromotionLable,
             PromotionName = p.PromotionName,
             PromotionType = p.PromotionType
         });
     }
 }
Exemple #21
0
        public JsonResult CalculateShoppingCost(string jsonData)
        {
            PromotionProcessor.PromotionProcessor objPromotionProcessor = new PromotionProcessor.PromotionProcessor();
            int             promoId         = (int)JArray.Parse(jsonData).Children()["PromoId"].First();
            PromotionEntity objPromotion    = objPromotionProcessor.GetPromotionList().Where(x => x.PromotionId == promoId).ToList()[0];
            dynamic         jsonObj         = JsonConvert.DeserializeObject(jsonData);
            int             jCount          = jsonObj.Count;
            int             netShoppingCost = 0;
            int             i = 1;

            foreach (var obj in jsonObj)
            {
                if (i < jCount)
                {
                    int itemid    = Convert.ToInt32(obj.Itemid);
                    int itemCount = Convert.ToInt32(obj.ItemIdCount);
                    netShoppingCost += TotalItemCostWithOrWithoutPromotion(objPromotion, itemid, itemCount);
                    i++;
                }
            }

            return(Json("data", JsonRequestBehavior.AllowGet));
        }
Exemple #22
0
        public ActionResult Edit(FormCollection formCollection, [FetchPromotion(KeyName = "id")] PromotionEntity entity, PromotionViewModel vo)
        {
            if (entity == null || !ModelState.IsValid)
            {
                ModelState.AddModelError("", "参数验证失败.");
                return(View(vo));
            }


            entity.UpdatedDate      = DateTime.Now;
            entity.UpdatedUser      = base.CurrentUser.CustomerId;
            entity.Store_Id         = vo.Store_Id;
            entity.Status           = vo.Status;
            entity.IsProdBindable   = vo.IsProdBindable;
            entity.IsTop            = vo.IsTop;
            entity.Name             = vo.Name;
            entity.PublicationLimit = vo.PublicationLimit;
            entity.StartDate        = vo.StartDate;
            entity.EndDate          = vo.EndDate;
            entity.Description      = vo.Description;
            entity.IsMain           = vo.IsMain;
            entity.IsLimitPerUser   = vo.IsLimitPerUser;
            entity.PublicProCode    = vo.PublicProCode;
            using (TransactionScope ts = new TransactionScope())
            {
                this._promotionRepository.Update(entity);
                if (ControllerContext.HttpContext.Request.Files.Count > 0)
                {
                    this._resourceService.Save(ControllerContext.HttpContext.Request.Files
                                               , CurrentUser.CustomerId
                                               , -1, entity.Id
                                               , SourceType.Promotion);
                }
                ts.Complete();
            }
            return(RedirectToAction("List"));
        }
Exemple #23
0
        public PromotionEntity PromotionEntityMapping(PromotionEntity source, PromotionEntity target)
        {
            var result = Mapper.Map(source, target);

            return(PromotionEntityCheck(result));
        }
Exemple #24
0
        /// <summary>
        /// 添加sku信息
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="qty"></param>
        /// <param name="exchangeRate"></param>
        /// <param name="entity"></param>
        /// <returns></returns>
        public bool AddSkuInfo(int userId, int qty, decimal exchangeRate, Model.Product.ProductSkuEntity entity, PromotionEntity promotion)
        {
            //TODO:更新购物车的促销价格
            string sql = @"INSERT INTO  [ShoppingCart]( [ShoppingCartId],[UserId] ,[CountryId] ,[Spu] ,[Sku] ,[UnitPrice] ,[Quantity]
                        ,[TaxRate] ,[ExchangeRate] ,[CartStatus] ,[IsChecked] ,[CreateTime] ,[LastTime],[SortTime] {0})     VALUES
                        ( @ShoppingCartId  ,@UserId  ,@CountryId  ,@Spu  ,@Sku  ,@UnitPrice  ,@Quantity  ,@TaxRate  ,@ExchangeRate  ,@CartStatus  ,@IsChecked  ,@CreateTime  ,@LastTime ,@SortTime {1}) ";

            try
            {
                var parameters = DbSFO2ORead.CreateParameterCollection();
                parameters.Append("@ShoppingCartId", Guid.NewGuid());
                parameters.Append("@UserId", userId);
                parameters.Append("@CountryId", entity.SalesTerritory);
                parameters.Append("@Spu", entity.Spu);
                parameters.Append("@Sku", entity.Sku);
                parameters.Append("@UnitPrice", entity.Price);
                parameters.Append("@Quantity", qty);
                parameters.Append("@TaxRate", entity.TaxRate);
                parameters.Append("@ExchangeRate", exchangeRate);
                parameters.Append("@CartStatus", 1);
                parameters.Append("@IsChecked", 1);
                parameters.Append("@CreateTime", DateTime.Now);
                parameters.Append("@LastTime", DateTime.Now);
                parameters.Append("@SortTime", DateTime.Now);
                if (promotion != null)
                {
                    sql = string.Format(sql, ",DiscountPrice", ",@DiscountPrice");
                    parameters.Append("@DiscountPrice", promotion.DiscountPrice);
                }
                else
                {
                    sql = string.Format(sql, " ", "");
                }
                return(DbSFO2OMain.ExecuteSqlNonQuery(sql, parameters) > 0);
            }
            catch (Exception ex)
            {
                LogHelper.Error(ex);
                return(false);
            }
        }
Exemple #25
0
 //Promotion
 public void CreatePromotion(PromotionEntity promotion)
 {
     EcomakDbContext.Promotions.Add(promotion);
 }
 private static decimal GetDiscountPerApply(PromotionEntity promotionRelated, CartItemEntity cartItem)
 {
     return(((decimal)promotionRelated.DiscountPercentage / 100) * cartItem.Price);
 }
Exemple #27
0
 public void UpdatePromotion(PromotionEntity promotion)
 {
     EcomakDbContext.Promotions.Update(promotion);
 }
        public ActionResult Destroy(DestroyPromotionRequest request, int?authuid, UserModel authUser, [FetchPromotion(KeyName = "promotionid", IsCanMissing = true)] PromotionEntity entity)
        {
            if (entity == null || authUser == null)
            {
                return(new RestfulResult {
                    Data = new ExecuteResult {
                        StatusCode = StatusCode.ClientError, Message = "参数错误"
                    }
                });
            }

            //达人只能删除自己的商品,
            //店长 可以删除自己店铺下的商品
            //运营 管理员权限的用户才可以删除他人的商品
            var t = false;

            //3
            if ((authUser.UserRole & (int)UserRole.Admin) != 0)
            {
                t = true;
            }
            else
            {
                if (authUser.Id == entity.RecommendUser && (authUser.Level & UserLevel.Daren) != 0)
                {
                    t = true;
                }
            }
            request.AuthUid  = authuid.Value;
            request.AuthUser = authUser;

            return(t ? new RestfulResult {
                Data = this._promotionDataService.DestroyPromotion(request)
            } : new RestfulResult {
                Data = new ExecuteResult {
                    StatusCode = StatusCode.ClientError, Message = "您没有权限删除其他用户的活动"
                }
            });
        }