TaobaoOrderController.cs 2.5 KB

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