Esempio n. 1
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);
        }
Esempio n. 2
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);
        }
Esempio n. 3
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);
        }