Exemple #1
0
 public ThirdPartyDistributionAPIController(ShopDbContext shopDb, IOptions <ThirdConfig> poptions, IMapper mapper) : base(shopDb)
 {
     this.shopDb      = shopDb;
     this.thirdConfig = poptions.Value;
     this.parameter   = new ExThirdPartyDistributionParameter(thirdConfig);
     this._mapper     = mapper;
 }
Exemple #2
0
        /// <summary>
        /// 完成订单
        /// </summary>
        /// <param name="printDbContext"></param>
        /// <param name="db"></param>
        /// <param name="options"></param>
        /// <param name="shopOrderid"></param>
        /// <param name="_logger"></param>
        static void OrderFinish(PrintDbContext printDbContext, ShopDbContext db,
                                WechatTemplateSendOptions options, ThirdConfig toptions, ShopOrder shopOrder, ILogger _logger)
        {
            shopOrder.PayTime = DateTime.Now;
            shopOrder.Status  = ShopOrderStatus.已支付;
            db.SaveChanges();

            //获取订单中商品的数量
            var commodityIdAndCounts = db.Query <ShopOrderItem>()
                                       .Where(m => m.ShopOrderId == shopOrder.Id)
                                       .Where(m => !m.IsDel)
                                       .Select(m => new
            {
                m.CommodityStock.Sku.CommodityId,
                m.Count
            })
                                       .ToList()
                                       .GroupBy(m => m.CommodityId)
                                       .ToDictionary(m => m.Key, m => m.Select(x => x.Count).Sum());

            //更新商品的销售量
            //注意,这里如果有一个品牌,多个店铺的情况,会出现销售额共享的情况
            var commodityIds = commodityIdAndCounts.Select(m => m.Key).ToList();
            var commoditys   = db.Query <ShopBrandCommodity>()
                               .Where(m => commodityIds.Contains(m.Id))
                               .ToList();

            foreach (var item in commoditys)
            {
                item.SalesForMonth += commodityIdAndCounts[item.Id];
            }
        }
Exemple #3
0
        public SwiftpassPayController(ICommunityService communityService
                                      //, IOptions<SwiftpassPayOptions> options
                                      , FinanceDbContext db
                                      , IOptions <ShopConglomerationOrderOptions> shopConglomerationOrderServer
                                      , PayProxyFactory proxyFactory
                                      , WechatCoreDbContext wechatCoreDb
                                      , PrintDbContext printDbContext
                                      , ShopDbContext shopdb
                                      , MemberDbContext memberDbContext
                                      , ILoggerFactory loggerFactory
                                      , IOptions <WechatTemplateSendOptions> woptions
                                      , IOptions <ThirdConfig> toptions


                                      , IHostingEnvironment hostingEnvironment)
        {
            this.hostingEnvironment = hostingEnvironment;
            this.woptions           = woptions.Value;
            //this.options = options.Value;
            // this.db = ZRui.Web.BLL.DbContextFactory.FinanceDbContext;
            this.db               = db;
            this.shopdb           = shopdb;
            this.printDbContext   = printDbContext;
            this.wechatCoreDb     = wechatCoreDb;
            this.proxyFactory     = proxyFactory;
            this._memberDbContext = memberDbContext;

            _shopConglomerationOrderServer = shopConglomerationOrderServer.Value;
            _logger          = loggerFactory.CreateLogger <SwiftpassPayController>();
            this.thirdConfig = toptions.Value;
        }
Exemple #4
0
 public ThirdAPIController(IOptions <MemberAPIOptions> options, IOptions <ThirdConfig> poptions, ShopDbContext db, MemberDbContext memberDb, WechatCoreDbContext wechatCoreDb, IMapper mapper) : base(options, memberDb, wechatCoreDb)
 {
     this._db = db;
     //this.thirdServer = thirdServer;
     this._mapper     = mapper;
     this.thirdConfig = poptions.Value;
 }
