Example #1
0
        public static bool UserPayOrder(OrderInfo order, bool isBalancePayOrder)
        {
            bool flag = false;

            if (order.CheckAction(OrderActions.BUYER_PAY))
            {
                using (DbConnection connection = DatabaseFactory.CreateDatabase().CreateConnection())
                {
                    connection.Open();
                    DbTransaction dbTran = connection.BeginTransaction();
                    try
                    {
                        if (!TradeProvider.Instance().UserPayOrder(order, isBalancePayOrder, dbTran))
                        {
                            dbTran.Rollback();
                            return(false);
                        }
                        if ((HiContext.Current.SiteSettings.IsDistributorSettings && (order.GroupBuyId <= 0)) && !PurchaseOrderProvider.CreateInstance().CreatePurchaseOrder(order, dbTran))
                        {
                            dbTran.Rollback();
                            return(false);
                        }
                        flag = true;
                        dbTran.Commit();
                    }
                    catch
                    {
                        dbTran.Rollback();
                        return(false);
                    }
                    finally
                    {
                        connection.Close();
                    }
                }
                if (!flag)
                {
                    return(flag);
                }
                if (!HiContext.Current.SiteSettings.IsDistributorSettings)
                {
                    TradeProvider.Instance().UpdateStockPayOrder(order.OrderId);
                }
                TradeProvider.Instance().UpdateProductSaleCounts(order.LineItems);
                if ((order.UserId == 0) || (order.UserId == 0x44c))
                {
                    return(flag);
                }
                IUser user = Users.GetUser(order.UserId, false);
                if (((user == null) || (user.UserRole != UserRole.Member)) && ((user == null) || (user.UserRole != UserRole.Underling)))
                {
                    return(flag);
                }
                Member        member = user as Member;
                UserPointInfo point  = new UserPointInfo {
                    OrderId   = order.OrderId,
                    UserId    = member.UserId,
                    TradeDate = DateTime.Now,
                    TradeType = UserPointTradeType.Bounty,
                    Increased = new int?(order.Points),
                    Points    = order.Points + member.Points
                };
                if ((point.Points > 0x7fffffff) || (point.Points < 0))
                {
                    point.Points = 0x7fffffff;
                }
                TradeProvider.Instance().AddMemberPoint(point);
                int referralDeduct = HiContext.Current.SiteSettings.ReferralDeduct;
                if (((referralDeduct > 0) && member.ReferralUserId.HasValue) && (member.ReferralUserId.Value > 0))
                {
                    IUser user2 = Users.GetUser(member.ReferralUserId.Value, false);
                    if ((user2 != null) && ((user2.UserRole == UserRole.Member) || (user2.UserRole == UserRole.Underling)))
                    {
                        Member member2 = user2 as Member;
                        if ((member.ParentUserId == member2.ParentUserId) && member2.IsOpenBalance)
                        {
                            decimal           num2           = member2.Balance + ((order.GetTotal() * referralDeduct) / 100M);
                            BalanceDetailInfo balanceDetails = new BalanceDetailInfo {
                                UserId    = member2.UserId,
                                UserName  = member2.Username,
                                TradeDate = DateTime.Now,
                                TradeType = TradeTypes.ReferralDeduct,
                                Income    = new decimal?((order.GetTotal() * referralDeduct) / 100M),
                                Balance   = num2,
                                Remark    = string.Format("提成来自'{0}'的订单{1}", order.Username, order.OrderId)
                            };
                            PersonalProvider.Instance().AddBalanceDetail(balanceDetails);
                        }
                    }
                }
                TradeProvider.Instance().UpdateUserAccount(order.GetTotal(), point.Points, order.UserId);
                int historyPoint = TradeProvider.Instance().GetHistoryPoint(member.UserId);
                TradeProvider.Instance().ChangeMemberGrade(member.UserId, member.GradeId, historyPoint);
                Users.ClearUserCache(user);
            }
            return(flag);
        }
