团餐订单
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

OrderService.cs 23 KiB

11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608
  1. using BPA.KitChen.GroupMealOrder.Application.BaseDto;
  2. using BPA.KitChen.GroupMealOrder.Application.Service.TestService;
  3. using BPA.KitChen.GroupMealOrder.Core.Common.Const;
  4. using BPA.KitChen.StoreManagement.Application.Service.OrderManage.Dtos;
  5. using Furion.DatabaseAccessor;
  6. using Furion;
  7. using Furion.DependencyInjection;
  8. using Furion.DynamicApiController;
  9. using Microsoft.AspNetCore.Mvc;
  10. using SqlSugar;
  11. using System;
  12. using System.Collections.Generic;
  13. using System.Linq;
  14. using System.Text;
  15. using System.Threading.Tasks;
  16. using BPA.KitChen.GroupMealOrder.SqlSugar;
  17. using BPA.KitChen.GroupMealOrder.Core.Entity;
  18. using Microsoft.AspNetCore.Authorization;
  19. using Microsoft.AspNetCore.Hosting;
  20. using NPOI.SS.UserModel;
  21. using NPOI.XSSF.UserModel;
  22. using BPA.KitChen.GroupMealOrder.Application.Service.Order.Dtos;
  23. using Org.BouncyCastle.Crypto;
  24. namespace BPA.KitChen.GroupMealOrder.Application.Service.Order
  25. {
  26. [ApiDescriptionSettings("订单管理", Tag = "订单管理", SplitCamelCase = false)]
  27. public class OrderService : IDynamicApiController, ITransient, IOrderService
  28. {
  29. /// <summary>
  30. /// 核心对象:拥有完整的SqlSugar全部功能
  31. /// </summary>
  32. private readonly SqlSugarScope db;
  33. private readonly string CustomerIds = "omwji4jSSh6o-I0UPLGrxKEio73Y,omwji4lFXTPD6SoCQLMexKoWdWY4";
  34. private readonly string StoreId = "3b007e32-f1cc-4021-b4e0-f4764fa90f12";
  35. IWebHostEnvironment _hostingEnvironment;
  36. /// <summary>
  37. /// construct
  38. /// </summary>
  39. /// <param name="sqlSugarRepository"></param>
  40. public OrderService(IWebHostEnvironment hostingEnvironment)
  41. {
  42. db = SqlSugarDb.Db;
  43. _hostingEnvironment=hostingEnvironment;
  44. }
  45. /// <summary>
  46. /// 订单明细
  47. /// </summary>
  48. /// <param name="dto"></param>
  49. /// <returns></returns>
  50. [HttpPost("/api/Order/PostDetail")]
  51. public PageUtil PostDetail(OrderQueryInputDto dto)
  52. {
  53. //根据对应的条件查询和排序
  54. string strWhere = string.Empty;
  55. int total = 0;
  56. List<OrderFlowQuery> res = new List<OrderFlowQuery>();
  57. //if (!string.IsNullOrEmpty(dto.StoreTypeId))//店铺分类
  58. //{
  59. // strWhere += $" and d.Id='{dto.StoreTypeId}'";
  60. //}
  61. if (dto.StoreId != null && dto.StoreId.Length > 0)//店铺名称
  62. {
  63. strWhere += $" and a.StoreId in (";
  64. for (int i = 0; i < dto.StoreId.Length; i++)
  65. {
  66. strWhere += $"'{dto.StoreId[i]}',";
  67. }
  68. strWhere = strWhere.Substring(0, strWhere.LastIndexOf(','));
  69. strWhere += ")";
  70. }
  71. if (dto.GoodsId != null && dto.GoodsId.Length > 0)//商品名称
  72. {
  73. strWhere += $" and a.GoodId in (";
  74. for (int i = 0; i < dto.GoodsId.Length; i++)
  75. {
  76. strWhere += $"'{dto.GoodsId[i]}',";
  77. }
  78. strWhere = strWhere.Substring(0, strWhere.LastIndexOf(','));
  79. strWhere += ")";
  80. }
  81. if (!dto.isreport)
  82. {
  83. if (!string.IsNullOrWhiteSpace(CustomerIds))//屏蔽查询人
  84. {
  85. string key = "";
  86. string[] CustomerId = CustomerIds.Split(',');
  87. for (int i = 0; i < CustomerId.Length; i++)
  88. {
  89. key += $"'{CustomerId[i]}',";
  90. }
  91. key = key.Substring(0, key.LastIndexOf(','));
  92. strWhere += $" and a.Customer_ID not in (" + key + ")";
  93. }
  94. strWhere += $" and a.StoreId not in ('" + StoreId + "')";
  95. }
  96. //if (!string.IsNullOrEmpty(dto.Customer_Tel))
  97. //{
  98. // strWhere += $" and g.Phone='{dto.Customer_Tel}'";
  99. //}
  100. if (dto.GoodsTypeId != null && dto.GoodsTypeId.Length > 0)//商品类型
  101. {
  102. strWhere += $" and e.Goods_TypeID in (";
  103. for (int i = 0; i < dto.GoodsTypeId.Length; i++)
  104. {
  105. strWhere += $"'{dto.GoodsTypeId[i]}',";
  106. }
  107. strWhere = strWhere.Substring(0, strWhere.LastIndexOf(','));
  108. strWhere += ")";
  109. }
  110. //默认当天时间
  111. if (string.IsNullOrEmpty(dto.Order_CreateTime.ToString()))
  112. {
  113. dto.Order_CreateTime = DateTime.Now;
  114. }
  115. if (string.IsNullOrEmpty(dto.Order_EndTime.ToString()))
  116. {
  117. dto.Order_EndTime = DateTime.Now;
  118. }
  119. var GroupId = App.User.FindFirst(ClaimConst.GroupId)?.Value;
  120. if (!string.IsNullOrWhiteSpace(GroupId))
  121. {
  122. strWhere += $" and a.GroupId = '" + GroupId + "'";
  123. }
  124. if (dto.OrderStatus != null)
  125. {
  126. strWhere += $" and a.Order_Status = " + dto.OrderStatus;
  127. }
  128. var temp1 = Convert.ToDateTime(dto.Order_CreateTime.Value.ToString("yyyy-MM-dd"));
  129. var temp2 = Convert.ToDateTime(dto.Order_EndTime.Value.AddDays(1).ToString("yyyy-MM-dd"));
  130. if (!dto.isreport)
  131. {
  132. var lastDay = DateTime.Now.AddDays(1 - DateTime.Now.Day).AddMonths(-1).Date;
  133. if (temp1 < lastDay)
  134. {
  135. temp1 = lastDay;
  136. }
  137. if (temp2 < lastDay)
  138. {
  139. temp2 = lastDay;
  140. }
  141. }
  142. string sql = @"SELECT
  143. UUID() as orderFlowId,
  144. a.OrderInfo_Id AS Id,
  145. a.RefundStatus,
  146. a.StoreId,
  147. a.StoreName,
  148. (case when a.RefundStatus<0 then a.Order_RealMoney else 0 end ) AS Order_RealMoney,
  149. (case when a.RefundStatus<0 then a.Order_OriginalMoney else 0 end ) AS Order_OriginalMoney,
  150. (case when a.RefundStatus>=0 then a.Order_RealMoney else 0 end ) AS RefundRealMoney,
  151. (case when a.RefundStatus>=0 then a.Order_OriginalMoney else 0 end ) AS RefundOriginalMoney,
  152. a.Transaction_ID AS Order_Number,
  153. a.Order_CreateTime AS Order_CreateTime,
  154. a.PlaceMode AS PayMode,
  155. a.Order_Status AS Order_Status,
  156. a.Customer_ID AS Customer_Name,
  157. a.Customer_ID AS Customer_Tel,
  158. 1 as order_Count
  159. FROM
  160. (SELECT
  161. c.`OrderInfo_Id` AS `OrderInfo_Id`,
  162. c.`Order_Status` AS `Order_Status`,
  163. c.`Order_CreateTime` AS `Order_CreateTime`,
  164. c.`StoreId` AS `StoreId`,
  165. c.`StoreName` AS `StoreName`,
  166. c.`Order_OriginalMoney` AS `Order_OriginalMoney`,
  167. c.`Order_RealMoney` AS `Order_RealMoney`,
  168. c.`PlaceMode` AS `PlaceMode`,
  169. c.`Customer_ID` AS `Customer_ID`,
  170. c.`Transaction_ID` AS `Transaction_ID`,
  171. c.`RefundStatus` AS `RefundStatus`,
  172. c.`GroupId` AS `GroupId`,
  173. c.`order_Count` AS `order_Count`
  174. FROM
  175. (
  176. SELECT
  177. `a`.`Id` AS `OrderInfo_Id`,
  178. `a`.`OrderStatus` AS `Order_Status`,
  179. `a`.`CreatedAt` AS `Order_CreateTime`,
  180. `a`.`OrgId` AS `StoreId`,
  181. `a`.`OrgId` AS `StoreName`,
  182. `a`.`OrderOriginalMoney` AS `Order_OriginalMoney`,
  183. `a`.`OrderRealMoney` AS `Order_RealMoney`,((((
  184. `a`.`OrderRealMoney` + ifnull( `a`.`DiscountMoney`, 0 )) + ifnull( json_extract( `a`.`PriceCollection`, '$.CouponPrice' ), 0 )) + ifnull( json_extract( `a`.`PriceCollection`, '$.ActivityPrice' ), 0 )) + ifnull( json_extract( `a`.`PriceCollection`, '$.Vip' ), 0 )) AS `OrderRealMoney`,
  185. `a`.`OrderType` AS `PlaceMode`,
  186. `a`.`CustomerId` AS `Customer_ID`,
  187. `a`.`OrderCount` AS `order_Count`,
  188. `a`.`TransactionId` AS `Transaction_ID`,-(
  189. 1
  190. ) AS `RefundStatus`,
  191. `a`.`GroupId` AS `GroupId`
  192. FROM
  193. `bpa_order` `a`
  194. WHERE
  195. ( length( `a`.`TransactionId` ) > 1 )) AS c UNION ALL
  196. SELECT
  197. `a`.`OrderInfo_Id` AS `OrderInfo_Id`,
  198. `a`.`Order_Status` AS `Order_Status`,
  199. `b`.`RefundTime` AS `Order_CreateTime`,
  200. `a`.`StoreId` AS `StoreId`,
  201. `a`.`StoreName` AS `StoreName`,
  202. `a`.`Order_OriginalMoney` AS `Order_OriginalMoney`,
  203. `a`.`Order_RealMoney` AS `Order_RealMoney`,
  204. `a`.`PlaceMode` AS `PlaceMode`,
  205. `a`.`Customer_ID` AS `Customer_ID`,
  206. `a`.`Transaction_ID` AS `Transaction_ID`,
  207. `b`.`RefundResult` AS `RefundStatus`,
  208. `a`.`GroupId` AS `GroupId`,
  209. `a`.`order_Count` AS `order_Count`
  210. FROM
  211. (
  212. `bpa_orderrefundlog` `b`
  213. LEFT JOIN (
  214. SELECT
  215. `a`.`Id` AS `OrderInfo_Id`,
  216. `a`.`OrderStatus` AS `Order_Status`,
  217. `a`.`CreatedAt` AS `Order_CreateTime`,
  218. `a`.`OrgId` AS `StoreId`,
  219. `a`.`OrgId` AS `StoreName`,
  220. `a`.`OrderOriginalMoney` AS `Order_OriginalMoney`,
  221. `a`.`OrderRealMoney` AS `Order_RealMoney`,((((
  222. `a`.`OrderRealMoney` + ifnull( `a`.`DiscountMoney`, 0 )) + ifnull( json_extract( `a`.`PriceCollection`, '$.CouponPrice' ), 0 )) + ifnull( json_extract( `a`.`PriceCollection`, '$.ActivityPrice' ), 0 )) + ifnull( json_extract( `a`.`PriceCollection`, '$.Vip' ), 0 )) AS `OrderRealMoney`,
  223. `a`.`OrderType` AS `PlaceMode`,
  224. `a`.`CustomerId` AS `Customer_ID`,
  225. `a`.`OrderCount` AS `order_Count`,
  226. `a`.`TransactionId` AS `Transaction_ID`,-(
  227. 1
  228. ) AS `RefundStatus`,
  229. `a`.`GroupId` AS `GroupId`
  230. FROM
  231. `bpa_order` `a`
  232. WHERE
  233. ( length( `a`.`TransactionId` ) > 1 )) `a` ON ((
  234. `a`.`OrderInfo_Id` = `b`.`OrderId`
  235. )))
  236. WHERE
  237. (
  238. `b`.`Stutas` = 202)) a
  239. where a.RefundStatus is not NULL and
  240. a.Order_CreateTime >='" + temp1.ToString("yyyy-MM-dd HH:mm:ss") + @"' and a.Order_CreateTime <'" + temp2.ToString("yyyy-MM-dd HH:mm:ss") + @"'
  241. " + strWhere + "";
  242. res = db.SqlQueryable<OrderFlowQuery>(sql)
  243. .WhereIF(dto.PayMode.HasValue, (b) => b.PayMode == dto.PayMode)
  244. .OrderBy(a => a.Order_CreateTime, OrderByType.Desc).ToPageList(dto.Current, dto.PageSize, ref total);
  245. var ids = res.Select(x => x.Id).ToList();
  246. var orders = db.Queryable<BPA_Order>().Where(x => ids.Contains(x.Id)).ToList();
  247. foreach (var item in res)
  248. {
  249. item.PayMode = orders.FirstOrDefault(x => x.Id == item.Id)?.PayMode ?? 0;
  250. }
  251. PageUtil unit = new PageUtil()
  252. {
  253. Data = res,
  254. Total = total,
  255. };
  256. return unit;
  257. }
  258. [HttpPost("/api/Order/GetFlowExport"), ApiDescriptionSettings(SplitCamelCase = false), AllowAnonymous, NonUnify]
  259. public ResultEntity OrderDetailFlowExport([FromBody] OrderQueryInputDto dto)
  260. {
  261. List<OrderFlowQuery> orderFlows = OrderDetailFlowExportData(dto);
  262. return new ResultEntity()
  263. {
  264. Data = orderFlows,
  265. IsSuccess = orderFlows.Count > 0,
  266. };
  267. string fielName = DateTime.Now.ToString("yyyyMMddHHmmss");
  268. var currentUseId = "OrderFlow";
  269. var rootPath = _hostingEnvironment.ContentRootPath + "orderExcels\\";
  270. if (System.IO.Directory.Exists(rootPath) == false)
  271. System.IO.Directory.CreateDirectory(rootPath);
  272. var newFile = rootPath + "\\" + fielName + ".xlsx";
  273. if (System.IO.File.Exists(newFile))
  274. {
  275. System.IO.File.Delete(newFile);
  276. }
  277. using (var fs = new FileStream(newFile, FileMode.Create, FileAccess.Write))
  278. {
  279. IWorkbook workbook = new XSSFWorkbook();
  280. var sheet = workbook.CreateSheet("orders");
  281. var header = sheet.CreateRow(0);
  282. header.CreateCell(1).SetCellValue("店铺名称 ");
  283. header.CreateCell(2).SetCellValue("交易单号");
  284. header.CreateCell(3).SetCellValue("应付金额");
  285. header.CreateCell(4).SetCellValue("实付金额 ");
  286. header.CreateCell(5).SetCellValue("应退金额");
  287. header.CreateCell(6).SetCellValue("实退金额");
  288. header.CreateCell(7).SetCellValue("菜品数量");
  289. header.CreateCell(8).SetCellValue("下单时间");
  290. var rowIndex = 1;
  291. foreach (var item in orderFlows)
  292. {
  293. var datarow = sheet.CreateRow(rowIndex);
  294. datarow.CreateCell(0).SetCellValue(item.StoreName);
  295. datarow.CreateCell(1).SetCellValue(item.Order_Number);
  296. datarow.CreateCell(2).SetCellValue(item.Order_OriginalMoney.Value.ToString("#0.00"));
  297. datarow.CreateCell(3).SetCellValue(item.Order_RealMoney.Value.ToString("#0.00"));
  298. datarow.CreateCell(4).SetCellValue(item.RefundOriginalMoney.Value.ToString("#0.00"));
  299. datarow.CreateCell(5).SetCellValue(item.RefundRealMoney.Value.ToString("#0.00"));
  300. datarow.CreateCell(6).SetCellValue(item.Order_Count);
  301. datarow.CreateCell(7).SetCellValue(item.Order_CreateTime.ToString("yyyy-MM-dd HH:mm:ss"));
  302. rowIndex++;
  303. }
  304. workbook.Write(fs);
  305. }
  306. var memory = new MemoryStream();
  307. using (var stream = new FileStream(newFile, FileMode.Open))
  308. {
  309. stream.CopyTo(memory);
  310. }
  311. memory.Position = 0;
  312. var result = new FileStreamResult(memory, "application/octet-stream")
  313. {
  314. FileDownloadName = fielName + ".xlsx"
  315. };
  316. // return result;
  317. }
  318. private List<OrderFlowQuery> OrderDetailFlowExportData(OrderQueryInputDto dto)
  319. {
  320. //根据对应的条件查询和排序
  321. string strWhere = string.Empty;
  322. int total = 0;
  323. List<OrderFlowQuery> res = new List<OrderFlowQuery>();
  324. if (!string.IsNullOrEmpty(dto.StoreTypeId))//店铺分类
  325. {
  326. strWhere += $" and d.Id='{dto.StoreTypeId}'";
  327. }
  328. if (dto.StoreId != null && dto.StoreId.Length > 0)//店铺名称
  329. {
  330. strWhere += $" and a.StoreId in (";
  331. for (int i = 0; i < dto.StoreId.Length; i++)
  332. {
  333. strWhere += $"'{dto.StoreId[i]}',";
  334. }
  335. strWhere = strWhere.Substring(0, strWhere.LastIndexOf(','));
  336. strWhere += ")";
  337. }
  338. if (dto.GoodsId != null && dto.GoodsId.Length > 0)//商品名称
  339. {
  340. strWhere += $" and a.GoodId in (";
  341. for (int i = 0; i < dto.GoodsId.Length; i++)
  342. {
  343. strWhere += $"'{dto.GoodsId[i]}',";
  344. }
  345. strWhere = strWhere.Substring(0, strWhere.LastIndexOf(','));
  346. strWhere += ")";
  347. }
  348. if (!dto.isreport)
  349. {
  350. if (!string.IsNullOrWhiteSpace(CustomerIds))//屏蔽查询人
  351. {
  352. string key = "";
  353. string[] CustomerId = CustomerIds.Split(',');
  354. for (int i = 0; i < CustomerId.Length; i++)
  355. {
  356. key += $"'{CustomerId[i]}',";
  357. }
  358. key = key.Substring(0, key.LastIndexOf(','));
  359. strWhere += $" and a.Customer_ID not in (" + key + ")";
  360. }
  361. strWhere += $" and a.StoreId not in ('" + StoreId + "')";
  362. }
  363. if (!string.IsNullOrEmpty(dto.Customer_Tel))
  364. {
  365. strWhere += $" and g.Phone='{dto.Customer_Tel}'";
  366. }
  367. if (dto.GoodsTypeId != null && dto.GoodsTypeId.Length > 0)//商品类型
  368. {
  369. strWhere += $" and e.Goods_TypeID in (";
  370. for (int i = 0; i < dto.GoodsTypeId.Length; i++)
  371. {
  372. strWhere += $"'{dto.GoodsTypeId[i]}',";
  373. }
  374. strWhere = strWhere.Substring(0, strWhere.LastIndexOf(','));
  375. strWhere += ")";
  376. }
  377. //默认当天时间
  378. if (string.IsNullOrEmpty(dto.Order_CreateTime.ToString()))
  379. {
  380. dto.Order_CreateTime = DateTime.Now;
  381. }
  382. if (string.IsNullOrEmpty(dto.Order_EndTime.ToString()))
  383. {
  384. dto.Order_EndTime = DateTime.Now;
  385. }
  386. var GroupId = App.User.FindFirst(ClaimConst.GroupId)?.Value;
  387. if (!string.IsNullOrWhiteSpace(GroupId))
  388. {
  389. strWhere += $" and a.GroupId = '" + GroupId + "'";
  390. }
  391. if (dto.OrderStatus != null)
  392. {
  393. strWhere += $" and a.OrderStatus = " + dto.OrderStatus;
  394. }
  395. var temp1 = Convert.ToDateTime(dto.Order_CreateTime.Value.ToString("yyyy-MM-dd"));
  396. var temp2 = Convert.ToDateTime(dto.Order_EndTime.Value.AddDays(1).ToString("yyyy-MM-dd"));
  397. if (!dto.isreport)
  398. {
  399. var lastDay = DateTime.Now.AddDays(1 - DateTime.Now.Day).AddMonths(-1).Date;
  400. if (temp1 < lastDay)
  401. {
  402. temp1 = lastDay;
  403. }
  404. if (temp2 < lastDay)
  405. {
  406. temp2 = lastDay;
  407. }
  408. }
  409. string sql = @"SELECT
  410. a.OrderInfo_Id AS Id,
  411. a.RefundStatus,
  412. a.StoreId,
  413. a.StoreName,
  414. (case when a.RefundStatus<0 then a.Order_RealMoney else 0 end ) AS Order_RealMoney,
  415. (case when a.RefundStatus<0 then a.Order_OriginalMoney else 0 end ) AS Order_OriginalMoney,
  416. (case when a.RefundStatus>=0 then a.Order_RealMoney else 0 end ) AS RefundRealMoney,
  417. (case when a.RefundStatus>=0 then a.Order_OriginalMoney else 0 end ) AS RefundOriginalMoney,
  418. a.Transaction_ID AS Order_Number,
  419. a.Order_CreateTime AS Order_CreateTime,
  420. a.PlaceMode AS PayMode,
  421. a.Order_Status AS Order_Status,
  422. '' AS Customer_Name,
  423. '' AS Customer_Tel,
  424. 1 as order_Count
  425. FROM
  426. (SELECT
  427. c.`OrderInfo_Id` AS `OrderInfo_Id`,
  428. c.`Order_Status` AS `Order_Status`,
  429. c.`Order_CreateTime` AS `Order_CreateTime`,
  430. c.`StoreId` AS `StoreId`,
  431. c.`StoreName` AS `StoreName`,
  432. c.`Order_OriginalMoney` AS `Order_OriginalMoney`,
  433. c.`Order_RealMoney` AS `Order_RealMoney`,
  434. c.`PlaceMode` AS `PlaceMode`,
  435. c.`Customer_ID` AS `Customer_ID`,
  436. c.`Transaction_ID` AS `Transaction_ID`,
  437. c.`RefundStatus` AS `RefundStatus`,
  438. c.`GroupId` AS `GroupId`,
  439. c.`order_Count` AS `order_Count`
  440. FROM
  441. (
  442. SELECT
  443. `a`.`Id` AS `OrderInfo_Id`,
  444. `a`.`OrderStatus` AS `Order_Status`,
  445. `a`.`CreatedAt` AS `Order_CreateTime`,
  446. `a`.`OrgId` AS `StoreId`,
  447. `a`.`OrgId` AS `StoreName`,
  448. `a`.`OrderOriginalMoney` AS `Order_OriginalMoney`,
  449. `a`.`OrderRealMoney` AS `Order_RealMoney`,((((
  450. `a`.`OrderRealMoney` + ifnull( `a`.`DiscountMoney`, 0 )) + ifnull( json_extract( `a`.`PriceCollection`, '$.CouponPrice' ), 0 )) + ifnull( json_extract( `a`.`PriceCollection`, '$.ActivityPrice' ), 0 )) + ifnull( json_extract( `a`.`PriceCollection`, '$.Vip' ), 0 )) AS `OrderRealMoney`,
  451. `a`.`OrderType` AS `PlaceMode`,
  452. `a`.`CustomerId` AS `Customer_ID`,
  453. `a`.`OrderCount` AS `order_Count`,
  454. `a`.`TransactionId` AS `Transaction_ID`,-(
  455. 1
  456. ) AS `RefundStatus`,
  457. `a`.`GroupId` AS `GroupId`
  458. FROM
  459. `bpa_order` `a`
  460. WHERE
  461. ( length( `a`.`TransactionId` ) > 1 )) AS c UNION ALL
  462. SELECT
  463. `a`.`OrderInfo_Id` AS `OrderInfo_Id`,
  464. `a`.`Order_Status` AS `Order_Status`,
  465. `b`.`RefundTime` AS `Order_CreateTime`,
  466. `a`.`StoreId` AS `StoreId`,
  467. `a`.`StoreName` AS `StoreName`,
  468. `a`.`Order_OriginalMoney` AS `Order_OriginalMoney`,
  469. `a`.`Order_RealMoney` AS `Order_RealMoney`,
  470. `a`.`PlaceMode` AS `PlaceMode`,
  471. `a`.`Customer_ID` AS `Customer_ID`,
  472. `a`.`Transaction_ID` AS `Transaction_ID`,
  473. `b`.`RefundResult` AS `RefundStatus`,
  474. `a`.`GroupId` AS `GroupId`,
  475. `a`.`order_Count` AS `order_Count`
  476. FROM
  477. (
  478. `bpa_orderrefundlog` `b`
  479. LEFT JOIN (
  480. SELECT
  481. `a`.`Id` AS `OrderInfo_Id`,
  482. `a`.`OrderStatus` AS `Order_Status`,
  483. `a`.`CreatedAt` AS `Order_CreateTime`,
  484. `a`.`OrgId` AS `StoreId`,
  485. `a`.`OrgId` AS `StoreName`,
  486. `a`.`OrderOriginalMoney` AS `Order_OriginalMoney`,
  487. `a`.`OrderRealMoney` AS `Order_RealMoney`,((((
  488. `a`.`OrderRealMoney` + ifnull( `a`.`DiscountMoney`, 0 )) + ifnull( json_extract( `a`.`PriceCollection`, '$.CouponPrice' ), 0 )) + ifnull( json_extract( `a`.`PriceCollection`, '$.ActivityPrice' ), 0 )) + ifnull( json_extract( `a`.`PriceCollection`, '$.Vip' ), 0 )) AS `OrderRealMoney`,
  489. `a`.`OrderType` AS `PlaceMode`,
  490. `a`.`CustomerId` AS `Customer_ID`,
  491. `a`.`OrderCount` AS `order_Count`,
  492. `a`.`TransactionId` AS `Transaction_ID`,-(
  493. 1
  494. ) AS `RefundStatus`,
  495. `a`.`GroupId` AS `GroupId`
  496. FROM
  497. `bpa_order` `a`
  498. WHERE
  499. ( length( `a`.`TransactionId` ) > 1 )) `a` ON ((
  500. `a`.`OrderInfo_Id` = `b`.`OrderId`
  501. )))
  502. WHERE
  503. (
  504. `b`.`Stutas` = 202)) a
  505. where a.RefundStatus is not NULL and
  506. a.Order_CreateTime >='" + temp1.ToString("yyyy-MM-dd HH:mm:ss") + @"' and a.Order_CreateTime <'" + temp2.ToString("yyyy-MM-dd HH:mm:ss") + @"'
  507. " + strWhere + "";
  508. res = db.SqlQueryable<OrderFlowQuery>(sql)
  509. .WhereIF(dto.PayMode.HasValue, (b) => b.PayMode == dto.PayMode)
  510. .OrderBy(a => a.Order_CreateTime, OrderByType.Desc).ToList();
  511. return res;
  512. }
  513. #region 第三方订单
  514. /// <summary>
  515. /// 获取第三方
  516. /// </summary>
  517. /// <param name="inputDto"></param>
  518. /// <returns></returns>
  519. [HttpPost("/api/Order/ThirdOrderPage")]
  520. public async Task<PageUtil> ThirdOrderPageAsync(ThirdOrderInputDto inputDto)
  521. {
  522. var total = new RefAsync<int>();
  523. var data = await db.Queryable<BPA_ThirdOrder>()
  524. .OrderBy(a => a.CreateAt, OrderByType.Desc)
  525. .WhereIF(!string.IsNullOrEmpty(inputDto.OrderNum),x=>x.OrderNum.Contains(inputDto.OrderNum))
  526. .Select(x=>new ThirdOrderDto()
  527. {
  528. Id = x.Id.SelectAll()
  529. })
  530. .ToPageListAsync(inputDto.Current, inputDto.PageSize, total);
  531. var ids = data.Select(x => x.Id).ToList();
  532. var thirdOrderInfos = await db.Queryable<BPA_ThirdOrderInfo>()
  533. .Where(x=>ids.Contains(x.ThirdOrderId))
  534. .ToListAsync();
  535. foreach (var item in data)
  536. {
  537. var thisData = thirdOrderInfos.Where(x => x.ThirdOrderId == item.Id).ToList();
  538. item.ThirdOrderInfos= thisData;
  539. }
  540. return new PageUtil()
  541. {
  542. Data = data,
  543. Total = total
  544. };
  545. }
  546. /// <summary>
  547. /// 获取第三方订单详情
  548. /// </summary>
  549. /// <param name="thirdOrderId"></param>
  550. /// <returns></returns>
  551. [HttpGet("/api/Order/GetThirdOrderInfo")]
  552. public async Task<ThirdOrderDto> GetThirdOrderInfo(string thirdOrderId)
  553. {
  554. var data = await db.Queryable<BPA_ThirdOrder>()
  555. .Where(x=>x.Id==thirdOrderId)
  556. .OrderBy(a => a.CreateAt, OrderByType.Desc)
  557. .Select(x => new ThirdOrderDto()
  558. {
  559. Id = x.Id.SelectAll()
  560. }).FirstAsync();
  561. var thirdOrderInfos = await db.Queryable<BPA_ThirdOrderInfo>()
  562. .Where(x => x.ThirdOrderId==thirdOrderId)
  563. .ToListAsync();
  564. data.ThirdOrderInfos = thirdOrderInfos;
  565. return data;
  566. }
  567. #endregion
  568. }
  569. }