Exemple #5
0
 /// <summary>
 /// 在后台任务中完成订单
 /// </summary>
 /// <param name="shopOrderId"></param>
 public static void SetShopOrderFinish(int shopOrderId)
 {
     using (ShopDbContext shopDb = DbContextFactory.ShopDb)
     {
         using (var printDbContext = DbContextFactory.PrintDb)
         {
             ILogger     logger      = ServiceLocator.Instance.GetService <ILoggerFactory>().CreateLogger <ShopOrderUtil>();
             ShopOrder   shopOrder   = shopDb.GetSingle <ShopOrder>(shopOrderId);
             ThirdConfig thirdConfig = ServiceLocator.Instance.GetService <IOptions <ThirdConfig> >().Value;
             WechatTemplateSendOptions wechatTemplateSend = ServiceLocator.Instance.GetService <IOptions <WechatTemplateSendOptions> >().Value;
             shopOrder.PayWay = "会员余额支付";
             shopOrder.SetShopOrderFinish(printDbContext, shopDb, wechatTemplateSend, thirdConfig, logger);
         }
     }
 }
Exemple #6
0
 public WechatPayController(ICommunityService communityService
                            , IOptions <WechatTemplateSendOptions> options
                            , IOptions <ThirdConfig> poptions
                            , PayProxyFactory proxyFactory
                            , FinanceDbContext db
                            , WechatCoreDbContext wechatCoreDb
                            , PrintDbContext printDbContext
                            , ShopDbContext shopDb
                            , ILoggerFactory loggerFactory
                            , IHostingEnvironment hostingEnvironment)
 {
     this.hostingEnvironment = hostingEnvironment;
     this.options            = options.Value;
     this.db             = db;
     this.shopDb         = shopDb;
     this.printDbContext = printDbContext;
     this.wechatCoreDb   = wechatCoreDb;
     this.proxyFactory   = proxyFactory;
     this.thirdConfig    = poptions.Value;
     _logger             = loggerFactory.CreateLogger <WechatPayController>();
 }
Exemple #7
0
        public ShopOrderAPIController(
            IOptions <MemberAPIOptions> options
            , IOptions <WechatTemplateSendOptions> tOption
            , ShopDbContext db
            , ILoggerFactory loggerFactory
            , WechatCoreDbContext wechatCoreDb
            , MemberDbContext memberDb
            , IHostingEnvironment hostingEnvironment
            , IOptions <ThirdConfig> pOption

            // , ThirdServer thirdServer
            )
            : base(options, memberDb, wechatCoreDb)
        {
            this.db = db;
            wechatTemplateSendOptions = tOption.Value;
            this.hostingEnvironment   = hostingEnvironment;
            _logger = loggerFactory.CreateLogger <ShopOrderAPIController>();
            //  this.thirdServer = thirdServer;
            this.thirdConfig = pOption.Value;
        }
Exemple #8
0
        /// <summary>
        /// 处理达达预发单信息发起订单
        /// </summary>
        /// <param name="db"></param>
        /// <param name="thirdConfig"></param>
        /// <param name="model"></param>
        /// <param name="_logger"></param>
        public static void ThirdAfterOrder(ShopDbContext db, ThirdConfig thirdConfig, ShopOrder model, ILogger _logger)
        {
            try
            {
                var queryfee = db.ThirdApiData.FirstOrDefault(r => r.OrderId == model.OrderNumber && r.JsonData == "QueryFee");
                if (queryfee != null)
                {
                    var         queryfeedata = JsonConvert.DeserializeObject <CallbackAfterOrder>(queryfee.ResultData);
                    ThirdServer thirdServer  = new ThirdServer(db, thirdConfig);
                    var         result       = thirdServer.CallbackAfter(new AddAfterQuery()
                    {
                        deliveryNo = queryfeedata.result.deliveryNo
                        ,
                        Fee         = queryfeedata.result.fee,
                        OrderNumber = model.OrderNumber,
                        ShopId      = model.ShopId
                    });
                    if (result.errorCode == 0 || result.status == "success")
                    {
                        _logger.LogInformation($"===========回调达达发单成功 更改订单状态为待接单=============");

                        model.Status = ShopOrderStatus.待接单;
                    }
                    else
                    {
                        _logger.LogInformation($"===========回调达达发单失败 原因{result.msg}=============");
                    }
                }
                else
                {
                    _logger.LogInformation($"===========回调达达发单失败 未找到订单预发单信息=============");
                }
            }
            catch (Exception ex)
            {
                _logger.LogInformation($"=========== ThirdAfterOrder Exception {ex.Message}=============");
            }
        }
