Exemplo n.º 1
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);
        }
Exemplo n.º 2
0
        public bool InsertUseWallet(UseWallet wallet)
        {
            string            sql       = "";
            DynamicParameters parasuser = new DynamicParameters();

            parasuser.Add("@userCode", wallet.UserCode, System.Data.DbType.String);
            var tempWallet = DapperSqlHelper.FindOne <UseWallet>("SELECT MAX(WalletCode) WalletCode,MAX(Sort) Sort FROM [dbo].[UseWallet]where UserCode=@userCode ", parasuser, false);

            if (tempWallet != null)
            {
                //wallet.WalletCode = Guid.NewGuid().ToString();
                if (tempWallet.Sort == null)
                {
                    wallet.Sort = 1;
                }
                else
                {
                    wallet.Sort = tempWallet.Sort + 1;
                }
            }
            else
            {
                wallet.WalletCode = "1";
                wallet.Sort       = 1;
            }

            sql = @"INSERT INTO [dbo].[UseWallet]([WalletCode],[UserCode] ,[AccountPrincipal]  ,[DonationAmount] ,
            [Ratio]  ,[Status] ,[Sort]) 
            VALUES  ( @WalletCode, 
                      @UserCode, 
                      @AccountPrincipal, 
                      @DonationAmount, 
                      @Ratio, 
                      1, 
                      @Sort)";


            DynamicParameters paras = new DynamicParameters();

            paras.Add("@WalletCode", wallet.WalletCode, System.Data.DbType.String);
            paras.Add("@UserCode", wallet.UserCode, System.Data.DbType.String);
            paras.Add("@AccountPrincipal", wallet.AccountPrincipal, System.Data.DbType.String);
            paras.Add("@DonationAmount", wallet.DonationAmount, System.Data.DbType.String);
            paras.Add("@Ratio", wallet.Ratio, System.Data.DbType.String);
            paras.Add("@Sort", wallet.Sort, System.Data.DbType.Int32);
            int i = DapperSqlHelper.ExcuteNonQuery <UseWallet>(sql, paras, false);

            return(true);
        }
Exemplo n.º 3
0
        public IHttpActionResult InsertUseWallet(UseWallet useWallet)
        {
            LogHelper.WriteLog("InsertUseWallet useWallet" + useWallet?.WalletCode);
            SimpleResult      result   = new SimpleResult();
            IUseWalletService _service = new UseWalletService();

            try
            {
                var list = _service.InsertUseWallet(useWallet);
                result.Resource = list;
                result.Status   = Result.SUCCEED;
            }
            catch (Exception ex)
            {
                LogHelper.WriteLog("InsertUseWallet useWallet" + useWallet.UserCode, ex);
                result.Status = Result.FAILURE;
                result.Msg    = ex.Message;
            }
            LogHelper.WriteLog("InsertUseWallet result" + Json(result));
            return(Json(result));
        }
Exemplo n.º 4
0
        /// <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);
        }