Exemplo n.º 1
0
        public ActionResult GetBirthdayCoupon()
        {
            int count      = 0;
            var couponlist = CouponBLL.SearchList(1, 1, new CouponSearchInfo {
                Type = (int)CouponKind.BirthdayGet, CanUse = 1
            }, ref count);

            //如果有进行中的生日礼券,并且 用户本年度未领取生日礼券
            if (couponlist.Count > 0 && (user.HasBirthdayCoupon == 0 || (user.HasBirthdayCoupon != 0 && user.GetBirthdayCouponDate.Year != DateTime.Now.Year)))
            {
                UserCouponInfo userCoupon = UserCouponBLL.ReadLast(couponlist[0].Id);
                if (UserCouponBLL.UniqueUserCatch(user.Id, couponlist[0].Id))
                {
                    int startNumber = 0;
                    if (userCoupon.Id > 0)
                    {
                        string tempNumber = userCoupon.Number.Substring(3, 5);
                        while (tempNumber.Substring(0, 1) == "0")
                        {
                            tempNumber = tempNumber.Substring(1);
                        }
                        startNumber = Convert.ToInt32(tempNumber);
                    }
                    startNumber++;
                    int cpid = UserCouponBLL.Add(new UserCouponInfo
                    {
                        UserId   = user.Id,
                        UserName = user.UserName,
                        CouponId = couponlist[0].Id,
                        GetType  = (int)CouponType.CatchByUser,
                        Number   = ShopCommon.CreateCouponNo(couponlist[0].Id, startNumber),
                        Password = ShopCommon.CreateCouponPassword(startNumber),
                        IsUse    = (int)BoolType.False,
                        OrderId  = 0
                    });
                    //领取成功改变user表标识
                    if (cpid > 0)
                    {
                        Dictionary <string, object> dict = new Dictionary <string, object>();
                        dict.Add("[HasBirthdayCoupon]", 1);
                        dict.Add("[GetBirthdayCouponDate]", DateTime.Now);
                        UserBLL.UpdatePart("[usr]", dict, user.Id);
                        return(Json(new { ok = true }));
                    }
                    return(Json(new { ok = false, msg = "领取失败,请稍后重试" }));
                }
                else
                {
                    return(Json(new { ok = false, msg = "领取失败,您已领取过生日礼券" }));
                }
            }
            else
            {
                return(Json(new { ok = false, msg = "活动暂停或者您已领取过生日礼券" }));
            }
        }
Exemplo n.º 2
0
        public ActionResult GetCouponByUser()
        {
            int couponId = RequestHelper.GetForm <int>("couponId");

            if (uid > 0 && couponId > 0)
            {
                CouponInfo coupon = CouponBLL.Read(couponId);
                if (UserCouponBLL.UniqueUserCatch(uid, couponId))
                {
                    if (coupon.TotalCount - 1 < coupon.UsedCount)
                    {
                        return(Json(new { ok = false, msg = "优惠券余量不足" }));
                    }
                    UserCouponInfo userCoupon  = UserCouponBLL.ReadLast(couponId);
                    int            startNumber = 0;
                    if (userCoupon.Id > 0)
                    {
                        string tempNumber = userCoupon.Number.Substring(3, 5);
                        while (tempNumber.Substring(0, 1) == "0")
                        {
                            tempNumber = tempNumber.Substring(1);
                        }
                        startNumber = Convert.ToInt32(tempNumber);
                    }
                    startNumber++;
                    UserCouponInfo tmpCoupon = new UserCouponInfo();
                    tmpCoupon.CouponId = couponId;
                    tmpCoupon.GetType  = (int)CouponType.CatchByUser;
                    tmpCoupon.Number   = ShopCommon.CreateCouponNo(couponId, startNumber);
                    tmpCoupon.Password = ShopCommon.CreateCouponPassword(startNumber);
                    tmpCoupon.IsUse    = (int)BoolType.False;
                    tmpCoupon.OrderId  = 0;
                    tmpCoupon.UserId   = uid;
                    tmpCoupon.UserName = user.UserName;
                    if (UserCouponBLL.Add(tmpCoupon) > 0)
                    {//如果领取成功,增加优惠券的发放(领取)量
                        coupon.UsedCount++;
                        Dictionary <string, object> dict = new Dictionary <string, object>();
                        dict.Add("[UsedCount]", coupon.UsedCount);
                        CouponBLL.UpdatePart("[Coupon]", dict, coupon.Id);
                    }
                    return(Json(new { ok = true, msg = "领券成功" }));
                }
                else
                {
                    return(Json(new { ok = false, msg = "您已领过此优惠券" }));
                }
            }
            else
            {
                return(Json(new { ok = false, msg = "请先登录" }));
            }
        }
