Ejemplo n.º 1
0
        public ActionResult RatingOrder(string OrderGuid, int?OrderStatus, string Description)
        {
            shOrderService _order = new shOrderService();
            shOrder        order  = _order.FindByKey(OrderGuid);

            OrderStatus = C.Core.Common.OrderStatus.DaGiaoHang_DaXacNhan.GetHashCode();

            string MemberGuid = null;

            if (User.Identity.GetMemberLogin() != null)
            {
                MemberGuid = User.Identity.GetMemberLogin().MemberGuid;
            }
            shOrderHistoryService _orderHistory = new shOrderHistoryService();
            shOrderHistory        orderHistory  = _orderHistory.Insert_Update(
                null,
                order.OrderGuid,
                OrderStatus,
                MemberGuid,
                Description,
                null,
                true,
                DateTime.Now);

            order.OrderStatus = OrderStatus;
            _order.Update(order);

            if (Request.IsAjaxRequest())
            {
                return(Json("OK", JsonRequestBehavior.AllowGet));
            }

            return(RedirectToAction("Index"));
        }
Ejemplo n.º 2
0
        public ActionResult Order(int?p, int?pay_type, string City, string Town, string order_name, string order_address, string order_phone, string order_email, string base_remark)
        {
            using (var context = new ShopOnlineDb())
            {
                using (var dbContextTransaction = context.Database.BeginTransaction())
                {
                    try
                    {
                        #region Get Infor login
                        string MemberGuid   = string.Empty;
                        bool   isCoTaiKhoan = false;

                        if (string.IsNullOrEmpty(User.Identity.GetMemberLogin().MemberGuid) ||
                            string.IsNullOrWhiteSpace(User.Identity.GetMemberLogin().MemberGuid))
                        {
                            //return Redirect("/dang-nhap?urlPrefix=/gio-hang");
                            isCoTaiKhoan = false;
                        }
                        else
                        {
                            isCoTaiKhoan = true;
                            MemberGuid   = User.Identity.GetMemberLogin().MemberGuid;
                        }

                        var cart = Session[CartSession];
                        if (cart == null)
                        {
                            TempData["Cart"] = "Giỏ hàng trống. Vui lòng thao tác lại.";
                            return(Redirect("/gio-hang"));
                        }

                        cart = cart as List <CartItem>;
                        shSizeService _size = new shSizeService();
                        decimal       price = _size.ListProductPrice_Quantity(cart as List <CartItem>, 0, 0, 0);

                        decimal Feeship = Config.FeeShip;
                        if (price > Config.FeeTotal)
                        {
                            Feeship = 0;
                        }

                        int _Status = OrderStatus.DangXuLy.GetHashCode();

                        shOrderService _order = new shOrderService();
                        #endregion

                        #region Tìm nhân viên random được chọn xử lý đơn hàng
                        // ds nhân viên được phân xử lý đơn hàng
                        qtUser        UserId             = new qtUser();
                        List <qtUser> dsUser_XuLyDonhang = CommonHelper.GetUserTheoMaCauHinhHeThong_GetTheoUser(Config.TAI_KHOAN_NHAN_DON_HANG, Units.ChiNhanhShowRoom.GetHashCode()).ToList();

                        int userid_dagiaoviec         = 0;
                        IEnumerable <shOrder> dsOrder = _order.DanhSachOrder()
                                                        .Where(x => x.UserId != null && x.UserId != 0)
                                                        .OrderByDescending(x => x.OrderId);

                        foreach (var item in dsOrder)
                        {
                            if (item.UserId != null && item.UserId != 0)
                            {
                                userid_dagiaoviec = item.UserId.Value;
                                break;
                            }
                        }

                        for (int i = 0; i < dsUser_XuLyDonhang.Count(); i++)
                        {
                            qtUser user = dsUser_XuLyDonhang[i];

                            if (user.UserId == userid_dagiaoviec)
                            {
                                if (i == (dsUser_XuLyDonhang.Count() - 1))
                                {
                                    UserId = dsUser_XuLyDonhang[0];
                                }
                                else if (i < (dsUser_XuLyDonhang.Count() - 1))
                                {
                                    UserId = dsUser_XuLyDonhang[i + 1];
                                }
                            }
                        }
                        #endregion

                        #region shOrder
                        shOrder order = _order.Insert_Update(
                            null,
                            null,
                            null,
                            MemberGuid,
                            order_name,
                            order_email,
                            order_phone,
                            order_address,
                            price,
                            _Status,
                            null,
                            TypeHelper.ToInt32(Town),
                            TypeHelper.ToInt32(City),
                            Feeship,
                            true,
                            DateTime.Now,
                            pay_type,
                            DateTime.Now,
                            UserId.UserId
                            );
                        #endregion

                        #region shOrderHistory
                        shOrderHistoryService _orderHistory = new shOrderHistoryService();
                        shOrderHistory        orderHistory  = _orderHistory.Insert_Update(
                            null,
                            order.OrderGuid,
                            _Status,
                            User.Identity.GetMemberLogin().MemberGuid,
                            "Đặt hàng",
                            null,
                            true,
                            DateTime.Now);

                        #endregion

                        #region shOrderDetail
                        shOrderDetailService _orderDetail = new shOrderDetailService();
                        price = 0;
                        decimal total = 0;
                        foreach (var item in cart as List <CartItem> )
                        {
                            price = _size.ProductPrice(item.SizeGuid);
                            total = price * item.Quantity;

                            _orderDetail.Insert_Update(
                                null,
                                null,
                                null,
                                order.OrderGuid,
                                MemberGuid,
                                item.Product.ProductGuid,
                                item.Product.ProductName,
                                item.SectionGuid,
                                item.SizeGuid,
                                item.Quantity,
                                price,
                                total,
                                true,
                                DateTime.Now,
                                DateTime.Now
                                );
                        }
                        #endregion

                        #region SEND EMAIL, MESSAGE
                        // 1. Gửi Email tới Quản trị viên xác nhận đơn hàng

                        /// ds User cấu hình nhận Email trong hệ thống
                        IEnumerable <qtUser> dsUser = CommonHelper.GetUserTheoMaCauHinhHeThong_GetTheoUser(Config.TAI_KHOAN_EMAIL_THONG_BAO_TIEP_NHAN_DON_HANG, Units.ChiNhanhShowRoom.GetHashCode());
                        string noidungdonhang       = EmailHelper.NoiDungDonHang(order, cart as List <CartItem>);
                        string noidungEmail         = string.Empty;
                        foreach (var user in dsUser)
                        {
                            noidungEmail = string.Empty;
                            qtUnitService _unit = new qtUnitService();
                            noidungEmail = EmailHelper.NoiDungMailThongBaoQuanTri(_unit.UnitName(Units.ChiNhanhShowRoom.GetHashCode()), 1, noidungdonhang);
                            EmailHelper.ThongBaoEmailDonHangMoi(user.Email, noidungEmail);
                        }

                        if (UserId.UserId > 0)
                        {
                            noidungEmail = string.Empty;
                            qtUnitService _unit = new qtUnitService();
                            noidungEmail = EmailHelper.NoiDungMailThongBaoQuanTri(_unit.UnitName(Units.ChiNhanhShowRoom.GetHashCode()), 1, noidungdonhang);
                            EmailHelper.ThongBaoEmailDonHangMoi(UserId.Email, noidungEmail);
                        }

                        // 2. Gửi Email xác nhận đơn hàng tới khách hàng
                        noidungEmail = "";
                        if (isCoTaiKhoan)
                        {
                            noidungEmail = EmailHelper.NoiDungMailThongBaoNguoiDatHang(noidungdonhang);
                            EmailHelper.ThongBaoEmailDonHangMoiToiNguoiDatHang(User.Identity.GetMemberLogin().Email, noidungEmail);
                        }
                        // 3. Gửi thông báo tới Quản trị viên nhận thông báo
                        ThongBaoService _thongbao = new ThongBaoService();
                        foreach (var user in dsUser)
                        {
                            int?Memberid = null;
                            if (isCoTaiKhoan)
                            {
                                Memberid = User.Identity.GetMemberLogin().MemberId;
                            }

                            _thongbao.InsertOrUpdate(
                                null,
                                "Thông báo đơn hàng mới. Người đặt hàng: " + order_name + ", giá trị: " + Format.FormatDecimalToString(price),
                                "Bạn có đơn hàng mới cần xử lý từ khách hàng: " + order_name +
                                " với đơn hàng tổng giá trị: " + Format.FormatDecimalToString(price) +
                                " lúc: " + DateTime.Now.ToString("dd/MM/yyyy HH:mm") +
                                ". Vui lòng truy cập hệ thống để xử lý",
                                "/DanhMuc/Order/Index/s=" + order.OrderGuid,
                                Memberid,
                                user.UserId,
                                DateTime.Now,
                                false,
                                Config.THONG_BAO_DON_HANG_MOI,
                                null
                                );
                        }

                        if (UserId.UserId > 0)
                        {
                            int?Memberid = null;
                            if (isCoTaiKhoan)
                            {
                                Memberid = User.Identity.GetMemberLogin().MemberId;
                            }

                            _thongbao.InsertOrUpdate(
                                null,
                                "Thông báo đơn hàng mới. Người đặt hàng: " + order_name + ", giá trị: " + Format.FormatDecimalToString(price),
                                "Bạn có đơn hàng mới cần xử lý từ khách hàng: " + order_name +
                                " với đơn hàng tổng giá trị: " + Format.FormatDecimalToString(price) +
                                " lúc: " + DateTime.Now.ToString("dd/MM/yyyy HH:mm") +
                                ". Vui lòng truy cập hệ thống để xử lý",
                                "/DanhMuc/Order/Index/s=" + order.OrderGuid,
                                Memberid,
                                UserId.UserId,
                                DateTime.Now,
                                false,
                                Config.THONG_BAO_DON_HANG_MOI,
                                null
                                );
                        }

                        #endregion

                        #region Clear data cookies after order
                        Session[CartSession] = null;
                        #endregion

                        dbContextTransaction.Commit();
                    }
                    catch (Exception ex)
                    {
                        dbContextTransaction.Rollback();
                    }
                }
            }

            return(Redirect("/thong-tin-ca-nhan"));
        }
