using Ninject; using NPOI.POIFS.FileSystem; using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Text; using System.Web.Mvc; using WX.CRM.BLL.Base; using WX.CRM.BLL.Util; using WX.CRM.Common; using WX.CRM.IBLL.Ord; using WX.CRM.IBLL.Res; using WX.CRM.IBLL.Util; using WX.CRM.IBLL.Wx; using WX.CRM.Model.Entity; using WX.CRM.Model.Enum; using WX.CRM.WEB.Controllers.Csvr; using WX.CRM.WebHelper; namespace WX.CRM.WEB.Controllers.Res { public class MobileQueryLogController : BaseController { ValidationErrors errors = new ValidationErrors(); WX.CRM.IBLL.Util.ISecurityHelper sHelper = new SecurityHelper(); [Inject] public IRES_MOBILEQUERYLOG res_MobileQueryLog_BL { get; set; } [Inject] public IRES_RESOURCEMOBILE_Q res_ResourceMobile_BL { get; set; } [Inject] public IWX_SZZYORDER wx_SzzyOrder_BL { get; set; } [Inject] public IORD_PURPOSEMEMO_Q ord_PurposeMemo_BL { get; set; } [Inject] public IRES_CUSTOMER_SALES _ResCustomerSales { get; set; } [Inject] public IRES_CUSTOMER_Q res_Customer_BL { get; set; } private ICACHE_Q cacheQ; [HttpPost] public JsonResult GetMobileByResId(string resId) { string roleCodes = DataCacheHelper.GetCache().Get_RoleCodes(userRoleId); #region 代码控制手机是否查看方式 //var queryMobile = ConfigurationManager.AppSettings["QueryMobile"]; //if (!string.IsNullOrWhiteSpace(queryMobile) && queryMobile == "1") //{ // if (roleCodes.IndexOf("CKSJ") < 0) // { // errors.Add("你没有查看手机的权限"); // return JsonHandler.ManageMessage(errors, false); // } //} ////升级客服角色 //var flag = roleCodes.IndexOf("GJSSJKF") >= 0; ////if (!flag) ////{ //// errors.Add("你没有权限查看"); //// return JsonHandler.ManageMessage(errors, false); ////} //if (string.IsNullOrWhiteSpace(resId)) //{ // errors.Add("客户编号不能为空"); // return JsonHandler.ManageMessage(errors, false); //} //if (!IsLogin) //{ // errors.Add("登录用户才能查看客户手机"); // return JsonHandler.ManageMessage(errors, false); //} //if (!flag) //{ // List resIds = new List(); // List list = res_Customer_BL.GetList_CustomerByResid(resId); // if (list != null && list.Count > 0) // { // resIds = list.Select(m => m.RESID).ToList(); // } // else // { // resIds.Add(resId); // } // var order = wx_SzzyOrder_BL.Get(m => resIds.Contains(m.RESID)); // if (order != null) // { // //errors.Add("订单用户不允许查看手机号码"); // errors.Add("禁止查看该用户号码"); // return JsonHandler.ManageMessage(errors, false); // } // var customerSale = _ResCustomerSales.Get(p => p.RESID == resId); // if (customerSale != null) // { // errors.Add("绑定的用户不允许查看手机号码"); // return JsonHandler.ManageMessage(errors, false); // } // //var purpose = ord_PurposeMemo_BL.GetModelByMemoTypeAndResId(201, resId); // //if (purpose != null) // //{ // // errors.Add("意向用户不允许查看手机号码"); // // return JsonHandler.ManageMessage(errors, false); // //} //} #endregion #region 过程方式 if (string.IsNullOrWhiteSpace(resId)) { errors.Add("客户编号不能为空"); return JsonHandler.ManageMessage(errors, false); } //if (!IsLogin) //{ // errors.Add("登录用户才能查看客户手机"); // return JsonHandler.ManageMessage(errors, false); //} DataTable dataTable = res_Customer_BL.CheckResidCanShowMobile(resId, UserId, roleCodes); int isShowMobile = Convert.ToInt32(dataTable.Rows[0]["isLook"]); string message = dataTable.Rows[0]["msg"].ToString(); if (isShowMobile == 0)//等于零为不允许查看号码 { errors.Add(message); return JsonHandler.ManageMessage(errors, false); } #endregion var mobile = res_ResourceMobile_BL.GetNumberByResId(resId); var model = new RES_MOBILEQUERYLOG(); model.PKID = new SEQUENCES_BL().Seq_base_get(); model.INNERUSERID = UserId; model.RESID = resId; model.CTIME = DateTime.Now; model.IP = Utility.GetIp(); res_MobileQueryLog_BL.Add(model); return JsonHandler.ManageMessage(mobile, true); } [HttpPost] public JsonResult GetMobileByResIdAndUserId(string resId) { if (string.IsNullOrWhiteSpace(resId)) { errors.Add("客户编号不能为空"); return JsonHandler.ManageMessage(errors, false); } if (!IsLogin) { errors.Add("登录用户才能查看客户手机"); return JsonHandler.ManageMessage(errors, false); } var flag = res_MobileQueryLog_BL.CanShowMobile(resId, UserId); var mobile = errors.Error; if (flag) { mobile = res_ResourceMobile_BL.GetNumberByResId(resId); if (string.IsNullOrEmpty(mobile)) { string clientid = Utility.GetSettingByKey("CRMClientKey"); var list = GetCustomerMoblieByResid(resId); var data = list.FirstOrDefault(x => x.Resid == resId); if (data != null) { mobile = sHelper.decyptData(clientid, data.Mobile); } } } return JsonHandler.ManageMessage(mobile, flag); } private List GetCustomerMoblieByResid(string resid) { var host = cacheQ.GetValue_Parameter(Parameter.Hg_Internal_WebApi); var url = host + "/api/Customer/moblies"; var res = Utility.GetData(url, "resid=" + resid, Encoding.UTF8); var result = JsonHelper.JsonDivertToObj>>(res); if (result.Code == 0) { return result.Data; } return new List(); } } }