示例#1
0
        public ActionResult GetDiscountsForPay(PayDiscountSearchDTO req)
        {
            if (req.ListType == 1)
            {
                req.offset = (req.offset - 1) * req.limit;
            }

            var list = _discountRepository.GetList(out int total, req);

            return(Json(new { rows = list, total = total, code = 0, msg = "" }, JsonRequestBehavior.AllowGet));
        }
示例#2
0
        public List <DiscountDTO> GetList(out int total, PayDiscountSearchDTO req)
        {
            using (var db = new SqlSugarClient(Connection))
            {
                string order = "s1.Id desc";

                var data = db.Sqlable()
                           .From <R_Discount>("s1")
                           .Join <R_Restaurant>("s2", "s1.R_Restaurant_Id", "s2.Id", JoinType.Left)
                           .Join <R_Market>("s3", "s1.R_Market_Id", "s3.Id", JoinType.Left)
                           .Join <R_Area>("s4", "s1.R_Area_Id", "s4.Id", JoinType.Left);

                if (!string.IsNullOrEmpty(req.Name))
                {
                    data = data.Where("s1.Name like '%" + req.Name + "%'");
                }

                if (req.Restaurant > 0)
                {
                    data = data.Where("s2.Id=" + req.Restaurant);
                }

                if (!string.IsNullOrEmpty(req.StartDate))
                {
                    data = data.Where("s1.StartDate>=" + req.StartDate);
                }

                if (!string.IsNullOrEmpty(req.EndDate))
                {
                    data = data.Where("s1.EndDate<=" + req.EndDate);
                }

                if (req.IsEnable == true)
                {
                    data = data.Where("s1.IsEnable=1");
                }

                if (!string.IsNullOrEmpty(req.Sort))
                {
                    if (req.Sort.Equals("id", StringComparison.OrdinalIgnoreCase))
                    {
                        order = "s1.Id desc";
                    }
                    else
                    {
                        order = string.Format("{0} {1}", req.Sort, req.Order);
                    }
                }

                if (!string.IsNullOrEmpty(req.CurrentDate))
                {
                    data = data.Where("'" + req.CurrentDate + "' BETWEEN s1.StartDate  AND s1.EndDate");
                }

                if (!string.IsNullOrEmpty(req.OrderCreateDate))
                {
                    data = data.Where("'" + req.OrderCreateDate + "' BETWEEN s1.StartDate  AND s1.EndDate");
                }

                total = data.Count();
                List <DiscountDTO> list = data.SelectToPageList <DiscountDTO>(
                    @"s1.Id,s1.Name,s3.Name as Market,s2.Name as Restaurant,
                      s4.Name as Area,s1.IsEnable,s1.StartDate,s1.EndDate",
                    order, (req.offset / req.limit) + 1, req.limit, null);

                foreach (var item in list)
                {
                    item.CyxmZkCp = db.Queryable <R_DiscountCategory>().
                                    Where(p => p.R_Discount_Id == item.Id).ToList();
                }
                return(list);
            }
        }