示例#1
0
        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);
        }
示例#2
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));
        }
示例#3
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);
        }