|
@@ -11,6 +11,22 @@ namespace Util
|
|
|
public class PrizeDo
|
|
|
{
|
|
|
public static string batchNo = "";
|
|
|
+ //发奖入口
|
|
|
+ public static void sendPrize(string content)
|
|
|
+ {
|
|
|
+ batchNo = DateTime.Now.ToString("yyyyMMddHHmmssfff") + Function.get_Random(3);
|
|
|
+ int projectId = 1;
|
|
|
+ string priObjString = prizeObject(projectId, content);
|
|
|
+ if(!string.IsNullOrEmpty(priObjString))
|
|
|
+ {
|
|
|
+ string[] priObjData = priObjString.Split('|');
|
|
|
+ string priObj = priObjData[0];
|
|
|
+ string priListIds = priObjData[1];
|
|
|
+ prizeSend(projectId, priListIds, priObj, content);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
//接收入参
|
|
|
public static Dictionary<string, string> getRequestParams(string content)
|
|
|
{
|
|
@@ -166,7 +182,7 @@ namespace Util
|
|
|
}
|
|
|
|
|
|
//奖励发放对象
|
|
|
- public static object prizeObject(int projectId, string content)
|
|
|
+ public static string prizeObject(int projectId, string content)
|
|
|
{
|
|
|
Dictionary<string, object> dic = new Dictionary<string, object>();
|
|
|
var prizeObjectTableService = App.GetService<IPriPrizeObjectTableService>();
|
|
@@ -272,8 +288,11 @@ namespace Util
|
|
|
|
|
|
var db = initDb(projectId);
|
|
|
var item = db.SqlQueryable<Dictionary<string, object>>("select " + field + " from " + prizeObjectTable.tableEnName + " where 1=1" + condi).First();
|
|
|
-
|
|
|
- return item[field];
|
|
|
+ if(item != null)
|
|
|
+ {
|
|
|
+ return item[field].ToString() + "|" + prizeObjectTable.prizeListIds;
|
|
|
+ }
|
|
|
+ return "";
|
|
|
}
|
|
|
|
|
|
//奖励列表
|
|
@@ -288,6 +307,13 @@ namespace Util
|
|
|
//奖励发放
|
|
|
public static void prizeSend(int projectId, string prizeIds, 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 condiDic = condition(projectId, content);
|
|
|
+
|
|
|
var priList = prizeList(projectId, prizeIds);
|
|
|
foreach(var sub in priList)
|
|
|
{
|
|
@@ -296,42 +322,136 @@ namespace Util
|
|
|
var prizeContent = sub.prizeContent; //奖励内容
|
|
|
var conditionMode = sub.conditionMode; //条件模式
|
|
|
var recursionFlag = sub.recursionFlag; //是否递归
|
|
|
- if(prizePercent > 0)
|
|
|
+
|
|
|
+ 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; //匹配值类型
|
|
|
|
|
|
- }
|
|
|
- if(prizeAmount > 0)
|
|
|
- {
|
|
|
- var recordService = App.GetService<IPriRecordService>();
|
|
|
- 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)
|
|
|
+ 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") //模糊匹配
|
|
|
{
|
|
|
- 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(fieldQueryValueType == "text")
|
|
|
+ {
|
|
|
+ if(checkObj.ToString().Contains(GetExpressionVal(checkVal))) passCount += 1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if(fieldQueryKind == "2") //精确匹配
|
|
|
+ {
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if(fieldQueryKind == "3") //范围匹配
|
|
|
+ {
|
|
|
+ string[] val = checkVal.Split(':');
|
|
|
+ if(fieldQueryModel == "request_param")
|
|
|
+ {
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if(fieldQueryModel == "fixed_value")
|
|
|
+ {
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if(fieldQueryKind == "4") //取反匹配
|
|
|
+ {
|
|
|
+ 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(fieldQueryValueType == "text")
|
|
|
+ {
|
|
|
+ if(checkObj.ToString() != GetExpressionVal(checkVal)) passCount += 1;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
- else
|
|
|
+ bool op = false;
|
|
|
+ if(conditionMode == "all" && passCount == allCount) op = true;
|
|
|
+ else if(conditionMode == "one" && passCount == 1) op = true;
|
|
|
+ if(op) //满足条件
|
|
|
{
|
|
|
- var conditionService = App.GetService<IPriConditionService>();
|
|
|
- var conditions = conditionService.GetList(m => m.listId == sub.id);
|
|
|
- foreach(var condition in conditions)
|
|
|
+ if(prizePercent > 0)
|
|
|
+ {
|
|
|
+
|
|
|
+ }
|
|
|
+ if(prizeAmount > 0)
|
|
|
{
|
|
|
- var returnFieldId = condition.returnFieldId; //条件返回字段
|
|
|
- var fieldQueryKind = condition.fieldQueryKind; //匹配条件
|
|
|
- var fieldQueryModel = condition.fieldQueryModel; //匹配方式
|
|
|
- var fieldQueryValue = condition.fieldQueryValue; //匹配值
|
|
|
- var fieldQueryValueType = condition.fieldQueryValueType; //匹配值类型
|
|
|
+ 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); //入库
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|