Exemple #9
0
 public SwiftpassPayForShopWechatOpenAPIController(IOptions <MemberAPIOptions> memberOptions
                                                   //, FinanceDbContext db
                                                   , IOptions <ThirdConfig> poptions
                                                   , IOptions <WechatTemplateSendOptions> options
                                                   , ShopDbContext shopDb
                                                   , Core.Printer.Data.PrintDbContext printDbContext
                                                   , PayProxyFactory proxyFactory
                                                   , WechatCoreDbContext wechatCoreDb
                                                   , MemberDbContext memberDb
                                                   , ILoggerFactory loggerFactory
                                                   , IHostingEnvironment hostingEnvironment) : base(memberOptions, memberDb, wechatCoreDb)
 {
     this.hostingEnvironment = hostingEnvironment;
     this.finaceDb           = DbContextFactory.FinanceDbContext;
     this.options            = options.Value;
     this.shopDb             = shopDb;
     this.wechatCoreDb       = wechatCoreDb;
     this.memberDb           = memberDb;
     this.LogDbContext       = DbContextFactory.LogDbContext;
     this.printDbContext     = printDbContext;
     this.thirdConfig        = poptions.Value;
     this._logger            = loggerFactory.CreateLogger <SwiftpassPayForShopWechatOpenAPIController>();
     this.proxyFactory       = proxyFactory;
 }
Exemple #10
0
 public ThirdServer(ShopDbContext shopDb, ThirdConfig options)
 {
     this.shopDb       = ZRui.Web.BLL.DbContextFactory.ShopDb;
     this.parameter    = new ExThirdPartyDistributionParameter(options);
     this.thirdoptions = options;
 }
Exemple #11
0
        static void SetShopOrderFinish(PrintDbContext printDbContext, ShopDbContext db,
                                       MemberTradeForRechange memberTradeForRechange, WechatTemplateSendOptions options, ThirdConfig toptions, ILogger _logger)
        {
            if (!memberTradeForRechange.ShopOrderId.HasValue)
            {
                throw new Exception("memberTradeForRechange.ShopOrderId is null");
            }
            var shopOrder = db.ShopOrders.FirstOrDefault(p => p.Id == memberTradeForRechange.ShopOrderId.Value);

            shopOrder.PayWay = "微信支付";
            memberTradeForRechange.Status = MemberTradeForRechangeStatus.成功;
            db.SaveChanges();
            OrderFinish(printDbContext, db, options, toptions, shopOrder, _logger);
            var shopName = db.Query <Shop>()
                           .Where(m => m.Id == shopOrder.ShopId)
                           .Select(m => m.Name)
                           .FirstOrDefault();

            AfterOrderPlacing(printDbContext, db, toptions, shopOrder, shopName, options, _logger);
        }
Exemple #12
0
        public static void SetFinish(this MemberTradeForRechange rechange, PrintDbContext printDbContext, ThirdConfig toptions, ShopDbContext shopDb, DbContext db, WechatTemplateSendOptions options, PayResponseBaseHandler result, ILogger _logger)
        {
            if (result.TradeState != "NOTPAY")
            {
                if (rechange.Status == MemberTradeForRechangeStatus.未完成)
                {
                    if (rechange.TotalFee != result.TotalFee)
                    {
                        throw new Exception("指定的金额不对应");
                    }
                    rechange.OutBank          = result.Xml;
                    rechange.MechanismTradeNo = result.TransactionId;
                    switch (result.TradeState)
                    {
                    case "SUCCESS":
                        db.SetMemberTradeForRechangeSuccess(rechange);
                        if (rechange.OrderType == OrderType.充值订单)
                        {
                            SetShopMemberRechangeFinish(rechange, shopDb);
                        }
                        else
                        {
                            SetShopOrderFinish(printDbContext, shopDb, rechange, options, toptions, _logger);
                        }
                        break;

                    case "CLOSED":
                        rechange.Status = MemberTradeForRechangeStatus.取消;
                        break;

                    default:
                        db.SetMemberTradeForRechangeFail(rechange, result.TradeState);
                        break;
                    }
                }
            }
        }
Exemple #13
0
        /// <summary>
        /// 直接设置订单完成
        /// </summary>
        /// <param name="shopOrder"></param>
        /// <param name="printDbContext"></param>
        /// <param name="db"></param>
        /// <param name="options"></param>
        /// <param name="_logger"></param>
        public static void SetShopOrderFinish(this ShopOrder shopOrder, PrintDbContext printDbContext,
                                              ShopDbContext db, WechatTemplateSendOptions options, ThirdConfig toptions, ILogger _logger)
        {
            OrderFinish(printDbContext, db, options, toptions, shopOrder, _logger);
            var shopName = db.Query <Shop>()
                           .Where(m => m.Id == shopOrder.ShopId)
                           .Select(m => m.Name)
                           .FirstOrDefault();

            AfterOrderPlacing(printDbContext, db, toptions, shopOrder, shopName, options, _logger);
        }
