예제 #1
0
        public static void Insert_Mall_CouponUser(int UserID, int CouponID, int CouponType, int CouponRuleID, DateTime IsReadySendTime, SqlHelper helper = null, bool IsSent = true)
        {
            Mall_Coupon coupon = null;

            if (helper == null)
            {
                coupon = Mall_Coupon.GetMall_Coupon(CouponID);
            }
            else
            {
                coupon = Mall_Coupon.GetMall_Coupon(CouponID, helper);
            }
            if (coupon == null)
            {
                return;
            }
            var coupon_user = new Mall_CouponUser();

            coupon_user.AddTime         = DateTime.Now;
            coupon_user.AddUserMan      = "System";
            coupon_user.UserID          = UserID;
            coupon_user.CouponID        = CouponID;
            coupon_user.IsUsed          = false;
            coupon_user.UseType         = 0;
            coupon_user.CouponType      = CouponType;
            coupon_user.AmountRuleID    = CouponRuleID;
            coupon_user.IsRead          = false;
            coupon_user.IsSent          = IsSent;
            coupon_user.IsReadySendTime = IsReadySendTime;
            coupon_user.IsTaken         = false;
            coupon_user.StartTime       = coupon.StartTime;
            coupon_user.EndTime         = coupon.EndTime;
            coupon_user.IsActive        = true;
            if (helper == null)
            {
                coupon_user.Save();
                return;
            }
            coupon_user.Save(helper);
        }
예제 #2
0
 public static decimal CalculateCouponPrice(decimal TotalCost, Mall_Coupon coupon)
 {
     if (TotalCost <= 0)
     {
         return(0);
     }
     if (coupon == null)
     {
         return(0);
     }
     if (coupon.ReduceAmount <= 0)
     {
         return(0);
     }
     if (coupon.UseType == 1 && coupon.UseNeedAmount <= TotalCost)
     {
         if (coupon.AmountType == 1)
         {
             return(coupon.ReduceAmount);
         }
         if (coupon.AmountType == 2)
         {
             return(Math.Round((TotalCost * coupon.ReduceAmount) / 100, 2, MidpointRounding.AwayFromZero));
         }
         return(0);
     }
     if (coupon.UseType == 2)
     {
         if (coupon.AmountType == 1)
         {
             return(coupon.ReduceAmount);
         }
         if (coupon.AmountType == 2)
         {
             return(Math.Round((TotalCost * coupon.ReduceAmount) / 100, 2, MidpointRounding.AwayFromZero));
         }
         return(0);
     }
     return(0);
 }
예제 #3
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="AndroidUserID"></param>
 /// <param name="IOSUserID"></param>
 /// <param name="PushContent"></param>
 /// <param name="PushResult"></param>
 /// <param name="PushType">1-客户服务 2-物业公告 3-小区新闻 4-系统通知 5-设备维保 6-限时购通知 7-团购通知 8-生日通知 9-退款通知 10 发货通知 11-绩效考核</param>
 /// <param name="RelatedID"></param>
 public static void Insert_JPushLog(string[] AndroidUserID, string[] IOSUserID, Dictionary <string, object> PushContent, string PushResult, int PushType, int RelatedID, bool IsPushed, string Title, int[] UserIDList = null)
 {
     try
     {
         var data = new JPushLog();
         if (AndroidUserID == null)
         {
             data.AndroidUserID = "ALL";
         }
         else
         {
             data.AndroidUserID = JsonConvert.SerializeObject(AndroidUserID);
         }
         if (IOSUserID == null)
         {
             data.IOSUserID = "ALL";
         }
         else
         {
             data.IOSUserID = JsonConvert.SerializeObject(IOSUserID);
         }
         data.IsPushed = IsPushed;
         if (data.IsPushed)
         {
             data.PushTime = DateTime.Now;
         }
         data.AddTime     = DateTime.Now;
         data.Title       = Title;
         data.PushContent = JsonConvert.SerializeObject(PushContent);
         data.PushResult  = PushResult;
         data.PushType    = PushType;
         data.RelatedID   = RelatedID;
         data.Save();
         var coupon = Mall_Coupon.GetMall_Coupon(RelatedID);
         if (coupon == null)
         {
             return;
         }
         List <Mall_CouponUser> my_coupon_list = new List <Mall_CouponUser>();
         if (data.PushType == 8 && RelatedID > 0 && UserIDList != null)
         {
             foreach (var UserID in UserIDList)
             {
                 var my_coupon = new Mall_CouponUser();
                 my_coupon.CouponID     = RelatedID;
                 my_coupon.UserID       = UserID;
                 my_coupon.AddTime      = DateTime.Now;
                 my_coupon.CouponType   = 2;
                 my_coupon.UseType      = 0;
                 my_coupon.AddUserMan   = "System";
                 my_coupon.IsUsed       = false;
                 my_coupon.AmountRuleID = 0;
                 my_coupon.IsRead       = false;
                 my_coupon.IsSent       = true;
                 my_coupon.SentTime     = DateTime.Now;
                 my_coupon.IsTaken      = false;
                 my_coupon.StartTime    = coupon.StartTime;
                 my_coupon.EndTime      = coupon.EndTime;
                 my_coupon.IsActive     = true;
                 my_coupon_list.Add(my_coupon);
             }
         }
         foreach (var item in my_coupon_list)
         {
             item.Save();
         }
     }
     catch (Exception)
     {
     }
 }
