Ejemplo n.º 1
0
        public static bool UpdateCalculationCommission(OrderInfo order)
        {
            Exception exception;

            new MemberDao().SetOrderDate(order.UserId, 2);
            DistributorsInfo userIdDistributors = GetUserIdDistributors(order.ReferralUserId);
            SiteSettings     masterSettings     = SettingsManager.GetMasterSettings(false);
            bool             flag = false;

            if (userIdDistributors != null)
            {
                flag = setCommission(order, userIdDistributors);
                if (!string.IsNullOrEmpty(order.ReferralPath))
                {
                    string    userOpenIdByUserId;
                    string    aliUserOpenIdByUserId;
                    int       notDescDistributorGrades;
                    ArrayList commTatalList  = new ArrayList();
                    decimal   num            = 0M;
                    ArrayList userIdList     = new ArrayList();
                    string    referralUserId = order.ReferralUserId.ToString();
                    string    orderId        = order.OrderId;
                    ArrayList orderTotalList = new ArrayList();
                    decimal   num2           = 0M;
                    ArrayList gradeIdList    = new ArrayList();
                    string[]  strArray       = order.ReferralPath.Split(new char[] { '|' });
                    if (strArray.Length == 1)
                    {
                        DistributorsInfo distributor = GetUserIdDistributors(int.Parse(strArray[0]));
                        if (distributor != null)
                        {
                            foreach (LineItemInfo info3 in order.LineItems.Values)
                            {
                                if (info3.OrderItemsStatus.ToString() == OrderStatus.SellerAlreadySent.ToString())
                                {
                                    num  += info3.SecondItemsCommission;
                                    num2 += info3.GetSubTotal();
                                }
                            }
                            commTatalList.Add(num);
                            orderTotalList.Add(num2 + order.AdjustedFreight);
                            userIdList.Add(distributor.UserId);
                            try
                            {
                                if ((order != null) && (num > 0M))
                                {
                                    userOpenIdByUserId    = MemberProcessor.GetUserOpenIdByUserId(distributor.UserId);
                                    aliUserOpenIdByUserId = MemberProcessor.GetAliUserOpenIdByUserId(distributor.UserId);
                                    Messenger.SendWeiXinMsg_OrderGetCommission(order, userOpenIdByUserId, aliUserOpenIdByUserId, num);
                                }
                            }
                            catch (Exception exception1)
                            {
                                exception = exception1;
                            }
                            notDescDistributorGrades = GetNotDescDistributorGrades(distributor.UserId.ToString());
                            if (distributor.DistriGradeId != notDescDistributorGrades)
                            {
                                DistributorGradeChange(distributor, order.OrderId, notDescDistributorGrades);
                            }
                        }
                    }
                    if (strArray.Length == 2)
                    {
                        DistributorsInfo info4 = GetUserIdDistributors(int.Parse(strArray[0]));
                        foreach (LineItemInfo info3 in order.LineItems.Values)
                        {
                            if (info3.OrderItemsStatus.ToString() == OrderStatus.SellerAlreadySent.ToString())
                            {
                                num  += info3.ThirdItemsCommission;
                                num2 += info3.GetSubTotal();
                            }
                        }
                        commTatalList.Add(num);
                        orderTotalList.Add(num2 + order.AdjustedFreight);
                        userIdList.Add(info4.UserId);
                        try
                        {
                            if ((order != null) && (num > 0M))
                            {
                                userOpenIdByUserId    = MemberProcessor.GetUserOpenIdByUserId(info4.UserId);
                                aliUserOpenIdByUserId = MemberProcessor.GetAliUserOpenIdByUserId(info4.UserId);
                                Messenger.SendWeiXinMsg_OrderGetCommission(order, userOpenIdByUserId, aliUserOpenIdByUserId, num);
                            }
                        }
                        catch (Exception exception2)
                        {
                            exception = exception2;
                        }
                        notDescDistributorGrades = GetNotDescDistributorGrades(info4.UserId.ToString());
                        if (info4.DistriGradeId != notDescDistributorGrades)
                        {
                            DistributorGradeChange(info4, order.OrderId, notDescDistributorGrades);
                        }
                        DistributorsInfo info5 = GetUserIdDistributors(int.Parse(strArray[1]));
                        num  = 0M;
                        num2 = 0M;
                        foreach (LineItemInfo info3 in order.LineItems.Values)
                        {
                            if (info3.OrderItemsStatus.ToString() == OrderStatus.SellerAlreadySent.ToString())
                            {
                                num  += info3.SecondItemsCommission;
                                num2 += info3.GetSubTotal();
                            }
                        }
                        commTatalList.Add(num);
                        orderTotalList.Add(num2 + order.AdjustedFreight);
                        userIdList.Add(info5.UserId);
                        try
                        {
                            if ((order != null) && (num > 0M))
                            {
                                userOpenIdByUserId    = MemberProcessor.GetUserOpenIdByUserId(info5.UserId);
                                aliUserOpenIdByUserId = MemberProcessor.GetAliUserOpenIdByUserId(info5.UserId);
                                Messenger.SendWeiXinMsg_OrderGetCommission(order, userOpenIdByUserId, aliUserOpenIdByUserId, num);
                            }
                        }
                        catch (Exception exception3)
                        {
                            exception = exception3;
                        }
                        int newDistributorGradeid = GetNotDescDistributorGrades(info5.UserId.ToString());
                        if (info5.DistriGradeId != newDistributorGradeid)
                        {
                            DistributorGradeChange(info5, order.OrderId, newDistributorGradeid);
                        }
                    }
                    flag = new DistributorsDao().UpdateTwoCalculationCommission(userIdList, referralUserId, orderId, orderTotalList, commTatalList);
                    for (int i = 0; i < userIdList.Count; i++)
                    {
                        int num6 = GetNotDescDistributorGrades(userIdList[i].ToString());
                        gradeIdList.Add(num6);
                    }
                    flag = new DistributorsDao().UpdateGradeId(gradeIdList, userIdList);
                }
                RemoveDistributorCache(userIdDistributors.UserId);
            }
            OrderRedPagerBrower.CreateOrderRedPager(order.OrderId, order.GetTotal(), order.UserId);
            int id = Globals.IsNumeric(order.ActivitiesId) ? Globals.ToNum(order.ActivitiesId) : 0;

            if (id > 0)
            {
                ActivityDetailInfo activityDetailInfo = new Hidistro.SqlDal.VShop.ActivityDao().GetActivityDetailInfo(id);
                if (activityDetailInfo != null)
                {
                    OrderInfo info8;
                    int       couponId = activityDetailInfo.CouponId;
                    int       integral = activityDetailInfo.Integral;
                    if ((couponId > 0) && (ShoppingProcessor.GetCoupon(couponId.ToString()) != null))
                    {
                        SendCouponResult result = new CouponDao().SendCouponToMember(couponId, order.UserId);
                        try
                        {
                            info8 = order;
                            if (info8 != null)
                            {
                                Messenger.SendWeiXinMsg_OrderGetCoupon(info8);
                            }
                        }
                        catch (Exception exception4)
                        {
                            exception = exception4;
                        }
                    }
                    if (integral > 0)
                    {
                        new OrderDao().AddMemberPointNumber(integral, order, null);
                        try
                        {
                            info8 = order;
                            if (info8 != null)
                            {
                                Messenger.SendWeiXinMsg_OrderGetPoint(info8, integral);
                            }
                        }
                        catch (Exception exception5)
                        {
                            exception = exception5;
                        }
                    }
                }
            }
            MemberProcessor.UpdateUserAccount(order);
            try
            {
                string   retInfo   = "";
                DateTime orderDate = order.OrderDate;
                DateTime?payDate   = order.PayDate;
                if (order.Gateway == "hishop.plugins.payment.podrequest")
                {
                    payDate = new DateTime?(orderDate);
                }
                if (payDate.HasValue && (payDate.Value.ToString("yyyy-MM-dd") != DateTime.Now.ToString("yyyy-MM-dd")))
                {
                    bool flag2 = new ShopStatisticDao().StatisticsOrdersByRecDate(payDate.Value, UpdateAction.AllUpdate, 0, out retInfo);
                }
            }
            catch
            {
            }
            return(flag);
        }
