public JsonResult EditShopSales(ShopSaleModel Model) { JsonModel Jm = new JsonModel(); if (ModelState.IsValid) { //促销BLL IShopSaleBLL SaleBLL = BLLFactory <IShopSaleBLL> .GetBLL("ShopSaleBLL"); T_ShopSale ShopSale = SaleBLL.GetEntity(a => a.Id == Model.Id); if (ShopSale != null) { ShopSale.Title = Model.Title; ShopSale.Phone = Model.Phone; ShopSale.Content = Model.Content; ShopSale.GoodsCategoryId = Model.GoodsCategoryId.Value; ShopSale.RemainingAmout = Model.RemainingAmout; ShopSale.Price = Model.Price; //保存修改 SaleBLL.Update(ShopSale); } else { Jm.Msg = "该商品不存在"; } //记录日志 Jm.Content = Property.Common.PropertyUtils.ModelToJsonString(Model); } else { Jm.Msg = ConstantParam.JSON_RESULT_MODEL_CHECK_ERROR; } return(Json(Jm, JsonRequestBehavior.AllowGet)); }
public JsonResult AddShopSales(ShopSaleModel model) { JsonModel Jm = new JsonModel(); if (ModelState.IsValid) { var currentShopId = GetCurrentShopId(); //如果门店已创建 if (currentShopId != null) { T_ShopSale ShopSale = new T_ShopSale(); ShopSale.Title = model.Title; ShopSale.Phone = model.Phone; ShopSale.Content = model.Content; ShopSale.GoodsCategoryId = model.GoodsCategoryId.Value; ShopSale.RemainingAmout = model.RemainingAmout; ShopSale.Price = model.Price; ShopSale.CreateTime = DateTime.Now; ShopSale.InSales = 1; //促销BLL IShopSaleBLL SaleBLL = BLLFactory <IShopSaleBLL> .GetBLL("ShopSaleBLL"); //保存 SaleBLL.Save(ShopSale); //绿色直供推送 if (model.IsPush) { IShopBLL shopBLL = BLLFactory <IShopBLL> .GetBLL("ShopBLL"); string shopName = shopBLL.GetEntity(s => s.Id == currentShopId).ShopName; //推送给业主客户端 IUserPushBLL userPushBLL = BLLFactory <IUserPushBLL> .GetBLL("UserPushBLL"); var registrationIds = userPushBLL.GetList(p => !string.IsNullOrEmpty(p.RegistrationId)).Select(p => p.RegistrationId).ToArray(); string alert = shopName + "的商品" + model.Title + "上架了"; bool flag = PropertyUtils.SendPush("商品上架", alert, ConstantParam.MOBILE_TYPE_OWNER, registrationIds); if (!flag) { Jm.Msg = "推送发生异常"; } } //记录 Log Jm.Content = Property.Common.PropertyUtils.ModelToJsonString(model); } else { Jm.Msg = "门店还未创建"; } } else { Jm.Msg = ConstantParam.JSON_RESULT_MODEL_CHECK_ERROR; } return(Json(Jm, JsonRequestBehavior.AllowGet)); }
/// <summary> /// 促销详细页面 /// </summary> /// <param name="id">促销ID</param> /// <returns></returns> public ActionResult SaleDetail(int id) { //获取要查看详细的门店实体对象 IShopSaleBLL SaleBll = BLLFactory <IShopSaleBLL> .GetBLL("ShopSaleBLL"); T_ShopSale Sale = SaleBll.GetEntity(s => s.Id == id); return(View(Sale)); }
public JsonResult DelShopSales(int id) { JsonModel Jm = new JsonModel(); try { //促销BLL IShopSaleBLL SaleBLL = BLLFactory <IShopSaleBLL> .GetBLL("ShopSaleBLL"); T_ShopSale ShopSale = SaleBLL.GetEntity(a => a.Id == id); //图片集合 List <string> Path = new List <string>(); //缩略图集合 List <string> ThumPath = new List <string>(); if (!string.IsNullOrEmpty(ShopSale.ImgPath) && !string.IsNullOrEmpty(ShopSale.ImgThumbnail)) { Path = ShopSale.ImgPath.Split(new char[] { ';' }).ToList(); ThumPath = ShopSale.ImgThumbnail.Split(new char[] { ';' }).ToList(); } //删除文件 for (int i = 0; i < ThumPath.Count; i++) { if (!string.IsNullOrEmpty(Path[i].Trim())) { //删除缩略图 DelFile(ThumPath[i]); //删除图片 //DelFile(Path[i]); } } if (ShopSale.OrderDetails.Count > 0) { Jm.Msg = "该商品已被订购,无法删除"; } else { //执行删除 SaleBLL.Delete(ShopSale); } } catch { Jm.Msg = "删除失败"; } return(Json(Jm, JsonRequestBehavior.AllowGet)); }
public ActionResult Upload(int id) { //门店BLL IShopSaleBLL SaleBLL = BLLFactory <IShopSaleBLL> .GetBLL("ShopSaleBLL"); T_ShopSale Model = SaleBLL.GetEntity(a => a.Id == id); ShopSaleModel List = new ShopSaleModel(); List.Id = Model.Id; if (Model.ImgPath != null && Model.ImgThumbnail != null) { List <string> pathstr = Model.ImgPath.Split(new char[] { ';' }).ToList(); List <string> ThumPath = Model.ImgThumbnail.Split(new char[] { ';' }).ToList(); List.PathList = pathstr; List.ThumPathList = ThumPath; } return(View(List)); }
public ActionResult ReAddShopSales(int id) { JsonModel Jm = new JsonModel(); int ShopId = GetCurrentShopId().Value;//当前门店 IShopSaleBLL SaleBLL = BLLFactory <IShopSaleBLL> .GetBLL("ShopSaleBLL"); T_ShopSale ShopSale = SaleBLL.GetEntity(a => a.Id == id); if (ShopSale != null) { ShopSale.CreateTime = DateTime.Now; ShopSale.InSales = 1; } else { Jm.Msg = "该商品已经上架"; } SaleBLL.Update(ShopSale); return(Json(Jm, JsonRequestBehavior.AllowGet)); }
public ApiResultModel AddGoods(GoodsInfoModel 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); //商品分类实例化 T_ShopSale goods = new T_ShopSale() { Title = model.Name, Content = model.Content, CreateTime = DateTime.Now, GoodsCategoryId = model.GoodCategoryId, Price = model.Price, RemainingAmout = model.RemainingAmount, InSales = 1 }; //话题文件资源保存目录 string dir = HttpContext.Current.Server.MapPath(ConstantParam.SHOP_Sales); if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } //图片上传 if (!string.IsNullOrEmpty(model.PicList)) { 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.PicList); bw.Write(datas); bw.Close(); } } //图片集路径保存 goods.ImgPath = PropertyUtils.UnZip(filepath, dir, ConstantParam.SHOP_Sales); StringBuilder imgsSB = new StringBuilder(); //生成缩略图保存 foreach (var path in goods.ImgPath.Split(';')) { string thumpFile = DateTime.Now.ToFileTime() + ".jpg"; string thumpPath = Path.Combine(HttpContext.Current.Server.MapPath(ConstantParam.SHOP_Sales_ThumIMG), thumpFile); PropertyUtils.getThumImage(Path.Combine(HttpContext.Current.Server.MapPath(path)), 18, 3, thumpPath); imgsSB.Append(ConstantParam.SHOP_Sales_ThumIMG + "/" + thumpFile + ";"); } goods.ImgThumbnail = imgsSB.ToString(); goods.ImgThumbnail = goods.ImgThumbnail.Substring(0, goods.ImgThumbnail.Length - 1); } //保存商品 IShopSaleBLL goodsBLL = BLLFactory <IShopSaleBLL> .GetBLL("ShopSaleBLL"); goodsBLL.Save(goods); //绿色直供推送 if (model.IsPush == 1) { IShopBLL shopBLL = BLLFactory <IShopBLL> .GetBLL("ShopBLL"); string shopName = shopBLL.GetEntity(s => s.Id == model.ShopId).ShopName; //推送给业主客户端 IUserPushBLL userPushBLL = BLLFactory <IUserPushBLL> .GetBLL("UserPushBLL"); var registrationIds = userPushBLL.GetList(p => !string.IsNullOrEmpty(p.RegistrationId)).Select(p => p.RegistrationId).ToArray(); string alert = shopName + "的商品" + goods.Title + "上架了"; bool flag = PropertyUtils.SendPush("商品上架", alert, ConstantParam.MOBILE_TYPE_OWNER, registrationIds); if (!flag) { resultModel.Msg = "推送发生异常"; } } } else { resultModel.Msg = APIMessage.NO_USER; } } catch (Exception ex) { PropertyUtils.WriteLogInfo("test"); PropertyUtils.WriteLogError(ex); resultModel.Msg = APIMessage.REQUEST_EXCEPTION; } return(resultModel); }
public JsonResult DelFile(int id, string href, string thum) { JsonModel Jm = new JsonModel(); try { //促销BLL IShopSaleBLL SaleBLL = BLLFactory <IShopSaleBLL> .GetBLL("ShopSaleBLL"); T_ShopSale ShopSale = SaleBLL.GetEntity(a => a.Id == id); //删除缩略图路径 List <string> ImgThumbnailList = ShopSale.ImgThumbnail.Split(';').ToList(); ImgThumbnailList.Remove(href); string newImgThumbnails = ""; foreach (var item in ImgThumbnailList) { if (!string.IsNullOrEmpty(item.Trim())) { newImgThumbnails = newImgThumbnails + item + ";"; } } if (!string.IsNullOrEmpty(newImgThumbnails)) { newImgThumbnails = newImgThumbnails.Substring(0, newImgThumbnails.Length - 1); } ShopSale.ImgThumbnail = newImgThumbnails; //获取缩略图片文件 string path = Server.MapPath(href); if (System.IO.File.Exists(path)) { try { System.IO.File.Delete(path); } catch { } } //删除大图路径 List <string> ImgPathList = ShopSale.ImgPath.Split(';').ToList(); ImgPathList.Remove(thum); string newImgPaths = ""; foreach (var item in ImgPathList) { if (!string.IsNullOrEmpty(item.Trim())) { newImgPaths = newImgPaths + item + ";"; } } if (!string.IsNullOrEmpty(newImgPaths)) { newImgPaths = newImgPaths.Substring(0, newImgPaths.Length - 1); } ShopSale.ImgPath = newImgPaths; string thumPath = Server.MapPath(thum); if (System.IO.File.Exists(thumPath)) { try { //删除原图片 System.IO.File.Delete(thumPath); } catch { } } SaleBLL.Update(ShopSale); //记录log Jm.Content = "删除商品图片" + href; } catch { Jm.Msg = "删除出现异常"; } return(Json(Jm)); }
public JsonResult Upload(ShopSaleModel Model) { JsonModel jm = new JsonModel(); try { //促销BLL IShopSaleBLL SaleBLL = BLLFactory <IShopSaleBLL> .GetBLL("ShopSaleBLL"); T_ShopSale ShopSale = SaleBLL.GetEntity(a => a.Id == Model.Id); //图片路径 string PathList = string.IsNullOrEmpty(ShopSale.ImgPath) ? "" : ShopSale.ImgPath + ";"; //缩略图路径 string ThumPathList = string.IsNullOrEmpty(ShopSale.ImgThumbnail) ? "" : ShopSale.ImgThumbnail + ";"; int currentImgCount = PathList.Split(';').Count() - 1; if (Request.Files.Count + currentImgCount > 6) { jm.Msg = "最多只能上传6张商品图片"; return(Json(jm, JsonRequestBehavior.AllowGet)); } 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 (!System.IO.Directory.Exists(Server.MapPath(ConstantParam.SHOP_Sales))) { System.IO.Directory.CreateDirectory(Server.MapPath(ConstantParam.SHOP_Sales)); } //判断缩略图路径是否存在 if (!System.IO.Directory.Exists(Server.MapPath(ConstantParam.SHOP_Sales_ThumIMG))) { System.IO.Directory.CreateDirectory(Server.MapPath(ConstantParam.SHOP_Sales_ThumIMG)); } //保存图片 var path = Path.Combine(Server.MapPath(ConstantParam.SHOP_Sales), fileName); file.SaveAs(path); //生成缩略图 string thumpFile = DateTime.Now.ToFileTime() + ".jpg"; var thumpPath = Path.Combine(Server.MapPath(ConstantParam.SHOP_Sales_ThumIMG), thumpFile); PropertyUtils.getThumImage(path, 18, 3, thumpPath); PathList += ConstantParam.SHOP_Sales + "/" + fileName + ";"; ThumPathList += ConstantParam.SHOP_Sales_ThumIMG + "/" + thumpFile + ";"; } } ShopSale.ImgPath = PathList.Substring(0, PathList.Length - 1); ShopSale.ImgThumbnail = ThumPathList.Substring(0, ThumPathList.Length - 1);; //保存 SaleBLL.Update(ShopSale); jm.Content = "商品:" + Model.Title + "上传图片"; } catch (Exception e) { jm.Msg = e.Message; } return(Json(jm, JsonRequestBehavior.AllowGet)); }