Esempio n. 1
0
        public async Task <APIResult> CTestThird([FromBody] ThirdOrderAPIModels model)
        {
            var order = new ShopOrder()
            {
                AddTime     = DateTime.Now,
                MemberId    = 0,
                ShopId      = model.ShopId,
                Remark      = "达达配送",
                AddUser     = $"member",
                AddIp       = GetIp(),
                Flag        = Guid.NewGuid().ToString(),
                IsTakeOut   = true,
                Status      = ShopOrderStatus.待支付,
                OrderNumber = model.OrderId
                              //TakeDistributionType = args.TakeDistributionType
            };

            db.Add(order);

            //处理达达配送
            ThirdServer thirdServer     = new ThirdServer(db, thirdConfig);
            var         shoptakeoutinfo = db.ShopTakeOutInfo.FirstOrDefault(r => r.ShopId == model.ShopId && !r.IsDel);

            if (shoptakeoutinfo.TakeDistributionType == TakeDistributionType.达达配送)
            {
                var merchant = db.Merchant.FirstOrDefault(r => r.ShopId == model.ShopId);
                if (merchant == null)
                {
                    throw new Exception("商户未在达达开户");
                }
                var thirdshop = db.ThirdShop.FirstOrDefault(r => r.ShopId == model.ShopId);
                if (thirdshop == null)
                {
                    throw new Exception("商户门店不存在");
                }
                model.thirdShopAddOrderModel.origin_id = model.OrderId;
                var result = await thirdServer.ThirdAddOrder(model.thirdShopAddOrderModel, null);

                if (result.errorCode == 0 || result.status == "success")
                {
                    db.ThirdMoneyReport.Add(new Data.ThirdMoneyReport()
                    {
                        OrderNumber = model.OrderId,
                        Amount      = result.result.fee,
                        AddTime     = DateTime.Now,
                        ProduceType = Data.ProduceType.发起订单
                    });
                }
                db.SaveChanges();
                return(Success(result));
            }
            return(Error("error"));
        }
Esempio n. 2
0
        /// <summary>
        /// 达达配送
        /// </summary>
        /// <param name="db"></param>
        /// <param name="shopOrderid"></param>
        /// <param name="_logger"></param>
        public static async Task <ThirdAddOrderResult> ThirdOrderFinish(ShopDbContext db, ThirdConfig toptions, ShopOrder model, ILogger _logger, ExSource exSource)
        {
            var result = new ThirdAddOrderResult();

            try
            {
                _logger.LogInformation("===========开始OrderFinish=============");

                if (model == null)
                {
                    _logger.LogInformation($"============订单不存在============");
                }
                var shoptakeoutinfo = db.ShopTakeOutInfo.FirstOrDefault(r => r.ShopId == model.ShopId && !r.IsDel);
                if (shoptakeoutinfo != null && shoptakeoutinfo.TakeDistributionType == TakeDistributionType.达达配送 && model.IsTakeOut)
                {
                    _logger.LogInformation($"===========开始处理达达配送业务=============");
                    _logger.LogInformation($"===========订单信息:{JsonConvert.SerializeObject(model)}=============");
                    double fee = 0;
                    model.Status = exSource == ExSource.发起支付 ? ShopOrderStatus.待支付 : ShopOrderStatus.待接单;
                    ThirdServer thirdServer = new ThirdServer(db, toptions);
                    var         merchant    = db.Merchant.FirstOrDefault(r => r.ShopId == model.ShopId);
                    if (merchant == null)
                    {
                        _logger.LogInformation($"============商户ID{model.ShopId}未在达达开户============");
                    }
                    var thirdshop = db.ThirdShop.FirstOrDefault(r => r.ShopId == model.ShopId && r.Status == Data.ThirdShop.ShopStatus.门店激活);
                    if (thirdshop == null)
                    {
                        _logger.LogInformation($"============商户ID{model.ShopId}商户门店不存在============");
                    }
                    var shopordertakeout = db.ShopOrderTakeouts.FirstOrDefault(r => r.ShopOrderId == model.Id && !r.IsDel);
                    if (shoptakeoutinfo == null)
                    {
                        _logger.LogInformation($"============商户ID{model.ShopId}订单外卖信息不存在============");
                    }
                    //处理达达配送
                    var thirddshopaddmodel = new ThirdShopAddOrderModel()
                    {
                        ShopId    = model.ShopId,
                        origin_id = model.OrderNumber,//DateTime.Now.Ticks + CommonUtil.CreateNoncestr(5),//
                        //shop_no = "11047059",//测试
                        shop_no          = thirdshop.OriginShopId,
                        cargo_type       = -1,
                        cargo_price      = model.Amount,
                        city_code        = "0769",
                        is_prepay        = 0,
                        origin_mark      = "HCHH",
                        origin_mark_no   = model.OrderNumber,
                        receiver_lng     = shopordertakeout.Longitude.Value,
                        receiver_lat     = shopordertakeout.Latitude.Value,
                        receiver_phone   = shopordertakeout.Phone,
                        receiver_address = shopordertakeout.Address,
                        receiver_name    = shopordertakeout.Name,
                        callback         = toptions.CallBackUrl,
                    };
                    _logger.LogInformation($"============商户ID{model.ShopId}达达配送信息:{JsonConvert.SerializeObject(thirddshopaddmodel)}============");
                    result = await thirdServer.ThirdAddOrder(thirddshopaddmodel, model);

                    _logger.LogInformation($"============商户ID{model.ShopId}达达发单返回信息:{JsonConvert.SerializeObject(result)}============");
                    if (result.errorCode != 0 || result.status != "success")
                    {
                        _logger.LogInformation($"============商户ID{model.ShopId}达达发单失败。原因:{result.msg}============");
                        return(result);
                    }
                    // db.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                _logger.LogInformation($"===========OrderFinish出现异常==============");
                _logger.LogInformation($"============{ex.Message} {ex.StackTrace}============");
            }
            return(result);
        }