示例#1
0
        public void SetBonusToUsed(long userid, List <OrderInfo> orders, long rid)
        {
            ShopBonusReceiveInfo nullable = (
                from p in context.ShopBonusReceiveInfo
                where p.UserId == userid && p.Id == rid
                select p).FirstOrDefault();

            nullable.State       = ShopBonusReceiveInfo.ReceiveState.Use;
            nullable.UsedTime    = new DateTime?(DateTime.Now);
            nullable.UsedOrderId = new long?(orders.FirstOrDefault((OrderInfo p) => p.ShopId == nullable.ChemCloud_ShopBonusGrant.ChemCloud_ShopBonus.ShopId).Id);
            context.SaveChanges();
            ser_wxcard.Consume(nullable.Id, ThisCouponType);
        }
示例#2
0
        public decimal GetUsedPrice(long orderid, long userid)
        {
            ShopBonusReceiveInfo shopBonusReceiveInfo = (
                from p in context.ShopBonusReceiveInfo
                where p.UsedOrderId == orderid && p.UserId == userid
                select p).FirstOrDefault();

            if (shopBonusReceiveInfo == null)
            {
                return(new decimal(0));
            }
            return(shopBonusReceiveInfo.Price.Value);
        }
示例#3
0
        /// <summary>
        /// 生成红包详情
        /// </summary>
        public long GenerateBonusDetail(ShopBonusInfo model, long orderid, string receiveurl)
        {
            if (model.DateEnd <= DateTime.Now || model.IsInvalid)  //过期、失效
            {
                Log.Info("此活动已过期 , shopid = " + model.ShopId);
                return(0);
            }
            else if (model.DateStart > DateTime.Now) // 未开始
            {
                Log.Info("此活动未开始 , shopid = " + model.ShopId);
                return(0);
            }

            ShopBonusGrantInfo grant = null;

            try
            {
                var order = DbFactory.Default.Get <OrderInfo>().Where(r => r.Id == orderid).FirstOrDefault();

                grant = DbFactory.Default.Get <ShopBonusGrantInfo>().Where(p => p.OrderId == orderid).FirstOrDefault();

                //if (Context.ShopBonusGrantInfo.Exist((p => p.OrderId == orderid)))
                if (DbFactory.Default.Get <ShopBonusGrantInfo>().Where(p => p.OrderId == orderid).Exist())
                {
                    Log.Info("此活动已存在防止多次添加 , shopid = " + model.ShopId);
                    return(grant.Id);
                }
                DbFactory.Default.InTransaction(() =>
                {
                    grant             = new ShopBonusGrantInfo();
                    grant.ShopBonusId = model.Id;
                    grant.UserId      = order.UserId;
                    grant.OrderId     = orderid;
                    grant.BonusQR     = "";
                    DbFactory.Default.Add(grant);

                    string path   = GenerateQR(Path.Combine(receiveurl, grant.Id.ToString()));
                    grant.BonusQR = path;
                    DbFactory.Default.Set <ShopBonusGrantInfo>().Set(e => e.BonusQR, path).Where(e => e.Id == grant.Id).Succeed();

                    for (int i = 0; i < model.Count; i++)
                    {
                        decimal randPrice           = GenerateRandomAmountPrice(model.RandomAmountStart, model.RandomAmountEnd);
                        ShopBonusReceiveInfo detail = new ShopBonusReceiveInfo
                        {
                            BonusGrantId = grant.Id,
                            Price        = randPrice,
                            OpenId       = null,
                            State        = ShopBonusReceiveInfo.ReceiveState.NotUse
                        };
                        DbFactory.Default.Add(detail);
                    }
                });
            }
            catch (Exception e)
            {
                Log.Info("错误:", e);

                var sql = DbFactory.Default.Get <ShopBonusGrantInfo>()
                          .Where <ShopBonusReceiveInfo>((sbg, sbr) => sbg.Id == sbr.BonusGrantId && sbg.ShopBonusId == model.Id);
                DbFactory.Default.Del <ShopBonusReceiveInfo>().Where(n => n.ExExists(sql)).Succeed();

                DbFactory.Default.Del <ShopBonusGrantInfo>().Where(s => s.ShopBonusId == model.Id).Succeed();
                DbFactory.Default.Del <ShopBonusInfo>().Where(s => s.Id == model.Id).Succeed();
            }
            return(grant.Id);
        }
