orders.cs 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525
  1. using dodohold.core;
  2. using Spire.Pdf.Xmp;
  3. using System.Data;
  4. using System.Drawing.Printing;
  5. using System.Runtime.InteropServices;
  6. using System.Text.Json;
  7. using System.Text.RegularExpressions;
  8. using static System.Runtime.InteropServices.JavaScript.JSType;
  9. namespace molilian.core
  10. {
  11. public partial class AlimamaPlus
  12. {
  13. private const string base_orders_url = "https://pub.alimama.com/openapi/param2/1/gateway.unionpub/report.getTbkOrderDetails.json";
  14. public int GetHistoryOrders(int sleep, DateTime startTime, DateTime endTime)
  15. {
  16. //DateTime endTime = DateTime.Now;
  17. //DateTime startTime = endTime.AddDays(-90);
  18. //if (_accountId == 3) endTime = DateTime.Parse("2024-04-07");
  19. #if DEBUG
  20. startTime = DateTime.Parse("2024-05-01");
  21. endTime = DateTime.Parse("2024-06-01");
  22. int total = 0;
  23. List<DateTime> orderTimes = new List<DateTime>();
  24. for (DateTime date = startTime; date <= endTime; date = date.AddDays(1))
  25. {
  26. orderTimes.Add(date);
  27. }
  28. #else
  29. //当日往前查询
  30. (int total, DateTime max_modifiedTime, List<DateTime> orderTimes) = GetTkOrders(startTime, endTime, DateTime.MinValue, false, sleep);
  31. #endif
  32. string sql = @"
  33. UPDATE tk_report tr
  34. JOIN (
  35. SELECT
  36. accountId, DATE(tbPaidTime) AS date, SUM(alipayTotalPrice) AS order_ord_amt,
  37. COUNT(*) AS order_ord_num, SUM(pubShareFeeForCommission) AS order_ord_tfee
  38. FROM tk_order_details
  39. WHERE DATE(tbPaidTime) IN @orderTimes AND tkStatus=3 AND accountId=@accountId
  40. GROUP BY DATE(tbPaidTime), accountId
  41. ) AS sub
  42. ON tr.accountId = sub.accountId AND tr.report_date = sub.date
  43. SET tr.order_ord_amt = sub.order_ord_amt, tr.order_ord_num_3 = sub.order_ord_num,
  44. tr.order_ord_tfee = sub.order_ord_tfee;";
  45. DBContext.Execute(sql, new { accountId = _accountId, orderTimes });
  46. sql = @"
  47. UPDATE tk_report tr
  48. JOIN (
  49. SELECT
  50. accountId, DATE(tbPaidTime) AS date, SUM(alipayTotalPrice) AS order_ord_amt,
  51. COUNT(*) AS order_ord_num, SUM(pubSharePreFeeForCommission) AS order_ord_tfee
  52. FROM tk_order_details
  53. WHERE DATE(tbPaidTime) IN @orderTimes AND tkStatus=12 AND accountId=@accountId
  54. GROUP BY DATE(tbPaidTime), accountId
  55. ) AS sub
  56. ON tr.accountId = sub.accountId AND tr.report_date = sub.date
  57. SET tr.order_ord_amt_12 = sub.order_ord_amt, tr.order_ord_num_12 = sub.order_ord_num,
  58. tr.order_ord_tfee_12 = sub.order_ord_tfee;";
  59. DBContext.Execute(sql, new { accountId = _accountId, orderTimes });
  60. sql = @"
  61. UPDATE tk_report tr
  62. JOIN (
  63. SELECT
  64. accountId, DATE(tbPaidTime) AS date, SUM(alipayTotalPrice) AS order_ord_amt,
  65. COUNT(*) AS order_ord_num, SUM(pubSharePreFeeForCommission) AS order_ord_tfee
  66. FROM tk_order_details
  67. WHERE DATE(tbPaidTime) IN @orderTimes AND tkStatus=13 AND accountId=@accountId
  68. GROUP BY DATE(tbPaidTime), accountId
  69. ) AS sub
  70. ON tr.accountId = sub.accountId AND tr.report_date = sub.date
  71. SET tr.order_ord_amt_13 = sub.order_ord_amt, tr.order_ord_num_13 = sub.order_ord_num,
  72. tr.order_ord_tfee_13 = sub.order_ord_tfee;";
  73. DBContext.Execute(sql, new { accountId = _accountId, orderTimes });
  74. sql = @"
  75. UPDATE tk_report tr
  76. JOIN (
  77. SELECT
  78. accountId, DATE(tbPaidTime) AS date, SUM(alipayTotalPrice) AS order_ord_amt,
  79. COUNT(*) AS order_ord_num, SUM(pubSharePreFeeForCommission) AS order_ord_tfee
  80. FROM tk_order_details
  81. WHERE DATE(tbPaidTime) IN @orderTimes AND tkStatus=14 AND accountId=@accountId
  82. GROUP BY DATE(tbPaidTime), accountId
  83. ) AS sub
  84. ON tr.accountId = sub.accountId AND tr.report_date = sub.date
  85. SET tr.order_ord_amt_14 = sub.order_ord_amt, tr.order_ord_num_14 = sub.order_ord_num,
  86. tr.order_ord_tfee_14 = sub.order_ord_tfee;";
  87. DBContext.Execute(sql, new { accountId = _accountId, orderTimes });
  88. sql = @"UPDATE tk_report
  89. SET order_ord_num = order_ord_num_3 + order_ord_num_12 + order_ord_num_13 + order_ord_num_14
  90. WHERE DATE(report_date) IN @orderTimes AND accountId=@accountId;";
  91. DBContext.Execute(sql, new { accountId = _accountId, orderTimes });
  92. return total;
  93. }
  94. public int GetIncyOrders(int sleep)
  95. {
  96. string cacheKey = $":cache:GetIncyOrders:{_accountName}";
  97. string cacheKey2 = $":cache:GetIncyOrders:{_accountId}";
  98. DateTime endTime = DateTime.Now;
  99. DateTime startTime = endTime.AddDays(-1);
  100. DateTime last_modifiedTime = RedisHelper.Get<DateTime>(cacheKey);
  101. ////找出数据库最新的一天
  102. //var last = new DBContext.Table("tk_order_details")
  103. // .Order("modifiedTime DESC")
  104. // .Get<TkOrderDetailDTO>("accountId=@accountId", new { accountId = _accountId });
  105. if (last_modifiedTime != DateTime.MinValue)
  106. {
  107. startTime = last_modifiedTime;
  108. }
  109. else
  110. {
  111. last_modifiedTime = startTime;
  112. }
  113. //当日往前查询
  114. (int total, DateTime max_modifiedTime, List<DateTime> orderTimes) = GetTkOrders(startTime, endTime, last_modifiedTime, true, sleep);
  115. if (max_modifiedTime != DateTime.MinValue)
  116. {
  117. RedisHelper.Set(cacheKey, max_modifiedTime);
  118. RedisHelper.Set(cacheKey2, max_modifiedTime);
  119. }
  120. //todo 根据orderTimes、settlementTimes 更新被影响的相关行
  121. string sql = @"
  122. UPDATE tk_report tr
  123. JOIN (
  124. SELECT
  125. accountId, DATE(tbPaidTime) AS date, SUM(alipayTotalPrice) AS order_ord_amt,
  126. COUNT(*) AS order_ord_num, SUM(pubShareFeeForCommission) AS order_ord_tfee
  127. FROM tk_order_details
  128. WHERE DATE(tbPaidTime) IN @orderTimes AND tkStatus=3 AND accountId=@accountId
  129. GROUP BY DATE(tbPaidTime), accountId
  130. ) AS sub
  131. ON tr.accountId = sub.accountId AND tr.report_date = sub.date
  132. SET tr.order_ord_amt = sub.order_ord_amt, tr.order_ord_num_3 = sub.order_ord_num,
  133. tr.order_ord_tfee = sub.order_ord_tfee;";
  134. DBContext.Execute(sql, new { accountId = _accountId, orderTimes });
  135. sql = @"
  136. UPDATE tk_report tr
  137. JOIN (
  138. SELECT
  139. accountId, DATE(tbPaidTime) AS date, SUM(alipayTotalPrice) AS order_ord_amt,
  140. COUNT(*) AS order_ord_num, SUM(pubSharePreFeeForCommission) AS order_ord_tfee
  141. FROM tk_order_details
  142. WHERE DATE(tbPaidTime) IN @orderTimes AND tkStatus=12 AND accountId=@accountId
  143. GROUP BY DATE(tbPaidTime), accountId
  144. ) AS sub
  145. ON tr.accountId = sub.accountId AND tr.report_date = sub.date
  146. SET tr.order_ord_amt_12 = sub.order_ord_amt, tr.order_ord_num_12 = sub.order_ord_num,
  147. tr.order_ord_tfee_12 = sub.order_ord_tfee;";
  148. DBContext.Execute(sql, new { accountId = _accountId, orderTimes });
  149. sql = @"
  150. UPDATE tk_report tr
  151. JOIN (
  152. SELECT
  153. accountId, DATE(tbPaidTime) AS date, SUM(alipayTotalPrice) AS order_ord_amt,
  154. COUNT(*) AS order_ord_num, SUM(pubSharePreFeeForCommission) AS order_ord_tfee
  155. FROM tk_order_details
  156. WHERE DATE(tbPaidTime) IN @orderTimes AND tkStatus=13 AND accountId=@accountId
  157. GROUP BY DATE(tbPaidTime), accountId
  158. ) AS sub
  159. ON tr.accountId = sub.accountId AND tr.report_date = sub.date
  160. SET tr.order_ord_amt_13 = sub.order_ord_amt, tr.order_ord_num_13 = sub.order_ord_num,
  161. tr.order_ord_tfee_13 = sub.order_ord_tfee;";
  162. DBContext.Execute(sql, new { accountId = _accountId, orderTimes });
  163. sql = @"
  164. UPDATE tk_report tr
  165. JOIN (
  166. SELECT
  167. accountId, DATE(tbPaidTime) AS date, SUM(alipayTotalPrice) AS order_ord_amt,
  168. COUNT(*) AS order_ord_num, SUM(pubSharePreFeeForCommission) AS order_ord_tfee
  169. FROM tk_order_details
  170. WHERE DATE(tbPaidTime) IN @orderTimes AND tkStatus=14 AND accountId=@accountId
  171. GROUP BY DATE(tbPaidTime), accountId
  172. ) AS sub
  173. ON tr.accountId = sub.accountId AND tr.report_date = sub.date
  174. SET tr.order_ord_amt_14 = sub.order_ord_amt, tr.order_ord_num_14 = sub.order_ord_num,
  175. tr.order_ord_tfee_14 = sub.order_ord_tfee;";
  176. DBContext.Execute(sql, new { accountId = _accountId, orderTimes });
  177. sql = @"UPDATE tk_report
  178. SET order_ord_num = order_ord_num_3 + order_ord_num_12 + order_ord_num_13 + order_ord_num_14
  179. WHERE DATE(report_date) IN @orderTimes AND accountId=@accountId;";
  180. DBContext.Execute(sql, new { accountId = _accountId, orderTimes });
  181. return total;
  182. }
  183. public (int, DateTime, List<DateTime>) GetTkOrders(DateTime startTime, DateTime endTime, DateTime last_modifiedTime, bool desc = true, int sleep = 100)
  184. {
  185. List<DateTime> orderTimes = [];
  186. // 确保 startTime 小于 endTime
  187. if (startTime > endTime)
  188. {
  189. (startTime, endTime) = (endTime, startTime);
  190. }
  191. DateTime max_modifiedTime = last_modifiedTime;
  192. int pageNo = 1;
  193. string positionIndex = string.Empty;
  194. int pageSize = 100;
  195. bool hasNext = true;
  196. int total = 0;
  197. while (hasNext)
  198. {
  199. var ts = DateTime.Now.Convert2UnixTimestamp(true);
  200. //string jumpType = desc ? pageNo == 1 ? "0" : "1" : "-1";
  201. string jumpType = pageNo == 1 ? "0" : "1";
  202. #if DEBUG
  203. jumpType = pageNo == 1 ? "0" : "1";
  204. #endif
  205. //string queryType = "1";
  206. //1 创建时间;3结算时间 2付款时间 4更新时间
  207. //string queryType = "2";
  208. string queryType = desc ? "4" : "2";
  209. string url = $"{base_orders_url}?t={ts}&_tb_token_={_tb_token}&pageNo={pageNo}&pageSize={pageSize}&startTime={startTime:yyyy-MM-dd}&endTime={endTime:yyyy-MM-dd}&payStatus=&queryType={queryType}&jumpType={jumpType}&tkTradeId=&positionIndex={positionIndex.UrlEncode()}";
  210. //https://pub.alimama.com/openapi/param2/1/gateway.unionpub/report.getTbkOrderDetails.json?t=1719477837298&_tb_token_=7537e7ed93338&pageNo=92&pageSize=20&startTime=2024-03-31&endTime=2024-03-31&payStatus=&queryType=2&jumpType=1&tkTradeId=&positionIndex=1711883373_2vtPPr7CyYX2%7C1711883522_4zcICUeUevh2
  211. //https://pub.alimama.com/openapi/param2/1/gateway.unionpub/report.getTbkOrderDetails.json?t=1719477942492&_tb_token_=7537e7ed93338&pageNo=7&pageSize=20&startTime=2024-03-31&endTime=2024-03-31&payStatus=&queryType=2&jumpType=1&tkTradeId=&positionIndex=1711899163_4zdpOH1mbTQ2%7C1711899483_4zbH9BHqgl82
  212. string body = "";
  213. JsonElement data;
  214. try
  215. {
  216. for (var i = 1; i <= 5; i++)
  217. {
  218. var client = new WebClientUtility().SetContentType("application/json;charset=utf-8")
  219. .AddHeaders("X-Requested-With", "XMLHttpRequest")
  220. .AddHeaders("Cookie", _cookies);
  221. #if DEBUG
  222. #else
  223. client.Proxy = _proxy;
  224. #endif
  225. if (!string.IsNullOrEmpty(_user_agent)) client.UserAgent = _user_agent;
  226. var response = client.Request(url);
  227. if (response.ResponseException != null)
  228. {
  229. _ = new LoggerLibrary("api_error", "fail")
  230. .Info(response.ResponseException.Message, response.ResponseException.StackTrace)
  231. .SaveAsync();
  232. throw response.ResponseException;
  233. }
  234. body = response.Body();
  235. #if DEBUG
  236. _ = new LoggerLibrary("debug", "GetTkOrders")
  237. .Info(body)
  238. .SaveAsync();
  239. #endif
  240. if (body.Contains("{\"action\":\"captcha\""))
  241. {
  242. string message = $"【GetTkOrders】【{_accountId}:{_accountName}】第 {i} 次出现滑动验证码";
  243. NotifyCore.Notify(new NifyMessage
  244. {
  245. message = message,
  246. priority = NifyMessagePriority.high,
  247. tags = ["red_circle"]
  248. });
  249. Thread.Sleep(i * 60 * 1000);
  250. continue;
  251. }
  252. if (body.Contains("\"resultCode\":500"))
  253. {
  254. //{"success":false,"resultCode":500,"bizErrorDesc":"系统繁忙,请稍后重试!","bizErrorCode":3001}
  255. string message = $"【GetTkOrders】【{_accountId}:{_accountName}】第 {i} 次出现错误\n{body}";
  256. NotifyCore.Notify(new NifyMessage
  257. {
  258. message = message,
  259. priority = NifyMessagePriority.high,
  260. tags = ["red_circle"]
  261. });
  262. Thread.Sleep(i * 60 * 1000);
  263. continue;
  264. }
  265. break;
  266. }
  267. /*
  268. <script>sessionStorage.x5referer = window.location.href;var url = window.location.protocol + "//pub.alimama.com//openapi/param2/1/gateway.unionpub/report.getTbkOrderDetails.json/_____tmd_____/punish?x5secdata=xc1iwR0XfHknuQ2tGhtadtTAvEt14YScfTDHt2ZiSRqroaYZK98uykgsVOy7o75Rw8uuycKT3Rpx30%2fB5H0gRc0%2fJVGQUcV5g%2fsAmZ%2bc46eyD7DXSdA4R3mLnmtbp9wuZ1vmrG3ZPlH7brUilFbXBdZ7EBrru1X7wPfC05Eq3g4mhDFiGq39xUtwQcC%2f%2bPbtekcm8%2fVJ%2brVt8aExunwzXzJPJJTAvEt14YScfTDHt2ZiSRqroaYZK98uykgsiXIkw%2ffMWwebJ3zxCja5CzSu%2ffTA%3d%3d__bx__pub.alimama.com%2fopenapi%2fparam2%2f1%2fgateway.unionpub%2freport.getTbkOrderDetails.json&x5step=1";window.location.replace(url);window._config_ = {"action":"captcha","url":"https://pub.alimama.com//openapi/param2/1/gateway.unionpub/report.getTbkOrderDetails.json/_____tmd_____/punish?x5secdata=xc1iwR0XfHknuQ2tGhtadtTAvEt14YScfTDHt2ZiSRqroaYZK98uykgsVOy7o75Rw8uuycKT3Rpx30%2fB5H0gRc0%2fJVGQUcV5g%2fsAmZ%2bc46eyD7DXSdA4R3mLnmtbp9wuZ1vmrG3ZPlH7brUilFbXBdZ7EBrru1X7wPfC05Eq3g4mhDFiGq39xUtwQcC%2f%2bPbtekcm8%2fVJ%2brVt8aExunwzXzJPJJTAvEt14YScfTDHt2ZiSRqroaYZK98uykgsiXIkw%2ffMWwebJ3zxCja5CzSu%2ffTA%3d%3d__bx__pub.alimama.com%2fopenapi%2fparam2%2f1%2fgateway.unionpub%2freport.getTbkOrderDetails.json&x5step=1"};</script><!--rgv587_flag:sm--> */
  269. var root = body.Convert2JsonElement();
  270. var success = root.Read<bool>("success");
  271. data = root.ElementRead("data");
  272. //{"code":601,"info":{"ok":false,"message":"nologin"}}
  273. if (!success && body.Contains("nologin"))
  274. {
  275. (success, string message) = RenewCookie();
  276. if (!success)
  277. {
  278. TkPoolCore.Disabled(_accountId, _accountName, $"{body}");
  279. }
  280. return (0, DateTime.MinValue, new List<DateTime>());
  281. }
  282. if (!success)
  283. {
  284. throw new APIException(body);
  285. }
  286. }
  287. catch (Exception ex)
  288. {
  289. throw new APIException(body);
  290. }
  291. using var conn = DBContext.GetOpenConnection();
  292. conn.Open();
  293. try
  294. {
  295. foreach (var order in data.ElementRead("result").EnumerateArray())
  296. {
  297. TkOrderDetailDTO item = order.GetRawText().Convert2Object<TkOrderDetailDTO>();
  298. // 处理每个订单数据
  299. item.accountId = _accountId;
  300. item.accountName = _company;
  301. if (item.modifiedTime > max_modifiedTime) max_modifiedTime = item.modifiedTime;
  302. if (last_modifiedTime != DateTime.MinValue && last_modifiedTime >= item.modifiedTime)
  303. {
  304. return (total, max_modifiedTime, orderTimes);
  305. }
  306. //进行订单和转链匹配
  307. item.itemId = GetRawItemId(item.mktId);
  308. if (item.tkStatus == 3 && item.tbPaidTime != DateTime.MinValue) orderTimes.Add(item.tbPaidTime.Date);
  309. int? id = conn.Replace(item);
  310. if (id != null)
  311. {
  312. item.id = (int)id;
  313. TkOrderTrackingCore.MatchOrder(_account, item, conn);
  314. }
  315. total++;
  316. }
  317. }
  318. catch (Exception ex)
  319. {
  320. throw;
  321. }
  322. finally
  323. {
  324. conn.Dispose();
  325. }
  326. pageNo++;
  327. hasNext = data.Read<bool>("hasNext");
  328. positionIndex = data.Read<string>("positionIndex");
  329. if (sleep > 0) Thread.Sleep(sleep);
  330. }
  331. return (total, max_modifiedTime, orderTimes);
  332. }
  333. string GetRawItemId(string mktId)
  334. {
  335. try
  336. {
  337. string cacheKey = $":cache:mkt2itemId:{mktId}";
  338. string itemId = RedisHelper.Get(cacheKey);
  339. if (itemId != null) return itemId;
  340. var ts = DateTime.Now.Convert2UnixTimestamp(true);
  341. string url = "https://pub.alimama.com/openapi/param2/1/gateway.unionpub/union.moose.content.entry";
  342. //string url = $"{base_orders_url}?t={ts}&_tb_token_={_tb_token}&pageNo={pageNo}&pageSize={pageSize}&startTime={startTime:yyyy-MM-dd}&endTime={endTime:yyyy-MM-dd}&payStatus=&queryType={queryType}&jumpType={jumpType}&tkTradeId=&positionIndex={positionIndex}";
  343. var client = new WebClientUtility()
  344. .SetContentType("application/x-www-form-urlencoded")
  345. .AddHeaders("Cookie", _cookies)
  346. .AddHeaders("Origin", "https://pub.alimama.com")
  347. .Post("_tb_token_", _tb_token)
  348. .Post("t", ts.ToString())
  349. .Post("bizType", "detailPage")
  350. .Post("bizParam", $"{{\"itemId\":\"{mktId}\"}}");
  351. //_tb_token_=3b88755bbe3f7&t=1718896771391&bizType=detailPage&bizParam=%7B%22itemId%22%3A%22JbtMUqkGMQvagTNb2Fvta-9ag242pu7MOX5e0bsrY%22%7D
  352. //_tb_token_=361e383eb61e5&t=1718895935097&bizType=detailPage&bizParam=%7B%22itemId%22%3A%22JbtMUqkGMQvagTNb2Fvta-9ag242pu7MOX5e0bsrY%22%7D
  353. #if DEBUG
  354. #else
  355. client.Proxy = _proxy;
  356. #endif
  357. if (!string.IsNullOrEmpty(_user_agent)) client.UserAgent = _user_agent;
  358. var response = client.Request(url);
  359. if (!response.Successed)
  360. {
  361. throw response.ResponseException;
  362. }
  363. var body = response.Body();
  364. var root = body.Convert2JsonElement();
  365. itemId = root.PathRead<string>("model.item.itemId");
  366. if (!string.IsNullOrEmpty(itemId))
  367. {
  368. RedisHelper.Set(cacheKey, itemId, 86400 * 7);
  369. }
  370. return itemId;
  371. }
  372. catch (Exception ex)
  373. {
  374. string message = $"【GetRawItemId】[{mktId}\n{ex.Message}\n{ex.StackTrace}";
  375. NotifyCore.Notify(new NifyMessage
  376. {
  377. message = message,
  378. priority = NifyMessagePriority.high,
  379. tags = ["red_circle"]
  380. });
  381. }
  382. return null;
  383. }
  384. public void GetTkOrders222()
  385. {
  386. try
  387. {
  388. string url = "https://media.alimama.com/violationu2/warning_instance_page_v2.json?r=mx_208&toPage=1&pageSize=40&params=";
  389. var client = new WebClientUtility().SetContentType("application/json;charset=utf-8")
  390. .AddHeaders("X-Requested-With", "XMLHttpRequest")
  391. .AddHeaders("Cookie", _cookies);
  392. client.Proxy = _proxy;
  393. if (!string.IsNullOrEmpty(_user_agent)) client.UserAgent = _user_agent;
  394. var response = client.Request(url);
  395. var body = response.Body();
  396. var root = body.Convert2JsonElement();
  397. int resultCode = root.Read<int>("resultCode", 0);
  398. int totalCount = root.PathRead<int>("data.totalCount", 0);
  399. bool success = root.Read("success", false);
  400. if (!success)
  401. {
  402. _ = new LoggerLibrary("violationu", "warning_error")
  403. .Info(url, body)
  404. .SaveAsync();
  405. throw new Exception(body);
  406. }
  407. if (totalCount == 0) return;
  408. _ = new LoggerLibrary("violationu", "warning").Info(url, body).SaveAsync();
  409. var list = root.ElementRead("data").ElementRead("result").EnumerateArray();
  410. foreach (var data in list)
  411. {
  412. var violation_commission = data.PathRead<decimal>("mediaInfo.订单虚假交易违规佣金", 0);
  413. new DBContext.Table("alimama_warning")
  414. .Fill(data)
  415. .Loader<int>("filterRuleId", 0)
  416. .Loader<long>("gmtCreate", 0)
  417. .Loader<long>("id", 0, "ali_id")
  418. .Loader<string>("idStr", string.Empty)
  419. .Loader<int>("mediaDimension", 0)
  420. .Loader<long>("mediaId", 0)
  421. .Loader<int>("mediaInfo.abn_cnt", 0, "abn_cnt")
  422. .Add("violation_commission", violation_commission)
  423. .Loader<int>("mediaInfo.warning_cnt", 0, "warning_cnt")
  424. .Loader<string>("mediaName", string.Empty)
  425. .Loader<long>("memberId", 0)
  426. .Loader<string>("noticeCategory", string.Empty)
  427. .Loader<int>("noticeTemplateId", 0)
  428. .Loader<string>("noticeTemplateName", string.Empty)
  429. .Loader<string>("orderFile", string.Empty)
  430. .Loader<string>("pid", string.Empty)
  431. .Loader<int>("punishRuleId", 0)
  432. .Loader<string>("riskType", string.Empty)
  433. .Loader<string>("roleName", string.Empty)
  434. .Loader<string>("ruleLink", string.Empty)
  435. .Loader<bool>("showOrderDetail", false)
  436. .Loader<int>("status", 0, "ali_status")
  437. .Loader<string>("warningText", string.Empty)
  438. .Add("accountName", _accountName)
  439. .Add("status", true)
  440. .Add("create_time", DateTime.Now)
  441. .Add("last_time", DateTime.Now)
  442. .Create(DBContext.InsertType.REPLACE);
  443. }
  444. }
  445. catch (Exception ex) { }
  446. }
  447. }
  448. }