PrizeDo.cs 112 KB

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