예제 #1
0
        public ActionResult UploadPic(ShopImgModel model)
        {
            JsonModel jm = new JsonModel();

            try
            {
                //门店BLL
                IShopBLL shopBll = BLLFactory <IShopBLL> .GetBLL("ShopBLL");

                var shopInfo = shopBll.GetEntity(index => index.Id == model.Id);

                //图片路径
                string PathList = shopInfo.ImgPath;
                //缩略图路径
                string ThumPathList = shopInfo.ImgThumbnail;
                for (int i = 0; i < Request.Files.Count; i++)
                {
                    HttpPostedFileBase file = Request.Files[i];

                    if (file != null)
                    {
                        var fileName = DateTime.Now.ToFileTime() + Path.GetExtension(file.FileName);
                        //判断图片路径是否存在
                        if (!Directory.Exists(Server.MapPath(ConstantParam.SHOP_IMG_DIR)))
                        {
                            Directory.CreateDirectory(Server.MapPath(ConstantParam.SHOP_IMG_DIR));
                        }
                        //判断缩略图路径是否存在
                        if (!Directory.Exists(Server.MapPath(ConstantParam.SHOP_THUM_IMG_DIR)))
                        {
                            Directory.CreateDirectory(Server.MapPath(ConstantParam.SHOP_THUM_IMG_DIR));
                        }
                        //保存图片
                        var path = Path.Combine(Server.MapPath(ConstantParam.SHOP_IMG_DIR), fileName);
                        file.SaveAs(path);
                        //生成缩略图
                        string thumpFile = DateTime.Now.ToFileTime() + ".jpg";

                        var thumpPath = Path.Combine(Server.MapPath(ConstantParam.SHOP_THUM_IMG_DIR), thumpFile);
                        PropertyUtils.getThumImage(path, 18, 3, thumpPath);
                        PathList     += ConstantParam.SHOP_IMG_DIR + fileName + ";";
                        ThumPathList += ConstantParam.SHOP_THUM_IMG_DIR + thumpFile + ";";
                    }
                }
                // 更新图片
                shopInfo.ImgPath      = PathList;
                shopInfo.ImgThumbnail = ThumPathList;
                shopInfo.UpdateTime   = DateTime.Now;
                // 保存到数据库
                shopBll.Update(shopInfo);

                //日志记录
                jm.Content = PropertyUtils.ModelToJsonString(model);
            }
            catch (Exception e)
            {
                jm.Msg = e.Message;
            }
            return(Json(jm, JsonRequestBehavior.AllowGet));
        }
예제 #2
0
        public ApiResultModel SetShopInfo(ShopInfoModel model)
        {
            ApiResultModel resultModel = new ApiResultModel();

            try
            {
                //获取当前用户
                IShopUserBLL userBll = BLLFactory <IShopUserBLL> .GetBLL("ShopUserBLL");

                T_ShopUser user = userBll.GetEntity(u => u.Id == model.UserId && u.DelFlag == ConstantParam.DEL_FLAG_DEFAULT);

                if (user != null)
                {
                    //如果验证Token不通过或已过期
                    if (DateTime.Now > user.TokenInvalidTime || model.Token != user.Token)
                    {
                        resultModel.Msg = APIMessage.TOKEN_INVALID;
                        return(resultModel);
                    }
                    //更新最近登录时间和Token失效时间
                    user.LatelyLoginTime  = DateTime.Now;
                    user.TokenInvalidTime = DateTime.Now.AddDays(Convert.ToInt32(PropertyUtils.GetConfigParamValue("TokenInvalid")));
                    userBll.Update(user);

                    //调用商家BLL层获取商家信息
                    IShopBLL shopBll = BLLFactory <IShopBLL> .GetBLL("ShopBLL");

                    var shop = shopBll.GetEntity(s => s.Id == model.ShopId);

                    //设置主营内容
                    if (shop != null)
                    {
                        shop.ShopName = model.ShopName;
                        //shop.Content = model.ShopContent;
                        shop.MainSale          = model.MainSale;
                        shop.StartBusinessTime = model.StartBusinessTime;
                        shop.EndBusinessTime   = model.EndBusinessTime;
                        shop.Address           = model.Address;
                        shop.Phone             = model.Phone;
                        shop.UpdateTime        = DateTime.Now;
                        shopBll.Update(shop);
                    }
                }
                else
                {
                    resultModel.Msg = APIMessage.NO_USER;
                }
            }
            catch
            {
                resultModel.Msg = APIMessage.REQUEST_EXCEPTION;
            }

            return(resultModel);
        }
