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 System.Net.Mail;
|
using static CommonToolsCore.SendMailHelper;
|
using CommonToolsCore;
|
|
namespace zhengcaioa.Controllers.Customer
|
{
|
[CheckLogin]
|
public class CooperVisitController : Controller
|
{
|
private readonly ILogger<CooperVisitController> _logger;
|
private readonly IProjectService _projectService;
|
private readonly ILiaotianService _liaotianService;
|
private readonly ICooperatecustomCustomerService _cooperatecustomCustomerService;
|
private readonly IUserService _userService;
|
private readonly ICooperVisitService _cooperVisitService;
|
private readonly ICusFangwenjiluService _cusFangwenjiluService;
|
|
|
public CooperVisitController(ILogger<CooperVisitController> logger, IProjectService projectService, ILiaotianService liaotianService, ICooperatecustomCustomerService cooperatecustomCustomerService, IUserService userService, ICooperVisitService cooperVisitService
|
, ICusFangwenjiluService cusFangwenjiluService)
|
{
|
_logger = logger;
|
_projectService = projectService;
|
_liaotianService = liaotianService;
|
_cooperatecustomCustomerService = cooperatecustomCustomerService;
|
_userService = userService;
|
_cooperVisitService = cooperVisitService;
|
_cusFangwenjiluService = cusFangwenjiluService;
|
}
|
|
public IActionResult Index()
|
{
|
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("CooperatecustomCustomer", "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.ShengDropDown = _projectService.Getsheng().Select(x => new { code = x.CodeId, label = x.Name }).ToList();
|
return View();
|
|
}
|
|
public IActionResult GetList(CooperVisitDTOSearch search)
|
{
|
//JsonResult jsonResult = new JsonResult(_liaotianService.SearchByPaging(search), new Newtonsoft.Json.Serialization.DefaultContractResolver());
|
return new JsonResult(_cooperVisitService.SearchByPaging(search));
|
}
|
|
public IActionResult Edit(string id = null)
|
{
|
var curentuser = JsonConvert.DeserializeObject<PltUser>(HttpContext.Session.GetString("User"));
|
ViewData["curentuser"] = curentuser;
|
|
CooperVisitDTO dto = new CooperVisitDTO();
|
if (!String.IsNullOrEmpty(id))
|
{
|
dto = _cooperVisitService.Get(id);
|
|
}
|
else
|
{
|
dto.Vistime = DateTime.Now;
|
}
|
|
ViewData["customer"] = _cooperatecustomCustomerService.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.Model = dto;
|
return View();
|
}
|
|
|
/// <summary>
|
/// 保存
|
/// </summary>
|
/// <param name="data">岗位实体类对象</param>
|
/// <returns></returns>
|
///
|
[HttpPost]
|
public IActionResult Save(CooperVisitDTO 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 = _cooperVisitService.save(data);
|
|
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(_cooperVisitService.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<CooperatecustomCustomerDTO> result = new List<CooperatecustomCustomerDTO>();
|
|
if (baifangid != null)
|
{
|
result = _cooperVisitService.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 = "短信发送失败";
|
return new JsonResult(resultEntity);
|
}
|
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<CooperatecustomCustomerDTO> result = new List<CooperatecustomCustomerDTO>();
|
|
if (baifangid != null)
|
{
|
result = _cooperVisitService.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<CooperatecustomCustomerDTO> result = new List<CooperatecustomCustomerDTO>();
|
|
if (id != null)
|
{
|
result = _cooperVisitService.GetList(id.Split(","));
|
}
|
ViewData["customer"] = result;
|
|
return View();
|
}
|
}
|
}
|