예제 #1
0
        /// <summary>
        /// 提款申请
        /// </summary>
        /// <param name="widthdrawinfo"></param>
        /// <returns></returns>
        public async Task <OperationResult> Widthdraw(WidthdrawInfo widthdrawInfo)
        {
            UserRepository.UnitOfWork.TransactionEnabled = true;
            //验证用户
            User user = await UserManager.FindByIdAsync(widthdrawInfo.UserId);

            if (user == null)
            {
                return(new OperationResult(OperationResultType.QueryNull));
            }
            //验证密码
            if (!await UserManager.CheckPasswordAsync(user, widthdrawInfo.Password))
            {
                return(new OperationResult(OperationResultType.Error, "密码错误"));
            }
            //验证资金
            if (user.UserExtend.RmbCoin < widthdrawInfo.Amount)
            {
                return(new OperationResult(OperationResultType.Error, "提现金额大于账户余额"));
            }


            user.UserExtend.RmbCoin -= widthdrawInfo.Amount;

            //提款记录
            RmbCoinTransaction transaction = new RmbCoinTransaction()
            {
                Amount        = -widthdrawInfo.Amount,
                Type          = RmbTransactionType.Withdraw,
                State         = TransactionState.UnConfirmed,
                Direction     = TransactionDirection.Expend,
                RealAmount    = -widthdrawInfo.Amount,
                CreatedTime   = DateTime.Now,
                StreamId      = DateTime.Now.ToString("yyMMddHHmmss") + new Random().GetRandomNumberString(4),//生成序列号
                Remark        = "提现",
                OtherSideInfo = widthdrawInfo.BankName,
                Fee           = 0,
                Preferential  = 0,
                User          = user
            };
            await RmbCoinTransactionRepository.InsertAsync(transaction);

            user.RmbCoinTransactions.Add(transaction);

            IdentityResult result;

            result = await UserManager.UpdateAsync(user);

            if (!result.Succeeded)
            {
                return(result.ToOperationResult());
            }
            return(await UserRepository.UnitOfWork.SaveChangesAsync() > 0
                    ? new OperationResult(OperationResultType.Success, $"提款申请成功")
                    : OperationResult.NoChanged);
        }
예제 #2
0
        /// <summary>
        /// 转账
        /// </summary>
        /// <param name="transactionInfo"></param>
        /// <returns></returns>
        public async Task <OperationResult> Transaction(TransactionInfo transactionInfo)
        {
            UserRepository.UnitOfWork.TransactionEnabled = true;
            //验证用户
            User user = await UserManager.FindByIdAsync(transactionInfo.UserId);

            if (user == null)
            {
                return(new OperationResult(OperationResultType.QueryNull));
            }
            //验证收款方账号
            User otherSizeUser = await UserManager.FindByNameAsync(transactionInfo.OtherSizeUserName);

            if (otherSizeUser == null)
            {
                return(new OperationResult(OperationResultType.QueryNull));
            }
            //验证密码
            if (!await UserManager.CheckPasswordAsync(user, transactionInfo.Password))
            {
                return(new OperationResult(OperationResultType.Error, "密码错误"));
            }
            //验证资金
            if (user.UserExtend.RmbCoin < transactionInfo.Amount)
            {
                return(new OperationResult(OperationResultType.Error, "提现金额大于账户余额"));
            }


            user.UserExtend.RmbCoin          -= transactionInfo.Amount;
            otherSizeUser.UserExtend.RmbCoin += transactionInfo.Amount;

            string streamId = DateTime.Now.ToString("yyMMddHHmmss") + new Random().GetRandomNumberString(4);//生成序列号
            //付款人转账记录
            RmbCoinTransaction transaction = new RmbCoinTransaction()
            {
                Amount        = -transactionInfo.Amount,
                Type          = RmbTransactionType.Transaction,
                State         = TransactionState.Success,
                Direction     = TransactionDirection.Expend,
                RealAmount    = -transactionInfo.Amount,
                CreatedTime   = DateTime.Now,
                StreamId      = streamId,
                Remark        = "转账",
                OtherSideInfo = transactionInfo.OtherSizeUserName,
                Fee           = 0,
                Preferential  = 0,
                User          = user
            };
            await RmbCoinTransactionRepository.InsertAsync(transaction);

            user.RmbCoinTransactions.Add(transaction);

            //收款人转账记录
            RmbCoinTransaction transaction2 = new RmbCoinTransaction()
            {
                Amount        = transactionInfo.Amount,
                Type          = RmbTransactionType.Transaction,
                State         = TransactionState.Success,
                Direction     = TransactionDirection.InCome,
                RealAmount    = transactionInfo.Amount,
                CreatedTime   = DateTime.Now,
                StreamId      = streamId,
                Remark        = "转账",
                OtherSideInfo = user.UserName,
                Fee           = 0,
                Preferential  = 0,
                User          = otherSizeUser
            };
            await RmbCoinTransactionRepository.InsertAsync(transaction2);

            otherSizeUser.RmbCoinTransactions.Add(transaction2);

            IdentityResult result;

            result = await UserManager.UpdateAsync(user);

            result = await UserManager.UpdateAsync(otherSizeUser);

            if (!result.Succeeded)
            {
                return(result.ToOperationResult());
            }
            return(await UserRepository.UnitOfWork.SaveChangesAsync() > 0
                    ? new OperationResult(OperationResultType.Success, $"转账成功")
                    : OperationResult.NoChanged);
        }