using Core.Web.App_Start; using Core.Web.WebHelper; using CRM.Core.BLL.Base; using CRM.Core.BLL.EventBus.Events; using CRM.Core.BLL.Res; using CRM.Core.BLL.Util; using CRM.Core.BLL.Wx; using CRM.Core.Common.EventBus; using CRM.Core.Common.Layui; using CRM.Core.Common.WebHelper; using CRM.Core.DTO; using CRM.Core.DTO.Ord; using CRM.Core.Model.Entity; using CRM.Core.Model.Enum; using CRM.Core.Model.Map; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Web.Mvc; using WX.CRM.Common; namespace Core.Web.Controllers { public class HandleGiftController : BaseController { // GET: HandleGift CACHE_BL cache_BL = new CACHE_BL(); Wx_SzzyOrder_HandGift_BL handbl = new Wx_SzzyOrder_HandGift_BL(); SecurityHelper sHelper = new SecurityHelper(); BAS_PARAMETER_BL paramter_bl = new BAS_PARAMETER_BL(); [AuthorizeRedirect(RightsConfig.CONST_赠送订单列表, ToolBarConfig.CONST_NotButton, true)] [HttpGet] public ActionResult Index(string resid) { ViewBag.rightCode = RightsConfig.CONST_赠送订单列表; //var tool = new ToolBar(); //string[] toolbtn = new ToolButtonView().ToolButtonRight(InitRights.订单列表, userRightId); //tool.AllowButton(toolbtn); ////tool.AllowButton("Create", "Edit", "Details", "Delete"); //ViewBag.ToolBar = tool; var companyList = cache_BL.GetCompanyVirtual(); ViewBag.companyList = cache_BL.GetCompanyVirtual(); var allChannel = new List>(); foreach (var company in companyList) { var channel = new Dictionary { { "name", company.CompanyName }, { "value", company.Channel.Replace(",", ";") } }; allChannel.Add(channel); } ViewBag.AllChannel = JsonHelper.ToJson(allChannel); ViewBag.resid = resid; return View(); } [HttpPost] [AuthorizeRedirect(RightsConfig.CONST_赠送订单列表, ToolBarConfig.CONST_NotButton, false)] public JsonResult GetListHtml(Laypage pager, string columns, HandleGiftQueryDto dto) { try { var list = handbl.GetList(ref pager, dto); List virualList = GetCompanyVirual(); foreach (var item in list) { var df = virualList.FirstOrDefault(m => m.channels.Where(a => a.maxChannel >= item.channel && a.minChannel <= item.channel).Count() > 0); if (df != null) { item.companyname = df.companyname; } else { item.companyname = "未知"; } } var data = new LayuiData() { msg = "数据加载成功!", count = pager.count, code = 0, data = list }; return Json(data, JsonRequestBehavior.AllowGet); } catch (Exception ex) { LogHelper.Error(ex.ToString()); return Json(new { }, JsonRequestBehavior.AllowGet); } } [AuthorizeRedirect(RightsConfig.CONST_赠送订单列表, ToolBarConfig.CONST_Check, true)] [HttpGet] public ActionResult Check(int orderid) { var model = handbl.GetModel(orderid); return View(model); } [AuthorizeRedirect(RightsConfig.CONST_赠送订单列表, ToolBarConfig.CONST_Check, false)] [HttpPost] public JsonResult CheckSaveBatch(string orderids) { foreach (var orderid in orderids.Split(',')) { var jsonResult = CheckSave(decimal.Parse(orderid), 1, ""); var result = jsonResult.Data as retMsg; if (!result.result) { return jsonResult; } } return Json(new retMsg { result = true }, JsonRequestBehavior.AllowGet); } [AuthorizeRedirect(RightsConfig.CONST_赠送订单列表, ToolBarConfig.CONST_Check, false)] [HttpPost] public JsonResult UnCheckSaveBatch(string orderids) { foreach (var orderid in orderids.Split(',')) { var jsonResult = CheckSave(decimal.Parse(orderid), 2, ""); var result = jsonResult.Data as retMsg; if (!result.result) { return jsonResult; } } return Json(new retMsg { result = true }, JsonRequestBehavior.AllowGet); } [AuthorizeRedirect(RightsConfig.CONST_赠送订单列表, ToolBarConfig.CONST_Check, false)] [HttpPost] public JsonResult CheckSave(decimal orderid, int orderstatus, string MEMO) { try { //var ret = _orderService.Open(Convert.ToInt32(orderDto.ORDERID), Eid, UserName); //return Json(ret, JsonRequestBehavior.AllowGet); var ordermodel = handbl.GetModel(orderid); if (ordermodel == null) { return Json(new retMsg { result = false, retcode = 404, retmsg = "找不到订单!" }, JsonRequestBehavior.AllowGet); } if (ordermodel.orderstatus != 0) { return Json(new retMsg { result = false, retcode = 500, retmsg = "此订单已做过审核,不能在审核。" }, JsonRequestBehavior.AllowGet); } if (orderstatus != 1 && orderstatus != 2) { return Json(new retMsg { result = false, retcode = 500, retmsg = "请选【审核通过】或者【审核不通过】!" }, JsonRequestBehavior.AllowGet); } ordermodel.orderstatus = orderstatus; ordermodel.checkmemo = MEMO; ordermodel.optime = DateTime.Now; ordermodel.openuser = string.Format("{0}-{1}", Eid, UserName); if (orderstatus == 2)//不通过审核,无需调用开通接口 { handbl.CheckGift(ordermodel); EventBus.Instance.Publish(new HandGiftEvent(ordermodel, ordermodel.companycode));//推送数据到坐席端 return Json(new retMsg { result = true }, JsonRequestBehavior.AllowGet); } else//审核通过,调用开通订单接口 { #region =================调用NodeJs创建订单======================== LogHelper.Info("====调用NodeJs创建订单==="); CreateOrderReq suorder = new CreateOrderReq(); suorder.productId = ordermodel.subproductcode; suorder.userName = ordermodel.softusername; suorder.count = ordermodel.giftdays;//产品数量 suorder.busType = 1;// //suorder.ch = soft_user.REGCAMPAINID.HasValue ? Convert.ToInt32(soft_user.REGCAMPAINID.Value) : 0; suorder.source = 1; suorder.productType = ordermodel.producttype.Value;//0-单一产品、1-组合产品 suorder.mobile = new RES_RESOURCEMOBILE_BL().GetNumberByResId(ordermodel.resid);//手机号码 suorder.totalPrice = 0;//价格用分作为结算 //suorder.totalDays = ordermodel.opendays.HasValue ? Convert.ToInt32(ordermodel.opendays.Value) : 0; suorder.cssId = ordermodel.createuser.ToString(); suorder.currentCH = ordermodel.channel; suorder.originalCH = ordermodel.channel; suorder.ip = WX.CRM.Common.Utility.GetIp();//获取客户端IP suorder.totalDays = ordermodel.giftdays;//开通天数 //string json = string.Format("content={0}&clientid={1}&sign={2}", content, clientid, sign);//信息转发 var url = paramter_bl.GetValue_Parameter(Parameter.UserCenter_RiaService_AddOrderOpenFree);//封装出来的接口 string json = JsonHelper.ObjDivertToJson(suorder); LogHelper.Info("OpenFreeOrder=>Node.JS接口参数json=>:" + json); json = JsonHelper.ObjDivertToJson(sHelper.createAjaxSignEncodingStr(JsonHelper.ObjDivertToJson(suorder), SecurityHelper.OrderClientIdKey)); string retmsg = Utility.PostAjaxData(url, json, Encoding.UTF8);//返回信息 LogHelper.Info("OpenFreeOrder=>Node.JS接口返回数据json=>:" + retmsg); //retmsg = sHelper.decyptData(SecurityHelper.OrderClientIdKey, retmsg); CreateOrderRsp retmessage = JsonHelper.JsonDivertToObj(retmsg); //====================================================================== #endregion if (retmessage.retCode == (int)NodeJsOrderEnum.调用成功) { ordermodel.otime = DateTime.Now;//审核通过,设置开通时间 ordermodel.szzyorderid = Convert.ToDecimal(retmessage.orderId); handbl.CheckGift(ordermodel); EventBus.Instance.Publish(new HandGiftEvent(ordermodel, ordermodel.companycode));//推送数据到坐席端 return Json(new retMsg { result = true }, JsonRequestBehavior.AllowGet); } else { LogHelper.Error("retmessage:" + retmsg);//记录下单不成功 return Json(new retMsg { result = false, retmsg = retmessage.retMsg }, JsonRequestBehavior.AllowGet); } } } catch (Exception ex) { LogHelper.Error(ex.ToString()); return Json(new retMsg { result = false, retmsg = ex.ToString() }, JsonRequestBehavior.AllowGet); } } [AuthorizeRedirect(RightsConfig.CONST_赠送订单列表, ToolBarConfig.CONST_Other1, true)] [HttpGet] public ActionResult Close(int orderid) { var model = handbl.GetModel(orderid); return View(model); } [AuthorizeRedirect(RightsConfig.CONST_赠送订单列表, ToolBarConfig.CONST_Other1, false)] [HttpPost] public JsonResult Close(decimal orderid, string MEMO) { return Close2(orderid, MEMO); } public JsonResult Close2(decimal orderid, string MEMO) { try { //var ret = _orderService.Open(Convert.ToInt32(orderDto.ORDERID), Eid, UserName); //return Json(ret, JsonRequestBehavior.AllowGet); var ordermodel = handbl.GetModel(orderid); if (ordermodel == null) { return Json(new retMsg { result = false, retcode = 404, retmsg = "找不到订单!" }, JsonRequestBehavior.AllowGet); } if (ordermodel.orderstatus == 3) { return Json(new retMsg { result = false, retcode = 500, retmsg = "此订单已经关闭!" }, JsonRequestBehavior.AllowGet); } if (ordermodel.orderstatus != 1) { return Json(new retMsg { result = false, retcode = 500, retmsg = "已开通的订单才能关闭!" }, JsonRequestBehavior.AllowGet); } ordermodel.orderstatus = 3; ordermodel.closememo = MEMO; ordermodel.closetime = DateTime.Now; ordermodel.closeuser = string.Format("{0}-{1}", Eid, UserName); #region =================调用NodeJ关闭建订单======================== LogHelper.Info("====调用NodeJs关闭订单==="); freeOrderClose suorder = new freeOrderClose(); suorder.userName = ordermodel.softusername; suorder.flag = "0"; suorder.orderId = ordermodel.szzyorderid.ToString(); string url = paramter_bl.GetValue_Parameter(Parameter.UserCenter_RiaService_closeFreeOrder);//封装出来的接口 string json = JsonHelper.ObjDivertToJson(suorder); LogHelper.Info("Node.JS接口参数json=>:" + json); json = JsonHelper.ObjDivertToJson(sHelper.createAjaxSignEncodingStr(JsonHelper.ObjDivertToJson(suorder), SecurityHelper.OrderClientIdKey)); string retmsg = Utility.PostAjaxData(url, json, Encoding.UTF8);//返回信息 LogHelper.Info("Node.JS接口返回数据json=>:" + retmsg); freeOrderCloseRes retmessage = JsonHelper.JsonDivertToObj(retmsg); //====================================================================== #endregion if (retmessage.iRet == 0) { handbl.CheckGift(ordermodel); EventBus.Instance.Publish(new HandGiftEvent(ordermodel, ordermodel.companycode));//推送数据到坐席端 return Json(new retMsg { result = true }, JsonRequestBehavior.AllowGet); } else { LogHelper.Error("retmessage:" + retmsg);//记录下单不成功 return Json(new retMsg { result = false, retmsg = retmessage.sMsg }, JsonRequestBehavior.AllowGet); } } catch (Exception ex) { LogHelper.Error(ex.ToString()); return Json(new retMsg { result = false, retmsg = ex.ToString() }, JsonRequestBehavior.AllowGet); } } public List GetCompanyVirual() { List list = new List(); Bas_CompanyVirtual_BL bl = new Bas_CompanyVirtual_BL(); List virList = bl.GetList().ToList(); foreach (var item in virList) { var model = new CompanyVirlual() { channel = item.Channel, companycode = item.CompanyCode, companyname = item.CompanyName }; model.channels = new List(); foreach (var chennl in item.Channel.Split('|')) { var qujian = chennl.Split(','); model.channels.Add(new MyChannel() { minChannel = Convert.ToInt32(qujian[0].Trim()), maxChannel = Convert.ToInt32(qujian[1].Trim()) }); }; list.Add(model); } return list; } } }