using molilian.core; using dodohold.core; using Microsoft.AspNetCore.Mvc; using System.Text.Json; namespace molilian.api.Controllers { [ApiController] [MyAuthorize("admin")] [Route("api/[controller]/[action]")] public class TaobaoOrderController : ControllerBase { readonly IAuthorizationProvider provider = new AdminProvider(); protected IHttpContextAccessor _accessor; public TaobaoOrderController(IHttpContextAccessor accessor) { _accessor = accessor; } [HttpPost] public ActionResult list([FromBody] JsonElement form) { int page = form.Read("current", 1); int size = form.Read("pageSize", 10); bool getTotal = form.Read("getTotal", true); string sort = form.Read("sort"); string order = form.Read("order"); string name = form.Read("keyword"); string query_type = form.Read("query_type", "tbPaidTime"); var tkStatus = form.PathReadArray("tkStatus[]"); int maxTotal = form.Read("maxTotal", 0); var time = form.PathReadArray("query_date[]"); string filter = string.Empty; if (!string.IsNullOrEmpty(name)) { filter += $" AND accountId IN (SELECT ID FROM tk_pool WHERE company=@name)"; } if (tkStatus.Any()) { filter += $" AND tkStatus IN @tkStatus"; } DateTime stime = DateTime.MinValue, etime = DateTime.MinValue; if (time.Count == 2) { if (DateTime.TryParse(time[0], out stime) && DateTime.TryParse(time[1], out etime)) { etime = etime.AddDays(1).AddSeconds(-1); filter += query_type switch { "tkEarningTime" or "tkCreateTime" => $" AND {query_type} BETWEEN @stime AND @etime", _ => $" AND tbPaidTime BETWEEN @stime AND @etime", }; } } filter = filter.StringTrimStart(" AND "); //排序 string orderBy = $"{query_type} DESC"; if (!string.IsNullOrEmpty(order)) { order = "descending".Equals(order) ? "DESC" : "ASC"; orderBy = sort switch { _ => $"{sort} {order}", }; } var result = new DBContext.Table("tk_order_details") .Where(filter, new { name, stime, etime, tkStatus }) .Page(size, page) .Order(orderBy) .PageList(getTotal); //foreach (var item in result.List) //{ // if (string.IsNullOrEmpty(name)) // { // item.accountName = "-"; // } //} if (maxTotal != 0 && result.Count > maxTotal) { result.Count = maxTotal; result.PageCount = maxTotal / size; } return new APIResult(new { data = result }); } } }