示例#4
0
        private void GetOrderProductsInfo(string cartItemIds)
        {
            CartHelper cartHelper = new CartHelper();
            IEnumerable <ShoppingCartItem> cartItems = null;

            if (!string.IsNullOrWhiteSpace(cartItemIds))
            {
                char[]             chrArray = new char[] { ',' };
                IEnumerable <long> nums     =
                    from t in cartItemIds.Split(chrArray)
                    select long.Parse(t);

                cartItems = ServiceHelper.Create <ICartService>().GetCartItems(nums);
            }
            else
            {
                cartItems = cartHelper.GetCart(base.CurrentUser.Id).Items;
            }
            int cityId = 0;
            ShippingAddressInfo defaultUserShippingAddressByUserId = ServiceHelper.Create <IShippingAddressService>().GetDefaultUserShippingAddressByUserId(base.CurrentUser.Id);

            if (defaultUserShippingAddressByUserId != null)
            {
                cityId = Instance <IRegionService> .Create.GetCityId(defaultUserShippingAddressByUserId.RegionIdPath);
            }
            IProductService      productService = ServiceHelper.Create <IProductService>();
            IShopService         shopService    = ServiceHelper.Create <IShopService>();
            List <CartItemModel> list           = cartItems.Select <ShoppingCartItem, CartItemModel>((ShoppingCartItem item) => {
                ProductInfo product = productService.GetProduct(item.ProductId);
                SKUInfo sku         = productService.GetSku(item.SkuId);
                return(new CartItemModel()
                {
                    skuId = item.SkuId,
                    id = product.Id,
                    imgUrl = product.GetImage(ProductInfo.ImageSize.Size_100, 1),
                    name = product.ProductName,
                    price = sku.SalePrice,
                    shopId = product.ShopId,
                    count = item.Quantity
                });
            }).ToList();
            IEnumerable <IGrouping <long, CartItemModel> > groupings =
                from a in list
                group a by a.shopId;
            List <ShopCartItemModel> shopCartItemModels = new List <ShopCartItemModel>();

            foreach (IGrouping <long, CartItemModel> nums1 in groupings)
            {
                IEnumerable <long> nums2 =
                    from r in nums1
                    select r.id;
                IEnumerable <int> nums3 =
                    from r in nums1
                    select r.count;
                ShopCartItemModel shopCartItemModel = new ShopCartItemModel()
                {
                    shopId = nums1.Key
                };
                if (ServiceHelper.Create <IVShopService>().GetVShopByShopId(shopCartItemModel.shopId) != null)
                {
                    shopCartItemModel.vshopId = ServiceHelper.Create <IVShopService>().GetVShopByShopId(shopCartItemModel.shopId).Id;
                }
                else
                {
                    shopCartItemModel.vshopId = 0;
                }
                shopCartItemModel.CartItemModels = (
                    from a in list
                    where a.shopId == shopCartItemModel.shopId
                    select a).ToList();
                shopCartItemModel.ShopName = shopService.GetShop(shopCartItemModel.shopId, false).ShopName;
                if (cityId > 0)
                {
                    shopCartItemModel.Freight = ServiceHelper.Create <IProductService>().GetFreight(nums2, nums3, cityId);
                }
                List <ShopBonusReceiveInfo> detailToUse = ServiceHelper.Create <IShopBonusService>().GetDetailToUse(shopCartItemModel.shopId, base.CurrentUser.Id, nums1.Sum <CartItemModel>((CartItemModel a) => a.price * a.count));
                List <CouponRecordInfo>     userCoupon  = ServiceHelper.Create <ICouponService>().GetUserCoupon(shopCartItemModel.shopId, base.CurrentUser.Id, nums1.Sum <CartItemModel>((CartItemModel a) => a.price * a.count));
                if (detailToUse.Count() > 0 && userCoupon.Count() > 0)
                {
                    ShopBonusReceiveInfo shopBonusReceiveInfo = detailToUse.FirstOrDefault();
                    CouponRecordInfo     couponRecordInfo     = userCoupon.FirstOrDefault();
                    decimal?price = shopBonusReceiveInfo.Price;
                    decimal num   = couponRecordInfo.ChemCloud_Coupon.Price;
                    if ((price.GetValueOrDefault() <= num ? true : !price.HasValue))
                    {
                        shopCartItemModel.Coupon = new CouponModel()
                        {
                            CouponName  = couponRecordInfo.ChemCloud_Coupon.CouponName,
                            CouponId    = couponRecordInfo.Id,
                            CouponPrice = couponRecordInfo.ChemCloud_Coupon.Price,
                            Type        = 0
                        };
                    }
                    else
                    {
                        shopCartItemModel.Coupon = new CouponModel()
                        {
                            CouponName  = shopBonusReceiveInfo.ChemCloud_ShopBonusGrant.ChemCloud_ShopBonus.Name,
                            CouponId    = shopBonusReceiveInfo.Id,
                            CouponPrice = shopBonusReceiveInfo.Price.Value,
                            Type        = 1
                        };
                    }
                }
                else if (detailToUse.Count() <= 0 && userCoupon.Count() <= 0)
                {
                    shopCartItemModel.Coupon = null;
                }
                else if (detailToUse.Count() <= 0 && userCoupon.Count() > 0)
                {
                    CouponRecordInfo couponRecordInfo1 = userCoupon.FirstOrDefault();
                    shopCartItemModel.Coupon = new CouponModel()
                    {
                        CouponName  = couponRecordInfo1.ChemCloud_Coupon.CouponName,
                        CouponId    = couponRecordInfo1.Id,
                        CouponPrice = couponRecordInfo1.ChemCloud_Coupon.Price,
                        Type        = 0
                    };
                }
                else if (detailToUse.Count() > 0 && userCoupon.Count() <= 0)
                {
                    ShopBonusReceiveInfo shopBonusReceiveInfo1 = detailToUse.FirstOrDefault();
                    shopCartItemModel.Coupon = new CouponModel()
                    {
                        CouponName  = shopBonusReceiveInfo1.ChemCloud_ShopBonusGrant.ChemCloud_ShopBonus.Name,
                        CouponId    = shopBonusReceiveInfo1.Id,
                        CouponPrice = shopBonusReceiveInfo1.Price.Value,
                        Type        = 1
                    };
                }
                decimal num1        = shopCartItemModel.CartItemModels.Sum <CartItemModel>((CartItemModel d) => d.price * d.count);
                decimal num2        = num1 - (shopCartItemModel.Coupon == null ? new decimal(0) : shopCartItemModel.Coupon.CouponPrice);
                decimal freeFreight = shopService.GetShop(shopCartItemModel.shopId, false).FreeFreight;
                shopCartItemModel.isFreeFreight = false;
                if (freeFreight > new decimal(0))
                {
                    shopCartItemModel.shopFreeFreight = freeFreight;
                    if (num2 >= freeFreight)
                    {
                        shopCartItemModel.Freight       = new decimal(0);
                        shopCartItemModel.isFreeFreight = true;
                    }
                }
                shopCartItemModels.Add(shopCartItemModel);
            }
            decimal num3 = (
                from a in shopCartItemModels
                where a.Coupon != null
                select a).Sum <ShopCartItemModel>((ShopCartItemModel b) => b.Coupon.CouponPrice);

            ViewBag.products         = shopCartItemModels;
            base.ViewBag.totalAmount = list.Sum <CartItemModel>((CartItemModel item) => item.price * item.count);
            base.ViewBag.Freight     = shopCartItemModels.Sum <ShopCartItemModel>((ShopCartItemModel a) => a.Freight);
            dynamic viewBag = base.ViewBag;
            dynamic obj     = ViewBag.totalAmount;

            viewBag.orderAmount = obj + ViewBag.Freight - num3;
            IMemberIntegralService memberIntegralService = ServiceHelper.Create <IMemberIntegralService>();
            MemberIntegral         memberIntegral        = memberIntegralService.GetMemberIntegral(base.CurrentUser.Id);
            int num4 = (memberIntegral == null ? 0 : memberIntegral.AvailableIntegrals);

            ViewBag.userIntegrals      = num4;
            ViewBag.integralPerMoney   = 0;
            ViewBag.memberIntegralInfo = memberIntegral;
            MemberIntegralExchangeRules integralChangeRule = memberIntegralService.GetIntegralChangeRule();
            decimal num5     = new decimal(0);
            decimal num6     = new decimal(0);
            decimal viewBag1 = (decimal)ViewBag.totalAmount;

            if (integralChangeRule == null || integralChangeRule.IntegralPerMoney <= 0)
            {
                num5 = new decimal(0);
                num6 = new decimal(0);
            }
            else
            {
                if (((viewBag1 - num3) - Math.Round((decimal)num4 / integralChangeRule.IntegralPerMoney, 2)) <= new decimal(0))
                {
                    num5 = Math.Round(viewBag1 - num3, 2);
                    num6 = Math.Round((viewBag1 - num3) * integralChangeRule.IntegralPerMoney);
                }
                else
                {
                    num5 = Math.Round((decimal)num4 / integralChangeRule.IntegralPerMoney, 2);
                    num6 = num4;
                }
                if (num5 <= new decimal(0))
                {
                    num5 = new decimal(0);
                    num6 = new decimal(0);
                }
            }
            ViewBag.integralPerMoney = num5;
            ViewBag.userIntegrals    = num6;
        }
