PrizeDo.cs 112 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958
  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. index += 1;
  921. }
  922. setLogStep(sub.id, Newtonsoft.Json.JsonConvert.SerializeObject(topStepDic));
  923. }
  924. else
  925. {
  926. prizeSendDo(projectId, sub, prizeObjectId, content, new PriLoopSet());
  927. }
  928. }
  929. }
  930. static decimal loopAmount = 0;
  931. public static decimal prizeSendDo(int projectId, PriList sub, string prizeObjectId, string content, PriLoopSet set)
  932. {
  933. var recordService = App.GetService<IPriRecordService>();
  934. var conditionService = App.GetService<IPriConditionService>();
  935. var returnFieldService = App.GetService<IPriReturnFieldService>();
  936. var queryTableService = App.GetService<IPriQueryTableService>();
  937. var amountSetService = App.GetService<IPriListAmountSetService>();
  938. //查询匹配条件
  939. List<QueryCondition> condiDic = condiDic = condition(projectId, Tools.SpitIntArrary(sub.queryTableIdList, ',').ToList(), content);
  940. if(sub.prizeSourceFieldType == "loop") MergeCondiDic(condiDic, loopCondition(projectId, sub, prizeObjectId, content));
  941. var prizeSourceField = sub.prizeSourceField; //奖励金额来源字段(对应条件匹配返回字段)
  942. var prizePercent = sub.prizePercent; //奖励比例
  943. var prizeAmount = sub.prizeAmount; //奖励固定值
  944. var prizeContent = sub.prizeContent; //奖励内容
  945. var conditionMode = sub.conditionMode; //条件模式
  946. var recursionFlag = sub.recursionFlag; //是否递归
  947. var conditions = conditionService.GetList(m => m.listId == sub.id);
  948. int allCount = conditions.Count; //所有奖励条件数
  949. int passCount = 0; //通过条件数
  950. List<Dictionary<string, string>> logStepDics = new List<Dictionary<string, string>>();
  951. foreach(var condition in conditions)
  952. {
  953. Dictionary<string, string> logStepDic = new Dictionary<string, string>();
  954. var returnFieldId = condition.returnFieldId; //条件返回字段
  955. var fieldQueryKind = condition.fieldQueryKind; //匹配条件
  956. var fieldQueryModel = condition.fieldQueryModel; //匹配方式
  957. var fieldQueryValue = condition.fieldQueryValue; //匹配值
  958. var fieldQueryValueType = condition.fieldQueryValueType; //匹配值类型
  959. string checkObj = "";
  960. string checkTitle = "";
  961. if(returnFieldId.Contains(","))
  962. {
  963. string[] returnFieldIdList = returnFieldId.Split(',');
  964. foreach(string subField in returnFieldIdList)
  965. {
  966. string val = GetQueryTableData(condiDic, subField);
  967. checkObj += val + ",";
  968. string title = GetQueryTableTitle(condiDic, subField);
  969. checkTitle += title + ",";
  970. }
  971. checkObj = checkObj.TrimEnd(',');
  972. checkTitle = checkTitle.TrimEnd(',');
  973. }
  974. else if (returnFieldId.Contains("+") || returnFieldId.Contains("-") || returnFieldId.Contains("*") || returnFieldId.Contains("/") || returnFieldId.Contains("(") || returnFieldId.Contains(")"))
  975. {
  976. string expresssion = returnFieldId;
  977. checkTitle = returnFieldId;
  978. string[] returnFields = returnFieldId.Split(new char[] { '+', '-', '*', '/', '(', ')' });
  979. foreach(string returnField in returnFields)
  980. {
  981. string val = GetQueryTableData(condiDic, returnField);
  982. expresssion = expresssion.Replace(returnField, val);
  983. string title = GetQueryTableTitle(condiDic, returnField);
  984. checkTitle = checkTitle.Replace(returnField, title);
  985. }
  986. DataTable dt = new DataTable();
  987. checkObj = dt.Compute(expresssion, "false").ToString();
  988. }
  989. else
  990. {
  991. checkObj = GetQueryTableData(condiDic, returnFieldId);
  992. checkTitle = GetQueryTableTitle(condiDic, returnFieldId);
  993. }
  994. if(!sub.recursionFlag)
  995. {
  996. logStepDic.Add("标题", checkTitle);
  997. logStepDic.Add("匹配值", fieldQueryValue);
  998. logStepDic.Add("实际值", checkObj);
  999. }
  1000. string checkVal = fieldQueryValue;
  1001. bool passFlag = false;
  1002. if(fieldQueryKind == "1") //模糊匹配
  1003. {
  1004. if(fieldQueryValueType == "text")
  1005. {
  1006. if(checkObj.ToString().Contains(GetExpressionVal(checkVal)))
  1007. {
  1008. passCount += 1; passFlag = true;
  1009. }
  1010. }
  1011. }
  1012. else if(fieldQueryKind == "2") //精确匹配
  1013. {
  1014. if(fieldQueryValueType == "int")
  1015. {
  1016. if(int.Parse(Function.CheckInt(checkObj.ToString())) == int.Parse(Function.CheckNum(checkVal)))
  1017. {
  1018. passCount += 1; passFlag = true;
  1019. }
  1020. }
  1021. else if(fieldQueryValueType == "number")
  1022. {
  1023. if(decimal.Parse(Function.CheckNum(checkObj.ToString())) == decimal.Parse(Function.CheckNum(checkVal)))
  1024. {
  1025. passCount += 1; passFlag = true;
  1026. }
  1027. }
  1028. else
  1029. {
  1030. if(checkObj.ToString() == GetExpressionVal(checkVal))
  1031. {
  1032. passCount += 1; passFlag = true;
  1033. }
  1034. }
  1035. }
  1036. else if(fieldQueryKind == "3") //范围匹配
  1037. {
  1038. string[] val = checkVal.Split(':');
  1039. string valLeft = val[0];
  1040. string valRight = val[1];
  1041. if(fieldQueryModel == "request_param")
  1042. {
  1043. Dictionary<string, string> req = getRequestParams(projectId, content);
  1044. if(fieldQueryValueType == "number")
  1045. {
  1046. 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])))
  1047. {
  1048. passCount += 1; passFlag = true;
  1049. }
  1050. else if(!string.IsNullOrEmpty(req[valLeft]) && string.IsNullOrEmpty(req[valRight]) && decimal.Parse(checkObj) >= decimal.Parse(Function.CheckNum(req[valLeft])))
  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[valRight])))
  1055. {
  1056. passCount += 1; passFlag = true;
  1057. }
  1058. }
  1059. else if(fieldQueryValueType == "int")
  1060. {
  1061. 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])))
  1062. {
  1063. passCount += 1; passFlag = true;
  1064. }
  1065. else if(!string.IsNullOrEmpty(req[valLeft]) && string.IsNullOrEmpty(req[valRight]) && int.Parse(checkObj) >= int.Parse(Function.CheckInt(req[valLeft])))
  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[valRight])))
  1070. {
  1071. passCount += 1; passFlag = true;
  1072. }
  1073. }
  1074. else if(fieldQueryValueType.StartsWith("date"))
  1075. {
  1076. if(!string.IsNullOrEmpty(req[valLeft]) && !string.IsNullOrEmpty(req[valRight]) && DateTime.Parse(checkObj) >= DateTime.Parse(req[valLeft]) && DateTime.Parse(checkObj) <= DateTime.Parse(req[valRight]))
  1077. {
  1078. passCount += 1; passFlag = true;
  1079. }
  1080. else if(!string.IsNullOrEmpty(req[valLeft]) && string.IsNullOrEmpty(req[valRight]) && DateTime.Parse(checkObj) >= DateTime.Parse(req[valLeft]))
  1081. {
  1082. passCount += 1; passFlag = true;
  1083. }
  1084. else if(string.IsNullOrEmpty(req[valLeft]) && !string.IsNullOrEmpty(req[valRight]) && DateTime.Parse(checkObj) <= DateTime.Parse(req[valRight]))
  1085. {
  1086. passCount += 1; passFlag = true;
  1087. }
  1088. }
  1089. }
  1090. else if(fieldQueryModel == "fixed_value")
  1091. {
  1092. valLeft = GetExpressionVal(valLeft);
  1093. valRight = GetExpressionVal(valRight);
  1094. if(fieldQueryValueType == "number")
  1095. {
  1096. 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)))
  1097. {
  1098. passCount += 1; passFlag = true;
  1099. }
  1100. else if(!string.IsNullOrEmpty(valLeft) && string.IsNullOrEmpty(valRight) && decimal.Parse(Function.CheckNum(checkObj.ToString())) >= decimal.Parse(Function.CheckNum(valLeft)))
  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(valRight)))
  1105. {
  1106. passCount += 1; passFlag = true;
  1107. }
  1108. }
  1109. else if(fieldQueryValueType == "int")
  1110. {
  1111. 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)))
  1112. {
  1113. passCount += 1; passFlag = true;
  1114. }
  1115. else if(!string.IsNullOrEmpty(valLeft) && string.IsNullOrEmpty(valRight) && int.Parse(Function.CheckInt(checkObj.ToString())) >= int.Parse(Function.CheckInt(valLeft)))
  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(valRight)))
  1120. {
  1121. passCount += 1; passFlag = true;
  1122. }
  1123. }
  1124. else if(fieldQueryValueType.StartsWith("date"))
  1125. {
  1126. if(valLeft == "0") valLeft = "";
  1127. if(valRight == "0") valRight = "";
  1128. if(checkObj != "0" && checkObj != "")
  1129. {
  1130. if(!string.IsNullOrEmpty(valLeft) && !string.IsNullOrEmpty(valRight) && DateTime.Parse(checkObj.ToString()) >= DateTime.Parse(GetExpressionVal(valLeft)) && DateTime.Parse(checkObj.ToString()) <= DateTime.Parse(GetExpressionVal(valRight)))
  1131. {
  1132. passCount += 1; passFlag = true;
  1133. }
  1134. else if(!string.IsNullOrEmpty(valLeft) && string.IsNullOrEmpty(valRight) && DateTime.Parse(checkObj.ToString()) >= DateTime.Parse(GetExpressionVal(valLeft)))
  1135. {
  1136. passCount += 1; passFlag = true;
  1137. }
  1138. else if(string.IsNullOrEmpty(valLeft) && !string.IsNullOrEmpty(valRight) && DateTime.Parse(checkObj.ToString()) <= DateTime.Parse(GetExpressionVal(valRight)))
  1139. {
  1140. passCount += 1; passFlag = true;
  1141. }
  1142. }
  1143. }
  1144. }
  1145. else if(fieldQueryModel == "query_field")
  1146. {
  1147. string checkValLeft = valLeft.Replace("#{", "").Replace("}#", "");
  1148. string checkValRight = valRight.Replace("#{", "").Replace("}#", "");
  1149. if(checkValLeft.Contains(",")) checkValLeft = checkValLeft.Split(',')[0];
  1150. if(checkValRight.Contains(",")) checkValRight = checkValRight.Split(',')[0];
  1151. if(!string.IsNullOrEmpty(valLeft)) valLeft = valLeft.Replace(checkValLeft, GetQueryTableData(condiDic, checkValLeft));
  1152. if(!string.IsNullOrEmpty(valRight)) valRight = valRight.Replace(checkValRight, GetQueryTableData(condiDic, checkValRight));
  1153. valLeft = GetExpressionVal(valLeft);
  1154. valRight = GetExpressionVal(valRight);
  1155. if(fieldQueryValueType == "number")
  1156. {
  1157. 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)))
  1158. {
  1159. passCount += 1; passFlag = true;
  1160. }
  1161. else if(!string.IsNullOrEmpty(valLeft) && string.IsNullOrEmpty(valRight) && decimal.Parse(Function.CheckNum(checkObj.ToString())) >= decimal.Parse(Function.CheckNum(valLeft)))
  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(valRight)))
  1166. {
  1167. passCount += 1; passFlag = true;
  1168. }
  1169. }
  1170. else if(fieldQueryValueType == "int")
  1171. {
  1172. 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)))
  1173. {
  1174. passCount += 1; passFlag = true;
  1175. }
  1176. else if(!string.IsNullOrEmpty(valLeft) && string.IsNullOrEmpty(valRight) && int.Parse(Function.CheckInt(checkObj.ToString())) >= int.Parse(Function.CheckInt(valLeft)))
  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(valRight)))
  1181. {
  1182. passCount += 1; passFlag = true;
  1183. }
  1184. }
  1185. else if(fieldQueryValueType.StartsWith("date"))
  1186. {
  1187. if(valLeft == "0") valLeft = "";
  1188. if(valRight == "0") valRight = "";
  1189. if(checkObj != "0" && checkObj != "")
  1190. {
  1191. if(!string.IsNullOrEmpty(valLeft) && !string.IsNullOrEmpty(valRight) && DateTime.Parse(checkObj.ToString()) >= DateTime.Parse(GetExpressionVal(valLeft)) && DateTime.Parse(checkObj.ToString()) <= DateTime.Parse(GetExpressionVal(valRight)))
  1192. {
  1193. passCount += 1; passFlag = true;
  1194. }
  1195. else if(!string.IsNullOrEmpty(valLeft) && string.IsNullOrEmpty(valRight) && DateTime.Parse(checkObj.ToString()) >= DateTime.Parse(GetExpressionVal(valLeft)))
  1196. {
  1197. passCount += 1; passFlag = true;
  1198. }
  1199. else if(string.IsNullOrEmpty(valLeft) && !string.IsNullOrEmpty(valRight) && DateTime.Parse(checkObj.ToString()) <= DateTime.Parse(GetExpressionVal(valRight)))
  1200. {
  1201. passCount += 1; passFlag = true;
  1202. }
  1203. }
  1204. }
  1205. }
  1206. }
  1207. else if(fieldQueryKind == "4") //取反匹配
  1208. {
  1209. if(fieldQueryValueType == "int")
  1210. {
  1211. if(int.Parse(Function.CheckNum(checkObj.ToString())) != int.Parse(Function.CheckInt(checkVal)))
  1212. {
  1213. passCount += 1; passFlag = true;
  1214. }
  1215. }
  1216. else if(fieldQueryValueType == "number")
  1217. {
  1218. if(decimal.Parse(Function.CheckNum(checkObj.ToString())) != decimal.Parse(Function.CheckNum(checkVal)))
  1219. {
  1220. passCount += 1; passFlag = true;
  1221. }
  1222. }
  1223. else if(fieldQueryValueType == "text")
  1224. {
  1225. if(checkObj.ToString() != GetExpressionVal(checkVal))
  1226. {
  1227. passCount += 1; passFlag = true;
  1228. }
  1229. }
  1230. }
  1231. else if(fieldQueryKind == "5" || fieldQueryKind == "6") //数组匹配/排除
  1232. {
  1233. string val = ",";
  1234. string[] valList = checkVal.Split(',');
  1235. if(fieldQueryModel == "request_param")
  1236. {
  1237. Dictionary<string, string> req = getRequestParams(projectId, content);
  1238. foreach(string subVal in valList)
  1239. {
  1240. val += req[subVal] + ",";
  1241. }
  1242. }
  1243. else if(fieldQueryModel == "fixed_value")
  1244. {
  1245. foreach(string subVal in valList)
  1246. {
  1247. val += GetExpressionVal(subVal) + ",";
  1248. }
  1249. }
  1250. else if(fieldQueryModel == "db_field")
  1251. {
  1252. foreach(string subVal in valList)
  1253. {
  1254. val += GetDbExpressionVal(subVal) + ",";
  1255. }
  1256. }
  1257. if (fieldQueryKind == "5" && val.Contains("," + checkObj.ToString() + ","))
  1258. {
  1259. passCount += 1; passFlag = true;
  1260. }
  1261. if(fieldQueryKind == "6" && !val.Contains("," + checkObj.ToString() + ","))
  1262. {
  1263. passCount += 1; passFlag = true;
  1264. }
  1265. }
  1266. if(!sub.recursionFlag)
  1267. {
  1268. logStepDic.Add("状态", passFlag ? "通过" : "未通过");
  1269. logStepDics.Add(logStepDic);
  1270. }
  1271. }
  1272. bool op = false;
  1273. decimal prizeAmt = 0;
  1274. if(conditionMode == "all" && passCount == allCount && passCount > 0) op = true;
  1275. else if(conditionMode == "one" && passCount >= 1) op = true;
  1276. else if(conditionMode == "two" && passCount >= 2) op = true;
  1277. else if(conditionMode == "three" && passCount >= 3) op = true;
  1278. if(op) //满足条件
  1279. {
  1280. decimal number = 0;
  1281. if(prizeSourceField.Contains("/"))
  1282. {
  1283. number = decimal.Parse(prizeSourceField.Split('/')[1]);
  1284. prizeSourceField = prizeSourceField.Split('/')[0];
  1285. }
  1286. string prizeSourceData = "";
  1287. if(prizeSourceField.Contains(","))
  1288. {
  1289. string[] prizeSourceFieldList = prizeSourceField.Split(',');
  1290. foreach(string subField in prizeSourceFieldList)
  1291. {
  1292. string val = GetQueryTableData(condiDic, subField);
  1293. prizeSourceData += val + ",";
  1294. }
  1295. prizeSourceData = prizeSourceData.TrimEnd(',');
  1296. }
  1297. else
  1298. {
  1299. prizeSourceData = GetQueryTableData(condiDic, prizeSourceField);
  1300. }
  1301. if(string.IsNullOrEmpty(prizeSourceData)) prizeSourceData = "0";
  1302. if(prizeSourceField.Contains("/") && number > 0)
  1303. {
  1304. decimal prizeSourceDataNum = decimal.Parse(prizeSourceData) / number;
  1305. prizeSourceData = prizeSourceDataNum.ToString("f2");
  1306. }
  1307. var amountSet = amountSetService.GetFirst(m => m.listId == sub.id && m.prizeSourceField == prizeSourceData);
  1308. if(amountSet != null)
  1309. {
  1310. prizePercent = amountSet.prizePercent;
  1311. prizeAmount = amountSet.prizeAmount;
  1312. }
  1313. if(prizeSourceData.Contains(","))
  1314. {
  1315. string checkField = prizeSourceData.Split(',')[0] + ",";
  1316. amountSet = amountSetService.GetFirst(m => m.listId == sub.id && m.prizeSourceField.StartsWith(checkField) && m.prizeSourceField.EndsWith(",%"));
  1317. if(amountSet != null)
  1318. {
  1319. prizePercent = amountSet.prizePercent;
  1320. prizeAmount = amountSet.prizeAmount;
  1321. prizeSourceData = prizeSourceData.Split(',')[1];
  1322. }
  1323. }
  1324. if(prizePercent > 0) prizeAmt += decimal.Parse(Function.CheckNum(prizeSourceData)) * prizePercent;
  1325. if(prizeAmount > 0) prizeAmt += prizeAmount;
  1326. decimal getPrizeAmount = prizeAmt;
  1327. if(set.levelDiffFlag) prizeAmt -= loopAmount;
  1328. if(prizeAmt > 0)
  1329. {
  1330. setLogPrizeAmount(sub.id, prizeAmt);
  1331. var req = getRequestParams(projectId, content);
  1332. var requestParamField = req[sub.requestParamField];
  1333. var sendFlag = recordService.Any(m => m.prizeObjId == prizeObjectId && m.listId == sub.id && m.requestParamField == requestParamField);
  1334. if(!sendFlag)
  1335. {
  1336. recordService.Add(new PriRecord()
  1337. {
  1338. createDate = DateTime.Now,
  1339. projectId = projectId,
  1340. listId = sub.id,
  1341. prizeAmount = prizeAmt,
  1342. prizeObjId = prizeObjectId,
  1343. requestParamField = requestParamField,
  1344. batchNo = batchNo,
  1345. });
  1346. loopAmount = getPrizeAmount;
  1347. prizeToDatabase(projectId, sub.id, content, condiDic, prizeAmt); //入库
  1348. }
  1349. }
  1350. }
  1351. if(!sub.recursionFlag)
  1352. {
  1353. setLogStatus(sub.id, op ? 1 : 0);
  1354. setLogStep(sub.id, Newtonsoft.Json.JsonConvert.SerializeObject(logStepDics));
  1355. }
  1356. return prizeAmt;
  1357. }
  1358. //递归条件判断
  1359. public static List<QueryCondition> loopCondition(int projectId, PriList sub, string objId, string content)
  1360. {
  1361. List<QueryCondition> dic = new List<QueryCondition>();
  1362. var queryTableService = App.GetService<IPriRecursionStartTableService>();
  1363. var queryFieldService = App.GetService<IPriRecursionStartFieldService>();
  1364. var queryReturnFieldService = App.GetService<IPriRecursionStartReturnFieldService>();
  1365. int passCount = 0;
  1366. //查询表
  1367. var queryTables = queryTableService.GetList(m => m.listId == sub.id);
  1368. int allCount = queryTables.Count;
  1369. foreach(var queryTable in queryTables)
  1370. {
  1371. //查询返回字段
  1372. string fields = "1";
  1373. Dictionary<string, string> fieldDic = new Dictionary<string, string>();
  1374. var returnFields = queryReturnFieldService.GetList(m => m.objectTableId == queryTable.id);
  1375. if(returnFields.Count > 0)
  1376. {
  1377. fields = "";
  1378. foreach(var returnField in returnFields)
  1379. {
  1380. if(returnField.fieldReturnKind == "2")
  1381. {
  1382. fields += "count(" + returnField.fieldEnName + ") " + queryTable.tableEnName + "_" + returnField.fieldEnName + ",";
  1383. }
  1384. else if(returnField.fieldReturnKind == "3")
  1385. {
  1386. fields += "sum(" + returnField.fieldEnName + ") " + queryTable.tableEnName + "_" + returnField.fieldEnName + ",";
  1387. }
  1388. else if(returnField.fieldReturnKind == "4")
  1389. {
  1390. fields += "avg(" + returnField.fieldEnName + ") " + queryTable.tableEnName + "_" + returnField.fieldEnName + ",";
  1391. }
  1392. else
  1393. {
  1394. fields += returnField.fieldEnName + " " + queryTable.tableEnName + "_" + returnField.fieldEnName + ",";
  1395. }
  1396. fieldDic.Add(queryTable.tableEnName + "_" + returnField.fieldEnName, returnField.fieldName);
  1397. }
  1398. fields = fields.TrimEnd(',');
  1399. }
  1400. //查询匹配条件
  1401. string condi = "";
  1402. var queryFields = queryFieldService.GetList(m => m.objectTableId == queryTable.id);
  1403. foreach(var queryField in queryFields)
  1404. {
  1405. string fieldEnName = queryField.fieldEnName;
  1406. string fieldQueryKind = queryField.fieldQueryKind;
  1407. string fieldQueryModel = queryField.fieldQueryModel;
  1408. string fieldQueryValue = queryField.fieldQueryValue;
  1409. if(fieldQueryModel == "loop_field") fieldQueryValue = objId;
  1410. string fieldQueryValueType = queryField.fieldQueryValueType;
  1411. if(fieldQueryKind == "1") //模糊匹配
  1412. {
  1413. condi += " and " + fieldEnName + " like ";
  1414. if(fieldQueryModel == "request_param")
  1415. {
  1416. Dictionary<string, string> req = getRequestParams(projectId, content);
  1417. string val = req.ContainsKey(fieldQueryValue) ? req[fieldQueryValue] : "0";
  1418. condi += "'%" + val + "%'";
  1419. }
  1420. else if(fieldQueryModel == "fixed_value")
  1421. {
  1422. condi += "'%" + GetExpressionVal(fieldQueryValue) + "%'";
  1423. }
  1424. else if(fieldQueryModel == "db_field")
  1425. {
  1426. condi += "'%" + GetDbExpressionVal(fieldQueryValue) + "%'";
  1427. }
  1428. }
  1429. else if(fieldQueryKind == "2") //精确匹配
  1430. {
  1431. condi += " and " + fieldEnName + "=";
  1432. string val = fieldQueryValue;
  1433. if(fieldQueryModel == "request_param")
  1434. {
  1435. Dictionary<string, string> req = getRequestParams(projectId, content);
  1436. val = req.ContainsKey(fieldQueryValue) ? req[fieldQueryValue] : "0";
  1437. }
  1438. else if(fieldQueryModel == "fixed_value")
  1439. {
  1440. val = GetExpressionVal(fieldQueryValue);
  1441. }
  1442. else if(fieldQueryModel == "db_field")
  1443. {
  1444. val = GetDbExpressionVal(fieldQueryValue);
  1445. }
  1446. if(fieldQueryValueType == "text")
  1447. {
  1448. val = "'" + val + "'";
  1449. }
  1450. condi += val;
  1451. }
  1452. else if(fieldQueryKind == "5" || fieldQueryKind == "6") //数组匹配/排除
  1453. {
  1454. if(fieldQueryKind == "5") condi += " and " + fieldEnName + " in (";
  1455. else if(fieldQueryKind == "6") condi += " and " + fieldEnName + " not in (";
  1456. string val = "";
  1457. string[] valList = fieldQueryValue.Split(',');
  1458. if(fieldQueryModel == "request_param")
  1459. {
  1460. Dictionary<string, string> req = getRequestParams(projectId, content);
  1461. foreach(string subval in valList)
  1462. {
  1463. if(fieldQueryValueType == "text")
  1464. {
  1465. val += "'" + req[subval] + "',";
  1466. }
  1467. else
  1468. {
  1469. val += req[subval] + ",";
  1470. }
  1471. }
  1472. }
  1473. else if(fieldQueryModel == "fixed_value")
  1474. {
  1475. foreach(string subval in valList)
  1476. {
  1477. if(fieldQueryValueType == "text")
  1478. {
  1479. val += "'" + GetExpressionVal(subval) + "',";
  1480. }
  1481. else
  1482. {
  1483. val += GetExpressionVal(subval) + ",";
  1484. }
  1485. }
  1486. }
  1487. else if(fieldQueryModel == "db_field")
  1488. {
  1489. foreach(string subval in valList)
  1490. {
  1491. if(fieldQueryValueType == "text")
  1492. {
  1493. val += "'" + GetDbExpressionVal(subval) + "',";
  1494. }
  1495. else
  1496. {
  1497. val += GetDbExpressionVal(subval) + ",";
  1498. }
  1499. }
  1500. }
  1501. val = val.TrimEnd(',');
  1502. condi += val + ")";
  1503. }
  1504. else if(fieldQueryKind == "3") //范围匹配
  1505. {
  1506. string[] val = fieldQueryValue.Split(':');
  1507. if(fieldQueryModel == "request_param")
  1508. {
  1509. Dictionary<string, string> req = getRequestParams(projectId, content);
  1510. if(fieldQueryValueType == "number")
  1511. {
  1512. if(!string.IsNullOrEmpty(req[val[0]])) condi += " and " + fieldEnName + ">=" + req[val[0]];
  1513. if(!string.IsNullOrEmpty(req[val[1]])) condi += " and " + fieldEnName + "<=" + req[val[1]];
  1514. }
  1515. else
  1516. {
  1517. if(!string.IsNullOrEmpty(req[val[0]])) condi += " and " + fieldEnName + ">='" + req[val[0]] + "'";
  1518. if(!string.IsNullOrEmpty(req[val[1]])) condi += " and " + fieldEnName + "<='" + req[val[1]] + "'";
  1519. }
  1520. }
  1521. else if(fieldQueryModel == "fixed_value")
  1522. {
  1523. if(fieldQueryValueType == "number")
  1524. {
  1525. if(!string.IsNullOrEmpty(val[0])) condi += " and " + fieldEnName + ">=" + val[0];
  1526. if(!string.IsNullOrEmpty(val[1])) condi += " and " + fieldEnName + "<=" + val[1];
  1527. }
  1528. else
  1529. {
  1530. if(!string.IsNullOrEmpty(val[0])) condi += " and " + fieldEnName + ">='" + GetExpressionVal(val[0]) + "'";
  1531. if(!string.IsNullOrEmpty(val[1])) condi += " and " + fieldEnName + "<='" + GetExpressionVal(val[1]) + "'";
  1532. }
  1533. }
  1534. else if(fieldQueryModel == "db_field")
  1535. {
  1536. if(fieldQueryValueType == "number")
  1537. {
  1538. if(!string.IsNullOrEmpty(val[0])) condi += " and " + fieldEnName + ">=" + val[0];
  1539. if(!string.IsNullOrEmpty(val[1])) condi += " and " + fieldEnName + "<=" + val[1];
  1540. }
  1541. else
  1542. {
  1543. if(!string.IsNullOrEmpty(val[0])) condi += " and " + fieldEnName + ">='" + GetDbExpressionVal(val[0]) + "'";
  1544. if(!string.IsNullOrEmpty(val[1])) condi += " and " + fieldEnName + "<='" + GetDbExpressionVal(val[1]) + "'";
  1545. }
  1546. }
  1547. }
  1548. else if(fieldQueryKind == "4") //取反匹配
  1549. {
  1550. condi += " and " + fieldEnName + "!=";
  1551. string val = "";
  1552. if(fieldQueryModel == "request_param")
  1553. {
  1554. Dictionary<string, string> req = getRequestParams(projectId, content);
  1555. val = req.ContainsKey(fieldQueryValue) ? req[fieldQueryValue] : "0";
  1556. }
  1557. else if(fieldQueryModel == "fixed_value")
  1558. {
  1559. val = GetExpressionVal(fieldQueryValue);
  1560. }
  1561. else if(fieldQueryModel == "db_field")
  1562. {
  1563. val = GetDbExpressionVal(fieldQueryValue);
  1564. }
  1565. if(fieldQueryValueType == "text")
  1566. {
  1567. val = "'" + val + "'";
  1568. }
  1569. condi += val;
  1570. }
  1571. }
  1572. var db = initDb(queryTable.databaseId);
  1573. string sql = "select " + fields + " from " + queryTable.tableEnName + " where 1=1" + condi;
  1574. var items = db.Ado.GetDataTable(sql);
  1575. if(items.Rows.Count > 0)
  1576. {
  1577. foreach(string field in fieldDic.Keys)
  1578. {
  1579. if(!dic.Any(m => m.FieldEnName == field)) dic.Add(new QueryCondition()
  1580. {
  1581. FieldName = fieldDic[field],
  1582. FieldEnName = field,
  1583. Value = items.Rows[0][field].ToString()
  1584. });
  1585. }
  1586. }
  1587. }
  1588. return dic;
  1589. }
  1590. //奖励入库
  1591. public static void prizeToDatabase(int projectId, int listId, string content, List<QueryCondition> condiDic, decimal prize_amt)
  1592. {
  1593. var prizeInTableService = App.GetService<IPriPrizeInTableService>();
  1594. var prizeInFieldService = App.GetService<IPriPrizeInFieldService>();
  1595. var prizeInQueryFieldService = App.GetService<IPriPrizeInQueryFieldService>();
  1596. //入库表
  1597. var prizeInTables = prizeInTableService.GetList(m => m.listId == listId);
  1598. foreach(var prizeInTable in prizeInTables)
  1599. {
  1600. var db = initDb(prizeInTable.databaseId);
  1601. Dictionary<string, object> doFields = new Dictionary<string, object>();
  1602. //入库字段
  1603. var prizeInFields = prizeInFieldService.GetList(m => m.inTableId == prizeInTable.id);
  1604. foreach(var prizeInField in prizeInFields)
  1605. {
  1606. string fieldEnName = prizeInField.fieldEnName;
  1607. string fieldQueryModel = prizeInField.fieldQueryModel;
  1608. string fieldQueryValue = prizeInField.fieldQueryValue;
  1609. string fieldQueryValueType = prizeInField.fieldQueryValueType;
  1610. if(fieldQueryModel == "request_param")
  1611. {
  1612. Dictionary<string, string> req = getRequestParams(projectId, content);
  1613. fieldQueryValue = req.ContainsKey(fieldQueryValue) ? req[fieldQueryValue] : "0";
  1614. }
  1615. else if(fieldQueryModel == "query_field")
  1616. {
  1617. fieldQueryValue = GetQueryTableData(condiDic, fieldQueryValue);
  1618. }
  1619. else if(fieldQueryModel == "fixed_value")
  1620. {
  1621. fieldQueryValue = GetExpressionVal(fieldQueryValue);
  1622. }
  1623. else if(fieldQueryModel == "db_field")
  1624. {
  1625. fieldQueryValue = GetDbExpressionVal(fieldQueryValue);
  1626. }
  1627. else if(fieldQueryModel == "prize_amt")
  1628. {
  1629. fieldQueryValue = prize_amt.ToString();
  1630. }
  1631. if(fieldQueryValueType == "text") doFields.Add(fieldEnName, fieldQueryValue);
  1632. if(fieldQueryValueType == "int") doFields.Add(fieldEnName, int.Parse(fieldQueryValue));
  1633. if(fieldQueryValueType == "number") doFields.Add(fieldEnName, decimal.Parse(fieldQueryValue));
  1634. if(fieldQueryValueType == "datetime") doFields.Add(fieldEnName, DateTime.Parse(fieldQueryValue));
  1635. if(fieldQueryValueType == "bool") doFields.Add(fieldEnName, bool.Parse(fieldQueryValue));
  1636. }
  1637. //查询匹配条件
  1638. string condi = "";
  1639. var queryFields = prizeInQueryFieldService.GetList(m => m.inTableId == prizeInTable.id);
  1640. foreach(var queryField in queryFields)
  1641. {
  1642. string fieldEnName = queryField.fieldEnName;
  1643. string fieldQueryKind = queryField.fieldQueryKind;
  1644. string fieldQueryModel = queryField.fieldQueryModel;
  1645. string fieldQueryValue = queryField.fieldQueryValue;
  1646. string fieldQueryValueType = queryField.fieldQueryValueType;
  1647. if(fieldQueryKind == "1") //模糊匹配
  1648. {
  1649. condi += " and " + fieldEnName + " like ";
  1650. if(fieldQueryModel == "request_param")
  1651. {
  1652. Dictionary<string, string> req = getRequestParams(projectId, content);
  1653. string val = req.ContainsKey(fieldQueryValue) ? req[fieldQueryValue] : "0";
  1654. condi += "'%" + val + "%'";
  1655. }
  1656. else if(fieldQueryModel == "fixed_value")
  1657. {
  1658. condi += "'%" + fieldQueryValue + "%'";
  1659. }
  1660. else if(fieldQueryModel == "query_field")
  1661. {
  1662. condi += "'%" + GetQueryTableData(condiDic, fieldQueryValue) + "%'";
  1663. }
  1664. }
  1665. else if(fieldQueryKind == "2") //精确匹配
  1666. {
  1667. condi += " and " + fieldEnName + "=";
  1668. string val = "";
  1669. if(fieldQueryModel == "request_param")
  1670. {
  1671. Dictionary<string, string> req = getRequestParams(projectId, content);
  1672. val = req.ContainsKey(fieldQueryValue) ? req[fieldQueryValue] : "0";
  1673. }
  1674. else if(fieldQueryModel == "fixed_value")
  1675. {
  1676. val = fieldQueryValue;
  1677. }
  1678. else if(fieldQueryModel == "query_field")
  1679. {
  1680. val = GetQueryTableData(condiDic, fieldQueryValue);
  1681. }
  1682. if(fieldQueryValueType == "text")
  1683. {
  1684. val = "'" + val + "'";
  1685. }
  1686. condi += val;
  1687. }
  1688. else if(fieldQueryKind == "5" || fieldQueryKind == "6") //数组匹配/排除
  1689. {
  1690. if(fieldQueryKind == "5") condi += " and " + fieldEnName + " in (";
  1691. else if(fieldQueryKind == "6") condi += " and " + fieldEnName + " not in (";
  1692. string val = "";
  1693. string[] valList = fieldQueryValue.Split(',');
  1694. if(fieldQueryModel == "request_param")
  1695. {
  1696. Dictionary<string, string> req = getRequestParams(projectId, content);
  1697. foreach(string sub in valList)
  1698. {
  1699. if(fieldQueryValueType == "text")
  1700. {
  1701. val += "'" + req[sub] + "',";
  1702. }
  1703. else
  1704. {
  1705. val += req[sub] + ",";
  1706. }
  1707. }
  1708. }
  1709. else if(fieldQueryModel == "fixed_value")
  1710. {
  1711. foreach(string sub in valList)
  1712. {
  1713. if(fieldQueryValueType == "text")
  1714. {
  1715. val += "'" + GetExpressionVal(sub) + "',";
  1716. }
  1717. else
  1718. {
  1719. val += GetExpressionVal(sub) + ",";
  1720. }
  1721. }
  1722. }
  1723. else if(fieldQueryModel == "query_field")
  1724. {
  1725. foreach(string sub in valList)
  1726. {
  1727. if(fieldQueryValueType == "text")
  1728. {
  1729. val += "'" + GetQueryTableData(condiDic, sub) + "',";
  1730. }
  1731. else
  1732. {
  1733. val += GetQueryTableData(condiDic, sub) + ",";
  1734. }
  1735. }
  1736. }
  1737. else if(fieldQueryModel == "db_field")
  1738. {
  1739. foreach(string sub in valList)
  1740. {
  1741. if(fieldQueryValueType == "text")
  1742. {
  1743. val += "'" + GetDbExpressionVal(sub) + "',";
  1744. }
  1745. else
  1746. {
  1747. val += GetDbExpressionVal(sub) + ",";
  1748. }
  1749. }
  1750. }
  1751. val = val.TrimEnd(',');
  1752. condi += val + ")";
  1753. }
  1754. else if(fieldQueryKind == "3") //范围匹配
  1755. {
  1756. string[] val = fieldQueryValue.Split(':');
  1757. if(fieldQueryModel == "request_param")
  1758. {
  1759. Dictionary<string, string> req = getRequestParams(projectId, content);
  1760. if(fieldQueryValueType == "number")
  1761. {
  1762. if(!string.IsNullOrEmpty(req[val[0]])) condi += " and " + fieldEnName + ">=" + req[val[0]];
  1763. if(!string.IsNullOrEmpty(req[val[1]])) condi += " and " + fieldEnName + "<=" + req[val[1]];
  1764. }
  1765. else
  1766. {
  1767. if(!string.IsNullOrEmpty(req[val[0]])) condi += " and " + fieldEnName + ">='" + req[val[0]] + "'";
  1768. if(!string.IsNullOrEmpty(req[val[1]])) condi += " and " + fieldEnName + "<='" + req[val[1]] + "'";
  1769. }
  1770. }
  1771. else if(fieldQueryModel == "fixed_value")
  1772. {
  1773. if(fieldQueryValueType == "number")
  1774. {
  1775. if(!string.IsNullOrEmpty(val[0])) condi += " and " + fieldEnName + ">=" + val[0];
  1776. if(!string.IsNullOrEmpty(val[1])) condi += " and " + fieldEnName + "<=" + val[1];
  1777. }
  1778. else
  1779. {
  1780. if(!string.IsNullOrEmpty(val[0])) condi += " and " + fieldEnName + ">='" + val[0] + "'";
  1781. if(!string.IsNullOrEmpty(val[1])) condi += " and " + fieldEnName + "<='" + val[1] + "'";
  1782. }
  1783. }
  1784. }
  1785. else if(fieldQueryKind == "4") //取反匹配
  1786. {
  1787. condi += " and " + fieldEnName + "!=";
  1788. string val = "";
  1789. if(fieldQueryModel == "request_param")
  1790. {
  1791. Dictionary<string, string> req = getRequestParams(projectId, content);
  1792. val = req.ContainsKey(fieldQueryValue) ? req[fieldQueryValue] : "0";
  1793. }
  1794. else if(fieldQueryModel == "fixed_value")
  1795. {
  1796. val = fieldQueryValue;
  1797. }
  1798. if(fieldQueryValueType == "text")
  1799. {
  1800. val = "'" + val + "'";
  1801. }
  1802. condi += val;
  1803. }
  1804. }
  1805. // if(prizeInTable.excuteKind == "add") db.Insertable(doFields).AS(prizeInTable.tableEnName).ExecuteCommand();
  1806. // if(prizeInTable.excuteKind == "update") db.Updateable(doFields).AS(prizeInTable.tableEnName).Where("1=1" + condi).ExecuteCommand();
  1807. Function.WriteLog(DateTime.Now.ToString() + "\n" + prizeInTable.excuteKind + "\n" + prizeInTable.tableEnName + "\n" + Newtonsoft.Json.JsonConvert.SerializeObject(doFields) + "\n" + condi + "\n\n", "奖励入库数据");
  1808. }
  1809. }
  1810. //固定值表达式
  1811. public static string GetExpressionVal(string str)
  1812. {
  1813. if(str == "#{now}#") return DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  1814. if(str == "#{today}#") return DateTime.Now.ToString("yyyy-MM-dd");
  1815. if(str == "#{this_month}#") return DateTime.Now.ToString("yyyy-MM");
  1816. 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");
  1817. 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");
  1818. if(str.StartsWith("#{today") && str.EndsWith("DAY}#")) return DateTime.Now.AddDays(int.Parse(str.Replace("#", "").Replace("{", "").Replace("}", "").Split(',')[1])).ToString("yyyy-MM-dd");
  1819. if(str.StartsWith("#{today") && str.EndsWith("MONTH}#")) return DateTime.Now.AddMonths(int.Parse(str.Replace("#", "").Replace("{", "").Replace("}", "").Split(',')[1])).ToString("yyyy-MM-dd");
  1820. if(str.StartsWith("#{this_month") && str.EndsWith("DAY}#")) return DateTime.Now.AddDays(int.Parse(str.Replace("#", "").Replace("{", "").Replace("}", "").Split(',')[1])).ToString("yyyy-MM");
  1821. if(str.StartsWith("#{this_month") && str.EndsWith("MONTH}#")) return DateTime.Now.AddMonths(int.Parse(str.Replace("#", "").Replace("{", "").Replace("}", "").Split(',')[1])).ToString("yyyy-MM");
  1822. 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");
  1823. 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");
  1824. return str;
  1825. }
  1826. //库内字段值表达式
  1827. public static string GetDbExpressionVal(string str)
  1828. {
  1829. string[] data = str.Replace("#", "").Replace("{", "").Replace("}", "").Split(',');
  1830. if(str.StartsWith("#{") && str.EndsWith("DAY}#")) str = "DATE_ADD(" + data[0] + ",INTERVAL " + data[1] + " DAY)";
  1831. if(str.StartsWith("#{") && str.EndsWith("MONTH}#")) str = "DATE_ADD(" + data[0] + ",INTERVAL " + data[1] + " MONTH)";
  1832. return str;
  1833. }
  1834. //四则混合运算
  1835. public static string GetComputeVal(List<QueryCondition> condiDic, string expresssion)
  1836. {
  1837. if (expresssion.Contains("+") || expresssion.Contains("-") || expresssion.Contains("*") || expresssion.Contains("/") || expresssion.Contains("(") || expresssion.Contains(")"))
  1838. {
  1839. string[] returnFields = expresssion.Split(new char[] { '+', '-', '*', '/', '(', ')' });
  1840. foreach (string returnField in returnFields)
  1841. {
  1842. if(condiDic.Any(m => m.FieldEnName == returnField))
  1843. {
  1844. string val = GetQueryTableData(condiDic, returnField);
  1845. expresssion = expresssion.Replace(returnField, val);
  1846. }
  1847. }
  1848. DataTable dt = new DataTable();
  1849. return dt.Compute(expresssion, "false").ToString();
  1850. }
  1851. return expresssion;
  1852. }
  1853. //获取查询条件数据
  1854. public static string GetQueryTableData(List<QueryCondition> condiDic, string key)
  1855. {
  1856. return condiDic.Any(m => m.FieldEnName == key) ? condiDic.FirstOrDefault(m => m.FieldEnName == key).Value.ToString() : "0";
  1857. }
  1858. public static string GetQueryTableTitle(List<QueryCondition> condiDic, string key)
  1859. {
  1860. return condiDic.Any(m => m.FieldEnName == key) ? condiDic.FirstOrDefault(m => m.FieldEnName == key).FieldName : "";
  1861. }
  1862. //合并字典
  1863. public static void MergeCondiDic(List<QueryCondition> condiDic, List<QueryCondition> condiDic1)
  1864. {
  1865. foreach(QueryCondition sub in condiDic1)
  1866. {
  1867. condiDic.Add(sub);
  1868. }
  1869. }
  1870. //记录日志
  1871. public static void addLog(int projectId, int listId, int prizeIn, string requestParam)
  1872. {
  1873. var logService = App.GetService<IPriLogService>();
  1874. logService.Add(new PriLog()
  1875. {
  1876. createDate = DateTime.Now,
  1877. projectId = projectId,
  1878. listId = listId,
  1879. batchNo = batchNo,
  1880. prizeIn = prizeIn,
  1881. requestParam = requestParam,
  1882. });
  1883. }
  1884. public static void setLogPrizeAmount(int listId, decimal prizeAmount)
  1885. {
  1886. var logService = App.GetService<IPriLogService>();
  1887. var log = logService.GetFirst(m => m.batchNo == batchNo && m.listId == listId);
  1888. if(log != null)
  1889. {
  1890. log.prizeAmount = prizeAmount;
  1891. logService.Update(log);
  1892. }
  1893. }
  1894. public static void setLogStep(int listId, string step)
  1895. {
  1896. var logService = App.GetService<IPriLogService>();
  1897. var log = logService.GetFirst(m => m.batchNo == batchNo && m.listId == listId);
  1898. if(log != null)
  1899. {
  1900. log.stepList = step;
  1901. logService.Update(log);
  1902. }
  1903. }
  1904. public static void setLogStatus(int listId, int status)
  1905. {
  1906. var logService = App.GetService<IPriLogService>();
  1907. var log = logService.GetFirst(m => m.batchNo == batchNo && m.listId == listId);
  1908. if(log != null)
  1909. {
  1910. log.status = status;
  1911. logService.Update(log);
  1912. }
  1913. }
  1914. }
  1915. }