示例#1
0
        /// <summary>
        /// 消费处理
        /// </summary>
        /// <param name="order"></param>
        /// <param name="payment"></param>
        public static void GetEarnThroughBuy(Mall_Order order = null, Payment payment = null)
        {
            //消费赠与处理
            if (order == null)
            {
                return;
            }
            int[] ProductIDList = Mall_OrderItem.GetProductIDListByOrderID(order.ID, IsProduct: true);
            int[] ServiceIDList = Mall_OrderItem.GetProductIDListByOrderID(order.ID, IsService: true);
            if (payment == null)
            {
                payment = Payment.GetPaymentByTradeNo(order.TradeNo);
            }
            decimal TotalCost = order.TotalCost;

            if (payment != null)
            {
                TotalCost = payment.Amount / 100;
            }
            Dictionary <string, object> BackObject = new Dictionary <string, object>();

            Mall_AmountRule.GetBackAmountPoint(TotalCost, out BackObject, ProductIDList, ServiceIDList, AmountType: 2, UserID: order.UserID);
            string Title        = "消费赠与";
            int    CategoryType = 6;

            using (SqlHelper helper = new SqlHelper())
            {
                try
                {
                    helper.BeginTransaction();
                    decimal  BackAmount            = Utility.Tools.GetValueFromDic <decimal>(BackObject, "BackAmount");
                    int      AmountRuleID          = Utility.Tools.GetValueFromDic <int>(BackObject, "AmountRuleID");
                    bool     AmountIsSendNow       = Utility.Tools.GetValueFromDic <bool>(BackObject, "AmountIsSendNow");
                    DateTime AmountIsReadySendTime = Utility.Tools.GetValueFromDic <DateTime>(BackObject, "AmountIsReadySendTime");
                    if (BackAmount > 0 && AmountRuleID > 0)
                    {
                        Insert_Mall_UserBalance(order.UserID, 1, BackAmount, Title, "BalaceID:" + order.ID, CategoryType, "System", 1, "", RelatedID: order.ID, AmountRuleID: AmountRuleID, helper: helper, PaymentMethod: order.PaymentMethod, IsSent: AmountIsSendNow, IsReadySendTime: AmountIsReadySendTime);
                    }
                    int      BackPoint            = Utility.Tools.GetValueFromDic <int>(BackObject, "BackPoint");
                    int      PointRuleID          = Utility.Tools.GetValueFromDic <int>(BackObject, "PointRuleID");
                    bool     PointIsSendNow       = Utility.Tools.GetValueFromDic <bool>(BackObject, "PointIsSendNow");
                    DateTime PointIsReadySendTime = Utility.Tools.GetValueFromDic <DateTime>(BackObject, "PointIsReadySendTime");
                    if (BackPoint > 0 && PointRuleID > 0)
                    {
                        Mall_UserPoint.Insert_Mall_UserPoint(order.UserID, 1, 0, Title, "BalaceID:" + order.ID, CategoryType, "System", 1, "", 0, helper, RelatedID: order.ID, PointValue: BackPoint, AmountRuleID: PointRuleID, IsSent: PointIsSendNow, IsReadySendTime: PointIsReadySendTime);
                    }
                    if (order.TotalOrderPointCost > 0)
                    {
                        Mall_UserPoint.Insert_Mall_UserPoint(order.UserID, 2, 0, "购买商品", "OrderID:" + order.ID, 1, "System", 1, order.TradeNo, order.ID, helper, RelatedID: order.ID, PointValue: -order.TotalOrderPointCost, AmountRuleID: 0);
                    }

                    List <int> CouponIDList          = Utility.Tools.GetValueFromDic <List <int> >(BackObject, "CouponIDList");
                    int        CouponRuleID          = Utility.Tools.GetValueFromDic <int>(BackObject, "CouponRuleID");
                    bool       CouponIsSendNow       = Utility.Tools.GetValueFromDic <bool>(BackObject, "CouponIsSendNow");
                    DateTime   CouponIsReadySendTime = Utility.Tools.GetValueFromDic <DateTime>(BackObject, "CouponIsReadySendTime");
                    int        SendCouponCount       = Utility.Tools.GetValueFromDic <int>(BackObject, "SendCouponCount");
                    if (CouponIDList != null && CouponIDList.Count > 0 && CouponRuleID > 0)
                    {
                        foreach (var CouponID in CouponIDList)
                        {
                            for (int i = 0; i < SendCouponCount; i++)
                            {
                                Mall_CouponUser.Insert_Mall_CouponUser(order.UserID, CouponID, 3, CouponRuleID, CouponIsReadySendTime, helper: helper, IsSent: CouponIsSendNow);
                            }
                        }
                    }
                    if (payment != null)
                    {
                        payment.Save(helper);
                    }
                    if (order != null)
                    {
                        order.Save(helper);
                    }
                    helper.Commit();
                }
                catch (Exception ex)
                {
                    helper.Rollback();
                    Utility.LogHelper.WriteError("Mall_UserBalance.cs", "GetEarnThroughBuy", ex);
                }
            }
        }
