Пример #1
0
        public void Delete(WalletCustomer customer)
        {
            customer.IsDelete = true;
            FDIDB.WalletCustomers.Attach(customer);
            var entry = FDIDB.Entry(customer);

            entry.Property(e => e.IsDelete).IsModified = true;
            // DB.Customers.Remove(customer);
        }
Пример #2
0
        public ActionResult AjaxForm()
        {
            var model = new WalletCustomer();

            ViewBag.customer = _customerApi.GetList();
            if (DoAction == ActionType.Edit)
            {
                model = _walletCustomerDa.GetById(ArrId.FirstOrDefault());
            }
            ViewBag.Action   = DoAction;
            ViewBag.AgencyId = UserItem.AgencyID;
            return(View(model));
        }
Пример #3
0
        public ActionResult Add(string key, string json)
        {
            var model = new WalletCustomer();
            var msg   = new JsonMessage(false, "Thêm mới dữ liệu thành công.");

            try
            {
                UpdateModel(model);
                model.DateCreate = ConvertDate.TotalSeconds(DateTime.Now);
                model.IsDelete   = false;
                _da.Add(model);
                _da.Save();
            }
            catch (Exception ex)
            {
                msg.Erros   = true;
                msg.Message = "Dữ liệu chưa được thêm mới";
                Log2File.LogExceptionToFile(ex);
            }
            return(Json(msg, JsonRequestBehavior.AllowGet));
        }
Пример #4
0
 public ActionResult AddTranfer(string key, string moneyTranfer, string agencyId, string customerId)
 {
     // var model = new WalletCustomer();
     try
     {
         var wallet = new WalletCustomer
         {
             AgencyId   = int.Parse(agencyId),
             CustomerID = int.Parse(customerId),
             DateCreate = DateTime.Now.TotalSeconds(),
             IsDelete   = false,
             TotalPrice = decimal.Parse(moneyTranfer)
         };
         _da.Add(wallet);
         _da.Save();
         return(Json(1, JsonRequestBehavior.AllowGet));
     }
     catch (Exception ex)
     {
         return(Json(0, JsonRequestBehavior.AllowGet));
     }
 }
Пример #5
0
 public ActionResult AddWallets(WalletCustomerAppIG4Item data)
 {
     try
     {
         var wallet = new WalletCustomer
         {
             CustomerID     = data.CustomerID,
             TotalPrice     = data.Totalprice ?? 0,
             DateCreate     = DateTime.Now.TotalSeconds(),
             IsDelete       = false,
             Note           = data.Note,
             IsActive       = true,
             Transaction_no = data.TransactionNo,
         };
         _walletCustomerDa.Add(wallet);
         _walletCustomerDa.Save();
         UpdateLevelCustomer(data.CustomerID ?? 0);
     }
     catch (Exception ex)
     {
         return(Json(new JsonMessage(404, ex.ToString()), JsonRequestBehavior.AllowGet));
     }
     return(Json(new JsonMessage(200, ""), JsonRequestBehavior.AllowGet));
 }
Пример #6
0
        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));
        }
