Пример #1
0
        /// <summary>
        /// Tạo ID kế tiếp
        /// </summary>
        /// <returns></returns>
        public string NextId()
        {
            var orderImports = GetOrderImports();

            if (orderImports != null)
            {
                OrderImport orderImport = orderImports.LastOrDefault();
                if (orderImport != null)
                {
                    string lastId = orderImport.OrderImportID.Remove(0, 3);
                    string orderImportId;
                    if (!string.IsNullOrEmpty(lastId))
                    {
                        int nextId = int.Parse(lastId) + 1;
                        orderImportId = string.Format("HD{0}", nextId.ToString(CultureInfo.InvariantCulture).PadLeft(5, '0'));
                    }
                    else
                    {
                        orderImportId = string.Format("HD0000{0}", 1);
                    }
                    return(orderImportId);
                }
                return(string.Format("HD0000{0}", 1));
            }
            return(string.Format("HD0000{0}", 1));
        }
Пример #2
0
        /// <summary>
        /// Lưu
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(gridLookUpEditSuppliers.Text))
            {
                gridLookUpEditSuppliers.Properties.Appearance.BorderColor = System.Drawing.Color.Red;
                XtraMessageBox.Show("Vui lòng chọn Nhà cung cấp!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                gridLookUpEditSuppliers.Focus();
            }
            else if (string.IsNullOrEmpty(gridLookUpEditEmployee.Text))
            {
                gridLookUpEditEmployee.Properties.Appearance.BorderColor = System.Drawing.Color.Red;
                XtraMessageBox.Show("Vui lòng chọn Nhân viên!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                gridLookUpEditEmployee.Focus();
            }
            else
            {
                var orderImport = new OrderImport()
                {
                    OrderImportID = txtOrderImportID.Text,
                    SupplierID    = gridLookUpEditSuppliers.EditValue.ToString(),
                    EmployeeID    = _employeeId,
                    ImportDate    = dateEditImportDate.DateTime,
                    TotalMoney    = Convert.ToInt32(_total),
                    //Price = Convert.ToInt32(_price),
                    IsActive = true,
                };

                try
                {
                    _orderImportService.Add(orderImport);
                    foreach (Cart cart in _order.Carts)
                    {
                        InsertOrderImportDetail(txtOrderImportID.Text, cart.ProductId, cart.Quantity, cart.Price, cart.Total);
                        _inventoryService.InsertOrUpdateInventoryImport(cart.ProductId, cart.Quantity, txtOrderImportID.Text);
                    }
                    if (_order.Carts.Count > 0)
                    {
                        _order.Carts.Clear();
                    }


                    XtraMessageBox.Show("Nhập hàng thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    gridControlStockImport.DataSource = null;
                    ResetProductControls();
                    ResetSupplierControls();
                    EnabledButtonSaveAndPrint(false);
                    // Tạo tiếp ID
                    txtOrderImportID.Text            = _orderImportService.NextId();
                    gridLookUpEditEmployee.EditValue = _employeeId;
                }
                catch (SqlException ex)
                {
                    XtraMessageBox.Show(string.Format("Lỗi! \n {0}", ex.Message), "Thông báo lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                catch (Exception ex)
                {
                    XtraMessageBox.Show(string.Format("Lỗi! \n {0}", ex.Message), "Thông báo lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Пример #3
0
        /// <summary>
        /// Xóa theo ID
        /// </summary>
        /// <param name="orderImportId"></param>
        public void Delete(string orderImportId)
        {
            OrderImport orderImport = GetOrderImportById(orderImportId);

            _context.OrderImports.Remove(orderImport);
            SaveChanges();
        }
        public async Task UpdateOrderImport(int orderImportId, OrderImport orderImport, CancellationToken cancellationToken = default)
        {
            cancellationToken.ThrowIfCancellationRequested();

            orderImport.OrderImportId = orderImportId;

            await _orderImportRepository.Edit(orderImport, cancellationToken);
        }
Пример #5
0
        public bool CheckOrderImportIdExit(string orderImportId)
        {
            OrderImport orderImport = GetOrderImportById(orderImportId);

            if (orderImport != null)
            {
                return(false);
            }
            return(true);
        }
        public async Task <OrderImport> CreateOrderImport(IFormFile dataFile, DataFormat dataFormat, CancellationToken cancellationToken = default)
        {
            cancellationToken.ThrowIfCancellationRequested();

            string path = Path.Combine(Path.GetTempPath(), $"{Guid.NewGuid()}-Order.json");

            using FileStream fileStream = File.Create(path);
            await dataFile.CopyToAsync(fileStream, cancellationToken);

            await fileStream.FlushAsync(cancellationToken);

            var orderImport = new OrderImport {
                DataFormat = dataFormat, ImportStatus = OrderImportStatus.Waiting
            };
            await _orderImportRepository.Add(orderImport, cancellationToken);

            await _bus.Publish(new OrderImportEvent { OrderImportId = orderImport.OrderImportId, Path = path, DataFormat = dataFormat }, cancellationToken);

            return(orderImport);
        }
Пример #7
0
 /// <summary>
 /// Cập nhật thông tin
 /// </summary>
 /// <param name="orderImport"></param>
 public void Update(OrderImport orderImport)
 {
     _context.OrderImports.Attach(orderImport);
     _context.Entry(orderImport).State = EntityState.Modified;
     SaveChanges();
 }
Пример #8
0
 /// <summary>
 /// Thêm mới
 /// </summary>
 /// <param name="orderImport"></param>
 /// <returns></returns>
 public void Add(OrderImport orderImport)
 {
     _context.OrderImports.Add(orderImport);
     SaveChanges();
 }
Пример #9
0
        /// <summary>
        /// 同步订单
        /// </summary>
        /// <param name="account"></param>
        /// <param name="startDate"></param>
        /// <param name="endDate"></param>
        /// <returns></returns>
        public async Task <bool> SyncOrders(AdvertAccount account, DateTime startDate, DateTime endDate)
        {
            bool readEnd   = false;
            int  pageIndex = 1;
            int  pageSize  = 100;

            while (!readEnd)
            {
                var response = await QueryOrderAsync(account, startDate, endDate, pageIndex, pageSize);

                if (response.Code > 0)
                {
                    _logger.Error(string.Format("订单同步失败。{0}", response.Message));
                    break;
                }

                foreach (var orderData in response.Data.Orders)
                {
                    var orderDto = new OrderImport()
                    {
                        OrderSource     = OrderSource.Tenant,
                        StoreId         = account.StoreId,
                        AdvertAccountId = account.Id,
                        OrderNumber     = orderData.OrderId,
                        ProductSku      = GetSku(orderData.PackageInfo),
                        OrderStatus     = OrderStatus.WaitConfirm,
                        ShippingStatus  = ShippingStatus.NotYetShipped,
                        OrderTotal      = Convert.ToDecimal(orderData.TotalPrice) / 100,

                        PackageNum  = orderData.Quantity,
                        PackageName = orderData.PageName,

                        CustomerComment = GetSelectPackageInfo(orderData),

                        ReceiverName = orderData.UserName,
                        Telephone    = orderData.UserPhone,
                        FullAddress  = orderData.UserAddress,
                        Address      = orderData.UserAddress,
                        Province     = orderData.UserProvince,
                        City         = orderData.UserCity,
                        District     = orderData.UserArea,

                        PlaceOnUtc   = orderData.OrderTime.LocalTimeConverUtcTime(_dateTimeHelper),
                        CreatedOnUtc = orderData.OrderTime.LocalTimeConverUtcTime(_dateTimeHelper),
                    };

                    try
                    {
                        await _orderImportor.ImportOrderAsync(orderDto);
                    }
                    catch (Exception exc)
                    {
                        _logger.Error(string.Format("订单同步失败。{0}", exc.Message), exc);
                    }
                }

                readEnd = (pageIndex) * response.Data.PageInfo.PageSize > response.Data.PageInfo.TotalNumber;

                pageIndex += 1;
            }

            return(true);
        }
Пример #10
0
        public override void Execute(int arg)
        {
            AsyncHelper.RunSync(async() =>
            {
                using (_unitOfWorkManager.Current.SetTenantId(arg))
                {
                    var stores = await _storeManager.Stores.ToListAsync();

                    foreach (var store in stores)
                    {
                        try
                        {
                            if (store.OrderSource != OrderSource.FxgPd && store.OrderSource != OrderSource.FxgAd)
                            {
                                continue;
                            }

                            ToutiaoApiHelper.AppKey    = store.AppKey;
                            ToutiaoApiHelper.AppSecret = store.AppSecret;

                            bool readEnd  = false;
                            int pageIndex = 0;
                            int pageSize  = 100;

                            while (!readEnd)
                            {
                                OrderListRequestPara para = new OrderListRequestPara()
                                {
                                    StartTime = DateTime.Now.GetStartTimeOfDate().AddDays(-30).DateTimeString("yyyy/MM/dd HH:mm:ss"),
                                    EndTime   = DateTime.Now.GetEndTimeOfDate().DateTimeString("yyyy/MM/dd HH:mm:ss"),
                                    Page      = pageIndex.ToString(),
                                    Size      = pageSize.ToString(),
                                    OrderBy   = "create_time"
                                };

                                var response = await ToutiaoApiHelper.GetOrderList(para);

                                if (response.ErrorNo > 0 || response.Data.Items == null)
                                {
                                    _logger.Error(string.Format("订单同步失败。{0}", response.Message));
                                    break;
                                }

                                foreach (var orderData in response.Data.Items)
                                {
                                    //跳过待确认
                                    if (orderData.OrderStatus == (int)ToutiaoOrderStatus.WaitForComfirm)
                                    {
                                        continue;
                                    }

                                    //跳过已取消订单
                                    if (orderData.OrderStatus == (int)ToutiaoOrderStatus.Canceled && orderData.LogisticsCode.IsNullOrEmpty())
                                    {
                                        continue;
                                    }

                                    if (orderData.BuyerWords.Trim().ToLower() == "x" ||
                                        orderData.SellerWords.Trim().ToLower() == "shua")
                                    {
                                        continue;
                                    }

                                    foreach (var orderItemData in orderData.Childs)
                                    {
                                        if (orderItemData.Code.StartsWith("FXG011"))
                                        {
                                            continue;
                                        }

                                        var orderTotal = Convert.ToDecimal(orderItemData.TotalAmount) / 100;
                                        var shipInfo   = ToutiaoShipInfoData.GetToutiaoShipInfoById(orderItemData.LogisticsId);

                                        var orderDto = new OrderImport()
                                        {
                                            OrderSource         = store.OrderSource,
                                            StoreId             = store.Id,
                                            OrderNumber         = orderItemData.OrderId,
                                            ProductSku          = orderItemData.Code,
                                            OrderStatus         = orderItemData.OrderStatus.GetOrderStatus(),
                                            ShippingStatus      = orderItemData.OrderStatus.GetShippingStatus(),
                                            OrderTotal          = orderTotal,
                                            Reward              = orderItemData.GetOrderReward(orderTotal),
                                            ShipTotal           = Convert.ToDecimal(orderItemData.PostAmount) / 100,
                                            DiscountAmount      = orderItemData.ShopCouponAmount / 100 + orderItemData.CouponAmount / 100,
                                            PackageNum          = orderItemData.ComboNum,
                                            PackageName         = orderItemData.ProductName,
                                            LogisticsName       = shipInfo?.Name,
                                            TrackingNumber      = orderItemData.LogisticsCode,
                                            TrackingOrderNumber = orderItemData.LogisticsCode,

                                            CustomerComment = orderItemData.BuyerWords,
                                            AdminComment    = orderItemData.SellerWords,

                                            ReceiverName = orderItemData.PostReceiver,
                                            Telephone    = orderItemData.PostTel,
                                            FullAddress  = orderItemData.PostAddress.Detail,
                                            Province     = orderItemData.PostAddress.Provice.Name,
                                            City         = orderItemData.PostAddress.City.Name,
                                            District     = orderItemData.PostAddress.Town.Name,
                                            Address      = orderItemData.PostAddress.Detail,

                                            PlaceOnUtc      = orderItemData.LogisticsTime.GetTime(false),
                                            DeliveriedOnUtc = orderItemData.ReceiptTime.GetTime(false),
                                            CreatedOnUtc    = orderItemData.CreateTime.GetTime(false),
                                        };

                                        if (orderItemData.OrderStatus == ToutiaoOrderStatus.Canceled || orderItemData.OrderStatus > ToutiaoOrderStatus.Refunse)
                                        {
                                            orderDto.OrderStatus    = OrderStatus.Canceled;
                                            orderDto.ShippingStatus = ShippingStatus.IssueWithReject;
                                        }

                                        await _orderImportor.ImportOrderAsync(orderDto);
                                    }
                                }

                                pageIndex += 1;
                                readEnd    = (pageIndex) * pageSize > response.Data.Total;
                            }
                        }
                        catch (Exception ex)
                        {
                            _logger.Error(string.Format("订单同步失败。{0}", ex.Message), ex);
                        }
                    }
                }
            });
        }