/// <summary>
        /// 充值
        /// </summary>
        /// <param name="userCode"></param>
        /// <param name="order"></param>
        /// <param name="payType"></param>
        /// <returns></returns>
        public financialStatements getDataRechargeRecord(string userCode, string typeCode, UseWallet useWallet, string storeCode, decimal?ratio, string payType)
        {
            ICouponService       _couponService      = new CouponService();
            IRechargeTypeService rt                  = new RechargeTypeService();
            IProductInfoService  _productInfoService = new ProductInfoService();
            ICouponTypeService   _couponTypeService  = new CouponTypeService();
            IUseWalletService    _useWalletService   = new UseWalletService();
            IUserStoreService    _userStoreService   = new UserStoreService();
            IStoreService        _storeService       = new StoreService();
            IUserInfo            _userService        = new UserInfo();
            var rechargetype = rt.GetRechargeTypeByCode(typeCode);
            var uw           = _useWalletService.GetUseWalletCountMoney(userCode);

            if (string.IsNullOrEmpty(storeCode))
            {
                var us = _userStoreService.GetUserStorebyUserCode(userCode);
                storeCode = us.MembershipCardStore;
            }
            var s = _storeService.GetStore(storeCode);
            var u = _userService.GetUserByCode(userCode);
            financialStatements fs = new financialStatements();

            fs.Code           = Guid.NewGuid().ToString();
            fs.CreateTime     = DateTime.Now;
            fs.UserPhone      = u?.Phone;
            fs.UserCreateTime = u?.CreateTime;
            fs.StoreName      = s?.StoreName;
            fs.ProductionType = "体验服务";
            fs.Cstname        = "普通销售";
            fs.ProductionCode = rechargetype?.RechargeTypeCode;
            fs.ProductionName = rechargetype?.RechargeTypeName;
            fs.Iquantity      = 1;
            fs.Itaxunitprice  = useWallet?.AccountPrincipal;
            fs.Isum           = useWallet?.AccountPrincipal;
            fs.CpersonName    = "业务员";
            fs.PayType        = payType;
            fs.AmountOfIncome = useWallet?.AccountPrincipal;
            fs.DonationAmount = useWallet?.DonationAmount;
            fs.CouponUseCode  = "";
            fs.CouponUseMoney = 0;
            fs.UseWalletMoney = uw?.TotalAmount + useWallet?.AccountPrincipal + useWallet?.DonationAmount;

            if (ratio != null)
            {
                fs.Ratio = Math.Round(100 - Convert.ToDouble(ratio) * 100, 2).ToString() + '%';
            }

            fs.UseWalletMoney1           = fs?.UseWalletMoney;
            fs.UseWalletAccountPrincipal = uw?.AccountPrincipal + useWallet?.AccountPrincipal;

            fs.ProductInfoRate = "0";
            return(fs);
        }
        public string  PayOrder(string productCode, string userCode, string peopleCount, DateTime dateTime, decimal money, string storeId, string orderCode = "", string couponCode = "")
        {
            string msg = "SUCCEED";
            IProductInfoService          _productInfoService = new ProductInfoService();
            DateTime                     now                         = DateTime.Now;
            ICouponService               _couponService              = new CouponService();
            IOrderService                _orderService               = new OrderService();
            IUserInfo                    _userService                = new UserInfo();
            IStoreService                _storeService               = new StoreService();
            IUserStoreService            _userStoreService           = new UserStoreService();
            IRecordsOfConsumptionService _recordsOfConsumption       = new RecordsOfConsumptionService();
            IUseWalletService            _useWalletService           = new UseWalletService();
            IFinancialStatementsService  _financialStatementsService = new FinancialStatementService();
            ICouponTypeService           _couponTypeService          = new CouponTypeService();
            var   u  = _userService.GetUserByCode(userCode);
            var   p  = _productInfoService.GetProductInfo(productCode);
            var   s  = _storeService.GetStore(storeId);
            var   uw = _useWalletService.GetUseWalletCountMoney(userCode);
            var   accountPrincipal = _useWalletService.GetUseAccountPrincipalByUserCode(userCode);
            Order order            = new Order();

            order.Money = money;
            int ss = 0;

            if (int.TryParse(peopleCount, out ss))
            {
                order.Number = ss;
            }
            order.PayTime               = now;
            order.StoreCode             = storeId;
            order.UserCode              = userCode;
            order.ProductCode           = productCode;
            order.CreateTime            = now;
            order.ExperienceVoucherCode = couponCode;
            order.AppointmentTime       = dateTime;
            order.WxPrepayId            = string.Empty;
            financialStatements fs = _financialStatementsService.getData(userCode, order, "会员卡");

            using (var scope = new TransactionScope())//创建事务
            {
                if (!string.IsNullOrEmpty(orderCode))
                {
                    var temporder = _orderService.GetOrderByCode(orderCode);
                    if (temporder != null && temporder.UserCode == userCode)
                    {
                        order.OrderCode  = temporder.OrderCode;
                        order.CreateTime = temporder.CreateTime;
                        order.OrderNO    = temporder.OrderNO;
                        _orderService.UpdateOrder(order);
                        msg = temporder.OrderCode;
                    }
                    else
                    {
                        if (string.IsNullOrEmpty(order.OrderCode))
                        {
                            order.OrderCode = Guid.NewGuid().ToString();
                            order.OrderNO   = WxPayApi.GenerateOutTradeNo().ToString();
                            orderCode       = order.OrderCode;
                        }
                        msg = _orderService.InsertOrder(order);
                    }
                }
                else
                {
                    if (string.IsNullOrEmpty(order.OrderCode))
                    {
                        order.OrderCode = Guid.NewGuid().ToString();
                        order.OrderNO   = WxPayApi.GenerateOutTradeNo().ToString();
                        orderCode       = order.OrderCode;
                    }
                    msg = _orderService.InsertOrder(order);
                }
                fs.OrderNo = order?.OrderNO;
                if (money == 0)
                {
                    LogHelper.WriteLog("会员支付0元 " + money);
                    LogHelper.WriteLog("couponCode " + couponCode);
                    _couponService.UsedUpdate(couponCode, userCode, orderCode);

                    LogHelper.WriteLog("financialStatements " + fs.Code);

                    _financialStatementsService.Insert(fs);
                }
                else
                {
                    LogHelper.WriteLog("couponCode " + couponCode);
                    _couponService.UsedUpdate(couponCode, userCode, orderCode);
                    LogHelper.WriteLog("会员支付金额 " + money);
                    decimal?recordsaccountPrincipalTemp = 0m;
                    _useWalletService.UpdateData(userCode, money, orderCode, out recordsaccountPrincipalTemp);
                    LogHelper.WriteLog("会员支付金额 accountPrincipal " + accountPrincipal);
                    LogHelper.WriteLog("会员支付金额 aecordsdonationAmountTemp " + recordsaccountPrincipalTemp);
                    fs.UseWalletAccountPrincipal = accountPrincipal - recordsaccountPrincipalTemp;
                    LogHelper.WriteLog("financialStatements " + fs.Code);

                    _financialStatementsService.Insert(fs);
                }


                scope.Complete();//这是最后提交事务
            }
            return(msg);
        }
        /// <summary>
        /// 购买获取报表的实体
        /// </summary>
        /// <param name="userCode"></param>
        /// <param name="order"></param>
        /// <param name="payType"></param>
        /// <returns></returns>
        public financialStatements getData(string userCode, Order order, string payType)
        {
            ICouponService      _couponService      = new CouponService();
            IProductInfoService _productInfoService = new ProductInfoService();
            ICouponTypeService  _couponTypeService  = new CouponTypeService();
            IUseWalletService   _useWalletService   = new UseWalletService();
            IStoreService       _storeService       = new StoreService();
            IUserInfo           _userService        = new UserInfo();
            var uw = _useWalletService.GetUseWalletCountMoney(userCode);
            var s  = _storeService.GetStore(order.StoreCode);
            var p  = _productInfoService.GetProductInfo(order.ProductCode);
            var u  = _userService.GetUserByCode(userCode);
            financialStatements fs = new financialStatements();

            fs.Code           = Guid.NewGuid().ToString();
            fs.CreateTime     = order.CreateTime;
            fs.UserPhone      = u?.Phone;
            fs.UserCreateTime = u?.CreateTime;
            fs.StoreName      = s?.StoreName;
            fs.OrderNo        = order.OrderNO;
            switch (p.Type)
            {
            case "1":
                fs.ProductionType = "体验服务"; break;

            case "2":
                fs.ProductionType = "硬件产品"; break;

            case "3":
                fs.ProductionType = "水吧服务"; break;

            case "4":
                fs.ProductionType = "衍生品"; break;

            case "5":
                fs.ProductionType = "配件"; break;
            }
            fs.Cstname        = "普通销售";
            fs.ProductionCode = p.ProductCode;
            fs.ProductionName = p.ProductName;
            fs.Iquantity      = order.Number;
            fs.Itaxunitprice  = p.ExperiencePrice;
            if (payType.Equals("微信"))
            {
                fs.Isum = order.Money;
            }
            else
            {
                fs.Isum = p.ExperiencePrice * order.Number;
            }
            fs.CpersonName    = p.CreatorName;
            fs.PayType        = payType;
            fs.AmountOfIncome = order.Money;
            fs.DonationAmount = 0;
            fs.CouponUseCode  = order.ExperienceVoucherCode;
            if (!string.IsNullOrEmpty(order.ExperienceVoucherCode))
            {
                var coupon      = _couponService.GetCouponByCode(order.ExperienceVoucherCode);
                var couponMoney = _couponTypeService.GetCouponTypeByCode(coupon?.CouponTypeCode);
                if (couponMoney != null)
                {
                    fs.CouponUseMoney = couponMoney.Money;
                }
            }
            fs.GetCouponTime = order.CreateTime;
            if (payType.Equals("微信"))
            {
                fs.UseWalletMoney = order.Money;
                fs.Ratio          = "100%";
            }
            else
            {
                fs.UseWalletMoney            = uw.TotalAmount;
                fs.UseWalletMoney1           = fs.UseWalletMoney;
                fs.UseWalletAccountPrincipal = uw.AccountPrincipal;
                if (!string.IsNullOrEmpty(uw.Ratio))
                {
                    fs.Ratio = Math.Round(100 - Convert.ToDouble(uw.Ratio) * 100, 2).ToString() + '%';
                }
                fs.UseWalletMoney            = uw.TotalAmount - order.Money;
                fs.UseWalletAccountPrincipal = uw.AccountPrincipal - order.Money * (1 - Convert.ToDecimal(uw.Ratio));
                if (fs.UseWalletMoney != 0)
                {
                    if (!string.IsNullOrEmpty(uw.Ratio))
                    {
                        fs.Ratio = Math.Round(100 - Convert.ToDouble(uw.Ratio) * 100, 2).ToString() + '%';
                    }
                    else
                    {
                        fs.Ratio = "100%";
                    }
                }
                else
                {
                    fs.Ratio = "100%";
                }
                fs.UseWalletMoney1 = fs.UseWalletMoney;
            }

            fs.ProductInfoRate = p.Rate + "%";
            return(fs);
        }
        /// <summary>
        /// 核销
        /// </summary>
        /// <param name="userCode"></param>
        /// <param name="order"></param>
        /// <param name="payType"></param>
        /// <returns></returns>
        public financialStatements getWriteOff(string wfuserName, string userCode, string orderCode, string payType, decimal?RecordsAccountPrincipalMoney)
        {
            var                 dateTime            = DateTime.Now;
            ICouponService      _couponService      = new CouponService();
            IProductInfoService _productInfoService = new ProductInfoService();
            ICouponTypeService  _couponTypeService  = new CouponTypeService();
            IUseWalletService   _useWalletService   = new UseWalletService();
            IOrderService       _orderService       = new OrderService();
            IStoreService       _storeService       = new StoreService();
            IUserInfo           _userService        = new UserInfo();
            var                 order = _orderService.GetOrderByCode(orderCode);
            var                 uw    = _useWalletService.GetUseWalletCountMoneyWf(userCode);
            var                 s     = _storeService.GetStore(order.StoreCode);
            var                 p     = _productInfoService.GetProductInfo(order.ProductCode);
            var                 u     = _userService.GetUserByCode(userCode);
            financialStatements fs    = new financialStatements();

            fs.OrderNo        = order?.OrderNO;
            fs.Code           = Guid.NewGuid().ToString();
            fs.CreateTime     = dateTime;
            fs.UserPhone      = u?.Phone;
            fs.UserCreateTime = u?.CreateTime;
            fs.StoreName      = s?.StoreName;
            switch (p.Type)
            {
            case "1":
                fs.ProductionType = "体验服务"; break;

            case "2":
                fs.ProductionType = "硬件产品"; break;

            case "3":
                fs.ProductionType = "水吧服务"; break;

            case "4":
                fs.ProductionType = "衍生品"; break;

            case "5":
                fs.ProductionType = "配件"; break;
            }
            fs.Cstname        = "普通销售";
            fs.ProductionCode = "";
            fs.ProductionName = "";
            fs.Iquantity      = 0;
            fs.Itaxunitprice  = 0;
            fs.Isum           = 0;
            fs.CpersonName    = p.CreatorName;
            fs.PayType        = payType;
            fs.AmountOfIncome = 0;
            fs.DonationAmount = 0;
            fs.CouponUseCode  = "";
            fs.CouponUseMoney = 0;
            fs.GetCouponTime  = null;
            if (payType.Equals("微信"))
            {
                fs.UseWalletMoney = order.Money;
                fs.Ratio          = "100%";
            }
            else
            {
                fs.UseWalletMoney            = uw.TotalAmount;
                fs.UseWalletMoney1           = fs.UseWalletMoney;
                fs.UseWalletAccountPrincipal = uw.AccountPrincipal;
                if (!string.IsNullOrEmpty(uw.Ratio))
                {
                    fs.Ratio = Math.Round(100 - Convert.ToDouble(uw.Ratio) * 100, 2).ToString() + '%';
                }
            }
            fs.RecordsOfConsumptionCreateTime = dateTime;
            fs.WriteOffUser    = wfuserName;
            fs.ProductionCode1 = p.ProductCode;
            fs.ProductionName1 = p.ProductName;
            fs.ExperiencePrice = p.ExperiencePrice;
            fs.Iquantity1      = order.Number;
            fs.RecordsMoney    = p.ExperiencePrice * order.Number;
            if (!string.IsNullOrEmpty(order.ExperienceVoucherCode))
            {
                var coupon      = _couponService.GetCouponByCode(order.ExperienceVoucherCode);
                var couponMoney = _couponTypeService.GetCouponTypeByCode(coupon?.CouponTypeCode);
                if (couponMoney != null)
                {
                    fs.CouponUseMoney1   = couponMoney.Money;
                    fs.ActualConsumption = fs.RecordsMoney - fs.CouponUseMoney1;
                    if (fs.ActualConsumption < 0m)
                    {
                        fs.ActualConsumption = 0m;
                    }
                }
            }
            else
            {
                fs.ActualConsumption = fs.RecordsMoney;
            }

            if (payType.Equals("微信"))
            {
                fs.FinancialRevenueAccounting = fs.ActualConsumption;
            }
            else
            {
                fs.FinancialRevenueAccounting = RecordsAccountPrincipalMoney;
            }
            fs.Imoney          = fs.FinancialRevenueAccounting / (Convert.ToDecimal((Convert.ToDouble(p.Rate)) * 0.01) + 1);
            fs.ProductInfoRate = p.Rate + "%";
            fs.Itax            = fs.Imoney * Convert.ToDecimal((Convert.ToDouble(p.Rate)) * 0.01);
            fs.GrossProfit     = fs.Imoney;
            return(fs);
        }