using System; using System.Collections.Generic; using System.Data; using System.Data.SqlClient; using System.IO; using System.Linq; using System.Net.Http.Headers; using System.Threading.Tasks; using Common.Model; using CoreEntity.Entity; using CoreEntity.ESEntity; using JCSoft.WX.Framework.Api; using MemberWeb.Commonss; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Caching.Memory; using Newtonsoft.Json; using Newtonsoft.Json.Converters; using Newtonsoft.Json.Linq; using NPOI.HSSF.UserModel; using PublicLibrary.Model; using SupplierWeb.Commonss; using ZcPeng.PublicLibrary; using Num = CoreEntity.ESEntity.Num; namespace SupplierWeb.Controllers { [Route("web/memingorder")] public class mem_OrdersController : BaseController { private readonly IHostingEnvironment _hostingEnvironment; public mem_OrdersController(IHostingEnvironment hostingEnvironmen,IMemoryCache cache, IApiClient client) : base(cache, client) { _hostingEnvironment = hostingEnvironmen; } public IActionResult Index() { return View(); } /// /// 订单列表 /// /// /// /// [HttpPost] [Route("allOrderList")] public ActionResult allOrderList(QueryFilter[] filters, Int32 pageIndex, Int32 pageSize, string sortField, Int32 sortDirection, string[] sumFields, [FromBody]dynamic data) { if (data != null) { filters = data.filters.ToObject(); pageIndex = data.pageIndex; pageSize = data.pageSize; sortField = data.sortField; sortDirection = data.sortDirection; sumFields = data.sumFields.ToObject(); } DataTable dt = new DataTable(); string result; IList permss = new List(0); List parameters = new List(); string filterstr = QueryFilter.getFilterSqlParam(filters, out parameters, new Mem_Orders(), "A."); string direct = " desc "; if (sortDirection != 1) { direct = " asc"; } if (sortField==null|| sortField=="") { sortField = "A.OrderTime "; } int start = (pageIndex - 1) * pageSize; int end = (start + 1 + pageSize); string commandText0 = "select * from "; string commandText1 = "( SELECT A.*,row_number() over( order by A." + sortField + direct + " ) as rownum FROM (" + "SELECT o.*,p.Integral,p.payPirce,p.Is_Pay,p.PayType,p.PostagePrice,d.ProductName,d.Manufacturer,d.Amount,d.MarketPrice,d.MarketIng,d.ProductObject from mem_ingOrders o LEFT JOIN mem_ingOrdersPay p ON o. OrdersCode=p.OrdersCode LEFT JOIN mem_ingProduct d ON d.ProductCode=o.ProductCode where 1=1 " + ") as A where 1=1 " +filterstr+" )AAA "; string commandText2 = " where AAA.rownum > "+ start + " and AAA.rownum < "+ end + " ORDER BY AAA.LastModified desc "; string commandText3 = commandText0 + commandText1+commandText2; bool success = DataAccess.GetValues(commandText3, ref dt, parameters.ToArray(), out result); if (dt != null && dt.Rows.Count > 0) { // 把DataTable转换为IList permss = ModelConvertHelper.ConvertToModel(dt); } string result1; long totalcount = DataAccess.GetRowCountDefine("select count(1) from " + commandText1, parameters.ToArray(), out result1); IsoDateTimeConverter timejson = new IsoDateTimeConverter { DateTimeFormat = "yyyy'-'MM'-'dd' 'HH':'mm':'ss" }; //IList menus = Permission.Convert(permss); var jsonData = JsonConvert.SerializeObject(permss, timejson); return Json(new { items = JsonConvert.DeserializeObject(jsonData), sum = new { }, totalCount = totalcount }); } /// /// 获取订单日志 /// /// /// /// [HttpPost] [Route("getOrderLog")] public JsonResult getProductLog([FromBody]dynamic data, string staffId) { string accountId = getStaff(staffId, "userid"); //判断参数是否合法 if (string.IsNullOrEmpty(accountId)) { return Json(new { timeout = false, msg = "没有登陆" }); } DataTable dt = new DataTable(); if (data != null && data.orderCode != null) { List parameters = new List(); string commandText = "SELECT l.*,a.AccountRealName FROM mem_ingProductLog l LEFT JOIN mem_Account a ON l.MemberId=a.Id WHERE l.logCode=2 AND l.Value='" + data.orderCode + "' ORDER BY CreationDate DESC "; string result; bool success = DataAccess.GetValues(commandText, ref dt, parameters.ToArray(), out result); } return Json(new { obj = dt }); } /// /// 审核订单 /// /// /// /// [HttpPost] [Route("editOrder")] public JsonResult editOrder([FromBody]dynamic data, string staffId) { string accountId = getStaff(staffId, "userid"); //判断参数是否合法 if (string.IsNullOrEmpty(accountId)) { return Json(new { timeout = false, msg = "没有登陆" }); } string msgStr = ""; DataTable dt = new DataTable(); if (data != null && data.orderCode != null) { List parameters = new List(); string commandText = " select o.OrderState,u.openid,p.ProductObject FROM mem_ingOrders o LEFT JOIN mem_weixin_user_info u ON o.AccountId = u.secret_phone LEFT JOIN mem_ingProduct p on p.ProductCode=o.ProductCode where o.OrdersCode='"+ data.orderCode + "'"; string result; bool success = DataAccess.GetValues(commandText, ref dt, parameters.ToArray(), out result); //实物商品推送wms,虚拟商品推送微信消息 DataRow dr = dt.Rows[0]; string OrderState = Convert.ToString(dr["OrderState"]); string openid = Convert.ToString(dr["openid"]); string ProductObject = Convert.ToString(dr["ProductObject"]); if (ProductObject.Equals("1")) {//实物 if (OrderState != "5") { return Json(new { timeout = false, msg = "订单状态已完成!" }); } } else if(ProductObject.Equals("2")) {//虚拟 if (data.ordesc != null&&data.ordesc != ""&& data.orurl != null && data.orurl != "") { //修改状态 string msgInfo = data.ordesc + data.orurl; dynamic messageInfo = new { message = msgInfo, openid = openid }; string tagjson = JsonConvert.SerializeObject(messageInfo); //string reqStr = Util.WechatHttp("https://mem.360lj.com/weixin/sendMsg", "POST", tagjson); string msg1 = ""; int success1 = mem_ProductController.addProductLog(accountId, "2", msgInfo, Convert.ToString(data.orderCode),tagjson); msgStr = "发送成功!"; if (OrderState=="2") {//审核 string sql = "UPDATE mem_ingOrders SET OrderState='5' where OrdersCode='" + data.orderCode + "'"; //准备参数 List> parametersC = new List>(); List parametersC1 = DataAccess.ToParameters(parametersC); if (success1 > 0) { DataAccess.ExecuteCommand(sql, parametersC1, out msg1); msgStr += "审核成功!"; } } } } } return Json(new { msg = msgStr }); } [HttpPost] [Route("callOrder")] public JsonResult callOrder([FromBody]dynamic data, string staffId) { string accountId = getStaff(staffId, "userid"); //判断参数是否合法 if (string.IsNullOrEmpty(accountId)) { return Json(new { timeout = false, msg = "没有登陆" }); } string msgStr = ""; DataTable dt = new DataTable(); if (data != null && data.orderCode != null) { List parameters = new List(); string commandText = " SELECT o.OrderState,o.OrdersCode,u.openid,u.secret_phone,d.ProductName,p.* FROM mem_ingOrders o LEFT JOIN mem_ingOrdersPay p ON p.OrdersCode=o.OrdersCode " + " LEFT JOIN mem_weixin_user_info u ON o.AccountId = u.secret_phone LEFT JOIN mem_ingProduct d ON d.ProductCode = o.ProductCode WHERE o.OrdersCode ='" + data.orderCode + "'"; string result; bool success = DataAccess.GetValues(commandText, ref dt, parameters.ToArray(), out result); if (dt.Rows.Count>0) { DataRow dr = dt.Rows[0]; string msgText = data.msgText; string OrdersCode = Convert.ToString(dr["OrdersCode"]); string OrderState = Convert.ToString(dr["OrderState"]); string openid = Convert.ToString(dr["openid"]); string ProductName = Convert.ToString(dr["ProductName"]); string secret_phone = Convert.ToString(dr["secret_phone"]); Int32 Integral = Convert.ToInt32(dr["Integral"]); Int32 payPirce = Convert.ToInt32(dr["payPirce"]); //修改状态 string msgInfo = "取消已订单!订单编号:"+ OrdersCode+",商品:"+ProductName; dynamic messageInfo = new { message = msgInfo, openid = openid }; string tagjson = JsonConvert.SerializeObject(messageInfo); //string reqStr = Util.WechatHttp("https://mem.360lj.com/weixin/sendMsg", "POST", tagjson); string msg1 = ""; int success1 = mem_ProductController.addProductLog(accountId, "2", msgInfo+",取消原因:" + msgText, Convert.ToString(data.orderCode), tagjson); msgStr = "发送成功!"; if (OrderState == "2") {//审核 string sql = "UPDATE mem_ingOrders SET OrderState='6' where OrdersCode='" + data.orderCode + "'"; //准备参数 List> parametersC = new List>(); List parametersC1 = DataAccess.ToParameters(parametersC); if (success1 > 0) { DataAccess.ExecuteCommand(sql, parametersC1, out msg1); string commandText1 = "SELECT top 1 * FROM mem_user_point_log WHERE secret_phone='"+ secret_phone + "' ORDER BY crt_date DESC "; string result1; DataTable dt1 = new DataTable(); if (dt1.Rows.Count>0) { DataRow dr1 = dt1.Rows[0]; Int32 Ingvalue=Convert.ToInt32(dr1["value"]); //取消,返回积分 } success = DataAccess.GetValues(commandText1, ref dt1, parameters.ToArray(), out result1); msgStr += "取消成功!"; } } } } return Json(new { msg = msgStr }); } } }