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 ActionResult EditShopSales(int id)
        {
            //初始化模型
            ShopSaleModel model = new ShopSaleModel();
            //促销BLL
            IShopSaleBLL SaleBLL = BLLFactory <IShopSaleBLL> .GetBLL("ShopSaleBLL");

            var lst = SaleBLL.GetEntity(a => a.Id == id);

            if (lst != null)
            {
                model.Id                = lst.Id;
                model.Title             = lst.Title;
                model.Content           = lst.Content;
                model.Phone             = lst.Phone;
                model.RemainingAmout    = lst.RemainingAmout;
                model.Price             = lst.Price;
                model.GoodsCategoryId   = lst.GoodsCategoryId;
                model.GoodsCategoryList = GetGoodsCategoryList(lst.GoodsCategory.ShopId);
                return(View(model));
            }
            else
            {
                return(RedirectToAction("SaleList"));
            }
        }
        public ActionResult SaleList(ShopSaleSearchModel model)
        {
            //如果门店已创建
            if (GetCurrentShopId() != null)
            {
                int ShopId = GetCurrentShopId().Value;
                //促销BLL
                IShopSaleBLL SaleBLL = BLLFactory <IShopSaleBLL> .GetBLL("ShopSaleBLL");

                //条件
                Expression <Func <T_ShopSale, bool> > whereLambda = a => a.GoodsCategory.ShopId == ShopId;
                if (!string.IsNullOrEmpty(model.Kword))
                {
                    whereLambda = PredicateBuilder.And <T_ShopSale>(whereLambda, a => a.Title.Contains(model.Kword));
                }
                if (model.InSale != null)
                {
                    whereLambda = PredicateBuilder.And(whereLambda, u => u.InSales == model.InSale.Value);
                }
                if (model.GoodsCategoryId != null)
                {
                    whereLambda = PredicateBuilder.And <T_ShopSale>(whereLambda, a => a.GoodsCategoryId == model.GoodsCategoryId.Value);
                }
                var sortModel = SettingSorting("Id", false);
                //查询数据
                model.ResultList        = SaleBLL.GetPageList(whereLambda, sortModel.SortName, sortModel.IsAsc, model.PageIndex) as PagedList <T_ShopSale>;
                model.GoodsCategoryList = GetGoodsCategoryList(ShopId);
                model.GoodsStateList    = GetGoodsGoodsStateList(null);
                return(View(model));
            }
            else
            {
                return(View());
            }
        }
Beispiel #4
0
        /// <summary>
        /// 取消订单
        /// </summary>
        /// <param name="order">要取消的订单实体对象</param>
        /// <returns></returns>
        public bool CancelOrder(T_Order order)
        {
            //使用事务进行数据库操作
            using (var tran = this.nContext.Database.BeginTransaction())
            {
                try
                {
                    IShopSaleBLL saleBll = BLLFactory <IShopSaleBLL> .GetBLL("ShopSaleBLL");

                    //更新商品剩余数量
                    foreach (var Goods in order.OrderDetails)
                    {
                        var sale = saleBll.GetEntity(s => s.Id == Goods.ShopSaleId);
                        sale.RemainingAmout = sale.RemainingAmout + Goods.SaledAmount;
                        saleBll.Update(sale);
                    }
                    //更新
                    base.Update(order);
                    //提交事务
                    tran.Commit();
                }
                catch
                {
                    tran.Rollback();
                    return(false);
                }
            }
            return(true);
        }
        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));
        }
        public ApiPageResultModel GetSaleList([FromUri] GoodsSearchModel model)
        {
            ApiPageResultModel resultModel = new ApiPageResultModel();

            try
            {
                //根据用户ID查找业主
                IUserBLL ownerBll = BLLFactory <IUserBLL> .GetBLL("UserBLL");

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

                    //该门店销售中的商品
                    Expression <Func <T_ShopSale, bool> > where = s => s.GoodsCategory.ShopId == model.ShopId && s.InSales == 1;
                    //如果选择了商品分类
                    if (model.GoodsCategoryId > 0)
                    {
                        where = PredicateBuilder.And(where, s => s.GoodsCategoryId == model.GoodsCategoryId);
                    }
                    //获取指定门店指定类别的商品列表
                    IShopSaleBLL SaleBll = BLLFactory <IShopSaleBLL> .GetBLL("ShopSaleBLL");

                    resultModel.Total  = SaleBll.Count(where);
                    resultModel.result = SaleBll.GetPageList(where, "Id", false, model.PageIndex).ToList().Select(s => new
                    {
                        GoodsId        = s.Id,
                        GoodsName      = s.Title,
                        GoodsDesc      = s.Content,
                        RemainingAmout = s.RemainingAmout,
                        SellAmout      = s.OrderDetails.Where(od => od.Order.OrderStatus == ConstantParam.OrderStatus_FINISH).Select(od => od.SaledAmount).ToArray().Sum(),
                        GoodsCoverImg  = string.IsNullOrEmpty(s.ImgThumbnail) ? "" : s.ImgThumbnail.Split(';')[0],
                        GoodsOtherImg  = string.IsNullOrEmpty(s.ImgPath) ? "" : s.ImgPath,
                        Price          = s.Price
                    });
                }
                else
                {
                    resultModel.Msg = APIMessage.NO_USER;
                }
            }
            catch
            {
                resultModel.Msg = APIMessage.REQUEST_EXCEPTION;
            }
            return(resultModel);
        }
