public static FastUserPay AddCard(FastUser FastUser, FastUserPay FastUserPay, FastPayWay FastPayWay, LokFuEntity Entity) { //添加/修改结算卡------不需要修改的需到上一步添加 if (FastUserPay.CardState == 2) { string[] PayConfigArr = FastPayWay.QueryArray.Split(','); if (FastPayWay.DllName == "HFJSPay") { #region 结算中心 if (PayConfigArr.Length == 3) { UserCard UserCard = Entity.UserCard.FirstOrNew(n => n.Card == FastUserPay.Card && n.UId == FastUser.UId); string Mobile = UserCard.Mobile; Users Users = Entity.Users.FirstOrNew(n => n.Id == FastUser.UId); if (Mobile.IsNullOrEmpty()) { Mobile = Users.UserName; } string Code = PayConfigArr[0]; string CodeKey = PayConfigArr[1]; string PayWayCode = PayConfigArr[2]; fastuseraddModel model = new fastuseraddModel() { code = Code, merid = FastUserPay.MerId, cardno = Users.CardId, accountcard = UserCard.Card, accountbin = UserCard.Bin, accountmobile = UserCard.Mobile }; fastuserResult fastuserResult = HFJSTools.fastuseredit(model, CodeKey); if (fastuserResult.respcode == "00") { FastUserPay.CardState = 1; Entity.SaveChanges(); } else { FastUserPay.CardMsg = fastuserResult.respcode + "[" + fastuserResult.respmsg + "]"; FastUserPay.CardState = 4; Entity.SaveChanges(); } } #endregion } } return(FastUserPay); }
public void Execute(IJobExecutionContext context) { string JobName = "OutMoneyPush"; string CanRun = ConfigurationManager.AppSettings["Run" + JobName].ToString(); if (CanRun == "true") { if (!IsRun) { LokFuEntity Entity = new LokFuEntity(); IsRun = true; try { Log.Write(JobName + "任务开始执行!"); //------------------------------------------------------- #region 任务主体 IList <TaskCashInfo> List = Entity.TaskCashInfo.Where(n => n.NState == 1).OrderBy(n => n.Id).ToList(); foreach (var p in List) { Orders O = Entity.Orders.FirstOrDefault(n => n.TNum == p.OId); O.SendMsg(Entity); p.NState = 2; Log.WriteLog("Notice执行完毕:" + p.OId, JobName); Thread.Sleep(500); } Entity.SaveChanges(); #endregion //------------------------------------------------------- Log.Write(JobName + "任务执行结束![共计" + List.Count + "条]"); } catch (Exception Ex) { Log.Write(JobName + "任务执行过程出错!", Ex); } IsRun = false; } else { Log.Write(JobName + "任务还在执行中!"); } } }
public void Execute(IJobExecutionContext context) { string JobName = "JPayRun"; string CanRun = ConfigurationManager.AppSettings["Run" + JobName].ToString(); if (CanRun == "true") { if (!IsRun) { //0取消 1待付款 2待执行 3执行中 4执行完成 5执行失败 6暂停(预留) //状态:0取消 1待执行 2执行中 3执行完成 4执行失败 LokFuEntity Entity = new LokFuEntity(); IsRun = true; try { Utils.WriteLog("执行收款任务开始执行!", JobName); DateTime Now = DateTime.Now; DateTime Today = DateTime.Parse(Now.ToString("yyyy-MM-dd")); IList <JobItem> JobItemList = Entity.JobItem.Where(n => n.State == 1 && n.RunTime > Today && n.RunTime <= Now && n.RunType == 1).ToList(); foreach (var p in JobItemList) { p.State = 2; p.RunedTime = DateTime.Now; } Entity.SaveChanges(); foreach (var p in JobItemList) { p.Pay(Entity); Utils.WriteLog("处理任务[" + p.RunNum + "]!", JobName); } Utils.WriteLog("执行收款任务执行结束![共计" + JobItemList.Count + "条]", JobName); } catch (Exception Ex) { Log.Write("执行收款任务执行过程出错!", Ex); } IsRun = false; } } }
public void Execute(IJobExecutionContext context) { string JobName = "BaoTask"; string CanRun = ConfigurationManager.AppSettings["Run" + JobName].ToString(); if (CanRun == "true") { if (!IsRun) { LokFuEntity Entity = new LokFuEntity(); IsRun = true; try { Log.Write(JobName + "任务开始执行!"); //------------------------------------------------------- #region 任务主体 BaoConfig BaoConfig = Entity.BaoConfig.FirstOrDefault(); //余额理财昨天收益归0 //============================================================================================= Entity.ExecuteStoreCommand("Update BaoUsers Set LastRec=0 Where LastRec>0"); //余额理财计息程序 //============================================================================================= Log.WriteLog("余额理财任务开始执行!", JobName); DateTime Today = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd")); //今天0点 DateTime EDate = Today.AddDays(1); //今天24点 int BaoTime = Int32.Parse(ConfigurationManager.AppSettings["BaoTime"].ToString()); DateTime sTime = Today.AddHours(BaoTime - 24); //计息前节点 DateTime eTime = Today.AddHours(BaoTime); //计息后节点 BaoStory BaoStory = Entity.BaoStory.FirstOrDefault(n => n.SDate == Today && n.LType == 1); if (BaoStory == null) { //添加总日志,后期可形成曲线图 BaoStory = new BaoStory(); BaoStory.SDate = Today; BaoStory.GetCost = BaoConfig.GetCost; BaoStory.YearPer = BaoConfig.YearPer; BaoStory.InMoney = 0; BaoStory.OutMoney = 0; BaoStory.BfAllMoney = 0; BaoStory.BfActMoney = 0; BaoStory.BfInMoney = 0; BaoStory.LType = 1; try { BaoStory.InMoney = Entity.BaoLog.Where(n => n.AddTime > sTime && n.AddTime <= eTime && n.LType == 1).Sum(n => n.Amount); } catch (Exception) { Log.WriteLog("余额理财统计转入出错!", JobName); } try { BaoStory.OutMoney = Entity.BaoLog.Where(n => n.AddTime > sTime && n.AddTime <= eTime && n.LType == 2).Sum(n => n.Amount); } catch (Exception) { Log.WriteLog("余额理财统计转出金额出错!", JobName); } try { BaoStory.BfAllMoney = Entity.BaoUsers.Sum(n => n.AllMoney); } catch (Exception) { Log.WriteLog("余额理财统计总金额出错!", JobName); } try { BaoStory.BfActMoney = Entity.BaoUsers.Sum(n => n.ActMoney); } catch (Exception) { Log.WriteLog("余额理财统计计息金额出错!", JobName); } try { BaoStory.BfInMoney = Entity.BaoUsers.Sum(n => n.InMoney); } catch (Exception) { Log.WriteLog("余额理财统计未计息金额出错!", JobName); } Entity.BaoStory.AddObject(BaoStory); Entity.SaveChanges(); IList <BaoUsers> BaoUsersList = Entity.BaoUsers.Where(n => n.InMoney > 0 || n.ActMoney > 0).ToList(); foreach (var p in BaoUsersList) { p.PayLIXI(BaoConfig, Entity); Log.WriteLog("计算利息:" + p.UId, JobName); } try { BaoStory.Interest = Entity.BaoLog.Where(n => n.AddTime >= Today && n.AddTime < EDate && n.LType == 3).Sum(n => n.Amount);//利息 } catch (Exception) { Log.WriteLog("余额理财统计利息出错!", JobName); } BaoStory.AfAllMoney = BaoStory.BfAllMoney + BaoStory.Interest; BaoStory.AfActMoney = BaoStory.BfActMoney + BaoStory.AfInMoney + BaoStory.Interest; BaoStory.AfInMoney = 0; Entity.SaveChanges(); Log.WriteLog("余额理财计息完成[" + BaoUsersList.Count + "]!", JobName); } Log.WriteLog("余额理财任务执行结束!", JobName); //============================================================================================= //自动转入余额理财 Log.WriteLog("自动转入余额理财任务开始执行!", JobName); IList <Users> UsersList = Entity.Users.Where(n => n.State == 1 && n.AutoBao == 1 && n.Amount > 0 && (n.StopPayState == 0 || n.StopPayState == 1)).ToList(); foreach (var p in UsersList) { p.AutoBao(Entity); Log.WriteLog("自动转入:" + p.Id, JobName); } Log.WriteLog("自动转入余额理财任务执行结束[" + UsersList.Count + "]!", JobName); //============================================================================================= Log.WriteLog("余额生息任务开始执行!", JobName); BaoStory = Entity.BaoStory.FirstOrDefault(n => n.SDate == Today && n.LType == 2); if (BaoStory == null) { //添加总日志,后期可形成曲线图 BaoStory = new BaoStory(); BaoStory.SDate = Today; BaoStory.GetCost = BaoConfig.GetCost; BaoStory.YearPer = BaoConfig.YearPer; BaoStory.InMoney = 0; BaoStory.OutMoney = 0; BaoStory.BfAllMoney = 0; BaoStory.BfActMoney = 0; BaoStory.BfInMoney = 0; BaoStory.LType = 2; try { BaoStory.BfAllMoney = Entity.Users.Sum(n => n.Amount); } catch (Exception) { Log.WriteLog("余额生息统计总金额出错!", JobName); } try { BaoStory.BfActMoney = Entity.Users.Sum(n => n.YAmount); } catch (Exception) { Log.WriteLog("余额生息统计计息金额出错!", JobName); } Entity.BaoStory.AddObject(BaoStory); Entity.SaveChanges(); decimal GetCost = BaoConfig.GetCost / 10000; Entity.ExecuteStoreCommand("Exec SP_UsersProfit " + GetCost); try { BaoStory.Interest = Entity.UserLog.Where(n => n.AddTime >= Today && n.AddTime < EDate && n.OType == 15).Sum(n => n.Amount);//利息 } catch (Exception) { Log.WriteLog("余额生息统计利息出错!", JobName); } BaoStory.AfAllMoney = BaoStory.BfAllMoney + BaoStory.Interest; BaoStory.AfActMoney = BaoStory.BfActMoney + BaoStory.AfInMoney + BaoStory.Interest; BaoStory.AfInMoney = 0; Entity.SaveChanges(); } Log.WriteLog("余额生息任务执行结束!", JobName); //============================================================================================= #endregion //------------------------------------------------------- Log.Write(JobName + "任务执行结束!"); } catch (Exception Ex) { Log.Write(JobName + "任务执行过程出错!", Ex); } IsRun = false; } else { Log.Write(JobName + "任务还在执行中!"); } } }
public void Execute(IJobExecutionContext context) { string JobName = "OrderProfit"; string CanRun = ConfigurationManager.AppSettings["Run" + JobName].ToString(); if (CanRun == "true") { if (!IsRun) { LokFuEntity Entity = new LokFuEntity(); IsRun = true; try { Log.Write(JobName + "任务开始执行!"); //------------------------------------------------------- #region 任务主体 IList <Orders> List = Entity.Orders.Where(n => n.RunSplit == 1).Take(50).ToList(); foreach (var p in List) { p.RunSplit = 2; } Entity.SaveChanges(); foreach (var O in List) { if (O.TType == 1)//银联卡支付 { OrderRecharge OrderRecharge = Entity.OrderRecharge.FirstOrDefault(n => n.OId == O.TNum); if (OrderRecharge != null) { OrderRecharge = OrderRecharge.PayAgent(Entity, 1, O.FrozenState); O.AgentPayGet = (decimal)OrderRecharge.AgentPayGet; O.AgentState = 1; } } if (O.TType == 2)//提现 { OrderCash OrderCash = Entity.OrderCash.FirstOrDefault(n => n.OId == O.TNum); if (OrderCash != null) { OrderCash = OrderCash.PayAgent(Entity, 1); O.AgentPayGet = (decimal)OrderCash.AgentCashGet; } } if (O.TType == 3)//转帐 { OrderTransfer OrderTransfer = Entity.OrderTransfer.FirstOrDefault(n => n.OId == O.TNum); if (OrderTransfer != null) { OrderTransfer = OrderTransfer.PayAgent(Entity, 1); O.AgentPayGet = (decimal)OrderTransfer.AgentPayGet; } } if (O.TType == 5)//房租 { OrderHouse OrderHouse = Entity.OrderHouse.FirstOrDefault(n => n.OId == O.TNum); if (OrderHouse != null) { OrderHouse = OrderHouse.PayAgent(Entity, 1); O.AgentPayGet = (decimal)OrderHouse.AgentPayGet; } } if (O.TType == 6)//升级 { VIPOrder VIPOrder = Entity.VIPOrder.FirstOrDefault(n => n.TNum == O.TNum); if (VIPOrder != null) { VIPOrder = VIPOrder.PayAgent(Entity, 1); O.AgentPayGet = (decimal)VIPOrder.SplitMoney; O.AgentState = 1; } } if (O.TType == 7 || O.TType == 8 || O.TType == 9)//扫码 NFC { OrderF2F OrderF2F = Entity.OrderF2F.FirstOrDefault(n => n.OId == O.TNum); if (OrderF2F != null) { OrderF2F = OrderF2F.PayAgent(Entity, 1, O.FrozenState); O.AgentPayGet = (decimal)OrderF2F.AgentPayGet; } } if (O.TType == 10)//代理自助开通 { DaiLiOrder DaiLiOrder = Entity.DaiLiOrder.FirstOrDefault(n => n.OId == O.TNum); if (DaiLiOrder != null) { DaiLiOrder = DaiLiOrder.PayAgent(Entity, 1); O.AgentPayGet = (decimal)DaiLiOrder.AgentGet; O.AgentState = 1; } } O.RunSplit = 3; Entity.SaveChanges(); } #endregion //------------------------------------------------------- Log.Write(JobName + "任务执行结束![共计" + List.Count + "条]"); } catch (Exception Ex) { Log.Write(JobName + "任务执行过程出错!", Ex); } IsRun = false; } else { Log.Write(JobName + "任务还在执行中!"); } } }
public static FastUser AddMer(FastUser FastUser, FastPayWay FastPayWay, FastConfig FastConfig, LokFuEntity Entity) { if (FastUser.Card.IsNullOrEmpty()) { //未绑定银行卡 return(FastUser); } FastUserPay FastUserPay = Entity.FastUserPay.FirstOrDefault(n => n.UId == FastUser.UId && n.PayWay == FastPayWay.Id); if (FastUserPay == null) { FastUserPay = new FastUserPay(); FastUserPay.UId = FastUser.UId; FastUserPay.PayWay = FastPayWay.Id; if (FastPayWay.DllName == "HFPay") { //不需要一户一码直接开通商户 FastUserPay.MerId = "HFPay" + FastUserPay.UId.ToString(); FastUserPay.MerState = 1; FastUserPay.CardState = 1; FastUserPay.BusiState = 1; } else { FastUserPay.MerId = ""; FastUserPay.MerState = 2; //状态 0锁定 1正常 2待提交 3审核中 4审核失败 FastUserPay.CardState = 2; //状态 0锁定 1正常 2待提交 3审核中 4审核失败 FastUserPay.BusiState = 2; //状态 1正常 2待提交 3审核中 4审核失败 } FastUserPay.CardName = FastUser.TrueName; FastUserPay.Bank = FastUser.Bank; FastUserPay.Card = FastUser.Card; FastUserPay.Bin = FastUser.Bin; //2017-11-22 修改成取通道配置,且分别计算微信/支付宝/银联 //FastUserPay.UserCost = FastConfig.UserCost; FastUserPay.UserCost = FastPayWay.InCost; FastUserPay.UserCost2 = FastPayWay.InCost2; FastUserPay.UserCost3 = FastPayWay.InCost3; if (FastPayWay.GroupType == "T1") { FastUserPay.UserCash = 0; } else { FastUserPay.UserCash = FastConfig.UserCash; } FastUserPay.AddTime = DateTime.Now; Entity.FastUserPay.AddObject(FastUserPay); Entity.SaveChanges(); } else { bool Save = false; if (FastUserPay.CardName != FastUser.TrueName) { FastUserPay.CardName = FastUser.TrueName; Save = true; } if (FastUserPay.Bank != FastUser.Bank) { FastUserPay.Bank = FastUser.Bank; Save = true; } if (FastUserPay.Card != FastUser.Card) { FastUserPay.Card = FastUser.Card; Save = true; } if (FastUserPay.Bin != FastUser.Bin) { FastUserPay.Bin = FastUser.Bin; Save = true; } if (Save) { Entity.SaveChanges(); } } string[] PayConfigArr = FastPayWay.QueryArray.Split(','); if (FastPayWay.DllName == "HFJSPay") { #region 结算系统 if (PayConfigArr.Length == 3) { string Code = PayConfigArr[0]; string CodeKey = PayConfigArr[1]; string PayWayCode = PayConfigArr[2]; #region 进件 if (FastUserPay.MerState == 2 || FastUserPay.MerState == 4) { UserCard UserCard = Entity.UserCard.FirstOrNew(n => n.Card == FastUserPay.Card && n.UId == FastUser.UId); string Mobile = UserCard.Mobile; Users Users = Entity.Users.FirstOrNew(n => n.Id == FastUser.UId); if (Mobile.IsNullOrEmpty()) { Mobile = Users.UserName; } fastuseraddModel model = new fastuseraddModel() { code = Code, mchid = "HF" + Users.Id.ToString(), mchname = Users.NeekName, truename = Users.TrueName, cardno = Users.CardId, accountcard = UserCard.Card, accountbin = UserCard.Bin, accountmobile = UserCard.Mobile }; fastuserResult fastuserResult = HFJSTools.fastuseradd(model, CodeKey); if (fastuserResult.respcode == "00") { bool RunTrue = true; string Msg = ""; if (fastuserResult.respmsg == "存在相同外部商户号") { //这里面要修改一下结算卡 fastuseraddModel modelEdit = new fastuseraddModel() { code = Code, merid = fastuserResult.merid, cardno = Users.CardId, accountcard = UserCard.Card, accountbin = UserCard.Bin, accountmobile = UserCard.Mobile }; fastuserResult fastuserresult = HFJSTools.fastuseredit(modelEdit, CodeKey); if (fastuserresult.respcode != "00") { Msg = fastuserresult.respmsg; RunTrue = false; } } if (RunTrue) { if (fastuserResult.state == 1) { FastUserPay.MerState = 1; FastUserPay.CardState = 1;//这里已绑定结算卡 FastUserPay.MerId = fastuserResult.merid; FastUserPay.MerKey = fastuserResult.merkey; } else if (fastuserResult.state == 2) { FastUserPay.MerId = fastuserResult.merid; FastUserPay.MerKey = fastuserResult.merkey; FastUserPay.MerState = 3; } else { FastUserPay.MerState = 4; FastUserPay.MerMsg = fastuserResult.respcode + "[" + fastuserResult.respmsg + "]"; } } else { FastUserPay.MerState = 4; FastUserPay.MerMsg = Msg; } } else { FastUserPay.MerState = 4; FastUserPay.MerMsg = fastuserResult.respcode + "[" + fastuserResult.respmsg + "]"; } Entity.SaveChanges(); } #endregion #region 开通道 if (FastUserPay.MerState == 1 && (FastUserPay.BusiState == 2 || FastUserPay.BusiState == 4)) { decimal Cost = FastPayWay.InCost3;//刷卡手续费 Users Users = Entity.Users.FirstOrNew(n => n.Id == FastUser.UId); if (Users.IsVip == 1) { Cost = 0.005M; FastUserPay.UserCost3 = 0.005M; } decimal Cash = FastConfig.UserCash;//还款手续费 userspayopenbModel userspayopenbModel = new userspayopenbModel() { merid = FastUserPay.MerId, paywaycode = PayWayCode, code = Code, bankcost = Cost, //surcharge = 0, cash = Cash, bankcostmin = 0, bankcostmax = 9999999 }; fastuserResult fastuserResult = HFJSTools.userspayopen(userspayopenbModel, CodeKey); if (fastuserResult.respcode == "00") { if (fastuserResult.state == 1) { FastUserPay.BusiState = 1; } else { FastUserPay.BusiState = 4; FastUserPay.BusiMsg = fastuserResult.respcode + "[" + fastuserResult.respmsg + "]"; } } else { FastUserPay.BusiState = 4; FastUserPay.BusiMsg = fastuserResult.respcode + "[" + fastuserResult.respmsg + "]"; } Entity.SaveChanges(); } #endregion } #endregion } return(FastUser); }
public void Execute(IJobExecutionContext context) { string JobName = "OutMoney"; string CanRun = ConfigurationManager.AppSettings["Run" + JobName].ToString(); if (CanRun == "true") { if (!IsRun) { LokFuEntity Entity = new LokFuEntity(); IsRun = true; try { Log.Write(JobName + "任务开始执行!"); //------------------------------------------------------- #region 任务主体 #region 全局变量 SysSet BasicSet = Entity.SysSet.FirstOrDefault(); string NoticePath = ConfigurationManager.AppSettings["NoticePath"].ToString(); string NoticeUrl = NoticePath + "/PayCenter/HFCash/Notice.html"; //提交结算中心 string merId = ConfigurationManager.AppSettings["Cash_merId"].ToString(); //商户号 string merKey = ConfigurationManager.AppSettings["Cash_merKey"].ToString(); //商户密钥 #endregion //0=无效,1=待执行,2=执行中,3=完成 IList <TaskCash> TaskCashList = Entity.TaskCash.Where(n => n.State == 1 || n.State == 2).OrderBy(n => n.Id).ToList(); //读取待执行 foreach (var P in TaskCashList) { //任务状态设置为执行中 if (P.State == 1) { P.State = 2; P.STime = DateTime.Now; Entity.SaveChanges(); } IList <TaskCashInfo> TaskCashInfoList = Entity.TaskCashInfo.Where(n => (n.State == 1 || n.State == 2) && n.TId == P.Id).OrderBy(n => n.Id).ToList(); foreach (var p in TaskCashInfoList) { if (p.State == 1) { p.State = 2; p.STime = DateTime.Now; Entity.SaveChanges(); } OrderCash OC = Entity.OrderCash.FirstOrDefault(n => n.OId == p.OId); bool CanPay = true; if (OC == null) { CanPay = false; } if (OC.FState == 1)//已付过款 { CanPay = false; } if (OC.OrderState != 2 || OC.PayState != 1) { CanPay = false; } if (CanPay)//开启自动结算时执行 { if (BasicSet.CashPayWay == 0) { p.State = 3;//标识成功 p.OState = 2; p.NState = 1; p.Remark = "批量人工结算"; p.ETime = DateTime.Now; OC.PayState = 2; OC.FState = 1; OC.FTime = DateTime.Now; Orders O = Entity.Orders.FirstOrDefault(n => n.TNum == p.OId); if (O != null) { O.PayState = 2; O.InternalRm = "批量人工结算"; } Entity.SaveChanges(); //======分润====== OC = OC.PayAgent(Entity, 1); if (O != null) { O.AgentPayGet = (decimal)OC.AgentCashGet; } Entity.SaveChanges(); } else if (BasicSet.CashPayWay == 1) { #region 提交接口 string orderId = OC.OId;//商户流水号 decimal PayMoney = OC.Amoney - (decimal)OC.UserRate; decimal money = PayMoney * 100; long intmoney = Int64.Parse(money.ToString("F0")); string OrderMoney = intmoney.ToString();//金额,以分为单 string UserCardId = Entity.Users.FirstOrNew(n => n.Id == OC.UId).CardId; string PostJson = "{\"action\":\"QCash\",\"txnamt\":\"" + OrderMoney + "\",\"merid\":\"" + merId + "\",\"orderid\":\"" + orderId + "\",\"backurl\":\"" + NoticeUrl + "\",\"bin\":\"" + OC.Bin + "\",\"accno\":\"" + OC.CardNum + "\",\"accname\":\"" + OC.Owner + "\",\"cardno\":\"" + UserCardId + "\"}"; //传送数据Base64 string DataBase64 = LokFuEncode.Base64Encode(PostJson, "utf-8"); //获得签名 string Sign = (DataBase64 + merKey).GetMD5(); //传送数据UrlEnCode DataBase64 = System.Web.HttpUtility.UrlEncode(DataBase64); //组装Post数据 string PostData = string.Format("req={0}&sign={1}", DataBase64, Sign); string HFNFC_Url = "https://api.zhifujiekou.com/api/qcashgateway"; //Post数据,获得结果 string Ret = Utils.PostRequest(HFNFC_Url, PostData, "utf-8"); string runType = "PayOk"; JObject JS = new JObject(); try { JS = (JObject)JsonConvert.DeserializeObject(Ret); } catch (Exception) { Utils.WriteLog("[" + OC.OId + "]" + Ret, "PayCashCenterErr"); runType = "PayIng"; } string Remark = ""; if (runType == "PayOk") { if (JS != null) { string resp = JS["resp"].ToString(); Ret = LokFuEncode.Base64Decode(resp, "utf-8"); try { JS = (JObject)JsonConvert.DeserializeObject(Ret); } catch (Exception) { runType = "PayIng"; } if (runType == "PayOk") { if (JS != null) { string respcode = JS["respcode"].ToString(); if (respcode != "00") { if (respcode == "45") { //限额了,需要特别处理 runType = "PayErr"; } else { runType = "PayIng"; } Remark = JS["respmsg"].ToString(); } else { string resultcode = JS["resultcode"].ToString(); if (resultcode == "0000") { runType = "PayOk"; } else if (resultcode == "2002" || resultcode == "2003") { runType = "PayErr"; Remark = JS["resultmsg"].ToString(); } else { runType = "PayIng"; Remark = JS["resultmsg"].ToString(); } } } else { runType = "PayIng"; } } } else { runType = "PayIng"; } } if (runType == "PayIng") { //处理中 p.ETime = DateTime.Now; p.State = 5;//标识 未知状态 Entity.SaveChanges(); } if (runType == "PayErr") { OC.PayState = 3; OC.Remark = Remark; p.State = 4;//标识失败 p.OState = 2; p.NState = 1; p.Remark = Remark; p.ETime = DateTime.Now; Orders O = Entity.Orders.FirstOrDefault(n => n.TNum == p.OId); if (O != null) { O.PayState = 3; O.Remark = Remark; } Entity.SaveChanges(); } if (runType == "PayOk") { OC.PayState = 2; OC.FState = 1; OC.FTime = DateTime.Now; p.State = 3;//标识成功 p.OState = 2; p.NState = 1; p.ETime = DateTime.Now; Entity.SaveChanges(); OC = OC.PayAgent(Entity, 1);//======分润====== Orders O = Entity.Orders.FirstOrDefault(n => n.TNum == p.OId); if (O != null) { O.PayState = 2; O.AgentPayGet = (decimal)OC.AgentCashGet; Entity.SaveChanges(); } } Log.WriteLog("执行提现:" + p.OId, JobName); Thread.Sleep(1000); #endregion } } else { p.Remark = "订单状态不符,需查单!"; p.ETime = DateTime.Now; p.State = 5;//标识 未知状态 Entity.SaveChanges(); } } //当前任务所有子项执行完成 int state1 = Entity.TaskCashInfo.Count(n => n.State == 1 && n.TId == P.Id); int state2 = Entity.TaskCashInfo.Count(n => n.State == 2 && n.TId == P.Id); int state3 = Entity.TaskCashInfo.Count(n => n.State == 3 && n.TId == P.Id); int state4 = Entity.TaskCashInfo.Count(n => n.State == 4 && n.TId == P.Id); int state5 = Entity.TaskCashInfo.Count(n => n.State == 5 && n.TId == P.Id); if (state1 == 0 && state2 == 0) { P.State = 3; P.ETime = DateTime.Now; } P.Success = state3 + state5; P.Fail = state4; Entity.SaveChanges(); Log.WriteLog("TaskCashInfo任务执行完毕!共计" + TaskCashInfoList.Count + "笔交易", JobName); } Log.WriteLog("TaskCash任务执行完毕!共计" + TaskCashList.Count + "个任务", JobName); #endregion //------------------------------------------------------- Log.Write(JobName + "任务执行结算!"); } catch (Exception Ex) { Log.Write(JobName + "任务执行过程出错!", Ex); } IsRun = false; } else { Log.Write(JobName + "任务还在执行中!"); } } }
/// <summary> /// 订单分润/分润退款 /// </summary> /// <param name="O"></param> /// <param name="Entity"></param> /// <param name="Type">1分润入帐 2分润退款</param> /// <returns></returns> public static FastOrder PayAgent(this FastOrder O, LokFuEntity Entity, int Type) { FastConfig FastConfig = Entity.FastConfig.FirstOrNew(); if (FastConfig.AgentWay != 1) { return(O); } if (O.Agent.IsNullOrEmpty()) {//代理商没有情况下 return(O); } //if (O.AgentPayGet.IsNullOrEmpty()) //{ // //没有佣金 // //直接标识为已结算 // O.AgentState = 1; // O.AgentTime = DateTime.Now; // Entity.SaveChanges(); // return O; //} if (Type != 1)//类型不对 { return(O); } Users OrderUser = Entity.Users.FirstOrDefault(n => n.Id == O.UId);//读取订单用户 if (Type == 1) { string TypeString = "收付直通车"; #region 结算 if (O.AgentState != 0) {//已结算,不能重复结算 return(O); } O.AgentState = 1; O.AgentTime = DateTime.Now; Entity.SaveChanges(); //获取各级代理商 SysAgent SysAgent = new SysAgent(); SysAgent.Id = O.Agent; IList <SysAgent> SysAgentList = SysAgent.GetAgentsById(Entity); decimal AIdPayGet = (decimal)O.AgentPayGet; // decimal sumpayget = 0; int tier = 1; foreach (var p in SysAgentList) { if (p.State == 1) { decimal PayGet = SysAgent.GetSplit(p.Tier, Entity); AIdPayGet = O.Amoney * PayGet; //当前级总佣金,需获取是否有下级拆分他的佣金 AIdPayGet = AIdPayGet.Floor(); decimal AIdPayGetNext = 0; //定义下一级佣金 if (tier < SysAgentList.Count) { //不是最后一级,需计算下级拆分金额 SysAgent SysAgentNext = SysAgentList.Skip(tier).Take(1).FirstOrDefault(); if (SysAgentNext != null) { if (SysAgentNext.State == 1) {//下级状态有效时才计算,如关闭了则不正计算下级 decimal PayGetNext = SysAgent.GetSplit(SysAgentNext.Tier, Entity); AIdPayGetNext = O.Amoney * PayGetNext; AIdPayGetNext = AIdPayGetNext.Floor(); } } } decimal AIdPayGetMy = AIdPayGet - AIdPayGetNext; //当前级所能得到真实佣金 decimal UsersGetAll = 0; //定义所有用户佣金 //最后一级代理商 处理用户分润 #region 最后一级代理商 处理用户分润 if (tier == SysAgentList.Count) { //获取各级分润配置 SysSet SysSet = Entity.SysSet.FirstOrNew(); int MaxLevel = SysSet.GlobaPromoteMaxLevel; //有用户分润,开始执行用户分润 Users Users = new Users(); Users.Id = O.UId; //获取用户各级关系,最大级不超过用户配置级数。返回数据包含当前用户,当前用户级数标识Tier为0 IList <Users> UsersList = Users.GetUsersById(Entity, MaxLevel); int UsersTier = 1; foreach (var U in UsersList.Where(n => n.Tier > 0 && n.State == 1)) { //UsersGetAll //UserPromoteGet UserPromoteGet = UserPromoteGetList.FirstOrDefault(n => n.PromoteLevel == U.Tier); //if (UserPromoteGet != null) //{ decimal PromoteGet = Users.GetUsersSplit(Entity, U.Tier); decimal UsersGet = O.Amoney * PromoteGet; UsersGet = UsersGet.Floor(); if (UsersTier == 1) { UsersGetAll = UsersGet; } //UsersGetSum += UsersGet; if (UsersTier < UsersList.Count) { //不是最后一级,需计算下级拆分金额 byte nexttier = (byte)(U.Tier + 1); Users UsersNext = UsersList.FirstOrDefault(o => o.Tier == nexttier); if (UsersNext != null) { if (UsersNext.State == 1) { //下级状态有效时才计算,如关闭了则不正计算下级 decimal PayGetNext = Users.GetUsersSplit(Entity, UsersNext.Tier); decimal UserPayGetNext = O.Amoney * PayGetNext; UserPayGetNext = UserPayGetNext.Floor(); //减掉下级用户的金额 UsersGet = UsersGet - UserPayGetNext; } } } if (UsersGet > 0) { //帐户变动记录 string Remark = string.Format("{0}[{1}]", TypeString, O.TNum); string SP_Ret = Entity.SP_UsersMoney(U.Id, O.TNum, UsersGet, 8, Remark, 0); if (SP_Ret != "3") { Utils.WriteLog(string.Format("U{0},O{1},T{2}:{3}【{4}】", U.Id, O.TNum, 8, UsersGet, SP_Ret), "SP_UsersMoney"); } //记录清分记录 OrderProfitLog OPL = new OrderProfitLog(); OPL.AddTime = DateTime.Now; OPL.UId = U.Id; OPL.Agent = 0; OPL.TNum = O.TNum; OPL.LogType = 1; OPL.Tier = U.Tier; OPL.Profit = UsersGet; OPL.Amoney = O.Amoney; OPL.OrderType = 21; OPL.UserName = OrderUser.UserName; Entity.OrderProfitLog.AddObject(OPL); //=====增加统计记录===== ShareTotal ShareTotal = Entity.ShareTotal.FirstOrDefault(n => n.UId == U.Id && n.Tier == U.Tier); if (ShareTotal == null) { ShareTotal = new ShareTotal(); ShareTotal.UId = U.Id; ShareTotal.AddTime = DateTime.Now; ShareTotal.ShareNum = 0; ShareTotal.Amount = O.Amoney; ShareTotal.Profit = UsersGet; ShareTotal.Tier = U.Tier; Entity.ShareTotal.AddObject(ShareTotal); } else { ShareTotal.Amount += O.Amoney; ShareTotal.Profit += UsersGet; } sumpayget = sumpayget + UsersGet; } UsersTier++; // } } } #endregion //20160704 Lin 增加统计用户拆分多少,最后一级代理金额减掉这部分金额即可。 //解决用户分剩下钱规系统逻辑问题 AIdPayGetMy = AIdPayGetMy - UsersGetAll; #region 最后一级代理商 处理同级分润 if (tier == SysAgentList.Count) { if (!p.SameAgent.IsNullOrEmpty() && AIdPayGet > 0) { SysMoneySet SysMoneySet = Entity.SysMoneySet.FirstOrNew(); decimal SameMoney = AIdPayGet * SysMoneySet.SameAgent; SameMoney = SameMoney.Floor(); SysAgent SameSysAgent = Entity.SysAgent.FirstOrNew(o => o.Id == p.SameAgent); if (SameSysAgent.State == 1 && !SameSysAgent.MyUId.IsNullOrEmpty()) { //帐户变动记录 string Remark = string.Format("{0}[{1}]", "直通车同级分润", O.TNum); string SP_Ret = Entity.SP_UsersMoney(SameSysAgent.MyUId, O.TNum, SameMoney, 8, Remark, 0); if (SP_Ret != "3") { Utils.WriteLog(string.Format("U{0},O{1},T{2}:{3}【{4}】", SameSysAgent.MyUId, O.TNum, 8, SameMoney, SP_Ret), "SP_UsersMoney"); } //记录清分记录 OrderProfitLog OPL = new OrderProfitLog(); OPL.AddTime = DateTime.Now; OPL.UId = SameSysAgent.MyUId; OPL.Agent = SameSysAgent.Id; OPL.TNum = O.TNum; OPL.LogType = 3; OPL.Tier = p.Tier; OPL.Profit = SameMoney; OPL.Amoney = O.Amoney; OPL.OrderType = 21; OPL.UserName = OrderUser.UserName; Entity.OrderProfitLog.AddObject(OPL); O.SameGet = SameMoney; } } } #endregion if (!p.MyUId.IsNullOrEmpty() && AIdPayGetMy > 0)//某一级未绑定钱包,钱留给系统^-^ { //获取钱包信息 //为了减少系统开销,这里不读取用户信息——By Lin //Users Users = Entity.Users.FirstOrDefault(n => n.Id == p.MyUId); if (p.MyUId > 0) { //帐户变动记录 string Remark = string.Format("{0}[{1}]", TypeString, O.TNum); string SP_Ret = Entity.SP_UsersMoney(p.MyUId, O.TNum, AIdPayGetMy, 8, Remark, 0); if (SP_Ret != "3") { Utils.WriteLog(string.Format("U{0},O{1},T{2}:{3}【{4}】", p.MyUId, O.TNum, 8, AIdPayGetMy, SP_Ret), "SP_UsersMoney"); } //记录清分记录 OrderProfitLog OPL = new OrderProfitLog(); OPL.AddTime = DateTime.Now; OPL.UId = p.MyUId; OPL.Agent = p.Id; OPL.TNum = O.TNum; OPL.LogType = 2; OPL.Tier = p.Tier; OPL.Profit = AIdPayGetMy; OPL.Amoney = O.Amoney; OPL.OrderType = 21; OPL.UserName = OrderUser.UserName; Entity.OrderProfitLog.AddObject(OPL); sumpayget = sumpayget + AIdPayGetMy; } } } tier++; } Entity.SaveChanges(); //统计所有分润 //decimal Profit = 0; //if (Entity.OrderProfitLog.Count(n => n.TNum == O.TNum) > 0) //{ // Profit = Entity.OrderProfitLog.Where(n => n.TNum == O.TNum).Sum(n => n.Profit);//是否会为空的情况 //} O.AgentPayGet = sumpayget;//记录总佣金支出,以便总系统计算利润 O.AgentState = 1; Entity.SaveChanges(); #endregion } if (Type == 2) { //没有退款,分润也不需要写 } return(O); }
public void Execute(IJobExecutionContext context) { string JobName = "FastQuery"; string CanRun = ConfigurationManager.AppSettings["Run" + JobName].ToString(); if (CanRun == "true") { if (!IsRun) { LokFuEntity Entity = new LokFuEntity(); IsRun = true; try { Log.Write(JobName + "任务开始执行!"); //------------------------------------------------------- #region 任务主体 //查询所有已支付但未代付订单 DateTime STime = DateTime.Now.AddDays(-1); DateTime ETime = DateTime.Now.AddSeconds(-30); IList <FastOrder> List = Entity.FastOrder.Where(n => n.State == 1 && n.PayState == 1 && n.UserState == 3 && n.UserTime <ETime && n.UserTime> STime).ToList(); //UserState 0未付 1已付 2失败 3结果未明 4付起中 foreach (var p in List) { FastPayWay FastPayWay = Entity.FastPayWay.FirstOrDefault(n => n.Id == p.PayWay && n.State == 1); FastUserPay FastUserPay = Entity.FastUserPay.FirstOrDefault(n => n.PayWay == p.PayWay && n.UId == p.UId); if (FastPayWay != null) { string[] PayConfigArr = FastPayWay.QueryArray.Split(','); if (FastPayWay.DllName == "HFPay") { #region 查代付结果 if (PayConfigArr.Length == 3) { string HF_Url = "https://api.zhifujiekou.com/api/qcashquery"; string MerId = PayConfigArr[0]; string MerKey = PayConfigArr[1]; string orderId = p.TNum;//商户流水号 string PostJson = "{\"merid\":\"" + MerId + "\",\"orderid\":\"" + orderId + "\"}"; string DataBase64 = LokFuEncode.Base64Encode(PostJson, "utf-8"); string Sign = (DataBase64 + MerKey).GetMD5(); DataBase64 = HttpUtility.UrlEncode(DataBase64); string PostData = string.Format("req={0}&sign={1}", DataBase64, Sign); string Ret = Utils.PostRequest(HF_Url, PostData, "utf-8"); JObject JS = new JObject(); try { JS = (JObject)JsonConvert.DeserializeObject(Ret); } catch (Exception) { JS = null; } if (JS != null) { if (JS["resp"] != null) { string resp = JS["resp"].ToString(); Ret = LokFuEncode.Base64Decode(resp, "utf-8"); try { JS = (JObject)JsonConvert.DeserializeObject(Ret); } catch (Exception) { JS = null; } if (JS != null) { string respcode = JS["respcode"].ToString(); if (respcode == "00") { string resultcode = JS["resultcode"].ToString(); if (resultcode == "0000") { p.UserState = 1; } else if (resultcode == "2002" || resultcode == "2003") { p.UserState = 2; } else { } Entity.SaveChanges(); } } } } //================================================ PayLog PayLog = new PayLog(); PayLog.PId = FastPayWay.Id; PayLog.OId = p.TNum; PayLog.TId = ""; PayLog.Amount = 0; PayLog.Way = "FASTDFQ"; PayLog.AddTime = DateTime.Now; PayLog.Data = Ret; PayLog.State = 1; Entity.PayLog.AddObject(PayLog); //================================================ Entity.SaveChanges(); } #endregion } if (FastPayWay.DllName == "HFJSPay") { #region 结算系统 //不需要 fastordersqueryModel fastordersqueryModel = new fastordersqueryModel() { merid = FastUserPay.MerId, orderid = "", queryid = p.TNum }; fastordersqueryResult fastordersqueryResult = HFJSTools.fastordersquery(fastordersqueryModel, FastUserPay.MerKey); //================================================ //记录通知信息 PayLog PayLog = new PayLog(); PayLog.PId = p.PayWay.Value; PayLog.OId = p.TNum; PayLog.TId = fastordersqueryResult.queryid; PayLog.Amount = p.Amoney; PayLog.Way = "FASTDFQ"; PayLog.AddTime = DateTime.Now; PayLog.Data = HFJSTools.MyObjectToJson(fastordersqueryResult); PayLog.State = 1; Entity.PayLog.AddObject(PayLog); Entity.SaveChanges(); //================================================ if (fastordersqueryResult.respcode == "00") { if (fastordersqueryResult.resultcode == "0000") { p.UserState = 1; Entity.SaveChanges(); } if (fastordersqueryResult.resultcode == "1003") { p.UserState = 2; Entity.SaveChanges(); } } else { string resp_desc = fastordersqueryResult.respmsg; Utils.WriteLog("HFJS[Query][" + p.TNum + "]:" + resp_desc, "JobHFJS"); } #endregion } } Log.WriteLog("查询代付[" + p.TNum + "]!", JobName); } #endregion //------------------------------------------------------- Log.Write(JobName + "任务执行结束![共计" + List.Count + "条]"); } catch (Exception Ex) { Log.Write(JobName + "任务执行过程出错!", Ex); } IsRun = false; } else { Log.Write(JobName + "任务还在执行中!"); } } }
/// <summary> /// 分润 /// </summary> /// <param name="O"></param> /// <param name="Entity"></param> /// <returns></returns> public static JobOrders PayAgent(this JobOrders JobOrders, LokFuEntity Entity) { SysSet SysSet = Entity.SysSet.FirstOrNew(); if (JobOrders.AgentId.IsNullOrEmpty()) {//代理商没有情况下 return(JobOrders); } //if (JobOrders.AgentGet.IsNullOrEmpty()) //{//没有佣金 // return JobOrders; //} Users OrderUser = Entity.Users.FirstOrDefault(n => n.Id == JobOrders.UId);//读取订单用户 #region 结算 if (JobOrders.AgentState != 0) {//已结算,不能重复结算 return(JobOrders); } JobOrders.AgentState = 1; Entity.SaveChanges(); //获取各级代理商 SysAgent SysAgent = new SysAgent(); SysAgent.Id = JobOrders.AgentId; IList <SysAgent> SysAgentList = SysAgent.GetAgentsById(Entity); decimal AIdPayGet = 0; //总佣金 decimal AgengtGet = 0; //分润 decimal Amount = JobOrders.TotalMoney - JobOrders.Poundage; int tier = 1; foreach (var p in SysAgentList) { if (p.State == 1) { decimal PayGet = SysAgent.GetJobSplit(p.Tier, Entity); AIdPayGet = Amount * PayGet;//当前级总佣金,需获取是否有下级拆分他的佣金 AIdPayGet = AIdPayGet.Floor(); decimal AIdPayGetNext = 0;//定义下一级佣金 if (tier < SysAgentList.Count) { //不是最后一级,需计算下级拆分金额 SysAgent SysAgentNext = SysAgentList.Skip(tier).Take(1).FirstOrDefault(); if (SysAgentNext != null) { if (SysAgentNext.State == 1) {//下级状态有效时才计算,如关闭了则不正计算下级 decimal PayGetNext = SysAgent.GetJobSplit(SysAgentNext.Tier, Entity); AIdPayGetNext = Amount * PayGetNext; AIdPayGetNext = AIdPayGetNext.Floor(); } } } decimal AIdPayGetMy = AIdPayGet - AIdPayGetNext; //当前级所能得到真实佣金 decimal UsersGetAll = 0; //定义所有用户佣金 //最后一级代理商 处理用户分润 #region 最后一级代理商 处理用户分润 if (tier == SysAgentList.Count) { int MaxLevel = SysSet.GlobaPromoteMaxLevel; //有用户分润,开始执行用户分润 Users Users = new Users(); Users.Id = JobOrders.UId; //获取用户各级关系,最大级不超过用户配置级数。返回数据包含当前用户,当前用户级数标识Tier为0 IList <Users> UsersList = Users.GetUsersById(Entity, MaxLevel); int UsersTier = 1; foreach (var U in UsersList.Where(n => n.Tier > 0 && n.State == 1)) { //UsersGetAll //UserPromoteGet UserPromoteGet = UserPromoteGetList.FirstOrDefault(n => n.PromoteLevel == U.Tier); //if (UserPromoteGet != null) //{ decimal PromoteGet = Users.GetUsersJobSplit(Entity, U.Tier); decimal UsersGet = Amount * PromoteGet; UsersGet = UsersGet.Floor(); if (UsersTier == 1) { UsersGetAll = UsersGet; } //UsersGetSum += UsersGet; if (UsersTier < UsersList.Count) { //不是最后一级,需计算下级拆分金额 byte nexttier = (byte)(U.Tier + 1); Users UsersNext = UsersList.FirstOrDefault(o => o.Tier == nexttier); if (UsersNext != null) { if (UsersNext.State == 1) {//下级状态有效时才计算,如关闭了则不正计算下级 decimal PayGetNext = Users.GetUsersJobSplit(Entity, UsersNext.Tier); decimal UserPayGetNext = Amount * PayGetNext; UserPayGetNext = UserPayGetNext.Floor(); //减掉下级用户的金额 UsersGet = UsersGet - UserPayGetNext; } } } if (UsersGet > 0) { //帐户变动记录 string Remark = string.Format("{0}[{1}]", "卡管家分润", JobOrders.TNum); string SP_Ret = Entity.SP_UsersMoney(U.Id, JobOrders.TNum, UsersGet, 8, Remark, 0); if (SP_Ret != "3") { Utils.WriteLog(string.Format("U{0},O{1},T{2}:{3}【{4}】", U.Id, JobOrders.TNum, 8, UsersGet, SP_Ret), "SP_UsersMoney"); } //记录清分记录 OrderProfitLog OPL = new OrderProfitLog(); OPL.AddTime = DateTime.Now; OPL.UId = U.Id; OPL.Agent = 0; OPL.TNum = JobOrders.TNum; OPL.LogType = 1; OPL.Tier = U.Tier; OPL.Profit = UsersGet; OPL.Amoney = Amount; OPL.OrderType = 31; OPL.UserName = OrderUser.UserName; Entity.OrderProfitLog.AddObject(OPL); //=====增加统计记录===== //ShareTotal ShareTotal = Entity.ShareTotal.FirstOrDefault(n => n.UId == U.Id && n.Tier == U.Tier); //if (ShareTotal == null) //{ // ShareTotal = new ShareTotal(); // ShareTotal.UId = U.Id; // ShareTotal.AddTime = DateTime.Now; // ShareTotal.ShareNum = 0; // ShareTotal.Amount = JobOrders.Amount; // ShareTotal.Profit = UsersGet; // ShareTotal.Tier = U.Tier; // Entity.ShareTotal.AddObject(ShareTotal); //} //else //{ // ShareTotal.Amount += JobOrders.Amount; // ShareTotal.Profit += UsersGet; //} AgengtGet = AgengtGet + UsersGet; } UsersTier++; // } } } #endregion //20160704 Lin 增加统计用户拆分多少,最后一级代理金额减掉这部分金额即可。 //解决用户分剩下钱规系统逻辑问题 AIdPayGetMy = AIdPayGetMy - UsersGetAll; #region 最后一级代理商 处理同级分润 if (tier == SysAgentList.Count) { if (!p.SameAgent.IsNullOrEmpty() && AIdPayGet > 0) { SysMoneySet SysMoneySet = Entity.SysMoneySet.FirstOrNew(); decimal SameMoney = AIdPayGet * SysMoneySet.SameAgent; SameMoney = SameMoney.Floor(); SysAgent SameSysAgent = Entity.SysAgent.FirstOrNew(o => o.Id == p.SameAgent); if (SameSysAgent.State == 1 && !SameSysAgent.MyUId.IsNullOrEmpty()) { //帐户变动记录 string Remark = string.Format("{0}[{1}]", "卡管家同级分润", JobOrders.TNum); string SP_Ret = Entity.SP_UsersMoney(SameSysAgent.MyUId, JobOrders.TNum, SameMoney, 8, Remark, 0); if (SP_Ret != "3") { Utils.WriteLog(string.Format("U{0},O{1},T{2}:{3}【{4}】", SameSysAgent.MyUId, JobOrders.TNum, 8, SameMoney, SP_Ret), "SP_UsersMoney"); } //记录清分记录 OrderProfitLog OPL = new OrderProfitLog(); OPL.AddTime = DateTime.Now; OPL.UId = SameSysAgent.MyUId; OPL.Agent = SameSysAgent.Id; OPL.TNum = JobOrders.TNum; OPL.LogType = 3; OPL.Tier = p.Tier; OPL.Profit = SameMoney; OPL.Amoney = Amount; OPL.OrderType = 31; OPL.UserName = OrderUser.UserName; Entity.OrderProfitLog.AddObject(OPL); JobOrders.SameGet = SameMoney; } } } #endregion if (!p.MyUId.IsNullOrEmpty() && AIdPayGetMy > 0)//某一级未绑定钱包,钱留给系统^-^ { //获取钱包信息 //为了减少系统开销,这里不读取用户信息——By Lin //Users Users = Entity.Users.FirstOrDefault(n => n.Id == p.MyUId); if (p.MyUId > 0) { //帐户变动记录 string Remark = string.Format("{0}[{1}]", "卡管家分润", JobOrders.TNum); string SP_Ret = Entity.SP_UsersMoney(p.MyUId, JobOrders.TNum, AIdPayGetMy, 8, Remark, 0); if (SP_Ret != "3") { Utils.WriteLog(string.Format("U{0},O{1},T{2}:{3}【{4}】", p.MyUId, JobOrders.TNum, 8, AIdPayGetMy, SP_Ret), "SP_UsersMoney"); } //记录清分记录 OrderProfitLog OPL = new OrderProfitLog(); OPL.AddTime = DateTime.Now; OPL.UId = p.MyUId; OPL.Agent = p.Id; OPL.TNum = JobOrders.TNum; OPL.LogType = 2; OPL.Tier = p.Tier; OPL.Profit = AIdPayGetMy; OPL.Amoney = Amount; OPL.OrderType = 31; OPL.UserName = OrderUser.UserName; Entity.OrderProfitLog.AddObject(OPL); AgengtGet = AgengtGet + AIdPayGetMy; } } } tier++; } Entity.SaveChanges(); //统计所有分润 //decimal Profit = 0; //if (Entity.OrderProfitLog.Count(n => n.TNum == JobOrders.TNum) > 0) //{ // Profit = Entity.OrderProfitLog.Where(n => n.TNum == JobOrders.TNum).Sum(n => n.Profit);//是否会为空的情况 //} JobOrders.AgentGet = AgengtGet;//记录总佣金支出,以便总系统计算利润 decimal RunGet = Entity.JobItem.Where(o => o.TNum == JobOrders.TNum && o.RunType == 1).Sum(o => o.RunGet); JobOrders.HFGet = JobOrders.Poundage - AgengtGet - RunGet - JobOrders.CashGet; JobOrders.AgentTime = DateTime.Now; Entity.SaveChanges(); #endregion return(JobOrders); }
public void Execute(IJobExecutionContext context) { string JobName = "FastCash"; string CanRun = ConfigurationManager.AppSettings["Run" + JobName].ToString(); if (CanRun == "true") { if (!IsRun) { LokFuEntity Entity = new LokFuEntity(); IsRun = true; try { Log.Write(JobName + "任务开始执行!"); //------------------------------------------------------- #region 任务主体 //查询所有已支付但未代付订单 DateTime CanPayTime = DateTime.Now.AddSeconds(-300);//20秒前支付订单可付 IList <FastOrder> List = Entity.FastOrder.Where(n => n.State == 1 && n.PayState == 1 && n.UserState == 0 && n.PayTime < CanPayTime).ToList(); //UserState 0未付 1已付 2失败 3结果未明 4付起中 //foreach (var p in List.Where(n=>n.PayWay==16 && n.)) //List = List.Where(n => n.PayWay != 16 || (n.PayWay == 16 && n.PayTime < CanPayTime2)).ToList(); foreach (var p in List) { p.UserTime = DateTime.Now; p.UserState = 4; } Entity.SaveChanges(); foreach (var p in List) { Users Users = Entity.Users.FirstOrDefault(n => n.Id == p.UId); if (Users.StopPayState == 0) { FastPayWay FastPayWay = Entity.FastPayWay.FirstOrDefault(n => n.Id == p.PayWay && n.State == 1); if (FastPayWay != null) { string[] PayConfigArr = FastPayWay.QueryArray.Split(','); if (FastPayWay.DllName == "HFPay") { #region 结算中心代付 string HFCash_Url = "https://api.zhifujiekou.com/api/qcashgateway"; //不需要 string NoticePath = ConfigurationManager.AppSettings["NoticePath"].ToString(); string NoticeUrl = NoticePath + "/PayCenter/HFCash/FastNotice.html"; //提交结算中心 string merId = PayConfigArr[0]; //商户号 string merKey = PayConfigArr[1]; //商户密钥 string orderId = p.TNum; //商户流水号 string OrderMoney = (p.PayMoney * 100).ToString("F0"); //金额,以分为单 string UserCardId = Users.CardId; string PostJson = "{\"action\":\"QCash\",\"txnamt\":\"" + OrderMoney + "\",\"merid\":\"" + merId + "\",\"orderid\":\"" + orderId + "\",\"backurl\":\"" + NoticeUrl + "\",\"bin\":\"" + p.Bin + "\",\"accno\":\"" + p.Card + "\",\"accname\":\"" + p.CardName + "\",\"cardno\":\"" + UserCardId + "\"}"; //传送数据Base64 string DataBase64 = LokFuEncode.Base64Encode(PostJson, "utf-8"); //获得签名 string Sign = (DataBase64 + merKey).GetMD5(); //传送数据UrlEnCode DataBase64 = HttpUtility.UrlEncode(DataBase64); //组装Post数据 string PostData = string.Format("req={0}&sign={1}", DataBase64, Sign); //Post数据,获得结果 string Ret = Utils.PostRequest(HFCash_Url, PostData, "utf-8"); JObject JS = new JObject(); try { JS = (JObject)JsonConvert.DeserializeObject(Ret); } catch (Exception) { Utils.WriteLog("处理代付[" + p.TNum + "]!" + Ret, "CashPay"); JS = null; } if (JS != null) { string resp = JS["resp"].ToString(); Ret = LokFuEncode.Base64Decode(resp, "utf-8"); try { JS = (JObject)JsonConvert.DeserializeObject(Ret); } catch (Exception) { Utils.WriteLog("处理代付[" + p.TNum + "]!解密出错", "CashPay"); JS = null; } if (JS != null) { string respcode = JS["respcode"].ToString(); if (respcode == "00") { string resultcode = JS["resultcode"].ToString(); if (resultcode == "0000") { p.UserState = 1; } else if (resultcode == "2002" || resultcode == "2003") { p.UserState = 2; } else { p.UserState = 3; } } else { string respmsg = JS["respmsg"].ToString(); Utils.WriteLog("处理代付[" + p.TNum + "]!" + respmsg, "CashPay"); } } } //====================================== PayLog PayLog = new PayLog(); PayLog.PId = FastPayWay.Id; PayLog.OId = p.TNum; PayLog.TId = ""; PayLog.Amount = 0; PayLog.Way = "FASTDF"; PayLog.AddTime = DateTime.Now; PayLog.Data = Ret; PayLog.State = 1; Entity.PayLog.AddObject(PayLog); //====================================== Entity.SaveChanges(); #endregion } if (FastPayWay.DllName == "HFJSPay") { #region 结算系统 //不需要 #endregion } } Log.WriteLog("处理代付[" + p.TNum + "]!", JobName); } else { Log.WriteLog("处理代付[" + p.TNum + "]!商户止付", JobName); } } #endregion //------------------------------------------------------- Log.Write(JobName + "任务执行结束![共计" + List.Count + "条]"); } catch (Exception Ex) { Log.Write(JobName + "任务执行过程出错!", Ex); } IsRun = false; } else { Log.Write(JobName + "任务还在执行中!"); } } }
public void Execute(IJobExecutionContext context) { string JobName = "TnInMoney"; string CanRun = ConfigurationManager.AppSettings["Run" + JobName].ToString(); if (CanRun == "true") { if (!IsRun) { LokFuEntity Entity = new LokFuEntity(); IsRun = true; try { Log.Write(JobName + "任务开始执行!"); //------------------------------------------------------- #region 任务主体 IList <TaskOrders> List = Entity.TaskOrders.Where(n => n.State == 1 && n.ODate <= DateTime.Now).ToList(); foreach (var p in List) { p.State = 2; Entity.SaveChanges(); Orders Orders = Entity.Orders.FirstOrDefault(n => n.TNum == p.OId); if (Orders != null) { if (Orders.FrozenState == 1) { Orders.FrozenState = 0; Entity.SaveChanges(); if (Orders.TType == 1) { OrderRecharge OrderRecharge = Entity.OrderRecharge.FirstOrDefault(n => n.OId == Orders.TNum); if (OrderRecharge != null) { OrderRecharge.SetUnFrozen(Entity); } } if (Orders.TType == 7 || Orders.TType == 8 || Orders.TType == 9) { OrderF2F OrderF2F = Entity.OrderF2F.FirstOrDefault(n => n.OId == Orders.TNum); if (OrderF2F != null) { OrderF2F.SetUnFrozen(Entity); } } } Orders.InState = 1; Orders.TState = 2; Orders.InTimed = DateTime.Now; Entity.SaveChanges(); } Log.WriteLog("执行入帐:" + p.OId, JobName); } #endregion //------------------------------------------------------- Log.Write(JobName + "任务执行结束![共计" + List.Count + "条]"); } catch (Exception Ex) { Log.Write(JobName + "任务执行过程出错!", Ex); } IsRun = false; } else { Log.Write(JobName + "任务还在执行中!"); } } }