public void SaveEdit(OrderCash OrderCash) { OrderCash baseOrderCash = Entity.OrderCash.FirstOrDefault(n => n.Id == OrderCash.Id); Orders Orders = Entity.Orders.FirstOrDefault(n => n.TNum == baseOrderCash.OId); if (baseOrderCash.OrderState == 2 && baseOrderCash.PayState == 3) { baseOrderCash.PayState = 2; baseOrderCash.FState = 1; baseOrderCash.FTime = DateTime.Now; Orders.PayState = 2; Entity.SaveChanges(); //======分润====== baseOrderCash = baseOrderCash.PayAgent(Entity, 1); Orders.AgentPayGet = (decimal)baseOrderCash.AgentCashGet; var OrderCashLog = new OrderCashLog() { AddTime = DateTime.Now, AdminId = this.AdminUser.Id, AdminName = this.AdminUser.TrueName, TNum = baseOrderCash.OId, Remark = string.Empty, LogType = 4, }; this.Entity.OrderCashLog.AddObject(OrderCashLog); Entity.SaveChanges(); Orders.SendMsg(Entity);//发送消息类 } BaseRedirect(); }
public void Save(OrderCash OrderCash) { OrderCash baseOrderCash = Entity.OrderCash.FirstOrDefault(n => n.Id == OrderCash.Id); Orders Orders = Entity.Orders.FirstOrDefault(n => n.TNum == baseOrderCash.OId); var OrderCashLog = new OrderCashLog() { AddTime = DateTime.Now, AdminId = this.AdminUser.Id, AdminName = this.AdminUser.TrueName, TNum = baseOrderCash.OId, Remark = string.Empty, LogType = 1, }; this.Entity.OrderCashLog.AddObject(OrderCashLog); Entity.SaveChanges(); if (BasicSet.CashPayWay == 1)//开启自动结算时执行 { //自动出款 baseOrderCash.PayCash(Orders, Entity);//去付款 } else { if (baseOrderCash.OrderState == 2 && baseOrderCash.PayState == 1 && baseOrderCash.FState == 0) { baseOrderCash.PayState = 2; baseOrderCash.FState = 1; baseOrderCash.FTime = DateTime.Now; Orders.PayState = 2; Entity.SaveChanges(); //======分润====== baseOrderCash = baseOrderCash.PayAgent(Entity, 1); Orders.AgentPayGet = (decimal)baseOrderCash.AgentCashGet; Entity.SaveChanges(); } } Orders.SendMsg(Entity);//发送消息类 BaseRedirect(); }
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 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 + "任务还在执行中!"); } } }
public ActionResult Save(OrderCash OrderCash) { OrderCash baseOrderCash = Entity.OrderCash.FirstOrDefault(n => n.Id == OrderCash.Id); string tnum = "TK" + baseOrderCash.OId; if (!this.GetRuningState(tnum)) { this.SetRuningState(tnum); try { OrdersPayOnly OPO = new OrdersPayOnly(); OPO.TNum = tnum; OPO.AddTime = DateTime.Now; Entity.OrdersPayOnly.AddObject(OPO); Entity.SaveChanges(); } catch (Exception) { ViewBag.ErrorMsg = "重复入帐!"; return(View("Error")); } //return null; if (baseOrderCash.OrderState == 2 && baseOrderCash.PayState == 3) { var OrderCashLog = new OrderCashLog() { AddTime = DateTime.Now, AdminId = this.AdminUser.Id, AdminName = this.AdminUser.TrueName, TNum = baseOrderCash.OId, Remark = string.Empty, LogType = 3, }; this.Entity.OrderCashLog.AddObject(OrderCashLog); baseOrderCash.RefundTime = DateTime.Now; baseOrderCash.PayState = 4; Orders Orders = Entity.Orders.FirstOrDefault(n => n.TNum == baseOrderCash.OId); Orders.PayState = 4; //退款到余额 Users baseUsers = Entity.Users.FirstOrDefault(n => n.Id == baseOrderCash.UId); //帐户变动记录 int USERSID = baseUsers.Id; string TNUM = Orders.TNum; decimal PAYMONEY = baseOrderCash.Amoney; string SP_Ret = Entity.SP_UsersMoney(USERSID, TNUM, PAYMONEY, 6, ""); if (SP_Ret != "3") { Utils.WriteLog(string.Format("U{0},O{1},T{2}:{3}【{4}】", USERSID, TNUM, 6, PAYMONEY, SP_Ret), "SP_UsersMoney"); } //======分润====== baseOrderCash = baseOrderCash.PayAgent(Entity, 2); Orders.AgentPayGet = (decimal)baseOrderCash.AgentCashGet; Entity.SaveChanges(); Orders.SendMsg(Entity);//发送消息类 //T0时增加配额 if (baseOrderCash.TrunType == 0) { decimal Money = baseOrderCash.Amoney - (decimal)baseOrderCash.UserRate; DateTime Today = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd")); TaskTimeSet TaskTimeSet = Entity.TaskTimeSet.FirstOrDefault(n => n.ODate == Today); if (TaskTimeSet != null) { if (TaskTimeSet.UsedMoney >= Money) { TaskTimeSet.UsedMoney -= Money; } else { TaskTimeSet.UsedMoney = 0; } Entity.SaveChanges(); } } } BaseRedirect(); } return(null); }