Beispiel #1
0
        public ApiResultModel GetShopInfo([FromUri] 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)
                    {
                        resultModel.result = new
                        {
                            ShopName          = shop.ShopName,
                            ShopContent       = string.Format("MobilePage/StoreIntroduce?ShopId={0}", shop.Id),
                            ShopMainSale      = shop.MainSale,
                            StartBusinessTime = shop.StartBusinessTime,
                            EndBusinessTime   = shop.EndBusinessTime,
                            ShopAddress       = shop.Address,
                            Phone             = shop.Phone,
                            ShopPicList       = shop.ImgPath
                        };
                    }
                    else
                    {
                        resultModel.Msg = APIMessage.NO_APP;
                    }
                }
                else
                {
                    resultModel.Msg = APIMessage.NO_USER;
                }
            }
            catch
            {
                resultModel.Msg = APIMessage.REQUEST_EXCEPTION;
            }

            return(resultModel);
        }
Beispiel #2
0
        public ApiResultModel EditGoodsCategory(GoodsCategoryInfoModel 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)
                    {
                        IGoodsCategoryBLL goodsBLL = BLLFactory <IGoodsCategoryBLL> .GetBLL("GoodsCategoryBLL");

                        if (goodsBLL.Exist(m => m.Name == model.Name && m.Id != model.Id && m.ShopId == model.ShopId))
                        {
                            resultModel.Msg = "该商品类别已经存在";
                        }
                        else
                        {
                            var goodsCategory = goodsBLL.GetEntity(g => g.Id == model.Id.Value);
                            //修改商品分类
                            if (goodsCategory != null)
                            {
                                goodsCategory.Name = model.Name;
                                goodsBLL.Update(goodsCategory);
                            }
                            else
                            {
                                resultModel.Msg = "不存在当前商品分类";
                            }
                        }
                    }
                }
                else
                {
                    resultModel.Msg = APIMessage.NO_USER;
                }
            }
            catch
            {
                resultModel.Msg = APIMessage.REQUEST_EXCEPTION;
            }

            return(resultModel);
        }
        public JsonResult AddShopUser(ShopUserModel Model)
        {
            JsonModel jm = new JsonModel();

            //如果表单验证成功
            if (ModelState.IsValid)
            {
                IShopUserBLL shopUserBll = BLLFactory <IShopUserBLL> .GetBLL("ShopUserBLL");

                T_ShopUser shopUser = new T_ShopUser()
                {
                    UserName = Model.UserName,
                    TrueName = Model.TrueName,
                    Phone    = Model.Phone,
                    Gender   = Model.Gender,
                    Email    = Model.Email,
                    Password = PropertyUtils.GetMD5Str(Model.Password),
                    Memo     = Model.Memo
                };
                //保存到数据库
                shopUserBll.Save(shopUser);
                //日志记录
                jm.Content = PropertyUtils.ModelToJsonString(Model);
            }
            else
            {
                //保存异常日志
                jm.Msg = ConstantParam.JSON_RESULT_MODEL_CHECK_ERROR;
            }
            return(Json(jm, JsonRequestBehavior.AllowGet));
        }
        public ActionResult EditShopUser(int id)
        {
            IShopUserBLL shopUserBll = BLLFactory <IShopUserBLL> .GetBLL("ShopUserBLL");

            //获取要编辑的门店用户
            T_ShopUser shopUser = shopUserBll.GetEntity(m => m.Id == id && m.DelFlag == ConstantParam.DEL_FLAG_DEFAULT);

            if (shopUser != null)
            {
                //初始化返回页面的模型
                ShopUserModel model = new ShopUserModel()
                {
                    Id         = shopUser.Id,
                    UserName   = shopUser.UserName,
                    TrueName   = shopUser.TrueName,
                    Phone      = shopUser.Phone,
                    Gender     = shopUser.Gender,
                    GenderList = GetGenderList(),
                    Email      = shopUser.Email,
                    Memo       = shopUser.Memo
                };
                return(View(model));
            }
            else
            {
                return(RedirectToAction("ShopUserList"));
            }
        }