Пример #7
0
        public async Task <ActionResult> PaymentMoMoServer(dataItem item)
        {
            var refId     = Guid.NewGuid();
            var requestId = Guid.NewGuid();
            var model     = new HashMoMoItem
            {
                amount       = item.amount ?? 0,
                partnerRefId = refId.ToString(),
                partnerCode  = PartnerCode,
                //partnerName = "Công ty cổ phần công nghệ G-store",
                partnerTransId = DateTime.Now.TotalSeconds().ToString(),
                description    = item.description ?? "",
            };
            var json = new JavaScriptSerializer().Serialize(model);

            byte[] data   = Encoding.UTF8.GetBytes(json);
            string result = null;

            using (var rsa = new RSACryptoServiceProvider(4096)) //KeySize
            {
                try
                {
                    // MoMo's public key has format PEM.
                    // You must convert it to XML format. Recommend tool: https://superdry.apphb.com/tools/online-rsa-key-converter
                    rsa.FromXmlString(publickey);
                    var encryptedData   = rsa.Encrypt(data, false);
                    var base64Encrypted = Convert.ToBase64String(encryptedData);
                    result = base64Encrypted;
                }
                finally
                {
                    rsa.PersistKeyInCsp = false;
                }
            }
            var data1 = new ProcessMoMoItem
            {
                customerNumber = item.customerNumber ?? "",
                partnerCode    = PartnerCode,
                partnerRefId   = refId.ToString(),
                appData        = item.token ?? "",
                hash           = result,
                payType        = 3,
                description    = item.description ?? "",
                version        = 2
            };
            var                      url = Momo + "pay/app";
            ResultMoMoItem           kq;
            ResultDataMoMoAppIG4Item resutl;

            new ResultDataMoMoAppIG4Item();
            try
            {
                kq = await PostDataAsync <ResultMoMoItem>(url, data1);

                var requestType = "";
                var obj         = new ConfirmMoMoItem();
                if (kq.status == 0)
                {
                    obj.requestType = "capture";
                    requestType     = "capture";
                }
                else
                {
                    obj.requestType = "revertAuthorize";
                    requestType     = "revertAuthorize";
                }
                var    sign      = string.Format("partnerCode={0}&partnerRefId={1}&requestType={2}&requestId={3}&momoTransId={4}", PartnerCode, refId.ToString(), requestType, requestId.ToString(), kq.transid);
                string signature = signSHA256(sign, serectkey);
                obj.partnerCode    = PartnerCode;
                obj.partnerRefId   = refId.ToString();
                obj.customerNumber = item.customerNumber;
                obj.description    = item.description;
                obj.momoTransId    = kq.transid;
                obj.requestId      = requestId.ToString();
                obj.signature      = signature;
                var urlconfirm = Momo + "pay/confirm";
                try
                {
                    resutl = await PostDataAsync <ResultDataMoMoAppIG4Item>(urlconfirm, obj);

                    if (resutl.status == 0)
                    {
                        // thêm tiền vào ví chính
                        var wallet = new WalletCustomer
                        {
                            //Price = (decimal)resutl.data.amount,
                            TotalPrice     = (decimal)resutl.data.amount,
                            CustomerID     = item.CustomerId,
                            DateCreate     = DateTime.Now.TotalSeconds(),
                            IsDelete       = false,
                            IsActive       = true,
                            Note           = item.description,
                            Transaction_no = resutl.transid,
                            Type           = 1,
                        };
                        _walletCustomerDa.Add(wallet);
                        _walletCustomerDa.Save();
                        var gettoken = _customerDa.GetItemByID(item.CustomerId);
                        // % khuyến mãi vào ví thưởng.
                        var config = _walletCustomerDa.GetConfig();
                        var reward = new RewardHistory
                        {
                            CustomerID  = item.CustomerId,
                            Price       = config.Percent * ((decimal)resutl.data.amount) / 100,
                            IsActive    = true,
                            IsDeleted   = false,
                            Date        = DateTime.Now.TotalSeconds(),
                            WalletCusId = wallet.ID,
                            Type        = (int)Reward.Dep,
                            Percent     = config.Percent,
                        };
                        _rewardHistoryDa.Add(reward);
                        _rewardHistoryDa.Save();
                        var sucess = orderDA.GetNotifyById(4);
                        var token  = gettoken.tokenDevice;
                        Pushnotifycation(sucess.Title.Replace("{percent}", config.Percent.ToString()), sucess.Content.Replace("{price}", reward.Price.Money()).Replace("{total}", resutl.data.amount.MoneyDouble()), token, sucess.ID.ToString());
                    }
                    return(Json(resutl, JsonRequestBehavior.AllowGet));
                }
                catch (Exception ex)
                {
                    resutl = new ResultDataMoMoAppIG4Item
                    {
                        status  = -1,
                        message = ex.ToString()
                    };
                    return(Json(resutl, JsonRequestBehavior.AllowGet));
                }
            }
            catch (Exception ex)
            {
                resutl = new ResultDataMoMoAppIG4Item
                {
                    status  = -1,
                    message = ex.ToString()
                };
                return(Json(resutl, JsonRequestBehavior.AllowGet));
            }
        }
