/// <summary> /// 领取红包 /// </summary> /// <param name="userRedEnvelopeId"></param> /// <returns></returns> public Jinher.AMP.BTP.Deploy.CustomDTO.ResultDTO DrawRedEnvelopeExt(Guid userRedEnvelopeId) { ContextSession contextSession = ContextFactory.CurrentThreadContext; Jinher.AMP.BTP.Deploy.CustomDTO.ResultDTO result = new ResultDTO(); UserRedEnvelope query = null; lock (getRedLock) { //用户分红表 query = UserRedEnvelope.ObjectSet().Where(q => q.Id == userRedEnvelopeId).FirstOrDefault(); if (query == null) { result.ResultCode = 1; result.Message = "没有红包可领"; return(result); } else if (query.State == 0 && DateTime.Now > query.DueDate) { result.ResultCode = 1; result.Message = "红包已过期"; return(result); } else if (query.State == 1) { result.ResultCode = 1; result.Message = "红包已领"; return(result); } int num = UpdateRedState(query, 1); if (num > 0) { result.ResultCode = 0; result.Message = "领取红包成功"; } else { result.ResultCode = 1; result.Message = "领取红包失败"; return(result); } } MultiPayeeTradeByPasswordArg arg = new MultiPayeeTradeByPasswordArg(); ReturnInfoDTO gReturnDTO = new ReturnInfoDTO(); arg.PayeeComments = new List <string>(); arg.PayorComments = new List <string>(); arg.AppId = query.AppId; arg.Payees = new List <Tuple <Guid, bool> >(); arg.Payees.Add(new Tuple <Guid, bool>(query.UserId, true)); arg.BizSystem = "BTP"; arg.BizId = query.Id; arg.Golds = new List <long> { query.GoldCount }; arg.PayorPassword = CustomConfig.ShareGoldAccout.BTPShareAccountPwd; //众销 if (query.RedEnvelopeType == 0) { arg.PayorId = CustomConfig.ShareGoldAccout.BTPShareGoldAccount; arg.UsageId = CustomConfig.ShareGoldAccout.BTPGlodUsageId; arg.BizType = "BTP_ShareDividend_Auto"; arg.PayorComments.Add("电商分享红包支出"); arg.PayeeComments.Add("电商分享红包收益"); } else { //众筹 arg.PayorId = CustomConfig.CrowdfundingAccount.BTPCrowdfundingAcount; arg.UsageId = CustomConfig.CrowdfundingAccount.BTPCrowdfundingUsageId; arg.BizType = "BTP_CrowdfundingDividend"; arg.PayorComments.Add("电商众筹分红支出"); arg.PayeeComments.Add("电商众筹分红收益"); //计算用户已得分红 var uc = UserCrowdfunding.ObjectSet().Where(q => q.AppId == query.AppId && q.UserId == query.UserId).FirstOrDefault(); uc.RealGetDividend += query.GoldCount; uc.EntityState = EntityState.Modified; contextSession.SaveObject(uc); } try { gReturnDTO = Jinher.AMP.BTP.TPS.Finance.Instance.MultiPayeeTradeByPassword(arg); } catch (Exception ex) { int num = UpdateRedState(query, 0); LogHelper.Error(string.Format("获取我的红包UserRedEnvelopeSV-DrawRedEnvelopeExt-MultiPayeeTrade,参数redEnvelopeId:{0},红包状态恢复{1}", userRedEnvelopeId, (num > 0 ? "成功" : "失败")), ex); result.ResultCode = 1; result.Message = "调用金币接口失败"; return(result); } if (gReturnDTO == null || !gReturnDTO.IsSuccess) { int num = UpdateRedState(query, 0); result.ResultCode = 1; result.Message = "分享红包支付失败"; LogHelper.Error(string.Format("调用金币MultiPayeeTradeByPassword方法失败,code:{0},错误消息:{1},参数redEnvelopeId:{2},红包状态恢复{3}", gReturnDTO.Code, gReturnDTO.Info, userRedEnvelopeId, (num > 0 ? "成功" : "失败"))); return(result); } return(result); }
/// <summary> /// 处理众筹过期红包 /// </summary> public void HandleCfInValidRedEnvelopeExt() { DateTime now = DateTime.Now; int pageIndex = 0; int pageSize = 500; ContextSession session = ContextFactory.CurrentThreadContext; bool isContinue = true; do { var userRedEnvelopes = (from u in UserRedEnvelope.ObjectSet() where u.DueDate < now && u.State == 0 && u.RedEnvelopeType == 1 select u) .OrderBy(a => a.DueDate).Take(pageSize).Skip(pageIndex).ToList(); if (!userRedEnvelopes.Any()) { break; } if (userRedEnvelopes.Count < pageSize) { isContinue = false; } var totalGoldNum = userRedEnvelopes.Sum(x => x.GoldCount); MultiPayeeTradeByPasswordArg arg = new MultiPayeeTradeByPasswordArg(); arg.PayeeComments = new List <string>(); arg.PayorComments = new List <string>(); arg.AppId = userRedEnvelopes[0].AppId; arg.PayorId = CustomConfig.CrowdfundingAccount.BTPCrowdfundingAcount; arg.UsageId = CustomConfig.CrowdfundingAccount.BTPCrowdfundingUsageId; arg.Golds = new List <long>() { totalGoldNum }; arg.Payees = new List <Tuple <Guid, bool> >(); arg.Payees.Add(new Tuple <Guid, bool>(CustomConfig.CrowdfundingAccount.JhCrowdfundingGoldAccount, true)); arg.BizSystem = "BTP"; arg.BizId = userRedEnvelopes[0].Id; arg.BizType = "BTP_Cf_InvalidRed_Auto"; arg.PayorComments.Add("众筹活动电商过期红包支出"); arg.PayeeComments.Add("众筹活动电商过期红包收益"); arg.PayorPassword = CustomConfig.CrowdfundingAccount.BTPCrowdfundingPwd; ReturnInfoDTO gReturnDTO = new ReturnInfoDTO(); try { gReturnDTO = Jinher.AMP.BTP.TPS.Finance.Instance.MultiPayeeTradeByPassword(arg); if (gReturnDTO.IsSuccess) { foreach (var userRedEnvelope in userRedEnvelopes) { userRedEnvelope.State = 2; userRedEnvelope.EntityState = System.Data.EntityState.Modified; } session.SaveChanges(); LogHelper.Info(string.Format("众筹活动电商过期红包Job处理了UserRedEnvelope表{0}条记录", userRedEnvelopes.Count)); } else { JAP.Common.Loging.LogHelper.Error("众筹活动电商过期红包MultiPayeeTrade fail:" + gReturnDTO.Code + ":" + gReturnDTO.Info); isContinue = false; } } catch (Exception ex) { LogHelper.Error("众筹活动电商过期红包Job服务异常。", ex); isContinue = false; } }while (isContinue); }