Exemple #14
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);
        }
Exemple #15
0
        public static void SetFinish(this MemberTradeForRechange rechange, PrintDbContext printDbContext, ShopDbContext shopDb, DbContext db, WechatTemplateSendOptions options, ThirdConfig toptions, ILogger _logger)
        {
            if (rechange.ShopOrderId != 0)
            {
                if (rechange.OrderType == OrderType.充值订单)
                {
                    SetShopMemberRechangeFinish(rechange, shopDb);
                }
                else
                {
                    SetShopOrderFinish(printDbContext, shopDb, rechange, options, toptions, _logger);
                }
            }
            if (rechange.ConglomerationOrderId != 0)
            {
                _logger.LogInformation("进入回调,拼团订单");

                try
                {
                    SetConglomerationOrderFinish(printDbContext, shopDb, rechange, options, _logger);
                }
                catch (Exception e)
                {
                    _logger.LogInformation($"回调错误,错误信息:{ e}");

                    throw;
                }
            }
        }
Exemple #16
0
        /// <summary>
        /// 订单下单后进行的操作
        /// </summary>
        static async void AfterOrderPlacing(PrintDbContext printDbContext, ShopDbContext db, ThirdConfig thirdConfig, ShopOrder shopOrder, string shopName, WechatTemplateSendOptions options, ILogger _logger)
        {
            //是否外卖单
            if (shopOrder.IsTakeOut)
            {
                //var takeOutInfo = db.Query<ShopTakeOutInfo>()
                //.Where(m => !m.IsDel)
                //.Where(m => m.ShopId == shopOrder.ShopId)
                //.FirstOrDefault();
                ////自动接单
                //if (takeOutInfo!=null && takeOutInfo.AutoTakeOrdre)
                //{
                //    shopOrder.Status = ShopOrderStatus.已确认;
                //    PrintOrder(printDbContext, db, shopOrder, shopName, _logger);
                //}
                PrintOrder(printDbContext, db, shopOrder, shopName, _logger);
            }
            else
            {
                PrintOrder(printDbContext, db, shopOrder, shopName, _logger);
            }


            if (!shopOrder.IsSend)
            {
                var receiver = db.Query <ShopOrderReceiver>()
                               .Where(m => !m.IsDel)
                               .Where(m => m.IsUsed)
                               .Where(m => m.ShopId == shopOrder.ShopId)
                               .Select(m => m.ReceiverOpenId)
                               .Distinct()
                               .ToList();
                receiver.ForEach(o =>
                                 shopOrder.SendTemplateMessage(db, options, o, _logger));
            }
            shopOrder.IsSend = true;

            if (!shopOrder.ShopPartId.HasValue && !shopOrder.ShopOrderSelfHelpId.HasValue)
            {
                var shoptakeoutinfo      = db.ShopTakeOutInfo.FirstOrDefault(r => r.ShopId == shopOrder.ShopId && !r.IsDel);
                var shopordertakeoutinfo = db.ShopOrderTakeouts.FirstOrDefault(r => r.ShopOrderId == shopOrder.Id && !r.IsDel);
                if (shoptakeoutinfo != null && shoptakeoutinfo.TakeDistributionType == TakeDistributionType.达达配送 && shopordertakeoutinfo.TakeWay == TakeWay.送货上门)
                {
                    //  await ThirdOrderFinish(db, thirdConfig, shopOrder, _logger, ExSource.支付成功);

                    ThirdAfterOrder(db, thirdConfig, shopOrder, _logger);
                }
            }



            db.SaveChanges();
            _logger.LogInformation("=================其他订单回调完成===============");
        }
Exemple #17
0
        public static async Task <CThirdRechargeQueryResult> ThirdAmountFinish(ShopDbContext db, ThirdConfig thirdConfig, CThirdShopRechargeQueryModel model)
        {
            ThirdServer thirdServer = new ThirdServer(db, thirdConfig);

            return(await thirdServer.ThirdShopRechargeQuery(model));
        }