static decimal OperateInvitorFee(InvitorFeeTrans trans, Trader to, OptionDbCtx db, Action <string> log) { try { if (trans.Trader == null) { return(0); } var start = trans.LastTransferTime ?? DateTime.Now.Date; var ls = db.SysAccountRecords.Where(a => a.ChangedType == SysAccountChangeType.收取手续费 && a.Who != null && a.Who.Id == trans.Trader.Id && a.When > start && a.When < DateTime.Now ).Select(a => new { Delta = a.Delta }); if (ls == null) { return(0); } var count = ls.Count(); if (count == 0) { return(0); } var total = ls.Sum(a => a.Delta); if (total == 0) { return(0); } var r = total * trans.Ratio; if (r == 0) { return(0); } string detal = string.Format("{0}从{1}到{2}共交易{3}笔,手续费总额{4},返还比例{5},返还总额{6}", trans.Trader.Name, start, DateTime.Now, count, total, trans.Ratio, r); bool result = TraderService.OperateInvitorFee(to, r, detal); if (result) { trans.UpdateSumAction(r); } if (log != null) { log(detal); } return(r); } catch (Exception ex) { Singleton <TextLog> .Instance.Error(ex); return(0); } }
public static decimal TransBonus(Trader t, List <string> invitedNames) { if (t == null || invitedNames == null || invitedNames.Count == 0) { return(0); } decimal result = 0; foreach (var v in invitedNames) { if (string.IsNullOrEmpty(v)) { continue; } bool r = TraderService.OperateInvitorBonus(t, InvitorBonusInCny, "被推荐人" + v); result += InvitorBonusInCny; log.Info(string.Format("{0}成功推荐了{1},获取奖金{2}元", t.Name, v, InvitorBonusInCny)); } return(result); }
/// <summary> /// 下单后,冻结维持保证金或需要的金额 /// 同时要添加到用户的下单列表 /// 下单列表只保留最近的10000单 /// </summary> /// <param name="o"></param> public bool Handle(Order o) { try { log.Info(string.Format("下单后==下单订单信息:{0}", o)); if (o.IsMarketPrice()) { o.Price = 0; } bool bailresult = true; //如果是市价,则不冻结也不解冻 if (!o.IsMarketPrice() && o.IsNeedBailExceptMaintainBail()) { var c = o.GetSellOpenCountToFreeze(); bailresult = TraderService.OperateAccount(o.Trader, c, AccountChangeType.保证金冻结, "system", o); log.Info(string.Format("下单后==保证金冻结成功,冻结{0}", o.GetNeededCache())); } if (bailresult) { o.State = OrderState.等待中; o.Trader.Orders().Add(o); //成功下单,重新计算保证率 o.Trader.RaiseRatioChangedAfterOrder(); log.Info(string.Format("下单后==已将{0}添加到用户的下单列表", o)); } return(bailresult); } catch (Exception e) { Singleton <TextLog> .Instance.Error(e, "order post handle"); return(false); } }
public static bool Manual(this Trader t, decimal delta, AccountChangeType type, string byWho, bool isAbountFreeze = false, bool isFreeze = false) { return(TraderService.ManualChange(t, delta, type, byWho, isAbountFreeze, isFreeze)); }