using Core.Web.App_Start; using Core.Web.WebHelper; using CRM.Core.BLL; using CRM.Core.BLL.Application.B; using CRM.Core.BLL.Application.Bill; using CRM.Core.BLL.Util; using CRM.Core.BLL.Wx; using CRM.Core.Common.Layui; using CRM.Core.Common.WebHelper; using CRM.Core.DTO; using CRM.Core.DTO.Bill; using CRM.Core.Model.Entity; using CRM.Core.Model.Enum; using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Web.Helpers; using System.Web.Mvc; using WX.CRM.Common; using WX.CRM.Common.Employee; using WX.CRM.Common.WxPay; using WX.CRM.WebHelper; using static Core.Web.Controllers.OrderRefundApplyController; using static NPOI.HSSF.Util.HSSFColor; namespace Core.Web.Controllers { public class OrderRefundApplyController : BaseController { private CACHE_BL cache_BL = new CACHE_BL(); WX_SZZYORDER_BL _order = new WX_SZZYORDER_BL(); public readonly string webapi = ""; public OrderRefundApplyController() { webapi = cache_BL.GetValue_Parameter(Parameter.Hg_Core_WebApi); } [HttpGet] [AuthorizeRedirect(RightsConfig.CONST_退款申请列表, ToolBarConfig.CONST_NotButton, true)] public ActionResult Index() { ViewBag.rightCode = RightsConfig.CONST_退款申请列表; ViewBag.eid = Eid; ViewBag.userName = UserName; ViewBag.File_Server = cache_BL.GetValue_Parameter("File_Server"); var deptments = cache_BL.GetDeptments(); ViewBag.companyList = deptments; ViewBag.webapi = webapi; ViewBag.hgServiceHost = cache_BL.GetValue_Parameter("HgCrm_ServiceHost"); return View(); } [HttpGet] [AuthorizeRedirect(RightsConfig.CONST_退款申请列表, ToolBarConfig.CONST_NotButton, false)] public JsonResult OrderRefundApplyHtml(Laypage pager, SearchOrderRefundDto dto) { var url = $"{webapi}/api/OrderRefundApply/page"; var para = $"Deptid={dto.Deptid}&Orderid={dto.Orderid}&Channel={dto.Channel}" + $"&RefundType={dto.RefundType}&Resid={dto.Resid}&UMID={dto.UMID}& CreaetOrUpdateUser={dto.CreaetOrUpdateUser}" + $"&BusinessStatus={dto.BusinessStatus}&Cname={dto.Cname}&ComplaintId={dto.ComplaintId}" + $"&DateType={dto.DateType}&ApplyStatus={dto.ApplyStatus}&Eid={dto.Eid}" + $"&PayStatus={dto.PayStatus}&RefundStatus={dto.RefundStatus}" + $"&DateFrom={dto.DateFrom}&DateTo={dto.DateTo}&PageIndex={pager.page}&PageSize={pager.limit}"; var result = Utility.GetData(url, para, Encoding.UTF8); var data = JsonConvert.DeserializeObject>>(result); return Json(data, JsonRequestBehavior.AllowGet); } [HttpGet] [AuthorizeRedirect(RightsConfig.CONST_退款申请列表, ToolBarConfig.CONST_NotButton, true)] public ActionResult OrderRefundApplyEdit(int? id = null, bool read = false) { var model = new OrderRefundDto(); model.RefundDateStr = DateTime.Now.ToString("yyyy-MM-dd"); if (id != null) { var url = $"{webapi}/api/OrderRefundApply"; var para = $"id={id}"; var result = Utility.GetData(url, para, Encoding.UTF8); var data = JsonConvert.DeserializeObject>(result); model = data.data; } ViewBag.id = id; ViewBag.rightCode = RightsConfig.CONST_退款申请列表; ViewBag.eid = Eid; ViewBag.userName = UserName; ViewBag.File_Server = cache_BL.GetValue_Parameter("File_Server"); ViewBag.Readonly = read; return View(model); } [HttpPost] [AuthorizeRedirect(RightsConfig.CONST_退款申请列表, ToolBarConfig.CONST_NotButton, false)] public JsonResult Create(CreateOrderRefundDto dto) { var order = _order.GetModel(dto.Orderid.Value); if (order == null) return Json(new ApiResult { code = -1, message = "请输入正确的订单号!" }, JsonRequestBehavior.AllowGet); if (dto.RefundPrice <= 0) return Json(new ApiResult { code = -1, message = "退款金额必须大于零!" }, JsonRequestBehavior.AllowGet); if (order.ARRIVALPAY == null || order.ARRIVALPAY.Value <= 0) return Json(new ApiResult { code = -1, message = "无可退金额!" }, JsonRequestBehavior.AllowGet); var oldrefSum = new WX_SzzyOrderRefund_BL().GetList(m => m.orderid == dto.Orderid && m.auditstatus == 1 && m.isdelete == 0).Sum(m => m.refundprice); if((order.ARRIVALPAY - oldrefSum) < dto.RefundPrice) { var canRefPay = ((order.ARRIVALPAY ?? 0) - oldrefSum); return Json(new ApiResult { code = -1, message = " 当前可退款金额:" + canRefPay.ToString("#0.00") + " 元" }, JsonRequestBehavior.AllowGet); } var url = $"{webapi}/api/OrderRefundApply"; var result = Utility.PostAjaxData(url, dto.ToJson(), Encoding.UTF8); var data = JsonConvert.DeserializeObject>(result); return Json(data, JsonRequestBehavior.AllowGet); } [HttpGet] [AuthorizeRedirect(RightsConfig.CONST_退款申请列表, ToolBarConfig.CONST_NotButton, false)] public JsonResult GetOrderRefundCustomerInfo(string resid) { var url = $"{webapi}/api/OrderRefundApply/customerInfo"; var para = $"resid={resid}"; var result = Utility.GetData(url, para, Encoding.UTF8); var data = JsonConvert.DeserializeObject>(result); return Json(data, JsonRequestBehavior.AllowGet); } [HttpPost] [AuthorizeRedirect(RightsConfig.CONST_退款申请列表, ToolBarConfig.CONST_NotButton, false)] public JsonResult CreateOrderRefundApplyRestore(CreateRefundRestoreDto dto) { var url = $"{webapi}/api/OrderRefundApply/Restore"; var result = Utility.PostAjaxData(url, dto.ToJson(), Encoding.UTF8); var data = JsonConvert.DeserializeObject>(result); return Json(data, JsonRequestBehavior.AllowGet); } [HttpGet] [AuthorizeRedirect(RightsConfig.CONST_退款申请列表, ToolBarConfig.CONST_NotButton, false)] public JsonResult GetOrderRefundApplyRestore(int? id) { var url = $"{webapi}/api/OrderRefundApply/Restore"; var para = $"id={id}"; var result = Utility.GetData(url, para, Encoding.UTF8); var data = JsonConvert.DeserializeObject>(result); return Json(data, JsonRequestBehavior.AllowGet); } [HttpGet] [AuthorizeRedirect(RightsConfig.CONST_退款申请列表, ToolBarConfig.CONST_NotButton, true)] public ActionResult OrderRefundApplyHandle(int id, bool read = false) { var model = new OrderRefundDto(); var url = $"{webapi}/api/OrderRefundApply"; var para = $"id={id}"; var result = Utility.GetData(url, para, Encoding.UTF8); var data = JsonConvert.DeserializeObject>(result); model = data.data; ViewBag.id = id; ViewBag.rightCode = RightsConfig.CONST_退款申请列表; ViewBag.eid = Eid; ViewBag.userName = UserName; ViewBag.File_Server = cache_BL.GetValue_Parameter("File_Server"); ViewBag.Readonly = read; return View(model); } [HttpGet] [AuthorizeRedirect(RightsConfig.CONST_退款申请列表, ToolBarConfig.CONST_Export, false)] public FileResult ExportData(string param) { var url = $"{webapi}/api/OrderRefundApply/page"; var dto = Utility.ToObject(param); var para = $"Deptid={dto.Deptid}&Orderid={dto.Orderid}" + $"&RefundType={dto.RefundType}&Resid={dto.Resid}&CreaetOrUpdateUser={dto.CreaetOrUpdateUser}" + $"&BusinessStatus={dto.BusinessStatus}&Cname={dto.Cname}&ComplaintId={dto.ComplaintId}" + $"&DateType={dto.DateType}&ApplyStatus={dto.ApplyStatus}&Eid={dto.Eid}" + $"&PayStatus={dto.PayStatus}&RefundStatus={dto.RefundStatus}" + $"&DateFrom={dto.DateFrom}&DateTo={dto.DateTo}&PageIndex=1&PageSize=100000"; var result = Utility.GetData(url, para, Encoding.UTF8); var data = JsonConvert.DeserializeObject>>(result); string checkedFilds = Server.UrlDecode(Request.Cookies["checkedFilds"].Value); string checkedTitle = Server.UrlDecode(Request.Cookies["checkedTitles"].Value); Request.Cookies.Remove("checkedFilds");//用完后删除cookies Request.Cookies.Remove("checkedTitles");//用完后删除cookies String file = string.Format("退款申请列表{0}.xls", DateTime.Now.ToLocalTime().ToString("yyyyMMddHHmmssfffff")); return File(ExcelHelper.ExportListModelToExcel(data.data.Data.ToList(), "sheet", 30000, checkedFilds, checkedTitle, DataFormart), "application/ms-excel", file); } public string DataFormart(string key, object value) { string formartValue = string.Empty; switch (key) { case "ChannelList": formartValue = string.Join("\n", Utility.ToObject>(Utility.ToJson(value))); break; default: formartValue = string.Format("{0}", value); break; } return formartValue; } #region 实体 public class SearchOrderRefundDto { /// /// 事业部 /// public int? Deptid { get; set; } public string Channel { get; set; } /// /// 投诉类型 /// public int? RefundType { get; set; } /// /// 业务确认状态 /// public int? BusinessStatus { get; set; } /// /// 申请状态 /// public int? ApplyStatus { get; set; } /// /// 退款状态 /// public int? RefundStatus { get; set; } /// /// 支付类型 /// public int? PayStatus { get; set; } /// /// 投诉单号 /// public string ComplaintId { get; set; } /// /// 客户ID /// public string Resid { get; set; } /// /// 客户ID /// public string UMID { get; set; } /// /// 客户姓名 /// public string Cname { get; set; } /// /// 成交客服/工号 /// public string Eid { get; set; } /// /// 已退订单号 /// public decimal? Orderid { get; set; } /// /// 创建人/更新人 /// public string CreaetOrUpdateUser { get; set; } /// /// 日期搜索类型 /// public int DateType { get; set; } /// /// 日期 /// public DateTime? DateFrom { get; set; } /// /// 日期 /// public DateTime? DateTo { get; set; } } public class OrderRefundDto { public int Id { get; set; } /// /// 投诉单号 /// public string ComplaintId { get; set; } /// /// 客户ID /// public string Resid { get; set; } /// /// UMID /// public string UMID { get; set; } /// /// 退款订单号 /// public int? Orderid { get; set; } /// /// 客户姓名 /// public string Cname { get; set; } /// /// 事业部 /// public int? Deptid { get; set; } /// /// 事业部 /// public string Deptname { get; set; } /// /// 成交客服 /// public int? Eid { get; set; } /// /// 成交客服 /// public string Euser { get; set; } /// /// 投诉类型 /// public int? RefundType { get; set; } public string RefundTypeStr { get; set; } /// /// 业务确认状态 /// public int? BusinessStatus { get; set; } public string BusinessStatusStr { get; set; } /// /// 申请状态 /// public int? ApplyStatus { get; set; } public string ApplyStatusStr { get; set; } /// /// 退款状态 /// public int? RefundStatus { get; set; } public string RefundStatusStr { get; set; } /// /// 支付类型 /// public int? PayStatus { get; set; } public string PayStatusStr { get; set; } /// /// 退款人账号 /// public string RefundNo { get; set; } /// /// 退款人姓名 /// public string RefundName { get; set; } /// /// 退款金额 /// public decimal? RefundPrice { get; set; } /// /// 退款日期 /// public DateTime? RefundDate { get; set; } public string RefundDateStr { get; set; } /// /// 退款说明 /// public string RefundRemark { get; set; } /// /// 创建人 /// public string Creator { get; set; } /// /// 创建时间 /// public DateTime CreateTime { get; set; } /// /// 更新人 /// public string Updater { get; set; } /// /// 更新时间 /// public DateTime? UpdateTime { get; set; } public int? CreateEid { get; set; } public int? UpdateEid { get; set; } /// /// 是否有处理意见 /// public bool HasComplianceRemark { get; set; } /// /// 是否有附件 /// public bool HasAttachment { get; set; } public string Attachment { get; set; } /// /// 处理结果 /// public int? ComplianceResult { get; set; } public string ComplianceResultStr { get; set; } /// /// 处理说明 /// public string ComplianceRemark { get; set; } /// /// 处理附件 /// public string ComplianceAttachment { get; set; } } public class OrderRefundRestoreDto { public int? Id { get; set; } /// /// 客户ID /// public string Resid { get; set; } /// /// 退款订单号 /// public int? Orderid { get; set; } /// /// 客户姓名 /// public string Cname { get; set; } /// /// 退款金额 /// public decimal? RefundPrice { get; set; } /// /// 处理结果 /// public int? ComplianceResult { get; set; } public string ComplianceResultStr { get; set; } /// /// 处理说明 /// public string ComplianceRemark { get; set; } /// /// 相关附件 /// public string Attachment { get; set; } /// /// 处理人 /// public string Operator { get; set; } /// /// 处理人id /// public int? OperatorEid { get; set; } } public class CreateOrderRefundDto { /// /// 投诉单号 /// public string ComplaintId { get; set; } /// /// 客户ID /// public string Resid { get; set; } /// /// 退款订单号 /// public int? Orderid { get; set; } /// /// 客户姓名 /// public string Cname { get; set; } /// /// 事业部 /// public int? Deptid { get; set; } /// /// 客服 /// public int? Eid { get; set; } /// /// 退款类型 /// public int? RefundType { get; set; } /// /// 支付类型 /// public int? PayStatus { get; set; } /// /// 退款人账号 /// public string RefundNo { get; set; } /// /// 退款人姓名 /// public string RefundName { get; set; } /// /// 退款金额 /// public decimal? RefundPrice { get; set; } /// /// 退款日期 /// public DateTime? RefundDate { get; set; } /// /// 退款说明 /// public string RefundRemark { get; set; } public string Operator { get; set; } public int? OperatorEid { get; set; } /// /// 附件 /// public string Attachment { get; set; } } public class CreateRefundRestoreDto { public int? Id { get; set; } /// /// 处理结果 /// public int? ComplianceResult { get; set; } /// /// 处理说明 /// public string ComplianceRemark { get; set; } /// /// 相关附件 /// public string Attachment { get; set; } /// /// 处理人 /// public string Operator { get; set; } /// /// 处理人id /// public int? OperatorEid { get; set; } } public class OrderRefundCustomerInfoDto { /// /// 客户姓名 /// public string Cname { get; set; } /// /// 订单号 /// public List Orders { get; set; } /// /// 投诉单号 /// public List Complaints { get; set; } } public class OrderRefundCustomerOrderDto { /// /// 订单 /// public int Orderid { get; set; } /// /// 价格 /// public decimal? Price { get; set; } /// /// 事业部ID /// public int? DeptId { get; set; } public int? Channel { get; set; } } public class OrderRefundCustomerComplaintDto { /// /// 投诉单号 /// public string ComplaintId { get; set; } /// /// 投诉类型 /// public int? ComplaintType { get; set; } } #endregion } }