TaobaoController.cs 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606
  1. using molilian.core;
  2. using dodohold.core;
  3. using Microsoft.AspNetCore.Mvc;
  4. using System.Text.Json;
  5. using System.Net;
  6. namespace molilian.api.Controllers
  7. {
  8. [ApiController]
  9. [MyAuthorize("admin")]
  10. [Route("api/[controller]/[action]")]
  11. public class TaobaoController : ControllerBase
  12. {
  13. readonly IAuthorizationProvider provider = new AdminProvider();
  14. protected IHttpContextAccessor _accessor;
  15. public TaobaoController(IHttpContextAccessor accessor)
  16. {
  17. _accessor = accessor;
  18. }
  19. [HttpPost]
  20. public async Task<ActionResult> updateCookies([FromBody] JsonElement form)
  21. {
  22. string cookie = form.Read<string>("cookie", string.Empty);
  23. string user_agent = _accessor.HttpContext.Request.UserAgent();
  24. var success = TkPoolCore.UpdateCookies(cookie, user_agent);
  25. return new APIResult(new
  26. {
  27. data = new { success, msg = success ? "更新成功" : "更新失败,请检查输入的cookie" },
  28. });
  29. }
  30. [HttpPost]
  31. public async Task<ActionResult> update([FromBody] JsonElement form)
  32. {
  33. int id = form.Read<int>("id", 0);
  34. string name = form.Read<string>("name", string.Empty);
  35. string val = form.Read<string>("val", string.Empty);
  36. if (id == 0)
  37. {
  38. return new APIResult(new { data = new { success = false, msg = "更新失败,请检查输入的cookie" } });
  39. }
  40. int result;
  41. switch (name)
  42. {
  43. case "enable_fake_click":
  44. case "enable_parse":
  45. case "enable_coupon":
  46. case "status":
  47. bool bVal = val.Equals("True");
  48. result = new DBContext.Table("tk_pool")
  49. .Add(name, bVal)
  50. .Add("last_time", DateTime.Now)
  51. .Where("id=@id", new { id })
  52. .Update();
  53. break;
  54. default:
  55. return new APIResult(new { data = new { success = false, msg = "更新失败,未授权操作" } });
  56. }
  57. bool success = result > 0;
  58. if (success) await EndPointCore.NotifyReload(true);
  59. return new APIResult(new
  60. {
  61. data = new { success, msg = success ? "更新成功" : "更新失败,请检查输入信息" },
  62. });
  63. }
  64. /// <summary>
  65. /// 账号列表
  66. /// </summary>
  67. /// <param name="form"></param>
  68. /// <returns></returns>
  69. [HttpPost]
  70. public ActionResult list([FromBody] JsonElement form)
  71. {
  72. var token = provider.Get(_accessor.HttpContext);
  73. int page = form.Read("current", 1);
  74. int size = form.Read("pageSize", 10);
  75. string keyword = form.Read("name", string.Empty);
  76. bool getTotal = form.Read("getTotal", true);
  77. string _status = form.Read("status", string.Empty);
  78. int status = _status switch
  79. {
  80. "online" => 1,
  81. "offline" => 0,
  82. _ => -1,
  83. };
  84. var lastTime = form.PathReadArray<string>("lastTime[]");
  85. string sort = form.Read<string>("sort");
  86. string order = form.Read<string>("order");
  87. string filter = string.Empty;
  88. if (!string.IsNullOrEmpty(keyword))
  89. {
  90. filter += $" AND (`name` LIKE @keyword OR `description` LIKE @keyword)";
  91. keyword = $"%{keyword}%";
  92. }
  93. DateTime stime = DateTime.MinValue, etime = DateTime.MinValue;
  94. if (lastTime.Count == 2)
  95. {
  96. if (DateTime.TryParse(lastTime[0], out stime) && DateTime.TryParse(lastTime[1], out etime))
  97. {
  98. etime = etime.AddDays(1).AddSeconds(-1);
  99. filter += $" AND last_time BETWEEN @stime AND @etime";
  100. }
  101. }
  102. if (status != -1)
  103. {
  104. filter += $" AND status=@status";
  105. }
  106. filter = filter.StringTrimStart(" AND ");
  107. //排序
  108. string orderBy = "id DESC";
  109. if (!string.IsNullOrEmpty(order))
  110. {
  111. order = "descending".Equals(order) ? "DESC" : "ASC";
  112. orderBy = sort switch
  113. {
  114. //"num" => $"num {order}",
  115. _ => $"{sort} {order}",
  116. };
  117. }
  118. using var conn = DBContext.GetOpenConnection();
  119. var result = new DBContext.Table(conn, "tk_pool")
  120. .Where(filter, new { keyword, status, stime, etime })
  121. .Page(size, page)
  122. .Order(orderBy)
  123. .PageList<TkPoolDTO>(getTotal);
  124. foreach (var item in result.List)
  125. {
  126. item.current_amt = Math.Round(TkPoolCore.GetIncomeAmt(item.name), 2);
  127. item.cookies = string.Empty;
  128. }
  129. return new APIResult(new { data = result });
  130. }
  131. [HttpPost]
  132. public ActionResult report_dailys([FromBody] JsonElement form)
  133. {
  134. int page = form.Read("current", 1);
  135. int size = form.Read("pageSize", 10);
  136. bool getTotal = form.Read("getTotal", true);
  137. string sort = form.Read<string>("sort");
  138. string order = form.Read<string>("order");
  139. var report_date = form.PathReadArray<string>("query_date[]");
  140. string dailys_accountName = "all";
  141. int dailys_accountId = 0;
  142. string filter = string.Empty;
  143. DateTime stime = DateTime.MinValue, etime = DateTime.MinValue;
  144. if (report_date.Count == 2)
  145. {
  146. if (DateTime.TryParse(report_date[0], out stime) && DateTime.TryParse(report_date[1], out etime))
  147. {
  148. etime = etime.AddDays(1).AddSeconds(-1);
  149. filter += $" AND A.report_date BETWEEN @stime AND @etime";
  150. }
  151. }
  152. filter = filter.StringTrimStart(" AND ");
  153. //排序
  154. string orderBy = "A.report_date DESC";
  155. if (!string.IsNullOrEmpty(order))
  156. {
  157. order = "descending".Equals(order) ? "DESC" : "ASC";
  158. orderBy = sort switch
  159. {
  160. _ => $"A.{sort} {order}",
  161. };
  162. }
  163. var result = new DBContext.Table("v_tk_report_dailys")
  164. .LeftJoin("daily_logs",
  165. "B.log_date = A.report_date AND B.accountId=@dailys_accountId",
  166. "total_count, B.abandon_count, B.success_count, B.abandon_percentage, B.success_percentage," +
  167. "B.parse_total_count, B.parse_abandon_count, B.parse_success_count, B.parse_abandon_percentage, B.parse_success_percentage," +
  168. "B.coupon_total_count, B.coupon_abandon_count, B.coupon_success_count, B.coupon_abandon_percentage, B.coupon_success_percentage")
  169. .Where(filter, new { dailys_accountId, dailys_accountName, stime, etime })
  170. .Page(size, page)
  171. .Order(orderBy)
  172. .PageList<TkReportDTO>(getTotal);
  173. foreach (var item in result.List)
  174. {
  175. if (item.total_count > 0) continue;
  176. item.total_count = TkLogCore.GetTotal($":total:all:{item.report_date:yyyyMMdd}");
  177. if (item.total_count == 0) continue;
  178. item.success_count = TkLogCore.GetTotal($":total:all:success:{item.report_date:yyyyMMdd}");
  179. item.abandon_count = TkLogCore.GetTotal($":total:all:放弃转链:{item.report_date:yyyyMMdd}");
  180. if (item.total_count > 0)
  181. {
  182. item.success_percentage = $"{item.success_count / (double)item.total_count * 100:f2}%";
  183. item.abandon_percentage = $"{item.abandon_count / (double)item.total_count * 100:f2}%";
  184. }
  185. if (item.parse_total_count > 0) continue;
  186. item.parse_total_count = TkLogCore.GetTotal($":parse_total:all:{item.report_date:yyyyMMdd}");
  187. if (item.parse_total_count == 0) continue;
  188. item.parse_success_count = TkLogCore.GetTotal($":parse_total:all:success:{item.report_date:yyyyMMdd}");
  189. item.parse_abandon_count = TkLogCore.GetTotal($":parse_total:all:放弃转链:{item.report_date:yyyyMMdd}");
  190. if (item.parse_total_count > 0)
  191. {
  192. item.parse_success_percentage = $"{item.parse_success_count / (double)item.parse_total_count * 100:f2}%";
  193. item.parse_abandon_percentage = $"{item.parse_abandon_count / (double)item.parse_total_count * 100:f2}%";
  194. }
  195. if (item.coupon_total_count > 0) continue;
  196. item.coupon_total_count = TkLogCore.GetTotal($":coupon_total:all:{item.report_date:yyyyMMdd}");
  197. if (item.coupon_total_count == 0) continue;
  198. item.coupon_success_count = TkLogCore.GetTotal($":coupon_total:all:success:{item.report_date:yyyyMMdd}");
  199. item.coupon_abandon_count = TkLogCore.GetTotal($":coupon_total:all:放弃转链:{item.report_date:yyyyMMdd}");
  200. if (item.coupon_total_count > 0)
  201. {
  202. item.coupon_success_percentage = $"{item.coupon_success_count / (double)item.coupon_total_count * 100:f2}%";
  203. item.coupon_abandon_percentage = $"{item.coupon_abandon_count / (double)item.coupon_total_count * 100:f2}%";
  204. }
  205. }
  206. return new APIResult(new { data = result });
  207. }
  208. [HttpPost]
  209. public ActionResult report_list([FromBody] JsonElement form)
  210. {
  211. int page = form.Read("current", 1);
  212. int size = form.Read("pageSize", 10);
  213. bool getTotal = form.Read("getTotal", true);
  214. string sort = form.Read<string>("sort");
  215. string order = form.Read<string>("order");
  216. var report_date = form.PathReadArray<string>("query_date[]");
  217. int accountId = form.Read("accountId", 0);
  218. string filter = string.Empty;
  219. if (accountId != 0)
  220. {
  221. filter += $" AND A.accountId=@accountId";
  222. }
  223. DateTime stime = DateTime.MinValue, etime = DateTime.MinValue;
  224. if (report_date.Count == 2)
  225. {
  226. if (DateTime.TryParse(report_date[0], out stime) && DateTime.TryParse(report_date[1], out etime))
  227. {
  228. etime = etime.AddDays(1).AddSeconds(-1);
  229. filter += $" AND A.report_date BETWEEN @stime AND @etime";
  230. }
  231. }
  232. filter = filter.StringTrimStart(" AND ");
  233. //排序
  234. string orderBy = "A.id DESC";
  235. if (!string.IsNullOrEmpty(order))
  236. {
  237. order = "descending".Equals(order) ? "DESC" : "ASC";
  238. orderBy = sort switch
  239. {
  240. _ => $"A.{sort} {order}",
  241. };
  242. }
  243. var result = new DBContext.Table("tk_report")
  244. .LeftJoin("daily_logs",
  245. "B.log_date = A.report_date AND B.accountId=A.accountId",
  246. "total_count, B.abandon_count, B.success_count, B.abandon_percentage, B.success_percentage," +
  247. "B.parse_total_count, B.parse_abandon_count, B.parse_success_count, B.parse_abandon_percentage, B.parse_success_percentage," +
  248. "B.coupon_total_count, B.coupon_abandon_count, B.coupon_success_count, B.coupon_abandon_percentage, B.coupon_success_percentage")
  249. .Where(filter, new { accountId, stime, etime })
  250. .Page(size, page)
  251. .Order(orderBy)
  252. .PageList<TkReportDTO>(getTotal);
  253. foreach (var item in result.List)
  254. {
  255. //var tk = TkPoolCore.GetOne(item.accountId);
  256. //if (tk != null) item.accountName = tk.company;
  257. string accountName = $"{TkChannelEnum.tb}_{item.accountId}";
  258. if (item.total_count == 0)
  259. {
  260. item.total_count = TkLogCore.GetTotal($":total:{accountName}:{item.report_date:yyyyMMdd}");
  261. if (item.total_count == 0)
  262. {
  263. //todo 过度用, 0613 跑两天就可以删掉
  264. accountName = item.accountName;
  265. item.total_count = TkLogCore.GetTotal($":total:{accountName}:{item.report_date:yyyyMMdd}");
  266. }
  267. if (item.total_count == 0) continue;
  268. item.success_count = TkLogCore.GetTotal($":total:{accountName}:success:{item.report_date:yyyyMMdd}");
  269. item.abandon_count = TkLogCore.GetTotal($":total:{accountName}:放弃转链:{item.report_date:yyyyMMdd}");
  270. if (item.total_count > 0)
  271. {
  272. item.success_percentage = $"{item.success_count / (double)item.total_count * 100:f2}%";
  273. item.abandon_percentage = $"{item.abandon_count / (double)item.total_count * 100:f2}%";
  274. }
  275. }
  276. if (item.parse_total_count == 0)
  277. {
  278. item.parse_total_count = TkLogCore.GetTotal($":parse_total:{accountName}:{item.report_date:yyyyMMdd}");
  279. if (item.parse_total_count == 0) continue;
  280. item.parse_success_count = TkLogCore.GetTotal($":parse_total:{accountName}:success:{item.report_date:yyyyMMdd}");
  281. item.parse_abandon_count = TkLogCore.GetTotal($":parse_total:{accountName}:放弃转链:{item.report_date:yyyyMMdd}");
  282. if (item.parse_total_count > 0)
  283. {
  284. item.parse_success_percentage = $"{item.parse_success_count / (double)item.parse_total_count * 100:f2}%";
  285. item.parse_abandon_percentage = $"{item.parse_abandon_count / (double)item.parse_total_count * 100:f2}%";
  286. }
  287. }
  288. if (item.coupon_total_count == 0)
  289. {
  290. item.coupon_total_count = TkLogCore.GetTotal($":coupon_total:{accountName}:{item.report_date:yyyyMMdd}");
  291. if (item.coupon_total_count == 0) continue;
  292. item.coupon_success_count = TkLogCore.GetTotal($":coupon_total:{accountName}:success:{item.report_date:yyyyMMdd}");
  293. item.coupon_abandon_count = TkLogCore.GetTotal($":coupon_total:{accountName}:放弃转链:{item.report_date:yyyyMMdd}");
  294. if (item.coupon_total_count > 0)
  295. {
  296. item.coupon_success_percentage = $"{item.coupon_success_count / (double)item.coupon_total_count * 100:f2}%";
  297. item.coupon_abandon_percentage = $"{item.coupon_abandon_count / (double)item.coupon_total_count * 100:f2}%";
  298. }
  299. }
  300. }
  301. return new APIResult(new { data = result });
  302. }
  303. [HttpPost]
  304. public ActionResult report_hourtrend([FromBody] JsonElement form)
  305. {
  306. int page = form.Read("current", 1);
  307. int size = form.Read("pageSize", 10);
  308. bool getTotal = form.Read("getTotal", true);
  309. string sort = form.Read<string>("sort");
  310. string order = form.Read<string>("order");
  311. var report_date = form.PathReadArray<string>("query_date[]");
  312. int accountId = form.Read("accountId", 0);
  313. string filter = string.Empty;
  314. if (accountId != 0)
  315. {
  316. filter += $" AND accountId=@accountId";
  317. }
  318. DateTime stime = DateTime.MinValue, etime = DateTime.MinValue;
  319. if (report_date.Count == 2)
  320. {
  321. if (DateTime.TryParse(report_date[0], out stime) && DateTime.TryParse(report_date[1], out etime))
  322. {
  323. etime = etime.AddDays(1).AddSeconds(-1);
  324. if (etime > DateTime.Now) etime = DateTime.Now;
  325. filter += $" AND report_date BETWEEN @stime AND @etime";
  326. }
  327. }
  328. filter = filter.StringTrimStart(" AND ");
  329. //排序
  330. string orderBy = "id ASC";
  331. if (!string.IsNullOrEmpty(order))
  332. {
  333. order = "descending".Equals(order) ? "DESC" : "ASC";
  334. orderBy = sort switch
  335. {
  336. _ => $"{sort} {order}",
  337. };
  338. }
  339. using var conn = DBContext.GetOpenConnection();
  340. var result = new DBContext.Table(conn, "tk_report_hourtrend")
  341. .Where(filter, new { accountId, stime, etime })
  342. .Page(size, page)
  343. .Order(orderBy)
  344. .PageList<TkReportDTO>(getTotal);
  345. foreach (var item in result.List)
  346. {
  347. string accountName = $"{TkChannelEnum.tb}_{item.accountId}";
  348. if (item.total_count == 0)
  349. {
  350. item.total_count = TkLogCore.GetTotal($":total:{accountName}:{item.report_date:yyyyMMddHH}");
  351. if (item.total_count == 0)
  352. {
  353. //todo 过度用, 0613 跑两天就可以删掉
  354. accountName = item.accountName;
  355. item.total_count = TkLogCore.GetTotal($":total:{accountName}:{item.report_date:yyyyMMddHH}");
  356. }
  357. if (item.total_count == 0) continue;
  358. item.success_count = TkLogCore.GetTotal($":total:{item.accountName}:success:{item.report_date:yyyyMMddHH}");
  359. item.abandon_count = TkLogCore.GetTotal($":total:{item.accountName}:放弃转链:{item.report_date:yyyyMMddHH}");
  360. if (item.total_count > 0)
  361. {
  362. item.success_percentage = $"{item.success_count / (double)item.total_count * 100:f2}%";
  363. item.abandon_percentage = $"{item.abandon_count / (double)item.total_count * 100:f2}%";
  364. }
  365. }
  366. if (item.parse_total_count == 0)
  367. {
  368. item.parse_total_count = TkLogCore.GetTotal($":parse_total:{accountName}:{item.report_date:yyyyMMddHH}");
  369. if (item.parse_total_count == 0) continue;
  370. item.parse_success_count = TkLogCore.GetTotal($":parse_total:{item.accountName}:success:{item.report_date:yyyyMMddHH}");
  371. item.parse_abandon_count = TkLogCore.GetTotal($":parse_total:{item.accountName}:放弃转链:{item.report_date:yyyyMMddHH}");
  372. if (item.parse_total_count > 0)
  373. {
  374. item.parse_success_percentage = $"{item.parse_success_count / (double)item.parse_total_count * 100:f2}%";
  375. item.parse_abandon_percentage = $"{item.parse_abandon_count / (double)item.parse_total_count * 100:f2}%";
  376. }
  377. }
  378. if (item.coupon_total_count == 0)
  379. {
  380. item.coupon_total_count = TkLogCore.GetTotal($":coupon_total:{accountName}:{item.report_date:yyyyMMddHH}");
  381. if (item.coupon_total_count == 0) continue;
  382. item.coupon_success_count = TkLogCore.GetTotal($":coupon_total:{item.accountName}:success:{item.report_date:yyyyMMddHH}");
  383. item.coupon_abandon_count = TkLogCore.GetTotal($":coupon_total:{item.accountName}:放弃转链:{item.report_date:yyyyMMddHH}");
  384. if (item.coupon_total_count > 0)
  385. {
  386. item.coupon_success_percentage = $"{item.coupon_success_count / (double)item.coupon_total_count * 100:f2}%";
  387. item.coupon_abandon_percentage = $"{item.coupon_abandon_count / (double)item.coupon_total_count * 100:f2}%";
  388. }
  389. }
  390. }
  391. return new APIResult(new { data = result });
  392. }
  393. [HttpPost]
  394. public ActionResult chartData([FromBody] JsonElement form)
  395. {
  396. var result = new List<dynamic>();
  397. var reason_result = new List<dynamic>();
  398. var report_date = form.PathReadArray<string>("query_date[]");
  399. var accountName = form.Read("accountName", string.Empty);
  400. var isHourtrend = form.Read<bool>("isLeaf", false);
  401. var total_key = form.Read("total_key", "total");
  402. if (string.IsNullOrEmpty(accountName)) accountName = "all";
  403. DateTime stime = DateTime.MinValue;
  404. if (!DateTime.TryParse(report_date[0], out stime)) return new APIResult(new { data = result, data2 = reason_result });
  405. string _report_date = stime.ToString("yyyyMMdd");
  406. if (isHourtrend) _report_date = stime.ToString("yyyyMMddHH");
  407. string cacheKey = $":{total_key}:{accountName}:{_report_date}";
  408. double total = TkLogCore.GetTotal(cacheKey);
  409. if (total > 0)
  410. {
  411. string[] keys = ["success"];
  412. cacheKey = $":{total_key}:{accountName}:message:{_report_date}";
  413. string[] message_keys = TkLogCore.GetTotalKeys(cacheKey);
  414. string[] combinedKeys = keys.Union(message_keys).ToArray();
  415. foreach (var keyname in combinedKeys)
  416. {
  417. cacheKey = $":{total_key}:{accountName}:{keyname}:{_report_date}";
  418. int value = TkLogCore.GetTotal(cacheKey);
  419. if (value == 0) continue;
  420. result.Add(new { name = keyname, value, increases = Math.Round(value / total * 100, 2) });
  421. }
  422. result = result.OrderByDescending(item => item.value).ToList();
  423. cacheKey = $":{total_key}:{accountName}:reason:{_report_date}";
  424. string[] reason_keys = TkLogCore.GetTotalKeys(cacheKey);
  425. foreach (var keyname in reason_keys)
  426. {
  427. cacheKey = $":{total_key}:{accountName}:{keyname}:{_report_date}";
  428. int value = TkLogCore.GetTotal(cacheKey);
  429. if (value == 0) continue;
  430. reason_result.Add(new { name = keyname, value, increases = Math.Round(value / total * 100, 2) });
  431. }
  432. reason_result = reason_result.OrderByDescending(item => item.value).ToList();
  433. }
  434. return new APIResult(new { total, data = result, data2 = reason_result });
  435. }
  436. [HttpPost]
  437. public ActionResult settle_bills_total([FromBody] JsonElement form)
  438. {
  439. int page = form.Read("current", 1);
  440. int size = form.Read("pageSize", 10);
  441. bool getTotal = form.Read("getTotal", true);
  442. string sort = form.Read<string>("sort");
  443. string order = form.Read<string>("order");
  444. var belongTime = form.PathReadArray<string>("query_date[]");
  445. string filter = string.Empty;
  446. DateTime stime = DateTime.MinValue, etime = DateTime.MinValue;
  447. if (belongTime.Count == 2)
  448. {
  449. if (DateTime.TryParse(belongTime[0], out stime) && DateTime.TryParse(belongTime[1], out etime))
  450. {
  451. etime = etime.AddDays(1).AddSeconds(-1);
  452. filter += $" AND belongTime BETWEEN @stime AND @etime";
  453. }
  454. }
  455. filter = filter.StringTrimStart(" AND ");
  456. //排序
  457. string orderBy = "belongTime DESC";
  458. if (!string.IsNullOrEmpty(order))
  459. {
  460. order = "descending".Equals(order) ? "DESC" : "ASC";
  461. orderBy = sort switch
  462. {
  463. _ => $"{sort} {order}",
  464. };
  465. }
  466. var result = new DBContext.Table("v_tk_report_bills")
  467. .Where(filter, new { stime, etime })
  468. .Page(size, page)
  469. .Order(orderBy)
  470. .PageList<TkSettleBillDTO>(getTotal);
  471. return new APIResult(new { data = result });
  472. }
  473. [HttpPost]
  474. public ActionResult settle_bills([FromBody] JsonElement form)
  475. {
  476. int page = form.Read("current", 1);
  477. int size = form.Read("pageSize", 10);
  478. bool getTotal = form.Read("getTotal", true);
  479. string sort = form.Read<string>("sort");
  480. string order = form.Read<string>("order");
  481. string name = form.Read<string>("keyword");
  482. var belongTime = form.PathReadArray<string>("query_date[]");
  483. string filter = string.Empty;
  484. if (!string.IsNullOrEmpty(name))
  485. {
  486. filter += $" AND accountId IN (SELECT ID FROM tk_pool WHERE company=@name)";
  487. }
  488. DateTime stime = DateTime.MinValue, etime = DateTime.MinValue;
  489. if (belongTime.Count == 2)
  490. {
  491. if (DateTime.TryParse(belongTime[0], out stime) && DateTime.TryParse(belongTime[1], out etime))
  492. {
  493. etime = etime.AddDays(1).AddSeconds(-1);
  494. filter += $" AND belongTime BETWEEN @stime AND @etime";
  495. }
  496. }
  497. filter = filter.StringTrimStart(" AND ");
  498. //排序
  499. string orderBy = "belongTime DESC";
  500. if (!string.IsNullOrEmpty(order))
  501. {
  502. order = "descending".Equals(order) ? "DESC" : "ASC";
  503. orderBy = sort switch
  504. {
  505. _ => $"{sort} {order}",
  506. };
  507. }
  508. var result = new DBContext.Table("tk_settle_bill")
  509. .Where(filter, new { name, stime, etime })
  510. .Page(size, page)
  511. .Order(orderBy)
  512. .PageList<TkSettleBillDTO>(getTotal);
  513. //foreach (var item in result.List)
  514. //{
  515. // if (string.IsNullOrEmpty(name))
  516. // {
  517. // item.accountName = "-";
  518. // }
  519. //}
  520. return new APIResult(new { data = result });
  521. }
  522. }
  523. }