/// <summary>
        /// 创建分类控件
        /// </summary>
        /// <returns></returns>
        public IActionResult _CreateCategoryLevel()
        {
            ViewBag.SubjectTitle = "商品分类创建";
            CategoryLevelModel model = new CategoryLevelModel();

            return(View("/Views/SystemGoods/_EditCategoryLevel.cshtml", model));
        }
        /// <summary>
        /// 编辑分类控件
        /// </summary>
        /// <param name="categoryId"></param>
        /// <param name="level"></param>
        /// <returns></returns>
        public IActionResult _EditCategoryLevel(int categoryId, CategoryLevel level)
        {
            ViewBag.SubjectTitle = "商品分类编辑";
            CategoryLevelModel model = new CategoryLevelModel();

            if (level == CategoryLevel.Level1)
            {
                model.ToCategoryLevel1Model(goodsCategoryLevelService.GetCategoryLevel1(categoryId));
            }
            else
            {
                model.ToCategoryLevel2Model(goodsCategoryLevelService.GetCategoryLevel2(categoryId));
                model.ParentCategoryName = goodsCategoryLevelService.GetCategoryLevel1(model.ParentCategoryId.Value).CategoryName;
            }
            return(View(model));
        }
        /// <summary>
        /// 查看分类详情控件
        /// </summary>
        /// <param name="categoryId"></param>
        /// <param name="level"></param>
        /// <returns></returns>
        public IActionResult _DetailsCategoryLevel(int categoryId, CategoryLevel level)
        {
            CategoryLevelModel model = new CategoryLevelModel();

            if (level == CategoryLevel.Level1)
            {
                model.ToCategoryLevel1Model(goodsCategoryLevelService.GetCategoryLevel1(categoryId));
            }
            else
            {
                model.ToCategoryLevel2Model(goodsCategoryLevelService.GetCategoryLevel2(categoryId));
                model.ParentCategoryName = goodsCategoryLevelService.GetCategoryLevel1(model.ParentCategoryId.Value).CategoryName;
            }

            return(View(model));
        }
        public async Task <IActionResult> EditCategoryLevelAsync([FromServices] IHostingEnvironment env, IFormFile files, CategoryLevelModel model, bool isUpdate)
        {
            var file = files;

            if (file != null)
            {
                var filePath      = string.Format("/Uploads/Images/{0}/{1}/{2}/", DateTime.Now.ToString("yyyy"), DateTime.Now.ToString("MM"), DateTime.Now.ToString("dd"));
                var qiniuFilePath = string.Format("{0}/{1}/{2}/", DateTime.Now.ToString("yyyy"), DateTime.Now.ToString("MM"), DateTime.Now.ToString("dd"));
                if (!Directory.Exists(env.WebRootPath + filePath))
                {
                    Directory.CreateDirectory(env.WebRootPath + filePath);
                }
                long         size          = file.Length;
                var          fileExtension = Path.GetExtension(file.FileName);
                const string fileFilt      = ".gif|.jpg|.jpeg|.png|.webp|";
                const string saveSuffix    = ".jpeg";
                if (fileExtension == null)
                {
                    return(Json(new StatusMessageData(StatusMessageType.Error, "上传的文件没有后缀")));
                }
                if (fileFilt.IndexOf(fileExtension.ToLower(), StringComparison.Ordinal) <= -1)
                {
                    return(Json(new StatusMessageData(StatusMessageType.Error, "上传的文件不是图片")));
                }
                if (size > 1024 * 1024 * 2)
                {
                    return(Json(new StatusMessageData(StatusMessageType.Error, "上传的文件不能大于2M")));
                }
                var strDateTime = DateTime.Now.ToString("yyyyMMddhhmmssfff");
                var strRan      = Convert.ToString(new Random().Next(100, 999));
                var saveName    = strDateTime + strRan;
                var useQiNiu    = BuilderContext.Configuration["UseQiNiu"];
                var qiniuHost   = BuilderContext.Configuration["QiNiuHost"];
                var pathName    = string.Empty;

                string hostPath      = WebSiteUtility.MapPhysicsToUrl($"{filePath}{saveName}");
                string qiniuHostPath = WebSiteUtility.MapPhysicsToUrl($"{qiniuHost}{qiniuFilePath}{saveName}");

                using (var stream = new FileStream($"{env.WebRootPath}{filePath}{saveName}{saveSuffix}", FileMode.Create))
                {
                    await file.CopyToAsync(stream);

                    stream.Flush();
                    pathName       = stream.Name;
                    model.ImageUrl = $"{Request.Scheme}://{Request.Host}{hostPath}{saveSuffix}";
                }
                if (useQiNiu.Equals("true", StringComparison.CurrentCultureIgnoreCase))
                {
                    await Task.Run(() =>
                    {
                        QiniuManager qiniu = new QiniuManager();
                        string savekey     = $"{qiniuFilePath}{saveName}";
                        byte[] data        = System.IO.File.ReadAllBytes(pathName);
                        qiniu.ByteUpload(data, savekey);
                    });

                    model.ImageUrl = qiniuHostPath;
                }
            }
            if (isUpdate)
            {
                if (model.LevelEnum == CategoryLevel.Level1)
                {
                    GoodsCategoryLevel1 category = goodsCategoryLevelService.GetCategoryLevel1(model.CategoryId);
                    category.CategoryName           = model.CategoryName;
                    category.Description            = model.Description ?? string.Empty;
                    category.CategoryLevel1ImageUrl = model.ImageUrl ?? string.Empty;
                    goodsCategoryLevelService.UpdataCategoryLevel <GoodsCategoryLevel1>(category);
                    return(Json(new StatusMessageData(StatusMessageType.Success, "保存成功")));
                }
                else if (model.LevelEnum == CategoryLevel.Level2)
                {
                    GoodsCategoryLevel2 category = goodsCategoryLevelService.GetCategoryLevel2(model.CategoryId);
                    var oldCategoryLevel2Id      = category.CategoryLevel1Id;
                    category.CategoryName           = model.CategoryName;
                    category.CategoryLevel1Id       = model.ParentCategoryId.Value;
                    category.Description            = model.Description ?? string.Empty;
                    category.CategoryLevel2ImageUrl = model.ImageUrl ?? string.Empty;
                    goodsCategoryLevelService.UpdataCategoryLevel <GoodsCategoryLevel2>(category, oldCategoryLevel2Id);
                    return(Json(new StatusMessageData(StatusMessageType.Success, "保存成功")));
                }
            }
            else
            {
                if (model.LevelEnum == CategoryLevel.Level1)
                {
                    GoodsCategoryLevel1 category = GoodsCategoryLevel1.New();
                    category.CategoryName           = model.CategoryName;
                    category.Description            = model.Description ?? string.Empty;
                    category.CategoryLevel1ImageUrl = model.ImageUrl ?? string.Empty;
                    goodsCategoryLevelService.CreateCategoryLevel <GoodsCategoryLevel1>(category);
                    return(Json(new StatusMessageData(StatusMessageType.Success, "保存成功")));
                }
                else if (model.LevelEnum == CategoryLevel.Level2)
                {
                    GoodsCategoryLevel2 category = GoodsCategoryLevel2.New();
                    category.CategoryName           = model.CategoryName;
                    category.CategoryLevel1Id       = model.ParentCategoryId.Value;
                    category.Description            = model.Description ?? string.Empty;
                    category.CategoryLevel2ImageUrl = model.ImageUrl ?? string.Empty;
                    goodsCategoryLevelService.CreateCategoryLevel <GoodsCategoryLevel2>(category);
                    return(Json(new StatusMessageData(StatusMessageType.Success, "保存成功")));
                }
            }

            return(Json(new StatusMessageData(StatusMessageType.Error, "保存失败")));
        }