示例#2
0
        public static List <Dictionary <string, object> > GetExpiringMall_CouponUserListByUserID(int UserID)
        {
            List <SqlParameter> parameters = new List <SqlParameter>();
            List <string>       conditions = new List <string>();

            if (UserID == 0)
            {
                return(new List <Dictionary <string, object> >());
            }
            conditions.Add("[IsActive]=1");
            conditions.Add("[UserID]=@UserID");
            conditions.Add("isnull([IsTaken],0)=1");
            conditions.Add("isnull([IsUsed],0)=0");
            parameters.Add(new SqlParameter("@UserID", UserID));
            string cmdtext = "select * from [Mall_CouponUser] where  " + string.Join(" and ", conditions.ToArray()) + " order by [AddTime] desc";
            var    list    = GetList <Mall_CouponUser>(cmdtext, parameters).ToArray();
            List <Mall_CouponUser> finallist = new List <Mall_CouponUser>();
            var rule_list = Mall_AmountRule.GetMall_AmountRuleListByIDList(list.Select(p => p.AmountRuleID).Distinct().ToList());

            foreach (var item in list)
            {
                DateTime NowDate = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day);
                if (item.EndTime == DateTime.MinValue || item.EndTime < NowDate)
                {
                    continue;
                }
                var my_rule = rule_list.FirstOrDefault(p => p.ID == item.AmountRuleID);
                if (my_rule == null)
                {
                    continue;
                }
                if (my_rule.PopupBeforeExpireDay <= 0)
                {
                    continue;
                }
                DateTime ExpireReadDate = DateTime.Now;
                if (item.ExpireReadDate > DateTime.MinValue)
                {
                    ExpireReadDate = new DateTime(item.ExpireReadDate.Year, item.ExpireReadDate.Month, item.ExpireReadDate.Day);
                    if (ExpireReadDate >= NowDate)
                    {
                        continue;
                    }
                }
                if (item.ExpireReadDate == DateTime.MinValue)
                {
                    item.ExpireReadDate = DateTime.Now;
                }
                ExpireReadDate = new DateTime(item.ExpireReadDate.Year, item.ExpireReadDate.Month, item.ExpireReadDate.Day);
                if (ExpireReadDate.AddDays(my_rule.PopupBeforeExpireDay) >= item.EndTime)
                {
                    finallist.Add(item);
                    continue;
                }
            }
            var coupon_list = Mall_Coupon.GetMall_CouponListByIDList(finallist.Select(p => p.CouponID).Distinct().ToList());
            List <Dictionary <string, object> > items = new List <Dictionary <string, object> >();
            int item_count = 0;

            foreach (var item in finallist)
            {
                item.ExpireReadDate = DateTime.Now;
                item.Save();
                var dic       = new Dictionary <string, object>();
                var my_coupon = coupon_list.FirstOrDefault(p => p.ID == item.CouponID);
                if (my_coupon == null)
                {
                    continue;
                }
                dic["ID"]       = item.ID;
                dic["CouponID"] = my_coupon.ID;
                if (string.IsNullOrEmpty(my_coupon.CoverImage))
                {
                    dic["CoverImage"] = string.Empty;
                }
                else
                {
                    dic["CoverImage"] = Utility.Tools.GetContextPath() + my_coupon.CoverImage;
                }
                dic["UseTitle"]    = my_coupon.UseTitle;
                dic["UseSubTitle"] = my_coupon.UseSubTitle;
                int rest_count = item_count % 3;
                dic["background_img"] = "url('../image/icons/coupon_bg_" + rest_count + ".png')";
                items.Add(dic);
                item_count++;
            }
            return(items);
        }
