using Microsoft.AspNetCore.Mvc; using System; using System.Collections.Generic; using System.Linq; using Microsoft.Extensions.Logging; using IServices; using DTO; using Newtonsoft.Json; using zhengcaioa.Models; using Microsoft.AspNetCore.Http; using zhengcaioa.IService; using System.IO; using Microsoft.Extensions.Configuration; namespace zhengcaioa.Controllers.Expert { public class ExpertController : Controller { private readonly ILogger _logger; private readonly IExpertService _expertService; private readonly ILiaotianService _liaotianService; private readonly IProjectService _projectService; private readonly IUserService _userService; public ExpertController(ILogger logger, IExpertService expertService, IProjectService projectService, ILiaotianService liaotianService, IUserService userService) { _logger = logger; _expertService = expertService; _projectService = projectService; _liaotianService = liaotianService; _userService = userService; } [CheckLogin] public IActionResult Index() { var curentuser = JsonConvert.DeserializeObject(HttpContext.Session.GetString("User")); ViewData["curentuser"] = curentuser; List actionlist = new List(); 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.expertType = _liaotianService.GetSYScode("experts", "expertType").Select(x => new { code = x.CodeSn, label = x.Comments }).ToList(); ViewBag.level = _liaotianService.GetSYScode("experts", "level").Select(x => new { code = x.CodeSn, label = x.Comments }).ToList(); ViewBag.Province = _projectService.Getsheng().Select(x => new { code = x.CodeId, label = x.Name }).ToList(); // ViewBag.City = _projectService.Getshi( ).Select(x => new { code = x.CodeId, label = x.Name }).ToList(); ViewBag.ReviewItem = _liaotianService.GetSYScode("experts", "ReviewItem").Select(x => new { code = x.CodeSn, label = x.Comments }).ToList(); return View(); } #region 查询 [CheckLogin] public string GetList(ExpertDTOSearch search) { var curentuser = JsonConvert.DeserializeObject(HttpContext.Session.GetString("User")); search.ShenheStatus = "A"; ViewData["curentuser"] = curentuser; return JsonConvert.SerializeObject(_expertService.SearchByPaging(search)); } #endregion #region 编辑 [CheckLogin] public ActionResult Edit(string id = null) { var curentuser = JsonConvert.DeserializeObject(HttpContext.Session.GetString("User")); ViewData["curentuser"] = curentuser; List actionlist = new List(); ActionEntity actionEntity = new ActionEntity(); actionEntity.OpenType = 0; actionEntity.ActionUrl = ""; actionEntity.ActionFun = "Save"; actionEntity.PageIco = "glyphicon glyphicon-ok"; actionEntity.ActionName = "保存"; actionlist.Add(actionEntity); ViewData["ActionInfo"] = actionlist; ExpertDTO expertDTO = new ExpertDTO(); if (!string.IsNullOrEmpty(id)) { expertDTO = _expertService.Get(id); } else { expertDTO.Province = "510000"; expertDTO.City = "510100"; } // var sheng = _projectService.Getsheng(); ViewBag.InfoSource = _liaotianService.GetSYScode("CooperatecustomCustomer", "khly");//.Select(x => new { code = x.CodeSn, label = x.Comments }).ToList(); ViewBag.sex = _liaotianService.GetSYScode("plt_user", "sex");//.Select(x => new { code = x.CodeSn, label = x.Comments }).ToList(); ViewBag.expertType = _liaotianService.GetSYScode("experts", "expertType");//.Select(x => new { code = x.CodeSn, label = x.Comments }).ToList(); ViewBag.level = _liaotianService.GetSYScode("experts", "level");//.Select(x => new { code = x.CodeSn, label = x.Comments }).ToList(); ViewBag.ReviewItem = _liaotianService.GetSYScode("experts", "ReviewItem");//.Select(x => new { code = x.CodeSn, label = x.Comments }).ToList(); ViewBag.Province = _projectService.Getsheng();//.Select(x => new { code = x.CodeId, label = x.Name }).ToList(); ViewBag.City = _projectService.Getshi(expertDTO.Province);//.Select(x => new { code = x.CodeId, label = x.Name }).ToList(); ViewData.Model = expertDTO; return View(); } /// /// 图片上传 /// /// public string UploadImage() { var files = Request.Form.Files; if (files.Count == 0) { return "File does not exist!"; } var file = files[0]; string fileName = file.FileName; if (string.IsNullOrEmpty(fileName))//服务器是否存在该文件 { return "File does not exist!"; } // 获取上传的图片名称和扩展名称 string fileFullName = Path.GetFileName(file.FileName); string fileExtName = Path.GetExtension(fileFullName); string imgPath = string.Format("{0}\\wwwroot\\{1}\\", Directory.GetCurrentDirectory(), "UploadFile"); var newPath = fileFullName.Substring(0, fileFullName.IndexOf(fileExtName)) + System.DateTime.UtcNow.Ticks + fileExtName; var src = imgPath + newPath; // 如果目录不存在则要先创建 if (!Directory.Exists(imgPath)) { Directory.CreateDirectory(imgPath); } using (FileStream fs = System.IO.File.Create(src)) { file.CopyTo(fs); fs.Flush(); } // imgPath = string.Format("~/UploadFile/{0}", fileFullName); return newPath; } public string Get(string id = null) { ExpertDTO expertDTO = new ExpertDTO(); if (!String.IsNullOrEmpty(id)) { expertDTO = _expertService.Get(id); } return JsonConvert.SerializeObject(expertDTO); } /// /// 保存 /// /// 岗位实体类对象 /// [HttpPost] [CheckLogin] public string Save(ExpertDTO data) { var curentuser = JsonConvert.DeserializeObject(HttpContext.Session.GetString("User")); ViewData["curentuser"] = curentuser; data.ShenheStatus = "A"; data.ReviewItem = data.ReviewItemSelect; 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 = _expertService.save(data); return JsonConvert.SerializeObject(resultEntity); } #endregion /// /// 删除主信息 /// /// 实体 /// /// [CheckLogin] public string Nullify(string Id = "") { var curentuser = JsonConvert.DeserializeObject(HttpContext.Session.GetString("User")); ViewData["curentuser"] = curentuser; return JsonConvert.SerializeObject(_expertService.ModifyStatus(Id, curentuser.Id)); } #region 推广记录 /// /// 取得推广记录列表 /// /// /// [CheckLogin] public string GetPromoteList(ExpertPromoteDTOSearch search) { return JsonConvert.SerializeObject(_expertService.SearchExpPromote(search)); } /// /// 查看推广记录 /// /// /// [CheckLogin] public IActionResult Promote(string experId) { // ViewData["curentuser"] = curentuser; List actionlist = new List(); ActionEntity actionEntity = new ActionEntity(); actionEntity.OpenType = 0; actionEntity.ActionUrl = ""; actionEntity.ActionFun = "Search"; actionEntity.PageIco = "fa fa-search"; actionEntity.ActionName = "查询"; actionlist.Add(actionEntity); ViewData["ActionInfo"] = actionlist; ViewData["experId"] = experId; ViewBag.users = _userService.GetList().Select(x => new { code = x.Id, label = x.UserSn }).ToList(); return View(); } /// /// 新增推广记录 /// /// /// [CheckLogin] public IActionResult EditPromote(string experId) { ViewData["experId"] = experId; return View(); } /// /// 保存 /// /// 保存推广记录 /// [HttpPost] [CheckLogin] public string SavePromte(ExpertPromoteDTO data) { var curentuser = JsonConvert.DeserializeObject(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 = _expertService.SaveExpPromote(data); return JsonConvert.SerializeObject(resultEntity); } #endregion #region 专家派工 [CheckLogin] public IActionResult ExpertOrderDispatch() { var curentuser = JsonConvert.DeserializeObject(HttpContext.Session.GetString("User")); ViewData["curentuser"] = curentuser; List actionlist = new List(); ActionEntity actionEntity = new ActionEntity(); actionEntity.OpenType = 0; actionEntity.ActionUrl = ""; actionEntity.ActionFun = "Search"; actionEntity.PageIco = "fa fa-search"; actionEntity.ActionName = "查询"; actionlist.Add(actionEntity); ViewData["ActionInfo"] = actionlist; ViewBag.OrderType = _liaotianService.GetSYScode("CooperVisit", "jtype").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.Khlx = _liaotianService.GetSYScode("CooperatecustomCustomer", "khlx").Select(x => new { code = x.CodeSn, label = x.Comments }).ToList(); ViewBag.HuifangStatus = _liaotianService.GetSYScode("CooperOrder", "huifang_status").Select(x => new { code = x.CodeSn, label = x.Comments }).ToList(); ViewBag.PingjiaStatus = _liaotianService.GetSYScode("CooperOrder", "pingjia_status").Select(x => new { code = x.CodeSn, label = x.Comments }).ToList(); return View(); } [CheckLogin] public string GetOrderList(ExpertOrderDipatchDTOSearch search) { return JsonConvert.SerializeObject(_expertService.SearchOrderDispatch(search)); } [CheckLogin] public IActionResult Dispatch(string orderid) { List list = _expertService.GetList(); ViewData["experts"] = list; ViewBag.OrderId = orderid; return View(); } [CheckLogin] public string SaveDispatch(ExpertOrderDipatchDTO data) { var curentuser = JsonConvert.DeserializeObject(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 = _expertService.SaveDispatch(data); return JsonConvert.SerializeObject(resultEntity); } #endregion } }