143 lines
6.4 KiB
C#
143 lines
6.4 KiB
C#
using CRM.Core.DTO;
|
|
using CRM.Core.DTO.Ord;
|
|
using Newtonsoft.Json;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using WX.CRM.BLL.Base;
|
|
using WX.CRM.BLL.Util;
|
|
using WX.CRM.Common;
|
|
using WX.CRM.IBLL.Wx;
|
|
using WX.CRM.Model.Entity;
|
|
using WX.CRM.Model.Enum;
|
|
|
|
namespace WX.CRM.BLL.Wx
|
|
{
|
|
public class WX_COMMISSIONRULE_BL : DbContextRepository<WX_COMMISSIONRULE>, IWX_COMMISSIONRULE
|
|
{
|
|
WX.CRM.IBLL.Util.ISecurityHelper sHelper = new SecurityHelper();
|
|
private SEQUENCES_BL _sequencesBl = new SEQUENCES_BL();
|
|
CACHE_BL _cache = new CACHE_BL();
|
|
WX_SZZYORDER_BL _wxSzzyorder = new WX_SZZYORDER_BL();
|
|
public void CreateWxCommissionRuleList(WX_COMMISSIONRULE_VIEW info, decimal userId)
|
|
{
|
|
List<WX_COMMISSIONRULE> syncDto = new List<WX_COMMISSIONRULE>();
|
|
string txt = string.Empty;
|
|
if (info.item0.EID > 0)
|
|
{
|
|
CreateWxCommissionRule(info.WxSzzyOrder.ORDERID, info.WxSzzyOrder.SZZYORDERID, info.item0, userId, syncDto);
|
|
txt += string.Format("{0}:{1}%", info.item0.EID, info.item0.COMMISSIONRATIO);
|
|
}
|
|
if (info.item1.EID > 0)
|
|
{
|
|
CreateWxCommissionRule(info.WxSzzyOrder.ORDERID, info.WxSzzyOrder.SZZYORDERID, info.item1, userId, syncDto);
|
|
if (txt.Length > 0)
|
|
txt += " ";
|
|
txt += string.Format("{0}:{1}%", info.item1.EID, info.item1.COMMISSIONRATIO);
|
|
}
|
|
if (info.item2.EID > 0)
|
|
{
|
|
CreateWxCommissionRule(info.WxSzzyOrder.ORDERID, info.WxSzzyOrder.SZZYORDERID, info.item2, userId, syncDto);
|
|
if (txt.Length > 0)
|
|
txt += " ";
|
|
txt += string.Format("{0}:{1}%", info.item2.EID, info.item2.COMMISSIONRATIO);
|
|
}
|
|
if (info.item3.EID > 0)
|
|
{
|
|
CreateWxCommissionRule(info.WxSzzyOrder.ORDERID, info.WxSzzyOrder.SZZYORDERID, info.item3, userId, syncDto);
|
|
if (txt.Length > 0)
|
|
txt += " ";
|
|
txt += string.Format("{0}:{1}%", info.item3.EID, info.item3.COMMISSIONRATIO);
|
|
}
|
|
if (info.item4.EID > 0)
|
|
{
|
|
CreateWxCommissionRule(info.WxSzzyOrder.ORDERID, info.WxSzzyOrder.SZZYORDERID, info.item4, userId, syncDto);
|
|
if (txt.Length > 0)
|
|
txt += " ";
|
|
txt += string.Format("{0}:{1}%", info.item4.EID, info.item4.COMMISSIONRATIO, userId);
|
|
}
|
|
if (info.item5.EID > 0)
|
|
{
|
|
CreateWxCommissionRule(info.WxSzzyOrder.ORDERID, info.WxSzzyOrder.SZZYORDERID, info.item5, userId, syncDto);
|
|
if (txt.Length > 0)
|
|
txt += " ";
|
|
txt += string.Format("{0}:{1}%", info.item5.EID, info.item5.COMMISSIONRATIO);
|
|
}
|
|
if (info.item6.EID > 0)
|
|
{
|
|
CreateWxCommissionRule(info.WxSzzyOrder.ORDERID, info.WxSzzyOrder.SZZYORDERID, info.item6, userId, syncDto);
|
|
if (txt.Length > 0)
|
|
txt += " ";
|
|
txt += string.Format("{0}:{1}%", info.item6.EID, info.item6.COMMISSIONRATIO);
|
|
}
|
|
_wxSzzyorder.UpdateFCTXT(info.WxSzzyOrder.ORDERID, txt);//修改分成文本
|
|
if (syncDto.Count > 0)
|
|
{
|
|
string url = new CACHE_BL().GetValue_Parameter(Parameter.Core_ZxdService_SyncOrderRule);//中心点创建订单
|
|
string json = Utility.ConvertToJSON<List<WX_COMMISSIONRULE>>(syncDto);
|
|
json = sHelper.createSignEncodingStr(json, SecurityHelper.OrderClientIdKey);//数据参数加密
|
|
string retmsg = Utility.PostData(url + "?" + json, Encoding.UTF8);//实现中心点先入库
|
|
retmsg = sHelper.decyptData(SecurityHelper.OrderClientIdKey, retmsg);
|
|
CreateOrderRsp retmessage = JsonConvert.DeserializeObject<CreateOrderRsp>(retmsg);//返回信息
|
|
if (retmessage.retCode != (int)NodeJsOrderEnum.调用成功)//成功
|
|
{
|
|
LogHelper.Error($"同步销售组规则失败");
|
|
}
|
|
}
|
|
}
|
|
private int CreateWxCommissionRule(decimal orderId, decimal? szzyOrderId, WX_COMMISSIONRULE_ITEM item, decimal userId, List<WX_COMMISSIONRULE> syncDto)
|
|
{
|
|
var userList = _cache.GetUserList();
|
|
var user = userList.FirstOrDefault(n => n.EID == item.EID);
|
|
var wxCommissionRuleModel = new WX_COMMISSIONRULE()
|
|
{
|
|
PKID = _sequencesBl.Seq_base_get(),
|
|
ORDERID = orderId,
|
|
SZZYORDERID = szzyOrderId,
|
|
SALEUSERID = user.PKID,
|
|
EID = item.EID,
|
|
COMMISSIONRATIO = item.COMMISSIONRATIO.Value,
|
|
ISMAIN = item.ISMAIN,
|
|
CREATEUSERID = userId,
|
|
CREATETIME = DateTime.Now,
|
|
ENAME = user?.UNAME,
|
|
GID = item.GID
|
|
};
|
|
if (item.GID == null)
|
|
{
|
|
var usergroup = _cache.GetList_InnerUserGroup().FirstOrDefault(n => n.INNERUSERID == user.PKID);
|
|
var group = _cache.GetGroupList().FirstOrDefault(n => n.GID == usergroup?.GID);
|
|
if (group == null)
|
|
{
|
|
var dept = _cache.GetList_SalesDepartMent().FirstOrDefault(n => n.SALEDEPTID == usergroup.DEPTID);
|
|
wxCommissionRuleModel.GID = dept?.SALEDEPTID;
|
|
wxCommissionRuleModel.GNAME = dept?.DEPTNAME;
|
|
}
|
|
else
|
|
{
|
|
wxCommissionRuleModel.GID = group?.GID;
|
|
wxCommissionRuleModel.GNAME = group?.GNAME;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
var group = _cache.GetGroupList().FirstOrDefault(n => n.GID == item?.GID);
|
|
if (group == null)
|
|
{
|
|
var dept = _cache.GetList_SalesDepartMent().FirstOrDefault(n => n.SALEDEPTID == item?.GID);
|
|
wxCommissionRuleModel.GNAME = dept?.DEPTNAME;
|
|
}
|
|
else
|
|
{
|
|
wxCommissionRuleModel.GNAME = group?.GNAME;
|
|
}
|
|
}
|
|
var res = Add(wxCommissionRuleModel);
|
|
syncDto.Add(wxCommissionRuleModel);
|
|
return res;
|
|
}
|
|
|
|
}
|
|
}
|