Ejemplo n.º 2
0
        public static void DistributorGradeChange(DistributorsInfo distributor, string orderid, int newDistributorGradeid)
        {
            DistributorGradeInfo distributorGradeInfo = DistributorGradeBrower.GetDistributorGradeInfo(newDistributorGradeid);

            if ((distributorGradeInfo != null) && (distributorGradeInfo.AddCommission > 0M))
            {
                try
                {
                    Messenger.SendWeiXinMsg_DistributorGradeChange(MemberProcessor.GetMember(distributor.UserId, true), distributorGradeInfo.Name);
                }
                catch
                {
                }
                SiteSettings masterSettings = SettingsManager.GetMasterSettings(false);
                if (masterSettings.IsAddCommission == 1)
                {
                    try
                    {
                        DateTime time  = DateTime.Parse(masterSettings.AddCommissionStartTime);
                        DateTime time2 = DateTime.Parse(masterSettings.AddCommissionEndTime).AddDays(1.0);
                        if ((DateTime.Now > time) && (DateTime.Now < time2))
                        {
                            decimal num = distributor.ReferralRequestBalance + distributor.ReferralBlance;
                            DistributorGradeCommissionInfo info = new DistributorGradeCommissionInfo {
                                UserId             = distributor.UserId,
                                Commission         = distributorGradeInfo.AddCommission,
                                PubTime            = DateTime.Now,
                                OperAdmin          = "system",
                                Memo               = "升级奖励",
                                OrderID            = orderid,
                                OldCommissionTotal = num
                            };
                            if (!string.IsNullOrEmpty(info.OrderID))
                            {
                                info.ReferralUserId = new OrderDao().GetOrderReferralUserId(info.OrderID);
                            }
                            else
                            {
                                info.OrderID = "U" + GenerateOrderId();
                            }
                            info.CommType = 3;
                            if (info.ReferralUserId == 0)
                            {
                                info.ReferralUserId = info.UserId;
                                info.CommType       = 4;
                            }
                            DistributorGradeCommissionBrower.AddCommission(info);
                            NoticeInfo info4 = new NoticeInfo {
                                Title = "恭喜分销商获得升级奖励佣金¥" + distributorGradeInfo.AddCommission.ToString("F2")
                            };
                            StringBuilder builder = new StringBuilder();
                            builder.Append("<p class='textlist'>恭喜<span style='color:#3D9BDF;'>" + distributor.StoreName + "</span>自动升级为<span style='color:red;'>" + distributorGradeInfo.Name + "</span>分销商" + ((num > 0M) ? ("(累计获得佣金" + num.ToString("F2") + "元)") : "") + ",系统额外奖励佣金" + distributorGradeInfo.AddCommission.ToString("F2") + "元!</p>");
                            builder.Append("<p class='textlist'>自" + time.ToString("yyyy年MM月dd日") + "至" + time2.ToString("yyyy年MM月dd日") + ",分销商等级提升将获得系统奖励的额外佣金。</p>");
                            builder.Append("<table class='table table-bordered' style='text-align: center;'><thead><tr class='firstRow'><th style='text-align:center;'>等级名称</th><th style='text-align:center;'>需要佣金</th><th style='text-align:center;'>奖励佣金</th></tr></thead><tbody>");
                            DataTable allDistributorGrade = DistributorGradeBrower.GetAllDistributorGrade();
                            int       count = allDistributorGrade.Rows.Count;
                            for (int i = 0; i < count; i++)
                            {
                                builder.Append("<tr><td>" + allDistributorGrade.Rows[i]["Name"].ToString() + "</td><td>¥" + decimal.Parse(allDistributorGrade.Rows[i]["CommissionsLimit"].ToString()).ToString("F2") + "</td><td>¥" + decimal.Parse(allDistributorGrade.Rows[i]["AddCommission"].ToString()).ToString("F2") + "</td></tr>");
                            }
                            builder.Append("</tbody></table>");
                            info4.Memo     = builder.ToString();
                            info4.Author   = "system";
                            info4.AddTime  = DateTime.Now;
                            info4.IsPub    = 1;
                            info4.PubTime  = new DateTime?(DateTime.Now);
                            info4.SendType = 0;
                            info4.SendTo   = 0;
                            NoticeBrowser.SaveNotice(info4);
                        }
                    }
                    catch (Exception exception)
                    {
                        Globals.Debuglog("升级奖励异常" + exception.Message, "_Debuglog.txt");
                    }
                }
            }
        }