Example #2
0
        public static bool UserPayOrder(OrderInfo order, bool isBalancePayOrder)
        {
            bool flag = false;
            bool result;

            if (order.CheckAction(OrderActions.BUYER_PAY))
            {
                Database database = DatabaseFactory.CreateDatabase();
                using (System.Data.Common.DbConnection dbConnection = database.CreateConnection())
                {
                    dbConnection.Open();
                    System.Data.Common.DbTransaction dbTransaction = dbConnection.BeginTransaction();
                    try
                    {
                        if (!TradeProvider.Instance().UserPayOrder(order, isBalancePayOrder, dbTransaction))
                        {
                            dbTransaction.Rollback();
                            result = false;
                            return(result);
                        }
                        if (HiContext.Current.SiteSettings.IsDistributorSettings && order.GroupBuyId <= 0)
                        {
                            PurchaseOrderProvider purchaseOrderProvider = PurchaseOrderProvider.CreateInstance();
                            if (!purchaseOrderProvider.CreatePurchaseOrder(order, dbTransaction))
                            {
                                dbTransaction.Rollback();
                                result = false;
                                return(result);
                            }
                        }
                        flag = true;
                        dbTransaction.Commit();
                    }
                    catch
                    {
                        dbTransaction.Rollback();
                        result = false;
                        return(result);
                    }
                    finally
                    {
                        dbConnection.Close();
                    }
                }
                if (flag)
                {
                    if (!HiContext.Current.SiteSettings.IsDistributorSettings)
                    {
                        TradeProvider.Instance().UpdateStockPayOrder(order.OrderId);
                    }
                    TradeProvider.Instance().UpdateProductSaleCounts(order.LineItems);
                    if (order.UserId != 0 && order.UserId != 1100)
                    {
                        IUser user = Users.GetUser(order.UserId, false);
                        bool  arg_145_0;
                        if (user != null)
                        {
                            if (user.UserRole == UserRole.Member)
                            {
                                arg_145_0 = false;
                                goto IL_145;
                            }
                        }
                        arg_145_0 = (user == null || user.UserRole != UserRole.Underling);
IL_145:
                        if (!arg_145_0)
                        {
                            Member        member        = user as Member;
                            UserPointInfo userPointInfo = new UserPointInfo();
                            userPointInfo.OrderId   = order.OrderId;
                            userPointInfo.UserId    = member.UserId;
                            userPointInfo.TradeDate = DateTime.Now;
                            userPointInfo.TradeType = UserPointTradeType.Bounty;
                            userPointInfo.Increased = new int?(order.Points);
                            userPointInfo.Points    = order.Points + member.Points;
                            int arg_1B7_0 = userPointInfo.Points;
                            if (userPointInfo.Points < 0)
                            {
                                userPointInfo.Points = 2147483647;
                            }
                            TradeProvider.Instance().AddMemberPoint(userPointInfo);
                            int referralDeduct = HiContext.Current.SiteSettings.ReferralDeduct;
                            if (referralDeduct > 0 && member.ReferralUserId.HasValue && member.ReferralUserId.Value > 0)
                            {
                                IUser user2 = Users.GetUser(member.ReferralUserId.Value, false);
                                if (user2 != null && (user2.UserRole == UserRole.Member || user2.UserRole == UserRole.Underling))
                                {
                                    Member member2 = user2 as Member;
                                    if (member.ParentUserId == member2.ParentUserId && member2.IsOpenBalance)
                                    {
                                        decimal           balance           = member2.Balance + order.GetTotal() * referralDeduct / 100m;
                                        BalanceDetailInfo balanceDetailInfo = new BalanceDetailInfo();
                                        balanceDetailInfo.UserId    = member2.UserId;
                                        balanceDetailInfo.UserName  = member2.Username;
                                        balanceDetailInfo.TradeDate = DateTime.Now;
                                        balanceDetailInfo.TradeType = TradeTypes.ReferralDeduct;
                                        balanceDetailInfo.Income    = new decimal?(order.GetTotal() * referralDeduct / 100m);
                                        balanceDetailInfo.Balance   = balance;
                                        balanceDetailInfo.Remark    = string.Format("提成来自'{0}'的订单{1}", order.Username, order.OrderId);
                                        PersonalProvider.Instance().AddBalanceDetail(balanceDetailInfo);
                                    }
                                }
                            }
                            TradeProvider.Instance().UpdateUserAccount(order.GetTotal(), userPointInfo.Points, order.UserId);
                            int historyPoint = TradeProvider.Instance().GetHistoryPoint(member.UserId);
                            TradeProvider.Instance().ChangeMemberGrade(member.UserId, member.GradeId, historyPoint);
                            Users.ClearUserCache(user);
                        }
                    }
                }
            }
            result = flag;
            return(result);
        }