示例#5
0
        private void GetOrderProductsInfo(IEnumerable <string> skuIds, IEnumerable <int> counts)
        {
            IProductService     productService = ServiceHelper.Create <IProductService>();
            IShopService        shopService    = ServiceHelper.Create <IShopService>();
            int                 num3           = 0;
            int                 cityId         = 0;
            ShippingAddressInfo defaultUserShippingAddressByUserId = ServiceHelper.Create <IShippingAddressService>().GetDefaultUserShippingAddressByUserId(base.CurrentUser.Id);

            if (defaultUserShippingAddressByUserId != null)
            {
                cityId = Instance <IRegionService> .Create.GetCityId(defaultUserShippingAddressByUserId.RegionIdPath);
            }
            List <CartItemModel> list = skuIds.Select <string, CartItemModel>((string item) => {
                SKUInfo sku            = productService.GetSku(item);
                IEnumerable <int> nums = counts;
                int num  = num3;
                int num1 = num;
                num3     = num + 1;
                int num2 = nums.ElementAt <int>(num1);
                LimitTimeMarketInfo limitTimeMarketItemByProductId = ServiceHelper.Create <ILimitTimeBuyService>().GetLimitTimeMarketItemByProductId(sku.ProductInfo.Id);
                if (limitTimeMarketItemByProductId != null && num2 > limitTimeMarketItemByProductId.MaxSaleCount)
                {
                    throw new HimallException(string.Concat("超过最大限购数量:", limitTimeMarketItemByProductId.MaxSaleCount.ToString()));
                }
                return(new CartItemModel()
                {
                    skuId = item,
                    id = sku.ProductInfo.Id,
                    imgUrl = sku.ProductInfo.GetImage(ProductInfo.ImageSize.Size_100, 1),
                    name = sku.ProductInfo.ProductName,
                    shopId = sku.ProductInfo.ShopId,
                    price = (limitTimeMarketItemByProductId == null ? sku.SalePrice : limitTimeMarketItemByProductId.Price),
                    count = num2,
                    productCode = sku.ProductInfo.ProductCode
                });
            }).ToList();
            IEnumerable <IGrouping <long, CartItemModel> > groupings =
                from a in list
                group a by a.shopId;
            List <ShopCartItemModel> shopCartItemModels = new List <ShopCartItemModel>();

            foreach (IGrouping <long, CartItemModel> nums1 in groupings)
            {
                IEnumerable <long> nums2 =
                    from r in nums1
                    select r.id;
                IEnumerable <int> nums3 =
                    from r in nums1
                    select r.count;
                ShopCartItemModel shopCartItemModel = new ShopCartItemModel()
                {
                    shopId = nums1.Key
                };
                shopCartItemModel.CartItemModels = (
                    from a in list
                    where a.shopId == shopCartItemModel.shopId
                    select a).ToList();
                shopCartItemModel.ShopName = shopService.GetShop(shopCartItemModel.shopId, false).ShopName;
                if (cityId != 0)
                {
                    shopCartItemModel.Freight = ServiceHelper.Create <IProductService>().GetFreight(nums2, nums3, cityId);
                }
                List <ShopBonusReceiveInfo> detailToUse = ServiceHelper.Create <IShopBonusService>().GetDetailToUse(shopCartItemModel.shopId, base.CurrentUser.Id, nums1.Sum <CartItemModel>((CartItemModel a) => a.price * a.count));
                List <CouponRecordInfo>     userCoupon  = ServiceHelper.Create <ICouponService>().GetUserCoupon(shopCartItemModel.shopId, base.CurrentUser.Id, nums1.Sum <CartItemModel>((CartItemModel a) => a.price * a.count));
                if (detailToUse.Count() > 0 && userCoupon.Count() > 0)
                {
                    ShopBonusReceiveInfo shopBonusReceiveInfo = detailToUse.FirstOrDefault();
                    CouponRecordInfo     couponRecordInfo     = userCoupon.FirstOrDefault();
                    decimal?price  = shopBonusReceiveInfo.Price;
                    decimal price1 = couponRecordInfo.ChemCloud_Coupon.Price;
                    if ((price.GetValueOrDefault() <= price1 ? true : !price.HasValue))
                    {
                        shopCartItemModel.Coupon = new CouponModel()
                        {
                            CouponName  = couponRecordInfo.ChemCloud_Coupon.CouponName,
                            CouponId    = couponRecordInfo.Id,
                            CouponPrice = couponRecordInfo.ChemCloud_Coupon.Price,
                            Type        = 0
                        };
                    }
                    else
                    {
                        shopCartItemModel.Coupon = new CouponModel()
                        {
                            CouponName  = shopBonusReceiveInfo.ChemCloud_ShopBonusGrant.ChemCloud_ShopBonus.Name,
                            CouponId    = shopBonusReceiveInfo.Id,
                            CouponPrice = shopBonusReceiveInfo.Price.Value,
                            Type        = 1
                        };
                    }
                }
                else if (detailToUse.Count() <= 0 && userCoupon.Count() <= 0)
                {
                    shopCartItemModel.Coupon = null;
                }
                else if (detailToUse.Count() <= 0 && userCoupon.Count() > 0)
                {
                    CouponRecordInfo couponRecordInfo1 = userCoupon.FirstOrDefault();
                    shopCartItemModel.Coupon = new CouponModel()
                    {
                        CouponName  = couponRecordInfo1.ChemCloud_Coupon.CouponName,
                        CouponId    = couponRecordInfo1.Id,
                        CouponPrice = couponRecordInfo1.ChemCloud_Coupon.Price,
                        Type        = 0
                    };
                }
                else if (detailToUse.Count() > 0 && userCoupon.Count() <= 0)
                {
                    ShopBonusReceiveInfo shopBonusReceiveInfo1 = detailToUse.FirstOrDefault();
                    shopCartItemModel.Coupon = new CouponModel()
                    {
                        CouponName  = shopBonusReceiveInfo1.ChemCloud_ShopBonusGrant.ChemCloud_ShopBonus.Name,
                        CouponId    = shopBonusReceiveInfo1.Id,
                        CouponPrice = shopBonusReceiveInfo1.Price.Value,
                        Type        = 1
                    };
                }
                decimal num4        = shopCartItemModel.CartItemModels.Sum <CartItemModel>((CartItemModel d) => d.price * d.count);
                decimal num5        = num4 - (shopCartItemModel.Coupon == null ? new decimal(0) : shopCartItemModel.Coupon.CouponPrice);
                decimal freeFreight = shopService.GetShop(shopCartItemModel.shopId, false).FreeFreight;
                shopCartItemModel.isFreeFreight = false;
                if (freeFreight > new decimal(0))
                {
                    shopCartItemModel.shopFreeFreight = freeFreight;
                    if (num5 >= freeFreight)
                    {
                        shopCartItemModel.Freight       = new decimal(0);
                        shopCartItemModel.isFreeFreight = true;
                    }
                }
                shopCartItemModels.Add(shopCartItemModel);
            }
            decimal num6 = (
                from a in shopCartItemModels
                where a.Coupon != null
                select a).Sum <ShopCartItemModel>((ShopCartItemModel b) => b.Coupon.CouponPrice);

            ViewBag.products         = shopCartItemModels;
            base.ViewBag.totalAmount = list.Sum <CartItemModel>((CartItemModel item) => item.price * item.count);
            base.ViewBag.Freight     = shopCartItemModels.Sum <ShopCartItemModel>((ShopCartItemModel a) => a.Freight);
            dynamic viewBag = base.ViewBag;
            dynamic obj     = ViewBag.totalAmount;

            viewBag.orderAmount = obj + ViewBag.Freight - num6;
            IMemberIntegralService memberIntegralService = ServiceHelper.Create <IMemberIntegralService>();
            MemberIntegral         memberIntegral        = memberIntegralService.GetMemberIntegral(base.CurrentUser.Id);
            int num7 = (memberIntegral == null ? 0 : memberIntegral.AvailableIntegrals);

            ViewBag.userIntegrals      = num7;
            ViewBag.integralPerMoney   = 0;
            ViewBag.memberIntegralInfo = memberIntegral;
            MemberIntegralExchangeRules integralChangeRule = memberIntegralService.GetIntegralChangeRule();
            decimal viewBag1 = new decimal(0);
            decimal viewBag2 = new decimal(0);

            if (integralChangeRule == null || integralChangeRule.IntegralPerMoney <= 0)
            {
                viewBag1 = new decimal(0);
                viewBag2 = new decimal(0);
            }
            else
            {
                if (ViewBag.totalAmount - num6 - Math.Round((decimal)num7 / integralChangeRule.IntegralPerMoney, 2) <= 0)
                {
                    viewBag1 = Math.Round(ViewBag.totalAmount - num6, 2);
                    viewBag2 = Math.Round((ViewBag.totalAmount - num6) * integralChangeRule.IntegralPerMoney);
                }
                else
                {
                    viewBag1 = Math.Round((decimal)num7 / integralChangeRule.IntegralPerMoney, 2);
                    viewBag2 = num7;
                }
                if (viewBag1 <= new decimal(0))
                {
                    viewBag1 = new decimal(0);
                    viewBag2 = new decimal(0);
                }
            }
            ViewBag.integralPerMoney = viewBag1;
            ViewBag.userIntegrals    = viewBag2;
        }