Ejemplo n.º 3
0
        public static bool setCommission(OrderInfo order, DistributorsInfo DisInfo)
        {
            bool      flag               = false;
            decimal   num                = 0M;
            decimal   num2               = 0M;
            decimal   resultCommTatal    = 0M;
            string    userId             = order.ReferralUserId.ToString();
            string    orderId            = order.OrderId;
            decimal   num4               = 0M;
            ArrayList gradeIdList        = new ArrayList();
            ArrayList referralUserIdList = new ArrayList();

            foreach (LineItemInfo info in order.LineItems.Values)
            {
                if (info.OrderItemsStatus.ToString() == OrderStatus.SellerAlreadySent.ToString())
                {
                    num2 += info.ItemsCommission;
                    if ((!string.IsNullOrEmpty(info.ItemAdjustedCommssion.ToString()) && (info.ItemAdjustedCommssion > 0M)) && !info.IsAdminModify)
                    {
                        num += info.ItemAdjustedCommssion;
                    }
                    num4 += (info.GetSubTotal() - info.DiscountAverage) - info.ItemAdjustedCommssion;
                }
            }
            num4 -= order.AdjustedFreight;
            if (false)
            {
                resultCommTatal = num2;
            }
            else
            {
                resultCommTatal = num2 - num;
                if (resultCommTatal < 0M)
                {
                    resultCommTatal = 0M;
                }
            }
            flag = new DistributorsDao().UpdateCalculationCommission(userId, userId, orderId, num4 + order.AdjustedFreight, resultCommTatal);
            try
            {
                if ((order != null) && (resultCommTatal > 0M))
                {
                    string userOpenIdByUserId    = MemberProcessor.GetUserOpenIdByUserId(DisInfo.UserId);
                    string aliUserOpenIdByUserId = MemberProcessor.GetAliUserOpenIdByUserId(DisInfo.UserId);
                    Messenger.SendWeiXinMsg_OrderGetCommission(order, userOpenIdByUserId, aliUserOpenIdByUserId, resultCommTatal);
                }
            }
            catch (Exception exception)
            {
                Globals.Debuglog("分佣问题:" + exception.Message, "_Debuglog.txt");
            }
            int notDescDistributorGrades = GetNotDescDistributorGrades(userId);

            if (notDescDistributorGrades > 0)
            {
                gradeIdList.Add(notDescDistributorGrades);
                referralUserIdList.Add(userId);
                flag = new DistributorsDao().UpdateGradeId(gradeIdList, referralUserIdList);
                if (DisInfo.DistriGradeId != notDescDistributorGrades)
                {
                    DistributorGradeChange(DisInfo, order.OrderId, notDescDistributorGrades);
                }
            }
            return(flag);
        }
