using System; using System.Linq; using WX.CRM.BLL.Base; using WX.CRM.BLL.Soft; using WX.CRM.BLL.Util; using WX.CRM.Common; using WX.CRM.IBLL.Res; namespace WX.CRM.BLL.Res { public class RES_APPLY_BL : IRES_APPLY { private string clientid = Utility.GetSettingByKey("CRMClientKey"); private WX.CRM.IBLL.Util.ISecurityHelper sHelper = new SecurityHelper(); private CACHE_BL _cache = new CACHE_BL(); private ValidationErrors errors = new ValidationErrors(); public bool Create(ref ValidationErrors errors, WX.CRM.Model.Entity.RES_APPLY model) { //try //{ // var url = _cache.GetValue_Parameter("UserCenterAccountUrl"); // if (!string.IsNullOrEmpty(url)) // { // var rsp = Utility.HttpPostData(url, "mobile=" + model.MOBILE, Encoding.UTF8); // var ret = JsonConvert.DeserializeAnonymousType(rsp, new { ret = 0, msg = string.Empty, list = new List() { } }); // foreach (var item in ret.list) // { // if (item.appid.EndsWith("_1")) // { // model.SOURCETYPE = 4; // } // } // } //} //catch (Exception ex) //{ // LogHelper.Error("验证资源是否企微客户:" + ex.ToString()); //} try { using (WX.CRM.Model.Entity.crmContext db = new WX.CRM.Model.Entity.crmContext()) { var entry = db.RES_APPLY.FirstOrDefault(m => m.PKID == model.PKID); if (entry != null) { errors.Add("该编码已经被占用!"); return false; } model.PKID = new SEQUENCES_BL().Seq_base_get(); model.CTIME = DateTime.Now; model.ENMOBILE = Utility.NumberFormat(model.MOBILE); if (!string.IsNullOrWhiteSpace(model.MOBILE)) { model.MOBILE = sHelper.encyptData(clientid, model.MOBILE); } if (model.DEPTID <= 0) { GET_REGUSER _regUser = new GET_REGUSER(); model.DEPTID = _regUser.BuildDeptIdByResId(resId: model.RESID); LogHelper.Info($"获取RES_APPLY事业线{model.DEPTID}"); } db.RES_APPLY.Add(model); return db.SaveChanges().GetResult(); } } catch (Exception ex) { errors.Add(ex.Message); LogHelper.Error(ex.Message + "|" + ex.StackTrace + "|" + model.ToJson()); return false; } } private class AccountInfo { public string appid { get; set; } public string appuserid { get; set; } public int uid { get; set; } public string mobile { get; set; } public string unionid { get; set; } public string ctime { get; set; } } } }