예제 #3
0
        public ActionResult SetCoverImg(CoverImgUploadModel model)
        {
            JsonModel jm = new JsonModel();

            IShopBLL shopBll = BLLFactory <IShopBLL> .GetBLL("ShopBLL");

            var shop = shopBll.GetEntity(index => index.Id == model.ShopId);

            try
            {
                //存入文件的路径
                string directory = Server.MapPath(ConstantParam.SHOP_IMG_DIR);
                if (!Directory.Exists(directory))
                {
                    Directory.CreateDirectory(directory);
                }
                //获取上传文件的扩展名
                string fileEx = Path.GetExtension(Path.GetFileName(model.CoverImgFile.FileName));
                //保存数据文件
                string fileName = DateTime.Now.ToFileTime().ToString() + fileEx;
                string savePath = Path.Combine(directory, fileName);
                model.CoverImgFile.SaveAs(savePath);
                shop.ImgPath = ConstantParam.SHOP_IMG_DIR + fileName;

                //判断缩略图路径是否存在
                if (!Directory.Exists(Server.MapPath(ConstantParam.SHOP_THUM_IMG_DIR)))
                {
                    Directory.CreateDirectory(Server.MapPath(ConstantParam.SHOP_THUM_IMG_DIR));
                }
                //生成缩略图
                string thumpFile = DateTime.Now.ToFileTime() + ".jpg";

                var thumpPath = Path.Combine(Server.MapPath(ConstantParam.SHOP_THUM_IMG_DIR), thumpFile);
                if (PropertyUtils.getThumImage(savePath, 18, 3, thumpPath))
                {
                    shop.ImgThumbnail = ConstantParam.SHOP_THUM_IMG_DIR + thumpFile;
                }
                shopBll.Update(shop);
            }
            catch
            {
                jm.Msg = "请求发生异常";
            }
            return(Json(jm, JsonRequestBehavior.AllowGet));
        }
예제 #4
0
        public ActionResult EditShop(ShopPlatformModel model)
        {
            JsonModel jm = new JsonModel();

            //如果表单验证成功
            if (ModelState.IsValid)
            {
                IShopBLL ShopBll = BLLFactory <IShopBLL> .GetBLL("ShopBLL");

                T_Shop shop = ShopBll.GetEntity(m => m.Id == model.Id);
                if (shop != null)
                {
                    shop.ShopName          = model.ShopName;
                    shop.Phone             = model.Tel;
                    shop.Address           = model.Address;
                    shop.MainSale          = model.MainSale;
                    shop.Content           = model.Content;
                    shop.StartBusinessTime = model.StartBusinessTime;
                    shop.EndBusinessTime   = model.EndBusinessTime;
                    shop.UpdateTime        = DateTime.Now;

                    //修改保存到数据库
                    if (ShopBll.Update(shop))
                    {
                        //日志记录
                        jm.Content = PropertyUtils.ModelToJsonString(model);
                    }
                    else
                    {
                        jm.Msg = "编辑失败";
                    }
                }
                else
                {
                    jm.Msg = "该门店不存在";
                }
            }
            else
            {
                jm.Msg = ConstantParam.JSON_RESULT_MODEL_CHECK_ERROR;
            }
            return(Json(jm, JsonRequestBehavior.AllowGet));
        }
예제 #5
0
        public JsonResult DelShopImg(int id, string href, string thum)
        {
            JsonModel Jm = new JsonModel();

            try
            {
                IShopBLL shopBLL = BLLFactory <IShopBLL> .GetBLL("ShopBLL");

                T_Shop Shop = shopBLL.GetEntity(a => a.Id == id);
                //删除缩略图路径
                int start = Shop.ImgThumbnail.IndexOf(href + ";");
                Shop.ImgThumbnail = Shop.ImgThumbnail.Remove(start, href.Length + 1);
                //获取缩略图片路径
                string path = Server.MapPath(href);
                //删除缩略图片
                if (System.IO.File.Exists(path))
                {
                    System.IO.File.Delete(path);
                }
                //获取大图片路径
                int thumStart = Shop.ImgPath.IndexOf(thum + ";");
                Shop.ImgPath = Shop.ImgPath.Remove(thumStart, thum.Length + 1);
                string thumPath = Server.MapPath(thum);
                if (System.IO.File.Exists(thumPath))
                {
                    try
                    {
                        //删除原图片
                        System.IO.File.Delete(thumPath);
                    }
                    catch { }
                }
                shopBLL.Update(Shop);
                //记录log
                Jm.Content = "删除门店图片" + href;
            }
            catch
            {
                Jm.Msg = "删除出现异常";
            }
            return(Json(Jm));
        }