Beispiel #5
0
        public ApiResultModel GetShopUserInfo([FromUri] TokenModel 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);

                    var shop = user.Shops.FirstOrDefault();
                    //如果商家信息不为空
                    if (shop != null)
                    {
                        resultModel.result = new
                        {
                            ShopUserName  = user.UserName,
                            ShopUserImage = user.HeadPath,
                            ShopName      = shop.ShopName,
                            TrueName      = user.TrueName,
                            UserGender    = user.Gender.HasValue ? user.Gender.Value == 1 ? "男" : "女" : "",
                            PhoneNumber   = user.Phone,
                            Email         = user.Email
                        };
                    }
                    else
                    {
                        resultModel.Msg = APIMessage.SHOP_NOEXIST;
                    }
                }
                else
                {
                    resultModel.Msg = APIMessage.NO_USER;
                }
            }
            catch
            {
                resultModel.Msg = APIMessage.REQUEST_EXCEPTION;
            }

            return(resultModel);
        }
Beispiel #6
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);
        }
Beispiel #7
0
        public ApiPageResultModel GetGoodsCategoryList([FromUri] GoodsCategorySearchModel 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);

                    IGoodsCategoryBLL goodsBLL = BLLFactory <IGoodsCategoryBLL> .GetBLL("GoodsCategoryBLL");

                    Expression <Func <T_GoodsCategory, bool> > where = g => g.ShopId == model.ShopId;
                    // 获取商家的商品分类
                    var list = goodsBLL.GetPageList(where, model.PageIndex).Select(
                        g => new
                    {
                        Id    = g.Id,
                        Name  = g.Name,
                        Count = g.ShopSales.Count()
                    }).ToList();

                    resultModel.result = list;
                    resultModel.Total  = goodsBLL.Count(g => g.ShopId == model.ShopId);
                }
                else
                {
                    resultModel.Msg = APIMessage.NO_USER;
                }
            }
            catch
            {
                resultModel.Msg = APIMessage.REQUEST_EXCEPTION;
            }

            return(resultModel);
        }
Beispiel #8
0
        /// <summary>
        /// 保存门店用户的session信息
        /// </summary>
        /// <param name="user">登录的时候取出数据再赋值</param>
        private void SetUserSessiong(T_ShopUser user, IShopUserBLL bll)
        {
            //用户session模型
            UserSessionModel sessionInfo = new UserSessionModel();

            //设置基本信息
            sessionInfo.UserID   = user.Id;
            sessionInfo.UserName = user.UserName;
            sessionInfo.TrueName = user.TrueName;
            sessionInfo.UserType = ConstantParam.USER_TYPE_SHOP;
            sessionInfo.HeadPath = user.HeadPath;
            //设置session信息
            Session[ConstantParam.SESSION_USERINFO] = sessionInfo;
        }
