188 lines
7.3 KiB
C#
188 lines
7.3 KiB
C#
using CRM.Core.DAL.Res;
|
|
using CRM.Core.Model.Entity;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Linq;
|
|
using WX.CRM.Common;
|
|
|
|
namespace CRM.Core.BLL.Res
|
|
{
|
|
public class RES_CUSTOMER_BL
|
|
{
|
|
private CUSTOMER_DAL custDal = new CUSTOMER_DAL();
|
|
private RES_MOBILE_MD5_BL _mobileMD5 = new RES_MOBILE_MD5_BL();
|
|
|
|
public RES_CUSTOMER GetModel(string id)
|
|
{
|
|
using (var db = new CRM.Core.Model.Entity.zxdContext())
|
|
{
|
|
id = id.Trim();
|
|
var q = db.RES_CUSTOMER.Join(
|
|
db.RES_CUSTOMERDETAIL.Where(p => p.RESID == id)
|
|
, c => c.RESID
|
|
, d => d.RESID
|
|
, (c, d) => new { RESID = c.RESID, LASTNUM3 = c.LASTNUM3, CUSTOMERID = c.CUSTOMERID, CTIME = c.CTIME, CUSTOMERFROM = c.CUSTOMERFROM, RES_CUSTOMERDETAIL = d }
|
|
).FirstOrDefault();
|
|
return new RES_CUSTOMER() { RESID = q.RESID, LASTNUM3 = q.LASTNUM3, CUSTOMERID = q.CUSTOMERID, CTIME = q.CTIME, CUSTOMERFROM = q.CUSTOMERFROM, RES_CUSTOMERDETAIL = q.RES_CUSTOMERDETAIL };
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 根据客户ID查找对应的所有客户ID
|
|
/// </summary>
|
|
/// <param name="customerid"></param>
|
|
/// <returns></returns>
|
|
public List<RES_CUSTOMER> GetList_CustomerByResid(string Resid)
|
|
{
|
|
using (var db = new zxdContext())
|
|
{
|
|
var queryData = db.RES_CUSTOMER.AsQueryable();
|
|
if (!string.IsNullOrEmpty(Resid))
|
|
{
|
|
string trimResid = Resid.Trim();
|
|
queryData = queryData.Where(m => m.RESID == trimResid);
|
|
}
|
|
else
|
|
return new List<RES_CUSTOMER>();
|
|
|
|
List<RES_CUSTOMER> list = (from q in db.RES_CUSTOMER
|
|
join f in queryData on q.CUSTOMERID equals f.CUSTOMERID
|
|
// join d in db.RES_CUSTOMERDETAIL on q.RESID equals d.RESID
|
|
select new
|
|
{
|
|
RESID = q.RESID,
|
|
LASTNUM3 = q.LASTNUM3,
|
|
CUSTOMERID = q.CUSTOMERID,
|
|
// RES_CUSTOMERDETAIL = d,
|
|
CTIME = q.CTIME
|
|
}
|
|
)
|
|
.ToList().Select
|
|
(c => new RES_CUSTOMER
|
|
{
|
|
RESID = c.RESID,
|
|
CUSTOMERID = c.CUSTOMERID,
|
|
LASTNUM3 = c.LASTNUM3,
|
|
//RES_CUSTOMERDETAIL = c.RES_CUSTOMERDETAIL,
|
|
CTIME = c.CTIME
|
|
}).ToList();
|
|
return list;
|
|
}
|
|
}
|
|
|
|
public RES_CUSTOMER getResCustomerByResId(string resId)
|
|
{
|
|
//var redis = new RedisHelper();
|
|
//var customer = redis.Get<RES_CUSTOMER>("RES_CUSTOMER:" + resId);
|
|
//if (customer == null)
|
|
//{
|
|
using (var db = new zxdContext())
|
|
{
|
|
resId = resId.Trim();
|
|
RES_CUSTOMER entry = db.RES_CUSTOMER.FirstOrDefault(m => m.RESID == resId);
|
|
//var result = redis.AddToCache<RES_CUSTOMER>("RES_CUSTOMER:" + resId, entry);
|
|
//LogHelper.Info("RES_CUSTOMER:" + resId);
|
|
return entry;
|
|
}
|
|
//}
|
|
//else
|
|
//{
|
|
// LogHelper.Info("读取缓存数据customer:" + customer.RESID + "," + customer.RES_CUSTOMERDETAIL.RESID);
|
|
// return customer;
|
|
//}
|
|
}
|
|
|
|
public List<CRM.Core.Model.Entity.RES_CUSTOMER> GetListByResId(string resId)
|
|
{
|
|
using (var db = new CRM.Core.Model.Entity.zxdContext())
|
|
{
|
|
resId = resId.Trim();
|
|
List<CRM.Core.Model.Entity.RES_CUSTOMER> list = db.RES_CUSTOMER.Where(m => m.RESID == resId || m.CUSTOMERID == resId).ToList();
|
|
return list;
|
|
}
|
|
}
|
|
|
|
public int ResgisterCustomer(string CNumber, string ResId, string CustomerFrom, string customerDetailXml = null)
|
|
{
|
|
try
|
|
{
|
|
var mobile = _mobileMD5.Get(p => p.ResId == ResId);
|
|
if (mobile == null)
|
|
{
|
|
var md5 = Utility.UserMd5(CNumber);
|
|
_mobileMD5.Add(new RES_MOBILE_MD5() { ResId = ResId, Md5 = md5 });
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogHelper.Error(ex.ToString());
|
|
}
|
|
|
|
return custDal.ResgisterCustomer(CNumber, ResId, CustomerFrom, customerDetailXml);
|
|
}
|
|
|
|
public int CrossDBResgisterCustomer(string CNumber, string ResId, string CustomerFrom, string customerDetailXml = null)
|
|
{
|
|
return custDal.CrossDBResgisterCustomer(CNumber, ResId, CustomerFrom, customerDetailXml);
|
|
}
|
|
|
|
public List<CRM.Core.Model.Entity.RES_CUSTOMER> getResByResIds(string[] resIds)
|
|
{
|
|
using (var db = new CRM.Core.Model.Entity.zxdContext())
|
|
{
|
|
return db.RES_CUSTOMER.Where(p => resIds.Contains(p.RESID)).ToList();
|
|
}
|
|
}
|
|
|
|
public DataTable GetOpenAccountRes()
|
|
{
|
|
var dal = new CUSTOMER_DAL();
|
|
return dal.GetOpenAccountRes();
|
|
}
|
|
|
|
public void MergeCustomer(string oldResId, string newResId)
|
|
{
|
|
using (var db = new zxdContext())
|
|
{
|
|
var oldResIdArr = oldResId.Split(',');
|
|
foreach (var item in oldResIdArr)
|
|
{
|
|
var customer = db.RES_CUSTOMER.FirstOrDefault(p => p.RESID == item);
|
|
if (customer != null)
|
|
{
|
|
customer.CUSTOMERID = newResId;
|
|
db.SaveChanges();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
//根据主客户ID获取所有的用户名信息
|
|
public List<SOFT_USER> GetListByCustomerId(string CustomerId)
|
|
{
|
|
List<SOFT_USER> res = new List<SOFT_USER>();
|
|
if (string.IsNullOrWhiteSpace(CustomerId))
|
|
{
|
|
return res;
|
|
}
|
|
using (var db = new zxdContext())
|
|
{
|
|
CustomerId = CustomerId.Trim();
|
|
var customerids = db.RES_CUSTOMER.Where(b => b.CUSTOMERID == CustomerId).Select(b => b.RESID).ToList();
|
|
var entry = db.SOFT_USER.Where(m => customerids.Contains(m.RESID)).ToList();
|
|
return entry;
|
|
}
|
|
}
|
|
|
|
public RES_CUSTOMER getResCustomerByUmId(string umId)
|
|
{
|
|
using (var db = new zxdContext())
|
|
{
|
|
umId = umId.Trim();
|
|
RES_CUSTOMER entry = db.RES_CUSTOMER.FirstOrDefault(m => m.UMID == umId);
|
|
return entry;
|
|
}
|
|
}
|
|
}
|
|
} |