예제 #4
0
        public static Ui.DataGrid GetMall_CouponUserDetail2GridByKeywords(string keywords, int UserID, int CouponType, int IsUsed, int IsActive, long startRowIndex, int pageSize)
        {
            long   totalRows = 0;
            string OrderBy   = " order by [UserID] desc,[AddTime] desc";
            List <SqlParameter> parameters = new List <SqlParameter>();
            List <string>       conditions = new List <string>();

            conditions.Add("1=1");
            if (IsUsed >= 0)
            {
                conditions.Add("[IsUsed]=@IsUsed");
                parameters.Add(new SqlParameter("@IsUsed", IsUsed));
            }
            if (IsActive >= 0)
            {
                conditions.Add("([IsActive]=@IsActive and [EndTime]>=@EndTime)");
                parameters.Add(new SqlParameter("@IsActive", IsActive));
                parameters.Add(new SqlParameter("@EndTime", DateTime.Now));
            }
            if (UserID > 0)
            {
                conditions.Add("([UserID]=@UserID or [UserID] in (select [UserID] from [User] where [ParentUserID]=@UserID))");
                parameters.Add(new SqlParameter("@UserID", UserID));
            }
            if (CouponType > 0)
            {
                conditions.Add("[CouponID] in (select [ID] from [Coupon] where [CouponType]=@CouponType)");
                parameters.Add(new SqlParameter("@CouponType", CouponType));
            }
            if (!string.IsNullOrEmpty(keywords))
            {
                conditions.Add("[UserID] in (select [UserID] from [User] where [NickName] like @keywords or [PhoneNumber] like @keywords)");
                parameters.Add(new SqlParameter("@keywords", "%" + keywords + "%"));
            }
            string fieldList = "[Mall_CouponUser].*";
            string Statement = " from  [Mall_CouponUser] where  " + string.Join(" and ", conditions.ToArray());

            Mall_CouponUserDetail2[] list = GetList <Mall_CouponUserDetail2>(fieldList, Statement, parameters, OrderBy, startRowIndex, pageSize, out totalRows).ToArray();
            List <int> UserIDList         = list.Select(p => p.UserID).Distinct().ToList();
            var        user_list          = User.GetUserListByIDList(UserIDList);
            List <int> CouponIDList       = list.Select(p => p.CouponID).Distinct().ToList();
            var        coupon_list        = Mall_Coupon.GetMall_CouponListByIDList(CouponIDList);

            foreach (var item in list)
            {
                var my_user = user_list.FirstOrDefault(p => p.UserID == item.UserID);
                if (my_user != null)
                {
                    item.NickName    = my_user.NickName;
                    item.PhoneNumber = my_user.PhoneNumber;
                }
                var my_coupon = coupon_list.FirstOrDefault(p => p.ID == item.CouponID);
                if (my_coupon != null)
                {
                    item.CouponName          = my_coupon.CouponName;
                    item.CouponTypeDesc      = my_coupon.CouponTypeDesc;
                    item.UseForALLDesc       = my_coupon.UseForALLDesc;
                    item.UseTypeDesc         = my_coupon.UseTypeDesc;
                    item.ActiveTimeRangeDesc = my_coupon.ActiveTimeRangeDesc;
                }
            }
            DataAccess.Ui.DataGrid dg = new Ui.DataGrid();
            dg.rows  = list;
            dg.total = totalRows;
            dg.page  = pageSize;
            return(dg);
        }