Ejemplo n.º 4
0
        public static bool CreatOrder(OrderInfo orderInfo)//添加订单记录
        {
            bool flag = false;

            if (orderInfo.GetTotal() == 0M)
            {
                orderInfo.OrderStatus = OrderStatus.BuyerAlreadyPaid;
            }
            Database database = DatabaseFactory.CreateDatabase();
            //if (CS$<>9__CachedAnonymousMethodDelegate2 == null)
            //{
            //    CS$<>9__CachedAnonymousMethodDelegate2 = new Func<KeyValuePair<string, LineItemInfo>, int>(null, (IntPtr) <CreatOrder>b__1);
            //}
            //int quantity = Enumerable.Sum<KeyValuePair<string, LineItemInfo>>(orderInfo.LineItems, CS$<>9__CachedAnonymousMethodDelegate2);
            int quantity = orderInfo.LineItems.Sum <KeyValuePair <string, LineItemInfo> >((Func <KeyValuePair <string, LineItemInfo>, int>)(item => item.Value.Quantity));

            lock (createOrderLocker)
            {
                if (orderInfo.GroupBuyId > 0)
                {
                    checkCanGroupBuy(quantity, orderInfo.GroupBuyId);
                }
                using (DbConnection connection = database.CreateConnection())
                {
                    connection.Open();
                    DbTransaction dbTran = connection.BeginTransaction();
                    try
                    {
                        try
                        {
                            IntegralDetailInfo info4;
                            orderInfo.ClientShortType = (ClientShortType)Globals.GetClientShortType();
                            if (!new OrderDao().CreatOrder(orderInfo, dbTran))//添加订单记录
                            {
                                dbTran.Rollback();
                                return(false);
                            }
                            if ((orderInfo.LineItems.Count > 0) && !new LineItemDao().AddOrderLineItems(orderInfo.OrderId, orderInfo.LineItems.Values, dbTran))
                            {
                                dbTran.Rollback();
                                return(false);
                            }
                            if (!string.IsNullOrEmpty(orderInfo.CouponCode) && !new CouponDao().AddCouponUseRecord(orderInfo, dbTran))
                            {
                                dbTran.Rollback();
                                return(false);
                            }
                            ICollection values        = orderInfo.LineItems.Values;
                            MemberInfo  currentMember = MemberProcessor.GetCurrentMember();
                            foreach (LineItemInfo info2 in values)
                            {
                                if ((info2.Type == 1) && (info2.ExchangeId > 0))
                                {
                                    PointExchangeChangedInfo info3;
                                    info3 = new PointExchangeChangedInfo {
                                        exChangeId   = info2.ExchangeId,
                                        exChangeName = new OrderDao().GetexChangeName(info2.ExchangeId),
                                        ProductId    = info2.ProductId,
                                        PointNumber  = info2.PointNumber,
                                        MemberID     = orderInfo.UserId,
                                        Date         = DateTime.Now,
                                        MemberGrades = currentMember.GradeId
                                    };
                                    if (!new OrderDao().InsertPointExchange_Changed(info3, dbTran, info2.Quantity))
                                    {
                                        dbTran.Rollback();
                                        return(false);
                                    }
                                    info4 = new IntegralDetailInfo {
                                        IntegralChange     = -info2.PointNumber,
                                        IntegralSource     = "积分兑换商品-订单号:" + orderInfo.OrderMarking,
                                        IntegralSourceType = 2,
                                        Remark             = "积分兑换商品",
                                        Userid             = orderInfo.UserId,
                                        GoToUrl            = Globals.ApplicationPath + "/Vshop/MemberOrderDetails.aspx?OrderId=" + orderInfo.OrderId,
                                        IntegralStatus     = Convert.ToInt32(IntegralDetailStatus.IntegralExchange)
                                    };
                                    if (!new IntegralDetailDao().AddIntegralDetail(info4, dbTran))
                                    {
                                        dbTran.Rollback();
                                        return(false);
                                    }
                                }
                            }
                            if (orderInfo.PointExchange > 0)
                            {
                                info4 = new IntegralDetailInfo {
                                    IntegralChange     = -orderInfo.PointExchange,
                                    IntegralSource     = "积分抵现-订单号:" + orderInfo.OrderMarking,
                                    IntegralSourceType = 2,
                                    Remark             = "积分抵现",
                                    Userid             = orderInfo.UserId,
                                    GoToUrl            = Globals.ApplicationPath + "/Vshop/MemberOrderDetails.aspx?OrderId=" + orderInfo.OrderId,
                                    IntegralStatus     = Convert.ToInt32(IntegralDetailStatus.NowArrived)
                                };
                                if (!new IntegralDetailDao().AddIntegralDetail(info4, dbTran))
                                {
                                    dbTran.Rollback();
                                    return(false);
                                }
                            }
                            if ((orderInfo.RedPagerID > 0) && !new OrderDao().UpdateCoupon_MemberCoupons(orderInfo, dbTran))
                            {
                                dbTran.Rollback();
                                return(false);
                            }
                            dbTran.Commit();
                            flag = true;
                        }
                        catch
                        {
                            dbTran.Rollback();
                            throw;
                        }
                        return(flag);
                    }
                    finally
                    {
                        connection.Close();
                    }
                }
            }
            return(flag);
        }
