using System; using System.Collections.Generic; using System.Linq; using WX.CRM.Common; using WX.CRM.IBLL.Wx; using WX.CRM.Model.Entity; namespace WX.CRM.BLL.Wx { public class WX_BALANCESALEUSERAUDIT_BL3 : DbContextRepository, IWX_BALANCESALEUSERAUDIT3 { public IList GetAutitList(string gId, decimal uId, DateTime? balanceCode, string status) { using (var db = new crmContext()) { var where = PredicateExtensionses.True(); if (uId > 0) { where = where.And(p => p.INNERUSERID == uId); } else if (!string.IsNullOrEmpty(gId)) { decimal[] _groupids = OperationUtil.ConvertToDecimal(gId.Split(',')); var uIds = db.BAS_INNERUSERGROUP.Where(p => _groupids.Contains(p.GID.Value)).Select(p => p.INNERUSERID); var userEIds = db.BAS_INNERUSER.Where(d => uIds.Contains(d.PKID)).Select(p => p.EID).ToArray(); where = where.And(m => userEIds.Contains(m.EID)); } if (balanceCode.HasValue) { where = where.And(p => p.MONTH == balanceCode.Value); } if (!string.IsNullOrEmpty(status)) { where = where.And(p => p.STATUS == status); } var list = GetList(where); return list.ToList(); } } public void AuditPerformanceUser(decimal PKID, int sta, string remark, decimal auditid, string auditname) { using (var db = new crmContext()) { var info = db.WX_BALANCESALEUSERAUDIT3.FirstOrDefault(p => p.PKID == PKID); if (info == null) { throw new Exception("未找到结算记录!"); } if (info.STATUS == "已确认") { throw new Exception("已经确认过了!"); } if (sta == 0) info.STATUS = "未确认"; else if (sta == 1) info.STATUS = "已确认"; else info.STATUS = "未知"; info.REMARK = remark; info.AUDITBYUSERID = auditid; info.AUDITBYUSERNAME = auditname; info.AUDITTIME = System.DateTime.Now; db.SaveChanges(); } } public void AuditBatchPerformanceUser(DateTime balanceCode, decimal userid, string auditname) { using (var db = new crmContext()) { var balanceid = db.WX_BALANCESALEUSERAUDIT3.Where(p => p.MONTH == balanceCode).Max(m => m.BALANCEBATCHID); var q = from a in db.WX_BALANCESALEUSERAUDIT3 join u in db.BAS_INNERUSER on a.INNERUSERID equals u.PKID where a.BALANCEBATCHID == balanceid && a.MONTH == balanceCode && u.ISDISMISS == 1 && a.STATUS == "未确认" select a; int c = q.Count(); if (c == 0) throw new Exception("已经确认完成,不需要再次确认!"); var lis = q.ToList(); foreach (var o in lis) { o.STATUS = "已确认"; o.AUDITBYUSERID = userid; o.AUDITBYUSERNAME = auditname; o.AUDITTIME = System.DateTime.Now; o.REMARK = "批量确认"; } db.SaveChanges(); } } } }