예제 #6
0
        public ApiResultModel UploadShopImage(ShopImageModel model)
        {
            //string filePath = System.AppDomain.CurrentDomain.BaseDirectory + "YST.txt";
            //StreamWriter sw = new StreamWriter(filePath, true);
            //sw.Write("测试开始。。。");
            //sw.Close();
            ApiResultModel resultModel = new ApiResultModel();

            try
            {
                //获取要设置基本信息的物业用户
                IShopUserBLL userBll = BLLFactory <IShopUserBLL> .GetBLL("ShopUserBLL");

                T_ShopUser user = userBll.GetEntity(u => u.Id == model.UserId && u.DelFlag == ConstantParam.DEL_FLAG_DEFAULT);
                if (user != null)
                {
                    //如果验证Token不通过或已过期
                    if (DateTime.Now > user.TokenInvalidTime || model.Token != user.Token)
                    {
                        resultModel.Msg = APIMessage.TOKEN_INVALID;
                        return(resultModel);
                    }
                    //更新最近登录时间和Token失效时间
                    user.LatelyLoginTime  = DateTime.Now;
                    user.TokenInvalidTime = DateTime.Now.AddDays(Convert.ToInt32(PropertyUtils.GetConfigParamValue("TokenInvalid")));

                    userBll.Update(user);

                    //调用商家BLL层获取商家信息
                    IShopBLL shopBll = BLLFactory <IShopBLL> .GetBLL("ShopBLL");

                    var shop = shopBll.GetEntity(s => s.Id == model.ShopId);

                    if (shop != null)
                    {
                        //设定头像路径及文件名
                        string dir = HttpContext.Current.Server.MapPath(ConstantParam.SHOP_IMG_DIR);

                        if (!Directory.Exists(dir))
                        {
                            Directory.CreateDirectory(dir);
                        }
                        //设置商家封面
                        if (!string.IsNullOrEmpty(model.ShopImage))
                        {
                            var    fileName = DateTime.Now.ToFileTime().ToString() + ".zip";
                            string filepath = Path.Combine(dir, fileName);

                            using (FileStream fs = new FileStream(filepath, FileMode.Create))
                            {
                                using (BinaryWriter bw = new BinaryWriter(fs))
                                {
                                    byte[] datas = Convert.FromBase64String(model.ShopImage);
                                    bw.Write(datas);
                                    bw.Close();
                                }
                            }

                            //封面路径保存
                            shop.ImgPath = PropertyUtils.UnZip(filepath, dir, ConstantParam.SHOP_IMG_DIR);

                            StringBuilder imgsSB = new StringBuilder();
                            //生成缩略图保存
                            foreach (var path in shop.ImgPath.Split(';'))
                            {
                                string thumpFile = DateTime.Now.ToFileTime() + ".jpg";
                                string thumpPath = Path.Combine(HttpContext.Current.Server.MapPath(ConstantParam.SHOP_THUM_IMG_DIR), thumpFile);
                                PropertyUtils.getThumImage(Path.Combine(HttpContext.Current.Server.MapPath(path)), 18, 3, thumpPath);
                                imgsSB.Append(ConstantParam.SHOP_THUM_IMG_DIR + thumpFile + ";");
                            }

                            shop.ImgThumbnail = imgsSB.ToString();
                            shop.ImgThumbnail = shop.ImgThumbnail.Substring(0, shop.ImgThumbnail.Length - 1);
                        }

                        shopBll.Update(shop);
                    }
                }
                else
                {
                    resultModel.Msg = APIMessage.NO_USER;
                }
            }
            catch
            {
                resultModel.Msg = APIMessage.REQUEST_EXCEPTION;
            }

            return(resultModel);
        }