Ejemplo n.º 1
0
        /// <summary>
        /// 查询商品关联折扣信息数据
        /// Remark:可分页 + 可关键词查询
        /// </summary>
        /// <param name="opeType"></param>
        /// <param name="page"></param>
        /// <param name="size"></param>
        /// <param name="searchValue"></param>
        /// <returns></returns>
        public IEnumerable<dynamic> CommodityRelevanceDiscountListOpe(string opeType, int page, int size, string searchValue)
        {
            //DAL
            CommodityDiscountInfoDAL commDiscountDal = new CommodityDiscountInfoDAL();

            //Result
            IEnumerable<dynamic> list = null;

            //Query
            switch (opeType)
            {
                case "list":
                    list = commDiscountDal.CommodityRelevanceDiscountByPage(page, size);
                    break;

                case "search":
                    list = commDiscountDal.CommodityRelevanceDiscountBySearch(page, size, searchValue);
                    break;

                default:
                    break;
            }

            return list;
        }
Ejemplo n.º 2
0
        public IEnumerable<dynamic> CommodityDiscountItem(string discountID)
        {
            //Init
            SQLStringInfo _sqlInfo = new SQLStringInfo();
            _sqlInfo.ColumnSB.Append(" ,DIS.PostType,DIS.IsEndCommodity ");
            _sqlInfo.WhereSB.Append(" WHERE DiscountID = @DiscountID");
            _sqlInfo.OrderBySB.Append(",COMM.Title");

            //DAL
            CommodityDiscountInfoDAL discountDal = new CommodityDiscountInfoDAL();

            string strSql = _sqlInfo.GetSQLString(discountDal.CommodityDiscountListSQL());

            IEnumerable<dynamic> list = discountDal.Query(strSql, new { DiscountID = discountID });

            return list;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 重写 Main页面 商品类别列表页面 数据
        /// </summary>
        /// <param name="page"></param>
        /// <param name="size"></param>
        /// <param name="moduleID"></param>
        /// <returns></returns>
        public IEnumerable<CommodityDiscountInfoCNb> CommodityInfoQueryByPage(int page, int size, string moduleID, string strSearch)
        {
            //Init
            int iIndex = (page - 1) * size;

            //Result
            List<CommodityDiscountInfoCNa> result = new List<CommodityDiscountInfoCNa>();

            //Query
            IEnumerable<CommodityDiscountInfoCNa> list = new CommodityDiscountInfoDAL().CommodityInfoQueryByPage(page, size, moduleID, strSearch);

            //需要进行筛选
            DateTime now = DateTime.Now;

            //1.需要排除掉折扣 - 时间筛选
            IEnumerable<string> excludeID = list.Where(x => x.RealStartTime != null &&
                                                            ((DateTime.Compare(Convert.ToDateTime(x.RealStartTime), now) < 0 &&
                                                              DateTime.Compare(Convert.ToDateTime(x.RealEndTime), now) < 0) ||
                                                              DateTime.Compare(Convert.ToDateTime(x.RealStartTime), now) > 0)).
                                                 Select(x => x.DiscountID).
                                                 Distinct();

            //2.相同时间段筛选
            foreach (var item in list.GroupBy(x => x.ID))
            {
                CommodityDiscountInfoCNa cItem = new CommodityDiscountInfoCNa();

                if (item.Count().Equals(1) && item.ElementAt(0).RealStartTime == null)
                { //没有折扣

                    //4.没有折扣的也要注意
                    cItem = item.ElementAt(0);
                    cItem.DiscountPrice = cItem.Price;
                    cItem.HasDiscount = false;
                }
                else
                { //有折扣

                    //3.最后保留一个数据
                    cItem = item.Where(x => !excludeID.Contains(x.DiscountID)).OrderByDescending(x => x.RealDiscountOpeDate).FirstOrDefault();

                    if (cItem == null)
                    {
                        CommodityDiscountInfoCNa itemInfo = item.ElementAt(0);
                        itemInfo.DiscountCount = 0;
                        itemInfo.DiscountFlag = 0;
                        itemInfo.DiscountID = string.Empty;
                        itemInfo.DiscountOpeDate = null;
                        itemInfo.DiscountPost = 0;
                        itemInfo.DiscountPrice = 0;
                        itemInfo.DiscountValue = 0;
                        itemInfo.RealDiscountOpeDate = null;
                        itemInfo.RealStartTime = null;
                        itemInfo.RealEndTime = null;
                        itemInfo.StartTime = null;
                        itemInfo.EndTime = null;

                        cItem = itemInfo;
                        cItem.DiscountPrice = cItem.Price;
                        cItem.HasDiscount = false;
                    }
                    else { cItem.HasDiscount = true; }
                }

                result.Add(cItem);
            }

            //Convert
            IEnumerable<CommodityDiscountInfoCNb> resultNa = result.Select(x =>
            {
                return new CommodityDiscountInfoCNb()
                {
                    ID = x.ID,
                    MID = x.MID,
                    StoreID = x.StoreID,
                    Title = x.Title,
                    Price = x.Price,
                    Intro = x.Intro,
                    Remark = x.Remark,
                    Photo = x.Photo,
                    Flag = x.Flag,
                    DiscountFlag = x.DiscountFlag,
                    PostType = x.PostType,
                    PostPrice = x.PostPrice,
                    iOrder = x.iOrder,
                    OpeDate = x.OpeDate == null ? string.Empty : x.OpeDate.ToString(),
                    State = x.State,
                    Stock = x.Stock,
                    DiscountValue = x.DiscountValue,
                    DiscountPrice = x.DiscountPrice,
                    DiscountCount = x.DiscountCount,
                    StartTime = x.StartTime == null ? string.Empty : x.StartTime.ToString(),
                    EndTime = x.EndTime == null ? string.Empty : x.EndTime.ToString(),
                    DiscountPost = x.DiscountPost,
                    IsEndCommodity = x.IsEndCommodity,
                    DiscountOpeDate = x.DiscountOpeDate == null ? string.Empty : x.DiscountOpeDate.ToString(),
                    HasDiscount = x.HasDiscount
                };
            });

            return resultNa.Skip(iIndex).Take(size);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 限时折扣列表页面数据查询逻辑业务方法
        /// </summary>
        /// <param name="queryType"></param>
        /// <param name="page"></param>
        /// <param name="size"></param>
        /// <returns></returns>
        public Tuple<IEnumerable<dynamic>, string> CommodityDiscountListOpe(string queryType, int page, int size)
        {
            //Init
            SQLStringInfo _sqlInfo = new SQLStringInfo();

            //Query
            IEnumerable<dynamic> list = new CommodityDiscountInfoDAL().CommodityDiscountListOpe(_sqlInfo);

            //Result
            IEnumerable<dynamic> result = null;
            string strState = string.Empty;

            int startIndex = (page - 1) * size;

            switch (queryType)
            {
                case "1"://进行中
                    result = list.Where(x => DateTime.Compare(DateTime.Parse(x.StartTime.ToString()), DateTime.Now) <= 0 && DateTime.Compare(DateTime.Parse(x.EndTime.ToString()), DateTime.Now) >= 0);
                    strState = "进行中";
                    break;

                case "2"://未开始
                    result = list.Where(x => DateTime.Compare(DateTime.Parse(x.StartTime.ToString()), DateTime.Now) > 0);
                    strState = "未开始";
                    break;

                case "3"://已结束
                    result = list.Where(x => DateTime.Compare(DateTime.Parse(x.EndTime.ToString()), DateTime.Now) < 0);
                    strState = "已结束";
                    break;

                default:
                    result = list;
                    break;
            }

            result = result.Count() != 0 ? result.Skip(startIndex).Take(size) : null;

            return new Tuple<IEnumerable<dynamic>, string>(result, strState);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 商品关联折扣信息数据查询:商品详情页面用
        /// </summary>
        /// <param name="commodityID"></param>
        /// <returns></returns>
        public CommodityDiscountInfoCNb CommodityInfoQueryOnce(string commodityID)
        {
            //Query
            IEnumerable<CommodityDiscountInfoCNa> list = new CommodityDiscountInfoDAL().CommodityInfoQueryOnce(" COMM.ID = @ID", new { ID = commodityID });

            //开始折扣筛选
            DateTime now = DateTime.Now;

            //1.需要排除掉折扣 - 时间筛选
            IEnumerable<string> excludeID = list.Where(x => x.RealStartTime != null &&
                                                            ((DateTime.Compare(Convert.ToDateTime(x.RealStartTime), now) < 0 &&
                                                              DateTime.Compare(Convert.ToDateTime(x.RealEndTime), now) < 0) ||
                                                              DateTime.Compare(Convert.ToDateTime(x.RealStartTime), now) > 0)).
                                                 Select(x => x.DiscountID).
                                                 Distinct();

            //第一阶段结果集
            CommodityDiscountInfoCNa cItem = new CommodityDiscountInfoCNa();

            if (list.Count().Equals(1) && list.ElementAt(0).RealStartTime == null)
            { //没有折扣

                //4.没有折扣的也要注意
                cItem = list.ElementAt(0);
                cItem.DiscountPrice = cItem.Price;
                cItem.HasDiscount = false;
            }
            else
            { //有折扣

                //3.最后保留一个数据
                cItem = list.Where(x => !excludeID.Contains(x.DiscountID)).OrderByDescending(x => x.RealDiscountOpeDate).FirstOrDefault();

                if (cItem == null)
                {
                    CommodityDiscountInfoCNa itemInfo = list.ElementAt(0);
                    itemInfo.DiscountCount = 0;
                    itemInfo.DiscountFlag = 0;
                    itemInfo.DiscountID = string.Empty;
                    itemInfo.DiscountOpeDate = null;
                    itemInfo.DiscountPost = 0;
                    itemInfo.DiscountPrice = 0;
                    itemInfo.DiscountValue = 0;
                    itemInfo.RealDiscountOpeDate = null;
                    itemInfo.RealStartTime = null;
                    itemInfo.RealEndTime = null;
                    itemInfo.StartTime = null;
                    itemInfo.EndTime = null;

                    cItem = itemInfo;
                    cItem.DiscountPrice = cItem.Price;
                    cItem.HasDiscount = false;
                }
                else { cItem.HasDiscount = true; }
            }

            //第二阶段结果集
            CommodityDiscountInfoCNb result = new CommodityDiscountInfoCNb()
            {
                ID = cItem.ID,
                MID = cItem.MID,
                StoreID = cItem.StoreID,
                Title = cItem.Title,
                Price = cItem.Price,
                Intro = cItem.Intro,
                Remark = cItem.Remark,
                Photo = cItem.Photo,
                Flag = cItem.Flag,
                DiscountFlag = cItem.DiscountFlag,
                PostType = cItem.PostType,
                PostPrice = cItem.PostPrice,
                iOrder = cItem.iOrder,
                OpeDate = cItem.OpeDate == null ? string.Empty : cItem.OpeDate.ToString(),
                State = cItem.State,
                Stock = cItem.Stock,
                DiscountValue = cItem.DiscountValue,
                DiscountPrice = cItem.DiscountPrice,
                DiscountCount = cItem.DiscountCount,
                StartTime = cItem.StartTime == null ? string.Empty : cItem.StartTime.ToString(),
                EndTime = cItem.EndTime == null ? string.Empty : cItem.EndTime.ToString(),
                DiscountPost = cItem.DiscountPost,
                IsEndCommodity = cItem.IsEndCommodity,
                DiscountOpeDate = cItem.DiscountOpeDate == null ? string.Empty : cItem.DiscountOpeDate.ToString(),
                HasDiscount = cItem.HasDiscount
            };

            return result;
        }