PrizeDo.cs 112 KB

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