示例#3
0
        /// <summary>
        /// 充值处理
        /// </summary>
        /// <param name="BalanceStatus"></param>
        /// <param name="TradeNo"></param>
        /// <param name="payment"></param>
        /// <param name="AmountType"></param>
        public static void UpdateMall_UserBalanceStatus(int BalanceStatus, string TradeNo, Payment payment = null, int AmountType = 1, string PaymentMethod = "")
        {
            //充值赠与处理
            Dictionary <string, object> BackObject = new Dictionary <string, object>();
            Mall_UserBalance            data       = null;

            if (BalanceStatus == 1)
            {
                data = GetMall_UserBalanceByTradeNo(TradeNo);
                if (data == null)
                {
                    return;
                }
                Mall_AmountRule.GetBackAmountPoint(data.BalanceValue, out BackObject, new int[] { }, new int[] { }, AmountType: AmountType, UserID: data.UserID);
                //AmountRuleID = Utility.Tools.GetValueFromDic<int>(BackObject, "AmountRuleID");
                //BackAmount = Utility.Tools.GetValueFromDic<decimal>(BackObject, "BackAmount");
            }
            string Title        = "充值赠与";
            int    CategoryType = 5;
            User   user         = null;
            var    user_level   = Mall_UserLevel.GetMall_UserLevelByUserID(data.UserID, out user);

            using (SqlHelper helper = new SqlHelper())
            {
                try
                {
                    helper.BeginTransaction();
                    data.BalanceStatus = 1;
                    data.Save(helper);
                    if (user != null && user_level != null)
                    {
                        if (user.UserLevelID != user_level.ID)
                        {
                            string LevelTitle = "充值满" + user_level.StartAmount.ToString("0.00") + "升到到合伙人(" + user_level.Name + ")";
                            Mall_UserLevelApprove.Insert_Mall_UserLevelApprove(data.UserID, LevelTitle, user_level.ID, helper: helper, IncomingAmount: data.BalanceValue, IncomingType: data.PaymentMethodDesc, UserBalanceID: data.ID);
                        }
                    }
                    decimal  BackAmount            = Utility.Tools.GetValueFromDic <decimal>(BackObject, "BackAmount");
                    int      AmountRuleID          = Utility.Tools.GetValueFromDic <int>(BackObject, "AmountRuleID");
                    bool     AmountIsSendNow       = Utility.Tools.GetValueFromDic <bool>(BackObject, "AmountIsSendNow");
                    DateTime AmountIsReadySendTime = Utility.Tools.GetValueFromDic <DateTime>(BackObject, "AmountIsReadySendTime");
                    if (BackAmount > 0 && AmountRuleID > 0)
                    {
                        Insert_Mall_UserBalance(data.UserID, 1, BackAmount, Title, "BalaceID:" + data.ID, CategoryType, "System", 1, "", RelatedID: data.ID, AmountRuleID: AmountRuleID, helper: helper, PaymentMethod: PaymentMethod, IsSent: AmountIsSendNow, IsReadySendTime: AmountIsReadySendTime);
                    }
                    int      BackPoint            = Utility.Tools.GetValueFromDic <int>(BackObject, "BackPoint");
                    int      PointRuleID          = Utility.Tools.GetValueFromDic <int>(BackObject, "PointRuleID");
                    bool     PointIsSendNow       = Utility.Tools.GetValueFromDic <bool>(BackObject, "PointIsSendNow");
                    DateTime PointIsReadySendTime = Utility.Tools.GetValueFromDic <DateTime>(BackObject, "PointIsReadySendTime");
                    if (BackPoint > 0 && PointRuleID > 0)
                    {
                        Mall_UserPoint.Insert_Mall_UserPoint(data.UserID, 1, 0, Title, "BalaceID:" + data.ID, CategoryType, "System", 1, "", 0, helper, RelatedID: data.ID, PointValue: BackPoint, AmountRuleID: PointRuleID, IsSent: PointIsSendNow, IsReadySendTime: PointIsReadySendTime);
                    }
                    List <int> CouponIDList          = Utility.Tools.GetValueFromDic <List <int> >(BackObject, "CouponIDList");
                    int        CouponRuleID          = Utility.Tools.GetValueFromDic <int>(BackObject, "CouponRuleID");
                    bool       CouponIsSendNow       = Utility.Tools.GetValueFromDic <bool>(BackObject, "CouponIsSendNow");
                    DateTime   CouponIsReadySendTime = Utility.Tools.GetValueFromDic <DateTime>(BackObject, "CouponIsReadySendTime");
                    int        SendCouponCount       = Utility.Tools.GetValueFromDic <int>(BackObject, "SendCouponCount");
                    if (CouponIDList != null && CouponIDList.Count > 0 && CouponRuleID > 0)
                    {
                        foreach (var CouponID in CouponIDList)
                        {
                            for (int i = 0; i < SendCouponCount; i++)
                            {
                                Mall_CouponUser.Insert_Mall_CouponUser(data.UserID, CouponID, 1, CouponRuleID, CouponIsReadySendTime, helper: helper, IsSent: CouponIsSendNow);
                            }
                        }
                    }
                    if (payment != null)
                    {
                        payment.Save(helper);
                    }
                    helper.Commit();
                }
                catch (Exception ex)
                {
                    helper.Rollback();
                    Utility.LogHelper.WriteError("Mall_UserBalance.cs", "UpdateMall_UserBalanceStatus", ex);
                }
            }
        }