Beispiel #9
0
        public ActionResult ShopPlatformLogin(AccountModel model)
        {
            //判断提交模型数据是否正确
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            string code = (string)Session["ValidateCode"];

            if (model.CheckCode != code)
            {
                ModelState.AddModelError("CheckCode", "验证码不正确");
                return(View(model));
            }

            //根据用户名查找门店平台用户
            IShopUserBLL shopUserBll = BLLFactory <IShopUserBLL> .GetBLL("ShopUserBLL");

            T_ShopUser user = shopUserBll.GetEntity(u => u.UserName == model.UserName.Trim() &&
                                                    u.DelFlag == ConstantParam.DEL_FLAG_DEFAULT);

            //1.判断用户名是否正确
            if (user == null)
            {
                ModelState.AddModelError("UserName", "用户名不存在");
                return(View(model));
            }

            //2.判断密码是否正确
            string md5Str = PropertyUtils.GetMD5Str(model.Password);

            if (user.Password != md5Str)
            {
                ModelState.AddModelError("Password", "密码不正确");
                return(View(model));
            }

            //3.保存基本信息到session中
            this.SetUserSessiong(user, shopUserBll);
            BreadCrumb.ClearState();

            //4.跳转到
            return(RedirectToAction("Index", "ShopPlatform"));
        }
        public ActionResult SetShopUserInfo(LoggedInAccountModel model)
        {
            JsonModel jm = new JsonModel();

            //如果表单模型验证成功
            if (ModelState.IsValid)
            {
                // 获取Session Model
                UserSessionModel sessionModel = (UserSessionModel)Session[ConstantParam.SESSION_USERINFO];
                var id = sessionModel.UserID;

                IShopUserBLL shopUserBll = BLLFactory <IShopUserBLL> .GetBLL("ShopUserBLL");

                T_ShopUser shopUser = shopUserBll.GetEntity(m => m.Id == model.UserId && m.DelFlag == ConstantParam.DEL_FLAG_DEFAULT);//查询
                //如果数据为空,将输入数据写入
                if (shopUser != null)
                {
                    shopUser.TrueName = model.TrueName;
                    shopUser.Phone    = model.Phone;
                    shopUser.Email    = model.Email;
                    shopUser.Memo     = model.Memo;
                    // 保存到数据库
                    shopUserBll.Update(shopUser);

                    //更新SessionModel中的最新个人信息
                    sessionModel.TrueName = model.TrueName;

                    //日志记录
                    jm.Content = PropertyUtils.ModelToJsonString(model);
                }
                else
                {
                    jm.Msg = "该用户不存在";
                }
            }
            else
            {
                // 保存异常日志
                jm.Msg = ConstantParam.JSON_RESULT_MODEL_CHECK_ERROR;
            }
            return(Json(jm, JsonRequestBehavior.AllowGet));
        }
Beispiel #11
0
        public JsonResult EditShopUser(ShopUserModel model)
        {
            JsonModel jm = new JsonModel();

            //如果表单验证成功
            if (ModelState.IsValid)
            {
                IShopUserBLL shopUserBll = BLLFactory <IShopUserBLL> .GetBLL("ShopUserBLL");

                T_ShopUser shopUser = shopUserBll.GetEntity(m => m.Id == model.Id && m.DelFlag == ConstantParam.DEL_FLAG_DEFAULT);
                if (shopUser != null)
                {
                    shopUser.UserName = model.UserName;
                    shopUser.TrueName = model.TrueName;
                    shopUser.Email    = model.Email;
                    shopUser.Gender   = model.Gender;
                    shopUser.Phone    = model.Phone;
                    shopUser.Memo     = model.Memo;
                    //保存到数据库
                    if (shopUserBll.Update(shopUser))
                    {
                        //日志记录
                        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));
        }
        public ActionResult EditShopUserPwd(AccountPasswordChangeModel model)
        {
            JsonModel jm = new JsonModel();

            //如果表单模型验证成功
            if (ModelState.IsValid)
            {
                UserSessionModel sessionModel = (UserSessionModel)Session[ConstantParam.SESSION_USERINFO];
                var id = sessionModel.UserID;

                // 若当前登录用户为门店用户
                IShopUserBLL shopUserBll = BLLFactory <IShopUserBLL> .GetBLL("ShopUserBLL");

                T_ShopUser shopUser = shopUserBll.GetEntity(m => m.Id == model.UserId && m.DelFlag == ConstantParam.DEL_FLAG_DEFAULT);
                if (shopUser != null)
                {
                    shopUser.Password         = PropertyUtils.GetMD5Str(model.Password);
                    shopUser.Token            = null;
                    shopUser.TokenInvalidTime = null;

                    // 保存到数据库
                    shopUserBll.Update(shopUser);

                    //日志记录
                    jm.Content = PropertyUtils.ModelToJsonString(model);
                }
                else
                {
                    jm.Msg = "该门店用户不存在";
                }
            }
            else
            {
                // 保存异常日志
                jm.Msg = ConstantParam.JSON_RESULT_MODEL_CHECK_ERROR;
            }
            return(Json(jm, JsonRequestBehavior.AllowGet));
        }
Beispiel #13
0
        public JsonResult DeleteShopUser(int id)
        {
            JsonModel jm = new JsonModel();
            //获取要删除的门店用户
            IShopUserBLL shopUserBll = BLLFactory <IShopUserBLL> .GetBLL("ShopUserBLL");

            T_ShopUser shopUser = shopUserBll.GetEntity(m => m.Id == id && m.DelFlag == ConstantParam.DEL_FLAG_DEFAULT);

            //如果该门店用户存在
            if (shopUser == null)
            {
                jm.Msg = "该门店用户不存在";
            }
            else
            {
                //修改门店用户中的已删除标识
                shopUser.DelFlag = ConstantParam.DEL_FLAG_DELETE;
                shopUserBll.DeleteShopUser(shopUser);
                //操作日志
                jm.Content = "删除门店用户" + shopUser.UserName;
            }
            return(Json(jm, JsonRequestBehavior.AllowGet));
        }
Beispiel #14
0
        public ActionResult AddShop(int Id)
        {
            IShopUserBLL shopUserBll = BLLFactory <IShopUserBLL> .GetBLL("ShopUserBLL");

            T_ShopUser shopUser = shopUserBll.GetEntity(m => m.Id == Id && m.DelFlag == ConstantParam.DEL_FLAG_DEFAULT);

            if (shopUser != null)
            {
                ShopModel model = new ShopModel();
                model.TypeList     = GetTypeList();
                model.ProvinceList = GetProvinceList();
                model.CityList     = new List <SelectListItem>();
                model.CountyList   = new List <SelectListItem>();
                model.TimeList     = GetBusinessTimeList();
                model.ShopUserId   = Id;
                model.ShopUserName = shopUser.UserName;
                return(View(model));
            }
            else
            {
                return(RedirectToAction("ShopUserList"));
            }
        }
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);
        }
