TaobaoOrderController.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. using molilian.core;
  2. using dodohold.core;
  3. using Microsoft.AspNetCore.Mvc;
  4. using System.Text.Json;
  5. namespace molilian.api.Controllers
  6. {
  7. [ApiController]
  8. [MyAuthorize("admin")]
  9. [Route("api/[controller]/[action]")]
  10. public class TaobaoOrderController : ControllerBase
  11. {
  12. readonly IAuthorizationProvider provider = new AdminProvider();
  13. protected IHttpContextAccessor _accessor;
  14. public TaobaoOrderController(IHttpContextAccessor accessor)
  15. {
  16. _accessor = accessor;
  17. }
  18. [HttpPost]
  19. public ActionResult list([FromBody] JsonElement form)
  20. {
  21. int page = form.Read("current", 1);
  22. int size = form.Read("pageSize", 10);
  23. bool getTotal = form.Read("getTotal", true);
  24. string sort = form.Read<string>("sort");
  25. string order = form.Read<string>("order");
  26. string name = form.Read<string>("keyword");
  27. string query_type = form.Read<string>("query_type", "tbPaidTime");
  28. var tkStatus = form.PathReadArray<int>("tkStatus[]");
  29. int maxTotal = form.Read("maxTotal", 0);
  30. var time = form.PathReadArray<string>("query_date[]");
  31. string filter = string.Empty;
  32. if (!string.IsNullOrEmpty(name))
  33. {
  34. filter += $" AND accountId IN (SELECT ID FROM tk_pool WHERE company=@name)";
  35. }
  36. if (tkStatus.Any())
  37. {
  38. filter += $" AND tkStatus IN @tkStatus";
  39. }
  40. DateTime stime = DateTime.MinValue, etime = DateTime.MinValue;
  41. if (time.Count == 2)
  42. {
  43. if (DateTime.TryParse(time[0], out stime) && DateTime.TryParse(time[1], out etime))
  44. {
  45. etime = etime.AddDays(1).AddSeconds(-1);
  46. filter += query_type switch
  47. {
  48. "tkEarningTime" or "tkCreateTime" => $" AND {query_type} BETWEEN @stime AND @etime",
  49. _ => $" AND tbPaidTime BETWEEN @stime AND @etime",
  50. };
  51. }
  52. }
  53. filter = filter.StringTrimStart(" AND ");
  54. //排序
  55. string orderBy = $"{query_type} DESC";
  56. if (!string.IsNullOrEmpty(order))
  57. {
  58. order = "descending".Equals(order) ? "DESC" : "ASC";
  59. orderBy = sort switch
  60. {
  61. _ => $"{sort} {order}",
  62. };
  63. }
  64. var result = new DBContext.Table("tk_order_details")
  65. .Where(filter, new { name, stime, etime, tkStatus })
  66. .Page(size, page)
  67. .Order(orderBy)
  68. .PageList<TkOrderDetailDTO>(getTotal);
  69. //foreach (var item in result.List)
  70. //{
  71. // if (string.IsNullOrEmpty(name))
  72. // {
  73. // item.accountName = "-";
  74. // }
  75. //}
  76. if (maxTotal != 0 && result.Count > maxTotal)
  77. {
  78. result.Count = maxTotal;
  79. result.PageCount = maxTotal / size;
  80. }
  81. return new APIResult(new { data = result });
  82. }
  83. }
  84. }