Ejemplo n.º 3
0
        public ActionResult OrderStatus(string OrderGuid, int?Status, string Description)
        {
            shOrderService _order = new shOrderService();
            shOrder        order  = _order.FindByKey(OrderGuid);

            using (var context = new ShopOnlineDb())
            {
                using (var dbContextTransaction = context.Database.BeginTransaction())
                {
                    try
                    {
                        if (order != null)
                        {
                            shOrderHistoryService _orderHistory = new shOrderHistoryService();

                            // 1. Hủy đơn hàng
                            int UserId = 0;
                            if (User.Identity.GetUserLogin() != null)
                            {
                                UserId = User.Identity.GetUserLogin().Userid;
                            }

                            string         MemberGuid   = null;
                            shOrderHistory orderHistory = _orderHistory.Insert_Update(
                                null,
                                order.OrderGuid,
                                order.OrderStatus,
                                MemberGuid,
                                Description,
                                UserId,
                                true,
                                DateTime.Now);

                            order.OrderStatus = C.Core.Common.OrderStatus.HuyDonHang.GetHashCode();
                            _order.Update(order);

                            // 2. Thông báo cho member đơn hàng hủy
                            shMemberService _member   = new shMemberService();
                            shMember        member    = _member.FindByKey(order.MemberGuid);
                            int             MemberId  = member != null ? member.MemberId : 0;
                            ThongBaoService _thongbao = new ThongBaoService();
                            _thongbao.InsertOrUpdate(
                                null,
                                "Thông báo đơn hàng bị hủy",
                                "Đơn hàng của bạn đã bị hủy. Nếu có thắc mắc vui lòng liên hệ với quản trị viên để biết thêm chi tiết",
                                null,
                                UserId,
                                MemberId,
                                DateTime.Now,
                                false,
                                Config.THONG_BAO_DA_XU_LY_DON_HANG,
                                null
                                );

                            // 3. gửi email thông báo hủy đơn hàng

                            string noidungdonhang = EmailHelper.NoiDungDonHang(order, new List <CartItem>());
                            string noidungEmail   = EmailHelper.NoiDungMailThongBaoHuyDatHang(noidungdonhang);
                            EmailHelper.ThongBaoEmailDonHangMoiToiNguoiDatHang(member.Email, noidungEmail);
                        }

                        dbContextTransaction.Commit();
                    }
                    catch (Exception ex)
                    {
                        dbContextTransaction.Rollback();
                    }
                }
            }


            if (Request.IsAjaxRequest())
            {
                return(Json("OK", JsonRequestBehavior.AllowGet));
            }

            return(RedirectToAction("Index"));
        }
