ComplianceServer/oldcode/BLL/Wx/WX_BALANCESALEUSERAUDIT_BL.cs

114 lines
4.7 KiB
C#

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_BL : DbContextRepository<WX_BALANCESALEUSERAUDIT>, IWX_BALANCESALEUSERAUDIT
{
public IList<WX_BALANCESALEUSERAUDIT> GetAutitList(string gId, decimal uId, DateTime? balanceCode, string status)
{
using (var db = new crmContext())
{
var where = PredicateExtensionses.True<WX_BALANCESALEUSERAUDIT>();
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<decimal>();
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_BALANCESALEUSERAUDIT.FirstOrDefault(p => p.PKID == PKID);
//var lastInfo = db.WX_BALANCESALEUSERAUDIT.OrderByDescending(o => o.MONTH).FirstOrDefault();
//if (lastInfo == null)
//{
// throw new Exception("未找一最后一次的结算记录!");
//}
//if (lastInfo.CTIME != info.CTIME)
// 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();
var info = db.WX_BALANCESALEUSERAUDIT.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_BALANCESALEUSERAUDIT.Where(p => p.MONTH == balanceCode).Max(m => m.BALANCEBATCHID);
var q = from a in db.WX_BALANCESALEUSERAUDIT
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();
}
}
}
}