Beispiel #7
0
        /// <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 ShopSalesValidate(int id, string Title)
        {
            bool result = true;
            //促销BLL
            IShopSaleBLL SaleBLL = BLLFactory <IShopSaleBLL> .GetBLL("ShopSaleBLL");

            result = (SaleBLL.GetEntity(a => a.Id != id && a.Title.Equals(Title)) == null);
            return(Json(result, JsonRequestBehavior.AllowGet));
        }
Beispiel #9
0
        /// <summary>
        /// 修改订单
        /// </summary>
        /// <param name="order">订单模型</param>
        /// <param name="goodsDic">订单中的商品数据</param>
        /// <returns>是否修改成功</returns>
        public bool UpdateOrder(T_Order order, Dictionary <int, int> goodsDic)
        {
            //使用事务进行数据库操作
            using (var tran = this.nContext.Database.BeginTransaction())
            {
                try
                {
                    IShopSaleBLL saleBll = BLLFactory <IShopSaleBLL> .GetBLL("ShopSaleBLL");

                    //更新商品剩余数量
                    foreach (var Goods in order.OrderDetails)
                    {
                        var sale = saleBll.GetEntity(s => s.Id == Goods.ShopSaleId);
                        sale.RemainingAmout = sale.RemainingAmout + Goods.SaledAmount;
                        saleBll.Update(sale);
                    }

                    //删除该订单中的商品详细关联数据
                    this.nContext.Database.ExecuteSqlCommand("delete from T_OrderDetails where OrderId=" + order.Id);

                    //重新给订单添加商品
                    foreach (var Goods in goodsDic)
                    {
                        var sale = saleBll.GetEntity(s => s.Id == Goods.Key);
                        if (sale != null)
                        {
                            order.OrderDetails.Add(new T_OrderDetails()
                            {
                                ShopSaleId  = Goods.Key,
                                SaledAmount = Goods.Value,
                                Price       = sale.Price * Goods.Value
                            });
                            sale.RemainingAmout = sale.RemainingAmout + Goods.Value;
                            saleBll.Update(sale);
                        }
                    }
                    //更新
                    base.Update(order);
                    //提交事务
                    tran.Commit();
                }
                catch
                {
                    tran.Rollback();
                    return(false);
                }
            }
            return(true);
        }
        public ActionResult ShopSalesDetail(int id = 0)
        {
            //促销BLL
            IShopSaleBLL SaleBLL = BLLFactory <IShopSaleBLL> .GetBLL("ShopSaleBLL");

            var lst = SaleBLL.GetEntity(a => a.Id == id);

            if (lst != null)
            {
                return(View(lst));
            }
            else
            {
                return(RedirectToAction("SaleList"));
            }
        }
        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));
        }
Beispiel #13
0
        /// <summary>
        /// 获取指定门店促销分页列表数据
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="ShopId"></param>
        /// <returns></returns>
        public JsonResult ShopSaleList(int pageIndex, int shopId)
        {
            IShopSaleBLL SaleBll = BLLFactory <IShopSaleBLL> .GetBLL("ShopSaleBLL");

            var list = SaleBll.GetPageList(s => s.GoodsCategory.ShopId == shopId, "Id", false, pageIndex).Select(s => new
            {
                Id      = s.Id,
                Title   = s.Title,
                Content = s.Content.Length > 30 ? s.Content.Substring(0, 30) : s.Content,
                SaleImg = string.IsNullOrEmpty(s.ImgThumbnail) ? "" : s.ImgThumbnail.Split(';')[0]
            }).ToList();

            ApiPageResultModel model = new ApiPageResultModel();

            model.Total  = SaleBll.Count(s => s.GoodsCategory.ShopId == shopId);
            model.result = list;
            return(Json(model, JsonRequestBehavior.AllowGet));
        }
        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));
        }
