TaobaoController.cs 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615
  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.report_date.Date < DateTime.Now.Date) continue;
  176. if (item.total_count == 0)
  177. {
  178. item.total_count = TkLogCore.GetTotal($":total:tb:{item.report_date:yyyyMMdd}");
  179. if (item.total_count == 0) continue;
  180. item.success_count = TkLogCore.GetTotal($":total:tb:success:{item.report_date:yyyyMMdd}");
  181. item.abandon_count = TkLogCore.GetTotal($":total:tb:放弃转链:{item.report_date:yyyyMMdd}");
  182. if (item.total_count > 0)
  183. {
  184. item.success_percentage = $"{item.success_count / (double)item.total_count * 100:f2}%";
  185. item.abandon_percentage = $"{item.abandon_count / (double)item.total_count * 100:f2}%";
  186. }
  187. }
  188. if (item.parse_total_count == 0)
  189. {
  190. item.parse_total_count = TkLogCore.GetTotal($":parse_total:tb:{item.report_date:yyyyMMdd}");
  191. if (item.parse_total_count == 0) continue;
  192. item.parse_success_count = TkLogCore.GetTotal($":parse_total:tb:success:{item.report_date:yyyyMMdd}");
  193. item.parse_abandon_count = TkLogCore.GetTotal($":parse_total:tb:放弃转链:{item.report_date:yyyyMMdd}");
  194. if (item.parse_total_count > 0)
  195. {
  196. item.parse_success_percentage = $"{item.parse_success_count / (double)item.parse_total_count * 100:f2}%";
  197. item.parse_abandon_percentage = $"{item.parse_abandon_count / (double)item.parse_total_count * 100:f2}%";
  198. }
  199. }
  200. if (item.coupon_total_count == 0)
  201. {
  202. item.coupon_total_count = TkLogCore.GetTotal($":coupon_total:tb:{item.report_date:yyyyMMdd}");
  203. if (item.coupon_total_count == 0) continue;
  204. item.coupon_success_count = TkLogCore.GetTotal($":coupon_total:tb:success:{item.report_date:yyyyMMdd}");
  205. item.coupon_abandon_count = TkLogCore.GetTotal($":coupon_total:tb:放弃转链:{item.report_date:yyyyMMdd}");
  206. if (item.coupon_total_count > 0)
  207. {
  208. item.coupon_success_percentage = $"{item.coupon_success_count / (double)item.coupon_total_count * 100:f2}%";
  209. item.coupon_abandon_percentage = $"{item.coupon_abandon_count / (double)item.coupon_total_count * 100:f2}%";
  210. }
  211. }
  212. }
  213. return new APIResult(new { data = result });
  214. }
  215. [HttpPost]
  216. public ActionResult report_list([FromBody] JsonElement form)
  217. {
  218. int page = form.Read("current", 1);
  219. int size = form.Read("pageSize", 10);
  220. bool getTotal = form.Read("getTotal", true);
  221. string sort = form.Read<string>("sort");
  222. string order = form.Read<string>("order");
  223. var report_date = form.PathReadArray<string>("query_date[]");
  224. int accountId = form.Read("accountId", 0);
  225. string filter = string.Empty;
  226. if (accountId != 0)
  227. {
  228. filter += $" AND A.accountId=@accountId";
  229. }
  230. DateTime stime = DateTime.MinValue, etime = DateTime.MinValue;
  231. if (report_date.Count == 2)
  232. {
  233. if (DateTime.TryParse(report_date[0], out stime) && DateTime.TryParse(report_date[1], out etime))
  234. {
  235. etime = etime.AddDays(1).AddSeconds(-1);
  236. filter += $" AND A.report_date BETWEEN @stime AND @etime";
  237. }
  238. }
  239. filter = filter.StringTrimStart(" AND ");
  240. //排序
  241. string orderBy = "A.id DESC";
  242. if (!string.IsNullOrEmpty(order))
  243. {
  244. order = "descending".Equals(order) ? "DESC" : "ASC";
  245. orderBy = sort switch
  246. {
  247. _ => $"A.{sort} {order}",
  248. };
  249. }
  250. var result = new DBContext.Table("tk_report")
  251. .LeftJoin("daily_logs",
  252. "B.log_date = A.report_date AND B.accountId=A.accountId",
  253. "total_count, B.abandon_count, B.success_count, B.abandon_percentage, B.success_percentage," +
  254. "B.parse_total_count, B.parse_abandon_count, B.parse_success_count, B.parse_abandon_percentage, B.parse_success_percentage," +
  255. "B.coupon_total_count, B.coupon_abandon_count, B.coupon_success_count, B.coupon_abandon_percentage, B.coupon_success_percentage")
  256. .Where(filter, new { accountId, stime, etime })
  257. .Page(size, page)
  258. .Order(orderBy)
  259. .PageList<TkReportDTO>(getTotal);
  260. foreach (var item in result.List)
  261. {
  262. if (item.report_date.Date < DateTime.Now.Date) continue;
  263. //var tk = TkPoolCore.GetOne(item.accountId);
  264. //if (tk != null) item.accountName = tk.company;
  265. string accountName = $"{TkChannelEnum.tb}_{item.accountId}";
  266. if (item.total_count == 0)
  267. {
  268. item.total_count = TkLogCore.GetTotal($":total:{accountName}:{item.report_date:yyyyMMdd}");
  269. if (item.total_count == 0)
  270. {
  271. //todo 过度用, 0613 跑两天就可以删掉
  272. accountName = item.accountName;
  273. item.total_count = TkLogCore.GetTotal($":total:{accountName}:{item.report_date:yyyyMMdd}");
  274. }
  275. if (item.total_count == 0) continue;
  276. item.success_count = TkLogCore.GetTotal($":total:{accountName}:success:{item.report_date:yyyyMMdd}");
  277. item.abandon_count = TkLogCore.GetTotal($":total:{accountName}:放弃转链:{item.report_date:yyyyMMdd}");
  278. if (item.total_count > 0)
  279. {
  280. item.success_percentage = $"{item.success_count / (double)item.total_count * 100:f2}%";
  281. item.abandon_percentage = $"{item.abandon_count / (double)item.total_count * 100:f2}%";
  282. }
  283. }
  284. if (item.parse_total_count == 0)
  285. {
  286. item.parse_total_count = TkLogCore.GetTotal($":parse_total:{accountName}:{item.report_date:yyyyMMdd}");
  287. if (item.parse_total_count == 0) continue;
  288. item.parse_success_count = TkLogCore.GetTotal($":parse_total:{accountName}:success:{item.report_date:yyyyMMdd}");
  289. item.parse_abandon_count = TkLogCore.GetTotal($":parse_total:{accountName}:放弃转链:{item.report_date:yyyyMMdd}");
  290. if (item.parse_total_count > 0)
  291. {
  292. item.parse_success_percentage = $"{item.parse_success_count / (double)item.parse_total_count * 100:f2}%";
  293. item.parse_abandon_percentage = $"{item.parse_abandon_count / (double)item.parse_total_count * 100:f2}%";
  294. }
  295. }
  296. if (item.coupon_total_count == 0)
  297. {
  298. item.coupon_total_count = TkLogCore.GetTotal($":coupon_total:{accountName}:{item.report_date:yyyyMMdd}");
  299. if (item.coupon_total_count == 0) continue;
  300. item.coupon_success_count = TkLogCore.GetTotal($":coupon_total:{accountName}:success:{item.report_date:yyyyMMdd}");
  301. item.coupon_abandon_count = TkLogCore.GetTotal($":coupon_total:{accountName}:放弃转链:{item.report_date:yyyyMMdd}");
  302. if (item.coupon_total_count > 0)
  303. {
  304. item.coupon_success_percentage = $"{item.coupon_success_count / (double)item.coupon_total_count * 100:f2}%";
  305. item.coupon_abandon_percentage = $"{item.coupon_abandon_count / (double)item.coupon_total_count * 100:f2}%";
  306. }
  307. }
  308. }
  309. return new APIResult(new { data = result });
  310. }
  311. [HttpPost]
  312. public ActionResult report_hourtrend([FromBody] JsonElement form)
  313. {
  314. int page = form.Read("current", 1);
  315. int size = form.Read("pageSize", 10);
  316. bool getTotal = form.Read("getTotal", true);
  317. string sort = form.Read<string>("sort");
  318. string order = form.Read<string>("order");
  319. var report_date = form.PathReadArray<string>("query_date[]");
  320. int accountId = form.Read("accountId", 0);
  321. string filter = string.Empty;
  322. if (accountId != 0)
  323. {
  324. filter += $" AND accountId=@accountId";
  325. }
  326. DateTime stime = DateTime.MinValue, etime = DateTime.MinValue;
  327. if (report_date.Count == 2)
  328. {
  329. if (DateTime.TryParse(report_date[0], out stime) && DateTime.TryParse(report_date[1], out etime))
  330. {
  331. etime = etime.AddDays(1).AddSeconds(-1);
  332. if (etime > DateTime.Now) etime = DateTime.Now;
  333. filter += $" AND report_date BETWEEN @stime AND @etime";
  334. }
  335. }
  336. filter = filter.StringTrimStart(" AND ");
  337. //排序
  338. string orderBy = "id ASC";
  339. if (!string.IsNullOrEmpty(order))
  340. {
  341. order = "descending".Equals(order) ? "DESC" : "ASC";
  342. orderBy = sort switch
  343. {
  344. _ => $"{sort} {order}",
  345. };
  346. }
  347. using var conn = DBContext.GetOpenConnection();
  348. var result = new DBContext.Table(conn, "tk_report_hourtrend")
  349. .Where(filter, new { accountId, stime, etime })
  350. .Page(size, page)
  351. .Order(orderBy)
  352. .PageList<TkReportDTO>(getTotal);
  353. foreach (var item in result.List)
  354. {
  355. if (item.report_date.Date < DateTime.Now.Date) continue;
  356. string accountName = $"{TkChannelEnum.tb}_{item.accountId}";
  357. if (item.total_count == 0)
  358. {
  359. item.total_count = TkLogCore.GetTotal($":total:{accountName}:{item.report_date:yyyyMMddHH}");
  360. if (item.total_count == 0)
  361. {
  362. //todo 过度用, 0613 跑两天就可以删掉
  363. accountName = item.accountName;
  364. item.total_count = TkLogCore.GetTotal($":total:{accountName}:{item.report_date:yyyyMMddHH}");
  365. }
  366. if (item.total_count == 0) continue;
  367. item.success_count = TkLogCore.GetTotal($":total:{item.accountName}:success:{item.report_date:yyyyMMddHH}");
  368. item.abandon_count = TkLogCore.GetTotal($":total:{item.accountName}:放弃转链:{item.report_date:yyyyMMddHH}");
  369. if (item.total_count > 0)
  370. {
  371. item.success_percentage = $"{item.success_count / (double)item.total_count * 100:f2}%";
  372. item.abandon_percentage = $"{item.abandon_count / (double)item.total_count * 100:f2}%";
  373. }
  374. }
  375. if (item.parse_total_count == 0)
  376. {
  377. item.parse_total_count = TkLogCore.GetTotal($":parse_total:{accountName}:{item.report_date:yyyyMMddHH}");
  378. if (item.parse_total_count == 0) continue;
  379. item.parse_success_count = TkLogCore.GetTotal($":parse_total:{item.accountName}:success:{item.report_date:yyyyMMddHH}");
  380. item.parse_abandon_count = TkLogCore.GetTotal($":parse_total:{item.accountName}:放弃转链:{item.report_date:yyyyMMddHH}");
  381. if (item.parse_total_count > 0)
  382. {
  383. item.parse_success_percentage = $"{item.parse_success_count / (double)item.parse_total_count * 100:f2}%";
  384. item.parse_abandon_percentage = $"{item.parse_abandon_count / (double)item.parse_total_count * 100:f2}%";
  385. }
  386. }
  387. if (item.coupon_total_count == 0)
  388. {
  389. item.coupon_total_count = TkLogCore.GetTotal($":coupon_total:{accountName}:{item.report_date:yyyyMMddHH}");
  390. if (item.coupon_total_count == 0) continue;
  391. item.coupon_success_count = TkLogCore.GetTotal($":coupon_total:{item.accountName}:success:{item.report_date:yyyyMMddHH}");
  392. item.coupon_abandon_count = TkLogCore.GetTotal($":coupon_total:{item.accountName}:放弃转链:{item.report_date:yyyyMMddHH}");
  393. if (item.coupon_total_count > 0)
  394. {
  395. item.coupon_success_percentage = $"{item.coupon_success_count / (double)item.coupon_total_count * 100:f2}%";
  396. item.coupon_abandon_percentage = $"{item.coupon_abandon_count / (double)item.coupon_total_count * 100:f2}%";
  397. }
  398. }
  399. }
  400. return new APIResult(new { data = result });
  401. }
  402. [HttpPost]
  403. public ActionResult chartData([FromBody] JsonElement form)
  404. {
  405. var result = new List<dynamic>();
  406. var reason_result = new List<dynamic>();
  407. var report_date = form.PathReadArray<string>("query_date[]");
  408. var accountName = form.Read("accountName", string.Empty);
  409. var isHourtrend = form.Read<bool>("isLeaf", false);
  410. var total_key = form.Read("total_key", "total");
  411. if (string.IsNullOrEmpty(accountName)) accountName = "all";
  412. DateTime stime = DateTime.MinValue;
  413. if (!DateTime.TryParse(report_date[0], out stime)) return new APIResult(new { data = result, data2 = reason_result });
  414. string _report_date = stime.ToString("yyyyMMdd");
  415. if (isHourtrend) _report_date = stime.ToString("yyyyMMddHH");
  416. string cacheKey = $":{total_key}:{accountName}:{_report_date}";
  417. double total = TkLogCore.GetTotal(cacheKey);
  418. if (total > 0)
  419. {
  420. string[] keys = ["success"];
  421. cacheKey = $":{total_key}:{accountName}:message:{_report_date}";
  422. string[] message_keys = TkLogCore.GetTotalKeys(cacheKey);
  423. string[] combinedKeys = keys.Union(message_keys).ToArray();
  424. foreach (var keyname in combinedKeys)
  425. {
  426. cacheKey = $":{total_key}:{accountName}:{keyname}:{_report_date}";
  427. int value = TkLogCore.GetTotal(cacheKey);
  428. if (value == 0) continue;
  429. result.Add(new { name = keyname, value, increases = Math.Round(value / total * 100, 2) });
  430. }
  431. result = result.OrderByDescending(item => item.value).ToList();
  432. cacheKey = $":{total_key}:{accountName}:reason:{_report_date}";
  433. string[] reason_keys = TkLogCore.GetTotalKeys(cacheKey);
  434. foreach (var keyname in reason_keys)
  435. {
  436. cacheKey = $":{total_key}:{accountName}:{keyname}:{_report_date}";
  437. int value = TkLogCore.GetTotal(cacheKey);
  438. if (value == 0) continue;
  439. reason_result.Add(new { name = keyname, value, increases = Math.Round(value / total * 100, 2) });
  440. }
  441. reason_result = reason_result.OrderByDescending(item => item.value).ToList();
  442. }
  443. return new APIResult(new { total, data = result, data2 = reason_result });
  444. }
  445. [HttpPost]
  446. public ActionResult settle_bills_total([FromBody] JsonElement form)
  447. {
  448. int page = form.Read("current", 1);
  449. int size = form.Read("pageSize", 10);
  450. bool getTotal = form.Read("getTotal", true);
  451. string sort = form.Read<string>("sort");
  452. string order = form.Read<string>("order");
  453. var belongTime = form.PathReadArray<string>("query_date[]");
  454. string filter = string.Empty;
  455. DateTime stime = DateTime.MinValue, etime = DateTime.MinValue;
  456. if (belongTime.Count == 2)
  457. {
  458. if (DateTime.TryParse(belongTime[0], out stime) && DateTime.TryParse(belongTime[1], out etime))
  459. {
  460. etime = etime.AddDays(1).AddSeconds(-1);
  461. filter += $" AND belongTime BETWEEN @stime AND @etime";
  462. }
  463. }
  464. filter = filter.StringTrimStart(" AND ");
  465. //排序
  466. string orderBy = "belongTime DESC";
  467. if (!string.IsNullOrEmpty(order))
  468. {
  469. order = "descending".Equals(order) ? "DESC" : "ASC";
  470. orderBy = sort switch
  471. {
  472. _ => $"{sort} {order}",
  473. };
  474. }
  475. var result = new DBContext.Table("v_tk_report_bills")
  476. .Where(filter, new { stime, etime })
  477. .Page(size, page)
  478. .Order(orderBy)
  479. .PageList<TkSettleBillDTO>(getTotal);
  480. return new APIResult(new { data = result });
  481. }
  482. [HttpPost]
  483. public ActionResult settle_bills([FromBody] JsonElement form)
  484. {
  485. int page = form.Read("current", 1);
  486. int size = form.Read("pageSize", 10);
  487. bool getTotal = form.Read("getTotal", true);
  488. string sort = form.Read<string>("sort");
  489. string order = form.Read<string>("order");
  490. string name = form.Read<string>("keyword");
  491. var belongTime = form.PathReadArray<string>("query_date[]");
  492. string filter = string.Empty;
  493. if (!string.IsNullOrEmpty(name))
  494. {
  495. filter += $" AND accountId IN (SELECT ID FROM tk_pool WHERE company=@name)";
  496. }
  497. DateTime stime = DateTime.MinValue, etime = DateTime.MinValue;
  498. if (belongTime.Count == 2)
  499. {
  500. if (DateTime.TryParse(belongTime[0], out stime) && DateTime.TryParse(belongTime[1], out etime))
  501. {
  502. etime = etime.AddDays(1).AddSeconds(-1);
  503. filter += $" AND belongTime BETWEEN @stime AND @etime";
  504. }
  505. }
  506. filter = filter.StringTrimStart(" AND ");
  507. //排序
  508. string orderBy = "belongTime DESC";
  509. if (!string.IsNullOrEmpty(order))
  510. {
  511. order = "descending".Equals(order) ? "DESC" : "ASC";
  512. orderBy = sort switch
  513. {
  514. _ => $"{sort} {order}",
  515. };
  516. }
  517. var result = new DBContext.Table("tk_settle_bill")
  518. .Where(filter, new { name, stime, etime })
  519. .Page(size, page)
  520. .Order(orderBy)
  521. .PageList<TkSettleBillDTO>(getTotal);
  522. //foreach (var item in result.List)
  523. //{
  524. // if (string.IsNullOrEmpty(name))
  525. // {
  526. // item.accountName = "-";
  527. // }
  528. //}
  529. return new APIResult(new { data = result });
  530. }
  531. }
  532. }