예제 #1
0
        /// <summary>
        /// 获取众销明细
        /// </summary>
        /// <param name="pageSize"></param>
        /// <param name="pageIndex"></param>
        /// <returns></returns>
        public ShareListResult GetShareListExt(int pageSize, int pageIndex)
        {
            ShareListResult result = new ShareListResult();
            int             start  = (pageIndex - 1) * pageSize;

            result.Count = ShareDividendDetail.ObjectSet().Count();

            if (result.Count > 0)
            {
                result.ShareItems = new List <ShareItemDTO>();

                var orders = (from order in CommodityOrder.ObjectSet()
                              join dividend in ShareDividend.ObjectSet() on order.Id equals dividend.CommodityOrderId
                              join dividendDetail in ShareDividendDetail.ObjectSet() on dividend.Id equals
                              dividendDetail.ShareDivedendId
                              where (order.SrcType == 33 || order.SrcType == 34) && order.State == 3
                              orderby order.SubTime
                              select new ShareItemDTO
                {
                    ShareUserId = dividendDetail.UserId,
                    OrderCode = order.Code,
                    DividendGold = dividendDetail.Money
                }).Skip(start).Take(pageSize).ToList();
                if (orders.Any())
                {
                    var userIds = orders.Select(c => c.ShareUserId).Distinct().ToList();

                    List <UserNameAccountsDTO> userNamelist =
                        CBCSV.Instance.GetUserNameAccountsByIds(userIds) ?? new List <UserNameAccountsDTO>();
                    foreach (var shareItemDto in orders)
                    {
                        string userCode = "--";
                        string userName = "******";

                        var userInfo = userNamelist.FirstOrDefault(c => c.userId == shareItemDto.ShareUserId);
                        if (userInfo != null)
                        {
                            userName = userInfo.userName;
                            if (userInfo.Accounts != null && userInfo.Accounts.Any())
                            {
                                var account = userInfo.Accounts.FirstOrDefault(c => !string.IsNullOrEmpty(c.Account));
                                if (account != null)
                                {
                                    userCode = account.Account;
                                }
                            }
                        }
                        result.ShareItems.Add(new ShareItemDTO
                        {
                            DividendGold  = shareItemDto.DividendGold,
                            OrderCode     = shareItemDto.OrderCode,
                            ShareUserCode = userCode,
                            ShareUserName = userName,
                            ShareDate     = DateTime.Now,
                            ShareUserId   = shareItemDto.ShareUserId
                        });
                    }

                    result.SumUserCount    = ShareDividendDetail.ObjectSet().Select(c => c.UserId).Distinct().Count();
                    result.SumDividendGold = ShareDividendDetail.ObjectSet().Sum(c => c.Money);
                }
            }
            return(result);
        }
예제 #2
0
        /// <summary>
        /// 发送红包
        /// </summary>
        public void SendRedEnvelopeExt()
        {
            int pageIndex = 0;
            int pageSize  = 500;

            DateTime       today      = DateTime.Now.Date;
            ContextSession session    = ContextFactory.CurrentThreadContext;
            bool           isContinue = true;

            do
            {
                var userDividents = (from s in ShareDividendDetail.ObjectSet()
                                     where s.SettlementDate < today && s.State == 0
                                     group s by s.UserId into g
                                     select g
                                     ).OrderBy(a => a.Key).Take(pageSize).Skip(pageIndex)
                                    .ToDictionary(x => x.Key, y => y.ToList());


                foreach (Guid userId in userDividents.Keys)
                {
                    StringBuilder strDescription = new StringBuilder(50);
                    foreach (ShareDividendDetail userDivident in userDividents[userId])
                    {
                        userDivident.State       = 1;
                        userDivident.EntityState = System.Data.EntityState.Modified;

                        strDescription.Append(userDivident.Description).Append(",");
                    }
                    strDescription.Remove(strDescription.Length - 1, 1);
                    var             goldNum     = userDividents[userId].Sum(x => x.Money);
                    UserRedEnvelope redEnvelope = UserRedEnvelope.CreateUserRedEnvelope();
                    redEnvelope.EntityState = System.Data.EntityState.Added;
                    redEnvelope.AppId       = userDividents[userId][0].AppId;
                    redEnvelope.Content     = CustomConfig.SaleShare.DividentContent;
                    redEnvelope.Description = strDescription.ToString();
                    double dueDateAdd = 24;
                    double.TryParse(CustomConfig.SaleShare.DividentDue, out dueDateAdd);
                    redEnvelope.DueDate   = DateTime.Now.AddHours(dueDateAdd);
                    redEnvelope.GoldCount = goldNum;
                    redEnvelope.UserId    = userId;
                    redEnvelope.RoleType  = userDividents[userId][0].RoleType;

                    ShareRedMessageDTO contentCDTO = new ShareRedMessageDTO();
                    contentCDTO.message  = redEnvelope.Content;
                    contentCDTO.userName = redEnvelope.Content;
                    contentCDTO.msgId    = redEnvelope.Id;
                    contentCDTO.url      = string.Format("{0}ShareRedEnvelope/ShareRedEnvelopesDetail?msgId={1}", CustomConfig.BtpDomain, redEnvelope.Id);

                    double dueMessDateAdd = 48;
                    double.TryParse(CustomConfig.SaleShare.DividentMessageDue, out dueMessDateAdd);

                    if (userDividents[userId][0].RoleType == 2)
                    {
                        try
                        {
                            List <Guid> userIds  = Jinher.AMP.BTP.TPS.EBCSV.Instance.GetUserIdsByOrgIdAndCode(userId, "ReceiveRed");
                            int         msgCount = 0;
                            foreach (Guid id in userIds)
                            {
                                SendMessage(redEnvelope.Id, redEnvelope.AppId, id, DateTime.Now.AddHours(dueMessDateAdd), contentCDTO);
                                //最多选择20个代领者
                                msgCount += 1;
                                if (msgCount > 20)
                                {
                                    break;
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            LogHelper.Error("发送红包Job服务异常:EBC.ISV.Facade.OrganizationQueryFacade。", ex);

                            continue;
                        }
                    }
                    else
                    {
                        SendMessage(redEnvelope.Id, redEnvelope.AppId, redEnvelope.UserId, DateTime.Now.AddHours(dueMessDateAdd), contentCDTO);
                    }

                    session.SaveObject(redEnvelope);
                }

                try
                {
                    session.SaveChanges();
                    if (userDividents.Count < pageSize)
                    {
                        isContinue = false;
                    }
                    LogHelper.Info(string.Format("发送红包Job处理了ShareDividendDetail表{0}条记录", userDividents.Count));
                }
                catch (Exception ex)
                {
                    LogHelper.Error("发送红包Job服务异常。", ex);
                    isContinue = false;
                }
            }while (isContinue);
        }