|
@@ -64,6 +64,7 @@ namespace MySystem
|
|
|
|
|
|
public void ReturnStat(string orderidstring, int PayMode)
|
|
|
{
|
|
|
+ function.WriteLog("开始返现:" + orderidstring, "返现逻辑日志");
|
|
|
int OrderId = int.Parse(function.CheckInt(orderidstring));
|
|
|
WebCMSEntities db = new WebCMSEntities();
|
|
|
using (var tran = db.Database.BeginTransaction())
|
|
@@ -75,6 +76,7 @@ namespace MySystem
|
|
|
{
|
|
|
decimal PayMoney = order.PayMoney;
|
|
|
int MerchantId = order.MerchantId;
|
|
|
+ function.WriteLog("MerchantId:" + MerchantId, "返现逻辑日志");
|
|
|
MerchantInfo merchant = db.MerchantInfo.FirstOrDefault(m => m.Id == MerchantId);
|
|
|
if (merchant != null)
|
|
|
{
|
|
@@ -98,10 +100,12 @@ namespace MySystem
|
|
|
// decimal TotalActual = 0;
|
|
|
if (IsAll == 0 && PayMoney >= MinPayMoney && GetPercent < 1)
|
|
|
{
|
|
|
+ function.WriteLog("活动开启", "返现逻辑日志");
|
|
|
// PayMoney * (1 - 0.1 - 0.0038 - 0.01);
|
|
|
decimal DiviMoney = PayMoney * (1 - GetPercent - cusumerFeePercent - profitPercent);
|
|
|
if (DiviMoney > 0)
|
|
|
{
|
|
|
+ function.WriteLog("返现队列开始", "返现逻辑日志");
|
|
|
RedisDbconn.Instance.AddRightList("ConsumerOrdersHd:Divi:" + PayMode + ":" + order.MerchantId, order);
|
|
|
DiviMoney = DiviMoney / DiviPersons;
|
|
|
List<int> deletes = new List<int>();
|
|
@@ -116,27 +120,30 @@ namespace MySystem
|
|
|
{
|
|
|
QueueCount = DiviPersons;
|
|
|
}
|
|
|
- decimal OtherMoney = 0; // 退款金额>最大退款金额-当前退款金额,次金额应归还给商户
|
|
|
|
|
|
// 减去自己付的订单
|
|
|
int OutCount = 0; // 出局人数
|
|
|
List<int> orderids = new List<int>();
|
|
|
+ function.WriteLog("人数:" + CurDiviPersons, "返现逻辑日志");
|
|
|
while (CurDiviPersons > 0)
|
|
|
{
|
|
|
ConsumerOrders suborder = RedisDbconn.Instance.RPop<ConsumerOrders>("ConsumerOrdersHd:Divi:" + PayMode + ":" + MerchantId);
|
|
|
if (suborder != null)
|
|
|
{
|
|
|
+ function.WriteLog("返现对象订单:" + suborder.Id, "返现逻辑日志");
|
|
|
MerchantParamSet subset = Newtonsoft.Json.JsonConvert.DeserializeObject<MerchantParamSet>(order.SeoDescription);
|
|
|
int subProfitDays = subset.ProfitDays; //分红期限(天)
|
|
|
bool IsOut = suborder.UpdateDate.Value.AddDays(subProfitDays) < DateTime.Now ? true : false;
|
|
|
if (suborder.CurDivi < suborder.MaxDivi && !IsOut)
|
|
|
{
|
|
|
+ function.WriteLog("没出局:" + suborder.CurDivi + "--" + suborder.MaxDivi, "返现逻辑日志");
|
|
|
//如果没过期并且当前退款金额没超过最大退款金额,就执行
|
|
|
decimal GetMoney = suborder.MaxDivi - suborder.CurDivi;
|
|
|
if (GetMoney >= DiviMoney)
|
|
|
{
|
|
|
GetMoney = DiviMoney;
|
|
|
}
|
|
|
+ function.WriteLog("GetMoney:" + GetMoney, "返现逻辑日志");
|
|
|
if (GetMoney > minProfit)
|
|
|
{
|
|
|
suborder.CurDivi += GetMoney;
|
|
@@ -160,18 +167,23 @@ namespace MySystem
|
|
|
RefundAmount = Math.Round(RefundAmount, 2);
|
|
|
if(!orderids.Contains(suborder.Id))
|
|
|
{
|
|
|
+ function.WriteLog("请求退款接口", "返现逻辑日志");
|
|
|
var info = HaoDaHelper.Instance.AggregatedPayRefund(merchantAdd.OutMchtNo, merchantAdd.StoreNo, "HDTK" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8), suborder.OrderNo, RefundAmount.ToString("f0"));
|
|
|
+ function.WriteLog("接口返回:" + info, "返现逻辑日志");
|
|
|
orderids.Add(suborder.Id);
|
|
|
}
|
|
|
|
|
|
merchant.ActCurrentAmount += Math.Round(GetMoney, 2); //活动已返金额
|
|
|
db.SaveChanges();
|
|
|
+ function.WriteLog(suborder.CurDivi + ":" + suborder.MaxDivi, "返现逻辑日志");
|
|
|
if (suborder.CurDivi < suborder.MaxDivi)
|
|
|
{
|
|
|
+ function.WriteLog("返现未达最大值继续", "返现逻辑日志");
|
|
|
RedisDbconn.Instance.AddList("ConsumerOrdersHd:Divi:" + PayMode + ":" + MerchantId, suborder);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
+ function.WriteLog("返现达最大值,出局", "返现逻辑日志");
|
|
|
OutCount += 1;
|
|
|
}
|
|
|
Thread.Sleep(1000);
|
|
@@ -181,15 +193,18 @@ namespace MySystem
|
|
|
{
|
|
|
//否者计算人数不计入退款名额
|
|
|
CurDiviPersons += 1;
|
|
|
+ function.WriteLog("出局:CurDiviPersons:" + CurDiviPersons, "返现逻辑日志");
|
|
|
}
|
|
|
}
|
|
|
CurDiviPersons -= 1;
|
|
|
QueueCount = RedisDbconn.Instance.Count("ConsumerOrdersHd:Divi:" + PayMode + ":" + MerchantId);
|
|
|
+ function.WriteLog("当前队列数量:" + QueueCount, "返现逻辑日志");
|
|
|
if (QueueCount == 0)
|
|
|
{
|
|
|
CurDiviPersons = 0;
|
|
|
}
|
|
|
}
|
|
|
+ function.WriteLog("返现队列结束", "返现逻辑日志");
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -202,7 +217,8 @@ namespace MySystem
|
|
|
tran.Rollback();
|
|
|
}
|
|
|
}
|
|
|
- db.Dispose();
|
|
|
+ db.Dispose();
|
|
|
+ function.WriteLog("结束返现:" + orderidstring + "\n\n\n", "返现逻辑日志");
|
|
|
}
|
|
|
#endregion
|
|
|
}
|