307 lines
12 KiB
C#
307 lines
12 KiB
C#
using Ninject;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.Data.SqlClient;
|
||
using System.IO;
|
||
using System.Linq;
|
||
using System.Linq.Expressions;
|
||
using System.Web;
|
||
using System.Web.Mvc;
|
||
using WX.CRM.BLL.Base;
|
||
using WX.CRM.BLL.Csvr;
|
||
using WX.CRM.Common;
|
||
using WX.CRM.IBLL.Res;
|
||
using WX.CRM.IBLL.Util;
|
||
using WX.CRM.Model.Entity;
|
||
using WX.CRM.WebHelper;
|
||
|
||
namespace WX.CRM.WEB.Controllers.Res
|
||
{
|
||
public class VIPCustomerController : BaseController
|
||
{
|
||
[Inject]
|
||
public IRES_VIPCUSTOMER _RES_VIPCUSTOMER { get; set; }
|
||
[Inject]
|
||
public IRES_CUSTOMER_Q _customerq { get; set; }
|
||
[Inject]
|
||
public ICACHE_Q _CACHE_Q { get; set; }
|
||
|
||
[Inject]
|
||
public IRES_RESOURCEMOBILE_Q _RES_RESOURCEMOBILE { get; set; }
|
||
[Inject]
|
||
public IRES_RESOURCETYPE_Q resourceTypeBiz_Q { get; set; }
|
||
ValidationErrors errors = new ValidationErrors();
|
||
|
||
[AuthorizeRedirect(Roles = InitRights.CONST_VIP资源)]
|
||
public ActionResult Index()
|
||
{
|
||
var tool = new ToolBar();
|
||
string[] toolbtn = new ToolButtonView().ToolButtonRight(InitRights.VIP资源, userRightId);
|
||
List<string> listBtn = new List<string>(toolbtn);
|
||
List<string> Buttons = new List<string>();
|
||
Buttons.Add("Other1");
|
||
Buttons.AddRange(listBtn);
|
||
tool.AllowButton(Buttons.ToArray());
|
||
tool.AddOtherButton("Other1", "刷新", "icon-reload", "Reload_Click", true);
|
||
ViewBag.ToolBar = tool;
|
||
|
||
var pager = new Pager() { page = 1, rows = 10, sort = "CTIME", order = "desc" };
|
||
var tableId = "tablist";
|
||
var tab = new Table(tableId);
|
||
tab.AddHiddenHeadCol("PKID", "PKID");
|
||
tab.AddHeadCol("RESID", "", "客户ID ");
|
||
tab.AddHeadCol("REASON", "", "备注");
|
||
tab.AddHeadCol("CTIME", "", "添加时间");
|
||
tab.AddHeadRow();
|
||
|
||
ViewBag.List = tab.GetTable() + Pagination.GetPage(pager, tableId, "10,20,30");
|
||
return View();
|
||
}
|
||
|
||
[HttpPost]
|
||
[AuthorizeRedirect(Roles = InitRights.CONST_VIP资源)]
|
||
public JsonResult GetHtmlList(Pager pager, string columns)
|
||
{
|
||
try
|
||
{
|
||
string resid = Request.Form["ResId"];
|
||
|
||
Expression<Func<RES_VIPCUSTOMER, bool>> _where = ExpressionExtensions.True<RES_VIPCUSTOMER>();
|
||
if (!string.IsNullOrEmpty(resid))
|
||
{
|
||
_where = _where.And(obj => obj.RESID.Contains(resid));
|
||
}
|
||
Expression<Func<RES_VIPCUSTOMER, DateTime?>> _orderBy = e => e.CTIME;
|
||
|
||
var list = _RES_VIPCUSTOMER.GetList(_where, _orderBy, pager, SortOrder.Descending);
|
||
|
||
var table = new Table(columns, true);
|
||
table.gridPager = pager;
|
||
foreach (var model in list)
|
||
{
|
||
table.AddHiddenCol(model.PKID);
|
||
table.AddCol(model.RESID);
|
||
table.AddCol(model.REASON);
|
||
table.AddCol(model.CTIME);
|
||
table.AddRow();
|
||
}
|
||
var json = new
|
||
{
|
||
totalPages = pager.totalPages,
|
||
totalRows = pager.totalRows,
|
||
rowsList = table.GetRows()
|
||
};
|
||
return Json(json, JsonRequestBehavior.AllowGet);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
LogHelper.Error(ex.Message);
|
||
var json = new
|
||
{
|
||
errorMessag = "系统错误:" + ex.Message
|
||
};
|
||
return Json(json, JsonRequestBehavior.AllowGet);
|
||
}
|
||
}
|
||
|
||
[HttpGet]
|
||
[AuthorizeToolBar(InitRights.CONST_VIP资源, InitToolBar.CONST_Add)]
|
||
public ActionResult Add()
|
||
{
|
||
RES_CALLOUTCUSTOMER model = null;
|
||
return View(model);
|
||
}
|
||
|
||
[HttpPost]
|
||
[AuthorizeToolBar(InitRights.CONST_VIP资源, InitToolBar.CONST_Add)]
|
||
public ActionResult Add(string resids, string Reson)
|
||
{
|
||
if (string.IsNullOrEmpty(resids.Trim()))
|
||
{
|
||
ModelState.AddModelError("resids", "客户ID不能为空");
|
||
}
|
||
if (!ModelState.IsValid)
|
||
{
|
||
return JsonHandler.JsonResultSerialize(ModelState);
|
||
}
|
||
string[] resIds = resids.Replace(" ", "").Replace("\r", "").Replace("\n", "").Replace(",", ",").Split(',');
|
||
return Add(resIds, Reson);
|
||
}
|
||
|
||
private ActionResult Add(string[] resIds, string Reson)
|
||
{
|
||
try
|
||
{
|
||
string message = "";
|
||
string[] trueResIds = _customerq.getResByResIds(resIds).Select(m => m.RESID.Trim()).ToArray();
|
||
string[] existresIds = _RES_VIPCUSTOMER.GetByResIds(trueResIds).Select(m => m.RESID.Trim()).ToArray();
|
||
var nottrue = resIds.Except(trueResIds);
|
||
LogHelper.Info("资源总数:" + string.Join(",", resIds));
|
||
message = "资源总数:" + resIds.Count();
|
||
if (nottrue.Count() > 0)
|
||
{
|
||
if (message.Length > 0)
|
||
message += "<br>";
|
||
message = "不存在资源数量:" + nottrue.Count();
|
||
LogHelper.Info("不存在资源:" + string.Join(",", nottrue));
|
||
}
|
||
if (existresIds.Count() > 0)
|
||
{
|
||
if (message.Length > 0)
|
||
message += "<br>";
|
||
message += "已存在的资源数量:" + existresIds.Count();
|
||
LogHelper.Info("已添加的客户ID:" + string.Join(",", nottrue));
|
||
}
|
||
var updateResIds = trueResIds.Except(existresIds);
|
||
List<RES_VIPCUSTOMER> numbers = new List<RES_VIPCUSTOMER>();
|
||
//var gjsCustomer = _GJS_CUSTOMER.getGjsCustomersByResIds(updateResIds.ToArray());
|
||
var resMobiles = _RES_RESOURCEMOBILE.GetNumberByResId(updateResIds.ToArray());
|
||
var b = new CSVR_BLACKNUMBER_BL();
|
||
|
||
foreach (var resid in updateResIds)
|
||
{
|
||
if (!string.IsNullOrEmpty(resid))
|
||
{
|
||
RES_VIPCUSTOMER model = new RES_VIPCUSTOMER();
|
||
model.RESID = resid;
|
||
model.REASON = Reson;
|
||
model.CTIME = DateTime.Now;
|
||
model.PKID = new SEQUENCES_BL().Seq_base_get();
|
||
//var schStatus = gjsCustomer.FirstOrDefault(obj => obj.RESID == resid);
|
||
//model.SCHEDULESTATUS = schStatus != null ? schStatus.SCHEDULESTATUS : null;
|
||
model.SCHEDULESTATUS = null;
|
||
model.MOBILE = "";
|
||
if (resMobiles.ContainsKey(resid))
|
||
{
|
||
var mobile = resMobiles[resid];
|
||
mobile = Utility.EncryptMD5(mobile);
|
||
model.MOBILE = mobile;
|
||
}
|
||
|
||
numbers.Add(model);
|
||
}
|
||
}
|
||
if (numbers.Count > 0)
|
||
{
|
||
_RES_VIPCUSTOMER.AddList(numbers);
|
||
if (message.Length > 0)
|
||
message += "<br>";
|
||
LogHelper.Info("添加成功的客户ID:" + string.Join(",", numbers.Select(obj => obj.RESID)));
|
||
message += "添加成功" + numbers.Count + "个。";
|
||
return Json(new { type = true, message = message, value = message }, JsonRequestBehavior.AllowGet);
|
||
}
|
||
else
|
||
{
|
||
return Json(new { type = 0, message = "添加失败:" + message, value = message }, JsonRequestBehavior.AllowGet);
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
LogHelper.Error("BlackNumberController_Add:" + ex.StackTrace + ";" + ex.Message);
|
||
return Json(new { type = 0, message = ex.Message, value = "" }, JsonRequestBehavior.AllowGet);
|
||
}
|
||
}
|
||
|
||
#region 号码导入与号码文件导入
|
||
public ActionResult UploadFile(string Reson)
|
||
{
|
||
string msg = "ok";
|
||
try
|
||
{
|
||
List<string> mbs = new List<string>();
|
||
mbs = GetMiblesByTxtFile();
|
||
if (mbs == null || mbs.Count == 0)
|
||
{
|
||
return Json(new { type = true, message = "文件格式不正确或没有数据!", value = "文件格式不正确或没有数据!" }, JsonRequestBehavior.AllowGet);
|
||
}
|
||
|
||
return Add(mbs.ToArray(), Reson);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
msg = ex.Message;
|
||
LogHelper.Error("ImportResController:【UploadFile】:" + ex.Message + ex.StackTrace);
|
||
return Json(new { type = true, message = "导入出错:" + ex.Message, value = "导入出错:" + ex.Message }
|
||
, JsonRequestBehavior.AllowGet);
|
||
}
|
||
|
||
}
|
||
List<string> GetMiblesByTxtFile()
|
||
{
|
||
string vPath = System.Configuration.ConfigurationManager.AppSettings["UploadTemFileDic"];
|
||
List<string> lis = new List<string>();
|
||
HttpFileCollectionBase files = Request.Files;
|
||
HttpPostedFileBase file = files["FileMobile"];
|
||
if (file != null && file.ContentLength > 0)
|
||
{
|
||
string fileName = file.FileName;
|
||
//判断文件名字是否包含路径名,如果有则提取文件名
|
||
if (fileName.LastIndexOf("\\") > -1)
|
||
{
|
||
fileName = fileName.Substring(fileName.LastIndexOf("\\") + 1);
|
||
}
|
||
if (fileName.ToLower().IndexOf(".txt") > -1)
|
||
{
|
||
if (!System.IO.Directory.Exists(Server.MapPath(vPath)))
|
||
{
|
||
System.IO.Directory.CreateDirectory(Server.MapPath(vPath));
|
||
}
|
||
string path = Server.MapPath((vPath + "/") + fileName);
|
||
|
||
file.SaveAs(path);
|
||
FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read);
|
||
StreamReader sr = new StreamReader(fs, System.Text.Encoding.Default);
|
||
while (!sr.EndOfStream)
|
||
{
|
||
string number = sr.ReadLine();
|
||
lis.Add(number.Trim());
|
||
}
|
||
sr.Close();
|
||
fs.Close();
|
||
System.IO.File.Delete(path);
|
||
}
|
||
else
|
||
{
|
||
throw new Exception("文件格式不正确!");
|
||
}
|
||
}
|
||
else
|
||
{
|
||
throw new Exception("文件不存在!");
|
||
}
|
||
return lis;
|
||
}
|
||
List<string> GetMiblesByStr()
|
||
{
|
||
List<string> lis = new List<string>();
|
||
string mobileStr = string.Format("{0}", Request.Form["txtMobiles"]);
|
||
mobileStr = mobileStr.Replace("\r\n", "&");
|
||
mobileStr = mobileStr.Replace("\r", "&");
|
||
mobileStr = mobileStr.Replace("\n", "&");
|
||
string[] mbs = mobileStr.Trim().Split('&');
|
||
for (int i = 0; i < mbs.Length; i++)
|
||
{
|
||
if (WX.CRM.Common.Utility.ChekMobile(mbs[i]) || WX.CRM.Common.Utility.ValidateTelCode(mbs[i]))
|
||
lis.Add(mbs[i]);
|
||
}
|
||
|
||
//string patten = @"[1][34578]\d{9}";
|
||
//var mobiles = Regex.Matches(mobileStr, patten);
|
||
//string m = mobiles[0].Value;
|
||
|
||
//LogHelper.Error(mobileStr);
|
||
|
||
return lis;
|
||
}
|
||
#endregion
|
||
|
||
[AuthorizeToolBar(InitRights.CONST_VIP资源, InitToolBar.CONST_Delete)]
|
||
public JsonResult Delete(decimal pkid)
|
||
{
|
||
var delobj = _RES_VIPCUSTOMER.Get(obj => obj.PKID == pkid);
|
||
_RES_VIPCUSTOMER.Delete(delobj);
|
||
return JsonHandler.DeleteMessage(errors, true);
|
||
}
|
||
}
|
||
}
|