Beispiel #1
0
        /// <summary>
        ///     加载数据
        /// </summary>
        /// <param name="id">对象商品促销信息Id</param>
        /// <returns></returns>
        public ActionResult Create(long?id)
        {
            ProductRuleModel model = null;

            if (id.HasValue)
            {
                var result = _productRuleService.GetProductRuleById(id.Value);
                if (result.Data != null)
                {
                    model = result.Data;
                    model.TempStarDate = model.StarDate.ToString();
                    model.TempEndDate  = model.EndDate.ToString();
                    AddProductModel _addProductModel = _productService.GetSKU_ProductById(model.ProductId, ACultureHelper.GetLanguageID).Data;
                    if (_addProductModel != null)
                    {
                        model.HKPrice           = ToolUtil.Round(_addProductModel.HKPrice, 2);
                        model.ProductName       = _addProductModel.ProductName;
                        model.SalePrice         = ToolUtil.Round(model.HKPrice * _addProductModel.Discount, 2);
                        model.SKU_ProductModels = _addProductModel.SKU_ProductModels;
                    }
                }
            }
            else
            {
                model = new ProductRuleModel();
                //model.TempStarDate = DateTime.Now.AddDays(0).ToString("yyyy-MM-dd hh:mm");
                // model.TempEndDate = DateTime.Now.AddDays(3).ToString("yyyy-MM-dd hh:mm");
            }
            DrowSalesRuleList();
            return(PartialView(model));
        }
        public JsonResult IsExsitProduct(long?id)
        {
            if (id.HasValue)
            {
                AddProductModel  _addProductModel = _productService.GetSKU_ProductById(id.Value, ACultureHelper.GetLanguageID).Data;
                ProductRuleModel model            = new ProductRuleModel();
                if (_addProductModel != null)
                {
                    ProductStatus productStatus = (ProductStatus)Enum.Parse(typeof(ProductStatus), _addProductModel.Status.ToString());
                    switch (productStatus)
                    {
                    case ProductStatus.Uncommitted:
                        return(Json("Uncommitted", JsonRequestBehavior.AllowGet));

                    case ProductStatus.Submitting:
                        return(Json("Submitting", JsonRequestBehavior.AllowGet));

                    case ProductStatus.ExaminationNotThrough:
                        return(Json("ExaminationNotThrough", JsonRequestBehavior.AllowGet));

                    case ProductStatus.HasUpShelves:
                        model.HKPrice           = ToolUtil.Round(_addProductModel.HKPrice, 2);
                        model.SKU_ProductModels = _addProductModel.SKU_ProductModels;
                        model.ProductName       = _addProductModel.ProductName;
                        model.SalePrice         = ToolUtil.Round(model.HKPrice * _addProductModel.Discount, 2);

                        var jsonObject = Json(model, JsonRequestBehavior.AllowGet);
                        return(jsonObject);

                    case ProductStatus.HasUnderShelves:
                        return(Json("HasUnderShelves", JsonRequestBehavior.AllowGet));

                    default:
                        break;
                    }
                }
                else
                {
                    return(Json("", JsonRequestBehavior.AllowGet));
                }
            }
            return(Json("", JsonRequestBehavior.AllowGet));
        }
        /// <summary>
        /// 更新商品促销信息
        /// </summary>
        /// <param name="model">商品促销信息对象</param>
        /// <returns>返回true时,表示更新成功;反之,表示更新失败</returns>
        /// <remarks>added by jimmy,2015-7-10</remarks>
        public ResultModel Update(ProductRuleModel model)
        {
            var result  = new ResultModel();
            var prodcut = _database.Db.Product.FindByProductId(model.ProductId);
            var sp      = _database.Db.ProductRule;

            if (prodcut == null)
            {
                result.IsValid  = false;
                result.Messages = new List <string>()
                {
                    "Product not exist, cannot be promotion product"
                };
            }
            else
            {
                result.Data = sp.UpdateByProductRuleId(model);
            }
            return(result);
        }
