TaobaoOrderController.cs 2.7 KB

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