|
@@ -306,153 +306,187 @@ namespace Util
|
|
|
|
|
|
//奖励发放
|
|
|
public static void prizeSend(int projectId, string prizeIds, string prizeObjectId, string content)
|
|
|
+ {
|
|
|
+ var priList = prizeList(projectId, prizeIds);
|
|
|
+ foreach(var sub in priList)
|
|
|
+ {
|
|
|
+ var recursionFlag = sub.recursionFlag; //是否递归
|
|
|
+ if(recursionFlag)
|
|
|
+ {
|
|
|
+ var loopSetService = App.GetService<IPriLoopSetService>();
|
|
|
+ var loopSet = loopSetService.GetFirst(m => m.listId == sub.id) ?? new PriLoopSet();
|
|
|
+ var tableEnName = loopSet.tableEnName; //递归查询表
|
|
|
+ var parentField = loopSet.parentField; //父字段
|
|
|
+ var sonField = loopSet.sonField; //子字段
|
|
|
+ var db = initDb(projectId);
|
|
|
+ string objId = prizeObjectId;
|
|
|
+ while(!string.IsNullOrEmpty(objId) && objId != "0")
|
|
|
+ {
|
|
|
+ prizeSendDo(projectId, sub, objId, content);
|
|
|
+ var parent = db.SqlQueryable<Dictionary<string, object>>("select " + parentField + " from " + tableEnName + " where " + sonField + "=" + objId).First();
|
|
|
+ if(parent != null)
|
|
|
+ {
|
|
|
+ objId = parent[parentField].ToString();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ prizeSendDo(projectId, sub, prizeObjectId, content);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ public static void prizeSendDo(int projectId, PriList sub, string prizeObjectId, string content)
|
|
|
{
|
|
|
var recordService = App.GetService<IPriRecordService>();
|
|
|
var conditionService = App.GetService<IPriConditionService>();
|
|
|
var returnFieldService = App.GetService<IPriReturnFieldService>();
|
|
|
var queryTableService = App.GetService<IPriQueryTableService>();
|
|
|
+ var amountSetService = App.GetService<IPriListAmountSetService>();
|
|
|
//查询匹配条件
|
|
|
var condiDic = condition(projectId, content);
|
|
|
|
|
|
- var priList = prizeList(projectId, prizeIds);
|
|
|
- foreach(var sub in priList)
|
|
|
+ var prizeSourceField = sub.prizeSourceField; //奖励金额来源字段(对应条件匹配返回字段)
|
|
|
+ var prizePercent = sub.prizePercent; //奖励比例
|
|
|
+ var prizeAmount = sub.prizeAmount; //奖励固定值
|
|
|
+ var prizeContent = sub.prizeContent; //奖励内容
|
|
|
+ var conditionMode = sub.conditionMode; //条件模式
|
|
|
+ var recursionFlag = sub.recursionFlag; //是否递归
|
|
|
+
|
|
|
+ var conditions = conditionService.GetList(m => m.listId == sub.id);
|
|
|
+ int allCount = conditions.Count; //所有奖励条件数
|
|
|
+ int passCount = 0; //通过条件数
|
|
|
+ foreach(var condition in conditions)
|
|
|
{
|
|
|
- var requestParamField = sub; //奖励内容
|
|
|
- var prizePercent = sub.prizePercent; //奖励比例
|
|
|
- var prizeAmount = sub.prizeAmount; //奖励固定值
|
|
|
- var prizeContent = sub.prizeContent; //奖励内容
|
|
|
- var conditionMode = sub.conditionMode; //条件模式
|
|
|
- var recursionFlag = sub.recursionFlag; //是否递归
|
|
|
-
|
|
|
- var conditions = conditionService.GetList(m => m.listId == sub.id);
|
|
|
- int allCount = conditions.Count; //所有奖励条件数
|
|
|
- int passCount = 0; //通过条件数
|
|
|
- foreach(var condition in conditions)
|
|
|
- {
|
|
|
- var returnFieldId = condition.returnFieldId; //条件返回字段
|
|
|
- var fieldQueryKind = condition.fieldQueryKind; //匹配条件
|
|
|
- var fieldQueryModel = condition.fieldQueryModel; //匹配方式
|
|
|
- var fieldQueryValue = condition.fieldQueryValue; //匹配值
|
|
|
- var fieldQueryValueType = condition.fieldQueryValueType; //匹配值类型
|
|
|
+ var returnFieldId = condition.returnFieldId; //条件返回字段
|
|
|
+ var fieldQueryKind = condition.fieldQueryKind; //匹配条件
|
|
|
+ var fieldQueryModel = condition.fieldQueryModel; //匹配方式
|
|
|
+ var fieldQueryValue = condition.fieldQueryValue; //匹配值
|
|
|
+ var fieldQueryValueType = condition.fieldQueryValueType; //匹配值类型
|
|
|
|
|
|
- var returnField = returnFieldService.GetFirst(m => m.id == returnFieldId);
|
|
|
- var queryTable = queryTableService.GetFirst(m => m.id == returnField.queryTableId);
|
|
|
- var checkObj = condiDic[queryTable.tableEnName + "-" + returnField.fieldEnName];
|
|
|
- var checkVal = fieldQueryValue;
|
|
|
+ var returnField = returnFieldService.GetFirst(m => m.id == returnFieldId);
|
|
|
+ var queryTable = queryTableService.GetFirst(m => m.id == returnField.queryTableId);
|
|
|
+ var checkObj = condiDic[queryTable.tableEnName + "-" + returnField.fieldEnName];
|
|
|
+ var checkVal = fieldQueryValue;
|
|
|
|
|
|
- if(fieldQueryKind == "1") //模糊匹配
|
|
|
+ if(fieldQueryKind == "1") //模糊匹配
|
|
|
+ {
|
|
|
+ if(fieldQueryValueType == "text")
|
|
|
{
|
|
|
- if(fieldQueryValueType == "text")
|
|
|
- {
|
|
|
- if(checkObj.ToString().Contains(GetExpressionVal(checkVal))) passCount += 1;
|
|
|
- }
|
|
|
+ if(checkObj.ToString().Contains(GetExpressionVal(checkVal))) passCount += 1;
|
|
|
}
|
|
|
- else if(fieldQueryKind == "2") //精确匹配
|
|
|
+ }
|
|
|
+ else if(fieldQueryKind == "2") //精确匹配
|
|
|
+ {
|
|
|
+ if(fieldQueryValueType == "int")
|
|
|
{
|
|
|
- if(fieldQueryValueType == "int")
|
|
|
- {
|
|
|
- if((int)checkObj == int.Parse(Function.CheckInt(checkVal))) passCount += 1;
|
|
|
- }
|
|
|
- else if(fieldQueryValueType == "number")
|
|
|
- {
|
|
|
- if((decimal)checkObj == decimal.Parse(Function.CheckNum(checkVal))) passCount += 1;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- if(checkObj.ToString() == GetExpressionVal(checkVal)) passCount += 1;
|
|
|
- }
|
|
|
+ if((int)checkObj == int.Parse(Function.CheckInt(checkVal))) passCount += 1;
|
|
|
}
|
|
|
- else if(fieldQueryKind == "3") //范围匹配
|
|
|
+ else if(fieldQueryValueType == "number")
|
|
|
{
|
|
|
- string[] val = checkVal.Split(':');
|
|
|
- if(fieldQueryModel == "request_param")
|
|
|
+ if((decimal)checkObj == decimal.Parse(Function.CheckNum(checkVal))) passCount += 1;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if(checkObj.ToString() == GetExpressionVal(checkVal)) passCount += 1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if(fieldQueryKind == "3") //范围匹配
|
|
|
+ {
|
|
|
+ string[] val = checkVal.Split(':');
|
|
|
+ if(fieldQueryModel == "request_param")
|
|
|
+ {
|
|
|
+ Dictionary<string, string> req = getRequestParams(content);
|
|
|
+ if(fieldQueryValueType == "number")
|
|
|
{
|
|
|
- Dictionary<string, string> req = getRequestParams(content);
|
|
|
- if(fieldQueryValueType == "number")
|
|
|
- {
|
|
|
- if(!string.IsNullOrEmpty(req[val[0]]) && !string.IsNullOrEmpty(req[val[1]]) && (decimal)checkObj >= decimal.Parse(Function.CheckNum(req[val[0]])) && (decimal)checkObj <= decimal.Parse(Function.CheckNum(req[val[1]]))) passCount += 1;
|
|
|
- else if(!string.IsNullOrEmpty(req[val[0]]) && string.IsNullOrEmpty(req[val[1]]) && (decimal)checkObj >= decimal.Parse(Function.CheckNum(req[val[0]]))) passCount += 1;
|
|
|
- else if(string.IsNullOrEmpty(req[val[0]]) && !string.IsNullOrEmpty(req[val[1]]) && (decimal)checkObj <= decimal.Parse(Function.CheckNum(req[val[1]]))) passCount += 1;
|
|
|
- }
|
|
|
- else if(fieldQueryValueType == "int")
|
|
|
- {
|
|
|
- if(!string.IsNullOrEmpty(req[val[0]]) && !string.IsNullOrEmpty(req[val[1]]) && (int)checkObj >= int.Parse(Function.CheckInt(req[val[0]])) && (int)checkObj <= int.Parse(Function.CheckInt(req[val[1]]))) passCount += 1;
|
|
|
- else if(!string.IsNullOrEmpty(req[val[0]]) && string.IsNullOrEmpty(req[val[1]]) && (int)checkObj >= int.Parse(Function.CheckInt(req[val[0]]))) passCount += 1;
|
|
|
- else if(string.IsNullOrEmpty(req[val[0]]) && !string.IsNullOrEmpty(req[val[1]]) && (int)checkObj <= int.Parse(Function.CheckInt(req[val[1]]))) passCount += 1;
|
|
|
- }
|
|
|
- else if(fieldQueryValueType.StartsWith("date"))
|
|
|
- {
|
|
|
- if(!string.IsNullOrEmpty(req[val[0]]) && !string.IsNullOrEmpty(req[val[1]]) && (DateTime)checkObj >= DateTime.Parse(req[val[0]]) && (DateTime)checkObj <= DateTime.Parse(req[val[1]])) passCount += 1;
|
|
|
- else if(!string.IsNullOrEmpty(req[val[0]]) && string.IsNullOrEmpty(req[val[1]]) && (DateTime)checkObj >= DateTime.Parse(req[val[0]])) passCount += 1;
|
|
|
- else if(string.IsNullOrEmpty(req[val[0]]) && !string.IsNullOrEmpty(req[val[1]]) && (DateTime)checkObj <= DateTime.Parse(req[val[1]])) passCount += 1;
|
|
|
- }
|
|
|
+ if(!string.IsNullOrEmpty(req[val[0]]) && !string.IsNullOrEmpty(req[val[1]]) && (decimal)checkObj >= decimal.Parse(Function.CheckNum(req[val[0]])) && (decimal)checkObj <= decimal.Parse(Function.CheckNum(req[val[1]]))) passCount += 1;
|
|
|
+ else if(!string.IsNullOrEmpty(req[val[0]]) && string.IsNullOrEmpty(req[val[1]]) && (decimal)checkObj >= decimal.Parse(Function.CheckNum(req[val[0]]))) passCount += 1;
|
|
|
+ else if(string.IsNullOrEmpty(req[val[0]]) && !string.IsNullOrEmpty(req[val[1]]) && (decimal)checkObj <= decimal.Parse(Function.CheckNum(req[val[1]]))) passCount += 1;
|
|
|
}
|
|
|
- else if(fieldQueryModel == "fixed_value")
|
|
|
+ else if(fieldQueryValueType == "int")
|
|
|
{
|
|
|
- if(fieldQueryValueType == "number")
|
|
|
- {
|
|
|
- if(!string.IsNullOrEmpty(val[0]) && !string.IsNullOrEmpty(val[1]) && (decimal)checkObj >= decimal.Parse(Function.CheckNum(val[0])) && (decimal)checkObj <= decimal.Parse(Function.CheckNum(val[1]))) passCount += 1;
|
|
|
- else if(!string.IsNullOrEmpty(val[0]) && string.IsNullOrEmpty(val[1]) && (decimal)checkObj >= decimal.Parse(Function.CheckNum(val[0]))) passCount += 1;
|
|
|
- else if(string.IsNullOrEmpty(val[0]) && !string.IsNullOrEmpty(val[1]) && (decimal)checkObj <= decimal.Parse(Function.CheckNum(val[1]))) passCount += 1;
|
|
|
- }
|
|
|
- else if(fieldQueryValueType == "int")
|
|
|
- {
|
|
|
- if(!string.IsNullOrEmpty(val[0]) && !string.IsNullOrEmpty(val[1]) && (int)checkObj >= int.Parse(Function.CheckInt(val[0])) && (int)checkObj <= int.Parse(Function.CheckInt(val[1]))) passCount += 1;
|
|
|
- else if(!string.IsNullOrEmpty(val[0]) && string.IsNullOrEmpty(val[1]) && (int)checkObj >= int.Parse(Function.CheckInt(val[0]))) passCount += 1;
|
|
|
- else if(string.IsNullOrEmpty(val[0]) && !string.IsNullOrEmpty(val[1]) && (int)checkObj <= int.Parse(Function.CheckInt(val[1]))) passCount += 1;
|
|
|
- }
|
|
|
- else if(fieldQueryValueType.StartsWith("date"))
|
|
|
- {
|
|
|
- if(!string.IsNullOrEmpty(val[0]) && !string.IsNullOrEmpty(val[1]) && (DateTime)checkObj >= DateTime.Parse(GetExpressionVal(val[0])) && (DateTime)checkObj <= DateTime.Parse(GetExpressionVal(val[1]))) passCount += 1;
|
|
|
- else if(!string.IsNullOrEmpty(val[0]) && string.IsNullOrEmpty(val[1]) && (DateTime)checkObj >= DateTime.Parse(GetExpressionVal(val[0]))) passCount += 1;
|
|
|
- else if(string.IsNullOrEmpty(val[0]) && !string.IsNullOrEmpty(val[1]) && (DateTime)checkObj <= DateTime.Parse(GetExpressionVal(val[1]))) passCount += 1;
|
|
|
- }
|
|
|
+ if(!string.IsNullOrEmpty(req[val[0]]) && !string.IsNullOrEmpty(req[val[1]]) && (int)checkObj >= int.Parse(Function.CheckInt(req[val[0]])) && (int)checkObj <= int.Parse(Function.CheckInt(req[val[1]]))) passCount += 1;
|
|
|
+ else if(!string.IsNullOrEmpty(req[val[0]]) && string.IsNullOrEmpty(req[val[1]]) && (int)checkObj >= int.Parse(Function.CheckInt(req[val[0]]))) passCount += 1;
|
|
|
+ else if(string.IsNullOrEmpty(req[val[0]]) && !string.IsNullOrEmpty(req[val[1]]) && (int)checkObj <= int.Parse(Function.CheckInt(req[val[1]]))) passCount += 1;
|
|
|
+ }
|
|
|
+ else if(fieldQueryValueType.StartsWith("date"))
|
|
|
+ {
|
|
|
+ if(!string.IsNullOrEmpty(req[val[0]]) && !string.IsNullOrEmpty(req[val[1]]) && (DateTime)checkObj >= DateTime.Parse(req[val[0]]) && (DateTime)checkObj <= DateTime.Parse(req[val[1]])) passCount += 1;
|
|
|
+ else if(!string.IsNullOrEmpty(req[val[0]]) && string.IsNullOrEmpty(req[val[1]]) && (DateTime)checkObj >= DateTime.Parse(req[val[0]])) passCount += 1;
|
|
|
+ else if(string.IsNullOrEmpty(req[val[0]]) && !string.IsNullOrEmpty(req[val[1]]) && (DateTime)checkObj <= DateTime.Parse(req[val[1]])) passCount += 1;
|
|
|
}
|
|
|
}
|
|
|
- else if(fieldQueryKind == "4") //取反匹配
|
|
|
+ else if(fieldQueryModel == "fixed_value")
|
|
|
{
|
|
|
- if(fieldQueryValueType == "int")
|
|
|
+ if(fieldQueryValueType == "number")
|
|
|
{
|
|
|
- if((int)checkObj != int.Parse(Function.CheckInt(checkVal))) passCount += 1;
|
|
|
+ if(!string.IsNullOrEmpty(val[0]) && !string.IsNullOrEmpty(val[1]) && (decimal)checkObj >= decimal.Parse(Function.CheckNum(val[0])) && (decimal)checkObj <= decimal.Parse(Function.CheckNum(val[1]))) passCount += 1;
|
|
|
+ else if(!string.IsNullOrEmpty(val[0]) && string.IsNullOrEmpty(val[1]) && (decimal)checkObj >= decimal.Parse(Function.CheckNum(val[0]))) passCount += 1;
|
|
|
+ else if(string.IsNullOrEmpty(val[0]) && !string.IsNullOrEmpty(val[1]) && (decimal)checkObj <= decimal.Parse(Function.CheckNum(val[1]))) passCount += 1;
|
|
|
}
|
|
|
- else if(fieldQueryValueType == "number")
|
|
|
+ else if(fieldQueryValueType == "int")
|
|
|
{
|
|
|
- if((decimal)checkObj != decimal.Parse(Function.CheckNum(checkVal))) passCount += 1;
|
|
|
+ if(!string.IsNullOrEmpty(val[0]) && !string.IsNullOrEmpty(val[1]) && (int)checkObj >= int.Parse(Function.CheckInt(val[0])) && (int)checkObj <= int.Parse(Function.CheckInt(val[1]))) passCount += 1;
|
|
|
+ else if(!string.IsNullOrEmpty(val[0]) && string.IsNullOrEmpty(val[1]) && (int)checkObj >= int.Parse(Function.CheckInt(val[0]))) passCount += 1;
|
|
|
+ else if(string.IsNullOrEmpty(val[0]) && !string.IsNullOrEmpty(val[1]) && (int)checkObj <= int.Parse(Function.CheckInt(val[1]))) passCount += 1;
|
|
|
}
|
|
|
- else if(fieldQueryValueType == "text")
|
|
|
+ else if(fieldQueryValueType.StartsWith("date"))
|
|
|
{
|
|
|
- if(checkObj.ToString() != GetExpressionVal(checkVal)) passCount += 1;
|
|
|
+ if(!string.IsNullOrEmpty(val[0]) && !string.IsNullOrEmpty(val[1]) && (DateTime)checkObj >= DateTime.Parse(GetExpressionVal(val[0])) && (DateTime)checkObj <= DateTime.Parse(GetExpressionVal(val[1]))) passCount += 1;
|
|
|
+ else if(!string.IsNullOrEmpty(val[0]) && string.IsNullOrEmpty(val[1]) && (DateTime)checkObj >= DateTime.Parse(GetExpressionVal(val[0]))) passCount += 1;
|
|
|
+ else if(string.IsNullOrEmpty(val[0]) && !string.IsNullOrEmpty(val[1]) && (DateTime)checkObj <= DateTime.Parse(GetExpressionVal(val[1]))) passCount += 1;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- bool op = false;
|
|
|
- if(conditionMode == "all" && passCount == allCount) op = true;
|
|
|
- else if(conditionMode == "one" && passCount == 1) op = true;
|
|
|
- if(op) //满足条件
|
|
|
+ else if(fieldQueryKind == "4") //取反匹配
|
|
|
{
|
|
|
- if(prizePercent > 0)
|
|
|
+ if(fieldQueryValueType == "int")
|
|
|
{
|
|
|
-
|
|
|
+ if((int)checkObj != int.Parse(Function.CheckInt(checkVal))) passCount += 1;
|
|
|
}
|
|
|
- if(prizeAmount > 0)
|
|
|
+ else if(fieldQueryValueType == "number")
|
|
|
{
|
|
|
- var req = getRequestParams(content);
|
|
|
- var requestParamField = req[sub.requestParamField];
|
|
|
- var sendFlag = recordService.Any(m => m.prizeObjId == prizeObjectId && m.listId == sub.id && m.requestParamField == requestParamField);
|
|
|
- if(!sendFlag)
|
|
|
- {
|
|
|
- recordService.Add(new PriRecord()
|
|
|
- {
|
|
|
- createDate = DateTime.Now,
|
|
|
- projectId = projectId,
|
|
|
- listId = sub.id,
|
|
|
- prizeAmount = sub.prizeAmount,
|
|
|
- prizeObjId = prizeObjectId,
|
|
|
- requestParamField = requestParamField,
|
|
|
- batchNo = batchNo,
|
|
|
- });
|
|
|
- // prizeToDatabase(projectId, content); //入库
|
|
|
- }
|
|
|
+ if((decimal)checkObj != decimal.Parse(Function.CheckNum(checkVal))) passCount += 1;
|
|
|
+ }
|
|
|
+ else if(fieldQueryValueType == "text")
|
|
|
+ {
|
|
|
+ if(checkObj.ToString() != GetExpressionVal(checkVal)) passCount += 1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ bool op = false;
|
|
|
+ if(conditionMode == "all" && passCount == allCount) op = true;
|
|
|
+ else if(conditionMode == "one" && passCount == 1) op = true;
|
|
|
+ if(op) //满足条件
|
|
|
+ {
|
|
|
+ string prizeSourceData = condiDic[prizeSourceField].ToString();
|
|
|
+ decimal prizeAmt = 0;
|
|
|
+ var amountSet = amountSetService.GetFirst(m => m.listId == sub.id && m.prizeSourceField == prizeSourceData);
|
|
|
+ if(amountSet != null)
|
|
|
+ {
|
|
|
+ prizePercent = amountSet.prizePercent;
|
|
|
+ prizeAmount = amountSet.prizeAmount;
|
|
|
+ }
|
|
|
+ if(prizePercent > 0) prizeAmt += decimal.Parse(Function.CheckNum(prizeSourceData)) * prizePercent;
|
|
|
+ if(prizeAmount > 0) prizeAmt += prizeAmount;
|
|
|
+ if(prizeAmt > 0)
|
|
|
+ {
|
|
|
+ var req = getRequestParams(content);
|
|
|
+ var requestParamField = req[sub.requestParamField];
|
|
|
+ var sendFlag = recordService.Any(m => m.prizeObjId == prizeObjectId && m.listId == sub.id && m.requestParamField == requestParamField);
|
|
|
+ if(!sendFlag)
|
|
|
+ {
|
|
|
+ recordService.Add(new PriRecord()
|
|
|
+ {
|
|
|
+ createDate = DateTime.Now,
|
|
|
+ projectId = projectId,
|
|
|
+ listId = sub.id,
|
|
|
+ prizeAmount = sub.prizeAmount,
|
|
|
+ prizeObjId = prizeObjectId,
|
|
|
+ requestParamField = requestParamField,
|
|
|
+ batchNo = batchNo,
|
|
|
+ });
|
|
|
+ // prizeToDatabase(projectId, content); //入库
|
|
|
}
|
|
|
}
|
|
|
}
|