Пример #1
0
        /// <summary>
        /// 提交流水不带事务
        /// </summary>
        /// <param name="helper"></param>
        /// <param name="item"></param>
        /// <param name="error"></param>
        /// <returns></returns>
        public bool SubmitTransaction(DBExtend helper, ITransaction item, out string error)
        {
            //if (item.TradeType is System.Enum)
            //{
            //    item.TradeType = (int)item.TradeType;
            //}
            error = "";
            var account = AccountBusiness <TType> .Instance.GetAccountFromCache(item.AccountId);

            item.TransactionType = account.TransactionType;
            item.Amount          = Math.Abs(item.Amount);
            if (item.OperateType == OperateType.支出)
            {
                item.Amount = 0 - item.Amount;
            }
            if (string.IsNullOrEmpty(item.TransactionNo))
            {
                item.TransactionNo = GetSerialNumber(1, item.TradeType, (int)item.OperateType);
            }

            int transactionId = 0;

            try
            {
                //检测余额
                if (item.OperateType == OperateType.支出 && item.CheckBalance)
                {
                    string sql1 = "select CurrentBalance-LockedAmount from $IAccountDetail with (nolock) where id=@AccountId";
                    //sql1 = FormatTable(sql1);
                    helper.AddParam("AccountId", item.AccountId);
                    var balance = helper.AutoExecuteScalar <decimal>(sql1, typeof(IAccountDetail));
                    //var balance = helper.ExecScalar<decimal>(sql1, typeof(IAccountDetail));
                    if (balance + item.Amount < 0)
                    {
                        error = "对应帐户余额不足";
                        return(false);
                    }
                }
                transactionId = helper.InsertFromObj(item);
                string sql = @"
update $ITransaction set CurrentBalance=b.CurrentBalance+Amount,LastBalance=b.CurrentBalance from $IAccountDetail b where b.id=@AccountId and $ITransaction.id=@id
update $IAccountDetail set CurrentBalance=CurrentBalance+@amount where id=@AccountId";
                //helper.Clear();
                helper.AddParam("id", item.Id);
                helper.AddParam("amount", item.Amount);
                helper.AddParam("AccountId", item.AccountId);
                //sql = FormatTable(sql);
                helper.AutoSpUpdate(sql, typeof(ITransaction), typeof(IAccountDetail));
                //helper.Execute(sql, typeof(ITransaction), typeof(IAccountDetail));
            }
            catch (Exception ero)
            {
                error = ero.Message;
                CoreHelper.EventLog.Log("SubmitTransaction 发生错误" + ero, true);
                return(false);
            }
            return(true);
        }