Beispiel #15
0
        public ApiResultModel SetOnSale(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);

                    if (model.Id.HasValue)
                    {
                        IShopSaleBLL shopSaleBll = BLLFactory <IShopSaleBLL> .GetBLL("ShopSaleBLL");

                        var goods = shopSaleBll.GetEntity(g => g.Id == model.Id.Value);
                        //修改商品上/下架
                        if (goods != null)
                        {
                            goods.InSales = model.InSales;

                            if (goods.InSales == 0)
                            {
                                goods.UnShelveTime = DateTime.Now;
                            }
                            else
                            {
                                goods.CreateTime = DateTime.Now;
                            }

                            shopSaleBll.Update(goods);
                        }
                        else
                        {
                            resultModel.Msg = "不存在当前商品分类";
                        }
                    }
                }
                else
                {
                    resultModel.Msg = APIMessage.NO_USER;
                }
            }
            catch
            {
                resultModel.Msg = APIMessage.REQUEST_EXCEPTION;
            }

            return(resultModel);
        }
Beispiel #16
0
        public ApiResultModel DelGoods(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);

                    if (model.Id.HasValue)
                    {
                        IShopSaleBLL shopSaleBll = BLLFactory <IShopSaleBLL> .GetBLL("ShopSaleBLL");

                        var goods = shopSaleBll.GetEntity(g => g.Id == model.Id.Value);

                        if (goods == null)
                        {
                            resultModel.Msg = "该商品不存在";
                        }
                        else
                        {
                            if (goods.OrderDetails.Count > 0)
                            {
                                resultModel.Msg = "该商品已被订购,无法删除";
                            }
                            else
                            {
                                var imagePath    = goods.ImgPath;
                                var imgThumbnail = goods.ImgThumbnail;

                                shopSaleBll.Delete(goods);

                                if (!string.IsNullOrWhiteSpace(imagePath))
                                {
                                    if (imagePath.Contains(";"))
                                    {
                                        foreach (var path in imagePath.Split(';'))
                                        {
                                            DelFile(path);
                                        }
                                    }
                                    else
                                    {
                                        DelFile(imagePath);
                                    }
                                }

                                if (!string.IsNullOrWhiteSpace(imgThumbnail))
                                {
                                    if (imgThumbnail.Contains(";"))
                                    {
                                        foreach (var path in imgThumbnail.Split(';'))
                                        {
                                            DelFile(path);
                                        }
                                    }
                                    else
                                    {
                                        DelFile(imgThumbnail);
                                    }
                                }
                            }
                        }
                    }
                }
                else
                {
                    resultModel.Msg = APIMessage.NO_USER;
                }
            }
            catch
            {
                resultModel.Msg = APIMessage.REQUEST_EXCEPTION;
            }

            return(resultModel);
        }
Beispiel #17
0
        public ApiResultModel EditGoods(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);

                    if (model.Id.HasValue)
                    {
                        IShopSaleBLL shopSaleBll = BLLFactory <IShopSaleBLL> .GetBLL("ShopSaleBLL");

                        var goods = shopSaleBll.GetEntity(g => g.Id == model.Id.Value);

                        //修改商品分类
                        if (goods != null)
                        {
                            //基础信息
                            goods.Title           = model.Name;
                            goods.Content         = model.Content;
                            goods.Price           = model.Price;
                            goods.RemainingAmout  = model.RemainingAmount;
                            goods.GoodsCategoryId = model.GoodCategoryId;

                            //图片和压缩图
                            var sourceImgList           = goods.ImgPath == null ? null : goods.ImgPath.Split(';').ToList();
                            var sourceImgThumbnailArray = goods.ImgThumbnail == null ? null : goods.ImgThumbnail.Split(';').ToArray();

                            var remainingImgList          = goods.ImgPath == null ? new List <string>() : goods.ImgPath.Split(';').ToList();
                            var remainingImgThumbnailList = goods.ImgThumbnail == null ? new List <string>() : goods.ImgThumbnail.Split(';').ToList();


                            //要删除的缩略图列表
                            var delImgThumbnailList = new List <string>();

                            if (sourceImgList != null)
                            {
                                //对要删除的图片列表进行删除
                                if (!string.IsNullOrWhiteSpace(model.delPicList))
                                {
                                    foreach (var path in model.delPicList.Split(';'))
                                    {
                                        int index = sourceImgList.FindIndex(m => m == path);

                                        if (index < sourceImgThumbnailArray.Count())
                                        {
                                            delImgThumbnailList.Add(sourceImgThumbnailArray[index]);
                                        }

                                        remainingImgList.Remove(path);
                                        DelFile(path);
                                    }
                                }
                            }


                            foreach (var path in delImgThumbnailList)
                            {
                                remainingImgThumbnailList.Remove(path);
                                DelFile(path);
                            }

                            var strRemainedImg = "";

                            foreach (var item in remainingImgList)
                            {
                                if (!string.IsNullOrEmpty(item.Trim()))
                                {
                                    strRemainedImg = strRemainedImg + item + ";";
                                }
                            }

                            var strReminedThumbnailImg = "";

                            foreach (var item in remainingImgThumbnailList)
                            {
                                if (!string.IsNullOrEmpty(item.Trim()))
                                {
                                    strReminedThumbnailImg = strReminedThumbnailImg + item + ";";
                                }
                            }

                            //图片上传
                            if (!string.IsNullOrEmpty(model.PicList))
                            {
                                //文件资源保存目录
                                string dir = HttpContext.Current.Server.MapPath(ConstantParam.SHOP_Sales);

                                if (!Directory.Exists(dir))
                                {
                                    Directory.CreateDirectory(dir);
                                }

                                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();
                                    }
                                }

                                var imgZipParth = PropertyUtils.UnZip(filepath, dir, ConstantParam.SHOP_Sales);
                                //图片集路径保存
                                goods.ImgPath = strRemainedImg + imgZipParth;

                                StringBuilder imgsSB = new StringBuilder();
                                //生成缩略图保存
                                foreach (var path in imgZipParth.Split(';'))
                                {
                                    string thumpFile = DateTime.Now.ToFileTime().ToString() + ".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 = strReminedThumbnailImg + goods.ImgThumbnail.Substring(0, goods.ImgThumbnail.Length - 1);
                            }
                            else
                            {
                                goods.ImgPath      = strRemainedImg;
                                goods.ImgThumbnail = strReminedThumbnailImg;
                            }

                            shopSaleBll.Update(goods);
                        }
                        else
                        {
                            resultModel.Msg = "不存在当前商品";
                        }
                    }
                }
                else
                {
                    resultModel.Msg = APIMessage.NO_USER;
                }
            }
            catch
            {
                resultModel.Msg = APIMessage.REQUEST_EXCEPTION;
            }

            return(resultModel);
        }
