public ActionResult SearchMoney(string query, int cusId)
 {
     try
     {
         var totalwalet = customerDA.GetItemByID(cusId);
         var config     = _walletCustomerDa.GetConfig();
         if (totalwalet.Wallets > 0 && totalwalet.Wallets >= config.PriceSearch)
         {
             var recive = new ReceiveHistory
             {
                 CustomerID = cusId,
                 Price      = config.PriceSearch,
                 IsActive   = true,
                 Query      = query,
                 DateCreate = DateTime.Now.TotalSeconds(),
                 Type       = 1,
             };
             _rewardHistoryDa.Add(recive);
             _rewardHistoryDa.Save();
         }
         else
         {
             if (totalwalet.TotalWallets > 0 && totalwalet.TotalWallets >= config.PriceSearch)
             {
                 var recive = new CashOutWallet()
                 {
                     CustomerID = cusId,
                     TotalPrice = config.PriceSearch,
                     DateCreate = DateTime.Now.TotalSeconds(),
                     Type       = 3,
                     Query      = query,
                 };
                 _cashOutWalletDa.Add(recive);
                 _cashOutWalletDa.Save();
             }
             else
             {
                 return(Json(new BaseResponse <List <ProductItem> > {
                     Code = 1, Message = "Ví tiền của bạn không đủ.!"
                 }, JsonRequestBehavior.AllowGet));
             }
         }
         return(Json(new BaseResponse <List <ProductItem> > {
             Code = 200, Message = ""
         }, JsonRequestBehavior.AllowGet));
     }
     catch (Exception e)
     {
         return(Json(new BaseResponse <List <ProductItem> > {
             Code = -1, Message = e.ToString()
         }, JsonRequestBehavior.AllowGet));
     }
 }
        public ActionResult UpdateStatusCustomer(int orderId, int status, int cusId)
        {
            var     data  = orderDA.GetById(orderId);
            decimal?totak = 0;

            foreach (var items in data.Shop_Order_Details)
            {
                var k = items.Shop_Product.Category.Profit;
                totak += (items.Shop_Product.Product_Size != null ? (decimal)items.Shop_Product.Product_Size.Value : 1) * items.Quantity * k * 1000;
            }
            data.Status           = status;
            data.Check            = 2;
            data.DateUpdateStatus = DateTime.Now.TotalSeconds();
            foreach (var item in data.Shop_Order_Details)
            {
                item.Status           = status;
                item.DateUpdateStatus = DateTime.Now.TotalSeconds();
                item.Check            = 2;
            }

            var TotalPricegstore = data.Total + data.FeeShip;

            SpliceOrderCustomer(":4000", orderId);
            orderDA.Save();
            if (status == (int)StatusOrder.Complete)
            {
                #region đơn hàng đã giao thành chuyển tiền cho shop
                var cashout = new CashOutWallet
                {
                    CustomerID = 1,
                    TotalPrice = TotalPricegstore ?? 0,
                    DateCreate = DateTime.Now.TotalSeconds(),
                    OrderID    = data.ID,
                    Type       = 1,
                    Code       = data.Code,
                };
                _cashOutWalletDa.Add(cashout);
                _cashOutWalletDa.Save();
                #endregion

                var config = _walletCustomerDa.GetConfig();
                var shop   = customerDA.GetItemByID(data.ShopID ?? 0);

                //var TotalPrice = data.Total - (config.DiscountOrder * data.Total / 100) + data.FeeShip;
                var TotalPrice = (data.Total - totak) + (totak * shop.PercentDiscount / 100) + data.FeeShip;

                var walletcus = new WalletCustomer
                {
                    CustomerID     = data.ShopID,
                    TotalPrice     = TotalPrice ?? 0,
                    DateCreate     = DateTime.Now.TotalSeconds(),
                    IsActive       = true,
                    IsDelete       = false,
                    Type           = 2,
                    Transaction_no = data.Code,
                };
                _walletCustomerDa.Add(walletcus);
                _walletCustomerDa.Save();

                var cus    = customerDA.GetItemByID(data.CustomerID ?? 0);
                var sucess = orderDA.GetNotifyById(3);
                var token  = cus.tokenDevice;
                Pushnotifycation(sucess.Title, sucess.Content.Replace("{shop}", data.Customer.FullName).Replace("{price}", TotalPrice.Money()).Replace("{code}", data.Code), token, sucess.ID.ToString());

                var shopsucess = orderDA.GetNotifyById(5);
                var tokenshop  = shop.tokenDevice;
                Pushnotifycation(shopsucess.Title, shopsucess.Content.Replace("{price}", TotalPrice.Money()).Replace("{code}", data.Code).Replace("{customer}", data.Customer.FullName), tokenshop, shopsucess.ID.ToString());
                var bonusItems = customerDA.ListBonusTypeItems();
                // tính hoa hồng
                var iskg = data.Customer.Type == 2;
                if (!iskg)
                {
                    InsertRewardOrderCustomer(cus, config, totak, data.ID, bonusItems);
                    InsertRewardOrderAgency(shop, config, totak, data.ID, bonusItems);
                }
                else
                {
                    // chiết khấu shop ký gửi

                    //decimal totalpres = data.Shop_Order_Details.Where(detail => detail.IsPrestige == true).Sum(detail => detail.TotalPrice ?? 0);
                    //decimal totalnopres = data.Shop_Order_Details.Where(detail => detail.IsPrestige == false || !detail.IsPrestige.HasValue).Sum(detail => detail.TotalPrice ?? 0);
                    //if (totalpres > 0)
                    //{
                    //    InsertRewardCustomer(cus, totalpres, data.ID, bonusItems, 2, data.ShopID ?? 0);
                    //}
                    //if (totalnopres > 0)
                    //{
                    //    InsertRewardCustomer(cus, totalnopres, data.ID, bonusItems);
                    //}
                }
                // update level KH
                UpdateLevelCustomer(cusId);
            }
            else
            {
                var shop       = customerDA.GetItemByID(data.ShopID ?? 0);
                var shopsucess = orderDA.GetNotifyById(10);

                var tokenshop = shop.tokenDevice;
                Pushnotifycation(shopsucess.Title.Replace("{customer}", data.Customer.FullName), shopsucess.Content.Replace("{code}", data.Code), tokenshop, shopsucess.ID.ToString());
            }
            return(Json(new BaseResponse <List <ProductItem> > {
                Code = 200, Message = "Cập nhật trạng thái thành công!"
            }, JsonRequestBehavior.AllowGet));
        }
 public void Add(CashOutWallet obj)
 {
     FDIDB.CashOutWallets.Add(obj);
 }
        public async Task <ActionResult> AddOrderPackage(int typeid, int customerid)
        {
            try
            {
                var cus    = _customerDa.GetItemByID(customerid);
                var config = _walletCustomerDa.GetConfig();
                var type   = _customerTypeDa.GetById(typeid);
                if (cus.Wallets >= type.Price)
                {
                    var dateStart = _orderPackageDa.GetDateStartByCustomerID(customerid);

                    var date = DateTime.Now;
                    var item = new Order_Package
                    {
                        TypeID     = type.ID,
                        Price      = type.Price,
                        CustomerID = customerid,
                        Datecreate = date.TotalSeconds(),
                        DateStart  = dateStart ?? date.TotalSeconds(),
                        DateEnd    = date.AddMonths(type.Month ?? 0).AddDays(type.Day ?? 0).TotalSeconds(),
                    };

                    _orderPackageDa.Add(item);
                    var cashout = new CashOutWallet
                    {
                        CustomerID   = customerid,
                        DateCreate   = DateTime.Now.TotalSeconds(),
                        TotalPrice   = type.Price,
                        OrderPaketID = item.ID,
                        Type         = 2,
                    };
                    _cashOutWalletDa.Add(cashout);

                    await _orderPackageDa.SaveAsync();

                    //var walletcus = new WalletCustomer
                    //{
                    //    CustomerID = 1,
                    //    TotalPrice = type.Price*(100 - config.DiscountOrderPacket) ?? 0,
                    //    DateCreate = DateTime.Now.TotalSeconds(),
                    //    IsActive = true,
                    //    IsDelete = false,
                    //    Type = 3,
                    //    //Transaction_no = data.Code,
                    //    CustomerIDR = cus.ID,
                    //};
                    //_walletCustomerDa.Add(walletcus);
                    //_walletCustomerDa.Save();
                    _cashOutWalletDa.Save();
                    //var total = type.Price * config.DiscountOrderPacket / 100;
                    var bonusItems = _customerDa.ListBonusTypeItems();

                    InsertRewardOrderPacket(cus, config, type.Price, item.ID, bonusItems);
                    return(Json(new BaseResponse <JsonMessage> {
                        Code = 200, Message = "Mua gói dịch vụ thành công."
                    }, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    return(Json(new BaseResponse <OrderPacketAppAppIG4Item> {
                        Code = -1, Message = "Ví tiền không đủ."
                    }, JsonRequestBehavior.AllowGet));
                }
            }
            catch (Exception e)
            {
                return(Json(new BaseResponse <OrderPacketAppAppIG4Item> {
                    Code = -2, Message = e.ToString()
                }, JsonRequestBehavior.AllowGet));
            }
        }
Example #5
0
        public async Task <ActionResult> Booking(List <OrderAppIG4Item> datas)
        {
            try
            {
                decimal?totalall  = 0;
                var     listOrder = new List <Shop_Orders>();
                foreach (var data in datas)
                {
                    if (data.LisOrderDetailItems == null || !data.LisOrderDetailItems.Any())
                    {
                        return(Json(new JsonMessage(1000, "Không có sản phẩm trong giỏ hàng"),
                                    JsonRequestBehavior.AllowGet));
                    }

                    SaleCode coupon = null;
                    if (!string.IsNullOrEmpty(data.Coupon))
                    {
                        coupon = _productDa.GetSaleCodeUseByCode(data.Coupon);
                        if (coupon != null)
                        {
                            coupon.IsUse = true;
                        }
                        //if (coupon == null)
                        //{
                        //    return Json(new JsonMessage(1000, "Coupon không tồn tại"));
                        //}
                    }

                    var order = new Shop_Orders()
                    {
                        Address       = data.Address,
                        CustomerID    = CustomerId,
                        Longitude     = data.Longitude,
                        Latitude      = data.Latitude,
                        Mobile        = data.Mobile,
                        CustomerName  = data.CustomerName,
                        DateCreated   = DateTime.Now.TotalSeconds(),
                        Code          = FDIUtils.RandomCode(12),
                        FeeShip       = data.FeeShip ?? 0,
                        StatusPayment = (int)PaymentOrder.Process,
                        Coupon        = data.Coupon,
                        ShopID        = data.ShopID,
                        //Discount = data.Discount,
                        CouponPrice       = coupon?.DN_Sale.Price ?? 0,
                        PaymentMethodId   = data.PaymentmethodId,
                        Status            = (int)StatusOrder.Create,
                        Note              = data.Note,
                        CustomerAddressID = data.CustomerAddressID,
                    };
                    order.CouponPrice = !string.IsNullOrEmpty(data.Coupon)
                        ? coupon.DN_Sale.Price ?? 0
                        : order.CouponPrice = 0;

                    foreach (var product in data.LisOrderDetailItems)
                    {
                        var productData = _productDa.GetProductItem(product.ProductId ?? 0);
                        if (productData == null)
                        {
                            return(Json(new JsonMessage(1000, "Sản phẩm không tồn tại"), JsonRequestBehavior.AllowGet));
                        }

                        var item = new Shop_Order_Details()
                        {
                            ProductID     = product.ProductId,
                            Price         = productData.PriceNew ?? 0,
                            Quantity      = product.Quantity ?? 1,
                            Status        = (int)StatusOrder.Create,
                            TotalPrice    = productData.PriceNew * (product.Quantity ?? 1),
                            StatusPayment = (int)PaymentOrder.Process,
                            IsPrestige    = product.IsPrestige,
                        };
                        order.Shop_Order_Details.Add(item);
                    }

                    var total = order.Shop_Order_Details.Sum(m => m.Price * m.Quantity);
                    order.Total      = total;
                    order.TotalPrice = total;
                    order.Payments   = total - order.CouponPrice + data.FeeShip;
                    totalall        += total - order.CouponPrice + data.FeeShip;
                    listOrder.Add(order);
                    //orderDA.Add(order);
                }

                //kiểm tra ví và trừ tiền khách hàng sau đó lưu đơn hàng
                var check = CheckWallets(totalall, CustomerId);
                if (check)
                {
                    foreach (var order in listOrder)
                    {
                        orderDA.Add(order);
                        await orderDA.SaveAsync();

                        var cashout = new CashOutWallet
                        {
                            CustomerID = CustomerId,
                            TotalPrice = order.Payments,
                            DateCreate = DateTime.Now.TotalSeconds(),
                            OrderID    = order.ID,
                            Type       = 1,
                            Code       = order.Code,
                        };
                        _cashOutWalletDa.Add(cashout);
                        _cashOutWalletDa.Save();
                    }
                    await _productDa.SaveAsync();
                }
                else
                {
                    return(Json(new JsonMessage(1001, "Tài khoản của bạn không đủ tiền."),
                                JsonRequestBehavior.AllowGet));
                }
            }
            catch (Exception e)
            {
                return(Json(new JsonMessage(404, e.ToString()), JsonRequestBehavior.AllowGet));
            }

            return(Json(new JsonMessage(200, ""), JsonRequestBehavior.AllowGet));
        }