Beispiel #4
0
 public static ProductRule ToEntity(this ProductRuleModel model)
 {
     return(Mapper.Map <ProductRule>(model));
 }
        /// <summary>
        /// 添加商品促销信息
        /// </summary>
        /// <param name="model">商品促销信息对象</param>
        /// <returns></returns>
        /// <remarks>added by jimmy,2015-7-10</remarks>
        public ResultModel Add(ProductRuleModel model)
        {
            var result  = new ResultModel();
            var prodcut = _database.Db.Product.Find(_database.Db.Product.ProductId == model.ProductId && _database.Db.Product.IsDelete == 0);

            if (prodcut == null)
            {
                result.IsValid  = false;
                result.Messages = new List <string>()
                {
                    "The product information is not there, please fill in the other item number"
                };                                                                                                                    //该商品信息不存在,请填写别的商品编号
            }
            else if (prodcut.Status == (int)ProductStatus.ExaminationNotThrough)
            {
                result.IsValid  = false;
                result.Messages = new List <string>()
                {
                    "This product is not approved, and can not be used as a commodity promotion!"
                };                                                                                                                     //该商品没有审核通过,不能作为商品促销!
            }
            else if (prodcut.Status == (int)ProductStatus.HasUnderShelves)
            {
                result.IsValid  = false;
                result.Messages = new List <string>()
                {
                    "The goods have been under the shelf, can not be used as a commodity promotion!"
                };                                                                                                                        //该商品已下架,不能作为商品促销!
            }
            else if (prodcut.Status == (int)ProductStatus.Submitting)
            {
                result.IsValid  = false;
                result.Messages = new List <string>()
                {
                    "The commodity is in the state of the audit, not as a commodity promotion!"
                };                                                                                                                   //该商品处在待审核状态,不能作为商品促销!
            }
            else if (prodcut.Status == (int)ProductStatus.Uncommitted)
            {
                result.IsValid  = false;
                result.Messages = new List <string>()
                {
                    "The goods are not submitted, can not be used as a commodity promotion!"
                };                                                                                                                //该商品未提交,不能作为商品促销!
            }
            else
            {
                if (_database.Db.ProductRule.Find(_database.Db.ProductRule.ProductId == model.ProductId && _database.Db.ProductRule.SalesRuleId == 2) != null)
                {
                    result.IsValid  = false;
                    result.Messages = new List <string>()
                    {
                        "The product promotion information already exists, can not repeat to add!"
                    };                                                                                                                  //该商品促销信息已经存在,不能重复添加!
                }
                else
                {
                    try
                    {
                        var pr = _database.Db.ProductRule.Find(_database.Db.ProductRule.ProductId == model.ProductId && _database.Db.ProductRule.SalesRuleId == 1);
                        if (pr != null)
                        {
                            result.Data = _database.Db.ProductRule.UpdateByProductRuleId(ProductRuleId: pr.ProductRuleId, SalesRuleId: model.SalesRuleId, StarDate: model.StarDate, EndDate: model.EndDate, Discount: model.Discount);
                        }
                        else
                        {
                            result.Data = _database.Db.ProductRule.Insert(model);
                        }
                    }
                    catch (Exception ex)
                    {
                        //todo错误日志
                        throw;
                    }
                }
            }
            return(result);
        }
Beispiel #6
0
        public ActionResult Create(ProductRuleModel model)
        {
            var admin = UserInfo.CurrentUserName;

            if (ModelState.IsValid)
            {
                var resultModel = new ResultModel();
                model.StarDate = DateTime.Parse(model.TempStarDate);
                model.EndDate  = DateTime.Parse(model.TempEndDate);

                if (model.ProductRuleId != 0)
                {
                    switch (model.SalesRuleId)
                    {
                    case 1:
                        model.StarDate = DateTime.Now;
                        model.EndDate  = DateTime.Now;
                        break;

                    default:
                        break;
                    }
                    model.SalesRuleId = (int)ESalesRule.Discount;
                    var resultUp = _productRuleService.Update(model);
                    if (resultUp.IsValid)
                    {
                        resultModel.IsValid  = true;
                        resultModel.Messages = new List <string> {
                            "Modify promotion information success"
                        };
                    }
                    else
                    {
                        resultModel.IsValid  = false;
                        resultModel.Messages = new List <string> {
                            resultUp.Messages[0]
                        };
                    }
                    var opera = string.Format("修改商品促销:ProductRuleId={0},操作结果:{1}", model.ProductRuleId, resultModel.IsValid ? "成功" : "失败");
                    LogPackage.InserAC_OperateLog(opera, "商品管理--商品促销");
                }
                else
                {
                    model.ProductRuleId = MemCacheFactory.GetCurrentMemCache().Increment("commonId");
                    model.SalesRuleId   = (int)ESalesRule.Discount;
                    var result = _productRuleService.Add(model);
                    if (result.IsValid)
                    {
                        resultModel.IsValid  = true;
                        resultModel.Messages = new List <string> {
                            "Add promotion information success"
                        };
                    }
                    else
                    {
                        resultModel.IsValid  = false;
                        resultModel.Messages = new List <string> {
                            result.Messages[0]
                        };
                    }
                }
                return(Json(resultModel, JsonRequestBehavior.AllowGet));
            }
            else
            {
                DrowSalesRuleList();
            }
            return(PartialView(model));
        }