149 lines
5.1 KiB
C#
149 lines
5.1 KiB
C#
using CRM.Core.DTO;
|
|
using System;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using WX.CRM.BLL.Base;
|
|
using WX.CRM.BLL.Util;
|
|
using WX.CRM.BLL.Wx;
|
|
using WX.CRM.Common;
|
|
using WX.CRM.IBLL.Util;
|
|
using WX.CRM.IBLL.Wx;
|
|
using WX.CRM.Model.Entity;
|
|
using WX.CRM.Model.MAP;
|
|
|
|
namespace WX.CRM.CRMServices.WeiXin
|
|
{
|
|
public class SzzyOrderPush
|
|
{
|
|
IWX_SZZYORDERUSERNAME _szzyorderusername = new WX_SZZYORDERUSERNAME_BL();
|
|
IWX_SZZYORDER _szzyorder = new WX_SZZYORDER_BL();
|
|
ICACHE_Q cache_BL = new CACHE_BL();
|
|
WX.CRM.IBLL.Util.ISecurityHelper sHelper = new SecurityHelper();
|
|
string clientid = Utility.GetSettingByKey("CRMClientKey");
|
|
string _deptCode = Utility.GetSettingByKey("DataClientCode");
|
|
//一二部销售部门ID
|
|
//string SaleDeptId_OneAndTwo = new CACHE_BL().GetValue_Parameter(Model.Enum.Parameter.Sys_SaleDeptId_OneAndTwo);
|
|
/// <summary>
|
|
/// 开始推送
|
|
/// </summary>
|
|
public void StartPush()
|
|
{
|
|
try
|
|
{
|
|
new WX_SZZYORDER_BL().updateSzzyOrderEndTime();//先修改时间
|
|
|
|
var users = new BAS_INNERUSER_BL().GetAllList();
|
|
//获取所有需要推送的订单
|
|
var list = _szzyorder.GetSzzyOrderListInfo();
|
|
|
|
foreach (var item in list)
|
|
{
|
|
//先把inneruserId保存起来
|
|
var inneruserId = item.eid;
|
|
//inneruserId转成eid
|
|
var user = users.FirstOrDefault(p => p.PKID == item.eid);
|
|
item.eid = user != null ? user.EID : 0;
|
|
|
|
//推送数据
|
|
PushUpdateUserRights(item, inneruserId);
|
|
}
|
|
|
|
}
|
|
catch (Exception ex) { LogHelper.Error(ex.ToString()); }
|
|
}
|
|
/// <summary>
|
|
/// 推送数据执行方法
|
|
/// </summary>
|
|
/// <param name="info"></param>
|
|
public void PushUpdateUserRights(WX_SZZYORDER_PUSH info, decimal inneruserId)
|
|
{
|
|
info.phone = sHelper.decyptData(clientid, info.phone);//手机号解密
|
|
info.phone = Utility.EncryptMD5(info.phone.Trim() + "QBJ.PJ.MK");
|
|
info.userid = Utility.EncryptMD5(info.userid.Trim() + "QBJ.PJ.MK"); //用户名加密
|
|
#region 数据同步
|
|
try
|
|
{
|
|
var user = new Server_push_updateUserRights()
|
|
{
|
|
endTime = info.endTime.Value,
|
|
startTime = info.startTime.Value,
|
|
productid = info.productid.ToString(),
|
|
price = info.price,
|
|
phone = info.phone,
|
|
userid = info.userid,
|
|
eid = info.eid.ToString(),
|
|
Dept = _deptCode,
|
|
DeptId = 0,
|
|
SzzyOrderId = info.SzzyOrderId ?? 0,
|
|
orderstatus = int.Parse(info.orderstatus)
|
|
};
|
|
|
|
var host = Utility.GetSettingOrNullByKey("DataSyncApiUrl");
|
|
var url = host + "/api/DataSync";
|
|
|
|
var para = new SYNC_PUSH_DTO()
|
|
{
|
|
bidatatype = "Server_push_updateUserRights",
|
|
deptcode = _deptCode,
|
|
jsontext = user.ToJson()
|
|
};
|
|
|
|
var rep = Utility.PostAjaxData(url, para.ToJson(), Encoding.UTF8);
|
|
var ret = Utility.JSONToObject<retMsg>(rep);
|
|
if (ret.result)
|
|
{
|
|
info.eid = inneruserId;
|
|
SaveSzzyOrderUserName(info);
|
|
}
|
|
else
|
|
{
|
|
LogHelper.Info("订单推送写入失败:" + para.ToJson());
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogHelper.Error("同步到投顾错误:" + ex);
|
|
}
|
|
#endregion
|
|
}
|
|
|
|
private void SaveSzzyOrderUserName(WX_SZZYORDER_PUSH info)
|
|
{
|
|
var model = _szzyorderusername.Get(p => p.ORDERID == info.orderid);
|
|
if (model == null)
|
|
{
|
|
var item = new WX_SZZYORDERUSERNAME()
|
|
{
|
|
ORDERID = info.orderid,
|
|
USERNAME = info.userid,
|
|
INNERUSERID = info.eid,
|
|
ISDELETE = 0
|
|
};
|
|
_szzyorderusername.Add(item);
|
|
}
|
|
else
|
|
{
|
|
model.USERNAME = info.userid;
|
|
model.INNERUSERID = info.eid;
|
|
_szzyorderusername.Update(model);
|
|
}
|
|
}
|
|
}
|
|
|
|
public class Server_push_updateUserRights
|
|
{
|
|
public string eid { get; set; }
|
|
public string userid { get; set; }
|
|
public string phone { get; set; }
|
|
public string productid { get; set; }
|
|
public decimal price { get; set; }
|
|
public DateTime startTime { get; set; }
|
|
public DateTime endTime { get; set; }
|
|
public string Dept { get; set; }
|
|
public int DeptId { get; set; }
|
|
public decimal SzzyOrderId { get; set; }
|
|
public int orderstatus { get; set; }
|
|
}
|
|
}
|
|
|