/// <summary> /// 优惠券明细数据过滤 /// </summary> /// <param name="couponsNo"></param> /// <param name="user"></param> /// <param name="status"></param> /// <param name="faceVal"></param> /// <param name="beginTime"></param> /// <param name="endTime"></param> /// <param name="pageIndex"></param> /// <param name="pageSize"></param> /// <returns></returns> public dynamic GetCouponsDetails(CouponDetail coupondetail, PageInfo pageInfo, out int totalCount) { var query = _context.CouponDetails.Where(p => p.IsDeleted != 1); if (!coupondetail.CouponSN.IsNullOrEmpty()) { query = query.Where(p => p.CouponSN.Contains(coupondetail.CouponSN)); } if (!coupondetail.MemberId.IsNullOrEmpty()) {//coupondetail.MemberId 传手机号 var customer = new CustomersService().GetCustomerByWhere(a => a.Mobile.Contains(coupondetail.MemberId) && a.IsDeleted != 1); if (customer.Count() > 0) { string ids = ""; foreach (var item in customer) { ids += item.Id + ","; } query = query.Where(p => ids.Contains(p.MemberId)); } } //-1=全部 if (coupondetail.UseState != -1) { query = query.Where(a => a.UseState.Equals(coupondetail.UseState)); } if (coupondetail.CouponBatch.IsNotNullOrEmpty()) { query = query.Where(a => a.CouponBatch.Contains(coupondetail.CouponBatch)); } if (coupondetail.Denomination > 0) { query = query.Where(a => a.Denomination.Equals(coupondetail.Denomination)); } if (coupondetail.BeginValidDate != new DateTime()) { query = query.Where(a => a.BeginValidDate <coupondetail.BeginValidDate && a.EndValidDate> coupondetail.BeginValidDate); } //if (coupondetail.EndValidDate != new DateTime()) //{ // query = query.Where(a => a.EndValidDate < coupondetail.EndValidDate); //} totalCount = query.Count(); var result = (from x in query join cu1 in _context.Customers on x.MemberId equals cu1.Id into temp1 join cu2 in _context.Customers on x.UseMemberId equals cu2.Id into temp2 from cu1 in temp1.DefaultIfEmpty() from cu2 in temp2.DefaultIfEmpty() where x.IsDeleted != 1 select new { x.CouponSN, x.Denomination, x.SalesMoney, x.CreatedOn, x.BeginValidDate, x.EndValidDate, x.UseDate, x.UseState, x.UseMemberId, x.ConditionMoney, UseOrderSN = x.UseOrderSN, x.Title, OwnerMobile = cu1.Mobile, OwnerTel = cu1.Tel, OwnerFullName = cu1.FullName, UsedMobile = cu2.Mobile, UsedTel = cu2.Tel, UsedFullName = cu2.FullName, CouponBatch = x.CouponBatch }).OrderBy(p => p.UseState).ThenByDescending(p => p.CreatedOn).Skip((pageInfo.Page - 1) * pageInfo.Rows).Take(pageInfo.Rows); return(result.ToList()); }