protected void Application_Error(object sender, EventArgs e) { try { var exception = Server.GetLastError(); ExceptionLog exceptionLog = new ExceptionLog(); exceptionLog.Message = exception.Message; exceptionLog.StackTrace = exception.StackTrace; exceptionLog.CreationTime = DateTime.Now; exceptionLog.Explanation = exception.Source; _exceptionLogManager.Add(exceptionLog); } catch (Exception) { Response.Redirect($"~/WebSite/SinemaDevi.Home.aspx"); } }
private readonly static long companyAccountParamenterID = Convert.ToInt64(ConfigurationManager.AppSettings["companyAccountParamenterID"]); //公司虚拟帐户系统参数ID public void Execute(IJobExecutionContext context) { ExceptionLogModel exceptionLogModel = new ExceptionLogModel(); exceptionLogModel.ServiceName = "会员购物订单返现订单生成服务"; exceptionLogModel.CreateBy = "系统服务"; try { _logger.Error(typeof(BounsJob), "会员购物订单返现订单生成服务开始***********************************"); //订单信息 string sqlOrder = string.Format(@"select OrderID,OrderStatus,DelayDays,OrderAmount,CostAmount,UserID,RefundFlag from [Order] where OrderStatus=5 and RefundFlag in(0,2)"); List <dynamic> sourcesOrder = _database.RunSqlQuery(x => x.ToResultSets(sqlOrder))[0]; List <OderModel> listOrder = sourcesOrder.ToEntity <OderModel>(); //订单跟踪信息 string sqlOrderTrackingLog = string.Format(@"select OrderID,OrderStatus,CreateTime from OrderTrackingLog where OrderID in(select OrderID from [Order] where OrderStatus=5)"); List <dynamic> sourcesOrderTrackingLog = _database.RunSqlQuery(x => x.ToResultSets(sqlOrderTrackingLog))[0]; List <OrderTrackingLogModel> listOrderTrackingLog = sourcesOrderTrackingLog.ToEntity <OrderTrackingLogModel>(); if (listOrder != null && listOrder.Count > 0) { foreach (OderModel orderModel in listOrder) { YH_User currUser = (YH_User)_database.Db.YH_User.FindByUserID(orderModel.UserID); if (currUser != null) { try { #region 订单表状态为已收货OrderStatus=5且退货标示0正常,2已处理(包括成功,失败)RefundFlag in{0,2} if (orderModel.OrderStatus == (int)HKTHMall.Domain.Enum.OrderEnums.OrderStatus.OutTimeReceiving) { var orderLog = listOrderTrackingLog.Find(orderTrackingLog => orderTrackingLog.OrderID == orderModel.OrderID && orderTrackingLog.OrderStatus == orderModel.OrderStatus); if (orderLog != null) { //DateTime endTime = orderLog.CreateTime.AddDays(earningsDays); DateTime endTime = orderLog.CreateTime.AddMinutes(earningsDays); if (endTime < DateTime.Now && orderModel.IsReward == 0) { if (orderModel.RefundFlag != 1) { BackMessage resultModel = _rebateService.GenerateList(orderModel); if (resultModel.status == 1) { _logger.Error(typeof(BounsJob), string.Format("处理订单【{0}】的返现订单生成成功", orderModel.OrderID)); } else { exceptionLogModel.HandleId = orderModel.OrderID; exceptionLogModel.Status = 1; exceptionLogModel.ResultType = 1; exceptionLogModel.Message = string.Format("处理订单【{0}】的会员购物订单返现订单生成失败,", orderModel.OrderID); exceptionLogService.Add(exceptionLogModel); _logger.Error(typeof(BounsJob), string.Format("处理订单【{0}】的会员购物订单返现订单生成失败,", orderModel.OrderID)); } } } } else { exceptionLogModel.HandleId = orderModel.OrderID; exceptionLogModel.Status = 1; exceptionLogModel.ResultType = 1; exceptionLogModel.Message = "订单返现订单生成,订单【" + orderModel.OrderID + "】跟踪信息查询无结果"; exceptionLogService.Add(exceptionLogModel); _logger.Error(typeof(BounsJob), "订单返现订单生成,订单【" + orderModel.OrderID + "】跟踪信息查询无结果"); } } #endregion } catch (Exception ex) { exceptionLogModel.HandleId = orderModel.OrderID; exceptionLogModel.Status = 1; exceptionLogModel.ResultType = 1; exceptionLogModel.Message = "【会员购物订单返现订单生成算法foreach】" + ex.Message; exceptionLogService.Add(exceptionLogModel); _logger.Error(typeof(BounsJob), "【会员购物订单返现订单生成算法foreach】" + ex.Message); } } else { exceptionLogModel.HandleId = orderModel.OrderID; exceptionLogModel.Status = 1; exceptionLogModel.ResultType = 1; exceptionLogModel.Message = string.Format("处理订单【{0}】的订单返现订单生成失败,获取订单用户【{1}】信息失败", orderModel.OrderID, orderModel.UserID); exceptionLogService.Add(exceptionLogModel); _logger.Error(typeof(BounsJob), string.Format("处理订单【{0}】的订单返现订单生成失败,获取订单用户【{1}】信息失败", orderModel.OrderID, orderModel.UserID)); } } } else { _logger.Error(typeof(BounsJob), "【会员购物订单返现订单生成服务】本次未处理任何数据."); } exceptionLogModel.HandleId = "0"; exceptionLogModel.Status = 2; exceptionLogModel.ResultType = 2; exceptionLogModel.Message = "运行正常"; exceptionLogService.Add(exceptionLogModel); _logger.Error(typeof(BounsJob), "会员购物订单返现订单生成服务结束**********************************"); } catch (Exception ex) { exceptionLogModel.HandleId = "0"; exceptionLogModel.Status = 1; exceptionLogModel.ResultType = 1; exceptionLogModel.Message = "【会员购物订单返现订单生成服务运行环节报错】" + ex.Message; exceptionLogService.Add(exceptionLogModel); _logger.Error(typeof(BounsJob), "【会员购物订单返现订单生成服务运行环节报错】" + ex.Message); } }
/// <summary> /// 返现操作 /// </summary> /// <param name="id"></param> /// <returns></returns> public void CashBackOrder() { ExceptionLogModel exceptionLogModel = new ExceptionLogModel(); exceptionLogModel.ServiceName = "会员订单返现服务"; exceptionLogModel.CreateBy = "系统返现服务"; var zr = _database.Db.ZJ_RebateInfo; List <ZJ_RebateInfo> zjorder = zr.FindAll(zr.Status == 1 && zr.StartTime <= DateTime.Now).ToList <ZJ_RebateInfo>(); zjorder = zjorder.FindAll(x => x.LastUpdateTime == null || DateTime.Now.Date.Subtract(((DateTime)x.LastUpdateTime).Date).Days > 0); if (zjorder != null && zjorder.Count > 0) { foreach (ZJ_RebateInfo model in zjorder) { try { //判断是否已返现完成 if (model.TotalMoney <= model.PaidMoney) { zr.UpdateByID(ID: model.ID, Status: 2, LastUpdateBY: "系统服务", LastUpdateTime: DateTime.Now); _logger.Error(typeof(ZJ_RebateService), string.Format("订单【{0}】的已经返现完成", model.ID)); } else { decimal m = 0; //本次返回金额 decimal pm = 0; //当前已付金额+本次返回金额 int pd = 0; if (model.TotalDay - model.PaidDays == 1) //最后一天返回所有余额(小数点问题) { m = model.TotalMoney - model.PaidMoney; } else { m = ToFixed((model.TotalMoney / model.TotalDay), 2); if (m < 0.01m) { m = 0.01m; } } pm = model.PaidMoney + m; pd = model.PaidDays + 1; #region 用户余额 ZJ_UserBalanceModel ub = new ZJ_UserBalanceModel(); ub = _database.Db.ZJ_UserBalance.FindByUserId(UserId: model.UserID); if (ub == null) { exceptionLogModel.Message = string.Format("未能找到用户【{0}】的余额信息", model.UserID); exceptionLogModel.ResultType = 2; exceptionLogModel.Status = 1; } #endregion #region 添加资金异动流水 ZJ_UserBalanceChangeLogModel ulogModel = new ZJ_UserBalanceChangeLogModel(); ulogModel.AddOrCutAmount = m; ulogModel.AddOrCutType = 17; ulogModel.CreateBy = "系统返现服务"; ulogModel.CreateDT = DateTime.Now; ulogModel.IsAddOrCut = 1; ulogModel.IsDisplay = 1; ulogModel.NewAmount = ub.ConsumeBalance + m; ulogModel.OldAmount = ub.ConsumeBalance; ulogModel.OrderNo = model.OrderDetailsID.ToString(); ulogModel.Remark = model.Remark; ulogModel.UserID = (long)model.UserID; #endregion using (var bt = _database.Db.BeginTransaction()) { try { //用户余额修改 bt.ZJ_UserBalance.UpdateByUserId(UserId: model.UserID, ConsumeBalance: ulogModel.NewAmount, UpdateBy: "系统返现服务", UpdateDT: DateTime.Now); //添加资金异动记录 bt.ZJ_UserBalanceChangeLog.Insert(ulogModel); //修改返现表 bt.ZJ_RebateInfo.UpdateByID(ID: model.ID, PaidMoney: pm, PaidDays: pd, LastUpdateBY: "系统服务", LastUpdateTime: DateTime.Now); bt.Commit(); _logger.Error(typeof(ZJ_RebateService), string.Format("处理返现订单【{0}】的返现成功", model.ID)); } catch (Exception ex) { bt.Rollback(); exceptionLogModel.HandleId = model.ID.ToString(); exceptionLogModel.Status = 1; exceptionLogModel.ResultType = 1; exceptionLogModel.Message = string.Format("处理返现订单【{0}】的返现失败,{1},数据库事务回滚", model.ID, ex.Message); exceptionLogService.Add(exceptionLogModel); _logger.Error(typeof(ZJ_RebateService), string.Format("处理返现订单【{0}】的返现失败,{1},数据库事务回滚", model.ID, ex.Message)); } } } } catch (Exception ex) { exceptionLogModel.HandleId = model.ID.ToString(); exceptionLogModel.Status = 1; exceptionLogModel.ResultType = 1; exceptionLogModel.Message = string.Format("处理返现订单【{0}】的返现失败,{1}", model.ID, ex.Message); exceptionLogService.Add(exceptionLogModel); _logger.Error(typeof(ZJ_RebateService), string.Format("处理返现订单【{0}】的返现失败,{1}", model.ID, ex.Message)); } } } else { exceptionLogModel.CreateDT = DateTime.Now; exceptionLogModel.Message = "本次没有需要处理的返现"; exceptionLogModel.ResultType = 2; exceptionLogModel.Status = 1; } }