mem_ingOrdersController.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data;
  4. using System.Data.SqlClient;
  5. using System.IO;
  6. using System.Linq;
  7. using System.Net.Http.Headers;
  8. using System.Threading.Tasks;
  9. using Common.Model;
  10. using CoreEntity.Entity;
  11. using CoreEntity.ESEntity;
  12. using JCSoft.WX.Framework.Api;
  13. using MemberWeb.Commonss;
  14. using Microsoft.AspNetCore.Hosting;
  15. using Microsoft.AspNetCore.Mvc;
  16. using Microsoft.Extensions.Caching.Memory;
  17. using Newtonsoft.Json;
  18. using Newtonsoft.Json.Converters;
  19. using Newtonsoft.Json.Linq;
  20. using NPOI.HSSF.UserModel;
  21. using PublicLibrary.Model;
  22. using SupplierWeb.Commonss;
  23. using ZcPeng.PublicLibrary;
  24. using Num = CoreEntity.ESEntity.Num;
  25. namespace SupplierWeb.Controllers
  26. {
  27. [Route("web/memingorder")]
  28. public class mem_OrdersController : BaseController
  29. {
  30. private readonly IHostingEnvironment _hostingEnvironment;
  31. public mem_OrdersController(IHostingEnvironment hostingEnvironmen,IMemoryCache cache, IApiClient client) : base(cache, client)
  32. {
  33. _hostingEnvironment = hostingEnvironmen;
  34. }
  35. public IActionResult Index()
  36. {
  37. return View();
  38. }
  39. /// <summary>
  40. /// 订单列表
  41. /// </summary>
  42. /// <param name="data"></param>
  43. /// <param name="filters"></param>
  44. /// <returns></returns>
  45. [HttpPost]
  46. [Route("allOrderList")]
  47. public ActionResult allOrderList(QueryFilter[] filters, Int32 pageIndex, Int32 pageSize,
  48. string sortField, Int32 sortDirection, string[] sumFields, [FromBody]dynamic data)
  49. {
  50. if (data != null)
  51. {
  52. filters = data.filters.ToObject<QueryFilter[]>();
  53. pageIndex = data.pageIndex;
  54. pageSize = data.pageSize;
  55. sortField = data.sortField;
  56. sortDirection = data.sortDirection;
  57. sumFields = data.sumFields.ToObject<string[]>();
  58. }
  59. DataTable dt = new DataTable();
  60. string result;
  61. IList<Mem_Orders> permss = new List<Mem_Orders>(0);
  62. List<SqlParameter> parameters = new List<SqlParameter>();
  63. string filterstr = QueryFilter.getFilterSqlParam(filters, out parameters, new Mem_Orders(), "A.");
  64. string direct = " desc ";
  65. if (sortDirection != 1)
  66. {
  67. direct = " asc";
  68. }
  69. if (sortField==null|| sortField=="") {
  70. sortField = "A.OrderTime ";
  71. }
  72. int start = (pageIndex - 1) * pageSize;
  73. int end = (start + 1 + pageSize);
  74. string commandText0 = "select * from ";
  75. string commandText1 = "( SELECT A.*,row_number() over( order by A." + sortField + direct + " ) as rownum FROM (" +
  76. "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 " +
  77. ") as A where 1=1 " +filterstr+" )AAA ";
  78. string commandText2 = " where AAA.rownum > "+ start + " and AAA.rownum < "+ end + " ORDER BY AAA.LastModified desc ";
  79. string commandText3 = commandText0 + commandText1+commandText2;
  80. bool success = DataAccess.GetValues(commandText3, ref dt, parameters.ToArray(), out result);
  81. if (dt != null && dt.Rows.Count > 0)
  82. {
  83. // 把DataTable转换为IList<T>
  84. permss = ModelConvertHelper<Mem_Orders>.ConvertToModel(dt);
  85. }
  86. string result1;
  87. long totalcount = DataAccess.GetRowCountDefine("select count(1) from " + commandText1, parameters.ToArray(), out result1);
  88. IsoDateTimeConverter timejson = new IsoDateTimeConverter
  89. {
  90. DateTimeFormat = "yyyy'-'MM'-'dd' 'HH':'mm':'ss"
  91. };
  92. //IList<Menu> menus = Permission.Convert(permss);
  93. var jsonData = JsonConvert.SerializeObject(permss, timejson);
  94. return Json(new
  95. {
  96. items = JsonConvert.DeserializeObject(jsonData),
  97. sum = new { },
  98. totalCount = totalcount
  99. });
  100. }
  101. /// <summary>
  102. /// 获取订单日志
  103. /// </summary>
  104. /// <param name="data"></param>
  105. /// <param name="staffId"></param>
  106. /// <returns></returns>
  107. [HttpPost]
  108. [Route("getOrderLog")]
  109. public JsonResult getProductLog([FromBody]dynamic data, string staffId)
  110. {
  111. string accountId = getStaff(staffId, "userid");
  112. //判断参数是否合法
  113. if (string.IsNullOrEmpty(accountId))
  114. {
  115. return Json(new
  116. {
  117. timeout = false,
  118. msg = "没有登陆"
  119. });
  120. }
  121. DataTable dt = new DataTable();
  122. if (data != null && data.orderCode != null)
  123. {
  124. List<SqlParameter> parameters = new List<SqlParameter>();
  125. 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 ";
  126. string result;
  127. bool success = DataAccess.GetValues(commandText, ref dt, parameters.ToArray(), out result);
  128. }
  129. return Json(new
  130. {
  131. obj = dt
  132. });
  133. }
  134. /// <summary>
  135. /// 审核订单
  136. /// </summary>
  137. /// <param name="data"></param>
  138. /// <param name="staffId"></param>
  139. /// <returns></returns>
  140. [HttpPost]
  141. [Route("editOrder")]
  142. public JsonResult editOrder([FromBody]dynamic data, string staffId)
  143. {
  144. string accountId = getStaff(staffId, "userid");
  145. //判断参数是否合法
  146. if (string.IsNullOrEmpty(accountId))
  147. {
  148. return Json(new
  149. {
  150. timeout = false,
  151. msg = "没有登陆"
  152. });
  153. }
  154. string msgStr = "";
  155. DataTable dt = new DataTable();
  156. if (data != null && data.orderCode != null)
  157. {
  158. List<SqlParameter> parameters = new List<SqlParameter>();
  159. 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 + "'";
  160. string result;
  161. bool success = DataAccess.GetValues(commandText, ref dt, parameters.ToArray(), out result);
  162. //实物商品推送wms,虚拟商品推送微信消息
  163. DataRow dr = dt.Rows[0];
  164. string OrderState = Convert.ToString(dr["OrderState"]);
  165. string openid = Convert.ToString(dr["openid"]);
  166. string ProductObject = Convert.ToString(dr["ProductObject"]);
  167. if (ProductObject.Equals("1"))
  168. {//实物
  169. if (OrderState != "5")
  170. {
  171. return Json(new
  172. {
  173. timeout = false,
  174. msg = "订单状态已完成!"
  175. });
  176. }
  177. }
  178. else if(ProductObject.Equals("2"))
  179. {//虚拟
  180. if (data.ordesc != null&&data.ordesc != ""&& data.orurl != null && data.orurl != "") {
  181. //修改状态
  182. string msgInfo = data.ordesc + data.orurl;
  183. dynamic messageInfo = new
  184. {
  185. message = msgInfo,
  186. openid = openid
  187. };
  188. string tagjson = JsonConvert.SerializeObject(messageInfo);
  189. //string reqStr = Util.WechatHttp("https://mem.360lj.com/weixin/sendMsg", "POST", tagjson);
  190. string msg1 = "";
  191. int success1 = mem_ProductController.addProductLog(accountId, "2", msgInfo, Convert.ToString(data.orderCode),tagjson);
  192. msgStr = "发送成功!";
  193. if (OrderState=="2") {//审核
  194. string sql = "UPDATE mem_ingOrders SET OrderState='5' where OrdersCode='" + data.orderCode + "'";
  195. //准备参数
  196. List<List<Object>> parametersC = new List<List<Object>>();
  197. List<SqlParameter> parametersC1 = DataAccess.ToParameters(parametersC);
  198. if (success1 > 0)
  199. {
  200. DataAccess.ExecuteCommand(sql, parametersC1, out msg1);
  201. msgStr += "审核成功!";
  202. }
  203. }
  204. }
  205. }
  206. }
  207. return Json(new
  208. {
  209. msg = msgStr
  210. });
  211. }
  212. [HttpPost]
  213. [Route("callOrder")]
  214. public JsonResult callOrder([FromBody]dynamic data, string staffId)
  215. {
  216. string accountId = getStaff(staffId, "userid");
  217. //判断参数是否合法
  218. if (string.IsNullOrEmpty(accountId))
  219. {
  220. return Json(new
  221. {
  222. timeout = false,
  223. msg = "没有登陆"
  224. });
  225. }
  226. string msgStr = "";
  227. DataTable dt = new DataTable();
  228. if (data != null && data.orderCode != null)
  229. {
  230. List<SqlParameter> parameters = new List<SqlParameter>();
  231. 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 " +
  232. " 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 + "'";
  233. string result;
  234. bool success = DataAccess.GetValues(commandText, ref dt, parameters.ToArray(), out result);
  235. if (dt.Rows.Count>0) {
  236. DataRow dr = dt.Rows[0];
  237. string msgText = data.msgText;
  238. string OrdersCode = Convert.ToString(dr["OrdersCode"]);
  239. string OrderState = Convert.ToString(dr["OrderState"]);
  240. string openid = Convert.ToString(dr["openid"]);
  241. string ProductName = Convert.ToString(dr["ProductName"]);
  242. string secret_phone = Convert.ToString(dr["secret_phone"]);
  243. Int32 Integral = Convert.ToInt32(dr["Integral"]);
  244. Int32 payPirce = Convert.ToInt32(dr["payPirce"]);
  245. //修改状态
  246. string msgInfo = "取消已订单!订单编号:"+ OrdersCode+",商品:"+ProductName;
  247. dynamic messageInfo = new
  248. {
  249. message = msgInfo,
  250. openid = openid
  251. };
  252. string tagjson = JsonConvert.SerializeObject(messageInfo);
  253. //string reqStr = Util.WechatHttp("https://mem.360lj.com/weixin/sendMsg", "POST", tagjson);
  254. string msg1 = "";
  255. int success1 = mem_ProductController.addProductLog(accountId, "2", msgInfo+",取消原因:" + msgText, Convert.ToString(data.orderCode), tagjson);
  256. msgStr = "发送成功!";
  257. if (OrderState == "2")
  258. {//审核
  259. string sql = "UPDATE mem_ingOrders SET OrderState='6' where OrdersCode='" + data.orderCode + "'";
  260. //准备参数
  261. List<List<Object>> parametersC = new List<List<Object>>();
  262. List<SqlParameter> parametersC1 = DataAccess.ToParameters(parametersC);
  263. if (success1 > 0)
  264. {
  265. DataAccess.ExecuteCommand(sql, parametersC1, out msg1);
  266. string commandText1 = "SELECT top 1 * FROM mem_user_point_log WHERE secret_phone='"+ secret_phone + "' ORDER BY crt_date DESC ";
  267. string result1;
  268. DataTable dt1 = new DataTable();
  269. if (dt1.Rows.Count>0) {
  270. DataRow dr1 = dt1.Rows[0];
  271. Int32 Ingvalue=Convert.ToInt32(dr1["value"]);
  272. //取消,返回积分
  273. }
  274. success = DataAccess.GetValues(commandText1, ref dt1, parameters.ToArray(), out result1);
  275. msgStr += "取消成功!";
  276. }
  277. }
  278. }
  279. }
  280. return Json(new
  281. {
  282. msg = msgStr
  283. });
  284. }
  285. }
  286. }