public ActionResult Audit(OrdersRefund OrdersRefund) { #region 校验及初始化 if (!(OrdersRefund.TState == 2 || OrdersRefund.TState == 3)) { ViewBag.ErrorMsg = "请审核"; return(View("Error")); } if (OrdersRefund.TState == 3 && OrdersRefund.AuditRemark.IsNullOrEmpty()) { ViewBag.ErrorMsg = "请填写审核备注"; return(View("Error")); } if (OrdersRefund.AuditRemark.IsNullOrEmpty()) { OrdersRefund.AuditRemark = string.Empty; } var baseOrdersRefund = Entity.OrdersRefund.FirstOrDefault(n => n.Id == OrdersRefund.Id); if (baseOrdersRefund == null) { ViewBag.ErrorMsg = "数据不存在"; return(View("Error")); } if (baseOrdersRefund.TState != 1) { ViewBag.ErrorMsg = "已审核"; return(View("Error")); } Orders baseOrders = Entity.Orders.FirstOrDefault(o => o.TNum == baseOrdersRefund.TNum); if (baseOrders == null) { ViewBag.ErrorMsg = "订单不存在"; return(View("Error")); } Users baseUsers = Entity.Users.FirstOrDefault(o => o.Id == baseOrders.UId); if (baseUsers == null) { ViewBag.ErrorMsg = "订单商户不存在"; return(View("Error")); } #endregion //实际到账金额 decimal PayMoney = 0; #region 获取实际到账金额 //银联卡支付订单 OrderRecharge OrderRecharge = null; OrderF2F OrderF2F = null; if (baseOrders.TType == 1) { OrderRecharge = Entity.OrderRecharge.FirstOrNew(n => n.OId == baseOrders.TNum); PayMoney = OrderRecharge.PayMoney; } //微信 支付宝 NFC if (baseOrders.TType == 7 || baseOrders.TType == 8 || baseOrders.TType == 9) { OrderF2F = Entity.OrderF2F.FirstOrNew(n => n.OId == baseOrders.TNum); PayMoney = OrderF2F.PayMoney; } #endregion #region 审核通过 if (OrdersRefund.TState == 2) { //订单扣款 int USERSID = baseUsers.Id; string TNUM = baseOrders.TNum; string SP_Ret = Entity.SP_UsersMoney(USERSID, TNUM, PayMoney, 11, OrdersRefund.AuditRemark); if (SP_Ret != "3") { Utils.WriteLog(string.Format("U{0},O{1},T{2}:{3}【{4}】", USERSID, TNUM, 11, PayMoney, SP_Ret), "SP_UsersMoney"); ViewBag.ErrorMsg = "扣款失败"; return(View("Error")); } //订单信息修改 baseOrders.TState = 4; baseOrders.TDState = OrdersRefund.TState; #region 退还佣金 //银联卡支付订单 if (baseOrders.TType == 1) { OrderRecharge.OrderState = baseOrders.TState; //下级佣金退款 OrderRecharge.PayAgent(Entity, 2, 1); } //微信 支付宝 NFC if (baseOrders.TType == 7 || baseOrders.TType == 8 || baseOrders.TType == 9) { OrderF2F.OrderState = baseOrders.TState; //下级佣金退款 OrderF2F.PayAgent(Entity, 2, 1); } #endregion } #endregion #region 审核失败 if (OrdersRefund.TState == 3) { //资金解冻 #region 银联卡支付订单 if (baseOrders.TType == 1) { //包含下级分润 OrderRecharge.SetUnFrozen(Entity); } #endregion #region 微信 支付宝 NFC if (baseOrders.TType == 7 || baseOrders.TType == 8 || baseOrders.TType == 9) { //包含下级分润 OrderF2F.SetUnFrozen(Entity); } #endregion baseOrders.FrozenState = 0; //修改冗余属性 baseOrders.TDState = OrdersRefund.TState; } #endregion //保存退款信息,避免被savechanges baseOrdersRefund.AuditAdminId = this.AdminUser.Id; baseOrdersRefund.AuditAdminName = this.AdminUser.TrueName; baseOrdersRefund.AuditRemark = OrdersRefund.AuditRemark; baseOrdersRefund.TState = OrdersRefund.TState; baseOrdersRefund.AuditTime = DateTime.Now; //记录 var OrdersRefundLog = new OrdersRefundLog() { AddTime = DateTime.Now, AdminId = this.AdminUser.Id, AdminName = this.AdminUser.TrueName, Img = string.Empty, LogType = OrdersRefund.TState, Remark = OrdersRefund.AuditRemark, TNum = OrdersRefund.TNum, }; this.Entity.OrdersRefundLog.AddObject(OrdersRefundLog); Entity.SaveChanges(); ViewBag.Msg = "操作成功,审核结果:" + (OrdersRefund.TState == 2 ? "通过" : "失败"); return(View("Succeed")); }
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 + "任务还在执行中!"); } } }