PrizeDo.cs 94 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704
  1. using System.Data;
  2. using Common;
  3. using Infrastructure;
  4. using LitJson;
  5. using Microsoft.Extensions.Localization;
  6. using Model;
  7. using Model.Customer;
  8. using NuGet.Packaging;
  9. using Services;
  10. using System.Linq;
  11. using System.Net.Mime;
  12. namespace Util
  13. {
  14. public class PrizeDo
  15. {
  16. public static string batchNo = "";
  17. //发奖入口
  18. public static void sendPrize(int prizeInId, string content)
  19. {
  20. batchNo = DateTime.Now.ToString("yyyyMMddHHmmssfff") + Function.get_Random(3);
  21. string priObjString = prizeInSet(prizeInId);
  22. if(!string.IsNullOrEmpty(priObjString))
  23. {
  24. string[] priObjData = priObjString.Split('|');
  25. string priListIds = priObjData[0];
  26. int projectId = int.Parse(priObjData[1]);
  27. addLog(projectId, prizeInId, content); //初始化日志
  28. prizeSend(projectId, priListIds, content);
  29. }
  30. }
  31. //接收入参
  32. public static Dictionary<string, string> getRequestParams(int projectId, string content)
  33. {
  34. Dictionary<string, string> dic = new Dictionary<string, string>();
  35. JsonData jsonData = JsonMapper.ToObject(content);
  36. var paramService = App.GetService<IPriProjectParamService>();
  37. var paramList = paramService.GetList(m => m.projectId == projectId);
  38. foreach(var param in paramList)
  39. {
  40. if(content.Contains("\"" + param.fieldEnName + "\"")) dic.Add(param.fieldEnName, jsonData[param.fieldEnName].ToString());
  41. }
  42. return dic;
  43. }
  44. //数据库链接
  45. public static SqlSugarClient initDb(int id)
  46. {
  47. var databaseSetService = App.GetService<IPriDatabaseSetService>();
  48. var connectionString = databaseSetService.GetFirst(m => m.id == id);
  49. string server = connectionString.ipAddress;
  50. int port = connectionString.port;
  51. string user = connectionString.userId;
  52. string password = connectionString.password;
  53. string database = connectionString.databaseName;
  54. var db = new SqlSugarClient(new ConnectionConfig()
  55. {
  56. ConnectionString = "server=" + server + ";port=" + port + ";user=" + user + ";password=" + password + ";database=" + database + ";charset=utf8;",
  57. DbType = SqlSugar.DbType.MySql,
  58. IsAutoCloseConnection = true,
  59. });
  60. return db;
  61. }
  62. //查询条件匹配数据
  63. public static List<QueryCondition> condition(int projectId, List<int> ids, string content)
  64. {
  65. List<QueryCondition> dic = new List<QueryCondition>();
  66. var queryTableService = App.GetService<IPriQueryTableService>();
  67. var queryFieldService = App.GetService<IPriQueryFieldService>();
  68. var returnFieldService = App.GetService<IPriReturnFieldService>();
  69. //查询表
  70. var queryTables = queryTableService.GetList(m => ids.Contains(m.id));
  71. foreach(var queryTable in queryTables)
  72. {
  73. //查询返回字段
  74. string fields = "";
  75. Dictionary<string, string> fieldDic = new Dictionary<string, string>();
  76. var returnFields = returnFieldService.GetList(m => m.queryTableId == queryTable.id);
  77. foreach(var returnField in returnFields)
  78. {
  79. if(returnField.fieldReturnKind == "2")
  80. {
  81. fields += "count(" + returnField.fieldEnName + ") " + queryTable.tableEnName + "_" + returnField.fieldEnName + ",";
  82. }
  83. else if(returnField.fieldReturnKind == "3")
  84. {
  85. fields += "sum(" + returnField.fieldEnName + ") " + queryTable.tableEnName + "_" + returnField.fieldEnName + ",";
  86. }
  87. else if(returnField.fieldReturnKind == "4")
  88. {
  89. fields += "avg(" + returnField.fieldEnName + ") " + queryTable.tableEnName + "_" + returnField.fieldEnName + ",";
  90. }
  91. else
  92. {
  93. fields += returnField.fieldEnName + " " + queryTable.tableEnName + "_" + returnField.fieldEnName + ",";
  94. }
  95. fieldDic.Add(queryTable.tableEnName + "_" + returnField.fieldEnName, returnField.fieldName);
  96. }
  97. fields = fields.TrimEnd(',');
  98. //查询匹配条件
  99. string condi = "";
  100. var queryFields = queryFieldService.GetList(m => m.queryTableId == queryTable.id);
  101. foreach(var queryField in queryFields)
  102. {
  103. string fieldEnName = queryField.fieldEnName;
  104. string fieldQueryKind = queryField.fieldQueryKind;
  105. string fieldQueryModel = queryField.fieldQueryModel;
  106. string fieldQueryValue = queryField.fieldQueryValue;
  107. string fieldQueryValueType = queryField.fieldQueryValueType;
  108. if(fieldQueryKind == "1") //模糊匹配
  109. {
  110. condi += " and " + fieldEnName + " like ";
  111. if(fieldQueryModel == "request_param")
  112. {
  113. Dictionary<string, string> req = getRequestParams(projectId, content);
  114. string val = req.ContainsKey(fieldQueryValue) ? req[fieldQueryValue] : "0";
  115. condi += "'%" + val + "%'";
  116. }
  117. else if(fieldQueryModel == "fixed_value")
  118. {
  119. condi += "'%" + GetExpressionVal(fieldQueryValue) + "%'";
  120. }
  121. else if(fieldQueryModel == "db_field")
  122. {
  123. condi += "'%" + GetDbExpressionVal(fieldQueryValue) + "%'";
  124. }
  125. else if(fieldQueryModel == "query_field")
  126. {
  127. string val = GetQueryTableData(dic, fieldQueryValue);
  128. condi += "'%" + val + "%'";
  129. }
  130. }
  131. else if(fieldQueryKind == "2") //精确匹配
  132. {
  133. if(fieldQueryValue == "null" && fieldQueryValueType == "text") condi += " and " + fieldEnName + " is null";
  134. else
  135. {
  136. condi += " and " + fieldEnName + "=";
  137. string val = "";
  138. if(fieldQueryModel == "request_param")
  139. {
  140. Dictionary<string, string> req = getRequestParams(projectId, content);
  141. val = req.ContainsKey(fieldQueryValue) ? req[fieldQueryValue] : "0";
  142. }
  143. else if(fieldQueryModel == "fixed_value")
  144. {
  145. val = GetExpressionVal(fieldQueryValue);
  146. }
  147. else if(fieldQueryModel == "db_field")
  148. {
  149. val = GetDbExpressionVal(fieldQueryValue);
  150. }
  151. else if(fieldQueryModel == "query_field")
  152. {
  153. val = GetQueryTableData(dic, fieldQueryValue);
  154. }
  155. if(fieldQueryValueType == "text")
  156. {
  157. val = "'" + val + "'";
  158. }
  159. condi += val;
  160. }
  161. }
  162. else if(fieldQueryKind == "5" || fieldQueryKind == "6") //数组匹配/排除
  163. {
  164. if(fieldQueryKind == "5") condi += " and " + fieldEnName + " in (";
  165. else if(fieldQueryKind == "6") condi += " and " + fieldEnName + " not in (";
  166. string val = "";
  167. string[] valList = fieldQueryValue.Split(',');
  168. if(fieldQueryModel == "request_param")
  169. {
  170. Dictionary<string, string> req = getRequestParams(projectId, content);
  171. foreach(string sub in valList)
  172. {
  173. if(fieldQueryValueType == "text")
  174. {
  175. val += "'" + req[sub] + "',";
  176. }
  177. else
  178. {
  179. val += req[sub] + ",";
  180. }
  181. }
  182. }
  183. else if(fieldQueryModel == "fixed_value")
  184. {
  185. foreach(string sub in valList)
  186. {
  187. if(fieldQueryValueType == "text")
  188. {
  189. val += "'" + GetExpressionVal(sub) + "',";
  190. }
  191. else
  192. {
  193. val += GetExpressionVal(sub) + ",";
  194. }
  195. }
  196. }
  197. else if(fieldQueryModel == "db_field")
  198. {
  199. foreach(string sub in valList)
  200. {
  201. if(fieldQueryValueType == "text")
  202. {
  203. val += "'" + GetDbExpressionVal(sub) + "',";
  204. }
  205. else
  206. {
  207. val += GetDbExpressionVal(sub) + ",";
  208. }
  209. }
  210. }
  211. else if(fieldQueryModel == "query_field")
  212. {
  213. foreach(string sub in valList)
  214. {
  215. string dicVal = GetQueryTableData(dic, sub);
  216. if(fieldQueryValueType == "text")
  217. {
  218. val += "'" + dicVal + "',";
  219. }
  220. else
  221. {
  222. val += dicVal + ",";
  223. }
  224. }
  225. }
  226. val = val.TrimEnd(',');
  227. condi += val + ")";
  228. }
  229. else if(fieldQueryKind == "3") //范围匹配
  230. {
  231. string[] val = fieldQueryValue.Split(':');
  232. if(fieldQueryModel == "request_param")
  233. {
  234. Dictionary<string, string> req = getRequestParams(projectId, content);
  235. if(fieldQueryValueType == "number")
  236. {
  237. if(!string.IsNullOrEmpty(req[val[0]])) condi += " and " + fieldEnName + ">=" + req[val[0]];
  238. if(!string.IsNullOrEmpty(req[val[1]])) condi += " and " + fieldEnName + "<=" + req[val[1]];
  239. }
  240. else
  241. {
  242. if(!string.IsNullOrEmpty(req[val[0]])) condi += " and " + fieldEnName + ">='" + req[val[0]] + "'";
  243. if(!string.IsNullOrEmpty(req[val[1]])) condi += " and " + fieldEnName + "<='" + req[val[1]] + "'";
  244. }
  245. }
  246. else if(fieldQueryModel == "fixed_value")
  247. {
  248. if(fieldQueryValueType == "number")
  249. {
  250. if(!string.IsNullOrEmpty(val[0])) condi += " and " + fieldEnName + ">=" + val[0];
  251. if(!string.IsNullOrEmpty(val[1])) condi += " and " + fieldEnName + "<=" + val[1];
  252. }
  253. else
  254. {
  255. if(!string.IsNullOrEmpty(val[0])) condi += " and " + fieldEnName + ">='" + GetExpressionVal(val[0]) + "'";
  256. if(!string.IsNullOrEmpty(val[1])) condi += " and " + fieldEnName + "<='" + GetExpressionVal(val[1]) + "'";
  257. }
  258. }
  259. else if(fieldQueryModel == "db_field")
  260. {
  261. if(!string.IsNullOrEmpty(val[0])) condi += " and " + fieldEnName + ">=" + GetDbExpressionVal(val[0]);
  262. if(!string.IsNullOrEmpty(val[1])) condi += " and " + fieldEnName + "<=" + GetDbExpressionVal(val[1]);
  263. }
  264. else if(fieldQueryModel == "query_field")
  265. {
  266. string valLeft = val[0];
  267. string valRight = val[1];
  268. string dicValLeft = GetQueryTableData(dic, valLeft);
  269. string dicValRight = GetQueryTableData(dic, valRight);
  270. if(fieldQueryValueType == "number")
  271. {
  272. if(!string.IsNullOrEmpty(dicValLeft)) condi += " and " + fieldEnName + ">=" + dicValLeft;
  273. if(!string.IsNullOrEmpty(dicValRight)) condi += " and " + fieldEnName + "<=" + dicValRight;
  274. }
  275. else
  276. {
  277. if(!string.IsNullOrEmpty(dicValLeft)) condi += " and " + fieldEnName + ">='" + GetExpressionVal(dicValLeft) + "'";
  278. if(!string.IsNullOrEmpty(dicValRight)) condi += " and " + fieldEnName + "<='" + GetExpressionVal(dicValRight) + "'";
  279. }
  280. }
  281. }
  282. else if(fieldQueryKind == "4") //取反匹配
  283. {
  284. if(fieldQueryValue == "null" && fieldQueryValueType == "text") condi += " and " + fieldEnName + " is not null";
  285. else
  286. {
  287. condi += " and " + fieldEnName + "!=";
  288. string val = "";
  289. if(fieldQueryModel == "request_param")
  290. {
  291. Dictionary<string, string> req = getRequestParams(projectId, content);
  292. val = req.ContainsKey(fieldQueryValue) ? req[fieldQueryValue] : "0";
  293. }
  294. else if(fieldQueryModel == "fixed_value")
  295. {
  296. val = GetExpressionVal(fieldQueryValue);
  297. }
  298. else if(fieldQueryModel == "db_field")
  299. {
  300. val = GetDbExpressionVal(fieldQueryValue);
  301. }
  302. else if(fieldQueryModel == "query_field")
  303. {
  304. val = GetQueryTableData(dic, fieldQueryValue);
  305. }
  306. if(fieldQueryValueType == "text")
  307. {
  308. val = "'" + val + "'";
  309. }
  310. condi += val;
  311. }
  312. }
  313. }
  314. var db = initDb(queryTable.databaseId);
  315. string sql = "select " + fields + " from " + queryTable.tableEnName + " where 1=1" + condi;
  316. var items = db.Ado.GetDataTable(sql);
  317. if(items.Rows.Count > 0)
  318. {
  319. foreach(string field in fieldDic.Keys)
  320. {
  321. if(!dic.Any(m => m.FieldEnName == field)) dic.Add(new QueryCondition()
  322. {
  323. FieldName = fieldDic[field],
  324. FieldEnName = field,
  325. Value = items.Rows[0][field].ToString()
  326. });
  327. }
  328. }
  329. }
  330. return dic;
  331. }
  332. //奖励发放对象
  333. public static string prizeObject(int prizeObjectTag, string content)
  334. {
  335. Dictionary<string, object> dic = new Dictionary<string, object>();
  336. var prizeObjectTableService = App.GetService<IPriPrizeObjectTableService>();
  337. var prizeObjectFieldService = App.GetService<IPriPrizeObjectFieldService>();
  338. //查询表
  339. var prizeObjectTable = prizeObjectTableService.GetFirst(m => m.id == prizeObjectTag) ?? new PriPrizeObjectTable();
  340. //查询返回字段
  341. string field = prizeObjectTable.selectField;
  342. int projectId = prizeObjectTable.projectId;
  343. //查询匹配条件
  344. string condi = "";
  345. var queryFields = prizeObjectFieldService.GetList(m => m.objectTableId == prizeObjectTable.id);
  346. foreach(var queryField in queryFields)
  347. {
  348. string fieldEnName = queryField.fieldEnName;
  349. string fieldQueryKind = queryField.fieldQueryKind;
  350. string fieldQueryModel = queryField.fieldQueryModel;
  351. string fieldQueryValue = queryField.fieldQueryValue;
  352. string fieldQueryValueType = queryField.fieldQueryValueType;
  353. if(fieldQueryKind == "1") //模糊匹配
  354. {
  355. condi += " and " + fieldEnName + " like ";
  356. if(fieldQueryModel == "request_param")
  357. {
  358. Dictionary<string, string> req = getRequestParams(projectId, content);
  359. string val = req.ContainsKey(fieldQueryValue) ? req[fieldQueryValue] : "0";
  360. condi += "'%" + val + "%'";
  361. }
  362. else if(fieldQueryModel == "fixed_value")
  363. {
  364. condi += "'%" + GetExpressionVal(fieldQueryValue) + "%'";
  365. }
  366. else if(fieldQueryModel == "db_field")
  367. {
  368. condi += "'%" + GetDbExpressionVal(fieldQueryValue) + "%'";
  369. }
  370. }
  371. else if(fieldQueryKind == "2") //精确匹配
  372. {
  373. condi += " and " + fieldEnName + "=";
  374. string val = "";
  375. if(fieldQueryModel == "request_param")
  376. {
  377. Dictionary<string, string> req = getRequestParams(projectId, content);
  378. val = req.ContainsKey(fieldQueryValue) ? req[fieldQueryValue] : "0";
  379. }
  380. else if(fieldQueryModel == "fixed_value")
  381. {
  382. val = GetExpressionVal(fieldQueryValue);
  383. }
  384. else if(fieldQueryModel == "db_field")
  385. {
  386. val = GetDbExpressionVal(fieldQueryValue);
  387. }
  388. if(fieldQueryValueType == "text")
  389. {
  390. val = "'" + val + "'";
  391. }
  392. condi += val;
  393. }
  394. else if(fieldQueryKind == "5" || fieldQueryKind == "6") //数组匹配/排除
  395. {
  396. if(fieldQueryKind == "5") condi += " and " + fieldEnName + " in (";
  397. else if(fieldQueryKind == "6") condi += " and " + fieldEnName + " not in (";
  398. string val = "";
  399. string[] valList = fieldQueryValue.Split(',');
  400. if(fieldQueryModel == "request_param")
  401. {
  402. Dictionary<string, string> req = getRequestParams(projectId, content);
  403. foreach(string sub in valList)
  404. {
  405. if(fieldQueryValueType == "text")
  406. {
  407. val += "'" + req[sub] + "',";
  408. }
  409. else
  410. {
  411. val += req[sub] + ",";
  412. }
  413. }
  414. }
  415. else if(fieldQueryModel == "fixed_value")
  416. {
  417. foreach(string sub in valList)
  418. {
  419. if(fieldQueryValueType == "text")
  420. {
  421. val += "'" + GetExpressionVal(sub) + "',";
  422. }
  423. else
  424. {
  425. val += GetExpressionVal(sub) + ",";
  426. }
  427. }
  428. }
  429. else if(fieldQueryModel == "db_field")
  430. {
  431. foreach(string sub in valList)
  432. {
  433. if(fieldQueryValueType == "text")
  434. {
  435. val += "'" + GetDbExpressionVal(sub) + "',";
  436. }
  437. else
  438. {
  439. val += GetDbExpressionVal(sub) + ",";
  440. }
  441. }
  442. }
  443. val = val.TrimEnd(',');
  444. condi += val + ")";
  445. }
  446. else if(fieldQueryKind == "3") //范围匹配
  447. {
  448. string[] val = fieldQueryValue.Split(':');
  449. if(fieldQueryModel == "request_param")
  450. {
  451. Dictionary<string, string> req = getRequestParams(projectId, content);
  452. if(fieldQueryValueType == "number")
  453. {
  454. if(!string.IsNullOrEmpty(req[val[0]])) condi += " and " + fieldEnName + ">=" + req[val[0]];
  455. if(!string.IsNullOrEmpty(req[val[1]])) condi += " and " + fieldEnName + "<=" + req[val[1]];
  456. }
  457. else
  458. {
  459. if(!string.IsNullOrEmpty(req[val[0]])) condi += " and " + fieldEnName + ">='" + req[val[0]] + "'";
  460. if(!string.IsNullOrEmpty(req[val[1]])) condi += " and " + fieldEnName + "<='" + req[val[1]] + "'";
  461. }
  462. }
  463. else if(fieldQueryModel == "fixed_value")
  464. {
  465. if(fieldQueryValueType == "number")
  466. {
  467. if(!string.IsNullOrEmpty(val[0])) condi += " and " + fieldEnName + ">=" + val[0];
  468. if(!string.IsNullOrEmpty(val[1])) condi += " and " + fieldEnName + "<=" + val[1];
  469. }
  470. else
  471. {
  472. if(!string.IsNullOrEmpty(val[0])) condi += " and " + fieldEnName + ">='" + GetExpressionVal(val[0]) + "'";
  473. if(!string.IsNullOrEmpty(val[1])) condi += " and " + fieldEnName + "<='" + GetExpressionVal(val[1]) + "'";
  474. }
  475. }
  476. else if(fieldQueryModel == "db_field")
  477. {
  478. if(fieldQueryValueType == "number")
  479. {
  480. if(!string.IsNullOrEmpty(val[0])) condi += " and " + fieldEnName + ">=" + val[0];
  481. if(!string.IsNullOrEmpty(val[1])) condi += " and " + fieldEnName + "<=" + val[1];
  482. }
  483. else
  484. {
  485. if(!string.IsNullOrEmpty(val[0])) condi += " and " + fieldEnName + ">='" + GetDbExpressionVal(val[0]) + "'";
  486. if(!string.IsNullOrEmpty(val[1])) condi += " and " + fieldEnName + "<='" + GetDbExpressionVal(val[1]) + "'";
  487. }
  488. }
  489. }
  490. else if(fieldQueryKind == "4") //取反匹配
  491. {
  492. condi += " and " + fieldEnName + "!=";
  493. string val = "";
  494. if(fieldQueryModel == "request_param")
  495. {
  496. Dictionary<string, string> req = getRequestParams(projectId, content);
  497. val = req.ContainsKey(fieldQueryValue) ? req[fieldQueryValue] : "0";
  498. }
  499. else if(fieldQueryModel == "fixed_value")
  500. {
  501. val = GetExpressionVal(fieldQueryValue);
  502. }
  503. else if(fieldQueryModel == "db_field")
  504. {
  505. val = GetDbExpressionVal(fieldQueryValue);
  506. }
  507. if(fieldQueryValueType == "text")
  508. {
  509. val = "'" + val + "'";
  510. }
  511. condi += val;
  512. }
  513. }
  514. var db = initDb(prizeObjectTable.databaseId);
  515. var item = db.Ado.GetScalar("select " + field + " from " + prizeObjectTable.tableEnName + " where 1=1" + condi);
  516. if(item != null)
  517. {
  518. return item.ToString();
  519. }
  520. return "0";
  521. }
  522. //奖励发放入口
  523. public static string prizeInSet(int prizeObjectTag)
  524. {
  525. Dictionary<string, object> dic = new Dictionary<string, object>();
  526. var prizeInSetService = App.GetService<IPriPrizeInSetService>();
  527. //查询表
  528. var prizeInSet = prizeInSetService.GetFirst(m => m.id == prizeObjectTag) ?? new PriPrizeInSet();
  529. if(prizeInSet.id > 0)
  530. {
  531. int projectId = prizeInSet.projectId;
  532. return prizeInSet.prizeListIds + "|" + projectId;
  533. }
  534. return "";
  535. }
  536. //奖励列表
  537. public static List<PriList> prizeList(int projectId, string prizeIds)
  538. {
  539. List<int> ids = Tools.SpitIntArrary(prizeIds, ',').ToList();
  540. var priListService = App.GetService<IPriListService>();
  541. var priList = priListService.GetList(m => m.projectId == projectId && ids.Contains(m.id)).ToList();
  542. return priList;
  543. }
  544. //奖励发放
  545. public static void prizeSend(int projectId, string prizeIds, string content)
  546. {
  547. var loopSetService = App.GetService<IPriLoopSetService>();
  548. var recursionStartTableService = App.GetService<IPriRecursionStartTableService>();
  549. var recursionStartConditionService = App.GetService<IPriRecursionStartConditionService>();
  550. var priList = prizeList(projectId, prizeIds);
  551. foreach(var sub in priList)
  552. {
  553. string prizeObjectId = prizeObject(sub.prizeObj, content);
  554. var recursionFlag = sub.recursionFlag; //是否递归
  555. if(recursionFlag)
  556. {
  557. var loopSet = loopSetService.GetFirst(m => m.listId == sub.id) ?? new PriLoopSet();
  558. var recursionStartTable = recursionStartTableService.GetFirst(m => m.listId == sub.id) ?? new PriRecursionStartTable();
  559. var tableEnName = loopSet.tableEnName; //递归查询表
  560. var parentField = loopSet.parentField; //父字段
  561. var sonField = loopSet.sonField; //子字段
  562. var afterPrizeFlag = loopSet.afterPrizeFlag; //发奖后是否继续
  563. var db = initDb(recursionStartTable.databaseId);
  564. string objId = prizeObjectId;
  565. bool op = true;
  566. int index = 0;
  567. loopAmount = 0;
  568. Dictionary<string, object> topStepDic = new Dictionary<string, object>(); //递归日志数据
  569. while(!string.IsNullOrEmpty(objId) && objId != "0" && op)
  570. {
  571. List<Dictionary<string, string>> logStepDics = new List<Dictionary<string, string>>(); //条件日志数据
  572. List<QueryCondition> condiDic = loopCondition(projectId, sub, objId, content);
  573. if(condiDic.Count > 0)
  574. {
  575. bool prizeFlag = true;
  576. var conditions = recursionStartConditionService.GetList(m => m.loopSetId == loopSet.id);
  577. if(conditions.Count > 0)
  578. {
  579. int allCount = conditions.Count; //所有奖励条件数
  580. int passCount = 0; //通过条件数
  581. foreach(var condition in conditions)
  582. {
  583. if(condition.startIndex <= index)
  584. {
  585. Dictionary<string, string> logStepDic = new Dictionary<string, string>();
  586. var returnFieldId = condition.returnFieldId; //条件返回字段
  587. var fieldQueryKind = condition.fieldQueryKind; //匹配条件
  588. var fieldQueryModel = condition.fieldQueryModel; //匹配方式
  589. var fieldQueryValue = condition.fieldQueryValue; //匹配值
  590. var fieldQueryValueType = condition.fieldQueryValueType; //匹配值类型
  591. string checkObj = "";
  592. string checkTitle = "";
  593. if(returnFieldId.Contains(","))
  594. {
  595. string[] returnFieldIdList = returnFieldId.Split(',');
  596. foreach(string subField in returnFieldIdList)
  597. {
  598. string val = GetQueryTableData(condiDic, subField);
  599. checkObj += val + ",";
  600. string title = GetQueryTableTitle(condiDic, subField);
  601. checkTitle += title + ",";
  602. }
  603. checkObj = checkObj.TrimEnd(',');
  604. checkTitle = checkTitle.TrimEnd(',');
  605. }
  606. else if (returnFieldId.Contains("+") || returnFieldId.Contains("-") || returnFieldId.Contains("*") || returnFieldId.Contains("/") || returnFieldId.Contains("(") || returnFieldId.Contains(")"))
  607. {
  608. string expresssion = returnFieldId;
  609. checkTitle = returnFieldId;
  610. string[] returnFields = returnFieldId.Split(new char[] { '+', '-', '*', '/', '(', ')' });
  611. foreach(string returnField in returnFields)
  612. {
  613. string val = GetQueryTableData(condiDic, returnField);
  614. expresssion = expresssion.Replace(returnField, val);
  615. string title = GetQueryTableTitle(condiDic, returnField);
  616. checkTitle = checkTitle.Replace(returnField, title);
  617. }
  618. DataTable dt = new DataTable();
  619. checkObj = dt.Compute(expresssion, "false").ToString();
  620. }
  621. else
  622. {
  623. checkObj = GetQueryTableData(condiDic, returnFieldId);
  624. checkTitle = GetQueryTableTitle(condiDic, returnFieldId);
  625. }
  626. logStepDic.Add("标题", checkTitle);
  627. logStepDic.Add("匹配值", fieldQueryValue);
  628. logStepDic.Add("实际值", checkObj);
  629. var checkVal = fieldQueryValue;
  630. bool passFlag = false;
  631. if(fieldQueryKind == "1") //模糊匹配
  632. {
  633. if(fieldQueryValueType == "text")
  634. {
  635. if(checkObj.ToString().Contains(GetExpressionVal(checkVal))) passCount += 1; passFlag = true;
  636. }
  637. }
  638. else if(fieldQueryKind == "2") //精确匹配
  639. {
  640. if(fieldQueryValueType == "int")
  641. {
  642. if(int.Parse(Function.CheckInt(checkObj.ToString())) == int.Parse(Function.CheckNum(checkVal))) passCount += 1; passFlag = true;
  643. }
  644. else if(fieldQueryValueType == "number")
  645. {
  646. if(decimal.Parse(Function.CheckNum(checkObj.ToString())) == decimal.Parse(Function.CheckNum(checkVal))) passCount += 1; passFlag = true;
  647. }
  648. else
  649. {
  650. if(checkObj.ToString() == GetExpressionVal(checkVal)) passCount += 1; passFlag = true;
  651. }
  652. }
  653. else if(fieldQueryKind == "3") //范围匹配
  654. {
  655. string[] val = checkVal.Split(':');
  656. if(fieldQueryModel == "request_param")
  657. {
  658. Dictionary<string, string> req = getRequestParams(projectId, content);
  659. if(fieldQueryValueType == "number")
  660. {
  661. if(!string.IsNullOrEmpty(req[val[0]]) && !string.IsNullOrEmpty(req[val[1]]) && decimal.Parse(checkObj) >= decimal.Parse(Function.CheckNum(req[val[0]])) && decimal.Parse(checkObj) <= decimal.Parse(Function.CheckNum(req[val[1]])))
  662. {
  663. passCount += 1; passFlag = true;
  664. }
  665. else if(!string.IsNullOrEmpty(req[val[0]]) && string.IsNullOrEmpty(req[val[1]]) && decimal.Parse(checkObj) >= decimal.Parse(Function.CheckNum(req[val[0]])))
  666. {
  667. passCount += 1; passFlag = true;
  668. }
  669. else if(string.IsNullOrEmpty(req[val[0]]) && !string.IsNullOrEmpty(req[val[1]]) && decimal.Parse(checkObj) <= decimal.Parse(Function.CheckNum(req[val[1]])))
  670. {
  671. passCount += 1; passFlag = true;
  672. }
  673. }
  674. else if(fieldQueryValueType == "int")
  675. {
  676. if(!string.IsNullOrEmpty(req[val[0]]) && !string.IsNullOrEmpty(req[val[1]]) && int.Parse(checkObj) >= int.Parse(Function.CheckInt(req[val[0]])) && int.Parse(checkObj) <= int.Parse(Function.CheckInt(req[val[1]])))
  677. {
  678. passCount += 1; passFlag = true;
  679. }
  680. else if(!string.IsNullOrEmpty(req[val[0]]) && string.IsNullOrEmpty(req[val[1]]) && int.Parse(checkObj) >= int.Parse(Function.CheckInt(req[val[0]])))
  681. {
  682. passCount += 1; passFlag = true;
  683. }
  684. else if(string.IsNullOrEmpty(req[val[0]]) && !string.IsNullOrEmpty(req[val[1]]) && int.Parse(checkObj) <= int.Parse(Function.CheckInt(req[val[1]])))
  685. {
  686. passCount += 1; passFlag = true;
  687. }
  688. }
  689. else if(fieldQueryValueType.StartsWith("date"))
  690. {
  691. if(!string.IsNullOrEmpty(req[val[0]]) && !string.IsNullOrEmpty(req[val[1]]) && DateTime.Parse(checkObj) >= DateTime.Parse(req[val[0]]) && DateTime.Parse(checkObj) <= DateTime.Parse(req[val[1]]))
  692. {
  693. passCount += 1; passFlag = true;
  694. }
  695. else if(!string.IsNullOrEmpty(req[val[0]]) && string.IsNullOrEmpty(req[val[1]]) && DateTime.Parse(checkObj) >= DateTime.Parse(req[val[0]]))
  696. {
  697. passCount += 1; passFlag = true;
  698. }
  699. else if(string.IsNullOrEmpty(req[val[0]]) && !string.IsNullOrEmpty(req[val[1]]) && DateTime.Parse(checkObj) <= DateTime.Parse(req[val[1]]))
  700. {
  701. passCount += 1; passFlag = true;
  702. }
  703. }
  704. }
  705. else if(fieldQueryModel == "fixed_value")
  706. {
  707. if(fieldQueryValueType == "number")
  708. {
  709. if(!string.IsNullOrEmpty(val[0]) && !string.IsNullOrEmpty(val[1]) && decimal.Parse(checkObj) >= decimal.Parse(Function.CheckNum(val[0])) && decimal.Parse(Function.CheckNum(checkObj.ToString())) <= decimal.Parse(Function.CheckNum(val[1])))
  710. {
  711. passCount += 1; passFlag = true;
  712. }
  713. else if(!string.IsNullOrEmpty(val[0]) && string.IsNullOrEmpty(val[1]) && decimal.Parse(Function.CheckNum(checkObj.ToString())) >= decimal.Parse(Function.CheckNum(val[0])))
  714. {
  715. passCount += 1; passFlag = true;
  716. }
  717. else if(string.IsNullOrEmpty(val[0]) && !string.IsNullOrEmpty(val[1]) && decimal.Parse(Function.CheckNum(checkObj.ToString())) <= decimal.Parse(Function.CheckNum(val[1])))
  718. {
  719. passCount += 1; passFlag = true;
  720. }
  721. }
  722. else if(fieldQueryValueType == "int")
  723. {
  724. if(!string.IsNullOrEmpty(val[0]) && !string.IsNullOrEmpty(val[1]) && int.Parse(checkObj) >= int.Parse(Function.CheckInt(val[0])) && int.Parse(Function.CheckInt(checkObj.ToString())) <= int.Parse(Function.CheckInt(val[1])))
  725. {
  726. passCount += 1; passFlag = true;
  727. }
  728. else if(!string.IsNullOrEmpty(val[0]) && string.IsNullOrEmpty(val[1]) && int.Parse(Function.CheckInt(checkObj.ToString())) >= int.Parse(Function.CheckInt(val[0])))
  729. {
  730. passCount += 1; passFlag = true;
  731. }
  732. else if(string.IsNullOrEmpty(val[0]) && !string.IsNullOrEmpty(val[1]) && int.Parse(Function.CheckInt(checkObj.ToString())) <= int.Parse(Function.CheckInt(val[1])))
  733. {
  734. passCount += 1; passFlag = true;
  735. }
  736. }
  737. else if(fieldQueryValueType.StartsWith("date"))
  738. {
  739. if(!string.IsNullOrEmpty(val[0]) && !string.IsNullOrEmpty(val[1]) && DateTime.Parse(checkObj) >= DateTime.Parse(GetExpressionVal(val[0])) && DateTime.Parse(checkObj) <= DateTime.Parse(GetExpressionVal(val[1])))
  740. {
  741. passCount += 1; passFlag = true;
  742. }
  743. else if(!string.IsNullOrEmpty(val[0]) && string.IsNullOrEmpty(val[1]) && DateTime.Parse(checkObj) >= DateTime.Parse(GetExpressionVal(val[0])))
  744. {
  745. passCount += 1; passFlag = true;
  746. }
  747. else if(string.IsNullOrEmpty(val[0]) && !string.IsNullOrEmpty(val[1]) && DateTime.Parse(checkObj) <= DateTime.Parse(GetExpressionVal(val[1])))
  748. {
  749. passCount += 1; passFlag = true;
  750. }
  751. }
  752. }
  753. }
  754. else if(fieldQueryKind == "4") //取反匹配
  755. {
  756. if(fieldQueryValueType == "int")
  757. {
  758. if(int.Parse(checkObj) != int.Parse(Function.CheckInt(checkVal))) passCount += 1; passFlag = true;
  759. }
  760. else if(fieldQueryValueType == "number")
  761. {
  762. if(decimal.Parse(checkObj) != decimal.Parse(Function.CheckNum(checkVal))) passCount += 1; passFlag = true;
  763. }
  764. else if(fieldQueryValueType == "text")
  765. {
  766. if(checkObj.ToString() != GetExpressionVal(checkVal)) passCount += 1; passFlag = true;
  767. }
  768. }
  769. else if(fieldQueryKind == "5" || fieldQueryKind == "6") //数组匹配/排除
  770. {
  771. string val = ",";
  772. string[] valList = checkVal.Split(',');
  773. if(fieldQueryModel == "request_param")
  774. {
  775. Dictionary<string, string> req = getRequestParams(projectId, content);
  776. foreach(string subVal in valList)
  777. {
  778. val += req[subVal] + ",";
  779. }
  780. }
  781. else if(fieldQueryModel == "fixed_value")
  782. {
  783. foreach(string subVal in valList)
  784. {
  785. val += GetExpressionVal(subVal) + ",";
  786. }
  787. }
  788. else if(fieldQueryModel == "db_field")
  789. {
  790. foreach(string subVal in valList)
  791. {
  792. val += GetDbExpressionVal(subVal) + ",";
  793. }
  794. }
  795. if(fieldQueryKind == "5" && val.Contains("," + checkObj.ToString() + ",")) passCount += 1; passFlag = true;
  796. if(fieldQueryKind == "6" && val.Contains("," + checkObj.ToString() + ",")) passCount += 1; passFlag = true;
  797. }
  798. logStepDic.Add("状态", passFlag ? "通过" : "未通过");
  799. logStepDics.Add(logStepDic);
  800. }
  801. }
  802. if(loopSet.conditionMode == "all" && passCount == allCount) prizeFlag = true;
  803. else if(loopSet.conditionMode == "one" && passCount >= 1) prizeFlag = true;
  804. else prizeFlag = false;
  805. }
  806. else
  807. {
  808. prizeFlag = false;
  809. }
  810. if(prizeFlag)
  811. {
  812. decimal prizeAmt = prizeSendDo(projectId, sub, objId, content, loopSet);
  813. op = afterPrizeFlag;
  814. }
  815. }
  816. topStepDic.Add(objId, logStepDics);
  817. var parent = db.Ado.GetScalar("select " + parentField + " from " + tableEnName + " where " + sonField + "=" + objId);
  818. if(parent != null)
  819. {
  820. objId = parent.ToString();
  821. }
  822. index += 1;
  823. }
  824. setLogStep(Newtonsoft.Json.JsonConvert.SerializeObject(topStepDic));
  825. }
  826. else
  827. {
  828. prizeSendDo(projectId, sub, prizeObjectId, content, new PriLoopSet());
  829. }
  830. }
  831. }
  832. static decimal loopAmount = 0;
  833. public static decimal prizeSendDo(int projectId, PriList sub, string prizeObjectId, string content, PriLoopSet set)
  834. {
  835. var recordService = App.GetService<IPriRecordService>();
  836. var conditionService = App.GetService<IPriConditionService>();
  837. var returnFieldService = App.GetService<IPriReturnFieldService>();
  838. var queryTableService = App.GetService<IPriQueryTableService>();
  839. var amountSetService = App.GetService<IPriListAmountSetService>();
  840. //查询匹配条件
  841. List<QueryCondition> condiDic = new List<QueryCondition>();
  842. if(sub.prizeSourceFieldType == "condi") condiDic = condition(projectId, Tools.SpitIntArrary(sub.queryTableIdList, ',').ToList(), content);
  843. if(sub.prizeSourceFieldType == "loop") condiDic = loopCondition(projectId, sub, prizeObjectId, content);
  844. var prizeSourceField = sub.prizeSourceField; //奖励金额来源字段(对应条件匹配返回字段)
  845. var prizePercent = sub.prizePercent; //奖励比例
  846. var prizeAmount = sub.prizeAmount; //奖励固定值
  847. var prizeContent = sub.prizeContent; //奖励内容
  848. var conditionMode = sub.conditionMode; //条件模式
  849. var recursionFlag = sub.recursionFlag; //是否递归
  850. var conditions = conditionService.GetList(m => m.listId == sub.id);
  851. int allCount = conditions.Count; //所有奖励条件数
  852. int passCount = 0; //通过条件数
  853. List<Dictionary<string, string>> logStepDics = new List<Dictionary<string, string>>();
  854. foreach(var condition in conditions)
  855. {
  856. Dictionary<string, string> logStepDic = new Dictionary<string, string>();
  857. var returnFieldId = condition.returnFieldId; //条件返回字段
  858. var fieldQueryKind = condition.fieldQueryKind; //匹配条件
  859. var fieldQueryModel = condition.fieldQueryModel; //匹配方式
  860. var fieldQueryValue = condition.fieldQueryValue; //匹配值
  861. var fieldQueryValueType = condition.fieldQueryValueType; //匹配值类型
  862. string checkObj = "";
  863. string checkTitle = "";
  864. if(returnFieldId.Contains(","))
  865. {
  866. string[] returnFieldIdList = returnFieldId.Split(',');
  867. foreach(string subField in returnFieldIdList)
  868. {
  869. string val = GetQueryTableData(condiDic, subField);
  870. checkObj += val + ",";
  871. string title = GetQueryTableTitle(condiDic, subField);
  872. checkTitle += title + ",";
  873. }
  874. checkObj = checkObj.TrimEnd(',');
  875. checkTitle = checkTitle.TrimEnd(',');
  876. }
  877. else if (returnFieldId.Contains("+") || returnFieldId.Contains("-") || returnFieldId.Contains("*") || returnFieldId.Contains("/") || returnFieldId.Contains("(") || returnFieldId.Contains(")"))
  878. {
  879. string expresssion = returnFieldId;
  880. checkTitle = returnFieldId;
  881. string[] returnFields = returnFieldId.Split(new char[] { '+', '-', '*', '/', '(', ')' });
  882. foreach(string returnField in returnFields)
  883. {
  884. string val = GetQueryTableData(condiDic, returnField);
  885. expresssion = expresssion.Replace(returnField, val);
  886. string title = GetQueryTableTitle(condiDic, returnField);
  887. checkTitle = checkTitle.Replace(returnField, title);
  888. }
  889. DataTable dt = new DataTable();
  890. checkObj = dt.Compute(expresssion, "false").ToString();
  891. }
  892. else
  893. {
  894. checkObj = GetQueryTableData(condiDic, returnFieldId);
  895. checkTitle = GetQueryTableTitle(condiDic, returnFieldId);
  896. }
  897. if(!sub.recursionFlag)
  898. {
  899. logStepDic.Add("标题", checkTitle);
  900. logStepDic.Add("匹配值", fieldQueryValue);
  901. logStepDic.Add("实际值", checkObj);
  902. }
  903. string checkVal = fieldQueryValue;
  904. bool passFlag = false;
  905. if(fieldQueryKind == "1") //模糊匹配
  906. {
  907. if(fieldQueryValueType == "text")
  908. {
  909. if(checkObj.ToString().Contains(GetExpressionVal(checkVal))) passCount += 1; passFlag = true;
  910. }
  911. }
  912. else if(fieldQueryKind == "2") //精确匹配
  913. {
  914. if(fieldQueryValueType == "int")
  915. {
  916. if(int.Parse(Function.CheckInt(checkObj.ToString())) == int.Parse(Function.CheckNum(checkVal))) passCount += 1; passFlag = true;
  917. }
  918. else if(fieldQueryValueType == "number")
  919. {
  920. if(decimal.Parse(Function.CheckNum(checkObj.ToString())) == decimal.Parse(Function.CheckNum(checkVal))) passCount += 1; passFlag = true;
  921. }
  922. else
  923. {
  924. if(checkObj.ToString() == GetExpressionVal(checkVal)) passCount += 1; passFlag = true;
  925. }
  926. }
  927. else if(fieldQueryKind == "3") //范围匹配
  928. {
  929. string[] val = checkVal.Split(':');
  930. if(fieldQueryModel == "request_param")
  931. {
  932. Dictionary<string, string> req = getRequestParams(projectId, content);
  933. if(fieldQueryValueType == "number")
  934. {
  935. if(!string.IsNullOrEmpty(req[val[0]]) && !string.IsNullOrEmpty(req[val[1]]) && decimal.Parse(checkObj) >= decimal.Parse(Function.CheckNum(req[val[0]])) && decimal.Parse(checkObj) <= decimal.Parse(Function.CheckNum(req[val[1]])))
  936. {
  937. passCount += 1; passFlag = true;
  938. }
  939. else if(!string.IsNullOrEmpty(req[val[0]]) && string.IsNullOrEmpty(req[val[1]]) && decimal.Parse(checkObj) >= decimal.Parse(Function.CheckNum(req[val[0]])))
  940. {
  941. passCount += 1; passFlag = true;
  942. }
  943. else if(string.IsNullOrEmpty(req[val[0]]) && !string.IsNullOrEmpty(req[val[1]]) && decimal.Parse(checkObj) <= decimal.Parse(Function.CheckNum(req[val[1]])))
  944. {
  945. passCount += 1; passFlag = true;
  946. }
  947. }
  948. else if(fieldQueryValueType == "int")
  949. {
  950. if(!string.IsNullOrEmpty(req[val[0]]) && !string.IsNullOrEmpty(req[val[1]]) && int.Parse(checkObj) >= int.Parse(Function.CheckInt(req[val[0]])) && int.Parse(checkObj) <= int.Parse(Function.CheckInt(req[val[1]])))
  951. {
  952. passCount += 1; passFlag = true;
  953. }
  954. else if(!string.IsNullOrEmpty(req[val[0]]) && string.IsNullOrEmpty(req[val[1]]) && int.Parse(checkObj) >= int.Parse(Function.CheckInt(req[val[0]])))
  955. {
  956. passCount += 1; passFlag = true;
  957. }
  958. else if(string.IsNullOrEmpty(req[val[0]]) && !string.IsNullOrEmpty(req[val[1]]) && int.Parse(checkObj) <= int.Parse(Function.CheckInt(req[val[1]])))
  959. {
  960. passCount += 1; passFlag = true;
  961. }
  962. }
  963. else if(fieldQueryValueType.StartsWith("date"))
  964. {
  965. if(!string.IsNullOrEmpty(req[val[0]]) && !string.IsNullOrEmpty(req[val[1]]) && DateTime.Parse(checkObj) >= DateTime.Parse(req[val[0]]) && DateTime.Parse(checkObj) <= DateTime.Parse(req[val[1]]))
  966. {
  967. passCount += 1; passFlag = true;
  968. }
  969. else if(!string.IsNullOrEmpty(req[val[0]]) && string.IsNullOrEmpty(req[val[1]]) && DateTime.Parse(checkObj) >= DateTime.Parse(req[val[0]]))
  970. {
  971. passCount += 1; passFlag = true;
  972. }
  973. else if(string.IsNullOrEmpty(req[val[0]]) && !string.IsNullOrEmpty(req[val[1]]) && DateTime.Parse(checkObj) <= DateTime.Parse(req[val[1]]))
  974. {
  975. passCount += 1; passFlag = true;
  976. }
  977. }
  978. }
  979. else if(fieldQueryModel == "fixed_value")
  980. {
  981. if(fieldQueryValueType == "number")
  982. {
  983. if(!string.IsNullOrEmpty(val[0]) && !string.IsNullOrEmpty(val[1]) && decimal.Parse(Function.CheckNum(checkObj.ToString())) >= decimal.Parse(Function.CheckNum(val[0])) && decimal.Parse(Function.CheckNum(checkObj.ToString())) <= decimal.Parse(Function.CheckNum(val[1])))
  984. {
  985. passCount += 1; passFlag = true;
  986. }
  987. else if(!string.IsNullOrEmpty(val[0]) && string.IsNullOrEmpty(val[1]) && decimal.Parse(Function.CheckNum(checkObj.ToString())) >= decimal.Parse(Function.CheckNum(val[0])))
  988. {
  989. passCount += 1; passFlag = true;
  990. }
  991. else if(string.IsNullOrEmpty(val[0]) && !string.IsNullOrEmpty(val[1]) && decimal.Parse(Function.CheckNum(checkObj.ToString())) <= decimal.Parse(Function.CheckNum(val[1])))
  992. {
  993. passCount += 1; passFlag = true;
  994. }
  995. }
  996. else if(fieldQueryValueType == "int")
  997. {
  998. if(!string.IsNullOrEmpty(val[0]) && !string.IsNullOrEmpty(val[1]) && int.Parse(Function.CheckNum(checkObj.ToString())) >= int.Parse(Function.CheckInt(val[0])) && int.Parse(Function.CheckInt(checkObj.ToString())) <= int.Parse(Function.CheckInt(val[1])))
  999. {
  1000. passCount += 1; passFlag = true;
  1001. }
  1002. else if(!string.IsNullOrEmpty(val[0]) && string.IsNullOrEmpty(val[1]) && int.Parse(Function.CheckInt(checkObj.ToString())) >= int.Parse(Function.CheckInt(val[0])))
  1003. {
  1004. passCount += 1; passFlag = true;
  1005. }
  1006. else if(string.IsNullOrEmpty(val[0]) && !string.IsNullOrEmpty(val[1]) && int.Parse(Function.CheckInt(checkObj.ToString())) <= int.Parse(Function.CheckInt(val[1])))
  1007. {
  1008. passCount += 1; passFlag = true;
  1009. }
  1010. }
  1011. else if(fieldQueryValueType.StartsWith("date"))
  1012. {
  1013. if(!string.IsNullOrEmpty(val[0]) && !string.IsNullOrEmpty(val[1]) && DateTime.Parse(checkObj.ToString()) >= DateTime.Parse(GetExpressionVal(val[0])) && DateTime.Parse(checkObj.ToString()) <= DateTime.Parse(GetExpressionVal(val[1])))
  1014. {
  1015. passCount += 1; passFlag = true;
  1016. }
  1017. else if(!string.IsNullOrEmpty(val[0]) && string.IsNullOrEmpty(val[1]) && DateTime.Parse(checkObj.ToString()) >= DateTime.Parse(GetExpressionVal(val[0])))
  1018. {
  1019. passCount += 1; passFlag = true;
  1020. }
  1021. else if(string.IsNullOrEmpty(val[0]) && !string.IsNullOrEmpty(val[1]) && DateTime.Parse(checkObj.ToString()) <= DateTime.Parse(GetExpressionVal(val[1])))
  1022. {
  1023. passCount += 1; passFlag = true;
  1024. }
  1025. }
  1026. }
  1027. }
  1028. else if(fieldQueryKind == "4") //取反匹配
  1029. {
  1030. if(fieldQueryValueType == "int")
  1031. {
  1032. if(int.Parse(Function.CheckNum(checkObj.ToString())) != int.Parse(Function.CheckInt(checkVal))) passCount += 1; passFlag = true;
  1033. }
  1034. else if(fieldQueryValueType == "number")
  1035. {
  1036. if(decimal.Parse(Function.CheckNum(checkObj.ToString())) != decimal.Parse(Function.CheckNum(checkVal))) passCount += 1; passFlag = true;
  1037. }
  1038. else if(fieldQueryValueType == "text")
  1039. {
  1040. if(checkObj.ToString() != GetExpressionVal(checkVal)) passCount += 1; passFlag = true;
  1041. }
  1042. }
  1043. else if(fieldQueryKind == "5" || fieldQueryKind == "6") //数组匹配/排除
  1044. {
  1045. string val = ",";
  1046. string[] valList = checkVal.Split(',');
  1047. if(fieldQueryModel == "request_param")
  1048. {
  1049. Dictionary<string, string> req = getRequestParams(projectId, content);
  1050. foreach(string subVal in valList)
  1051. {
  1052. val += req[subVal] + ",";
  1053. }
  1054. }
  1055. else if(fieldQueryModel == "fixed_value")
  1056. {
  1057. foreach(string subVal in valList)
  1058. {
  1059. val += GetExpressionVal(subVal) + ",";
  1060. }
  1061. }
  1062. else if(fieldQueryModel == "db_field")
  1063. {
  1064. foreach(string subVal in valList)
  1065. {
  1066. val += GetDbExpressionVal(subVal) + ",";
  1067. }
  1068. }
  1069. if (fieldQueryKind == "5" && val.Contains("," + checkObj.ToString() + ",")) passCount += 1; passFlag = true;
  1070. if(fieldQueryKind == "6" && val.Contains("," + checkObj.ToString() + ",")) passCount += 1; passFlag = true;
  1071. }
  1072. if(!sub.recursionFlag)
  1073. {
  1074. logStepDic.Add("状态", passFlag ? "通过" : "未通过");
  1075. logStepDics.Add(logStepDic);
  1076. }
  1077. }
  1078. bool op = false;
  1079. decimal prizeAmt = 0;
  1080. if(conditionMode == "all" && passCount == allCount && passCount > 0) op = true;
  1081. else if(conditionMode == "one" && passCount >= 1) op = true;
  1082. if(op) //满足条件
  1083. {
  1084. decimal number = 0;
  1085. if(prizeSourceField.Contains("/"))
  1086. {
  1087. number = decimal.Parse(prizeSourceField.Split('/')[1]);
  1088. prizeSourceField = prizeSourceField.Split('/')[0];
  1089. }
  1090. string prizeSourceData = "";
  1091. if(prizeSourceField.Contains(","))
  1092. {
  1093. string[] prizeSourceFieldList = prizeSourceField.Split(',');
  1094. foreach(string subField in prizeSourceFieldList)
  1095. {
  1096. string val = GetQueryTableData(condiDic, subField);
  1097. prizeSourceData += val + ",";
  1098. }
  1099. prizeSourceData = prizeSourceData.TrimEnd(',');
  1100. }
  1101. else
  1102. {
  1103. prizeSourceData = GetQueryTableData(condiDic, prizeSourceField);
  1104. }
  1105. if(string.IsNullOrEmpty(prizeSourceData)) prizeSourceData = "0";
  1106. if(prizeSourceField.Contains("/") && number > 0)
  1107. {
  1108. decimal prizeSourceDataNum = decimal.Parse(prizeSourceData) / number;
  1109. prizeSourceData = prizeSourceDataNum.ToString("f2");
  1110. }
  1111. var amountSet = amountSetService.GetFirst(m => m.listId == sub.id && m.prizeSourceField == prizeSourceData);
  1112. if(amountSet != null)
  1113. {
  1114. prizePercent = amountSet.prizePercent;
  1115. prizeAmount = amountSet.prizeAmount;
  1116. }
  1117. if(prizeSourceData.Contains(","))
  1118. {
  1119. string checkField = prizeSourceData.Split(',')[0] + ",";
  1120. amountSet = amountSetService.GetFirst(m => m.listId == sub.id && m.prizeSourceField.StartsWith(checkField) && m.prizeSourceField.EndsWith(",%"));
  1121. if(amountSet != null)
  1122. {
  1123. prizePercent = amountSet.prizePercent;
  1124. prizeAmount = amountSet.prizeAmount;
  1125. prizeSourceData = prizeSourceData.Split(',')[1];
  1126. }
  1127. }
  1128. if(prizePercent > 0) prizeAmt += decimal.Parse(Function.CheckNum(prizeSourceData)) * prizePercent;
  1129. if(prizeAmount > 0) prizeAmt += prizeAmount;
  1130. decimal getPrizeAmount = prizeAmt;
  1131. if(set.levelDiffFlag) prizeAmt -= loopAmount;
  1132. if(prizeAmt > 0)
  1133. {
  1134. setLogPrizeAmount(prizeAmt);
  1135. var req = getRequestParams(projectId, content);
  1136. var requestParamField = req[sub.requestParamField];
  1137. var sendFlag = recordService.Any(m => m.prizeObjId == prizeObjectId && m.listId == sub.id && m.requestParamField == requestParamField);
  1138. if(!sendFlag)
  1139. {
  1140. recordService.Add(new PriRecord()
  1141. {
  1142. createDate = DateTime.Now,
  1143. projectId = projectId,
  1144. listId = sub.id,
  1145. prizeAmount = prizeAmt,
  1146. prizeObjId = prizeObjectId,
  1147. requestParamField = requestParamField,
  1148. batchNo = batchNo,
  1149. });
  1150. loopAmount = getPrizeAmount;
  1151. // prizeToDatabase(projectId, sub.id, content); //入库
  1152. }
  1153. }
  1154. }
  1155. if(!sub.recursionFlag)
  1156. {
  1157. setLogStatus(op ? 1 : 0);
  1158. setLogStep(Newtonsoft.Json.JsonConvert.SerializeObject(logStepDics));
  1159. }
  1160. return prizeAmt;
  1161. }
  1162. //递归条件判断
  1163. public static List<QueryCondition> loopCondition(int projectId, PriList sub, string objId, string content)
  1164. {
  1165. List<QueryCondition> dic = new List<QueryCondition>();
  1166. var queryTableService = App.GetService<IPriRecursionStartTableService>();
  1167. var queryFieldService = App.GetService<IPriRecursionStartFieldService>();
  1168. var queryReturnFieldService = App.GetService<IPriRecursionStartReturnFieldService>();
  1169. int passCount = 0;
  1170. //查询表
  1171. var queryTables = queryTableService.GetList(m => m.listId == sub.id);
  1172. int allCount = queryTables.Count;
  1173. foreach(var queryTable in queryTables)
  1174. {
  1175. //查询返回字段
  1176. string fields = "1";
  1177. Dictionary<string, string> fieldDic = new Dictionary<string, string>();
  1178. var returnFields = queryReturnFieldService.GetList(m => m.objectTableId == queryTable.id);
  1179. if(returnFields.Count > 0)
  1180. {
  1181. fields = "";
  1182. foreach(var returnField in returnFields)
  1183. {
  1184. if(returnField.fieldReturnKind == "2")
  1185. {
  1186. fields += "count(" + returnField.fieldEnName + ") " + queryTable.tableEnName + "_" + returnField.fieldEnName + ",";
  1187. }
  1188. else if(returnField.fieldReturnKind == "3")
  1189. {
  1190. fields += "sum(" + returnField.fieldEnName + ") " + queryTable.tableEnName + "_" + returnField.fieldEnName + ",";
  1191. }
  1192. else if(returnField.fieldReturnKind == "4")
  1193. {
  1194. fields += "avg(" + returnField.fieldEnName + ") " + queryTable.tableEnName + "_" + returnField.fieldEnName + ",";
  1195. }
  1196. else
  1197. {
  1198. fields += returnField.fieldEnName + " " + queryTable.tableEnName + "_" + returnField.fieldEnName + ",";
  1199. }
  1200. fieldDic.Add(queryTable.tableEnName + "_" + returnField.fieldEnName, returnField.fieldName);
  1201. }
  1202. fields = fields.TrimEnd(',');
  1203. }
  1204. //查询匹配条件
  1205. string condi = "";
  1206. var queryFields = queryFieldService.GetList(m => m.objectTableId == queryTable.id);
  1207. foreach(var queryField in queryFields)
  1208. {
  1209. string fieldEnName = queryField.fieldEnName;
  1210. string fieldQueryKind = queryField.fieldQueryKind;
  1211. string fieldQueryModel = queryField.fieldQueryModel;
  1212. string fieldQueryValue = queryField.fieldQueryValue;
  1213. if(fieldQueryModel == "loop_field") fieldQueryValue = objId;
  1214. string fieldQueryValueType = queryField.fieldQueryValueType;
  1215. if(fieldQueryKind == "1") //模糊匹配
  1216. {
  1217. condi += " and " + fieldEnName + " like ";
  1218. if(fieldQueryModel == "request_param")
  1219. {
  1220. Dictionary<string, string> req = getRequestParams(projectId, content);
  1221. string val = req.ContainsKey(fieldQueryValue) ? req[fieldQueryValue] : "0";
  1222. condi += "'%" + val + "%'";
  1223. }
  1224. else if(fieldQueryModel == "fixed_value")
  1225. {
  1226. condi += "'%" + GetExpressionVal(fieldQueryValue) + "%'";
  1227. }
  1228. else if(fieldQueryModel == "db_field")
  1229. {
  1230. condi += "'%" + GetDbExpressionVal(fieldQueryValue) + "%'";
  1231. }
  1232. }
  1233. else if(fieldQueryKind == "2") //精确匹配
  1234. {
  1235. condi += " and " + fieldEnName + "=";
  1236. string val = fieldQueryValue;
  1237. if(fieldQueryModel == "request_param")
  1238. {
  1239. Dictionary<string, string> req = getRequestParams(projectId, content);
  1240. val = req.ContainsKey(fieldQueryValue) ? req[fieldQueryValue] : "0";
  1241. }
  1242. else if(fieldQueryModel == "fixed_value")
  1243. {
  1244. val = GetExpressionVal(fieldQueryValue);
  1245. }
  1246. else if(fieldQueryModel == "db_field")
  1247. {
  1248. val = GetDbExpressionVal(fieldQueryValue);
  1249. }
  1250. if(fieldQueryValueType == "text")
  1251. {
  1252. val = "'" + val + "'";
  1253. }
  1254. condi += val;
  1255. }
  1256. else if(fieldQueryKind == "5" || fieldQueryKind == "6") //数组匹配/排除
  1257. {
  1258. if(fieldQueryKind == "5") condi += " and " + fieldEnName + " in (";
  1259. else if(fieldQueryKind == "6") condi += " and " + fieldEnName + " not in (";
  1260. string val = "";
  1261. string[] valList = fieldQueryValue.Split(',');
  1262. if(fieldQueryModel == "request_param")
  1263. {
  1264. Dictionary<string, string> req = getRequestParams(projectId, content);
  1265. foreach(string subval in valList)
  1266. {
  1267. if(fieldQueryValueType == "text")
  1268. {
  1269. val += "'" + req[subval] + "',";
  1270. }
  1271. else
  1272. {
  1273. val += req[subval] + ",";
  1274. }
  1275. }
  1276. }
  1277. else if(fieldQueryModel == "fixed_value")
  1278. {
  1279. foreach(string subval in valList)
  1280. {
  1281. if(fieldQueryValueType == "text")
  1282. {
  1283. val += "'" + GetExpressionVal(subval) + "',";
  1284. }
  1285. else
  1286. {
  1287. val += GetExpressionVal(subval) + ",";
  1288. }
  1289. }
  1290. }
  1291. else if(fieldQueryModel == "db_field")
  1292. {
  1293. foreach(string subval in valList)
  1294. {
  1295. if(fieldQueryValueType == "text")
  1296. {
  1297. val += "'" + GetDbExpressionVal(subval) + "',";
  1298. }
  1299. else
  1300. {
  1301. val += GetDbExpressionVal(subval) + ",";
  1302. }
  1303. }
  1304. }
  1305. val = val.TrimEnd(',');
  1306. condi += val + ")";
  1307. }
  1308. else if(fieldQueryKind == "3") //范围匹配
  1309. {
  1310. string[] val = fieldQueryValue.Split(':');
  1311. if(fieldQueryModel == "request_param")
  1312. {
  1313. Dictionary<string, string> req = getRequestParams(projectId, content);
  1314. if(fieldQueryValueType == "number")
  1315. {
  1316. if(!string.IsNullOrEmpty(req[val[0]])) condi += " and " + fieldEnName + ">=" + req[val[0]];
  1317. if(!string.IsNullOrEmpty(req[val[1]])) condi += " and " + fieldEnName + "<=" + req[val[1]];
  1318. }
  1319. else
  1320. {
  1321. if(!string.IsNullOrEmpty(req[val[0]])) condi += " and " + fieldEnName + ">='" + req[val[0]] + "'";
  1322. if(!string.IsNullOrEmpty(req[val[1]])) condi += " and " + fieldEnName + "<='" + req[val[1]] + "'";
  1323. }
  1324. }
  1325. else if(fieldQueryModel == "fixed_value")
  1326. {
  1327. if(fieldQueryValueType == "number")
  1328. {
  1329. if(!string.IsNullOrEmpty(val[0])) condi += " and " + fieldEnName + ">=" + val[0];
  1330. if(!string.IsNullOrEmpty(val[1])) condi += " and " + fieldEnName + "<=" + val[1];
  1331. }
  1332. else
  1333. {
  1334. if(!string.IsNullOrEmpty(val[0])) condi += " and " + fieldEnName + ">='" + GetExpressionVal(val[0]) + "'";
  1335. if(!string.IsNullOrEmpty(val[1])) condi += " and " + fieldEnName + "<='" + GetExpressionVal(val[1]) + "'";
  1336. }
  1337. }
  1338. else if(fieldQueryModel == "db_field")
  1339. {
  1340. if(fieldQueryValueType == "number")
  1341. {
  1342. if(!string.IsNullOrEmpty(val[0])) condi += " and " + fieldEnName + ">=" + val[0];
  1343. if(!string.IsNullOrEmpty(val[1])) condi += " and " + fieldEnName + "<=" + val[1];
  1344. }
  1345. else
  1346. {
  1347. if(!string.IsNullOrEmpty(val[0])) condi += " and " + fieldEnName + ">='" + GetDbExpressionVal(val[0]) + "'";
  1348. if(!string.IsNullOrEmpty(val[1])) condi += " and " + fieldEnName + "<='" + GetDbExpressionVal(val[1]) + "'";
  1349. }
  1350. }
  1351. }
  1352. else if(fieldQueryKind == "4") //取反匹配
  1353. {
  1354. condi += " and " + fieldEnName + "!=";
  1355. string val = "";
  1356. if(fieldQueryModel == "request_param")
  1357. {
  1358. Dictionary<string, string> req = getRequestParams(projectId, content);
  1359. val = req.ContainsKey(fieldQueryValue) ? req[fieldQueryValue] : "0";
  1360. }
  1361. else if(fieldQueryModel == "fixed_value")
  1362. {
  1363. val = GetExpressionVal(fieldQueryValue);
  1364. }
  1365. else if(fieldQueryModel == "db_field")
  1366. {
  1367. val = GetDbExpressionVal(fieldQueryValue);
  1368. }
  1369. if(fieldQueryValueType == "text")
  1370. {
  1371. val = "'" + val + "'";
  1372. }
  1373. condi += val;
  1374. }
  1375. }
  1376. var db = initDb(queryTable.databaseId);
  1377. string sql = "select " + fields + " from " + queryTable.tableEnName + " where 1=1" + condi;
  1378. var items = db.Ado.GetDataTable(sql);
  1379. if(items.Rows.Count > 0)
  1380. {
  1381. foreach(string field in fieldDic.Keys)
  1382. {
  1383. if(!dic.Any(m => m.FieldEnName == field)) dic.Add(new QueryCondition()
  1384. {
  1385. FieldName = fieldDic[field],
  1386. FieldEnName = field,
  1387. Value = items.Rows[0][field].ToString()
  1388. });
  1389. }
  1390. }
  1391. }
  1392. return dic;
  1393. }
  1394. //奖励入库
  1395. public static void prizeToDatabase(int projectId, int listId, string content)
  1396. {
  1397. var prizeInTableService = App.GetService<IPriPrizeInTableService>();
  1398. var prizeInFieldService = App.GetService<IPriPrizeInFieldService>();
  1399. var prizeInQueryFieldService = App.GetService<IPriPrizeInQueryFieldService>();
  1400. //入库表
  1401. var prizeInTables = prizeInTableService.GetList(m => m.listId == listId);
  1402. foreach(var prizeInTable in prizeInTables)
  1403. {
  1404. var db = initDb(prizeInTable.databaseId);
  1405. Dictionary<string, object> doFields = new Dictionary<string, object>();
  1406. //入库字段
  1407. var prizeInFields = prizeInFieldService.GetList(m => m.inTableId == prizeInTable.id);
  1408. foreach(var prizeInField in prizeInFields)
  1409. {
  1410. string fieldEnName = prizeInField.fieldEnName;
  1411. string fieldQueryModel = prizeInField.fieldQueryModel;
  1412. string fieldQueryValue = prizeInField.fieldQueryValue;
  1413. string fieldQueryValueType = prizeInField.fieldQueryValueType;
  1414. if(fieldQueryModel == "request_param")
  1415. {
  1416. Dictionary<string, string> req = getRequestParams(projectId, content);
  1417. fieldQueryValue = req.ContainsKey(fieldQueryValue) ? req[fieldQueryValue] : "0";
  1418. }
  1419. else if(fieldQueryModel == "query_field")
  1420. {
  1421. }
  1422. else if(fieldQueryModel == "fixed_value")
  1423. {
  1424. fieldQueryValue = GetExpressionVal(fieldQueryValue);
  1425. }
  1426. else if(fieldQueryModel == "db_field")
  1427. {
  1428. fieldQueryValue = GetDbExpressionVal(fieldQueryValue);
  1429. }
  1430. if(fieldQueryValueType == "text") doFields.Add(fieldEnName, fieldQueryValue);
  1431. if(fieldQueryValueType == "int") doFields.Add(fieldEnName, int.Parse(fieldQueryValue));
  1432. if(fieldQueryValueType == "number") doFields.Add(fieldEnName, decimal.Parse(fieldQueryValue));
  1433. if(fieldQueryValueType == "datetime") doFields.Add(fieldEnName, DateTime.Parse(fieldQueryValue));
  1434. if(fieldQueryValueType == "bool") doFields.Add(fieldEnName, bool.Parse(fieldQueryValue));
  1435. }
  1436. //查询匹配条件
  1437. string condi = "";
  1438. var queryFields = prizeInQueryFieldService.GetList(m => m.inTableId == prizeInTable.id);
  1439. foreach(var queryField in queryFields)
  1440. {
  1441. string fieldEnName = queryField.fieldEnName;
  1442. string fieldQueryKind = queryField.fieldQueryKind;
  1443. string fieldQueryModel = queryField.fieldQueryModel;
  1444. string fieldQueryValue = queryField.fieldQueryValue;
  1445. string fieldQueryValueType = queryField.fieldQueryValueType;
  1446. if(fieldQueryKind == "1") //模糊匹配
  1447. {
  1448. condi += " and " + fieldEnName + " like ";
  1449. if(fieldQueryModel == "request_param")
  1450. {
  1451. Dictionary<string, string> req = getRequestParams(projectId, content);
  1452. string val = req.ContainsKey(fieldQueryValue) ? req[fieldQueryValue] : "0";
  1453. condi += "'%" + val + "%'";
  1454. }
  1455. else if(fieldQueryModel == "fixed_value")
  1456. {
  1457. condi += "'%" + fieldQueryValue + "%'";
  1458. }
  1459. }
  1460. else if(fieldQueryKind == "2") //精确匹配
  1461. {
  1462. condi += " and " + fieldEnName + "=";
  1463. string val = "";
  1464. if(fieldQueryModel == "request_param")
  1465. {
  1466. Dictionary<string, string> req = getRequestParams(projectId, content);
  1467. val = req.ContainsKey(fieldQueryValue) ? req[fieldQueryValue] : "0";
  1468. }
  1469. else if(fieldQueryModel == "fixed_value")
  1470. {
  1471. val = fieldQueryValue;
  1472. }
  1473. if(fieldQueryValueType == "text")
  1474. {
  1475. val = "'" + val + "'";
  1476. }
  1477. condi += val;
  1478. }
  1479. else if(fieldQueryKind == "5" || fieldQueryKind == "6") //数组匹配/排除
  1480. {
  1481. if(fieldQueryKind == "5") condi += " and " + fieldEnName + " in (";
  1482. else if(fieldQueryKind == "6") condi += " and " + fieldEnName + " not in (";
  1483. string val = "";
  1484. string[] valList = fieldQueryValue.Split(',');
  1485. if(fieldQueryModel == "request_param")
  1486. {
  1487. Dictionary<string, string> req = getRequestParams(projectId, content);
  1488. foreach(string sub in valList)
  1489. {
  1490. if(fieldQueryValueType == "text")
  1491. {
  1492. val += "'" + req[sub] + "',";
  1493. }
  1494. else
  1495. {
  1496. val += req[sub] + ",";
  1497. }
  1498. }
  1499. }
  1500. else if(fieldQueryModel == "fixed_value")
  1501. {
  1502. foreach(string sub in valList)
  1503. {
  1504. if(fieldQueryValueType == "text")
  1505. {
  1506. val += "'" + GetExpressionVal(sub) + "',";
  1507. }
  1508. else
  1509. {
  1510. val += GetExpressionVal(sub) + ",";
  1511. }
  1512. }
  1513. }
  1514. else if(fieldQueryModel == "db_field")
  1515. {
  1516. foreach(string sub in valList)
  1517. {
  1518. if(fieldQueryValueType == "text")
  1519. {
  1520. val += "'" + GetDbExpressionVal(sub) + "',";
  1521. }
  1522. else
  1523. {
  1524. val += GetDbExpressionVal(sub) + ",";
  1525. }
  1526. }
  1527. }
  1528. val = val.TrimEnd(',');
  1529. condi += val + ")";
  1530. }
  1531. else if(fieldQueryKind == "3") //范围匹配
  1532. {
  1533. string[] val = fieldQueryValue.Split(':');
  1534. if(fieldQueryModel == "request_param")
  1535. {
  1536. Dictionary<string, string> req = getRequestParams(projectId, content);
  1537. if(fieldQueryValueType == "number")
  1538. {
  1539. if(!string.IsNullOrEmpty(req[val[0]])) condi += " and " + fieldEnName + ">=" + req[val[0]];
  1540. if(!string.IsNullOrEmpty(req[val[1]])) condi += " and " + fieldEnName + "<=" + req[val[1]];
  1541. }
  1542. else
  1543. {
  1544. if(!string.IsNullOrEmpty(req[val[0]])) condi += " and " + fieldEnName + ">='" + req[val[0]] + "'";
  1545. if(!string.IsNullOrEmpty(req[val[1]])) condi += " and " + fieldEnName + "<='" + req[val[1]] + "'";
  1546. }
  1547. }
  1548. else if(fieldQueryModel == "fixed_value")
  1549. {
  1550. if(fieldQueryValueType == "number")
  1551. {
  1552. if(!string.IsNullOrEmpty(val[0])) condi += " and " + fieldEnName + ">=" + val[0];
  1553. if(!string.IsNullOrEmpty(val[1])) condi += " and " + fieldEnName + "<=" + val[1];
  1554. }
  1555. else
  1556. {
  1557. if(!string.IsNullOrEmpty(val[0])) condi += " and " + fieldEnName + ">='" + val[0] + "'";
  1558. if(!string.IsNullOrEmpty(val[1])) condi += " and " + fieldEnName + "<='" + val[1] + "'";
  1559. }
  1560. }
  1561. }
  1562. else if(fieldQueryKind == "4") //取反匹配
  1563. {
  1564. condi += " and " + fieldEnName + "!=";
  1565. string val = "";
  1566. if(fieldQueryModel == "request_param")
  1567. {
  1568. Dictionary<string, string> req = getRequestParams(projectId, content);
  1569. val = req.ContainsKey(fieldQueryValue) ? req[fieldQueryValue] : "0";
  1570. }
  1571. else if(fieldQueryModel == "fixed_value")
  1572. {
  1573. val = fieldQueryValue;
  1574. }
  1575. if(fieldQueryValueType == "text")
  1576. {
  1577. val = "'" + val + "'";
  1578. }
  1579. condi += val;
  1580. }
  1581. }
  1582. // if(prizeInTable.excuteKind == "add") db.Insertable(doFields).AS(prizeInTable.tableEnName).ExecuteCommand();
  1583. // if(prizeInTable.excuteKind == "update") db.Updateable(doFields).AS(prizeInTable.tableEnName).Where("1=1" + condi).ExecuteCommand();
  1584. Function.WriteLog(DateTime.Now.ToString() + "\n" + prizeInTable.excuteKind + "\n" + prizeInTable.tableEnName + "\n" + Newtonsoft.Json.JsonConvert.SerializeObject(doFields) + "\n\n", "奖励入库数据");
  1585. }
  1586. }
  1587. //固定值表达式
  1588. public static string GetExpressionVal(string str)
  1589. {
  1590. if(str == "#{now}#") str = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  1591. if(str == "#{today}#") str = DateTime.Now.ToString("yyyy-MM-dd");
  1592. if(str == "#{this_month}#") str = DateTime.Now.ToString("yyyy-MM");
  1593. if(str.StartsWith("#{now") && str.EndsWith("DAY}#")) str = DateTime.Now.AddDays(int.Parse(str.Replace("#", "").Replace("{", "").Replace("}", "").Split(',')[1])).ToString("yyyy-MM-dd HH:mm:ss");
  1594. if(str.StartsWith("#{now") && str.EndsWith("MONTH}#")) str = DateTime.Now.AddMonths(int.Parse(str.Replace("#", "").Replace("{", "").Replace("}", "").Split(',')[1])).ToString("yyyy-MM-dd HH:mm:ss");
  1595. if(str.StartsWith("#{today") && str.EndsWith("DAY}#")) str = DateTime.Now.AddDays(int.Parse(str.Replace("#", "").Replace("{", "").Replace("}", "").Split(',')[1])).ToString("yyyy-MM-dd");
  1596. if(str.StartsWith("#{today") && str.EndsWith("MONTH}#")) str = DateTime.Now.AddMonths(int.Parse(str.Replace("#", "").Replace("{", "").Replace("}", "").Split(',')[1])).ToString("yyyy-MM-dd");
  1597. if(str.StartsWith("#{this_month") && str.EndsWith("DAY}#")) str = DateTime.Now.AddDays(int.Parse(str.Replace("#", "").Replace("{", "").Replace("}", "").Split(',')[1])).ToString("yyyy-MM");
  1598. if(str.StartsWith("#{this_month") && str.EndsWith("MONTH}#")) str = DateTime.Now.AddMonths(int.Parse(str.Replace("#", "").Replace("{", "").Replace("}", "").Split(',')[1])).ToString("yyyy-MM");
  1599. return str;
  1600. }
  1601. //库内字段值表达式
  1602. public static string GetDbExpressionVal(string str)
  1603. {
  1604. string[] data = str.Replace("#", "").Replace("{", "").Replace("}", "").Split(',');
  1605. if(str.StartsWith("#{") && str.EndsWith("DAY}#")) str = "DATE_ADD(" + data[0] + ",INTERVAL " + data[1] + " DAY)";
  1606. if(str.StartsWith("#{") && str.EndsWith("MONTH}#")) str = "DATE_ADD(" + data[0] + ",INTERVAL " + data[1] + " MONTH)";
  1607. return str;
  1608. }
  1609. //获取查询条件数据
  1610. public static string GetQueryTableData(List<QueryCondition> condiDic, string key)
  1611. {
  1612. return condiDic.Any(m => m.FieldEnName == key) ? condiDic.FirstOrDefault(m => m.FieldEnName == key).Value.ToString() : "0";
  1613. }
  1614. public static string GetQueryTableTitle(List<QueryCondition> condiDic, string key)
  1615. {
  1616. return condiDic.Any(m => m.FieldEnName == key) ? condiDic.FirstOrDefault(m => m.FieldEnName == key).FieldName : "";
  1617. }
  1618. //记录日志
  1619. public static void addLog(int projectId, int prizeIn, string requestParam)
  1620. {
  1621. var logService = App.GetService<IPriLogService>();
  1622. logService.Add(new PriLog()
  1623. {
  1624. createDate = DateTime.Now,
  1625. projectId = projectId,
  1626. batchNo = batchNo,
  1627. prizeIn = prizeIn,
  1628. requestParam = requestParam,
  1629. });
  1630. }
  1631. public static void setLogPrizeAmount(decimal prizeAmount)
  1632. {
  1633. var logService = App.GetService<IPriLogService>();
  1634. var log = logService.GetFirst(m => m.batchNo == batchNo);
  1635. if(log != null)
  1636. {
  1637. log.prizeAmount = prizeAmount;
  1638. logService.Update(log);
  1639. }
  1640. }
  1641. public static void setLogStep(string step)
  1642. {
  1643. var logService = App.GetService<IPriLogService>();
  1644. var log = logService.GetFirst(m => m.batchNo == batchNo);
  1645. if(log != null)
  1646. {
  1647. log.stepList = step;
  1648. logService.Update(log);
  1649. }
  1650. }
  1651. public static void setLogStatus(int status)
  1652. {
  1653. var logService = App.GetService<IPriLogService>();
  1654. var log = logService.GetFirst(m => m.batchNo == batchNo);
  1655. if(log != null)
  1656. {
  1657. log.status = status;
  1658. logService.Update(log);
  1659. }
  1660. }
  1661. }
  1662. }