TaobaoOrderController.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. int tkStatus = form.Read("tkStatus", 0);
  28. int maxTotal = form.Read("maxTotal", 0);
  29. var time = form.PathReadArray<string>("query_date[]");
  30. string filter = string.Empty;
  31. if (!string.IsNullOrEmpty(name))
  32. {
  33. filter += $" AND accountId IN (SELECT ID FROM tk_pool WHERE company=@name)";
  34. }
  35. if (tkStatus > 0)
  36. {
  37. filter += $" AND tkStatus=@tkStatus";
  38. }
  39. DateTime stime = DateTime.MinValue, etime = DateTime.MinValue;
  40. if (time.Count == 2)
  41. {
  42. if (DateTime.TryParse(time[0], out stime) && DateTime.TryParse(time[1], out etime))
  43. {
  44. etime = etime.AddDays(1).AddSeconds(-1);
  45. filter += $" AND tkPaidTime BETWEEN @stime AND @etime";
  46. }
  47. }
  48. filter = filter.StringTrimStart(" AND ");
  49. //排序
  50. string orderBy = "tkPaidTime DESC";
  51. if (!string.IsNullOrEmpty(order))
  52. {
  53. order = "descending".Equals(order) ? "DESC" : "ASC";
  54. orderBy = sort switch
  55. {
  56. _ => $"{sort} {order}",
  57. };
  58. }
  59. var result = new DBContext.Table("tk_order_details")
  60. .Where(filter, new { name, stime, etime, tkStatus })
  61. .Page(size, page)
  62. .Order(orderBy)
  63. .PageList<TkOrderDetailDTO>(getTotal);
  64. //foreach (var item in result.List)
  65. //{
  66. // if (string.IsNullOrEmpty(name))
  67. // {
  68. // item.accountName = "-";
  69. // }
  70. //}
  71. if (maxTotal != 0 && result.Count > maxTotal)
  72. {
  73. result.Count = maxTotal;
  74. result.PageCount = maxTotal / size;
  75. }
  76. return new APIResult(new { data = result });
  77. }
  78. }
  79. }