Exemplo n.º 3
0
 /// <summary>
 /// 生成线下优惠券
 /// </summary>
 private void CreateOfflineCoupon(int couponID, int sendCount, ref int startNumber)
 {
     if (sendCount > 0)
     {
         for (int i = 0; i < sendCount; i++)
         {
             startNumber++;
             UserCouponInfo userCoupon = new UserCouponInfo();
             userCoupon.CouponId = couponID;
             userCoupon.GetType  = (int)CouponType.Offline;
             userCoupon.Number   = ShopCommon.CreateCouponNo(couponID, startNumber);
             userCoupon.Password = ShopCommon.CreateCouponPassword(startNumber);
             userCoupon.IsUse    = (int)BoolType.False;
             userCoupon.OrderId  = 0;
             userCoupon.UserId   = 0;
             userCoupon.UserName = string.Empty;
             UserCouponBLL.Add(userCoupon);
         }
     }
 }
Exemplo n.º 4
0
 /// <summary>
 /// 生成按用户发放的优惠券
 /// </summary>
 private void SeandUserCoupon(int couponID, string sendUser, ref int startNumber)
 {
     if (sendUser != string.Empty)
     {
         foreach (string user in sendUser.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
         {
             startNumber++;
             int            userID     = Convert.ToInt32(user.Split('|')[0]);
             string         userName   = user.Split('|')[1];
             UserCouponInfo userCoupon = new UserCouponInfo();
             userCoupon.CouponId = couponID;
             userCoupon.GetType  = (int)CouponType.Online;
             userCoupon.Number   = ShopCommon.CreateCouponNo(couponID, startNumber);
             userCoupon.Password = ShopCommon.CreateCouponPassword(startNumber);
             userCoupon.IsUse    = (int)BoolType.False;
             userCoupon.OrderId  = 0;
             userCoupon.UserId   = userID;
             userCoupon.UserName = userName;
             UserCouponBLL.Add(userCoupon);
         }
     }
 }
Exemplo n.º 5
0
        public ActionResult Index()
        {
            int[] arrT = new int[5];
            //检查用户的待付款订单是否超时失效,超时则更新为失效状态
            OrderBLL.CheckOrderPayTime(user.Id);
            //订单自动收货
            OrderBLL.CheckOrderRecieveTimeProg(user.Id);

            OrderSearchInfo orderSearch = new OrderSearchInfo();

            orderSearch.OrderStatus = (int)(OrderStatus.WaitPay);
            orderSearch.UserId      = uid;
            orderSearch.IsDelete    = 0;
            arrT[0] = OrderBLL.SearchList(orderSearch).Count;
            orderSearch.OrderStatus = (int)(OrderStatus.WaitCheck);
            orderSearch.UserId      = uid;
            orderSearch.IsDelete    = 0;
            //待审核
            var orderList = OrderBLL.SearchList(orderSearch);

            arrT[1] = orderList.Count;
            #region 待分享
            var list1     = orderList.Where(k => k.IsActivity == (int)OrderKind.GroupBuy && k.FavorableActivityId > 0);
            var groupIds  = list1.Select(k => k.FavorableActivityId).ToArray();
            var groupList = GroupBuyBLL.ReadList(groupIds).Where(k => k.StartTime <= DateTime.Now && k.EndTime >= DateTime.Now && k.Quantity > k.SignCount);
            var ids       = groupList.Select(k => k.Id);
            var list2     = list1.Where(k => ids.Contains(k.FavorableActivityId));
            arrT[4] = list2.Count();
            #endregion

            orderSearch.OrderStatus = (int)(OrderStatus.HasShipping);
            orderSearch.UserId      = uid;
            orderSearch.IsDelete    = 0;
            arrT[2] = OrderBLL.SearchList(orderSearch).Count;
            orderSearch.OrderStatus = (int)(OrderStatus.ReceiveShipping);
            orderSearch.UserId      = uid;
            orderSearch.IsDelete    = 0;
            arrT[3] = OrderBLL.SearchList(orderSearch).Count;
            //是否填写手机号
            bool hasMobile = !string.IsNullOrEmpty(user.Mobile.Trim());
            #region 生日前后5天登录会员中心,自动发放本年度生日礼券。( 是否获取生日优惠券,本年生日前后5天出现提示)
            //判断是否能够获取本年度生日礼券
            bool     canGetBirthdayCoupon = true;
            DateTime birthday             = DateTime.MinValue;
            //如果用户已填写生日,则在生日前后5天提示领取生日礼券
            if (DateTime.TryParse(user.Birthday, out birthday) && (birthday.AddDays(-5).Month == DateTime.Now.Month && birthday.AddDays(-5).Day <= DateTime.Now.Day) && (birthday.AddDays(5).Month == DateTime.Now.Month && birthday.AddDays(5).Day >= DateTime.Now.Day))
            {
                int count      = 0;
                var couponlist = CouponBLL.SearchList(1, 1, new CouponSearchInfo {
                    Type = (int)CouponKind.BirthdayGet, CanUse = 1
                }, ref count);
                //如果有生日礼券活动进行中
                if (couponlist.Count > 0)
                {
                    ////如果本年度已获取,则不能再获取
                    //if (user.HasBirthdayCoupon != 0 && user.GetBirthdayCouponDate.Year == DateTime.Now.Year) canGetBirthdayCoupon = false;
                    #region 自动发放,每年度限领1次
                    if (user.HasBirthdayCoupon == 0 || (user.HasBirthdayCoupon != 0 && user.GetBirthdayCouponDate.Year != DateTime.Now.Year))
                    {
                        UserCouponInfo userCoupon = UserCouponBLL.ReadLast(couponlist[0].Id);
                        if (UserCouponBLL.UniqueUserCatch(user.Id, couponlist[0].Id))
                        {
                            int startNumber = 0;
                            if (userCoupon.Id > 0)
                            {
                                string tempNumber = userCoupon.Number.Substring(3, 5);
                                while (tempNumber.Substring(0, 1) == "0")
                                {
                                    tempNumber = tempNumber.Substring(1);
                                }
                                startNumber = Convert.ToInt32(tempNumber);
                            }
                            startNumber++;
                            int cpid = UserCouponBLL.Add(new UserCouponInfo
                            {
                                UserId   = user.Id,
                                UserName = user.UserName,
                                CouponId = couponlist[0].Id,
                                GetType  = (int)CouponType.BirthdayGet,
                                Number   = ShopCommon.CreateCouponNo(couponlist[0].Id, startNumber),
                                Password = ShopCommon.CreateCouponPassword(startNumber),
                                IsUse    = (int)BoolType.False,
                                OrderId  = 0
                            });
                            //领取成功改变user表标识
                            if (cpid > 0)
                            {
                                Dictionary <string, object> dict = new Dictionary <string, object>();
                                dict.Add("[HasBirthdayCoupon]", 1);
                                dict.Add("[GetBirthdayCouponDate]", DateTime.Now);
                                UserBLL.UpdatePart("[usr]", dict, user.Id);
                                //user对应的未使用优惠券数量加1
                                user.CouPonLeft++;
                            }
                        }
                    }
                    #endregion
                }
                else
                {
                    //如果商家后台没有设置正在进行中的会员生日券,则不能获取
                    canGetBirthdayCoupon = false;
                }
            }
            else
            {
                canGetBirthdayCoupon = false;
            }
            #endregion
            //计算是否
            return(Json(new { ordercount = arrT, hasmobile = hasMobile, usergrade = userGradeInfo, cangetbirthdaycoupon = canGetBirthdayCoupon, couponleft = user.CouPonLeft, pointleft = user.PointLeft }, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 6
0
        /// <summary>
        /// 完成确认按钮点击方法
        /// </summary>
        protected void ReceivedButton_Click(object sender, EventArgs e)
        {
            OrderInfo order = ButtoStart();

            #region 确认收货赠送优惠券
            int count      = 0;
            var couponlist = CouponBLL.SearchList(1, 1, new CouponSearchInfo {
                Type = (int)CouponKind.ReceiveShippingGet, CanUse = 1
            }, ref count);
            if (couponlist.Count > 0)
            {
                UserCouponInfo userCoupon  = UserCouponBLL.ReadLast(couponlist[0].Id);
                int            startNumber = 0;
                if (userCoupon.Id > 0)
                {
                    string tempNumber = userCoupon.Number.Substring(3, 5);
                    while (tempNumber.Substring(0, 1) == "0")
                    {
                        tempNumber = tempNumber.Substring(1);
                    }
                    startNumber = Convert.ToInt32(tempNumber);
                }
                startNumber++;
                UserCouponBLL.Add(new UserCouponInfo
                {
                    UserId   = order.UserId,
                    UserName = order.UserName,
                    CouponId = couponlist[0].Id,
                    GetType  = (int)CouponType.ReceiveShippingGet,
                    Number   = ShopCommon.CreateCouponNo(couponlist[0].Id, startNumber),
                    Password = ShopCommon.CreateCouponPassword(startNumber),
                    IsUse    = (int)BoolType.False,
                    OrderId  = 0
                });
            }
            #endregion
            #region 赠送积分
            //赠送积分--根据商品信息填写的赠送积分额度
            //int sendPoint = OrderBLL.ReadOrderSendPoint(order.Id);
            //根据订单付款金额全额返还积分
            int sendPoint = (int)Math.Floor(OrderBLL.ReadNoPayMoney(order));
            if (sendPoint > 0 && order.IsActivity == (int)BoolType.False)
            {
                var accountRecord = new UserAccountRecordInfo
                {
                    RecordType = (int)AccountRecordType.Point,
                    Money      = 0,
                    Point      = sendPoint,
                    Date       = DateTime.Now,
                    IP         = ClientHelper.IP,
                    Note       = ShopLanguage.ReadLanguage("OrderReceived").Replace("$OrderNumber", order.OrderNumber),
                    UserId     = order.UserId,
                    UserName   = order.UserName
                };
                UserAccountRecordBLL.Add(accountRecord);
            }
            #endregion
            #region 确认收货给分销商返佣
            //订单实际支付金额
            decimal paid_money = OrderBLL.ReadNoPayMoney(order);
            //购买人
            var user = UserBLL.Read(order.UserId);
            //购买者有推荐人 且 实际支付金额大于0才进行返佣
            if (user.Recommend_UserId > 0 && paid_money > 0)
            {
                RebateBLL.RebateToDistributor(user, paid_money, order.Id);
            }
            #endregion
            int startOrderStatus = order.OrderStatus;
            order.OrderStatus = (int)OrderStatus.ReceiveShipping;
            ButtonEnd(order, Note.Text, OrderOperate.Received, startOrderStatus);
        }
Exemplo n.º 7
0
        public JsonResult CouponRegister(int userId, int couponId)
        {
            try
            {
                UserInfo   user   = UserBLL.Read(userId);
                CouponInfo coupon = CouponBLL.Read(couponId);
                if (user == null || user.Id <= 0 || coupon.Id <= 0)
                {
                    return(Json(new { ok = false, error = "未登录或登录失效", code = -1 }));
                }

                if (UserCouponBLL.UniqueUserCatch(user.Id, couponId))
                {
                    //新人券暂时不限制总数
                    //if (coupon.TotalCount - 1 < coupon.UsedCount)
                    //{
                    //    return Json(new { ok = false, msg = "优惠券余量不足" });
                    //}
                    UserCouponInfo userCoupon  = UserCouponBLL.ReadLast(couponId);
                    int            startNumber = 0;
                    if (userCoupon.Id > 0)
                    {
                        string tempNumber = userCoupon.Number.Substring(3, 5);
                        while (tempNumber.Substring(0, 1) == "0")
                        {
                            tempNumber = tempNumber.Substring(1);
                        }
                        startNumber = Convert.ToInt32(tempNumber);
                    }
                    startNumber++;
                    UserCouponInfo tmpCoupon = new UserCouponInfo();
                    tmpCoupon.CouponId = couponId;
                    tmpCoupon.GetType  = (int)CouponType.RegisterGet;
                    tmpCoupon.Number   = ShopCommon.CreateCouponNo(couponId, startNumber);
                    tmpCoupon.Password = ShopCommon.CreateCouponPassword(startNumber);
                    tmpCoupon.IsUse    = (int)BoolType.False;
                    tmpCoupon.OrderId  = 0;
                    tmpCoupon.UserId   = user.Id;
                    tmpCoupon.UserName = user.UserName;
                    if (UserCouponBLL.Add(tmpCoupon) > 0)
                    {//如果领取成功,增加优惠券的发放(领取)量
                        coupon.UsedCount++;
                        Dictionary <string, object> dict = new Dictionary <string, object>();
                        dict.Add("[UsedCount]", coupon.UsedCount);
                        CouponBLL.UpdatePart("[Coupon]", dict, coupon.Id);
                        //该变用户标识:已领过新人券
                        dict = new Dictionary <string, object>();
                        dict.Add("[HasRegisterCoupon]", 1);
                        UserBLL.UpdatePart("[usr]", dict, userId);
                    }
                    return(Json(new { ok = true, error = "领券成功" }));
                }
                else
                {
                    //该变用户标识:已领过新人券
                    Dictionary <string, object> dict = new Dictionary <string, object>();
                    dict.Add("[HasRegisterCoupon]", 1);
                    UserBLL.UpdatePart("[usr]", dict, userId);
                    return(Json(new { ok = false, error = "您已领过", code = 0 }));
                }
            }
            catch (Exception ex)
            {
                return(Json(new { ok = false, error = "系统忙", code = 0 }));
            }
        }