Ejemplo n.º 5
0
        public static bool CreatOrder(OrderInfo orderInfo)
        {
            bool     flag     = false;
            Database database = DatabaseFactory.CreateDatabase();
            int      quantity = orderInfo.LineItems.Sum <KeyValuePair <string, LineItemInfo> >((Func <KeyValuePair <string, LineItemInfo>, int>)(item => item.Value.Quantity));

            lock (createOrderLocker)
            {
                if (orderInfo.GroupBuyId > 0)
                {
                    checkCanGroupBuy(quantity, orderInfo.GroupBuyId);
                }
                using (DbConnection connection = database.CreateConnection())
                {
                    connection.Open();
                    DbTransaction dbTran = connection.BeginTransaction();
                    try
                    {
                        try
                        {
                            if (!new OrderDao().CreatOrder(orderInfo, dbTran))
                            {
                                dbTran.Rollback();
                                return(false);
                            }
                            if ((orderInfo.LineItems.Count > 0) && !new LineItemDao().AddOrderLineItems(orderInfo.OrderId, orderInfo.LineItems.Values, dbTran))
                            {
                                dbTran.Rollback();
                                return(false);
                            }
                            if (!string.IsNullOrEmpty(orderInfo.CouponCode) && !new CouponDao().AddCouponUseRecord(orderInfo, dbTran))
                            {
                                dbTran.Rollback();
                                return(false);
                            }
                            ICollection values        = orderInfo.LineItems.Values;
                            MemberInfo  currentMember = MemberProcessor.GetCurrentMember();
                            foreach (LineItemInfo info2 in values)
                            {
                                if ((info2.Type == 1) && (info2.ExchangeId > 0))
                                {
                                    PointExchangeChangedInfo info3 = new PointExchangeChangedInfo();
                                    info3.exChangeId   = info2.ExchangeId;
                                    info3.exChangeName = new OrderDao().GetexChangeName(info3.exChangeId);
                                    info3.ProductId    = info2.ProductId;
                                    info3.PointNumber  = info2.PointNumber;
                                    info3.MemberID     = orderInfo.UserId;
                                    info3.Date         = DateTime.Now;
                                    info3.MemberGrades = currentMember.GradeId;

                                    if (!new OrderDao().InsertPointExchange_Changed(info3, dbTran, info2.Quantity))
                                    {
                                        dbTran.Rollback();
                                        return(false);
                                    }
                                    IntegralDetailInfo point = new IntegralDetailInfo
                                    {
                                        IntegralChange     = -info2.PointNumber,
                                        IntegralSource     = "积分兑换商品-订单号:" + orderInfo.OrderMarking,
                                        IntegralSourceType = 2,
                                        Remark             = "积分兑换商品",
                                        Userid             = orderInfo.UserId,
                                        GoToUrl            = Globals.ApplicationPath + "/Vshop/MemberOrderDetails.aspx?OrderId=" + orderInfo.OrderId,
                                        IntegralStatus     = Convert.ToInt32(IntegralDetailStatus.IntegralExchange)
                                    };
                                    if (!new IntegralDetailDao().AddIntegralDetail(point, dbTran))
                                    {
                                        dbTran.Rollback();
                                        return(false);
                                    }
                                }
                            }
                            if (orderInfo.PointExchange > 0)
                            {
                                IntegralDetailInfo info5 = new IntegralDetailInfo
                                {
                                    IntegralChange     = -orderInfo.PointExchange,
                                    IntegralSource     = "积分抵现-订单号:" + orderInfo.OrderMarking,
                                    IntegralSourceType = 2,
                                    Remark             = "积分抵现",
                                    Userid             = orderInfo.UserId,
                                    GoToUrl            = Globals.ApplicationPath + "/Vshop/MemberOrderDetails.aspx?OrderId=" + orderInfo.OrderId,
                                    IntegralStatus     = Convert.ToInt32(IntegralDetailStatus.NowArrived)
                                };
                                if (!new IntegralDetailDao().AddIntegralDetail(info5, dbTran))
                                {
                                    dbTran.Rollback();
                                    return(false);
                                }
                            }
                            if ((orderInfo.RedPagerID > 0) && !new OrderDao().UpdateCoupon_MemberCoupons(orderInfo, dbTran))
                            {
                                dbTran.Rollback();
                                return(false);
                            }
                            if (orderInfo.GroupBuyId > 0)
                            {
                                GroupBuyDao  dao      = new GroupBuyDao();
                                GroupBuyInfo groupBuy = dao.GetGroupBuy(orderInfo.GroupBuyId, dbTran);
                                groupBuy.SoldCount += quantity;
                                dao.UpdateGroupBuy(groupBuy, dbTran);
                                dao.RefreshGroupBuyFinishState(orderInfo.GroupBuyId, dbTran);
                            }
                            dbTran.Commit();
                            flag = true;
                        }
                        catch
                        {
                            dbTran.Rollback();
                            throw;
                        }
                        return(flag);
                    }
                    finally
                    {
                        connection.Close();
                    }
                    return(flag);
                }
            }
            return(flag);
        }
