299 lines
13 KiB
C#
299 lines
13 KiB
C#
using System;
|
||
using System.IO;
|
||
using System.Web.Configuration;
|
||
using System.Xml.Serialization;
|
||
using System.Linq;
|
||
using WX.CRM.BLL.Base;
|
||
using WX.CRM.BLL.Res;
|
||
using WX.CRM.BLL.Util;
|
||
using WX.CRM.BLL.Wx;
|
||
using WX.CRM.Common;
|
||
using WX.CRM.DataSynFactory.Templates;
|
||
using WX.CRM.Model.Entity;
|
||
|
||
namespace WX.CRM.DataSynFactory.Cmd
|
||
{
|
||
public class Client_Order_IMP : Interfaces.IDataImportSvr<Client_Order>
|
||
{
|
||
private WX_SZZYORDER_BL _order = new WX_SZZYORDER_BL();
|
||
private WX_ORDEREXT_BL _orderExtend = new WX_ORDEREXT_BL();
|
||
private RES_CUSTOMER_BL res_Customer_BL = new RES_CUSTOMER_BL();
|
||
private BAS_INNERUSER_BL _user = new BAS_INNERUSER_BL();
|
||
private WX_SZZYSUBPRODUCT_BL _subProduct = new WX_SZZYSUBPRODUCT_BL();
|
||
private WX_COMMISSIONRULE_BL _rule = new WX_COMMISSIONRULE_BL();
|
||
private CACHE_BL _cache = new CACHE_BL();
|
||
private WX_AFTERSALES3_BL _aftersale3 = new WX_AFTERSALES3_BL();
|
||
public bool GenerateBusinessOne(Client_Order t)
|
||
{
|
||
try
|
||
{
|
||
var deptCode = string.Empty;
|
||
var ch = decimal.Parse(t.CHANNEL);
|
||
var bussDept = _cache.GetList_BussinessDepartMent();
|
||
var saleDept = _cache.GetList_SalesDepartMent();
|
||
var bussIds = bussDept.Select(p => p.DEPTID).ToList();
|
||
var subDept = saleDept.Where(p => bussIds.Contains(p.SALEDEPTID));
|
||
var objDept = subDept.FirstOrDefault(p => p.CHANNELMIN <= ch && p.CHANNELMAX >= ch);
|
||
if (objDept != null)
|
||
{
|
||
deptCode = objDept.SALEDEPTCODE;
|
||
}
|
||
|
||
var order = _order.Get(p => p.SZZYORDERID == t.SZZYORDERID);
|
||
if (order == null)
|
||
{
|
||
decimal? userId = null;
|
||
decimal? eid = null;
|
||
string uname = null;
|
||
if (t.eid.HasValue)
|
||
{
|
||
var user = _user.GetModelByEid(t.eid.Value);
|
||
userId = user?.PKID;
|
||
eid = t.eid.Value;
|
||
uname = user?.UNAME;
|
||
}
|
||
else
|
||
{
|
||
var midProduct = _subProduct.Get(p => p.SUBPRODUCTID == t.SUBPRODUCTID);
|
||
if (midProduct != null)
|
||
{
|
||
var midProductId = midProduct.MIDPRODUCTID;
|
||
if (midProductId == 100900305)
|
||
{
|
||
userId = _user.GetModelByEid(3900)?.PKID;
|
||
eid = 3900;
|
||
}
|
||
}
|
||
}
|
||
var model = new WX_SZZYORDER()
|
||
{
|
||
ORDERID = t.ORDERID,
|
||
EMPLOYEEID = t.EMPLOYEEID,
|
||
PASSWORD = t.PASSWORD,
|
||
USERID = t.USERID,
|
||
PRODUCTID = t.PRODUCTID,
|
||
PRODUCTNAME = t.PRODUCTNAME,
|
||
SUBPRODUCTID = t.SUBPRODUCTID,
|
||
SUBPRODUCTNAME = t.SUBPRODUCTNAME,
|
||
ORDERTYPE = t.ORDERTYPE,
|
||
UPGRADEORDERIDS = t.UPGRADEORDERIDS,
|
||
TOTALUPGRADEVALUE = t.TOTALUPGRADEVALUE,
|
||
NEEDPAY = t.NEEDPAY,
|
||
OPENORDER = t.OPENORDER,
|
||
SZZYORDERID = t.SZZYORDERID,
|
||
CTIME = t.CTIME,
|
||
RETURNNEEDPAY = t.RETURNNEEDPAY,
|
||
CONTRACTCODE = t.CONTRACTCODE,
|
||
RET = t.RET,
|
||
MSG = t.MSG,
|
||
RETURNDETAIL = t.RETURNDETAIL,
|
||
INNERUSERID = userId,
|
||
OTIME = t.OTIME,
|
||
RESID = t.RESID,
|
||
REQUESTSTATUS = t.REQUESTSTATUS,
|
||
ISFINANCEPAY = t.ISFINANCEPAY,
|
||
FINACEPAYDATE = t.FINACEPAYDATE,
|
||
REMARK = t.REMARK,
|
||
FINALPAY = t.FINALPAY,
|
||
ORDERSTATUS = t.ORDERSTATUS,
|
||
ORDERSTATUSNAME = t.ORDERSTATUSNAME,
|
||
OPERATETIME = t.OPERATETIME,
|
||
STIME = t.STIME,
|
||
ETIME = t.ETIME,
|
||
SUSPENDCOMMENT = t.SUSPENDCOMMENT,
|
||
UPDATEORDERTIME = t.UPDATEORDERTIME,
|
||
ISOPEN = t.ISOPEN,
|
||
ENDTIME = t.ENDTIME,
|
||
TEAMSERVE = t.TEAMSERVE,
|
||
CUSTOMERUSERNAME = t.CUSTOMERUSERNAME,
|
||
ARRIVALPAY = t.ARRIVALPAY,
|
||
ARRIVALTIME = t.ARRIVALTIME,
|
||
SOURCE = t.SOURCE,
|
||
CNAME = t.CNAME,
|
||
OPENDAYS = t.OPENDAYS,
|
||
CUSTOMERCLASSIFY = t.CUSTOMERCLASSIFY,
|
||
SALEDEPTID = t.SALEDEPTID,
|
||
ACTIVEPRODUCTCODE = t.activeproductcode,
|
||
ACTIVEPRODUCTEXT = t.activeproductext,
|
||
ISTEST = t.ISTEST,
|
||
OUTORDERO = t.OUTORDERO,//***第三方平台订单号***
|
||
EXTERNAL_USERID = t.external_userid
|
||
};
|
||
if (!string.IsNullOrEmpty(deptCode))
|
||
{
|
||
model.DEPTCODE = deptCode;
|
||
}
|
||
|
||
_order.Add(model);
|
||
|
||
_orderExtend.Add(new WX_ORDEREXT()
|
||
{
|
||
ORDERID = t.ORDERID,
|
||
NAME = t.CNAME,
|
||
SOFTUSERNAME = t.SOFTUSERNAME,
|
||
ISPAYED = t.ISPAYED,
|
||
PAYTYPE = t.PAYTYPE,
|
||
OPENDAYS = t.OPENDAYS,
|
||
APPUSERNAME = t.APPUSERNAME,
|
||
PRODUCTID = t.SUBPRODUCTID,
|
||
PRODUCTCODE = t.PRODUCTCODE,
|
||
BIGPRODUCTCODE = t.BIGPRODUCTCODE,
|
||
CHANNEL = t.CHANNEL,
|
||
BOOKNUM = t.BOOKNUM,
|
||
ORDERSTATUS = int.Parse(t.ORDERSTATUS)
|
||
});
|
||
|
||
if (userId.HasValue)
|
||
{
|
||
//如果工号不是空的,补上分成信息
|
||
WX_COMMISSIONRULE_VIEW ruleView = new WX_COMMISSIONRULE_VIEW
|
||
{
|
||
WxSzzyOrder = model,
|
||
item0 = new WX_COMMISSIONRULE_ITEM
|
||
{
|
||
EID = eid,
|
||
ISMAIN = 1,
|
||
COMMISSIONRATIO = 100
|
||
}
|
||
};
|
||
_rule.CreateWxCommissionRuleList(ruleView, userId.Value);
|
||
|
||
//配置的产品写入高级分配
|
||
var subProductIds = _cache.GetValue_Parameter("SYS_WX_AFTERSALES3_AUTO");
|
||
if (!string.IsNullOrEmpty(subProductIds))
|
||
{
|
||
var subProductList = subProductIds.Split(',').ToList();
|
||
if (subProductList.Contains(model.SUBPRODUCTID.Value.ToString()))
|
||
{
|
||
var after3dto = new WX_AFTERSALES3() { RESID = model.RESID, INNERUSERID = userId.Value, EID = eid.Value, UNAME = uname };
|
||
_aftersale3.Save(after3dto);
|
||
}
|
||
}
|
||
}
|
||
|
||
if (!string.IsNullOrEmpty(t.mb))
|
||
{
|
||
var resid = WX.CRM.Common.ResUtil.CreateResId(t.mb);
|
||
if (res_Customer_BL.getResCustomerByResId(resid) == null)
|
||
{
|
||
var customerDetail = new RES_CUSTOMERDETAIL();
|
||
customerDetail.CNAME = t.CNAME;
|
||
var xmls = new XmlSerializer(typeof(RES_CUSTOMERDETAIL));
|
||
var sw = new StringWriter();
|
||
xmls.Serialize(sw, customerDetail);
|
||
res_Customer_BL.ResgisterCustomer(t.mb, resid, "orderres", sw.ToString());//注册资源
|
||
}
|
||
new RES_CUSTOMERUSER_BL().ContractUser(resid, t.SOFTUSERNAME);//关联用户
|
||
}
|
||
|
||
return true;
|
||
}
|
||
else
|
||
{
|
||
LogHelper.Info("已经存在的订单order:" + order.ToJson());
|
||
//LogHelper.Info("请求数据:" + t.ToJson());
|
||
decimal? userId = null;
|
||
decimal? eid = null;
|
||
string uname = null;
|
||
if (order.INNERUSERID == null)
|
||
{
|
||
if (t.eid.HasValue)
|
||
{
|
||
var user = _user.GetModelByEid(t.eid.Value);
|
||
userId = user?.PKID;
|
||
eid = t.eid.Value;
|
||
uname = user?.UNAME;
|
||
}
|
||
}
|
||
|
||
order.ORDERID = t.ORDERID;
|
||
order.EMPLOYEEID = t.EMPLOYEEID;
|
||
order.PASSWORD = t.PASSWORD;
|
||
order.USERID = t.USERID;
|
||
order.PRODUCTID = t.PRODUCTID;
|
||
order.PRODUCTNAME = t.PRODUCTNAME;
|
||
order.SUBPRODUCTID = t.SUBPRODUCTID;
|
||
order.SUBPRODUCTNAME = t.SUBPRODUCTNAME;
|
||
order.ORDERTYPE = t.ORDERTYPE;
|
||
order.UPGRADEORDERIDS = t.UPGRADEORDERIDS;
|
||
order.TOTALUPGRADEVALUE = t.TOTALUPGRADEVALUE;
|
||
order.NEEDPAY = t.NEEDPAY;
|
||
order.OPENORDER = t.OPENORDER;
|
||
order.SZZYORDERID = t.SZZYORDERID;
|
||
order.CTIME = t.CTIME;
|
||
order.RETURNNEEDPAY = t.RETURNNEEDPAY;
|
||
order.CONTRACTCODE = t.CONTRACTCODE;
|
||
order.RET = t.RET;
|
||
order.MSG = t.MSG;
|
||
order.RETURNDETAIL = t.RETURNDETAIL;
|
||
if (order.INNERUSERID == null && userId.HasValue)
|
||
{
|
||
order.INNERUSERID = userId;
|
||
order.EXTERNAL_USERID = t.external_userid;
|
||
}
|
||
order.OTIME = t.OTIME;
|
||
order.RESID = t.RESID;
|
||
order.REQUESTSTATUS = t.REQUESTSTATUS;
|
||
order.ISFINANCEPAY = t.ISFINANCEPAY;
|
||
order.FINACEPAYDATE = t.FINACEPAYDATE;
|
||
//order.REMARK = t.REMARK;
|
||
order.FINALPAY = t.FINALPAY;
|
||
order.ORDERSTATUS = t.ORDERSTATUS;
|
||
order.ORDERSTATUSNAME = t.ORDERSTATUSNAME;
|
||
order.OPERATETIME = t.OPERATETIME;
|
||
order.STIME = t.STIME;
|
||
order.ETIME = t.ETIME;
|
||
order.SUSPENDCOMMENT = t.SUSPENDCOMMENT;
|
||
order.UPDATEORDERTIME = t.UPDATEORDERTIME;
|
||
order.ISOPEN = t.ISOPEN;
|
||
order.ENDTIME = t.ENDTIME;
|
||
order.TEAMSERVE = t.TEAMSERVE;
|
||
order.CUSTOMERUSERNAME = t.CUSTOMERUSERNAME;
|
||
order.ARRIVALPAY = t.ARRIVALPAY;
|
||
order.ARRIVALTIME = t.ARRIVALTIME;
|
||
order.SOURCE = t.SOURCE;
|
||
order.CNAME = t.CNAME;
|
||
order.OPENDAYS = t.OPENDAYS;
|
||
order.CUSTOMERCLASSIFY = t.CUSTOMERCLASSIFY;
|
||
order.SALEDEPTID = t.SALEDEPTID;
|
||
order.ACTIVEPRODUCTCODE = t.activeproductcode;
|
||
order.ACTIVEPRODUCTEXT = t.activeproductext;
|
||
order.ISTEST = t.ISTEST;
|
||
order.OUTORDERO = t.OUTORDERO;//***第三方平台订单号***
|
||
order.RISKCTRLSTATUS = t.RISKCTRLSTATUS;
|
||
if (!string.IsNullOrEmpty(deptCode))
|
||
{
|
||
order.DEPTCODE = deptCode;
|
||
}
|
||
|
||
if (order.INNERUSERID == null && userId.HasValue)
|
||
{
|
||
//如果工号不是空的,补上分成信息
|
||
WX_COMMISSIONRULE_VIEW ruleView = new WX_COMMISSIONRULE_VIEW
|
||
{
|
||
WxSzzyOrder = order,
|
||
item0 = new WX_COMMISSIONRULE_ITEM
|
||
{
|
||
EID = eid,
|
||
ISMAIN = 1,
|
||
COMMISSIONRATIO = 100
|
||
}
|
||
};
|
||
_rule.CreateWxCommissionRuleList(ruleView, userId.Value);
|
||
}
|
||
|
||
_order.Update(order);
|
||
|
||
return true;
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
LogHelper.Error(ex.ToString());
|
||
LogHelper.Error("错误的json:" + t.ToJson());
|
||
return false;
|
||
}
|
||
}
|
||
}
|
||
}
|