123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325 |
- 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();
- }
- /// <summary>
- /// 订单列表
- /// </summary>
- /// <param name="data"></param>
- /// <param name="filters"></param>
- /// <returns></returns>
- [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<QueryFilter[]>();
- pageIndex = data.pageIndex;
- pageSize = data.pageSize;
- sortField = data.sortField;
- sortDirection = data.sortDirection;
- sumFields = data.sumFields.ToObject<string[]>();
- }
- DataTable dt = new DataTable();
- string result;
- IList<Mem_Orders> permss = new List<Mem_Orders>(0);
- List<SqlParameter> parameters = new List<SqlParameter>();
- 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<T>
- permss = ModelConvertHelper<Mem_Orders>.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<Menu> menus = Permission.Convert(permss);
- var jsonData = JsonConvert.SerializeObject(permss, timejson);
- return Json(new
- {
- items = JsonConvert.DeserializeObject(jsonData),
- sum = new { },
- totalCount = totalcount
- });
- }
- /// <summary>
- /// 获取订单日志
- /// </summary>
- /// <param name="data"></param>
- /// <param name="staffId"></param>
- /// <returns></returns>
- [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<SqlParameter> parameters = new List<SqlParameter>();
- 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
- });
- }
- /// <summary>
- /// 审核订单
- /// </summary>
- /// <param name="data"></param>
- /// <param name="staffId"></param>
- /// <returns></returns>
- [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<SqlParameter> parameters = new List<SqlParameter>();
- 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<List<Object>> parametersC = new List<List<Object>>();
- List<SqlParameter> 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<SqlParameter> parameters = new List<SqlParameter>();
- 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<List<Object>> parametersC = new List<List<Object>>();
- List<SqlParameter> 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
- });
- }
- }
- }
|