예제 #5
0
        public static List <Dictionary <string, object> > GetOrderMall_CouponUserDicList(decimal totalprice, int BusinessID, int UserID, out List <Dictionary <string, object> > couponlist, int[] ProductIDList = null, int[] ServiceIDList = null, int PaymentID = 0)
        {
            couponlist = new List <Dictionary <string, object> >();
            List <SqlParameter> parameters = new List <SqlParameter>();
            List <string>       conditions = new List <string>();

            if (UserID <= 0)
            {
                return(new List <Dictionary <string, object> >());
            }
            conditions.Add("[IsTaken]=1");
            parameters.Add(new SqlParameter("@UserID", UserID));
            conditions.Add("[UserID]=@UserID");
            conditions.Add("[IsUsed]=0");
            conditions.Add("[IsActive]=1");
            conditions.Add("([EndTime]>=@EndTime or [EndTime] is null)");
            parameters.Add(new SqlParameter("@EndTime", DateTime.Now));
            //物业收费
            if (PaymentID > 0)
            {
                conditions.Add("[IsUseForWY]=1");
            }
            //2-单个商品购买 6-拼团购买
            else if (ProductIDList != null && ProductIDList.Length > 0)
            {
                List <string> cmdlist = new List <string>();
                conditions.Add("[IsUseForProduct]=1");
                cmdlist.Add("[IsUseForALLProduct]=1");
                cmdlist.Add("[CouponID] in (select [CouponID] from [Mall_CouponProduct] where [ProductID] in (" + string.Join(",", ProductIDList) + "))");
                cmdlist.Add("[IsUseForALLStore]=1");
                if (BusinessID > 0)
                {
                    cmdlist.Add("[CouponID] in (select [CouponID] from [Mall_CouponProduct] where [BusinessID]=@BusinessID)");
                    parameters.Add(new SqlParameter("@BusinessID", BusinessID));
                }
                cmdlist.Add("[IsUseForALLCategory]=1");
                cmdlist.Add("[CouponID] in (select [CouponID] from [Mall_CouponProduct] where [ProductCategoryID] in (select [CategoryID] from [Mall_Product_Category] where [ProductID] in (" + string.Join(",", ProductIDList.ToArray()) + ")))");
                conditions.Add("(" + string.Join(" or ", cmdlist.ToArray()) + ")");
            }
            //购买服务
            else if (ServiceIDList != null && ServiceIDList.Length > 0)
            {
                List <string> cmdlist = new List <string>();
                conditions.Add("[IsUseForService]=1");
                cmdlist.Add("[IsUseForALLService]=1");
                cmdlist.Add("[CouponID] in (select [CouponID] from [Mall_CouponProduct] where [ServiceID] in (" + string.Join(",", ServiceIDList) + "))");
                conditions.Add("(" + string.Join(" or ", cmdlist.ToArray()) + ")");
            }
            else
            {
                return(new List <Dictionary <string, object> >());
            }
            string     cmdtext       = "select * from (select [Mall_CouponUser].*,[Mall_Coupon].IsUseForWY,[Mall_Coupon].IsUseForProduct,[Mall_Coupon].IsUseForALLProduct,[Mall_Coupon].IsUseForALLStore,[Mall_Coupon].IsUseForALLCategory,[Mall_Coupon].IsUseForService,[Mall_Coupon].IsUseForALLService from [Mall_CouponUser] left join [Mall_Coupon] on [Mall_Coupon].ID=[Mall_CouponUser].CouponID)A where " + string.Join(" and ", conditions.ToArray());
            var        list          = GetList <Mall_CouponUserDetail>(cmdtext, parameters).ToArray();
            List <int> CouponIDList  = list.Select(p => p.CouponID).Distinct().ToList();
            var        all_coupons   = Mall_Coupon.GetMall_CouponListByIDList(CouponIDList);
            var        allcouponlist = new List <Dictionary <string, object> >();
            List <int> MyIDList      = new List <int>();

            foreach (var item in list)
            {
                var my_coupon = all_coupons.FirstOrDefault(q => q.ID == item.CouponID);
                if (my_coupon == null)
                {
                    continue;
                }
                decimal price = Mall_Coupon.CalculateCouponPrice(totalprice, my_coupon);
                if (price <= 0)
                {
                    continue;
                }
                int count = 1;
                if (MyIDList.Contains(item.CouponID))
                {
                    foreach (var item2 in couponlist)
                    {
                        if (Convert.ToInt32(item2["couponid"]) == item.CouponID)
                        {
                            count          = Convert.ToInt32(item2["count"]);
                            count          = count + 1;
                            item2["count"] = count;
                        }
                    }
                }

                MyIDList.Add(item.CouponID);
                var dic = new Dictionary <string, object>();
                dic.Add("id", item.ID);
                dic.Add("couponid", item.CouponID);
                dic.Add("text", my_coupon.CouponName);
                dic.Add("selected", "");
                dic.Add("price", price);
                dic.Add("pricedesc", "¥-" + price.ToString("0.00"));
                dic.Add("count", 1);
                dic.Add("isused", false);
                allcouponlist.Add(dic);
                if (count > 1)
                {
                    continue;
                }
                dic = new Dictionary <string, object>();
                dic.Add("id", 0);
                dic.Add("couponid", item.CouponID);
                dic.Add("text", my_coupon.CouponName);
                dic.Add("selected", "");
                dic.Add("price", price);
                dic.Add("pricedesc", "¥-" + price.ToString("0.00"));
                dic.Add("count", count);
                couponlist.Add(dic);
            }
            return(allcouponlist);
        }
예제 #6
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);
        }