Exemple #1
0
        /// <summary>
        /// 人工充值转账
        /// </summary>
        /// <param name="uid"></param>
        /// <param name="amount"></param>
        /// <returns></returns>
        public bool Recharge(int uid, double amount)
        {
            // 1.封装参数
            IDictionary <string, DbParameter[]> dictionary = new Dictionary <string, DbParameter[]>();
            PayParam payParam = RechargeUtil.GetParam(uid, amount);

            // 2.检查甲方钱包
            var cause = string.Empty;

            if (!CheckFinance(Constants.HotAccountID, amount, ref cause))
            {
                throw new MsgException(cause);
            }

            // 3.生成流水账
            Pays payAccounts = RechargeUtil.GetPayAccounts(Constants.HotAccountID, uid, payParam);

            paysRepository.InsertAccounts(payAccounts, ref dictionary);

            // 4.扣减双方钱包余额
            var users = GetUsers(Constants.HotAccountID, uid);

            if (users == null || users.Count < 2)
            {
                throw new MsgException("加载用户信息超时");
            }
            var owner    = users[0];
            var customer = users[1];

            walletRepository.OutAccounts(owner.Uid, amount, owner.Version, ref dictionary);
            walletRepository.PutAccounts(customer.Uid, amount, customer.Version, ref dictionary);

            // 5.生成往来账
            var currentAccounts = GetCurrentAccounts(payParam);

            accountsRepository.BatchInsertAccounts(currentAccounts, ref dictionary);

            return(paysRepository.CommitTransactionLock(dictionary));
        }