Beispiel #21
0
        public ApiResultModel GetShopPayType([FromUri] 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)
                    {
                        var payTypeIds = shop.ShopPaymentManagements.Select(s => s.PayTypeId);
                        //是否是绿色直供
                        bool isGreenSupplied = shop.Type.Contains(Property.Common.ConstantParam.SHOP_TYPE_0.ToString());

                        //获取支付类型  绿色直供包含5种
                        var PayTypeList = new List <ShopPaymentType>();

                        if (isGreenSupplied)
                        {
                            PayTypeList.Add(new ShopPaymentType()
                            {
                                TypeId = 1, TypeName = "微信在线支付", TypeFlag = 1
                            });
                            PayTypeList.Add(new ShopPaymentType()
                            {
                                TypeId = 2, TypeName = "支付宝在线支付", TypeFlag = 2
                            });
                        }

                        PayTypeList.Add(new ShopPaymentType()
                        {
                            TypeId = 3, TypeName = "货到现金付款", TypeFlag = 3
                        });
                        PayTypeList.Add(new ShopPaymentType()
                        {
                            TypeId = 4, TypeName = "货到微信付款", TypeFlag = 1
                        });
                        PayTypeList.Add(new ShopPaymentType()
                        {
                            TypeId = 5, TypeName = "货到支付宝付款", TypeFlag = 2
                        });

                        var List = PayTypeList.Select(t => new { TypeId = t.TypeId, TypeName = t.TypeName, TypeFlag = t.TypeFlag, IsCheck = payTypeIds.Contains(t.TypeId) });
                        resultModel.result = List;
                    }
                    else
                    {
                        resultModel.Msg = APIMessage.NO_APP;
                    }
                }
                else
                {
                    resultModel.Msg = APIMessage.NO_USER;
                }
            }
            catch
            {
                resultModel.Msg = APIMessage.REQUEST_EXCEPTION;
            }

            return(resultModel);
        }
