1476 lines
66 KiB
C#
1476 lines
66 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
using System.Data;
|
||
using System.Linq;
|
||
using System.Text;
|
||
using WX.CRM.BLL.Base;
|
||
using WX.CRM.BLL.Res;
|
||
using WX.CRM.BLL.Util;
|
||
using WX.CRM.BLL.Ww;
|
||
using WX.CRM.Common;
|
||
using WX.CRM.DAL.Res;
|
||
using WX.CRM.DAL.Wx;
|
||
using WX.CRM.IBLL.Res;
|
||
using WX.CRM.IBLL.Ww;
|
||
|
||
using WX.CRM.BLL.Ww;
|
||
using WX.CRM.IBLL.Res;
|
||
|
||
using WX.CRM.BLL.Application.UserComBox;
|
||
using WX.CRM.Model.Entity;
|
||
using WX.CRM.Model.MAP;
|
||
using WX.CRM.IBLL.Wx;
|
||
using WX.CRM.BLL.Soft;
|
||
using CRM.Core.DTO.Res;
|
||
using WX.CRM.Model.DTO;
|
||
|
||
namespace WX.CRM.BLL.Wx
|
||
{
|
||
public class WX_SZZYORDER_BL : DbContextRepository<WX_SZZYORDER>, IWX_SZZYORDER
|
||
{
|
||
private string szzyOrderHost = System.Configuration.ConfigurationManager.AppSettings["SzzyOrderHost"];
|
||
private string szzyWxPayHost = System.Configuration.ConfigurationManager.AppSettings["SzzyWxPayHost"];
|
||
private string szzyEmployeeId = System.Configuration.ConfigurationManager.AppSettings["SzzyEmployeeID"];
|
||
private string szzyPassword = System.Configuration.ConfigurationManager.AppSettings["SzzyPassword"];
|
||
private WX_SZZYORDER_DAL wx_SzzyOrder_DAL = new WX_SZZYORDER_DAL();
|
||
private CACHE_BL cache_BL = new CACHE_BL();
|
||
private RES_CUSTOMER_BL res_Customer_BL = new RES_CUSTOMER_BL();
|
||
private RES_RESOURCEMOBILE_BL res_ResourceMobile_BL = new RES_RESOURCEMOBILE_BL();
|
||
private CUSTOMER_DAL custDal = new CUSTOMER_DAL();
|
||
private IRES_MYALLOCATERES _myRes = new RES_MYALLOCATERES_BL();
|
||
private BAS_INNERUSER_BL _user = new BAS_INNERUSER_BL();
|
||
private IWw_huser _hhUser = new Ww_huser_BL();
|
||
private IRES_ALLCOTE_USER _allcoteUser = new RES_ALLCOTE_USER_BL();
|
||
|
||
public bool CreatOrder(ref SzzyOrderResult<CreateOrderResultData> result, string employeeID, string password, string userID, decimal subProductID, string orderIDFromTeam, decimal orderType, string upgradeOrderIDs, decimal totalUpgradeValue, decimal needPay, decimal openOrder, decimal teamServe)
|
||
{
|
||
try
|
||
{
|
||
string url = string.Format("{0}/api/TeamOrderService/CreateOrder", szzyOrderHost);
|
||
string parms = string.Format("EmployeeID={0}&Password={1}&UserID={2}&SubProductID={3}&OrderIDFromTeam={4}&OrderType={5}&UpgradeOrderIDs={6}&TotalUpgradeValue={7}&NeedPay={8}&OpenOrder={9}&TeamServe={10}",
|
||
employeeID, password, userID, subProductID, orderIDFromTeam, orderType, upgradeOrderIDs, totalUpgradeValue, needPay, openOrder, teamServe);
|
||
|
||
string res = Utility.HttpPostData(url, parms, Encoding.UTF8);
|
||
LogHelper.Debug("调用订单接口:" + parms + "。返回值:" + res);
|
||
if (!string.IsNullOrWhiteSpace(res))
|
||
{
|
||
result = Utility.JSONToObject<SzzyOrderResult<CreateOrderResultData>>(res);
|
||
}
|
||
return true;
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
LogHelper.Error(ex);
|
||
result = null;
|
||
return false;
|
||
}
|
||
}
|
||
|
||
public List<WX_SZZYORDERDTO> GetList(ref Pager pager, OrderQueryDto querydto, QueryUserComboDto usercomboDto)
|
||
{
|
||
using (var db = new crmContext())
|
||
{
|
||
var queryData = (from M in db.WX_SZZYORDER.AsQueryable()
|
||
join d in db.RES_CUSTOMER on M.RESID equals d.RESID
|
||
select new WX_SZZYORDERDTO
|
||
{
|
||
ORDERID = M.ORDERID,
|
||
EMPLOYEEID = M.EMPLOYEEID,
|
||
PASSWORD = M.PASSWORD,
|
||
USERID = M.USERID,
|
||
PRODUCTID = M.PRODUCTID,
|
||
PRODUCTNAME = M.PRODUCTNAME,
|
||
SUBPRODUCTID = M.SUBPRODUCTID,
|
||
SUBPRODUCTNAME = M.SUBPRODUCTNAME,
|
||
ORDERTYPE = M.ORDERTYPE,
|
||
UPGRADEORDERIDS = M.UPGRADEORDERIDS,
|
||
TOTALUPGRADEVALUE = M.TOTALUPGRADEVALUE,
|
||
NEEDPAY = M.NEEDPAY,
|
||
OPENORDER = M.OPENORDER,
|
||
SZZYORDERID = M.SZZYORDERID,
|
||
ORDERSTATUS = M.ORDERSTATUS,
|
||
CTIME = M.CTIME,
|
||
RETURNNEEDPAY = M.RETURNNEEDPAY,
|
||
CONTRACTCODE = M.CONTRACTCODE,
|
||
RET = M.RET,
|
||
RETP = M.RETP,
|
||
MSG = M.MSG,
|
||
RETURNDETAIL = M.RETURNDETAIL,
|
||
INNERUSERID = M.INNERUSERID,
|
||
OTIME = M.OTIME,
|
||
ENDTIME = M.ENDTIME,
|
||
RESID = d.UMID,
|
||
REQUESTSTATUS = M.REQUESTSTATUS,
|
||
ISFINANCEPAY = M.ISFINANCEPAY,
|
||
FINACEPAYDATE = M.FINACEPAYDATE,
|
||
REMARK = M.REMARK,
|
||
FINALPAY = M.FINALPAY,
|
||
ORDERSTATUSNAME = M.ORDERSTATUSNAME,
|
||
OPERATETIME = M.OPERATETIME,
|
||
STIME = M.STIME,
|
||
ETIME = M.ETIME,
|
||
SUSPENDCOMMENT = M.SUSPENDCOMMENT,
|
||
UPDATEORDERTIME = M.UPDATEORDERTIME,
|
||
ISOPEN = M.ISOPEN,
|
||
TEAMSERVE = M.TEAMSERVE,
|
||
FCTEXT = M.FCTEXT,
|
||
CUSTOMERUSERNAME = M.CUSTOMERUSERNAME,
|
||
ARRIVALPAY = M.ARRIVALPAY,
|
||
ARRIVALTIME = M.ARRIVALTIME,
|
||
SOURCE = M.SOURCE,
|
||
CNAME = M.CNAME,
|
||
OPENDAYS = M.OPENDAYS,
|
||
CUSTOMERCLASSIFY = M.CUSTOMERCLASSIFY,
|
||
SALEDEPTID = M.SALEDEPTID,
|
||
RISKCTRLSTATUS = M.RISKCTRLSTATUS,
|
||
ACTIVEPRODUCTCODE = M.ACTIVEPRODUCTCODE,
|
||
ACTIVEPRODUCTEXT = M.ACTIVEPRODUCTEXT,
|
||
ISTEST = M.ISTEST,
|
||
HASHGRECORD = M.HASHGRECORD,
|
||
OUTORDERO = M.OUTORDERO,
|
||
GIFTDAYS = M.GIFTDAYS,
|
||
GIFTDAYS2 = M.GIFTDAYS2,
|
||
REJECTREMARK = M.REJECTREMARK,
|
||
EXTERNAL_USERID = M.EXTERNAL_USERID,
|
||
WEWORK_REMOTEID = M.WEWORK_REMOTEID,
|
||
FUJIAN = M.FUJIAN,
|
||
DEPTCODE = M.DEPTCODE,
|
||
ESTIMATEOTIME = M.ESTIMATEOTIME,
|
||
EID = M.EID
|
||
}
|
||
);
|
||
if (querydto.eid > 0 || usercomboDto.userId.HasValue)
|
||
{
|
||
queryData = (from M in db.WX_SZZYORDER.AsQueryable()
|
||
join d in db.RES_CUSTOMER on M.RESID equals d.RESID
|
||
join i in db.BAS_INNERUSER on M.INNERUSERID equals i.PKID into temp
|
||
from i in temp.DefaultIfEmpty()
|
||
select new WX_SZZYORDERDTO
|
||
{
|
||
ORDERID = M.ORDERID,
|
||
EMPLOYEEID = M.EMPLOYEEID,
|
||
PASSWORD = M.PASSWORD,
|
||
USERID = M.USERID,
|
||
PRODUCTID = M.PRODUCTID,
|
||
PRODUCTNAME = M.PRODUCTNAME,
|
||
SUBPRODUCTID = M.SUBPRODUCTID,
|
||
SUBPRODUCTNAME = M.SUBPRODUCTNAME,
|
||
ORDERTYPE = M.ORDERTYPE,
|
||
UPGRADEORDERIDS = M.UPGRADEORDERIDS,
|
||
TOTALUPGRADEVALUE = M.TOTALUPGRADEVALUE,
|
||
NEEDPAY = M.NEEDPAY,
|
||
OPENORDER = M.OPENORDER,
|
||
SZZYORDERID = M.SZZYORDERID,
|
||
ORDERSTATUS = M.ORDERSTATUS,
|
||
CTIME = M.CTIME,
|
||
RETURNNEEDPAY = M.RETURNNEEDPAY,
|
||
CONTRACTCODE = M.CONTRACTCODE,
|
||
RET = M.RET,
|
||
RETP = M.RETP,
|
||
MSG = M.MSG,
|
||
RETURNDETAIL = M.RETURNDETAIL,
|
||
INNERUSERID = M.INNERUSERID,
|
||
OTIME = M.OTIME,
|
||
ENDTIME = M.ENDTIME,
|
||
RESID = d.UMID,
|
||
REQUESTSTATUS = M.REQUESTSTATUS,
|
||
ISFINANCEPAY = M.ISFINANCEPAY,
|
||
FINACEPAYDATE = M.FINACEPAYDATE,
|
||
REMARK = M.REMARK,
|
||
FINALPAY = M.FINALPAY,
|
||
ORDERSTATUSNAME = M.ORDERSTATUSNAME,
|
||
OPERATETIME = M.OPERATETIME,
|
||
STIME = M.STIME,
|
||
ETIME = M.ETIME,
|
||
SUSPENDCOMMENT = M.SUSPENDCOMMENT,
|
||
UPDATEORDERTIME = M.UPDATEORDERTIME,
|
||
ISOPEN = M.ISOPEN,
|
||
TEAMSERVE = M.TEAMSERVE,
|
||
FCTEXT = M.FCTEXT,
|
||
CUSTOMERUSERNAME = M.CUSTOMERUSERNAME,
|
||
ARRIVALPAY = M.ARRIVALPAY,
|
||
ARRIVALTIME = M.ARRIVALTIME,
|
||
SOURCE = M.SOURCE,
|
||
CNAME = M.CNAME,
|
||
OPENDAYS = M.OPENDAYS,
|
||
CUSTOMERCLASSIFY = M.CUSTOMERCLASSIFY,
|
||
SALEDEPTID = M.SALEDEPTID,
|
||
RISKCTRLSTATUS = M.RISKCTRLSTATUS,
|
||
ACTIVEPRODUCTCODE = M.ACTIVEPRODUCTCODE,
|
||
ACTIVEPRODUCTEXT = M.ACTIVEPRODUCTEXT,
|
||
ISTEST = M.ISTEST,
|
||
HASHGRECORD = M.HASHGRECORD,
|
||
OUTORDERO = M.OUTORDERO,
|
||
GIFTDAYS = M.GIFTDAYS,
|
||
GIFTDAYS2 = M.GIFTDAYS2,
|
||
REJECTREMARK = M.REJECTREMARK,
|
||
EXTERNAL_USERID = M.EXTERNAL_USERID,
|
||
WEWORK_REMOTEID = M.WEWORK_REMOTEID,
|
||
FUJIAN = M.FUJIAN,
|
||
DEPTCODE = M.DEPTCODE,
|
||
ESTIMATEOTIME = M.ESTIMATEOTIME,
|
||
EID = M.EID,
|
||
ISDISMISS = i.ISDISMISS,
|
||
CreateEid = i.EID
|
||
}
|
||
);
|
||
if (querydto.eid.HasValue)
|
||
{
|
||
queryData = queryData.Where(m => m.CreateEid == querydto.eid);
|
||
}
|
||
else
|
||
{
|
||
queryData = queryData.Where(m => m.ISDISMISS == querydto.isdismiss);
|
||
}
|
||
}
|
||
if (usercomboDto.userId.HasValue)
|
||
{
|
||
queryData = queryData.Where(m => m.INNERUSERID == usercomboDto.userId.Value);
|
||
}
|
||
else if (!string.IsNullOrEmpty(usercomboDto.groupIds))
|
||
{
|
||
var _groupids = OperationUtil.ConvertToDecimal(usercomboDto.groupIds.Split(','));
|
||
queryData = (from a in queryData
|
||
join b in db.BAS_INNERUSERGROUP on a.INNERUSERID equals b.INNERUSERID
|
||
where _groupids.Contains(b.GID.Value)
|
||
select a);
|
||
}
|
||
else if (!string.IsNullOrEmpty(usercomboDto.deptId))
|
||
{
|
||
var depts = OperationUtil.ConvertToDecimal(usercomboDto.deptId.Split(','));
|
||
List<decimal> ALLdeptIDS = new List<decimal>();
|
||
List<decimal> ALLgidS = new List<decimal>();
|
||
UserServices userservices = new UserServices(cache_BL);
|
||
foreach (var item in depts)
|
||
{
|
||
List<decimal> deptIDS = new List<decimal>();
|
||
List<decimal> gidS = new List<decimal>();
|
||
userservices.GetAllDeptIDOrGidByDeptId(item, ref deptIDS, ref gidS);//获取所有的组别和gid
|
||
ALLdeptIDS.AddRange(deptIDS);
|
||
ALLgidS.AddRange(gidS);
|
||
}
|
||
|
||
var deptcodes = (from a in db.BAS_BUSINESSDEPARTMENT
|
||
join b in db.BAS_SALESDEPARTMENT on a.DEPTID equals b.SALEDEPTID
|
||
where ALLdeptIDS.Contains(a.DEPTID)
|
||
select b.SALEDEPTCODE).ToArray();
|
||
queryData = (from a in queryData
|
||
join x in db.BAS_INNERUSERGROUP on a.INNERUSERID equals x.INNERUSERID into tempB
|
||
from b in tempB.DefaultIfEmpty()
|
||
//join g in db.BAS_INNERGROUP on b.GID equals g.GID
|
||
where ALLdeptIDS.Contains(b.DEPTID.Value) || ALLgidS.Contains(b.GID.Value) || deptcodes.Contains(a.DEPTCODE)
|
||
select a);
|
||
}
|
||
else if (usercomboDto.companyId.HasValue)
|
||
{
|
||
queryData = (from a in queryData
|
||
join b in db.BAS_INNERUSERGROUP on a.INNERUSERID equals b.INNERUSERID
|
||
join g in db.BAS_INNERGROUP on b.GID equals g.GID
|
||
join m in db.BAS_SALESDEPARTMENT on g.SALEDEPTID equals m.SALEDEPTID
|
||
where m.COMPANYID == usercomboDto.companyId.Value
|
||
select a);
|
||
}
|
||
if (!string.IsNullOrWhiteSpace(querydto.resId))
|
||
{
|
||
querydto.resId = querydto.resId.Trim();
|
||
queryData = queryData.Where(m => m.RESID == querydto.resId);
|
||
}
|
||
if (querydto.szzyOrderId.HasValue)
|
||
{
|
||
queryData = queryData.Where(m => m.ORDERID == querydto.szzyOrderId.Value);
|
||
}
|
||
if (!string.IsNullOrWhiteSpace(querydto.contractCode))
|
||
{
|
||
querydto.contractCode = querydto.contractCode.Trim();
|
||
queryData = queryData.Where(m => m.CONTRACTCODE == querydto.contractCode);
|
||
}
|
||
if (querydto.subProductId > 0)
|
||
{
|
||
queryData = queryData.Where(m => m.SUBPRODUCTID == querydto.subProductId);
|
||
}
|
||
else
|
||
{
|
||
if (querydto.productId > 0)
|
||
{
|
||
queryData = queryData.Where(m => m.PRODUCTID == querydto.productId);
|
||
}
|
||
if (querydto.midProductId.HasValue)
|
||
{
|
||
var arr = db.WX_SZZYSUBPRODUCT.Where(p => p.MIDPRODUCTID == querydto.midProductId.Value).Select(p => p.SUBPRODUCTID).ToList();
|
||
queryData = queryData.Where(p => arr.Contains((int)p.SUBPRODUCTID));
|
||
}
|
||
}
|
||
if (querydto.orderType > 0)
|
||
{
|
||
queryData = queryData.Where(m => m.ORDERTYPE == querydto.orderType);
|
||
}
|
||
if (!string.IsNullOrWhiteSpace(querydto.stime))
|
||
{
|
||
DateTime time1 = Convert.ToDateTime(querydto.stime);
|
||
queryData = queryData.Where(m => m.ARRIVALTIME >= time1);
|
||
}
|
||
if (!string.IsNullOrWhiteSpace(querydto.etime))
|
||
{
|
||
DateTime time2 = Convert.ToDateTime(querydto.etime).AddDays(1);
|
||
queryData = queryData.Where(m => m.ARRIVALTIME < time2);
|
||
}
|
||
if (querydto.orderStatus == "201")
|
||
{
|
||
//待开通状态
|
||
querydto.orderStatus = "200";
|
||
querydto.riskctrlstatus = 2;
|
||
}
|
||
if (!string.IsNullOrWhiteSpace(querydto.orderStatus))
|
||
{
|
||
var orderStatusArr = querydto.orderStatus.Split(',');
|
||
queryData = queryData.Where(m => orderStatusArr.Contains(m.ORDERSTATUS));
|
||
}
|
||
if (!string.IsNullOrWhiteSpace(querydto.ostime))
|
||
{
|
||
DateTime time1 = Convert.ToDateTime(querydto.ostime);
|
||
queryData = queryData.Where(m => m.OTIME >= time1);
|
||
}
|
||
if (!string.IsNullOrWhiteSpace(querydto.oetime))
|
||
{
|
||
DateTime time2 = Convert.ToDateTime(querydto.oetime).AddDays(1);
|
||
queryData = queryData.Where(m => m.OTIME < time2);
|
||
}
|
||
if (!string.IsNullOrWhiteSpace(querydto.fcText))
|
||
{
|
||
querydto.fcText = querydto.fcText.Trim();
|
||
queryData = queryData.Where(m => m.FCTEXT.Contains(querydto.fcText));
|
||
}
|
||
if (!string.IsNullOrEmpty(querydto.cName))
|
||
{
|
||
queryData = queryData.Where(m => m.CNAME.Contains(querydto.cName));
|
||
}
|
||
if (!string.IsNullOrEmpty(querydto.source))
|
||
{
|
||
queryData = queryData.Where(m => m.SOURCE == querydto.source);
|
||
}
|
||
if (querydto.xstime.HasValue)
|
||
{
|
||
queryData = queryData.Where(m => m.CTIME >= querydto.xstime.Value);
|
||
}
|
||
if (querydto.xetime.HasValue)
|
||
{
|
||
querydto.xetime = querydto.xetime.Value.AddDays(1);
|
||
queryData = queryData.Where(m => m.CTIME < querydto.xetime.Value);
|
||
}
|
||
if (querydto.fstime.HasValue)
|
||
{
|
||
queryData = queryData.Where(m => m.FINACEPAYDATE >= querydto.fstime.Value);
|
||
}
|
||
if (querydto.fetime.HasValue)
|
||
{
|
||
querydto.fetime = querydto.fetime.Value.AddDays(1);
|
||
queryData = queryData.Where(m => m.FINACEPAYDATE < querydto.fetime.Value);
|
||
}
|
||
if (querydto.riskctrlstatus.HasValue)
|
||
{
|
||
if (querydto.riskctrlstatus.Value == 0)
|
||
{
|
||
//未审核
|
||
queryData = queryData.Where(m => m.RISKCTRLSTATUS != 2 && m.RISKCTRLSTATUS != -1 && m.RISKCTRLSTATUS != null && m.CONTRACTCODE != null);
|
||
}
|
||
else if (querydto.riskctrlstatus.Value == -9)
|
||
{
|
||
queryData = queryData.Where(m => m.RISKCTRLSTATUS == null);
|
||
}
|
||
else
|
||
{
|
||
queryData = queryData.Where(m => m.RISKCTRLSTATUS == querydto.riskctrlstatus.Value);
|
||
}
|
||
}
|
||
if (!string.IsNullOrEmpty(querydto.deptcode))
|
||
{
|
||
queryData = queryData.Where(p => p.DEPTCODE == querydto.deptcode);
|
||
}
|
||
if (querydto.orderStatus == "220" || querydto.orderStatus == "220,205")
|
||
{
|
||
queryData = queryData.OrderByDescending(m => m.OTIME).ThenByDescending(p => p.CTIME);
|
||
}
|
||
else
|
||
{
|
||
//queryData = queryData.OrderByDescending(m => m.OTIME.HasValue).ThenByDescending(m => m.OTIME).ThenByDescending(m => m.CTIME);
|
||
queryData = queryData.OrderByDescending(m => m.CTIME);
|
||
}
|
||
if (querydto.payminPrice.HasValue)
|
||
{
|
||
queryData = queryData.Where(n => n.ARRIVALPAY >= querydto.payminPrice);
|
||
}
|
||
if (querydto.paymaxPrice.HasValue)
|
||
{
|
||
queryData = queryData.Where(n => n.ARRIVALPAY <= querydto.paymaxPrice);
|
||
}
|
||
WX_SZZYORDERDTO orderSum = new WX_SZZYORDERDTO()
|
||
{
|
||
RESID = "合计",
|
||
NEEDPAY = queryData.Sum(p => p.NEEDPAY),
|
||
FINALPAY = queryData.Sum(p => p.FINALPAY),
|
||
ARRIVALPAY = queryData.Sum(p => p.ARRIVALPAY),
|
||
ORDERTYPE = 0,
|
||
ORDERSTATUS = string.Empty
|
||
};
|
||
PagerUtil.SetPager<WX_SZZYORDERDTO>(ref queryData, ref pager);
|
||
var list = queryData.ToList();
|
||
list.Add(orderSum);
|
||
|
||
//db.Database.Log = log => File.AppendAllText(@"d:\log\ef.log", string.Format("{0}{1}{2}", DateTime.Now, Environment.NewLine, log));
|
||
|
||
return list;
|
||
}
|
||
}
|
||
|
||
public List<WX_SZZYORDER> GetListByChannel(ref Pager pager, string resId, string contractCode, string szzyOrderId, decimal productId, decimal subProductId, decimal orderType, string stime, string etime, decimal saleDeptId, string groupId, decimal innerUserId, string orderStatus, string ostime, string oetime, string fcText, string cName, string channel)
|
||
{
|
||
using (var db = new crmContext())
|
||
{
|
||
var queryData = db.WX_SZZYORDER.AsQueryable();
|
||
if (innerUserId > 0)
|
||
{
|
||
queryData = queryData.Where(m => m.INNERUSERID == innerUserId);
|
||
}
|
||
else
|
||
{
|
||
if (!string.IsNullOrWhiteSpace(groupId) && (groupId.IndexOf(',') < 0 || saleDeptId <= 1)) //当单个组时走这个判断
|
||
{
|
||
var _groupids = OperationUtil.ConvertToDecimal(groupId.ToString().Split(','));
|
||
List<decimal?> groupList = new List<decimal?>();
|
||
if (_groupids != null)
|
||
{
|
||
foreach (var g in _groupids)
|
||
{
|
||
groupList.Add(g);
|
||
}
|
||
}
|
||
if (groupList != null)
|
||
{
|
||
var returnData = (from a in queryData
|
||
join b in db.BAS_INNERUSERGROUP on a.INNERUSERID equals b.INNERUSERID
|
||
where groupList.Contains(b.GID)
|
||
select a);
|
||
|
||
queryData = returnData;
|
||
}
|
||
}
|
||
else if (saleDeptId > 1) //销售部门走这个判断
|
||
{
|
||
queryData = (from a in queryData
|
||
join b in db.BAS_INNERUSERGROUP on a.INNERUSERID equals b.INNERUSERID
|
||
join c in db.BAS_INNERGROUP on b.GID equals c.GID
|
||
join d in db.BAS_SALESDEPARTMENT on c.SALEDEPTID equals d.SALEDEPTID
|
||
where d.SALEDEPTID == saleDeptId
|
||
select a);
|
||
}
|
||
}
|
||
if (!string.IsNullOrWhiteSpace(resId))
|
||
{
|
||
resId = resId.Trim();
|
||
queryData = queryData.Where(m => m.RESID == resId);
|
||
}
|
||
if (!string.IsNullOrWhiteSpace(szzyOrderId))
|
||
{
|
||
szzyOrderId = szzyOrderId.Trim();
|
||
var id = Convert.ToDecimal(szzyOrderId);
|
||
queryData = queryData.Where(m => m.ORDERID == id);
|
||
}
|
||
if (!string.IsNullOrWhiteSpace(contractCode))
|
||
{
|
||
contractCode = contractCode.Trim();
|
||
queryData = queryData.Where(m => m.CONTRACTCODE == contractCode);
|
||
}
|
||
if (subProductId > 0)
|
||
{
|
||
queryData = queryData.Where(m => m.SUBPRODUCTID == subProductId);
|
||
}
|
||
else
|
||
{
|
||
if (productId > 0)
|
||
{
|
||
queryData = queryData.Where(m => m.PRODUCTID == productId);
|
||
}
|
||
}
|
||
if (orderType > 0)
|
||
{
|
||
queryData = queryData.Where(m => m.ORDERTYPE == orderType);
|
||
}
|
||
if (!string.IsNullOrWhiteSpace(stime))
|
||
{
|
||
DateTime time1 = Convert.ToDateTime(stime);
|
||
queryData = queryData.Where(m => m.ARRIVALTIME >= time1);
|
||
}
|
||
if (!string.IsNullOrWhiteSpace(etime))
|
||
{
|
||
DateTime time2 = Convert.ToDateTime(etime).AddDays(1);
|
||
queryData = queryData.Where(m => m.ARRIVALTIME < time2);
|
||
}
|
||
if (!string.IsNullOrWhiteSpace(orderStatus))
|
||
{
|
||
var orderStatusArr = orderStatus.Split(',');
|
||
queryData = queryData.Where(m => orderStatusArr.Contains(m.ORDERSTATUS));
|
||
}
|
||
if (!string.IsNullOrWhiteSpace(ostime))
|
||
{
|
||
DateTime time1 = Convert.ToDateTime(ostime);
|
||
queryData = queryData.Where(m => m.OTIME >= time1);
|
||
}
|
||
if (!string.IsNullOrWhiteSpace(oetime))
|
||
{
|
||
DateTime time2 = Convert.ToDateTime(oetime).AddDays(1);
|
||
queryData = queryData.Where(m => m.OTIME < time2);
|
||
}
|
||
if (!string.IsNullOrWhiteSpace(fcText))
|
||
{
|
||
fcText = fcText.Trim();
|
||
queryData = queryData.Where(m => m.FCTEXT.Contains(fcText));
|
||
}
|
||
if (!string.IsNullOrEmpty(cName))
|
||
{
|
||
queryData = queryData.Where(m => m.CNAME.Contains(cName));
|
||
}
|
||
|
||
if (orderStatus == "220" || orderStatus == "220,205")
|
||
{
|
||
queryData = queryData.OrderByDescending(m => m.OTIME);
|
||
}
|
||
else
|
||
{
|
||
//queryData = queryData.OrderByDescending(m => m.OTIME.HasValue).ThenByDescending(m => m.OTIME).ThenByDescending(m => m.CTIME);
|
||
queryData = queryData.OrderByDescending(m => m.CTIME);
|
||
}
|
||
|
||
var channelEnd = (Convert.ToInt32(channel) + 100).ToString();
|
||
var query = (from a in queryData
|
||
join b in db.WX_ORDEREXT on a.ORDERID equals b.ORDERID
|
||
where b.CHANNEL.CompareTo(channel) >= 0 && b.CHANNEL.CompareTo(channelEnd) < 0
|
||
select a);
|
||
|
||
WX_SZZYORDER orderSum = new WX_SZZYORDER()
|
||
{
|
||
RESID = "合计",
|
||
NEEDPAY = query.Sum(p => p.NEEDPAY),
|
||
FINALPAY = query.Sum(p => p.FINALPAY),
|
||
ARRIVALPAY = query.Sum(p => p.ARRIVALPAY),
|
||
ORDERTYPE = 0,
|
||
ORDERSTATUS = string.Empty
|
||
};
|
||
|
||
PagerUtil.SetPager<WX_SZZYORDER>(ref query, ref pager);
|
||
var list = query.ToList();
|
||
list.Add(orderSum);
|
||
|
||
//db.Database.Log = log => File.AppendAllText(@"d:\log\ef.log", string.Format("{0}{1}{2}", DateTime.Now, Environment.NewLine, log));
|
||
|
||
return list;
|
||
}
|
||
}
|
||
|
||
public List<WX_SZZYORDER> GetList2(ref Pager pager, string resId, string contractCode, string szzyOrderId, decimal productId, decimal subProductId, decimal orderType, string stime, string etime, decimal saleDeptId, string groupId, decimal innerUserId, string orderStatus, string ostime, string oetime, string fcText, string cName, decimal? teamEid, bool? smallorder)
|
||
{
|
||
using (var db = new crmContext())
|
||
{
|
||
var queryData = db.WX_SZZYORDER.AsQueryable();
|
||
if (innerUserId > 0)
|
||
{
|
||
queryData = queryData.Where(m => m.INNERUSERID == innerUserId);
|
||
}
|
||
else
|
||
{
|
||
if (!string.IsNullOrWhiteSpace(groupId) && (groupId.IndexOf(',') < 0 || saleDeptId <= 1)) //当单个组时走这个判断
|
||
{
|
||
var _groupids = OperationUtil.ConvertToDecimal(groupId.Split(','));
|
||
List<decimal?> groupList = new List<decimal?>();
|
||
if (_groupids != null)
|
||
{
|
||
foreach (var g in _groupids)
|
||
{
|
||
groupList.Add(g);
|
||
}
|
||
}
|
||
if (groupList != null)
|
||
{
|
||
var returnData = (from a in queryData
|
||
join b in db.BAS_INNERUSERGROUP on a.INNERUSERID equals b.INNERUSERID
|
||
where groupList.Contains(b.GID)
|
||
select a);
|
||
|
||
queryData = returnData;
|
||
}
|
||
}
|
||
else if (saleDeptId > 1) //销售部门走这个判断
|
||
{
|
||
queryData = queryData.Where(m => m.SALEDEPTID == saleDeptId);
|
||
}
|
||
}
|
||
|
||
//用不上了,已经用了分组控件限制了
|
||
//if (teamEid.HasValue)
|
||
//{
|
||
// decimal t = teamEid.Value;
|
||
// var returnData = (from a in queryData
|
||
// join b in db.BAS_INNERUSERGROUP on a.INNERUSERID equals b.INNERUSERID
|
||
// join team in db.BAS_TEAM on b.GID equals team.GID
|
||
// where team.TEAMLEADEREID == t
|
||
// select a);
|
||
|
||
// queryData = returnData;
|
||
//}
|
||
if (!string.IsNullOrWhiteSpace(resId))
|
||
{
|
||
resId = resId.Trim();
|
||
queryData = queryData.Where(m => m.RESID == resId);
|
||
}
|
||
if (!string.IsNullOrWhiteSpace(szzyOrderId))
|
||
{
|
||
szzyOrderId = szzyOrderId.Trim();
|
||
var id = Convert.ToDecimal(szzyOrderId);
|
||
queryData = queryData.Where(m => m.SZZYORDERID == id);
|
||
}
|
||
if (!string.IsNullOrWhiteSpace(contractCode))
|
||
{
|
||
contractCode = contractCode.Trim();
|
||
queryData = queryData.Where(m => m.CONTRACTCODE == contractCode);
|
||
}
|
||
if (subProductId > 0)
|
||
{
|
||
queryData = queryData.Where(m => m.SUBPRODUCTID == subProductId);
|
||
}
|
||
else
|
||
{
|
||
if (productId > 0)
|
||
{
|
||
queryData = queryData.Where(m => m.PRODUCTID == productId);
|
||
}
|
||
}
|
||
if (orderType > 0)
|
||
{
|
||
queryData = queryData.Where(m => m.ORDERTYPE == orderType);
|
||
}
|
||
if (!string.IsNullOrWhiteSpace(stime))
|
||
{
|
||
DateTime time1 = Convert.ToDateTime(stime);
|
||
queryData = queryData.Where(m => m.ARRIVALTIME >= time1);
|
||
}
|
||
if (!string.IsNullOrWhiteSpace(etime))
|
||
{
|
||
DateTime time2 = Convert.ToDateTime(etime).AddDays(1);
|
||
queryData = queryData.Where(m => m.ARRIVALTIME < time2);
|
||
}
|
||
if (!string.IsNullOrWhiteSpace(orderStatus))
|
||
{
|
||
orderStatus = orderStatus.Trim();
|
||
queryData = queryData.Where(m => m.ORDERSTATUS == orderStatus);
|
||
}
|
||
if (!string.IsNullOrWhiteSpace(ostime))
|
||
{
|
||
DateTime time1 = Convert.ToDateTime(ostime);
|
||
queryData = queryData.Where(m => m.OTIME >= time1);
|
||
}
|
||
if (!string.IsNullOrWhiteSpace(oetime))
|
||
{
|
||
DateTime time2 = Convert.ToDateTime(oetime).AddDays(1);
|
||
queryData = queryData.Where(m => m.OTIME < time2);
|
||
}
|
||
if (!string.IsNullOrWhiteSpace(fcText))
|
||
{
|
||
fcText = fcText.Trim();
|
||
queryData = queryData.Where(m => m.FCTEXT.Contains(fcText));
|
||
}
|
||
if (!string.IsNullOrEmpty(cName))
|
||
{
|
||
queryData = queryData.Where(m => m.CNAME.Contains(cName));
|
||
}
|
||
if (smallorder.HasValue && !smallorder.Value && string.IsNullOrEmpty(resId) && string.IsNullOrEmpty(szzyOrderId) && subProductId == 0 && productId == 0)
|
||
{
|
||
queryData = queryData.Where(m => m.ARRIVALPAY > 100);
|
||
}
|
||
queryData = queryData.OrderByDescending(m => m.CTIME).OrderByDescending(m => m.OPERATETIME);
|
||
WX_SZZYORDER orderSum = new WX_SZZYORDER()
|
||
{
|
||
RESID = "合计",
|
||
NEEDPAY = queryData.Sum(p => p.NEEDPAY),
|
||
FINALPAY = queryData.Sum(p => p.FINALPAY),
|
||
ARRIVALPAY = queryData.Sum(p => p.ARRIVALPAY),
|
||
ORDERTYPE = 0,
|
||
ORDERSTATUS = string.Empty
|
||
};
|
||
PagerUtil.SetPager<WX_SZZYORDER>(ref queryData, ref pager);
|
||
var list = queryData.ToList();
|
||
list.Add(orderSum);
|
||
return list;
|
||
}
|
||
}
|
||
|
||
public List<WX_SZZYORDER> GetList_SH(ref Pager pager, string resId, string contractCode, string szzyOrderId, decimal productId, decimal subProductId, decimal orderType, string stime, string etime, decimal? groupId, decimal innerUserId, string orderStatus, string ostime, string oetime, string fcText, string cName, decimal? saleDeptId)
|
||
{
|
||
using (var db = new crmContext())
|
||
{
|
||
var queryData = db.WX_SZZYORDER.AsQueryable();
|
||
queryData = queryData.Where(m => m.SALEDEPTID == saleDeptId);
|
||
if (innerUserId > 0)
|
||
{
|
||
queryData = queryData.Where(m => m.INNERUSERID == innerUserId);
|
||
}
|
||
else if (groupId.HasValue && groupId.Value > 0)
|
||
{
|
||
decimal g = groupId.Value;
|
||
var returnData = (from a in queryData
|
||
join b in db.BAS_INNERUSERGROUP on a.INNERUSERID equals b.INNERUSERID
|
||
where b.GID == g
|
||
select a);
|
||
|
||
queryData = returnData;
|
||
}
|
||
if (!string.IsNullOrWhiteSpace(resId))
|
||
{
|
||
resId = resId.Trim();
|
||
queryData = queryData.Where(m => m.RESID == resId);
|
||
}
|
||
if (!string.IsNullOrWhiteSpace(szzyOrderId))
|
||
{
|
||
szzyOrderId = szzyOrderId.Trim();
|
||
var id = Convert.ToDecimal(szzyOrderId);
|
||
queryData = queryData.Where(m => m.SZZYORDERID == id);
|
||
}
|
||
if (!string.IsNullOrWhiteSpace(contractCode))
|
||
{
|
||
contractCode = contractCode.Trim();
|
||
queryData = queryData.Where(m => m.CONTRACTCODE == contractCode);
|
||
}
|
||
if (subProductId > 0)
|
||
{
|
||
queryData = queryData.Where(m => m.SUBPRODUCTID == subProductId);
|
||
}
|
||
else
|
||
{
|
||
if (productId > 0)
|
||
{
|
||
queryData = queryData.Where(m => m.PRODUCTID == productId);
|
||
}
|
||
}
|
||
if (orderType > 0)
|
||
{
|
||
queryData = queryData.Where(m => m.ORDERTYPE == orderType);
|
||
}
|
||
if (!string.IsNullOrWhiteSpace(stime))
|
||
{
|
||
DateTime time1 = Convert.ToDateTime(stime);
|
||
queryData = queryData.Where(m => m.ARRIVALTIME >= time1);
|
||
}
|
||
if (!string.IsNullOrWhiteSpace(etime))
|
||
{
|
||
DateTime time2 = Convert.ToDateTime(etime).AddDays(1);
|
||
queryData = queryData.Where(m => m.ARRIVALTIME < time2);
|
||
}
|
||
if (!string.IsNullOrWhiteSpace(orderStatus))
|
||
{
|
||
orderStatus = orderStatus.Trim();
|
||
queryData = queryData.Where(m => m.ORDERSTATUS == orderStatus);
|
||
}
|
||
if (!string.IsNullOrWhiteSpace(ostime))
|
||
{
|
||
DateTime time1 = Convert.ToDateTime(ostime);
|
||
queryData = queryData.Where(m => m.OTIME >= time1);
|
||
}
|
||
if (!string.IsNullOrWhiteSpace(oetime))
|
||
{
|
||
DateTime time2 = Convert.ToDateTime(oetime).AddDays(1);
|
||
queryData = queryData.Where(m => m.OTIME < time2);
|
||
}
|
||
if (!string.IsNullOrWhiteSpace(fcText))
|
||
{
|
||
fcText = fcText.Trim();
|
||
queryData = queryData.Where(m => m.FCTEXT.Contains(fcText));
|
||
}
|
||
if (!string.IsNullOrEmpty(cName))
|
||
{
|
||
queryData = queryData.Where(m => m.CNAME.Contains(cName));
|
||
}
|
||
queryData = queryData.OrderByDescending(m => m.CTIME).OrderByDescending(m => m.OPERATETIME);
|
||
WX_SZZYORDER orderSum = new WX_SZZYORDER()
|
||
{
|
||
RESID = "合计",
|
||
NEEDPAY = queryData.Sum(p => p.NEEDPAY),
|
||
FINALPAY = queryData.Sum(p => p.FINALPAY),
|
||
ARRIVALPAY = queryData.Sum(p => p.ARRIVALPAY),
|
||
ORDERTYPE = 0,
|
||
ORDERSTATUS = string.Empty
|
||
};
|
||
PagerUtil.SetPager<WX_SZZYORDER>(ref queryData, ref pager);
|
||
var list = queryData.ToList();
|
||
list.Add(orderSum);
|
||
return list;
|
||
}
|
||
}
|
||
|
||
public bool UpdateRequestStatus(decimal orderId, decimal flag)
|
||
{
|
||
try
|
||
{
|
||
using (var db = new crmContext())
|
||
{
|
||
var model = db.WX_SZZYORDER.Where(m => m.ORDERID == orderId).FirstOrDefault();
|
||
if (model != null)
|
||
{
|
||
model.REQUESTSTATUS = flag;
|
||
}
|
||
return db.SaveChanges().GetResult();
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
LogHelper.Error(ex);
|
||
return false;
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 修改分成信息
|
||
/// </summary>
|
||
/// <param name="orderId">订单号</param>
|
||
/// <param name="fctxt">分成内容</param>
|
||
/// <returns></returns>
|
||
public bool UpdateFCTXT(decimal orderId, string fctxt)
|
||
{
|
||
try
|
||
{
|
||
using (var db = new crmContext())
|
||
{
|
||
var model = db.WX_SZZYORDER.Where(m => m.ORDERID == orderId).FirstOrDefault();
|
||
if (model != null)
|
||
{
|
||
model.FCTEXT = fctxt;
|
||
}
|
||
return db.SaveChanges().GetResult();
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
LogHelper.Error(ex);
|
||
return false;
|
||
}
|
||
}
|
||
|
||
public List<WX_SZZYORDER> GetUpgradeList(string[] upgradeOrderIds)
|
||
{
|
||
using (var db = new crmContext())
|
||
{
|
||
var queryData = db.WX_SZZYORDER.AsQueryable();
|
||
if (upgradeOrderIds != null && upgradeOrderIds.Length > 0)
|
||
{
|
||
List<decimal> szzyOrderIds = upgradeOrderIds.Select<string, decimal>(m => Convert.ToDecimal(m)).ToList();
|
||
queryData = queryData.Where(m => szzyOrderIds.Contains(m.SZZYORDERID.Value));
|
||
return queryData.ToList();
|
||
}
|
||
return new List<WX_SZZYORDER>();
|
||
}
|
||
}
|
||
|
||
public DataSet CountSzzyOrder(string stime, string etime)
|
||
{
|
||
return wx_SzzyOrder_DAL.CountSzzyOrder(stime, etime);
|
||
}
|
||
|
||
public List<WX_SZZYORDER> GetList(decimal[] subProductIds, string stime, string etime, decimal type, decimal threeDeptId)
|
||
{
|
||
using (var db = new crmContext())
|
||
{
|
||
var queryData = db.WX_SZZYORDER.AsQueryable();
|
||
if (subProductIds != null && subProductIds.Length > 0)
|
||
{
|
||
queryData = queryData.Where(m => subProductIds.Contains(m.SUBPRODUCTID.Value));
|
||
}
|
||
if (!string.IsNullOrWhiteSpace(stime))
|
||
{
|
||
stime = stime.Trim();
|
||
var dt = Convert.ToDateTime(stime);
|
||
queryData = queryData.Where(m => m.ARRIVALTIME >= dt);
|
||
}
|
||
if (!string.IsNullOrWhiteSpace(etime))
|
||
{
|
||
etime = etime.Trim();
|
||
var dt = Convert.ToDateTime(etime).AddDays(1);
|
||
queryData = queryData.Where(m => m.ARRIVALTIME < dt);
|
||
}
|
||
if (type == 1)
|
||
{
|
||
queryData = queryData.Where(m => m.SALEDEPTID != threeDeptId && m.SALEDEPTID != 1619629758);
|
||
}
|
||
else if (type == 3)
|
||
{
|
||
queryData = queryData.Where(m => m.SALEDEPTID == threeDeptId);
|
||
}
|
||
else if (type == 5)
|
||
{
|
||
queryData = queryData.Where(m => m.SALEDEPTID == 1619629758);
|
||
}
|
||
return queryData.OrderByDescending(m => m.ARRIVALTIME).ToList();
|
||
}
|
||
}
|
||
|
||
public List<WX_SZZYORDER> GetUnPayList(int dayInterval)
|
||
{
|
||
using (var db = new crmContext())
|
||
{
|
||
string[] orderStatusArr = new string[] { "1", "2", "3" };
|
||
var queryData = db.WX_SZZYORDER.AsQueryable();
|
||
DateTime dt = DateTime.Now.AddDays(-dayInterval);
|
||
queryData = queryData.Where(m => m.CTIME > dt && orderStatusArr.Contains(m.ORDERSTATUS));
|
||
return queryData.OrderByDescending(m => m.CTIME).ToList();
|
||
}
|
||
}
|
||
|
||
private string getOrderStatusStr(string orderStatus)
|
||
{
|
||
if (orderStatus == "1")
|
||
{
|
||
return "已下单";
|
||
}
|
||
else if (orderStatus == "2")
|
||
{
|
||
return "部分支付";
|
||
}
|
||
else if (orderStatus == "3")
|
||
{
|
||
return "已支付";
|
||
}
|
||
else if (orderStatus == "4")
|
||
{
|
||
return "已开通";
|
||
}
|
||
else if (orderStatus == "5")
|
||
{
|
||
return "已到期";
|
||
}
|
||
else if (orderStatus == "6")
|
||
{
|
||
return "已升级";
|
||
}
|
||
else if (orderStatus == "7")
|
||
{
|
||
return "已退款";
|
||
}
|
||
else if (orderStatus == "8")
|
||
{
|
||
return "已取消";
|
||
}
|
||
else if (orderStatus == "9")
|
||
{
|
||
return "已关闭";
|
||
}
|
||
else if (orderStatus == "10")
|
||
{
|
||
return "隐藏";
|
||
}
|
||
else
|
||
{
|
||
return "";
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取已开通的订单列表(by时间间隔)
|
||
/// </summary>
|
||
/// <param name="starttime">开始时间</param>
|
||
/// <param name="endtime">结束时间</param>
|
||
/// <returns>订单列表</returns>
|
||
public List<WX_SZZYORDER_PUSH> GetSZZYOrderListByTime(DateTime starttime, DateTime endtime)
|
||
{
|
||
using (var db = new crmContext())
|
||
{
|
||
var query = from a in db.WX_SZZYORDER.Where(m => m.ISOPEN == 1 && ((m.OTIME >= starttime && m.OTIME < endtime) || (m.CTIME >= starttime && m.CTIME < endtime)))
|
||
join b in db.RES_RESOURCEMOBILE on a.RESID equals b.RESID
|
||
join d in db.WX_COMMISSIONRULE.Where(p => p.ISMAIN == 1) on a.ORDERID equals d.ORDERID into tmp0
|
||
from ad in tmp0.DefaultIfEmpty()
|
||
join c in db.BAS_INNERUSER on ad.SALEUSERID <= 0 ? a.INNERUSERID : ad.SALEUSERID equals c.PKID
|
||
select new WX_SZZYORDER_PUSH
|
||
{
|
||
orderid = a.ORDERID,
|
||
eid = c.EID,
|
||
userid = a.CUSTOMERUSERNAME,
|
||
phone = b.MOBILE,
|
||
productid = a.SUBPRODUCTID,
|
||
price = a.FINALPAY.Value,
|
||
startTime = a.OTIME,
|
||
endTime = a.ENDTIME,
|
||
SzzyOrderId = a.SZZYORDERID
|
||
};
|
||
|
||
return query.ToList();
|
||
}
|
||
}
|
||
|
||
public List<WX_SZZYORDER_PUSH> GetSZZYOrderListHasUserName()
|
||
{
|
||
using (var db = new crmContext())
|
||
{
|
||
var query = from a in db.WX_SZZYORDER.Where(m => m.ISOPEN == 1 && m.CUSTOMERUSERNAME != null)
|
||
join b in db.RES_RESOURCEMOBILE on a.RESID equals b.RESID
|
||
join c in db.BAS_INNERUSER on a.INNERUSERID equals c.PKID
|
||
join d in db.WX_SZZYORDERUSERNAME on a.ORDERID equals d.ORDERID
|
||
where d.ISDELETE == 0
|
||
select new WX_SZZYORDER_PUSH
|
||
{
|
||
orderid = a.ORDERID,
|
||
eid = c.EID,
|
||
userid = a.CUSTOMERUSERNAME,
|
||
phone = b.MOBILE,
|
||
productid = a.SUBPRODUCTID,
|
||
price = a.FINALPAY.Value,
|
||
startTime = a.OTIME,
|
||
endTime = a.ENDTIME,
|
||
SzzyOrderId = a.SZZYORDERID
|
||
};
|
||
|
||
return query.ToList();
|
||
}
|
||
}
|
||
|
||
public List<WX_SZZYORDER_PUSH> GetSzzyOrderListInfo()
|
||
{
|
||
var sTime = DateTime.Now.AddMonths(-2);
|
||
using (var db = new crmContext())
|
||
{
|
||
var query = from a in db.WX_SZZYORDER.Where(p => p.ISOPEN == 1)
|
||
join aa in db.WX_ORDEREXT on a.ORDERID equals aa.ORDERID
|
||
join b in db.RES_RESOURCEMOBILE on a.RESID equals b.RESID
|
||
join c in db.WX_COMMISSIONRULE.Where(p => p.ISMAIN == 1) on a.ORDERID equals c.ORDERID into tmp0
|
||
from ac in tmp0.DefaultIfEmpty()
|
||
join e in db.WX_SZZYORDERUSERNAME on a.ORDERID equals e.ORDERID into tmp2
|
||
from ae in tmp2.DefaultIfEmpty()
|
||
where a.OTIME >= sTime && a.OTIME < DateTime.Now && (ac.SALEUSERID > 0 ? ac.SALEUSERID : a.INNERUSERID) != ae.INNERUSERID
|
||
select new WX_SZZYORDER_PUSH
|
||
{
|
||
orderid = a.ORDERID,
|
||
eid = (ac.SALEUSERID > 0 ? ac.SALEUSERID : a.INNERUSERID).Value,
|
||
userid = aa.SOFTUSERNAME,
|
||
phone = b.MOBILE,
|
||
productid = a.SUBPRODUCTID,
|
||
price = a.FINALPAY.Value,
|
||
startTime = a.OTIME,
|
||
endTime = a.ENDTIME,
|
||
SzzyOrderId = a.ORDERID,
|
||
SaleDeptId = null,
|
||
orderstatus = a.ORDERSTATUS
|
||
};
|
||
return query.ToList();
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 计算订单的到期时间
|
||
/// </summary>
|
||
public void updateSzzyOrderEndTime()
|
||
{
|
||
new WX_SZZYORDER_DAL().updateSzzyOrderEndTime();
|
||
}
|
||
|
||
public bool UpdateCustomerWXUserNameByResId(string resId, string username)
|
||
{
|
||
try
|
||
{
|
||
wx_SzzyOrder_DAL.UpdateCustomerWXUserNameByResId(resId, username);
|
||
return true;
|
||
}
|
||
catch
|
||
{
|
||
return false;
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取mobile
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
public List<string> GetVipMobile(ref DateTime maxdatetime)
|
||
{
|
||
return wx_SzzyOrder_DAL.GetVipMobile(ref maxdatetime);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 修改状态
|
||
/// </summary>
|
||
/// <param name="time"></param>
|
||
/// <returns></returns>
|
||
public bool UpdateVipTime(DateTime time)
|
||
{
|
||
return wx_SzzyOrder_DAL.UpdateVipTime(time);
|
||
}
|
||
|
||
public bool UpdateResIdByWxUserName(string resId, string username)
|
||
{
|
||
try
|
||
{
|
||
wx_SzzyOrder_DAL.UpdateResIdByWxUserName(resId, username);
|
||
return true;
|
||
}
|
||
catch
|
||
{
|
||
return false;
|
||
}
|
||
}
|
||
|
||
public bool UpdateResIdByQwUserName(string resId, string username)
|
||
{
|
||
try
|
||
{
|
||
wx_SzzyOrder_DAL.UpdateResIdByQwUserName(resId, username);
|
||
return true;
|
||
}
|
||
catch
|
||
{
|
||
return false;
|
||
}
|
||
}
|
||
|
||
public bool DeleteResIdByWwUserName(string resId, string userId)
|
||
{
|
||
try
|
||
{
|
||
wx_SzzyOrder_DAL.DeleteResIdByWwUserName(resId, userId);
|
||
//UpdateIsBoundByResId(resId);//给res_customerdetial的isbound是否绑定微信做标记
|
||
return true;
|
||
}
|
||
catch (Exception e)
|
||
{
|
||
LogHelper.Error("resid:" + resId + ",错误:" + e.ToString());
|
||
return false;
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// todo
|
||
/// </summary>
|
||
/// <param name="resId"></param>
|
||
/// <param name="userId"></param>
|
||
/// <param name="innserUserid"></param>
|
||
/// <param name="corpId"></param>
|
||
/// <returns></returns>
|
||
public bool UpdateResIdByWwUserName(string resId, string userId, string innserUserid = null, string corpId = null)
|
||
{
|
||
try
|
||
{
|
||
decimal? fromEid = null;
|
||
decimal? toEid = null;
|
||
/* var myRes = _myRes.Get(p => p.RESID == resId);
|
||
//如果不是空,说明可以找到分配归属
|
||
if (myRes != null)
|
||
{
|
||
var user = _user.GetModel(myRes.INNERUSERID);
|
||
//找到分配归属EID
|
||
if (user != null)
|
||
{
|
||
fromEid = user.EID;
|
||
}
|
||
}*/
|
||
|
||
if (!string.IsNullOrEmpty(innserUserid) && !string.IsNullOrEmpty(corpId))
|
||
{
|
||
//找到企微对应的客服
|
||
var hhUserEid = _hhUser.GetModel(innserUserid, corpId);
|
||
if (hhUserEid != null)
|
||
{
|
||
toEid = hhUserEid.EID;
|
||
//写入待分配表
|
||
var user = _user.getInnerUserByEid(toEid.Value);
|
||
var myRes = _myRes.Get(p => p.RESID == resId && p.DEPTID == user.DEPTID);
|
||
if (myRes == null)
|
||
{
|
||
myRes = _myRes.Get(p => p.RESID == resId);
|
||
}
|
||
if (myRes != null)
|
||
{
|
||
var fromuser = _user.GetModel(myRes.INNERUSERID);
|
||
//找到分配归属EID
|
||
if (user != null)
|
||
{
|
||
fromEid = user.EID;
|
||
}
|
||
}
|
||
//如果资源没有归属才进行分配
|
||
if (myRes == null)
|
||
{
|
||
//如果归属的客服跟要分配的客服不同才进行分配
|
||
if (fromEid != toEid)
|
||
{
|
||
var pici = new SEQUENCES_BL().Seq_base_get();
|
||
var info = new RES_ALLCOTE_USER()
|
||
{
|
||
ID = new SEQUENCES_BL().Seq_base_get(),
|
||
INNERUSERID = user.PKID,
|
||
EID = toEid.Value,
|
||
NUM = 1,
|
||
CTIME = DateTime.Now,
|
||
PICI = pici,
|
||
RESID = resId,
|
||
TYPE = 1
|
||
};
|
||
_allcoteUser.Add(info);
|
||
|
||
//执行分配
|
||
var eid1000 = _user.getInnerUserByEid(10000).PKID;
|
||
_myRes.ExeSeniorDistributeByResId(eid1000, pici, "企微备注分配");
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
wx_SzzyOrder_DAL.UpdateResIdByWwUserName(resId, userId, fromEid, toEid);
|
||
UpdateIsBoundByResId(resId);//给res_customerdetial的isbound是否绑定微信做标记
|
||
return true;
|
||
}
|
||
catch (Exception e)
|
||
{
|
||
LogHelper.Error("resid:" + resId + ",错误:" + e.ToString());
|
||
return false;
|
||
}
|
||
}
|
||
|
||
public bool InsertWW_EXTUSER_PARES(WW_EXTUSER_PARES model)
|
||
{
|
||
try
|
||
{
|
||
wx_SzzyOrder_DAL.InsertWW_EXTUSER_PARES(model);
|
||
return true;
|
||
}
|
||
catch
|
||
{
|
||
return false;
|
||
}
|
||
}
|
||
|
||
public bool UpdateIsBoundByResId(string resId)
|
||
{
|
||
try
|
||
{
|
||
wx_SzzyOrder_DAL.UpdateIsBoundByResId(resId);
|
||
return true;
|
||
}
|
||
catch
|
||
{
|
||
return false;
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 存储订单选择企业微信外部联系人数据
|
||
/// </summary>
|
||
/// <param name="orderid"></param>
|
||
/// <param name="extuserid"></param>
|
||
/// <param name="userid"></param>
|
||
/// <param name="corpid"></param>
|
||
public void UpdateOrInsertOrderExtuserId(WW_SZZYORDER_EXTUSERID model)
|
||
{
|
||
try
|
||
{
|
||
using (var db = new crmContext())
|
||
{
|
||
var entry = db.WW_SZZYORDER_EXTUSERID.FirstOrDefault(m => m.ORDERID == model.ORDERID);
|
||
if (entry == null)
|
||
{
|
||
model.CTIME = DateTime.Now;
|
||
db.WW_SZZYORDER_EXTUSERID.Add(model);
|
||
}
|
||
else
|
||
{
|
||
entry.UTIME = DateTime.Now;
|
||
entry.USERID = model.USERID;
|
||
entry.EXTUSERID = model.EXTUSERID;
|
||
entry.CORPID = model.CORPID;
|
||
}
|
||
db.SaveChanges();
|
||
}
|
||
}
|
||
catch (Exception e)
|
||
{
|
||
LogHelper.Error(e.ToString());
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 存储订单选择企业微信外部联系人数据
|
||
/// </summary>
|
||
/// <param name="orderid"></param>
|
||
/// <param name="extuserid"></param>
|
||
/// <param name="userid"></param>
|
||
/// <param name="corpid"></param>
|
||
public WW_SZZYORDER_EXTUSERID GetExtUserIdByOrderId(decimal orderid)
|
||
{
|
||
using (var db = new crmContext())
|
||
{
|
||
var entry = db.WW_SZZYORDER_EXTUSERID.FirstOrDefault(m => m.ORDERID == orderid);
|
||
return entry;
|
||
}
|
||
}
|
||
|
||
public bool UpdateResIdByOpenId(string resId, string openId)
|
||
{
|
||
try
|
||
{
|
||
wx_SzzyOrder_DAL.UpdateResIdByOpenId(resId, openId);
|
||
return true;
|
||
}
|
||
catch
|
||
{
|
||
return false;
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 修改订单外部联系人ID,并新增推送消息
|
||
/// </summary>
|
||
/// <param name="time"></param>
|
||
/// <returns></returns>
|
||
public bool Sys_UpdateOrderExtentid(decimal v_orderid)
|
||
{
|
||
try
|
||
{
|
||
wx_SzzyOrder_DAL.Sys_UpdateOrderExtentid(v_orderid);
|
||
return true;
|
||
}
|
||
catch
|
||
{
|
||
return false;
|
||
}
|
||
}
|
||
|
||
public DataSet CountSzzyOrderBySource(string stime, string etime)
|
||
{
|
||
return wx_SzzyOrder_DAL.CountSzzyOrderBySource(stime, etime);
|
||
}
|
||
|
||
public DataSet CountSzzyClassifyOrder(string stime, string etime)
|
||
{
|
||
return wx_SzzyOrder_DAL.CountSzzyClassifyOrder(stime, etime);
|
||
}
|
||
|
||
public List<WX_SZZYORDER_PUSH> GetPayedOrderList(ref Pager pager)
|
||
{
|
||
//using(crmContext db = new crmContext())
|
||
//{
|
||
// var queryData = db.WX_SZZYORDER.AsQueryable();
|
||
// queryData = queryData.Where(m => m.ISOPEN == 1 && m.ARRIVALPAY>100);
|
||
// queryData = queryData.OrderByDescending(m => m.CTIME).OrderByDescending(m => m.OPERATETIME);
|
||
// PagerUtil.SetPager<WX_SZZYORDER>(ref queryData, ref pager);
|
||
// var list = queryData.ToList();
|
||
// return list;
|
||
//}
|
||
using (var db = new crmContext())
|
||
{
|
||
var query = from a in db.WX_SZZYORDER.Where(p => p.ISOPEN == 1 && p.ARRIVALPAY > 100)
|
||
join b in db.RES_RESOURCEMOBILE on a.RESID equals b.RESID
|
||
join c in db.WX_COMMISSIONRULE.Where(p => p.ISMAIN == 1) on a.ORDERID equals c.ORDERID into tmp0
|
||
from ac in tmp0.DefaultIfEmpty()
|
||
select new WX_SZZYORDER_PUSH
|
||
{
|
||
orderid = a.ORDERID,
|
||
eid = (ac.SALEUSERID > 0 ? ac.SALEUSERID : a.INNERUSERID).Value,
|
||
userid = a.CUSTOMERUSERNAME,
|
||
phone = b.MOBILE,
|
||
productid = a.SUBPRODUCTID,
|
||
price = a.FINALPAY.Value,
|
||
startTime = a.OTIME,
|
||
endTime = a.ENDTIME,
|
||
SzzyOrderId = a.SZZYORDERID,
|
||
SaleDeptId = a.SALEDEPTID
|
||
};
|
||
query = query.OrderBy(m => m.startTime);
|
||
PagerUtil.SetPager<WX_SZZYORDER_PUSH>(ref query, ref pager);
|
||
var list = query.ToList();
|
||
return list;
|
||
}
|
||
}
|
||
|
||
//public void UpdateWxSzzyOrder2(WX_SZZYORDER model)
|
||
//{
|
||
// wx_SzzyOrder_DAL.UpdateWxSzzyOrder2(model);
|
||
//}
|
||
|
||
public List<WX_SZZYORDER> GetCustomerUnpayOrderByResidAndWxname(string resid, decimal? subProductId, string wxCustomerId)
|
||
{
|
||
using (var db = new crmContext())
|
||
{
|
||
string[] orderStatusArr = new string[] { "1", "2" };
|
||
var queryData = db.WX_SZZYORDER.AsQueryable();
|
||
queryData = queryData.Where(m => m.RESID == resid && orderStatusArr.Contains(m.ORDERSTATUS) && m.SUBPRODUCTID == subProductId && m.CUSTOMERUSERNAME == wxCustomerId);
|
||
return queryData.OrderByDescending(m => m.CTIME).ToList();
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 更新订单用户的归类标识
|
||
/// </summary>
|
||
/// <param name="resId"></param>
|
||
/// <param name="customerClassify">客户分类id,多个用逗号隔开</param>
|
||
/// <returns></returns>
|
||
public bool UpdateCustomerClassify(string resId, string customerClassify)
|
||
{
|
||
return wx_SzzyOrder_DAL.UpdateCustomerClassify(resId, customerClassify);
|
||
}
|
||
|
||
public DataSet GetOrderCustomerVisit(ref Pager pg, string resId, string gender, string birthdayArea, string amountTypeId, decimal? provinceId, decimal? cityId, string jobTypeId, string operationType, decimal? hasHgRecord, string groupId, decimal? userId, decimal? orderType, string orderStatus, decimal? productId, decimal? midProductId, decimal? subProductId, DateTime? cTime1, DateTime? cTime2, DateTime? oTime1, DateTime? oTime2, DateTime? vTime1, DateTime? vTime2)
|
||
{
|
||
var ds = wx_SzzyOrder_DAL.GetOrderCustomerVisit(ref pg, resId, gender, birthdayArea, amountTypeId, provinceId, cityId, jobTypeId, operationType, hasHgRecord, groupId, userId, orderType, orderStatus, productId, midProductId, subProductId, cTime1, cTime2, oTime1, oTime2, vTime1, vTime2);
|
||
if (ds.Tables[0].Rows.Count > 0)
|
||
{
|
||
pg.totalRows = Convert.ToInt32(ds.Tables[0].Rows[0]["rowcount"]);
|
||
}
|
||
else pg.totalRows = 0;
|
||
return ds;
|
||
}
|
||
|
||
public DataSet GetOrderCustomerVisitExport(string resId, string gender, string birthdayArea, string amountTypeId, decimal? provinceId, decimal? cityId, string jobTypeId, string operationType, decimal? hasHgRecord, string groupId, decimal? userId, decimal? orderType, string orderStatus, decimal? productId, decimal? midProductId, decimal? subProductId, DateTime? cTime1, DateTime? cTime2, DateTime? oTime1, DateTime? oTime2, DateTime? vTime1, DateTime? vTime2)
|
||
{
|
||
var ds = wx_SzzyOrder_DAL.GetOrderCustomerVisitExport(resId, gender, birthdayArea, amountTypeId, provinceId, cityId, jobTypeId, operationType, hasHgRecord, groupId, userId, orderType, orderStatus, productId, midProductId, subProductId, cTime1, cTime2, oTime1, oTime2, vTime1, vTime2);
|
||
|
||
return ds;
|
||
}
|
||
|
||
public IList<WX_SZZYORDER> GetOrderByIds(List<decimal> Orderids)
|
||
{
|
||
using (var db = new crmContext())
|
||
{
|
||
string[] orderStatusArr = new string[] { "1", "2" };
|
||
var queryData = db.WX_SZZYORDER.AsQueryable();
|
||
queryData = queryData.Where(m => Orderids.Contains(m.ORDERID));
|
||
return queryData.ToList();
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取升级订单次数 同一天下的单算一次
|
||
/// </summary>
|
||
/// <param name="orderid"></param>
|
||
/// <returns></returns>
|
||
public int CountUpgradeOrder(decimal orderid)
|
||
{
|
||
var count = 0;
|
||
using (var db = new crmContext())
|
||
{
|
||
var order = db.WX_SZZYORDER.FirstOrDefault(n => n.ORDERID == orderid);
|
||
if (order != null && order.ORDERTYPE == 3)
|
||
{
|
||
//升级订单
|
||
List<string> containStatus = new List<string>
|
||
{
|
||
"220","205","80","90"
|
||
};
|
||
var orderDate = order.CTIME.Value.Date;
|
||
var hisOrderList = db.WX_SZZYORDER.Where(n => n.RESID == order.RESID && n.ORDERTYPE == 3 && n.CTIME < orderDate && containStatus.Contains(n.ORDERSTATUS)).ToList();
|
||
var oldcount = hisOrderList.GroupBy(n => n.CTIME.Value.ToShortDateString()).Count();
|
||
count = oldcount + 1;
|
||
}
|
||
return count;
|
||
}
|
||
}
|
||
|
||
public List<WX_SZZYORDER> GetOrderListByResId(string resId)
|
||
{
|
||
using (var db = new crmContext())
|
||
{
|
||
return db.WX_SZZYORDER.Where(n => n.RESID == resId).ToList();
|
||
}
|
||
}
|
||
}
|
||
} |