示例#6
0
        public long GenerateBonusDetail(ShopBonusInfo model, long createUserid, long orderid, string receiveurl)
        {
            if (model.DateEnd <= DateTime.Now || model.IsInvalid)
            {
                Log.Info(string.Concat("此活动已过期 , shopid = ", model.ShopId));
                return(0);
            }
            if (model.DateStart > DateTime.Now)
            {
                Log.Info(string.Concat("此活动未开始 , shopid = ", model.ShopId));
                return(0);
            }
            ShopBonusGrantInfo shopBonusGrantInfo = null;

            try
            {
                shopBonusGrantInfo = (
                    from p in context.ShopBonusGrantInfo
                    where p.OrderId == orderid
                    select p).FirstOrDefault();
                if (!context.ShopBonusGrantInfo.Exist <ShopBonusGrantInfo>((ShopBonusGrantInfo p) => p.OrderId == orderid))
                {
                    shopBonusGrantInfo = new ShopBonusGrantInfo()
                    {
                        ShopBonusId = model.Id,
                        UserId      = createUserid,
                        OrderId     = orderid,
                        BonusQR     = ""
                    };
                    shopBonusGrantInfo = context.ShopBonusGrantInfo.Add(shopBonusGrantInfo);
                    context.SaveChanges();
                    long   id  = shopBonusGrantInfo.Id;
                    string str = GenerateQR(Path.Combine(receiveurl, id.ToString()));
                    shopBonusGrantInfo.BonusQR = str;
                    List <ShopBonusReceiveInfo> shopBonusReceiveInfos = new List <ShopBonusReceiveInfo>();
                    for (int i = 0; i < model.Count; i++)
                    {
                        decimal num = GenerateRandomAmountPrice(model.RandomAmountStart, model.RandomAmountEnd);
                        ShopBonusReceiveInfo shopBonusReceiveInfo = new ShopBonusReceiveInfo()
                        {
                            BonusGrantId = shopBonusGrantInfo.Id,
                            Price        = new decimal?(num),
                            OpenId       = null,
                            State        = ShopBonusReceiveInfo.ReceiveState.NotUse
                        };
                        shopBonusReceiveInfos.Add(shopBonusReceiveInfo);
                    }
                    context.ShopBonusReceiveInfo.AddRange(shopBonusReceiveInfos);
                    context.SaveChanges();
                }
                else
                {
                    Log.Info(string.Concat("此活动已存在防止多次添加 , shopid = ", model.ShopId));
                    return(shopBonusGrantInfo.Id);
                }
            }
            catch (Exception exception)
            {
                Log.Info("错误:", exception);
                context.ShopBonusReceiveInfo.OrderBy((ShopBonusReceiveInfo p) => p.ChemCloud_ShopBonusGrant.ShopBonusId == model.Id);
                context.ShopBonusGrantInfo.OrderBy((ShopBonusGrantInfo p) => p.ShopBonusId == model.Id);
                context.ShopBonusInfo.OrderBy((ShopBonusInfo p) => p.Id == model.Id);
                context.SaveChanges();
            }
            return(shopBonusGrantInfo.Id);
        }
