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 Services; using System.Transactions; namespace zhengcaioa.Controllers.BusinessOrder { public class OrderBanciOrderController : Controller { private readonly ILogger _logger; private readonly ILiaotianService _liaotianService; private readonly IOrderBanciService _orderBanciService; private readonly IOrderBanciDtlService _orderBanciDtlService; private readonly IOrderBanciOrderService _orderBanciOrderService; public OrderBanciOrderController(ILogger logger, ILiaotianService liaotianService, IOrderBanciService orderBanciService, IOrderBanciDtlService orderBanciDtlService ,IOrderBanciOrderService orderBanciOrderService) { _logger = logger; _liaotianService = liaotianService; _orderBanciService = orderBanciService; _orderBanciDtlService = orderBanciDtlService; _orderBanciOrderService = orderBanciOrderService; } [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); ActionEntity actionEntity3 = new ActionEntity(); actionEntity3.OpenType = 0; actionEntity3.ActionUrl = ""; actionEntity3.ActionFun = "Print"; actionEntity3.PageIco = "fa fa-print"; actionEntity3.ActionName = "打印"; actionlist.Add(actionEntity3); ActionEntity actionEntity4 = new ActionEntity(); actionEntity4.OpenType = 0; actionEntity4.ActionUrl = ""; actionEntity4.ActionFun = "Duanxin"; actionEntity4.PageIco = ""; actionEntity4.ActionName = "发送短信"; actionlist.Add(actionEntity4); ViewData["ActionInfo"] = actionlist; ViewBag.kechengleixing = _liaotianService.GetSYScode("order_banci_order", "kechengleixing_id").Select(x => new { code = x.CodeSn, label = x.Comments }).ToList(); return View(); } [CheckLogin] public IActionResult GetList(OrderBanciOrderDTOSearch search) { //JsonResult jsonResult = new JsonResult(_liaotianService.SearchByPaging(search), new Newtonsoft.Json.Serialization.DefaultContractResolver()); return new JsonResult(_orderBanciOrderService.SearchByPaging(search)); } [CheckLogin] public IActionResult print(OrderBanciOrderDTOSearch search) { //JsonResult jsonResult = new JsonResult(_liaotianService.SearchByPaging(search), new Newtonsoft.Json.Serialization.DefaultContractResolver()); search.rows = 1000; search.page = 1; ViewBag.listLiaotianDTO = _orderBanciOrderService.SearchByPaging(search).DataList as List; return View(); } [CheckLogin] public IActionResult Duanxin(string id = null) { var curentuser = JsonConvert.DeserializeObject(HttpContext.Session.GetString("User")); ViewData["curentuser"] = curentuser; ViewData["baifangid"] = id; return View(); } [CheckLogin] public IActionResult Fasong(string neirong, string baifangid) { ResultEntity resultEntity = new ResultEntity(); resultEntity.Result = true; var curentuser = JsonConvert.DeserializeObject(HttpContext.Session.GetString("User")); ViewData["curentuser"] = curentuser; List result = new List(); if (baifangid != null) { result = _orderBanciOrderService.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(result[i].Lianxidianhua); customename += result[i].Xingming + ","; 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); } _logger.LogInformation(curentuser.UserName + "发送短信给客户" + customename); return new JsonResult(resultEntity); } /// /// 保存 /// /// 岗位实体类对象 /// /// [HttpPost] public IActionResult Save([FromBody] OrderBanciOrderDTO data) { //var curentuser = JsonConvert.DeserializeObject(HttpContext.Session.GetString("User")); //ViewData["curentuser"] = curentuser; ReturnMsg returnMsg = new ReturnMsg(); returnMsg.code = 2; try { using (TransactionScope scope = new TransactionScope()) { data.RecStatus = "A"; if (String.IsNullOrEmpty(data.Id)) { data.Creater = "1"; data.Createtime = DateTime.Now; } data.Modifier = "1"; data.Modifytime = DateTime.Now; OrderBanciOrderDTOSearch search = new OrderBanciOrderDTOSearch(); search.page = 1; search.rows = 1000; search.BanciId = data.BanciId; ResultDataEntity resultDataEntity = _orderBanciOrderService.SearchByPaging(search); data.Baomingrenshu = search.totalrows + 1; data.Jine = resultDataEntity.DataList.Sum(x => x.Xuefei); data.Jine += data.Xuefei; ResultEntity resultEntity = _orderBanciOrderService.save(data); if (resultEntity.Result) { returnMsg.code = 1; returnMsg.count = 1; returnMsg.returnObj = data; } else { returnMsg.error = resultEntity.Message; } scope.Complete(); } } catch (Exception ex) { returnMsg.code = 2; returnMsg.error = "没有获取到token"; returnMsg.count = 0; } return new JsonResult(returnMsg); } //获取当前的报名的人数 public IActionResult GetBaoMingRenShu([FromBody] OrderBanciOrderDTOSearch search) { ReturnMsg> returnMsg = new ReturnMsg>(); returnMsg.code = 2; try { search.page = 1; search.rows = 1; ResultDataEntity resultDataEntity = _orderBanciOrderService.SearchByPaging(search); returnMsg.code = 1; returnMsg.count = search.totalrows; returnMsg.returnObj = resultDataEntity.DataList; } catch (Exception ex) { returnMsg.code = 2; returnMsg.error = "没有获取到token"; returnMsg.count = 0; } return new JsonResult(returnMsg); } } }