Пример #8
0
        public ActionResult UpdateStatus(int orderId, int type)
        {
            var data = orderDA.GetById(orderId);

            data.Status           = type;
            data.Check            = 1;
            data.DateUpdateStatus = DateTime.Now.TotalSeconds();
            var totalPrice = data.Payments;

            //var TotalPricegstore = data.OrderTotal - ((data.Discount * data.OrderTotal / 100)) + data.FeeShip;
            //var config = _walletCustomerDa.GetConfig();
            //var totaldis = data.Discount + config.Percent;
            foreach (var item in data.Shop_Order_Details)
            {
                item.Status           = type;
                item.DateUpdateStatus = DateTime.Now.TotalSeconds();
                item.Check            = 1;
            }
            orderDA.Save();

            if (type == (int)StatusOrder.Complete)
            {
                // tru tien khach hang

                decimal?totak = 0;
                foreach (var items in data.Shop_Order_Details)
                {
                    var k = items.Shop_Product.Category.Profit;
                    if (items.Shop_Product.Product_Size.Value != null)
                    {
                        totak += (items.Shop_Product.Product_Size != null
                                     ? (decimal)items.Shop_Product.Product_Size.Value
                                     : 1) * items.Quantity * k * 1000;
                    }
                    var shop      = _customerDa.GetItemByID(data.ShopID ?? 0);
                    var config    = _walletCustomerDa.GetConfig();
                    var totalshop = (data.Total - totak) + (totak * shop.PercentDiscount / 100) + data.FeeShip;
                    var walletcus = new WalletCustomer
                    {
                        CustomerID     = data.ShopID,
                        TotalPrice     = totalshop ?? 0,
                        DateCreate     = DateTime.Now.TotalSeconds(),
                        IsActive       = true,
                        IsDelete       = false,
                        Type           = 2,
                        Transaction_no = data.Code,
                        CustomerIDR    = data.CustomerID,
                    };
                    _walletCustomerDa.Add(walletcus);
                    _walletCustomerDa.Save();
                    // kiem tra level khach hang.
                    //UpdateLevelCustomer(data.CustomerID ?? 0);
                    var cus = _customerDa.GetItemByID(data.CustomerID ?? 0);
                    //var shopsucess = orderDA.GetNotifyById(5);
                    //var tokenshop = shop.tokenDevice;
                    //Pushnotifycation(shopsucess.Title, shopsucess.Content.Replace("{price}", totalshop.Money()).Replace("{code}", data.Code).Replace("{customer}", data.Customer.FullName), tokenshop, shopsucess.ID.ToString());

                    var bonusItems = _customerDa.ListBonusTypeItems();
                    #region hoa hồng khách hàng và shop ký gửi
                    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(data.Customer.ListID, data.Customer.ParentID ?? 0, totalpres, data.ID, bonusItems, 2, data.ShopID ?? 0);
                        //    InsertRewardCustomer(data.Customer.ListID, data.Customer.ParentID ?? 0, totalpres, data.ID, bonusItems, 2, data.ShopID ?? 0);
                        //}
                        //if (totalnopres > 0)
                        //{
                        //    InsertRewardCustomer(data.Customer.ListID,data.Customer.ParentID ?? 0, totalnopres, data.ID, bonusItems);
                        //}
                    }
                    #endregion
                }
                #region // xử lý trừ số lượng trong kho của shop
                foreach (var item in data.Shop_Order_Details)
                {
                    var product = _productDa.GetById(item.ProductID ?? 0);
                    product.QuantityOut += item.Quantity;
                    _productDa.Save();
                }


                #endregion
            }
            #region push notify
            //var notify = orderDA.GetNotifyById(8);
            //var gettoken = _customerDa.GetItemByID(data.CustomerID ?? 0);
            //var token = gettoken.tokenDevice;
            //if (type == (int)StatusOrder.Process)
            //{
            //    Pushnotifycation(notify.Title, notify.Content.Replace("{status}", "đang được xử lý").Replace("{shop}", data.Customer.FullName).Replace("{code}", data.Code), token, notify.ID.ToString());
            //}
            //if (type == (int)StatusOrder.Shipping)
            //{
            //    Pushnotifycation(notify.Title, notify.Content.Replace("{status}", "đang được giao").Replace("{shop}", data.Customer.FullName).Replace("{code}", data.Code), token, notify.ID.ToString());
            //}
            //if (type == (int)StatusOrder.Cancel)
            //{
            //    Pushnotifycation(notify.Title, notify.Content.Replace("{status}", "vừa bị hủy bởi chủ cửa hàng.!").Replace("{shop}", data.Customer.FullName).Replace("{code}", data.Code), token, notify.ID.ToString());
            //}
            //if (type == (int)StatusOrder.Complete)
            //{
            //    notify = orderDA.GetNotifyById(3);
            //    Pushnotifycation(notify.Title, notify.Content.Replace("{shop}", data.Customer.FullName).Replace("{price}", totalPrice.Money()).Replace("{code}", data.Code), token, notify.ID.ToString());
            //}
            #endregion
            return(Json(new BaseResponse <List <ProductItem> > {
                Code = 200, Message = "Cập nhật thành công!"
            }, JsonRequestBehavior.AllowGet));
        }
Пример #9
0
 public void Add(WalletCustomer customer)
 {
     FDIDB.WalletCustomers.Add(customer);
 }
Пример #10
0
 public void Add(WalletCustomer obj)
 {
     FDIDB.WalletCustomers.Add(obj);
 }