Ejemplo n.º 6
0
        public static MemberInfo GetAnonymousMember(string adminType = "normal")
        {
            /*
             * MemberInfo anonymousMember =GetMemberByUserName("[匿名用户]");
             * if (anonymousMember != null && anonymousMember.OpenId == null)//如果查得到匿名用户,则返回
             * {
             *  return anonymousMember;
             * }
             * else//否则增加一个匿名用户
             * {
             *  anonymousMember = new MemberInfo
             *  {
             *      UserName="******",
             *      RealName="[匿名用户]",
             *      Password="******",
             *  };
             *  if (CreateMember(anonymousMember))
             *  {
             *      anonymousMember = GetMemberByUserName("[匿名用户]");
             *  }
             * }
             * return anonymousMember;
             */

            MemberInfo anonymousMember = new MemberInfo();

            if (adminType == "admin")
            {
                anonymousMember = MemberProcessor.GetusernameMember("[堂食用户]");
                if (anonymousMember == null)//如果没有匿名用户,新建一个
                {
                    MemberInfo member     = new MemberInfo();
                    string     generateId = Globals.GetGenerateId();
                    member.GradeId        = MemberProcessor.GetDefaultMemberGrade();
                    member.UserName       = "******";
                    member.RealName       = "[堂食用户]";
                    member.CreateDate     = System.DateTime.Now;
                    member.SessionId      = generateId;
                    member.SessionEndTime = System.DateTime.Now.AddYears(10);
                    member.Password       = HiCryptographer.Md5Encrypt("yihuikeji888");
                    MemberProcessor.CreateMember(member);
                    anonymousMember = MemberProcessor.GetMember(generateId);
                }
            }
            else if (adminType == "activity")
            {
                anonymousMember = MemberProcessor.GetusernameMember("[活动用户]");
                if (anonymousMember == null)//如果没有活动用户,新建一个
                {
                    MemberInfo member     = new MemberInfo();
                    string     generateId = Globals.GetGenerateId();
                    member.GradeId        = MemberProcessor.GetDefaultMemberGrade();
                    member.UserName       = "******";
                    member.RealName       = "[活动用户]";
                    member.CreateDate     = System.DateTime.Now;
                    member.SessionId      = generateId;
                    member.SessionEndTime = System.DateTime.Now.AddYears(10);
                    member.Password       = HiCryptographer.Md5Encrypt("yihuikeji888");
                    MemberProcessor.CreateMember(member);
                    anonymousMember = MemberProcessor.GetMember(generateId);
                }
            }

            if (System.Web.HttpContext.Current.Request.Cookies["Vshop-Member"] != null)
            {
                System.Web.HttpContext.Current.Response.Cookies["Vshop-Member"].Expires = System.DateTime.Now.AddDays(-1.0);
                System.Web.HttpCookie cookie = new System.Web.HttpCookie("Vshop-Member")
                {
                    Value   = anonymousMember.UserId.ToString(),
                    Expires = System.DateTime.Now.AddYears(10)
                };
                System.Web.HttpContext.Current.Response.Cookies.Add(cookie);
            }
            else
            {
                System.Web.HttpCookie cookie2 = new System.Web.HttpCookie("Vshop-Member")
                {
                    Value   = anonymousMember.UserId.ToString(),
                    Expires = System.DateTime.Now.AddYears(10)
                };
                System.Web.HttpContext.Current.Response.Cookies.Add(cookie2);
            }
            return(anonymousMember);
        }
        public static bool UpdateCalculationCommission(OrderInfo order)
        {
            new MemberDao().SetOrderDate(order.UserId, 2);
            DistributorsInfo userIdDistributors = GetUserIdDistributors(order.ReferralUserId);
            SiteSettings     masterSettings     = SettingsManager.GetMasterSettings(false);
            bool             flag = false;

            if (userIdDistributors != null)
            {
                flag = setCommission(order, userIdDistributors, masterSettings);
                if (!string.IsNullOrEmpty(order.ReferralPath))
                {
                    ArrayList commTatalList  = new ArrayList();
                    decimal   num            = 0M;
                    ArrayList userIdList     = new ArrayList();
                    string    referralUserId = order.ReferralUserId.ToString();
                    string    orderId        = order.OrderId;
                    ArrayList orderTotalList = new ArrayList();
                    decimal   num2           = 0M;
                    ArrayList gradeIdList    = new ArrayList();
                    string[]  strArray       = order.ReferralPath.Split(new char[] { '|' });
                    if (strArray.Length == 1)
                    {
                        DistributorsInfo distributor = GetUserIdDistributors(int.Parse(strArray[0]));
                        if (distributor != null)
                        {
                            foreach (LineItemInfo info3 in order.LineItems.Values)
                            {
                                if (info3.OrderItemsStatus.ToString() == OrderStatus.SellerAlreadySent.ToString())
                                {
                                    num  += Math.Round(info3.SecondItemsCommission, 2);
                                    num2 += info3.GetSubTotal();
                                }
                            }
                            commTatalList.Add(num);
                            orderTotalList.Add(num2);
                            userIdList.Add(distributor.UserId);
                            try
                            {
                                if ((order != null) && (num > 0M))
                                {
                                    string userOpenIdByUserId    = MemberProcessor.GetUserOpenIdByUserId(distributor.UserId);
                                    string aliUserOpenIdByUserId = MemberProcessor.GetAliUserOpenIdByUserId(distributor.UserId);
                                    Messenger.SendWeiXinMsg_OrderGetCommission(order, userOpenIdByUserId, aliUserOpenIdByUserId, num);
                                }
                            }
                            catch (Exception)
                            {
                            }
                            int notDescDistributorGrades = GetNotDescDistributorGrades(distributor.UserId.ToString());
                            if (distributor.DistriGradeId != notDescDistributorGrades)
                            {
                                DistributorGradeChange(distributor, order.OrderId, notDescDistributorGrades, true);
                            }
                        }
                    }
                    if (strArray.Length == 2)
                    {
                        DistributorsInfo info4 = GetUserIdDistributors(int.Parse(strArray[0]));
                        foreach (LineItemInfo info5 in order.LineItems.Values)
                        {
                            if (info5.OrderItemsStatus.ToString() == OrderStatus.SellerAlreadySent.ToString())
                            {
                                num  += Math.Round(info5.ThirdItemsCommission, 2);
                                num2 += info5.GetSubTotal();
                            }
                        }
                        commTatalList.Add(num);
                        orderTotalList.Add(num2);
                        userIdList.Add(info4.UserId);
                        try
                        {
                            if ((order != null) && (num > 0M))
                            {
                                string wxOpenId  = MemberProcessor.GetUserOpenIdByUserId(info4.UserId);
                                string aliOpneid = MemberProcessor.GetAliUserOpenIdByUserId(info4.UserId);
                                Messenger.SendWeiXinMsg_OrderGetCommission(order, wxOpenId, aliOpneid, num);
                            }
                        }
                        catch (Exception)
                        {
                        }
                        int newDistributorGradeid = GetNotDescDistributorGrades(info4.UserId.ToString());
                        if (info4.DistriGradeId != newDistributorGradeid)
                        {
                            DistributorGradeChange(info4, order.OrderId, newDistributorGradeid, true);
                        }
                        DistributorsInfo info6 = GetUserIdDistributors(int.Parse(strArray[1]));
                        num  = 0M;
                        num2 = 0M;
                        foreach (LineItemInfo info7 in order.LineItems.Values)
                        {
                            if (info7.OrderItemsStatus.ToString() == OrderStatus.SellerAlreadySent.ToString())
                            {
                                num  += Math.Round(info7.SecondItemsCommission, 2);
                                num2 += info7.GetSubTotal();
                            }
                        }
                        commTatalList.Add(num);
                        orderTotalList.Add(num2);
                        userIdList.Add(info6.UserId);
                        try
                        {
                            if ((order != null) && (num > 0M))
                            {
                                string str7 = MemberProcessor.GetUserOpenIdByUserId(info6.UserId);
                                string str8 = MemberProcessor.GetAliUserOpenIdByUserId(info6.UserId);
                                Messenger.SendWeiXinMsg_OrderGetCommission(order, str7, str8, num);
                            }
                        }
                        catch (Exception)
                        {
                        }
                        int num5 = GetNotDescDistributorGrades(info6.UserId.ToString());
                        if (info6.DistriGradeId != num5)
                        {
                            DistributorGradeChange(info6, order.OrderId, num5, true);
                        }
                    }
                    if (new DistributorsDao().UpdateTwoCalculationCommission(userIdList, referralUserId, orderId, orderTotalList, commTatalList))
                    {
                        for (int j = 0; j < userIdList.Count; j++)
                        {
                            CommissionAutoToBalance(Globals.ToNum(userIdList[j]), masterSettings, decimal.Parse(commTatalList[j].ToString()));
                        }
                    }
                    for (int i = 0; i < userIdList.Count; i++)
                    {
                        int num8 = GetNotDescDistributorGrades(userIdList[i].ToString());
                        gradeIdList.Add(num8);
                    }
                    flag = new DistributorsDao().UpdateGradeId(gradeIdList, userIdList);
                }
                RemoveDistributorCache(userIdDistributors.UserId);
            }
            OrderRedPagerBrower.CreateOrderRedPager(order.OrderId, order.GetTotal(), order.UserId);
            string[] strArray2 = !string.IsNullOrEmpty(order.ActivitiesId) ? order.ActivitiesId.Split(new char[] { ',' }) : null;
            if ((strArray2 != null) && (strArray2.Length > 0))
            {
                int pointNumber = 0;
                foreach (string str9 in strArray2)
                {
                    int id = Globals.IsNumeric(str9) ? Globals.ToNum(str9) : 0;
                    if (id > 0)
                    {
                        ActivityDetailInfo activityDetailInfo = new Hidistro.SqlDal.VShop.ActivityDao().GetActivityDetailInfo(id);
                        if (activityDetailInfo != null)
                        {
                            int couponId = activityDetailInfo.CouponId;
                            pointNumber += activityDetailInfo.Integral;
                            if ((couponId > 0) && (ShoppingProcessor.GetCoupon(couponId.ToString()) != null))
                            {
                                new CouponDao().SendCouponToMember(couponId, order.UserId);
                                try
                                {
                                    OrderInfo info10 = order;
                                    if (info10 != null)
                                    {
                                        Messenger.SendWeiXinMsg_OrderGetCoupon(info10);
                                    }
                                }
                                catch (Exception)
                                {
                                }
                            }
                        }
                    }
                }
                if (pointNumber > 0)
                {
                    new OrderDao().AddMemberPointNumber(pointNumber, order, null);
                    try
                    {
                        OrderInfo info11 = order;
                        if (info11 != null)
                        {
                            Messenger.SendWeiXinMsg_OrderGetPoint(info11, pointNumber);
                        }
                    }
                    catch (Exception)
                    {
                    }
                }
            }
            MemberProcessor.UpdateUserAccount(order);
            try
            {
                string   retInfo   = "";
                DateTime orderDate = order.OrderDate;
                DateTime?payDate   = order.PayDate;
                if (order.Gateway == "hishop.plugins.payment.podrequest")
                {
                    payDate = new DateTime?(orderDate);
                }
                if (payDate.HasValue && (payDate.Value.ToString("yyyy-MM-dd") != DateTime.Now.ToString("yyyy-MM-dd")))
                {
                    new ShopStatisticDao().StatisticsOrdersByRecDate(payDate.Value, UpdateAction.AllUpdate, 0, out retInfo);
                }
            }
            catch
            {
            }
            return(flag);
        }
        public static bool AddDistributors(DistributorsInfo distributors)
        {
            DistributorsDao dao = new DistributorsDao();

            if (dao.GetCustomDistributorStatistic(distributors.StoreName).Rows.Count > 0)
            {
                return(false);
            }
            MemberInfo currentMember = MemberProcessor.GetCurrentMember();

            distributors.DistributorGradeId = DistributorGrade.OneDistributor;
            distributors.ParentUserId       = new int?(currentMember.UserId);
            distributors.UserId             = currentMember.UserId;
            DistributorsInfo currentDistributors = GetCurrentDistributors(true);

            if (currentDistributors != null)
            {
                if (!string.IsNullOrEmpty(currentDistributors.ReferralPath) && !currentDistributors.ReferralPath.Contains("|"))
                {
                    distributors.ReferralPath = currentDistributors.ReferralPath + "|" + currentDistributors.UserId.ToString();
                }
                else if (!string.IsNullOrEmpty(currentDistributors.ReferralPath) && currentDistributors.ReferralPath.Contains("|"))
                {
                    distributors.ReferralPath = currentDistributors.ReferralPath.Split(new char[] { '|' })[1] + "|" + currentDistributors.UserId.ToString();
                }
                else
                {
                    distributors.ReferralPath = currentDistributors.UserId.ToString();
                }
                distributors.ParentUserId = new int?(currentDistributors.UserId);
                if (distributors.Logo == "")
                {
                    if (!string.IsNullOrEmpty(currentDistributors.Logo))
                    {
                        distributors.Logo = currentDistributors.Logo;
                    }
                    else
                    {
                        SiteSettings masterSettings = SettingsManager.GetMasterSettings(true);
                        distributors.Logo = masterSettings.DistributorLogoPic;
                    }
                }
                if (currentDistributors.DistributorGradeId == DistributorGrade.OneDistributor)
                {
                    distributors.DistributorGradeId = DistributorGrade.TowDistributor;
                }
                else if (currentDistributors.DistributorGradeId == DistributorGrade.TowDistributor)
                {
                    distributors.DistributorGradeId = DistributorGrade.ThreeDistributor;
                }
                else
                {
                    distributors.DistributorGradeId = DistributorGrade.ThreeDistributor;
                }
            }
            bool flag = new DistributorsDao().CreateDistributor(distributors);

            if (flag)
            {
                DistributorGradeChange(distributors, "", distributors.DistriGradeId, false);
                try
                {
                    DistributorsInfo distributor = distributors;
                    if (distributor != null)
                    {
                        Messenger.SendWeiXinMsg_DistributorCreate(distributor, MemberProcessor.GetCurrentMember());
                    }
                }
                catch
                {
                }
            }
            return(flag);
        }