示例#1
0
        public bool UpdateData(string userCode, decimal money, string OrderCode, out decimal?recordsaccountPrincipalTemp)
        {
            IRecordsOfConsumptionService _recordsOfConsumption = new RecordsOfConsumptionService();
            decimal           total       = 0;
            decimal?          kouchumoney = 0m;
            IList <UseWallet> list        = GetUseWallet(userCode);

            list = list.OrderBy(t => t.Sort).ToList();
            decimal?recordsdonationAmount   = 0m;
            decimal?recordsaccountPrincipal = 0m;

            foreach (var w in list)
            {
                if (w.AccountPrincipal > 0)
                {
                    //var ratio = decimal.Parse(w.Ratio);
                    var ratio     = Convert.ToDecimal(w.Ratio);
                    var tempTotal = decimal.Parse((w.AccountPrincipal + w.DonationAmount).ToString());
                    total = total + tempTotal;
                    var     tempmoney        = money - total;
                    decimal?donationAmount   = 0;
                    decimal?accountPrincipal = 0;
                    if (tempmoney >= 0)
                    {
                        donationAmount          = 0;
                        accountPrincipal        = 0;
                        kouchumoney             = kouchumoney + w.AccountPrincipal + w.DonationAmount;
                        recordsdonationAmount   = recordsdonationAmount + w.DonationAmount;
                        recordsaccountPrincipal = recordsaccountPrincipal + w.AccountPrincipal;
                    }
                    else
                    {
                        donationAmount          = w.DonationAmount - ((money - kouchumoney) - ((money - kouchumoney) * (1 - ratio)));
                        accountPrincipal        = w.AccountPrincipal - (money - kouchumoney) * (1 - ratio);
                        recordsdonationAmount   = recordsdonationAmount + ((money - kouchumoney) - ((money - kouchumoney) * (1 - ratio)));
                        recordsaccountPrincipal = recordsaccountPrincipal + (money - kouchumoney) * (1 - ratio);
                    }
                    DynamicParameters paras = new DynamicParameters();
                    paras.Add("@WalletCode", w.WalletCode, System.Data.DbType.String);
                    paras.Add("@DonationAmount", donationAmount, System.Data.DbType.Decimal);
                    paras.Add("@AccountPrincipal", accountPrincipal, System.Data.DbType.Decimal);
                    string sql = "update [dbo].[UseWallet] set AccountPrincipal=@AccountPrincipal,DonationAmount=@DonationAmount where WalletCode=@WalletCode";
                    int    i   = DapperSqlHelper.ExcuteNonQuery <UseWallet>(sql, paras, false);
                }
                if (total >= money)
                {
                    _recordsOfConsumption.InsertRecore("0", userCode, money, "", recordsdonationAmount, recordsaccountPrincipal, OrderCode, false);
                    recordsaccountPrincipalTemp = recordsaccountPrincipal;
                    return(true);
                }
            }
            recordsaccountPrincipalTemp = recordsaccountPrincipal;
            return(true);
        }
示例#2
0
        public bool Recharge(string typeCode, string userCode, decimal?money = 0, string storeCode = "")
        {
            IRechargeTypeService         s  = new RechargeTypeService();
            IRecordsOfConsumptionService cs = new RecordsOfConsumptionService();
            IUseWalletService            us = new UseWalletService();
            IFinancialStatementsService  _financialStatementsService = new FinancialStatementService();
            var     type           = s.GetRechargeTypeByCode(typeCode);
            var     explain        = "";
            decimal?donationAmount = 0;
            decimal?ratio          = 0;

            if (money > 0 && type == null)
            {
                typeCode = "0";
                ratio    = 0;
                explain  = "充值类型:任意金额,本金:" + money;
            }
            else
            {
                donationAmount = type.DonationAmount;
                money          = type.Money;
                ratio          = donationAmount / (money + donationAmount);
                explain        = "充值类型" + type.RechargeTypeName + ",本金:" + money + ",赠送:+" + donationAmount;
            }
            UseWallet wallet = new UseWallet()
            {
                WalletCode        = Guid.NewGuid().ToString(),
                UserCode          = userCode,
                AccountPrincipal  = money,
                DonationAmount    = donationAmount,
                Ratio             = decimal.Round(decimal.Parse(ratio.ToString()), 4).ToString(),
                Status            = true,
                Sort              = 1,
                IsMissionGiveaway = false
            };

            using (var scope2 = new TransactionScope())//创建事务
            {
                var fs = _financialStatementsService.getDataRechargeRecord(userCode, typeCode, wallet, storeCode, ratio, "微信");
                LogHelper.WriteLog("报表表数据更新完成");
                _financialStatementsService.Insert(fs);
                //钱包
                us.InsertUseWallet(wallet);
                //消费记录
                cs.InsertRecore(typeCode, userCode, decimal.Parse(money.ToString()), explain, null, null, null);
                scope2.Complete();
            }
            //充值
            //InsertRechargeRecord(record);
            return(true);
        }
        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);
        }