Ejemplo n.º 4
0
        public shGoodReceiptIsuue XuatDuLieuDonHang(string OrderGuid, int?OrderStatus, string Description, int UserId, int Phieu, int MaKho, int LoaiPhieu, string GhiChu, int TrangThai, bool?Status, DateTime?CreateDate, string MaDonHang)
        {
            // 1. Cập nhật trạng thái đơn hàng
            shOrderService _order = new shOrderService();
            shOrder        order  = _order.FindByKey(OrderGuid);

            order.OrderStatus = OrderStatus;
            _order.Update(order);

            shGoodReceiptIsuue receipt = new shGoodReceiptIsuue();

            if (OrderStatus != C.Core.Common.OrderStatus.HuyDonHang.GetHashCode())
            {
                // 2. ghi lịch sử cập nhật đơn hàng
                shOrderHistoryService _orderHistory = new shOrderHistoryService();
                shOrderHistory        orderHistory  = _orderHistory.Insert_Update(
                    null,
                    order.OrderGuid,
                    OrderStatus,
                    null,
                    Description,
                    UserId,
                    true,
                    DateTime.Now);

                // 3. Tạo hóa đơn xuất kho
                receipt = Insert_Update(
                    null,
                    null,
                    Phieu,
                    null,
                    null,
                    MaKho,
                    null,
                    LoaiPhieu,
                    MaDonHang,
                    GhiChu,
                    UserId,
                    TrangThai,
                    Status,
                    CreateDate
                    );


                // 4 Cập nhật số lượng tồn của mỗi sản phẩm
                shOrderDetailService        _orderdetail = new shOrderDetailService();
                IEnumerable <shOrderDetail> ds           = _orderdetail.DanhSachOrderDetailBy(order.OrderGuid, order.MemberGuid, null);

                shSizeService _size = new shSizeService();
                shSetSize     size  = new shSetSize();
                foreach (var item in ds)
                {
                    size = _size.FindByKey(item.SizeGuid);
                    if (size == null)
                    {
                        size = new shSetSize();
                    }

                    // 5.. Tạo chi tiết hóa đơn xuất hàng hóa
                    shGoodReceiptIsuueDetailService _receiptDetail = new shGoodReceiptIsuueDetailService();
                    shGoodReceiptIsuueDetail        receiptDetail  = _receiptDetail.Insert_Update(
                        null,
                        null,
                        receipt.ReceiptIsuueGuid,
                        size.ProductGuid,
                        size.SectionGuid,
                        size.SizeGuid,
                        item.Number,
                        Status,
                        CreateDate,
                        Phieu);

                    // 6.Update số lượng tồn ở bảng size

                    size.Inventory = size.Inventory - item.Number;
                    _size.Update(size);
                }

                // 5. Thông báo cho Khach hàng biết đơn hàng đã xử lý
                shMemberService _member   = new shMemberService();
                shMember        member    = _member.FindByKey(order.MemberGuid);
                int             MemberId  = member != null ? member.MemberId : 0;
                ThongBaoService _thongbao = new ThongBaoService();
                _thongbao.InsertOrUpdate(
                    null,
                    "Thông báo đơn hàng đang trong quá trình xử lý",
                    "Đơn hàng của bạn đang trong quá trình vận chuyển. Vui lòng kiểm tra thông tin cá nhân trong quá trình chúng tôi vận chuyển sản phẩm",
                    null,
                    UserId,
                    MemberId,
                    DateTime.Now,
                    false,
                    Config.THONG_BAO_DA_XU_LY_DON_HANG,
                    null
                    );

                // 6. Gửi Email báo xử lý đơn hàng

                string noidungdonhang = EmailHelper.NoiDungDonHang(order, new List <CartItem>());
                string noidungEmail   = EmailHelper.NoiDungMailThongBaoXuLyDatHang(noidungdonhang);

                EmailHelper.ThongBaoEmailDonHangMoiToiNguoiDatHang(member.Email, noidungEmail);
            }


            return(receipt);
        }