using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Text;
|
using AutoMapper;
|
using AngleSharp.Html.Parser;
|
using DTO;
|
using IServices;
|
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.Bot.Builder.Integration.AspNet.Core;
|
using Microsoft.Extensions.Logging;
|
using Newtonsoft.Json;
|
using System.Net.Http;
|
using System.Threading.Tasks;
|
using zhengcaioa.Models;
|
using zhengcaioa.IService;
|
using CommonToolsCore;
|
using static CommonToolsCore.SendMailHelper;
|
using System.Net.Mail;
|
using System.Transactions;
|
|
namespace zhengcaioa.Controllers.Customer
|
{
|
[CheckLogin]
|
public class IntentionVisitController : Controller
|
{
|
private readonly ILogger<IntentionVisitController> _logger;
|
private readonly IProjectService _projectService;
|
private readonly ILiaotianService _liaotianService;
|
private readonly IIntentionCustomerService _intentionCustomerService;
|
private readonly IUserService _userService;
|
private readonly IIntentionVisitService _intentionVisitService;
|
private readonly ICusFangwenjiluService _cusFangwenjiluService;
|
|
|
public IntentionVisitController(ILogger<IntentionVisitController> logger, IProjectService projectService, ILiaotianService liaotianService, IIntentionCustomerService intentionCustomerService, IUserService userService, IIntentionVisitService intentionVisitService
|
, ICusFangwenjiluService cusFangwenjiluService)
|
{
|
_logger = logger;
|
_projectService = projectService;
|
_liaotianService = liaotianService;
|
_intentionCustomerService = intentionCustomerService;
|
_userService = userService;
|
_intentionVisitService = intentionVisitService;
|
_cusFangwenjiluService = cusFangwenjiluService;
|
}
|
|
|
public IActionResult Index(string Viscustomer = "", string IsYwjl = "")
|
{
|
var curentuser = JsonConvert.DeserializeObject<PltUser>(HttpContext.Session.GetString("User"));
|
ViewData["curentuser"] = curentuser;
|
List<ActionEntity> actionlist = new List<ActionEntity>();
|
ActionEntity actionEntity = new ActionEntity();
|
actionEntity.OpenType = 0;
|
actionEntity.ActionUrl = "";
|
actionEntity.ActionFun = "Search";
|
actionEntity.PageIco = "fa fa-search";
|
actionEntity.ActionName = "查询";
|
actionlist.Add(actionEntity);
|
ActionEntity actionEntity1 = new ActionEntity();
|
actionEntity1.OpenType = 0;
|
actionEntity1.ActionUrl = "";
|
actionEntity1.ActionFun = "Add";
|
actionEntity1.PageIco = "fa fa-plus";
|
actionEntity1.ActionName = "新增";
|
actionlist.Add(actionEntity1);
|
|
|
|
|
|
ViewData["ActionInfo"] = actionlist;
|
|
|
ViewBag.khlx = _liaotianService.GetSYScode("CooperatecustomCustomer", "khlx").Select(x => new { code = x.CodeSn, label = x.Comments }).ToList();
|
ViewBag.khly = _liaotianService.GetSYScode("IntentionCustomer", "khly").Select(x => new { code = x.CodeSn, label = x.Comments }).ToList();
|
ViewBag.hyfl = _liaotianService.GetSYScode("CooperatecustomCustomer", "hyfl").Select(x => new { code = x.CodeSn, label = x.Comments }).ToList();
|
|
ViewBag.users = _userService.GetList().Where(x => x.IsYwjl == "A").Select(x => new { code = x.Id, label = x.UserName }).ToList();
|
|
ViewBag.creater = _userService.GetList().Select(x => new { code = x.Id, label = x.UserName }).ToList();
|
|
ViewBag.Viscustomer = Viscustomer;
|
ViewBag.IsYwjl = IsYwjl;
|
|
ViewBag.ShengDropDown = _projectService.Getsheng().Select(x => new { code = x.CodeId, label = x.Name }).ToList();
|
return View();
|
|
}
|
|
public IActionResult GetList(IntentionVisitDTOSearch search)
|
{
|
//JsonResult jsonResult = new JsonResult(_liaotianService.SearchByPaging(search), new Newtonsoft.Json.Serialization.DefaultContractResolver());
|
return new JsonResult(_intentionVisitService.SearchByPaging(search));
|
}
|
|
public IActionResult Edit(string id = null,string Viscustomer = null,string IsYwjl = "")
|
{
|
var curentuser = JsonConvert.DeserializeObject<PltUser>(HttpContext.Session.GetString("User"));
|
ViewData["curentuser"] = curentuser;
|
|
IntentionVisitDTO dto = new IntentionVisitDTO();
|
if (!String.IsNullOrEmpty(id))
|
{
|
dto = _intentionVisitService.Get(id);
|
|
}
|
else
|
{
|
dto.Vistime = DateTime.Now;
|
if (!string.IsNullOrWhiteSpace(Viscustomer))
|
{
|
dto.Viscustomer = Viscustomer;
|
}
|
|
dto.VisType = "01";
|
dto.Jtype = "02";
|
//dto.Jdr = "02";
|
dto.Talk = "介绍公司业务内容和产品。";
|
dto.Yx = "03";
|
dto.Jy = "02";
|
dto.Zw = "02";
|
|
|
|
}
|
|
|
ViewData["customer"] = _intentionCustomerService.GetList();
|
|
|
|
ViewData["visType"] = _liaotianService.GetSYScode("CooperVisit", "visType");
|
ViewData["jtype"] = _liaotianService.GetSYScode("CooperVisit", "jtype");
|
ViewData["zw"] = _liaotianService.GetSYScode("CooperVisit", "zw");
|
ViewData["yx"] = _liaotianService.GetSYScode("CooperVisit", "yx");
|
ViewData["jy"] = _liaotianService.GetSYScode("CooperVisit", "jy");
|
|
ViewData["Duanxin"] = _intentionVisitService.GetListDuanxin();
|
|
ViewBag.IsYwjl = IsYwjl;
|
|
ViewData.Model = dto;
|
return View();
|
}
|
|
|
public IActionResult getDuanxin(string id)
|
{
|
ResultEntity resultEntity = new ResultEntity();
|
resultEntity.Result = true;
|
var curentuser = JsonConvert.DeserializeObject<PltUser>(HttpContext.Session.GetString("User"));
|
ViewData["curentuser"] = curentuser;
|
|
var intentionVisitDuanxinDTO = _intentionVisitService.GetDuanxin(id);
|
if(intentionVisitDuanxinDTO!=null && !string.IsNullOrEmpty(intentionVisitDuanxinDTO.DuanxinNeirong))
|
{
|
resultEntity.Message = string.Format(intentionVisitDuanxinDTO.DuanxinNeirong, curentuser.UserName, curentuser.Phone);
|
}
|
|
|
return new JsonResult(resultEntity);
|
}
|
|
|
/// <summary>
|
/// 保存
|
/// </summary>
|
/// <param name="data">岗位实体类对象</param>
|
/// <returns></returns>
|
///
|
[HttpPost]
|
public IActionResult Save(IntentionVisitDTO data)
|
{
|
var curentuser = JsonConvert.DeserializeObject<PltUser>(HttpContext.Session.GetString("User"));
|
ViewData["curentuser"] = curentuser;
|
data.RecStatus = "A";
|
if (String.IsNullOrEmpty(data.Id))
|
{
|
data.Creater = curentuser.Id;
|
data.Createtime = DateTime.Now;
|
}
|
data.Modifier = curentuser.Id;
|
data.Modifytime = DateTime.Now;
|
ResultEntity resultEntity = new ResultEntity();
|
using (TransactionScope scope = new TransactionScope())
|
{
|
resultEntity = _intentionVisitService.save(data);
|
if (!resultEntity.Result)
|
{
|
return new JsonResult(resultEntity);
|
}
|
|
|
if (!string.IsNullOrEmpty(data.IsYwjl))
|
{
|
IntentionCustomerDTO intentionCustomerDTO = _intentionCustomerService.Get(data.Viscustomer);
|
intentionCustomerDTO.Zuijinzhuizongtime = data.Vistime;
|
if (string.IsNullOrEmpty(intentionCustomerDTO.Ywjl))
|
{
|
intentionCustomerDTO.Ywjl = curentuser.Id;
|
}
|
resultEntity = _intentionCustomerService.save(intentionCustomerDTO);
|
if (!resultEntity.Result)
|
{
|
return new JsonResult(resultEntity);
|
}
|
}
|
else if (data.Jy == "05")
|
{
|
IntentionCustomerDTO intentionCustomerDTO = _intentionCustomerService.Get(data.Viscustomer);
|
intentionCustomerDTO.Yixiang = data.Jy;
|
intentionCustomerDTO.Yixiangtime = data.Vistime;
|
intentionCustomerDTO.Dianxiaozhuanyuan = curentuser.Id;
|
resultEntity = _intentionCustomerService.save(intentionCustomerDTO);
|
if (!resultEntity.Result)
|
{
|
return new JsonResult(resultEntity);
|
}
|
|
}
|
|
|
if (!string.IsNullOrEmpty(data.DuanxinNeirong))
|
{
|
IntentionCustomerDTO intentionCustomerDTO = _intentionCustomerService.Get(data.Viscustomer);
|
if(intentionCustomerDTO!=null && ( !string.IsNullOrEmpty(intentionCustomerDTO.Phone) || !string.IsNullOrEmpty(intentionCustomerDTO.Tel)))
|
{
|
string sss = SMSHelper.PushWToUserMES(string.IsNullOrEmpty(intentionCustomerDTO.Phone)? intentionCustomerDTO.Tel: intentionCustomerDTO.Phone, data.DuanxinNeirong);
|
if (int.Parse(sss) <= 0)
|
{
|
resultEntity.Result = false;
|
resultEntity.Message = "短信发送失败";
|
|
}
|
if (!resultEntity.Result)
|
{
|
return new JsonResult(resultEntity);
|
}
|
}
|
else
|
{
|
resultEntity.Result = false;
|
resultEntity.Message = "客户无手机号码";
|
return new JsonResult(resultEntity);
|
}
|
|
|
}
|
|
|
|
scope.Complete();
|
}
|
|
|
return new JsonResult(resultEntity);
|
}
|
|
|
/// <summary>
|
/// 删除主信息
|
/// </summary>
|
/// <param name="info">实体</param>
|
/// <returns></returns>
|
///
|
public IActionResult Nullify(string Id = "")
|
{
|
var curentuser = JsonConvert.DeserializeObject<PltUser>(HttpContext.Session.GetString("User"));
|
ViewData["curentuser"] = curentuser;
|
return new JsonResult(_intentionVisitService.ModifyStatus(Id, curentuser.Id));
|
}
|
|
|
|
public IActionResult Duanxin(string id = null)
|
{
|
var curentuser = JsonConvert.DeserializeObject<PltUser>(HttpContext.Session.GetString("User"));
|
ViewData["curentuser"] = curentuser;
|
ViewData["baifangid"] = id;
|
|
|
|
return View();
|
}
|
|
public IActionResult Fasong(string neirong, string baifangid)
|
{
|
ResultEntity resultEntity = new ResultEntity();
|
resultEntity.Result = true;
|
var curentuser = JsonConvert.DeserializeObject<PltUser>(HttpContext.Session.GetString("User"));
|
ViewData["curentuser"] = curentuser;
|
List<IntentionCustomerDTO> result = new List<IntentionCustomerDTO>();
|
|
if (baifangid != null)
|
{
|
result = _intentionVisitService.GetList(baifangid.Split(","));
|
}
|
else
|
{
|
resultEntity.Result = false;
|
resultEntity.Message = "无联系人号码";
|
}
|
string customename = "";
|
StringBuilder number = new StringBuilder(); ;
|
if(result!=null&& result.Count > 0)
|
{
|
for(int i=0;i< result.Count; i++)
|
{
|
number.Append(string.IsNullOrEmpty(result[i].Phone)? result[i].Tel: result[i].Phone);
|
customename += result[i].Name + ",";
|
if (i!= result.Count - 1)
|
{
|
number.Append(",");
|
}
|
}
|
}
|
else
|
{
|
resultEntity.Result = false;
|
resultEntity.Message = "无联系人";
|
}
|
|
string sss = SMSHelper.PushWToUserMES(number.ToString(), neirong);
|
if (int.Parse(sss) <= 0)
|
{
|
resultEntity.Result = false;
|
resultEntity.Message = "短信发送失败";
|
|
}
|
CusFangwenjiluDTO dto = new CusFangwenjiluDTO();
|
dto.Fasongfangshi = "01";
|
dto.Fasongneirong = neirong;
|
dto.Jieshouren = baifangid;
|
dto.RecStatus = "A";
|
dto.Creater = curentuser.Id;
|
dto.Modifytime = DateTime.Now;
|
dto.Modifier = curentuser.Id;
|
dto.Createtime = dto.Modifytime;
|
resultEntity = _cusFangwenjiluService.save(dto);
|
_logger.LogInformation(curentuser.UserName + "发送短信给客户" + customename);
|
return new JsonResult(resultEntity);
|
}
|
|
|
|
public IActionResult Youjian(string id = null)
|
{
|
var curentuser = JsonConvert.DeserializeObject<PltUser>(HttpContext.Session.GetString("User"));
|
ViewData["curentuser"] = curentuser;
|
ViewData["baifangid"] = id;
|
|
|
|
return View();
|
}
|
|
public IActionResult YoujianFasong(string title, string neirong, string baifangid)
|
{
|
ResultEntity resultEntity = new ResultEntity();
|
resultEntity.Result = true;
|
var curentuser = JsonConvert.DeserializeObject<PltUser>(HttpContext.Session.GetString("User"));
|
ViewData["curentuser"] = curentuser;
|
List<IntentionCustomerDTO> result = new List<IntentionCustomerDTO>();
|
|
if (baifangid != null)
|
{
|
result = _intentionVisitService.GetList(baifangid.Split(","));
|
}
|
else
|
{
|
resultEntity.Result = false;
|
resultEntity.Message = "无联系人";
|
}
|
string customename = "";
|
List<MailAddress> receivers = new List<MailAddress>();
|
if (result != null && result.Count > 0)
|
{
|
for (int i = 0; i < result.Count; i++)
|
{
|
receivers.Add(new MailAddress(result[i].Email, result[i].FName));
|
customename += result[i].Name + ",";
|
}
|
}
|
else
|
{
|
resultEntity.Result = false;
|
resultEntity.Message = "无联系人号码";
|
}
|
|
MailModel model = new MailModel();
|
//model.ReceiverAddress = result[i].Email;//"272629192@qq.com";
|
//model.ReceiverName = result[i].FName;// "尧";
|
model.receivers = receivers;
|
model.Title = title; //"你好";
|
model.Content = neirong;// "你好呀";
|
//model.Host = "smtp.qq.com";
|
//model.Port = 587;
|
//model.SenderName = "尧";
|
//model.SenderAddress = "272629192@qq.com";
|
//model.SenderPassword = "mnooicotjaflbhdd";
|
|
_logger.LogInformation("准备发送邮件");
|
resultEntity = SendMailHelper.SendMail(model);
|
_logger.LogInformation("发送邮件完成" + resultEntity.Message);
|
if (resultEntity.Result == false)
|
{
|
return new JsonResult(resultEntity);
|
}
|
CusFangwenjiluDTO dto = new CusFangwenjiluDTO();
|
dto.Fasongfangshi = "02";
|
dto.Fasongneirong = neirong;
|
dto.Jieshouren = baifangid;
|
dto.RecStatus = "A";
|
dto.Creater = curentuser.Id;
|
dto.Modifytime = DateTime.Now;
|
dto.Modifier = curentuser.Id;
|
dto.Createtime = dto.Modifytime;
|
resultEntity = _cusFangwenjiluService.save(dto);
|
_logger.LogInformation(curentuser.UserName +"发送邮件给客户"+ customename);
|
|
return new JsonResult(resultEntity);
|
}
|
|
|
public IActionResult Xinhan(string id = null)
|
{
|
var curentuser = JsonConvert.DeserializeObject<PltUser>(HttpContext.Session.GetString("User"));
|
ViewData["curentuser"] = curentuser;
|
ViewData["baifangid"] = id;
|
|
List<IntentionCustomerDTO> result = new List<IntentionCustomerDTO>();
|
|
if (id != null)
|
{
|
result = _intentionVisitService.GetList(id.Split(","));
|
}
|
ViewData["customer"] = result;
|
|
return View();
|
}
|
|
|
}
|
}
|