Пример #1
0
        protected void btnAddCoupon_OnClick(object sender, EventArgs e)
        {
            if (Session["YeUser"] == null)
            {
                WebUtil.AlertAndRedirect("Please login first,then get the coupon!", "UserLogin.aspx");
                return;
            }
            var user = (Ye_User)Session["YeUser"];

            //TODO:确定优惠券规则,使用一次还是使用多次
            if (UserCouponBll.ExistsShopCoupon(user.UserID, YeShopCoupon.CouponID))
            {
                WebUtil.AlertAndReload("You have got the coupon.");
            }
            else
            {
                if (UserCouponBll.AddShopCoupon4User(new Ye_UserCoupon()
                {
                    ShopId = VisitingShop.ShopID,
                    CouponId = YeShopCoupon.CouponID,
                    IsUsed = false,
                    UserId = user.UserID
                }))
                {
                    WebUtil.AlertAndReload("Get the coupon successfully.");
                }
                else
                {
                    WebUtil.AlertAndReload("Failed to get the coupon.");
                }
            }
        }
Пример #2
0
        public void ProcessRequest(HttpContext context)
        {
            var userid = context.Request.Params["userid"];
            var shopid = context.Request.Params["shopid"];
            var code   = context.Request.Params["code"];

            context.Response.ContentType = "text/json";
            if (userid == null || shopid == null || code == null)
            {
                context.Response.Write(JsonConvert.ToString(new { code = 0 }));
            }
            else
            {
                var sid         = Convert.ToInt32(shopid);
                var userCoupons =
                    UserCouponBll.GetUserCouponsByUserId(Convert.ToInt32(userid))
                    .Where(p => p.IsUsed == false && p.IsUserDeleted == false && p.ShopId == sid)
                    .ToArray();
                var shopCoupon = ShopCouponBll.GetShopCouponsByShopId(sid).SingleOrDefault(p => p.CouponCode == code);
                if (shopCoupon != null && userCoupons.Count(p => p.CouponId == shopCoupon.CouponID) > 0)
                {
                    context.Response.Write(JsonConvert.SerializeObject(new { code = 1, dollor = shopCoupon.UnitCost }));
                }
                else
                {
                    context.Response.Write(JsonConvert.ToString(new { code = 0 }));
                }
            }
        }
Пример #3
0
        //提交订单
        protected void btnOK_OnClick(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(tbxReceiver.Text))
            {
                WebUtil.Alert("请输入收货人!");
                return;
            }
            if (string.IsNullOrWhiteSpace(tbxAddress.Text))
            {
                WebUtil.Alert("请输入收货地址!");
                return;
            }
            if (string.IsNullOrWhiteSpace(tbxMobile.Text))
            {
                WebUtil.Alert("请输入收货人地址!");
                return;
            }
            if (Convert.ToDecimal(hfTotalPrice.Value) <= 0)
            {
                WebUtil.Alert("请先选好数量!");
                return;
            }
            //订单信息
            var order = new Ye_Order()
            {
                UserID          = YeUser.UserID,
                ShopID          = OrderingShop.ShopID,
                OrderSN         = lblOrderSN.Text,
                OrderDesc       = tbxOrderDesc.Text,
                OrderCreateTime = DateTime.Now,
                OrderCheckTime  = null,
                OrderPayTime    = null,
                IsUserDeleted   = false,
                IsShopDeleted   = false,
                Receiver        = tbxReceiver.Text,
                ReceiveAddress  = tbxAddress.Text,
                ReceiverMobile  = tbxMobile.Text,
                TotalPrice      = Convert.ToDecimal(hfTotalPrice.Value),
                Tax             = Convert.ToDecimal(hfFax.Value),
                OrderStatus     = (int)OrderStatus.已下单
            };

            if (!string.IsNullOrWhiteSpace(tbxCode.Text))
            {
                var coupon = ShopCouponBll.GetShopCouponsByShopId(OrderingShop.ShopID)
                             .SingleOrDefault(
                    s => s.BeginDate <DateTime.Now && s.EndDate> DateTime.Now && s.CouponCode == tbxCode.Text);
                if (coupon == null)
                {
                    WebUtil.Alert("优惠券验证码无效!");
                    return;
                }
                else
                {
                    var userCoupon =
                        UserCouponBll.GetUserCouponsByUserId(YeUser.UserID)
                        .SingleOrDefault(p => p.CouponId == coupon.CouponID);
                    if (userCoupon == null)
                    {
                        WebUtil.Alert("您没有该验证码的使用权限!");
                        return;
                    }
                    else
                    {
                        if (userCoupon.IsUsed)
                        {
                            WebUtil.Alert("该验证码已被使用作废!");
                            return;
                        }
                        else
                        {
                            UserCouponBll.UseCoupon(YeUser.UserID, userCoupon.UserCouponId);
                            order.ShopCouponID   = coupon.CouponID;
                            order.UnitCouponCost = coupon.UnitCost;
                        }
                    }
                }
                //
            }
            var orderDetails = new List <Ye_OrderDetail>();//获取订单详情

            rptProduct.Controls.OfType <RepeaterItem>().ToList().ForEach(p =>
            {
                var lbl = p.FindControl("lblAmount") as Label;
                var hf  = p.FindControl("hfAmount") as HiddenField;
                orderDetails.Add(new Ye_OrderDetail()
                {
                    ProductID = Convert.ToInt32(lbl.Attributes["data-pid"]),
                    Quantity  = Convert.ToInt32(hf.Value),
                    UnitCost  = Convert.ToDecimal(lbl.Attributes["data-unitcost"])
                });
            });
            if (OrderBll.AddOrder(order, orderDetails))
            {
                Response.Cookies["shop_" + OrderingShop.ShopID.ToString()].Expires = DateTime.Now.AddDays(-1);//清空Cookie信息
                //WebUtil.AlertAndRedirect("您的订单已提交,请等候我们的回复!","ShopDetail.aspx?shopid="+OrderingShop.ShopID);
                WebUtil.AlertAndRedirect("您的订单已提交,请等候我们的回复!", "UserOrders.aspx");
            }
        }