Beispiel #1
0
        /// <summary>
        /// 获取贝贝网店订单
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public async Task <BbOrderResponse> GetOrder(BbOrderRequest request)
        {
            try
            {
                string method = "beibei.outer.trade.order.get";
                using (HttpClient hc = new HttpClient())
                {
                    Dictionary <string, string> dict = new Dictionary <string, string>();
                    dict.Add("method", method);
                    dict.Add("app_id", appId);
                    dict.Add("session", session);
                    dict.Add("timestamp", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
                    dict.Add("time_range", request.TimeRange);
                    dict.Add("start_time", request.StartTime.ToString("yyyy-MM-dd HH:mm:ss"));
                    dict.Add("end_time", request.EndTime.ToString("yyyy-MM-dd HH:mm:ss"));
                    //待发货
                    dict.Add("status", request.Status.ToString());
                    dict.Add("page_no", request.PageNo.ToString());
                    dict.Add("page_size", request.PageSize.ToString());
                    string sing = CommonHelper.BbOpera(dict, secret);
                    dict.Add("sign", sing);
                    FormUrlEncodedContent content = new FormUrlEncodedContent(dict);
                    HttpResponseMessage   msg     = await hc.PostAsync(gateway, content);

                    string res = await msg.Content.ReadAsStringAsync();

                    var resOrders = CommonHelper.DeJson <BbOrderResponse>(res);
                    return(resOrders);
                }
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Beispiel #2
0
        //获取待发货的订单号
        public async Task <List <string> > GetWaitSendOid()
        {
            try
            {
                List <string> sourceIds = new List <string>();
                bool          flag      = true;
                int           pageNo    = 1;
                while (flag)
                {
                    BbOrderRequest or = new BbOrderRequest
                    {
                        Status    = 1,
                        TimeRange = "pay_time",
                        StartTime = DateTime.Now.AddDays(-27),
                        EndTime   = DateTime.Now,
                        PageNo    = pageNo,
                        PageSize  = 300
                    };
                    var orders = await GetOrder(or);

                    if (orders != null)
                    {
                        if (orders.Count == 0)
                        {
                            break;
                        }

                        if (orders.Count > 0)
                        {
                            if (orders.Count == 300)
                            {
                                pageNo++;
                            }
                            else
                            {
                                //退出循环
                                flag = false;
                            }
                            foreach (var order in orders.Data)
                            {
                                sourceIds.Add(order.Oid);
                            }
                        }
                    }
                }

                return(sourceIds);
            }
            catch (Exception e)
            {
                log.Error(e);
                throw e;
            }
        }
Beispiel #3
0
        public async void DownloadOrders()
        {
            try
            {
                count = 0;
                bool flag   = true;
                int  pageNo = 1;
                while (flag)
                {
                    BbOrderRequest or = new BbOrderRequest
                    {
                        Status    = 1,
                        TimeRange = "pay_time",
                        StartTime = DateTime.Now.AddDays(-27),
                        EndTime   = DateTime.Now,
                        PageNo    = pageNo,
                        PageSize  = 300
                    };
                    var orders = await bbShopService.GetOrder(or);

                    if (orders != null)
                    {
                        if (orders.Count == 0)
                        {
                            break;
                        }

                        if (orders.Count > 0)
                        {
                            if (orders.Count == 300)
                            {
                                pageNo++;
                            }
                            else
                            {
                                //退出循环
                                flag = false;
                            }

                            foreach (var order in orders.Data)
                            {
                                if (orderService.QueryOrderIsExit(order.Oid))
                                {
                                    continue;
                                }
                                //orderIds 为ERP系统返回的单号 如EO1812027249,EO1812027250,
                                string orderIds = bbShopService.AddOrder(order);
                                if (!string.IsNullOrEmpty(orderIds))
                                {
                                    List <string> listorderId = orderIds.Split(',').ToList();
                                    List <string> listOrderId = new List <string>();
                                    foreach (var orderId in listorderId)
                                    {
                                        if (!string.IsNullOrEmpty(orderId))
                                        {
                                            //快递中间表没数据
                                            if (!expService.IsExit(orderId))
                                            {
                                                listOrderId.Add(orderId);
                                            }
                                        }
                                    }
                                    if (listOrderId.Count == 0)
                                    {
                                        continue;
                                    }
                                    //更新订单来源为贝贝
                                    orderService.UpdateOrderSourceTypeID(listOrderId, "031");
                                    if (listOrderId.Count == 1)
                                    {
                                        //没拆单
                                        expService.InsertExpressage(listOrderId[0], " ");
                                        count++;
                                    }
                                    else
                                    {
                                        //拆单
                                        Dictionary <string, string> dicOrder = new Dictionary <string, string>();
                                        foreach (var orderId in listOrderId)
                                        {
                                            List <BbOrderItem> orderList = new List <BbOrderItem>();
                                            foreach (var item in order.Item)
                                            {
                                                orderList.Add(new BbOrderItem {
                                                    Num = item.Num, Outer_id = item.Iid
                                                });
                                            }
                                            dicOrder.Add(orderId, CommonHelper.ToJson(orderList));
                                        }
                                        expService.InsertExpressageAll(dicOrder);
                                        count++;
                                    }
                                }
                            }
                        }
                    }
                }
                if (count > 0)
                {
                    log.Debug("===============贝店订单同步至ERP:" + count + "条数据同步成功=========================");
                }
            }
            catch (Exception e)
            {
                log.Error("执行BbDownloadOrderJob出错" + e);
            }
        }