Exemplo n.º 1
0
        /// <summary>
        /// 删除文件及记录
        /// </summary>
        /// <param name="uploadType">图片字段</param>
        /// <param name="fileBase64"></param>
        /// <param name="fileName"></param>
        /// <returns></returns>
        public AjaxResult DeleteFileToServer(string uploadType, string id, string fileName)
        {
            fileName = fileName.Replace(new ImagesData().ServicePath, "");
            var imageObj = new ImagesData()
            {
                ImageName = fileName
            };

            if (fileName.IsNullOrEmpty())
            {
                return(Error("文件为空"));
            }
            //FastDFSHelper.RemoveFile(fileName);
            dynamic obj = null;
            var     _ProductBusiness              = new ProductBusiness();
            var     _product_tagBusiness          = new product_tagBusiness();
            var     _DictionaryBusiness           = new DictionaryBusiness();
            var     _product_IntroductionBusiness = new product_IntroductionBusiness();

            switch (uploadType)
            {
            case "images":
            case "logo":
            case "photooffarmers":
            case "commodity_photo":
                obj = (product)_ProductBusiness.GetEntity(id.ToInt());
                break;

            case "img_url":
                obj = (product_tag)_product_tagBusiness.GetEntity(id);
                break;

            case "dicimages":
                obj = (dictionary)_DictionaryBusiness.GetEntity(id);
                break;

            default:
                obj = (product_Introduction)_product_IntroductionBusiness.GetEntity(uploadType);
                break;
            }
            string tempName = string.Empty;

            if (obj != null)
            {
                switch (uploadType)
                {
                case "images":    //产品图片
                    tempName   = obj.images;
                    obj.images = tempName.Replace(fileName + ",", "").Replace("," + fileName, "").Replace(fileName, "");
                    _ProductBusiness.UpdateAny(obj, new List <string>()
                    {
                        "images"
                    });
                    break;

                case "logo":    //logo
                    tempName = obj.logo;
                    obj.logo = tempName.Replace(fileName + ",", "").Replace("," + fileName, "").Replace(fileName, "");
                    _ProductBusiness.UpdateAny(obj, new List <string>()
                    {
                        "logo"
                    });
                    break;

                case "photooffarmers":    //农户照片
                    tempName           = obj.photooffarmers;
                    obj.photooffarmers = tempName.Replace(fileName + ",", "").Replace("," + fileName, "").Replace(fileName, "");
                    _ProductBusiness.UpdateAny(obj, new List <string>()
                    {
                        "photooffarmers"
                    });
                    break;

                case "commodity_photo":    //扶贫商品照片
                    tempName            = obj.commodity_photo;
                    obj.commodity_photo = tempName.Replace(fileName + ",", "").Replace("," + fileName, "").Replace(fileName, "");
                    _ProductBusiness.UpdateAny(obj, new List <string>()
                    {
                        "commodity_photo"
                    });
                    break;

                case "img_url":    //热门城市logo
                    tempName    = obj.img_url;
                    obj.img_url = tempName.Replace(fileName + ",", "").Replace("," + fileName, "").Replace(fileName, "");
                    _product_tagBusiness.UpdateAny(obj, new List <string>()
                    {
                        "img_url"
                    });
                    break;

                case "dicimages":    //数据字典照片
                    tempName   = obj.images;
                    obj.images = tempName.Replace(fileName + ",", "").Replace("," + fileName, "").Replace(fileName, "");
                    _DictionaryBusiness.UpdateAny(obj, new List <string>()
                    {
                        "images"
                    });
                    break;

                default:
                    tempName    = obj.picture;
                    obj.picture = tempName.Replace(fileName + ",", "").Replace("," + fileName, "").Replace(fileName, "");
                    _product_IntroductionBusiness.UpdateAny(obj, new List <string>()
                    {
                        "picture"
                    });
                    break;
                }
            }
            return(Success(imageObj));
        }
