|
@@ -31,134 +31,152 @@ namespace MySystem
|
|
}
|
|
}
|
|
#endregion
|
|
#endregion
|
|
|
|
|
|
- #region 消费队列
|
|
|
|
|
|
+ #region 消费队列(执行消费退款金额的统计)
|
|
public void StartListenTradeDo()
|
|
public void StartListenTradeDo()
|
|
{
|
|
{
|
|
- // TODO: 增加事务处理
|
|
|
|
bool op = true;
|
|
bool op = true;
|
|
while (op)
|
|
while (op)
|
|
{
|
|
{
|
|
- try
|
|
|
|
|
|
+ string orderidstring = TendisDbconn.Instance.LPop<string>("ConsumerOrders:Divi:List");
|
|
|
|
+ if (!string.IsNullOrEmpty(orderidstring))
|
|
{
|
|
{
|
|
- string orderidstring = TendisDbconn.Instance.LPop<string>("ConsumerOrders:Divi:List");
|
|
|
|
- if (!string.IsNullOrEmpty(orderidstring))
|
|
|
|
|
|
+ int OrderId = int.Parse(function.CheckInt(orderidstring));
|
|
|
|
+ WebCMSEntities db = new WebCMSEntities();
|
|
|
|
+ using (var tran = db.Database.BeginTransaction())
|
|
{
|
|
{
|
|
- int OrderId = int.Parse(function.CheckInt(orderidstring));
|
|
|
|
- WebCMSEntities db = new WebCMSEntities();
|
|
|
|
-
|
|
|
|
- ConsumerOrders order = db.ConsumerOrders.FirstOrDefault(m => m.Id == OrderId);
|
|
|
|
- if (order != null)
|
|
|
|
|
|
+ try
|
|
{
|
|
{
|
|
- decimal PayMoney = order.PayMoney * 10000M;
|
|
|
|
- if (OrderId == 81)
|
|
|
|
- {
|
|
|
|
- PayMoney = order.PayMoney * 5000M;
|
|
|
|
- }
|
|
|
|
- int MerchantId = order.MerchantId;
|
|
|
|
- MerchantInfo merchant = db.MerchantInfo.FirstOrDefault(m => m.Id == MerchantId);
|
|
|
|
- if (merchant != null)
|
|
|
|
|
|
+ ConsumerOrders order = db.ConsumerOrders.FirstOrDefault(m => m.Id == OrderId);
|
|
|
|
+ if (order != null)
|
|
{
|
|
{
|
|
- MerchantParamSet set = Newtonsoft.Json.JsonConvert.DeserializeObject<MerchantParamSet>(order.SeoDescription);
|
|
|
|
- int DiviPersons = set.DiviPersons; //单笔订单分红人数
|
|
|
|
- decimal DiviPercent = set.DiviPercent; //单人最大分红比例
|
|
|
|
- int ProfitDays = set.ProfitDays; //分红期限(天)
|
|
|
|
- decimal GetPercent = set.GetPercent; //商家实收比例
|
|
|
|
- decimal MinPayMoney = set.MinPayMoney; //订单参与门槛
|
|
|
|
- int IsAll = set.IsAll; //是否收全额
|
|
|
|
- if (IsAll == 0 && PayMoney >= MinPayMoney && GetPercent < 1)
|
|
|
|
|
|
+ decimal PayMoney = order.PayMoney * 10000M;
|
|
|
|
+ int MerchantId = order.MerchantId;
|
|
|
|
+ MerchantInfo merchant = db.MerchantInfo.FirstOrDefault(m => m.Id == MerchantId);
|
|
|
|
+ if (merchant != null)
|
|
{
|
|
{
|
|
- List<CustomTagSet> customTagSets = TendisDbconn.Instance.GetList<CustomTagSet>("CustomTagSet", 1, 1000); //获取公用配置参数集和
|
|
|
|
- //获取参数
|
|
|
|
- CustomTagSet profitPercentSet = customTagSets.FirstOrDefault(m => m.Tags == "CusumerProfitPercent") ?? new CustomTagSet();
|
|
|
|
- decimal profitPercent = decimal.Parse(function.CheckNum(profitPercentSet.Contents)); //基于收款金额的总分润比例;
|
|
|
|
- CustomTagSet cusumerFeePercentSet = customTagSets.FirstOrDefault(m => m.Tags == "CusumerFeePercent") ?? new CustomTagSet();
|
|
|
|
- decimal cusumerFeePercent = decimal.Parse(function.CheckNum(cusumerFeePercentSet.Contents)); //费率;
|
|
|
|
- CustomTagSet minProfitSet = customTagSets.FirstOrDefault(m => m.Tags == "MinProfit") ?? new CustomTagSet();
|
|
|
|
- decimal minProfit = decimal.Parse(function.CheckNum(minProfitSet.Contents)); //最小分润值;
|
|
|
|
- decimal DiviMoney = PayMoney * (1 - GetPercent - cusumerFeePercent - profitPercent);
|
|
|
|
- if (DiviMoney > 0)
|
|
|
|
|
|
+ MerchantParamSet set = Newtonsoft.Json.JsonConvert.DeserializeObject<MerchantParamSet>(order.SeoDescription);
|
|
|
|
+ int DiviPersons = set.DiviPersons; //单笔订单分红人数
|
|
|
|
+ decimal DiviPercent = set.DiviPercent; //单人最大分红比例
|
|
|
|
+ int ProfitDays = set.ProfitDays; //分红期限(天)
|
|
|
|
+ decimal GetPercent = set.GetPercent; //商家实收比例
|
|
|
|
+ decimal MinPayMoney = set.MinPayMoney; //订单参与门槛
|
|
|
|
+ int IsAll = set.IsAll; //是否收全额
|
|
|
|
+ if (IsAll == 0 && PayMoney >= MinPayMoney && GetPercent < 1)
|
|
{
|
|
{
|
|
- DiviMoney = DiviMoney / DiviPersons;
|
|
|
|
- //付款人获取退款返现
|
|
|
|
- decimal GetMoney = order.MaxDivi - order.CurDivi;
|
|
|
|
- if (GetMoney >= DiviMoney)
|
|
|
|
- {
|
|
|
|
- GetMoney = DiviMoney;
|
|
|
|
- }
|
|
|
|
- if (GetMoney > minProfit)
|
|
|
|
|
|
+ List<CustomTagSet> customTagSets = TendisDbconn.Instance.GetList<CustomTagSet>("CustomTagSet", 1, 1000); //获取公用配置参数集和
|
|
|
|
+ //获取参数
|
|
|
|
+ CustomTagSet profitPercentSet = customTagSets.FirstOrDefault(m => m.Tags == "CusumerProfitPercent") ?? new CustomTagSet();
|
|
|
|
+ decimal profitPercent = decimal.Parse(function.CheckNum(profitPercentSet.Contents)); //基于收款金额的总分润比例;
|
|
|
|
+ CustomTagSet cusumerFeePercentSet = customTagSets.FirstOrDefault(m => m.Tags == "CusumerFeePercent") ?? new CustomTagSet();
|
|
|
|
+ decimal cusumerFeePercent = decimal.Parse(function.CheckNum(cusumerFeePercentSet.Contents)); //费率;
|
|
|
|
+ CustomTagSet minProfitSet = customTagSets.FirstOrDefault(m => m.Tags == "MinProfit") ?? new CustomTagSet();
|
|
|
|
+ decimal minProfit = decimal.Parse(function.CheckNum(minProfitSet.Contents)); //最小分润值;
|
|
|
|
+ decimal DiviMoney = PayMoney * (1 - GetPercent - cusumerFeePercent - profitPercent);
|
|
|
|
+ if (DiviMoney > 0)
|
|
{
|
|
{
|
|
- order.CurDivi += GetMoney;
|
|
|
|
- db.ConsumerProfit.Add(new ConsumerProfit()
|
|
|
|
|
|
+ DiviMoney = DiviMoney / DiviPersons;
|
|
|
|
+ //付款人获取退款返现
|
|
|
|
+ decimal GetMoney = order.MaxDivi - order.CurDivi;
|
|
|
|
+ if (GetMoney >= DiviMoney)
|
|
{
|
|
{
|
|
- CreateDate = DateTime.Now,
|
|
|
|
- ConsumerId = order.ConsumerId,
|
|
|
|
- MerchantId = order.MerchantId,
|
|
|
|
- OrderId = OrderId,
|
|
|
|
- GetMoney = GetMoney,
|
|
|
|
- });
|
|
|
|
- }
|
|
|
|
- List<int> deletes = new List<int>();
|
|
|
|
- long CurDiviPersons = DiviPersons;
|
|
|
|
- long CurQueueCount = TendisDbconn.Instance.Count("ConsumerOrders:Divi:" + MerchantId);
|
|
|
|
- if (CurDiviPersons > CurQueueCount)
|
|
|
|
- {
|
|
|
|
- CurDiviPersons = CurQueueCount;
|
|
|
|
- }
|
|
|
|
- CurDiviPersons = CurDiviPersons - 1;
|
|
|
|
- while (CurDiviPersons > 0)
|
|
|
|
- {
|
|
|
|
- ConsumerOrders suborder = TendisDbconn.Instance.RPop<ConsumerOrders>("ConsumerOrders:Divi:" + MerchantId);
|
|
|
|
- if (suborder != null)
|
|
|
|
|
|
+ GetMoney = DiviMoney;
|
|
|
|
+ }
|
|
|
|
+ if (GetMoney > minProfit)
|
|
{
|
|
{
|
|
- if (suborder.CurDivi < suborder.MaxDivi)
|
|
|
|
|
|
+ order.CurDivi += GetMoney;
|
|
|
|
+ ConsumerProfit cprofit = db.ConsumerProfit.Add(new ConsumerProfit()
|
|
{
|
|
{
|
|
- GetMoney = suborder.MaxDivi - suborder.CurDivi;
|
|
|
|
- if (GetMoney >= DiviMoney)
|
|
|
|
- {
|
|
|
|
- GetMoney = DiviMoney;
|
|
|
|
- }
|
|
|
|
- if (GetMoney > minProfit)
|
|
|
|
|
|
+ CreateDate = DateTime.Now,
|
|
|
|
+ ConsumerId = order.ConsumerId,
|
|
|
|
+ MerchantId = order.MerchantId,
|
|
|
|
+ OrderId = OrderId,
|
|
|
|
+ GetMoney = GetMoney,
|
|
|
|
+ }).Entity;
|
|
|
|
+ db.SaveChanges();
|
|
|
|
+ TendisDbconn.Instance.AddList("ConsumerOrdersStat", new RefundItem()
|
|
|
|
+ {
|
|
|
|
+ ProfitId = cprofit.Id,
|
|
|
|
+ TradeNo = order.OrderNo,
|
|
|
|
+ RefundMoney = GetMoney,
|
|
|
|
+ TotalMoney = order.PayMoney,
|
|
|
|
+ PayMode = order.PayMode,
|
|
|
|
+ MerchantId = order.MerchantId,
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ List<int> deletes = new List<int>();
|
|
|
|
+ long CurDiviPersons = DiviPersons;
|
|
|
|
+ long CurQueueCount = TendisDbconn.Instance.Count("ConsumerOrders:Divi:" + MerchantId);
|
|
|
|
+ if (CurDiviPersons > CurQueueCount)
|
|
|
|
+ {
|
|
|
|
+ CurDiviPersons = CurQueueCount;
|
|
|
|
+ }
|
|
|
|
+ CurDiviPersons = CurDiviPersons - 1;
|
|
|
|
+ while (CurDiviPersons > 0)
|
|
|
|
+ {
|
|
|
|
+ ConsumerOrders suborder = TendisDbconn.Instance.RPop<ConsumerOrders>("ConsumerOrders:Divi:" + MerchantId);
|
|
|
|
+ if (suborder != null)
|
|
|
|
+ {
|
|
|
|
+ if (suborder.CurDivi < suborder.MaxDivi)
|
|
{
|
|
{
|
|
- suborder.CurDivi += GetMoney;
|
|
|
|
- db.ConsumerProfit.Add(new ConsumerProfit()
|
|
|
|
|
|
+ GetMoney = suborder.MaxDivi - suborder.CurDivi;
|
|
|
|
+ if (GetMoney >= DiviMoney)
|
|
{
|
|
{
|
|
- CreateDate = DateTime.Now,
|
|
|
|
- ConsumerId = suborder.ConsumerId,
|
|
|
|
- MerchantId = suborder.MerchantId,
|
|
|
|
- OrderId = OrderId,
|
|
|
|
- GetMoney = GetMoney,
|
|
|
|
- });
|
|
|
|
- if (suborder.CurDivi < suborder.MaxDivi)
|
|
|
|
|
|
+ GetMoney = DiviMoney;
|
|
|
|
+ }
|
|
|
|
+ if (GetMoney > minProfit)
|
|
{
|
|
{
|
|
- TendisDbconn.Instance.AddList("ConsumerOrders:Divi:" + MerchantId, suborder);
|
|
|
|
|
|
+ suborder.CurDivi += GetMoney;
|
|
|
|
+ ConsumerProfit cprofit = db.ConsumerProfit.Add(new ConsumerProfit()
|
|
|
|
+ {
|
|
|
|
+ CreateDate = DateTime.Now,
|
|
|
|
+ ConsumerId = suborder.ConsumerId,
|
|
|
|
+ MerchantId = suborder.MerchantId,
|
|
|
|
+ OrderId = OrderId,
|
|
|
|
+ GetMoney = GetMoney,
|
|
|
|
+ }).Entity;
|
|
|
|
+ db.SaveChanges();
|
|
|
|
+ TendisDbconn.Instance.AddList("ConsumerOrdersStat", new RefundItem()
|
|
|
|
+ {
|
|
|
|
+ ProfitId = cprofit.Id,
|
|
|
|
+ TradeNo = order.OrderNo,
|
|
|
|
+ RefundMoney = GetMoney,
|
|
|
|
+ TotalMoney = order.PayMoney,
|
|
|
|
+ PayMode = order.PayMode,
|
|
|
|
+ MerchantId = order.MerchantId,
|
|
|
|
+ });
|
|
|
|
+ if (suborder.CurDivi < suborder.MaxDivi)
|
|
|
|
+ {
|
|
|
|
+ TendisDbconn.Instance.AddList("ConsumerOrders:Divi:" + MerchantId, suborder);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ CurDiviPersons -= 1;
|
|
}
|
|
}
|
|
- CurDiviPersons -= 1;
|
|
|
|
- }
|
|
|
|
- db.SaveChanges();
|
|
|
|
|
|
|
|
- //创客分润
|
|
|
|
- // DoProfit(db, order);
|
|
|
|
|
|
+ //创客分润
|
|
|
|
+ // DoProfit(db, order);
|
|
|
|
|
|
- //代理商分润
|
|
|
|
- // AgentProfit(db, order);
|
|
|
|
|
|
+ //代理商分润
|
|
|
|
+ // AgentProfit(db, order);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ tran.Commit();
|
|
|
|
+ }
|
|
|
|
+ catch (Exception ex)
|
|
|
|
+ {
|
|
|
|
+ op = false;
|
|
|
|
+ function.WriteLog(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + ":" + ex.ToString(), "自定义分润程序监听队列异常");
|
|
|
|
+ tran.Rollback();
|
|
}
|
|
}
|
|
- db.Dispose();
|
|
|
|
- }
|
|
|
|
- else
|
|
|
|
- {
|
|
|
|
- op = false;
|
|
|
|
}
|
|
}
|
|
|
|
+ db.Dispose();
|
|
}
|
|
}
|
|
- catch (Exception ex)
|
|
|
|
|
|
+ else
|
|
{
|
|
{
|
|
op = false;
|
|
op = false;
|
|
- function.WriteLog(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + ":" + ex.ToString(), "自定义分润程序监听队列异常");
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|