示例#7
0
        public object Receive(long grantid, string openId, string wxhead, string wxname)
        {
            Log.Info(string.Format("Receive函数 = gid:{0} , oid:{1}", grantid, openId));
            if ((
                    from p in context.ShopBonusReceiveInfo
                    where (p.OpenId == openId) && p.BonusGrantId == grantid
                    select p).Count() > 0)
            {
                ShopReceiveModel shopReceiveModel = new ShopReceiveModel()
                {
                    State = ShopReceiveStatus.Receive,
                    Price = new decimal(0)
                };
                return(shopReceiveModel);
            }
            ShopBonusReceiveInfo nullable = (
                from p in context.ShopBonusReceiveInfo
                where p.BonusGrantId == grantid && string.IsNullOrEmpty(p.OpenId)
                select p).FirstOrDefault();

            if (nullable == null)
            {
                ShopReceiveModel shopReceiveModel1 = new ShopReceiveModel()
                {
                    State = ShopReceiveStatus.HaveNot,
                    Price = new decimal(0)
                };
                return(shopReceiveModel1);
            }
            if (nullable.ChemCloud_ShopBonusGrant.ChemCloud_ShopBonus.IsInvalid)
            {
                ShopReceiveModel shopReceiveModel2 = new ShopReceiveModel()
                {
                    State = ShopReceiveStatus.Invalid,
                    Price = new decimal(0)
                };
                return(shopReceiveModel2);
            }
            MemberOpenIdInfo memberOpenIdInfo = (
                from p in context.MemberOpenIdInfo
                where p.OpenId == openId
                select p).FirstOrDefault();
            MemberOpenIdInfo memberOpenIdInfo1 = memberOpenIdInfo;
            MemberOpenIdInfo memberOpenIdInfo2 = memberOpenIdInfo;

            memberOpenIdInfo2 = memberOpenIdInfo1;
            if (memberOpenIdInfo2 != null)
            {
                nullable.UserId = new long?(memberOpenIdInfo2.UserId);
            }
            nullable.OpenId      = openId;
            nullable.ReceiveTime = new DateTime?(DateTime.Now);
            nullable.WXHead      = wxhead;
            nullable.WXName      = wxname;
            context.SaveChanges();
            if (memberOpenIdInfo2 == null)
            {
                ShopReceiveModel shopReceiveModel3 = new ShopReceiveModel()
                {
                    State = ShopReceiveStatus.CanReceiveNotUser,
                    Price = nullable.Price.Value,
                    Id    = nullable.Id
                };
                return(shopReceiveModel3);
            }
            string str = (
                from p in context.UserMemberInfo
                where p.Id == memberOpenIdInfo2.UserId
                select p.UserName).FirstOrDefault();
            ShopReceiveModel shopReceiveModel4 = new ShopReceiveModel()
            {
                State    = ShopReceiveStatus.CanReceive,
                Price    = nullable.Price.Value,
                UserName = str,
                Id       = nullable.Id
            };

            return(shopReceiveModel4);
        }
        /// <summary>
        /// 生成红包详情
        /// </summary>
        public long GenerateBonusDetail(ShopBonusInfo model, long orderid, string receiveurl)
        {
            if (model.DateEnd <= DateTime.Now || model.IsInvalid)   //过期、失效
            {
                Log.Info("此活动已过期 , shopid = " + model.ShopId);
                return(0);
            }
            else if (model.DateStart > DateTime.Now)  // 未开始
            {
                Log.Info("此活动未开始 , shopid = " + model.ShopId);
                return(0);
            }

            ShopBonusGrantInfo grant = null;

            try
            {
                var order = Context.OrderInfo.Where(r => r.Id == orderid).FirstOrDefault();

                grant = Context.ShopBonusGrantInfo.Where(p => p.OrderId == orderid).FirstOrDefault();
                if (Context.ShopBonusGrantInfo.Exist((p => p.OrderId == orderid)))
                {
                    Log.Info("此活动已存在防止多次添加 , shopid = " + model.ShopId);
                    return(grant.Id);
                }
                grant             = new ShopBonusGrantInfo();
                grant.ShopBonusId = model.Id;
                grant.UserId      = order.UserId;
                grant.OrderId     = orderid;
                grant.BonusQR     = "";
                grant             = Context.ShopBonusGrantInfo.Add(grant);
                Context.SaveChanges();

                string path = GenerateQR(Path.Combine(receiveurl, grant.Id.ToString()));
                grant.BonusQR = path;

                List <ShopBonusReceiveInfo> list = new List <ShopBonusReceiveInfo>();
                for (int i = 0; i < model.Count; i++)
                {
                    decimal randPrice           = GenerateRandomAmountPrice(model.RandomAmountStart, model.RandomAmountEnd);
                    ShopBonusReceiveInfo detail = new ShopBonusReceiveInfo
                    {
                        BonusGrantId = grant.Id,
                        Price        = randPrice,
                        OpenId       = null,
                        State        = ShopBonusReceiveInfo.ReceiveState.NotUse
                    };
                    list.Add(detail);
                }
                Context.ShopBonusReceiveInfo.AddRange(list);
                Context.SaveChanges();
            }
            catch (Exception e)
            {
                Log.Info("错误:", e);
                Context.ShopBonusReceiveInfo.Remove(p => p.Himall_ShopBonusGrant.ShopBonusId == model.Id);
                Context.ShopBonusGrantInfo.Remove(p => p.ShopBonusId == model.Id);
                Context.ShopBonusInfo.Remove(p => p.Id == model.Id);
                Context.SaveChanges();
            }
            return(grant.Id);
        }