Exemplo n.º 2
0
        /// <summary>
        /// 上传文件到文件系统服务器
        /// </summary>
        /// <param name="uploadType">图片字段</param>
        /// <param name="fileBase64"></param>
        /// <param name="fileName"></param>
        /// <returns></returns>
        public AjaxResult UploadFileToServer(string uploadType, string id, string multiple, string fileBase64, string fileName)
        {
            string name = FastDFSHelper.UploadFile(fileBase64, fileName);

            if (name.IsNullOrEmpty())
            {
                return(Error("上传失败"));
            }
            dynamic obj = null;
            var     _ProductBusiness              = new ProductBusiness();
            var     _product_tagBusiness          = new product_tagBusiness();
            var     _DictionaryBusiness           = new DictionaryBusiness();
            var     _product_IntroductionBusiness = new product_IntroductionBusiness();

            switch (uploadType)
            {
            case "images":
            case "logo":
            case "photooffarmers":
            case "commodity_photo":
                obj = (product)_ProductBusiness.GetEntity(id.ToInt());
                break;

            case "img_url":
                obj = (product_tag)_product_tagBusiness.GetEntity(id);
                break;

            case "dicimages":
                obj = (dictionary)_DictionaryBusiness.GetEntity(id);
                break;

            default:
                obj = (product_Introduction)_product_IntroductionBusiness.GetTheData(uploadType);
                break;
            }
            if (obj != null)
            {
                switch (uploadType)
                {
                case "images":    //产品图片
                    obj.images = multiple == "0" ? name : (string.IsNullOrEmpty(obj.images) ? name : obj.images + "," + name);
                    _ProductBusiness.UpdateAny(obj, new List <string>()
                    {
                        "images"
                    });
                    break;

                case "logo":    //logo
                    obj.logo = multiple == "0" ? name : (string.IsNullOrEmpty(obj) ? name : obj.logo + "," + name);
                    _ProductBusiness.UpdateAny(obj, new List <string>()
                    {
                        "logo"
                    });
                    break;

                case "photooffarmers":    //农户照片
                    obj.photooffarmers = multiple == "0" ? name : (string.IsNullOrEmpty(obj.photooffarmers) ? name : obj.photooffarmers + "," + name);
                    _ProductBusiness.UpdateAny(obj, new List <string>()
                    {
                        "photooffarmers"
                    });
                    break;

                case "commodity_photo":    //扶贫商品照片
                    obj.commodity_photo = multiple == "0" ? name : (string.IsNullOrEmpty(obj.commodity_photo) ? name : obj.commodity_photo + "," + name);
                    _ProductBusiness.UpdateAny(obj, new List <string>()
                    {
                        "commodity_photo"
                    });
                    break;

                case "img_url":    //热门城市logo
                    obj.img_url = multiple == "0" ? name : (string.IsNullOrEmpty(obj.img_url) ? name : obj.img_url + "," + name);
                    _product_tagBusiness.UpdateAny(obj, new List <string>()
                    {
                        "img_url"
                    });
                    break;

                case "dicimages":    //数据字典照片
                    obj.images = multiple == "0" ? name : (string.IsNullOrEmpty(obj.images) ? name : obj.images + "," + name);
                    _DictionaryBusiness.UpdateAny(obj, new List <string>()
                    {
                        "images"
                    });
                    break;

                default:
                    obj.picture = multiple == "0" ? name : (string.IsNullOrEmpty(obj.picture) ? name : obj.picture + "," + name);
                    _product_IntroductionBusiness.UpdateAny(obj, new List <string>()
                    {
                        "picture"
                    });
                    break;
                }
            }
            return(Success(new ImagesData()
            {
                ImageName = name
            }));
        }
        /// <summary>
        /// 首页数据
        /// </summary>
        /// <param name="days"></param>
        /// <param name="pagination"></param>
        /// <returns></returns>
        public MainData GetMainData(int days, Pagination pagination)
        {
            var currentTime   = DateTime.Now.ToCstTime().ToString("yyyy-MM-dd");
            var yesterdayTime = DateTime.Now.ToCstTime().AddDays(-1).ToString("yyyy-MM-dd");
            var data          = new MainData();

            var listPays    = new payBusiness().GetIQueryable().Where(x => x.status == 1).ToList();                                                                       //支付记录
            var listProduct = new ProductBusiness().GetIQueryable().ToList();                                                                                             //产品清单
            var listMembers = new membersBusiness().GetIQueryable().ToList();                                                                                             //用户记录
            var listOrders  = new orderBusiness().GetIQueryable().Where(x => x.status == 1).ToList().Where(x => listPays.Find(a => a.order_id == x.Id) != null).ToList(); //订单 -支付完成的订单

            //浏览数
            data.T_VisitsNum = 0;
            data.Y_VisitsNum = 0;
            data.A_VisitsNum = 0;
            //注册用户数
            data.T_RegisteredUsers = listMembers.Where(x => x.registration_time?.ToString("yyyy-MM-dd") == currentTime).Count();
            data.Y_RegisteredUsers = listMembers.Where(x => x.registration_time?.ToString("yyyy-MM-dd") == yesterdayTime).Count();
            data.A_RegisteredUsers = listMembers.Where(x => x.registration_time != null).Count();
            //团长新增数
            data.T_NewHead = listMembers.Where(x => x.header_time?.ToString("yyyy-MM-dd") == currentTime).Count();
            data.Y_NewHead = listMembers.Where(x => x.header_time?.ToString("yyyy-MM-dd") == yesterdayTime).Count();
            data.A_NewHead = listMembers.Where(x => x.header_time != null).Count();
            //参团数
            data.T_Participants = listOrders.Where(x => x.create_time.ToString("yyyy-MM-dd") == currentTime).Sum(x => x.num);
            data.Y_Participants = listOrders.Where(x => x.create_time.ToString("yyyy-MM-dd") == yesterdayTime).Sum(x => x.num);
            data.A_Participants = listOrders.Where(x => x.create_time != null).Sum(x => x.num);
            //交易额
            data.T_TradingVolume = listPays.Where(x => x.pay_time?.ToString("yyyy-MM-dd") == currentTime).Sum(x => x.money);
            data.Y_TradingVolume = listPays.Where(x => x.pay_time?.ToString("yyyy-MM-dd") == yesterdayTime).Sum(x => x.money);
            data.A_TradingVolume = listPays.Where(x => x.pay_time != null).Sum(x => x.money);

            decimal value = 0;

            for (int i = days - 1; i >= 0; i--)
            {
                value += listPays.Where(x => x.pay_time?.ToString("yyyy-MM-dd") == DateTime.Now.ToCstTime().AddDays(-i).ToString("yyyy-MM-dd")).Sum(x => x.money);
                data.xAxisData.Add(DateTime.Now.ToCstTime().AddDays(-i).ToString("MM/dd"));
                data.yAxisData.Add(value);
            }

            List <SaleRank> ProductSaleRank     = new List <SaleRank>();
            var             listProductSaleRank = listOrders.GroupBy(x => x.product_id);

            foreach (var item in listProductSaleRank)
            {
                ProductSaleRank.Add(new SaleRank()
                {
                    name = listProduct.Find(x => x.Id == int.Parse(item.Key))?.title, num = item.Sum(x => x.num)
                });
            }
            data.ProductSaleRank = pagination.BuildTableResult_DataGrid(ProductSaleRank.GetPagination(pagination).ToList());

            List <SaleRank> TeamSaleRank     = new List <SaleRank>();
            var             listTeamSaleRank = listOrders.Where(x => x.share_id != null).GroupBy(x => x.share_id);

            foreach (var item in listTeamSaleRank)
            {
                TeamSaleRank.Add(new SaleRank()
                {
                    name = listMembers.Find(x => x.oppen_id == item.Key)?.nick_name, num = item.Sum(x => x.num)
                });
            }
            data.TeamSaleRank = pagination.BuildTableResult_DataGrid(TeamSaleRank.GetPagination(pagination).ToList());
            return(data);
        }