OrderListController.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406
  1. using Ant.Data;
  2. using Ant.ORM;
  3. using Ant.SuperSocket.Common;
  4. using Ant.Service.Common;
  5. using Ant.Service.Common.Enums;
  6. using Central.Control.Domain;
  7. using MES.Production.Entity;
  8. using MES.Production.Entity.Entity;
  9. using MES.Production.Entity.Enum;
  10. using MES.Production.Entity.Extensions;
  11. using MES.Production.Entity.Model;
  12. using MES.Production.Entity.Model.OrderList;
  13. using Ant.Service.Mongodb;
  14. using MES.Production.Service.IService;
  15. using MES.Production.Service.ServiceImp;
  16. using Ant.Service.Utility;
  17. using ChangFa.Machinery.WebPage.App_Start;
  18. using ChangFa.Machinery.WebPage.Areas.SysManage.Models;
  19. using ChangFa.Machinery.WebPage.Controllers;
  20. using ChangFa.Machinery.WebPage.Models;
  21. using MongoDB.Driver.Builders;
  22. using System;
  23. using System.Collections.Generic;
  24. using System.Data;
  25. using System.IO;
  26. using System.Linq;
  27. using System.Net;
  28. using System.Net.Http;
  29. using System.Text;
  30. using System.Web;
  31. using System.Web.Mvc;
  32. using JsonHelper = Ant.Service.Common.JsonHelper;
  33. namespace ChangFa.Machinery.WebPage.Areas.SysManage.Controllers
  34. {
  35. public class OrderListController : BaseController
  36. {
  37. /// <summary>
  38. /// 订单列表
  39. /// </summary>
  40. /// <returns></returns>
  41. [UserAuthorize(ModuleAlias = "OrderList", OperaAction = "View")]
  42. public ActionResult List()
  43. {
  44. try
  45. {
  46. PageInfo pageInfo = new PageInfo(base.page, base.pagesize, 0, JsonConverter.JsonClass(new List<YW_Order>()));
  47. #region 处理查询参数
  48. var orderId = Request.QueryString["orderId"];
  49. var os = Request.QueryString["orderStatus"];
  50. var deviceId = Request.QueryString["deviceId"];
  51. if (string.IsNullOrWhiteSpace(os))
  52. {
  53. os = "-1";
  54. }
  55. var orderStatus = ConvertHelper.ObjToInt(os);
  56. #endregion
  57. #region 加载列表
  58. using (AntORM orm = new AntORM())
  59. {
  60. orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
  61. RequestModel res = new RequestModel();
  62. res.newSt = new SqlNote() { Author = "smj", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取订单列表" };
  63. var query = orm.Queryable<YW_Order>();
  64. int pageno = (base.page - 1) * base.pagesize;
  65. // 订单id查询
  66. query = query.WhereIf(!string.IsNullOrEmpty(orderId), p => p.Id == orderId);
  67. // 订单状态
  68. query = query.WhereIf(orderStatus > -1, p => p.OrderStatus == (OrderStatusEnum)orderStatus);
  69. // 所属设备查询
  70. query = query.WhereIf(!string.IsNullOrWhiteSpace(deviceId), p => p.DeviceId == deviceId);
  71. var reslut = query.OrderByDesc(p => p.CreateDT).Skip(pageno).Top(pagesize).ToList(res);
  72. if (reslut.IsSuccess)
  73. {
  74. reslut.RecordNum = query.Count();
  75. #region 替换deviceid成设备名称
  76. var result = reslut.ResultModel as List<YW_Order>;
  77. var deviceIds = result.Select(p => p.DeviceId).ToList();
  78. var devices = orm.Queryable<SYS_Device>().Where(p => deviceIds.Contains(p.Id)).ToList(res).ResultModel as List<SYS_Device>;
  79. result.ForEach(item => {
  80. var deviceName = devices.FirstOrDefault(p => p.Id == item.DeviceId)?.Name;
  81. item.DeviceId = deviceName ?? item.DeviceId;
  82. });
  83. #endregion
  84. pageInfo = new PageInfo(base.page, base.pagesize, reslut.RecordNum, result);
  85. }
  86. // 查询所以设备数据,下拉框用
  87. List<SYS_Device> devicesData = orm.Queryable<SYS_Device>().Where(p => p.IsDelete == 0).ToList().ResultModel;
  88. ViewData["devicesData"] = devicesData;
  89. }
  90. ViewData["orderId"] = orderId;
  91. ViewData["orderStatus"] = orderStatus;
  92. ViewData["deviceId"] = deviceId ?? string.Empty;
  93. return View(pageInfo);
  94. #endregion
  95. }
  96. catch (Exception e)
  97. {
  98. WriteLog(enumOperator.Select, "获取参赛列表:", e);
  99. throw e.InnerException;
  100. }
  101. }
  102. /// <summary>
  103. /// 支付信息
  104. /// </summary>
  105. /// <returns></returns>
  106. [UserAuthorize(ModuleAlias = "OrderList", OperaAction = "payInfo")]
  107. public ActionResult PayInfo(string id)
  108. {
  109. PayCallDto result = new PayCallDto();
  110. using (AntORM orm = new AntORM())
  111. {
  112. orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
  113. RequestModel res = new RequestModel();
  114. res.newSt = new SqlNote() { Author = "smj", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "支付信息" };
  115. var payList = orm.Queryable<YW_PayCall>().Where(p => p.IsDelete == 0 && p.OrderId == id).ToList(res).ResultModel as List<YW_PayCall>;
  116. payList?.ForEach(payItem => {
  117. result.OrderPayInfos.Add(new OrderPayInfoDto()
  118. {
  119. Id = payItem.Id,
  120. PayStatus = payItem.PayStatus,
  121. PaySerialId = payItem.PaySerialId,
  122. BuyAccount = payItem.BuyAccount,
  123. CreateDT = payItem.CreateDT
  124. });
  125. });
  126. }
  127. return View(result);
  128. }
  129. /// <summary>
  130. /// 订单流程信息
  131. /// </summary>
  132. /// <returns></returns>
  133. [UserAuthorize(ModuleAlias = "OrderList", OperaAction = "processInfo")]
  134. public ActionResult ProcessInfo(string id)
  135. {
  136. ProcessInfoDto result = new ProcessInfoDto();
  137. using (AntORM orm = new AntORM())
  138. {
  139. orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
  140. RequestModel res = new RequestModel();
  141. res.newSt = new SqlNote() { Author = "smj", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "流程信息" };
  142. var processList = orm.Queryable<YW_OrderProcess>().Where(p => p.IsDelete == 0 && p.OrderId == id).ToList(res).ResultModel as List<YW_OrderProcess>;
  143. var devices = new List<SYS_Device>();
  144. var deviceIds = processList?.Select(p => p.DeviceId).ToList();
  145. if (deviceIds != null && deviceIds.Count() > 0)
  146. {
  147. devices = orm.Queryable<SYS_Device>().Where(p => p.IsDelete == 0 && deviceIds.Contains(p.Id)).ToList(res).ResultModel as List<SYS_Device>;
  148. }
  149. processList?.ForEach(processItem => {
  150. result.OrderProcessInfos.Add(new OrderProcessDto()
  151. {
  152. Id = processItem.Id,
  153. DeviceName = devices.FirstOrDefault(p => p.Id == processItem.DeviceId)?.Name ?? processItem.DeviceId,
  154. CurrentOrderStatus = processItem.CurrentOrderStatus,
  155. Message = processItem.Message,
  156. CreateDT = processItem.CreateDT
  157. });
  158. });
  159. }
  160. return View(result);
  161. }
  162. /// <summary>
  163. /// 订单日志信息
  164. /// </summary>
  165. /// <returns></returns>
  166. [UserAuthorize(ModuleAlias = "OrderList", OperaAction = "orderLog")]
  167. public ActionResult OrderLog(string id)
  168. {
  169. OrderLogDto result = new OrderLogDto();
  170. using (AntORM orm = new AntORM())
  171. {
  172. orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
  173. RequestModel res = new RequestModel();
  174. res.newSt = new SqlNote() { Author = "smj", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "订单日志" };
  175. var orderLogs = orm.Queryable<YW_OrderLog>().Where(p => p.OrderId == id).ToList(res).ResultModel as List<YW_OrderLog>;
  176. result.OrderLogInfos = orderLogs.Select(p => new OrderLogInfoDto()
  177. {
  178. Id = p.Id,
  179. Title = p.Title,
  180. Content = p.Content,
  181. CreateDT = p.CreateDT,
  182. CreateBY = p.CreateBY
  183. }).ToList();
  184. }
  185. return View(result);
  186. }
  187. /// <summary>
  188. /// 订单详情
  189. /// </summary>
  190. /// <param name="id"></param>
  191. /// <returns></returns>
  192. [UserAuthorize(ModuleAlias = "OrderList", OperaAction = "Detail")]
  193. public ActionResult Detail(string id)
  194. {
  195. OrderInfoDto entity = new OrderInfoDto();
  196. using (AntORM orm = new AntORM())
  197. {
  198. try
  199. {
  200. orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
  201. RequestModel request = new RequestModel
  202. {
  203. newSt = new SqlNote() { Author = "smj", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "订单详情" },
  204. Oid = id.ToString()
  205. };
  206. var reslut = orm.GetEntity<YW_Order>(request);
  207. if (reslut.IsSuccess)
  208. {
  209. YW_Order order = reslut.ResultModel;
  210. string payAccount = string.Empty;
  211. if (!string.IsNullOrWhiteSpace(order.PaySerialId))
  212. {
  213. // 若有支付流水号,则查询出事谁支付的
  214. var payCall = orm.Queryable<YW_PayCall>().Where(p=>p.PaySerialId == order.PaySerialId).FirstOrDefault().ResultModel as YW_PayCall;
  215. if (payCall != null)
  216. {
  217. payAccount = $"({payCall.BuyAccount})";
  218. }
  219. }
  220. // 查询订单所属的设备
  221. request.Oid = order.DeviceId;
  222. var device = orm.GetEntity<SYS_Device>(request).ResultModel as SYS_Device;
  223. // 查询订单详情
  224. var orderDetails = orm.Queryable<YW_OrderDetails>().Where(p => p.IsDelete == 0 && p.OrderId == order.Id).ToList(request).ResultModel as List<YW_OrderDetails>;
  225. List<OrderDetailsDto> od = new List<OrderDetailsDto>();
  226. decimal totalBuyPrice = 0;
  227. orderDetails?.ForEach(orderDetail =>
  228. {
  229. od.Add(new OrderDetailsDto()
  230. {
  231. Id = orderDetail.Id,
  232. ProductId = orderDetail.ProductId,
  233. Name = orderDetail.Name,
  234. Code = orderDetail.Code,
  235. Img = orderDetail.Img,
  236. Price = orderDetail.Price,
  237. BuyingPrice = orderDetail.BuyingPrice,
  238. Count = orderDetail.Count,
  239. CreateDT = orderDetail.CreateDT
  240. });
  241. totalBuyPrice += orderDetail.BuyingPrice * orderDetail.Count;
  242. });
  243. // 返回实体赋值
  244. entity.Id = order.Id;
  245. entity.DeviceName = device.Name;
  246. entity.Price = order.Price;
  247. entity.BuyingPrice = totalBuyPrice;
  248. entity.Profit = order.Price - totalBuyPrice;
  249. entity.OrderStatus = order.OrderStatus;
  250. entity.PaySerialId = order.PaySerialId;
  251. entity.BuyAccount = payAccount;
  252. entity.CreateDT = order.CreateDT;
  253. entity.OrderDetails = od;
  254. }
  255. }
  256. catch (Exception e)
  257. {
  258. }
  259. }
  260. return View(entity);
  261. }
  262. /// <summary>
  263. /// 订单退款
  264. /// </summary>
  265. /// <param name="id"></param>
  266. /// <returns></returns>
  267. [UserAuthorize(ModuleAlias = "OrderList", OperaAction = "orderRefund")]
  268. public ActionResult OrderRefundDetails(string id)
  269. {
  270. OrderRefundDto entity = new OrderRefundDto();
  271. using (AntORM orm = new AntORM())
  272. {
  273. try
  274. {
  275. orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
  276. RequestModel request = new RequestModel
  277. {
  278. newSt = new SqlNote() { Author = "smj", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "订单详情" },
  279. Oid = id.ToString()
  280. };
  281. var reslut = orm.GetEntity<YW_Order>(request);
  282. if (reslut.IsSuccess)
  283. {
  284. YW_Order order = reslut.ResultModel;
  285. string payAccount = string.Empty;
  286. if (!string.IsNullOrWhiteSpace(order.PaySerialId))
  287. {
  288. // 若有支付流水号,则查询出事谁支付的
  289. var payCall = orm.Queryable<YW_PayCall>().Where(p => p.PaySerialId == order.PaySerialId).FirstOrDefault().ResultModel as YW_PayCall;
  290. if (payCall != null)
  291. {
  292. payAccount = $"({payCall.BuyAccount})";
  293. }
  294. }
  295. // 查询订单所属的设备
  296. request.Oid = order.DeviceId;
  297. var device = orm.GetEntity<SYS_Device>(request).ResultModel as SYS_Device;
  298. // 返回实体赋值
  299. entity.Id = order.Id;
  300. entity.DeviceName = device.Name;
  301. entity.Price = order.Price;
  302. entity.PaySerialId = order.PaySerialId;
  303. entity.BuyAccount = payAccount;
  304. entity.PayStatus = order.PayStatus;
  305. entity.CreateDT = order.CreateDT;
  306. }
  307. }
  308. catch (Exception e)
  309. {
  310. }
  311. }
  312. return View(entity);
  313. }
  314. /// <summary>
  315. /// 订单退款
  316. /// </summary>
  317. /// <param name="id"></param>
  318. /// <returns></returns>
  319. [UserAuthorize(ModuleAlias = "OrderList", OperaAction = "orderRefund")]
  320. public ActionResult OrderRefund(OrderRefundDto entity)
  321. {
  322. Ant.ORM.RequestModel sqlQueryReq = new Ant.ORM.RequestModel();
  323. sqlQueryReq.newSt = new Ant.ORM.SqlNote() { Author = "smj", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "OrderListController-OrderRefund" };
  324. JsonHelper json = new JsonHelper() { Msg = "订单退款", Status = "n", ReUrl = "/OrderList/List" };
  325. // WebClient webClient = new WebClient();
  326. using (HttpClient client = new HttpClient())
  327. {
  328. // 参数设置
  329. string stringForHash = $"{entity.Id}|{WebSystemAccessConfig.Sign}";
  330. string token = MD5Helper.MD5Hash(stringForHash);
  331. string url = $"http://api.rgtech.ltd/api/order/orderrefund/{entity.Id}?token={token}";
  332. var method = new HttpMethod("PUT");
  333. var request = new HttpRequestMessage(method, url);
  334. var response = client.SendAsync(request).Result;
  335. if (response.IsSuccessStatusCode)
  336. {
  337. var stream = response.Content.ReadAsStringAsync().Result;
  338. ApiResult result = Newtonsoft.Json.JsonConvert.DeserializeObject<ApiResult>(stream);
  339. if (result.IsSuccess)
  340. {
  341. // 退款成功
  342. json.Status = "y";
  343. }
  344. else
  345. {
  346. json.Msg = result.Message;
  347. }
  348. }
  349. else
  350. {
  351. json.Msg = "退款失败";
  352. WriteLog(enumOperator.Audit, $"订单退款:{Newtonsoft.Json.JsonConvert.SerializeObject(response)}", enumLog4net.ERROR);
  353. }
  354. }
  355. return Json(json);
  356. }
  357. }
  358. }