Beispiel #22
0
        public ApiResultModel SetShopPayType(Property.UI.Models.Mobile.ShopPayTypeModel 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)
                    {
                        // 新建用户角色关联表
                        List <T_ShopPaymentManagement> payTypes = new List <T_ShopPaymentManagement>();

                        if (!string.IsNullOrEmpty(model.PayTypeIds))
                        {
                            foreach (var id in model.PayTypeIds.Split(';'))
                            {
                                T_ShopPaymentManagement item = new T_ShopPaymentManagement()
                                {
                                    ShopId = model.ShopId, PayTypeId = int.Parse(id)
                                };
                                payTypes.Add(item);
                            }

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

            return(resultModel);
        }
Beispiel #23
0
        public ApiResultModel GetShopShippingCost([FromUri] 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层获取商家信息
                    IShopShippingCostBLL shippingCostBLL = BLLFactory <IShopShippingCostBLL> .GetBLL("ShopShippingCostBLL");

                    var shippingCost = shippingCostBLL.GetEntity(s => s.ShopId == model.ShopId);
                    //如果商家信息不为空
                    if (shippingCost != null)
                    {
                        resultModel.result = new
                        {
                            Id           = shippingCost.Id,
                            OrderExpense = shippingCost.OrderExpense.HasValue ? shippingCost.OrderExpense.ToString() : "",
                            Price        = shippingCost.Price,
                            IsFree       = shippingCost.IsFree
                        };
                    }
                    else
                    {
                        resultModel.result = new
                        {
                            Id           = "",
                            OrderExpense = "",
                            Price        = "",
                            IsFree       = ""
                        };
                    }
                }
                else
                {
                    resultModel.Msg = APIMessage.NO_USER;
                }
            }
            catch
            {
                resultModel.Msg = APIMessage.REQUEST_EXCEPTION;
            }

            return(resultModel);
        }
Beispiel #24
0
        public ApiResultModel SetShopUserInfo(ShopUserInfoModel 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")));

                    if (!string.IsNullOrEmpty(model.Gender))
                    {
                        user.Gender = int.Parse(model.Gender);
                    }

                    user.Email    = model.Email;
                    user.Phone    = model.Phone;
                    user.TrueName = model.TrueName;
                    //设定头像路径及文件名
                    string dir = HttpContext.Current.Server.MapPath(ConstantParam.ShOPFORM_USER_HEAD_DIR);
                    if (!Directory.Exists(dir))
                    {
                        Directory.CreateDirectory(dir);
                    }
                    //设置商家用户头像
                    if (!string.IsNullOrEmpty(model.UserImg))
                    {
                        var    fileName = DateTime.Now.ToFileTime().ToString() + ".jpg";
                        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.UserImg);
                                bw.Write(datas);
                                bw.Close();
                            }
                        }
                        user.HeadPath = ConstantParam.ShOPFORM_USER_HEAD_DIR + fileName;
                    }
                    userBll.Update(user);
                }
                else
                {
                    resultModel.Msg = APIMessage.NO_USER;
                }
            }
            catch
            {
                resultModel.Msg = APIMessage.REQUEST_EXCEPTION;
            }

            return(resultModel);
        }
Beispiel #25
0
        public ApiResultModel SetShopShippingCost(Property.UI.Models.Mobile.ShopShippingCostModel 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);

                    IShopShippingCostBLL shippingCostBLL = BLLFactory <IShopShippingCostBLL> .GetBLL("ShopShippingCostBLL");

                    //如果存在更新,否则添加新的
                    if (model.Id.HasValue)
                    {
                        var shippingCost = shippingCostBLL.GetEntity(s => s.Id == model.Id);

                        shippingCost.OrderExpense = model.OrderExpense;
                        shippingCost.Price        = model.Price;
                        shippingCost.IsFree       = model.IsFree;

                        shippingCostBLL.Update(shippingCost);
                    }
                    else
                    {
                        T_ShopShippingCost shippingCost = new T_ShopShippingCost();

                        shippingCost.ShopId       = model.ShopId;
                        shippingCost.OrderExpense = model.OrderExpense;
                        shippingCost.Price        = model.Price;
                        shippingCost.IsFree       = model.IsFree;

                        shippingCostBLL.Save(shippingCost);
                    }
                }
                else
                {
                    resultModel.Msg = APIMessage.NO_USER;
                }
            }
            catch
            {
                resultModel.Msg = APIMessage.REQUEST_EXCEPTION;
            }

            return(resultModel);
        }
Beispiel #26
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);
        }