Beispiel #18
0
        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);
        }
Beispiel #19
0
        public ApiResultModel GetGoods([FromUri] 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);

                    if (model.Id.HasValue)
                    {
                        IShopSaleBLL shopSaleBll = BLLFactory <IShopSaleBLL> .GetBLL("ShopSaleBLL");

                        var goods = shopSaleBll.GetEntity(g => g.Id == model.Id.Value);
                        //商品详情
                        if (goods != null)
                        {
                            resultModel.result = new
                            {
                                Name              = goods.Title,
                                Content           = goods.Content,
                                Price             = goods.Price,
                                RemaintAmount     = goods.RemainingAmout,
                                GoodsCategoryId   = goods.GoodsCategoryId,
                                GoodsCategoryName = goods.GoodsCategory.Name,
                                ImgPath           = goods.ImgPath,
                                ImgThumbnail      = goods.ImgThumbnail
                            };
                        }
                        else
                        {
                            resultModel.Msg = "不存在当前商品";
                        }
                    }
                }
                else
                {
                    resultModel.Msg = APIMessage.NO_USER;
                }
            }
            catch
            {
                resultModel.Msg = APIMessage.REQUEST_EXCEPTION;
            }

            return(resultModel);
        }
Beispiel #20
0
        public ApiPageResultModel GetGoodsList([FromUri] GoodsSearchModel model)
        {
            ApiPageResultModel resultModel = new ApiPageResultModel();

            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);

                    Expression <Func <T_ShopSale, bool> > where = s => s.InSales == model.InSales && s.GoodsCategory.ShopId == model.ShopId;

                    if (model.GoodsCategoryId > 0)
                    {
                        where = PredicateBuilder.And(where, s => s.GoodsCategoryId == model.GoodsCategoryId);
                    }

                    IOrderBLL orderBll = BLLFactory <IOrderBLL> .GetBLL("OrderBLL");

                    IShopSaleBLL shopSaleBLL = BLLFactory <IShopSaleBLL> .GetBLL("ShopSaleBLL");

                    var list = shopSaleBLL.GetPageList(where, "CreateTime", false, model.PageIndex).Select(
                        s => new
                    {
                        Id             = s.Id,
                        ImgThumbnail   = string.IsNullOrEmpty(s.ImgThumbnail) ? "" : s.ImgThumbnail.Split(';').FirstOrDefault(),
                        Title          = s.Title,
                        Price          = s.Price,
                        RemainingAmout = s.RemainingAmout,
                        SaledCount     = s.OrderDetails.Where(od => od.Order.OrderStatus == ConstantParam.OrderStatus_FINISH).Select(od => od.SaledAmount).ToArray().Sum(),
                        CreateDate     = s.CreateTime.ToString("yyyy-MM-dd HH:mm:ss"),
                        UnShelveTime   = s.UnShelveTime.HasValue ? s.UnShelveTime.Value.ToString("yyyy-MM-dd HH:mm:ss") : "",
                        InSales        = s.InSales
                    });

                    resultModel.result = list;
                    resultModel.Total  = shopSaleBLL.Count(where);
                }
                else
                {
                    resultModel.Msg = APIMessage.NO_USER;
                }
            }
            catch
            {
                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));
        }