TaobaoOrderController.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. else
  37. {
  38. filter += $" AND accountId NOT IN (SELECT ID FROM tk_pool WHERE is_hide=1)";
  39. }
  40. if (tkStatus.Any())
  41. {
  42. filter += $" AND tkStatus IN @tkStatus";
  43. }
  44. DateTime stime = DateTime.MinValue, etime = DateTime.MinValue;
  45. if (time.Count == 2)
  46. {
  47. if (DateTime.TryParse(time[0], out stime) && DateTime.TryParse(time[1], out etime))
  48. {
  49. etime = etime.AddDays(1).AddSeconds(-1);
  50. filter += query_type switch
  51. {
  52. "tkEarningTime" or "tkCreateTime" => $" AND {query_type} BETWEEN @stime AND @etime",
  53. _ => $" AND tbPaidTime BETWEEN @stime AND @etime",
  54. };
  55. }
  56. }
  57. filter = filter.StringTrimStart(" AND ");
  58. //排序
  59. string orderBy = $"{query_type} DESC";
  60. if (!string.IsNullOrEmpty(order))
  61. {
  62. order = "descending".Equals(order) ? "DESC" : "ASC";
  63. orderBy = sort switch
  64. {
  65. _ => $"{sort} {order}",
  66. };
  67. }
  68. var result = new DBContext.Table("tk_order_details")
  69. .Where(filter, new { name, stime, etime, tkStatus })
  70. .Page(size, page)
  71. .Order(orderBy)
  72. .PageList<TkOrderDetailDTO>(getTotal);
  73. //foreach (var item in result.List)
  74. //{
  75. // if (string.IsNullOrEmpty(name))
  76. // {
  77. // item.accountName = "-";
  78. // }
  79. //}
  80. if (maxTotal != 0 && result.Count > maxTotal)
  81. {
  82. result.Count = maxTotal;
  83. result.PageCount = maxTotal / size;
  84. }
  85. return new APIResult(new { data = result });
  86. }
  87. }
  88. }