PrizeDo.cs 84 KB

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