Ejemplo n.º 1
0
 /// <summary>
 /// 取消订单时,删除结算详情
 /// </summary>
 public static void CancelOrder(ContextSession contextSession, CommodityOrder commodityOrder)
 {
     try
     {
         LogHelper.Info("结算单记录退款信息,全部退款,订单ID:" + commodityOrder.Id);
         var sad = SettleAccountsDetails.ObjectSet().Where(s => s.OrderId == commodityOrder.Id).FirstOrDefault();
         if (sad != null)
         {
             foreach (var saoi in SettleAccountsOrderItem.ObjectSet().Where(s => s.OrderId == sad.Id).ToList())
             {
                 contextSession.Delete(saoi);
             }
             contextSession.Delete(sad);
         }
     }
     catch (Exception ex)
     {
         LogHelper.Error("结算单记录退款信息,全部退款,订单ID:" + commodityOrder.Id + ",错误:", ex);
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// 导入自营商家未设置结算价时的结算订单
        /// </summary>
        public static void ImportNotSettleOrder()
        {
            LogHelper.Info("SettleAccountHelper.ImportNotSettleOrder 开始导入未设置结算价的订单");
            try
            {
                ContextSession contextSession = ContextFactory.CurrentThreadContext;
                // 查询商城下APP
                var mallQuery        = MallApply.ObjectSet().Where(m => m.Type == 0 && (m.State.Value == 2 || m.State.Value == 4));
                var startDate        = new DateTime(2017, 9, 1);
                var hadAddOrderQuery = SettleAccountsDetails.ObjectSet().AsQueryable();
                foreach (var mall in mallQuery.ToList())
                {
                    var orderQuery = CommodityOrder.ObjectSet().Where(o =>
                                                                      o.AppId == mall.AppId &&
                                                                      o.EsAppId == mall.EsAppId &&
                                                                      o.PaymentTime > startDate &&
                                                                      o.Payment != 0);
                    var orders = orderQuery.Join(CommodityOrderService.ObjectSet()
                                                 .Where(s => (s.State == 3 || s.State == 7 || s.State == 15)), o => o.Id, s => s.Id, (o, s) => new { s.State, o })
                                 .Where(so => !hadAddOrderQuery.Where(h => h.EsAppId == mall.EsAppId && h.AppId == mall.AppId && h.OrderId == so.o.Id)
                                        .Any(h => h.Id == so.o.Id))
                                 .ToList();
                    if (orders.Count > 0)
                    {
                        // 生成结算项
                        foreach (var so in orders)
                        {
                            SettleAccountHelper.CreateSettleAccountDetails(contextSession, so.o, mall, so.State);
                        }
                    }
                }
                contextSession.SaveChanges();
            }
            catch (Exception ex)
            {
                LogHelper.Error(string.Format("SettleAccountHelper.ImportNotSettleOrder 异常", ex));
            }
            LogHelper.Info("SettleAccountHelper.ImportNotSettleOrder 结束导入未设置结算价的订单");

            ImportNotSettleGoldOrder();
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 导入自营商家未设置结算价时的金币支付订单
        /// </summary>
        public static void ImportNotSettleGoldOrder()
        {
            LogHelper.Info("SettleAccountHelper.ImportNotSettleGoldOrder 开始导入未设置结算价的金币支付订单");
            try
            {
                ContextSession contextSession = ContextFactory.CurrentThreadContext;
                // 查询商城下APP
                var mallQuery = MallApply.ObjectSet().Where(m => m.Type == 0 && (m.State.Value == 2 || m.State.Value == 4));
                //var startDate = new DateTime(2017, 9, 1);
                var        hadAddOrderQuery = SettleAccountsDetails.ObjectSet().AsQueryable();
                ContextDTO contextDTO       = AuthorizeHelper.CoinInitAuthorizeInfo();
                // 生成结算项
                List <object> saveList = new List <object>();
                foreach (var mall in mallQuery.ToList())
                {
                    var orderQuery = CommodityOrder.ObjectSet().Where(o =>
                                                                      o.AppId == mall.AppId &&
                                                                      o.EsAppId == mall.EsAppId &&
                                                                      o.PaymentTime > mall.SubTime &&
                                                                      o.Payment == 0);
                    var orders = orderQuery.Join(CommodityOrderService.ObjectSet()
                                                 .Where(s => (s.State == 15)), o => o.Id, s => s.Id, (o, s) => o)
                                 .Where(o => !hadAddOrderQuery.Where(h => h.EsAppId == mall.EsAppId && h.AppId == mall.AppId && h.OrderId == o.Id)
                                        .Any(h => h.Id == o.Id))
                                 .ToList();
                    if (orders.Count > 0)
                    {
                        foreach (var o in orders)
                        {
                            LogHelper.Info("ImportNotSettleGoldOrder,导入自营商家未设置结算价时的金币支付订单,开始生成结算单,OrderId:" + o.Id);
                            var sa = SettleAccountHelper.CreateSettleAccount(contextSession, o, mall);
                            if (sa != null)
                            {
                                Jinher.AMP.App.Deploy.CustomDTO.AppIdOwnerIdTypeDTO applicationDTO = APPSV.Instance.GetAppOwnerInfo(o.AppId, contextDTO);
                                // 打款
                                var confirmDto = OrderSV.BuildConfirmPayDTOAfterSales(contextSession, o, out saveList, applicationDTO, isSaveObject: false);
                                LogHelper.Info("导入自营商家未设置结算价时的金币支付订单,开始打款,OrderId:" + o.Id + "ConfirmPayDTO: " + JsonHelper.JsonSerializer(confirmDto));
                                var goldPayResult = Jinher.AMP.BTP.TPS.FSPSV.Instance.ConfirmPay(confirmDto);
                                if (goldPayResult.Code != 0)
                                {
                                    // 打款失败
                                    sa.IsPaySuccess = false;
                                    LogHelper.Info("导入自营商家未设置结算价时的金币支付订单,结束打款,失败,OrderId:" + o.Id);

                                    var errorInfo = JsonHelper.JsonSerializer(goldPayResult);
                                    LogHelper.Error("OrderSV.CreateSettleAccount 生成结算单,打款异常,OrderId: " + o.Id + " ReturnInfoDTO: " + errorInfo);
                                    SettleAccountsException exception = new SettleAccountsException();
                                    exception.Id             = sa.Id;
                                    exception.OrderId        = o.Id;
                                    exception.OrderCode      = o.Code;
                                    exception.OrderRealPrice = o.RealPrice;
                                    exception.ClearingPrice  = sa.SellerAmount;
                                    exception.ExceptionInfo  = errorInfo;
                                    exception.AppId          = sa.AppId;
                                    exception.AppName        = sa.AppName;
                                    exception.EntityState    = EntityState.Added;
                                    contextSession.SaveObject(exception);
                                }
                                else
                                {
                                    // 打款成功
                                    sa.IsPaySuccess = true;
                                    LogHelper.Info("导入自营商家未设置结算价时的金币支付订单,结束打款,成功,OrderId:" + o.Id);
                                }
                                LogHelper.Info("ImportNotSettleGoldOrder,导入自营商家未设置结算价时的金币支付订单,结束生成结算单,OrderId:" + o.Id);
                            }
                        }
                    }
                }
                if (saveList != null && saveList.Any())
                {
                    foreach (var o in saveList)
                    {
                        contextSession.SaveObject(o);
                    }
                }
                contextSession.SaveChanges();
            }
            catch (Exception ex)
            {
                LogHelper.Error(string.Format("SettleAccountHelper.ImportNotSettleGoldOrder 异常", ex));
            }
            LogHelper.Info("SettleAccountHelper.ImportNotSettleGoldOrder 结束导入未设置结算价的金币支付订单");
        }