using System; using System.Collections.Generic; using System.Data; using System.Linq; using WX.CRM.BLL.Base; using WX.CRM.BLL.Util; using WX.CRM.Common; using WX.CRM.IBLL.Wx; using WX.CRM.Model.Entity; using WX.CRM.Model.QueryMap; namespace WX.CRM.BLL.Wx { public class WX_AFTERSALES3_BL : DbContextRepository, IWX_AFTERSALES3 { public void SaveAfterSale(List list) { foreach (var wxAftersales in list) { var model = Get(p => p.RESID == wxAftersales.RESID); if (model != null) { if (wxAftersales.INNERUSERID == 0) { Delete(model); } else { model.INNERUSERID = wxAftersales.INNERUSERID; model.CTIME = DateTime.Now;//CTIME会随着更改 Update(model); } } else { var info = new WX_AFTERSALES3() { PKID = new SEQUENCES_BL().Seq_base_get(), RESID = wxAftersales.RESID, INNERUSERID = wxAftersales.INNERUSERID, CTIME = DateTime.Now }; Add(info); } } } public List GetAfterSaleAssignViews(ref Pager pager, string resId, decimal? inneruserId, decimal? bindType, bool? samllorder = null) { using (var db = new crmContext()) { var where = PredicateExtensionses.True(); if (!string.IsNullOrWhiteSpace(resId)) { where = where.And(p => p.RESID == resId); } if (inneruserId.HasValue) { where = where.And(p => p.INNERUSERID == inneruserId.Value); } if (bindType.HasValue) { if (bindType == 1) { where = where.And(p => p.INNERUSERID > 0); } else { where = where.And(p => p.INNERUSERID == null); } } if (samllorder.HasValue) if (!samllorder.Value) where = where.And(p => p.FINALPAY > 100); var query = from p in db.WX_SZZYORDER.Where(p => p.ISOPEN == 1) join b in (db.WX_SZZYORDER.Where(p => p.ISOPEN == 1).GroupBy(p => p.RESID).Select(g => new { g.Key, finalPay = g.Max(gg => gg.FINALPAY) })) on p.RESID equals b.Key join a in db.WX_AFTERSALES3 on p.RESID equals a.RESID into t0 from pa in t0.DefaultIfEmpty() join r in db.WX_COMMISSIONRULE.Where(p => p.ISMAIN == 1) on p.ORDERID equals r.ORDERID into t1 from pr in t1.DefaultIfEmpty() where p.FINALPAY == b.finalPay select new AfterSaleAssignView() { RESID = p.RESID, INNERUSERID = pa.INNERUSERID, ORDERID = p.ORDERID, SUBPRODUCTNAME = p.SUBPRODUCTNAME, FINALPAY = p.FINALPAY, OTIME = p.OTIME, SALEUSERID = pr.SALEUSERID }; query = query.Where(where); if (bindType == 0) { query = query.OrderBy(p => p.OTIME); } else { query = query.OrderByDescending(p => p.ORDERID); } PagerUtil.SetPager(ref query, ref pager); return query.ToList(); } } } }