Exemplo n.º 1
0
        /// <summary>
        /// 已保存的活动发布
        /// </summary>
        /// <param name="activityId"></param>
        /// <returns></returns>
        public OpResult PushProductActivity(string activityId, string currentUser)
        {
            OpResult result = new OpResult()
            {
                Successed = false
            };

            try
            {
                var queryDatas = _context.ProductActivityDetail.Where(a => a.ProductActivityId.Equals(activityId)).ToList();
                foreach (var item in queryDatas)
                {
                    ProductActivityDetailPool padp = new ProductActivityDetailPool()
                    {
                        Id = CommonRules.GUID
                    };
                    padp.CopyProperty(item);
                    padp.CreatedOn = DateTime.Now;
                    padp.CreatedBy = currentUser;
                    padp.IsDeleted = 0;
                    _context.ProductActivityDetailPool.Add(padp);
                }
                //发布成功改掉活动状态
                var activity = _context.ProductActivity.Single(a => a.Id.Equals(activityId));
                activity.PublishStatus = 1;
                if (_context.SaveChanges() > 0)
                {
                    result.Successed = true;
                }
            }
            catch (Exception e)
            {
                result.Message = "发布失败!";
            }
            return(result);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 创建产品活动
        /// </summary>
        /// <param name="productActivity"></param>
        /// <returns></returns>
        public OpResult CreateProductActivity(ProductActivity productActivity, string currentUser)
        {
            var      createStatus = false;
            OpResult result       = new OpResult()
            {
                Successed = false
            };

            try
            {
                //添加活动主要数据
                if (productActivity.Id == null)
                {
                    createStatus              = true;
                    productActivity.Id        = CommonRules.GUID;
                    productActivity.CreatedBy = currentUser;
                    productActivity.CreatedOn = DateTime.Now;
                    productActivity.IsDeleted = 0;
                }
                else
                {
                    productActivity.ModifiedBy = currentUser;
                    productActivity.ModifiedOn = DateTime.Now;
                    //删除原来添加的产品
                    var oldProdata = _context.ProductActivityDetail.Where(a => a.ProductActivityId.Equals(productActivity.Id)).ToList();
                    foreach (var item in oldProdata)
                    {
                        item.IsDeleted = 1;
                    }
                    var oldProPoolData = _context.ProductActivityDetailPool.Where(a => a.ProductActivityId.Equals(productActivity.Id)).ToList();
                    foreach (var item in oldProPoolData)
                    {
                        _context.ProductActivityDetailPool.Remove(item);
                    }
                }

                //多个产品做活动
                if (productActivity.ProductIds.Contains(","))
                {
                    var arrayIds     = productActivity.ProductIds.Trim(',').Split(',');
                    var arrayPIds    = productActivity.ParentProductIds.Trim(',').Split(',');
                    var arrayPrices  = productActivity.ActivityProPrices.Trim(',').Split(',');
                    var arrayOprices = productActivity.ProOrginPrice.Trim(',').Split(',');
                    if (arrayIds.Count() != arrayPIds.Count() || arrayPIds.Count() != arrayPrices.Count() || arrayPIds.Count() != arrayOprices.Count())
                    {
                        result.Message = "提交数据异常,创建数据失败!";
                        return(result);
                    }
                    for (var i = 0; i < arrayPIds.Count(); i++)
                    {
                        ProductActivityDetail proActivityDetail = new ProductActivityDetail();
                        //插入活动历史表

                        proActivityDetail.Id                = CommonRules.GUID;
                        proActivityDetail.ProductId         = arrayPIds[i];
                        proActivityDetail.SubProductId      = arrayIds[i];
                        proActivityDetail.ProductActivityId = productActivity.Id;
                        proActivityDetail.ProductPrice      = Convert.ToDecimal(arrayOprices[i]);//产品原价
                        proActivityDetail.ActivityPrice     = Convert.ToDecimal(arrayPrices[i]);
                        proActivityDetail.BeginValidDate    = productActivity.BeginValidDate;
                        proActivityDetail.EndValidDate      = productActivity.EndValidDate;
                        proActivityDetail.CreatedBy         = currentUser;
                        proActivityDetail.CreatedOn         = DateTime.Now;
                        proActivityDetail.IsDeleted         = 0;
                        _context.ProductActivityDetail.Add(proActivityDetail);
                        //发布状态的话插入活动明细数据
                        if (productActivity.PublishStatus == 1)
                        {
                            //插入当前活动表
                            ProductActivityDetailPool proActivityDetailPool = new ProductActivityDetailPool();
                            proActivityDetailPool.CopyProperty(proActivityDetail);
                            proActivityDetailPool.CreatedBy = currentUser;
                            proActivityDetailPool.CreatedOn = DateTime.Now;
                            proActivityDetailPool.IsDeleted = 0;
                            proActivityDetailPool.Id        = CommonRules.GUID;


                            _context.ProductActivityDetailPool.Add(proActivityDetailPool);
                        }
                    }
                }
                else//单个产品做活动
                {
                    ProductActivityDetail proActivityDetail = new ProductActivityDetail();

                    //插入活动历史表

                    proActivityDetail.CopyProperty(productActivity);
                    proActivityDetail.Id = CommonRules.GUID;
                    proActivityDetail.ProductActivityId = productActivity.Id;
                    proActivityDetail.ProductId         = productActivity.ParentProductIds;
                    proActivityDetail.SubProductId      = productActivity.ProductIds;
                    proActivityDetail.ProductPrice      = Convert.ToDecimal(productActivity.ProOrginPrice);
                    proActivityDetail.ActivityPrice     = Convert.ToDecimal(productActivity.ActivityProPrices);
                    proActivityDetail.CreatedOn         = DateTime.Now;
                    proActivityDetail.CreatedBy         = currentUser;
                    proActivityDetail.IsDeleted         = 0;
                    _context.ProductActivityDetail.Add(proActivityDetail);

                    //发布状态的话插入活动明细数据
                    if (productActivity.PublishStatus == 1)
                    {
                        //插入当前活动表
                        ProductActivityDetailPool proActivityDetailPool = new ProductActivityDetailPool();
                        proActivityDetailPool.CopyProperty(productActivity);
                        proActivityDetailPool.ProductActivityId = productActivity.Id;
                        proActivityDetailPool.ProductId         = productActivity.ParentProductIds;
                        proActivityDetailPool.SubProductId      = productActivity.ProductIds;
                        proActivityDetailPool.ProductPrice      = Convert.ToDecimal(productActivity.ProOrginPrice);
                        proActivityDetailPool.ActivityPrice     = Convert.ToDecimal(productActivity.ActivityProPrices);
                        proActivityDetailPool.Id        = CommonRules.GUID;
                        proActivityDetailPool.CreatedOn = DateTime.Now;
                        proActivityDetailPool.CreatedBy = currentUser;
                        proActivityDetailPool.IsDeleted = 0;
                        _context.ProductActivityDetailPool.Add(proActivityDetailPool);
                    }
                }


                if (createStatus)
                {
                    _context.ProductActivity.Add(productActivity);
                }
                else
                {
                    var act = _context.ProductActivity.SingleOrDefault(a => a.Id.Equals(productActivity.Id));
                    act.ModifiedBy    = currentUser;
                    act.ModifiedOn    = DateTime.Now;
                    act.PublishStatus = productActivity.PublishStatus;
                }
                //移除过期活动
                RemoveTimeoutActivity();
                if (_context.SaveChanges() > 0)
                {
                    result.Successed = true;
                }
            }
            catch (Exception e)
            {
                result.Message = "活动创建失败!";
            }

            return(result);
        }