public CardRechargeRecord QueryByOrderSeq(String orderseq)
        {
            CardRechargeRecord obj = null;

            try
            {
                String where = String.Format(" where OrderSeq = '{0}'", orderseq);
                IList <CardRechargeRecord> list = QueryByWhere(where);
                if (list != null && list.Count > 0)
                {
                    obj = list[0];
                }
            }
            catch (Exception ex) { throw ex; }

            return(obj);
        }
        public CardRechargeRecord QueryByTransactionID(String transactionid)
        {
            CardRechargeRecord obj = null;

            try
            {
                String where = String.Format(" where PayTransactionID = '{0}'", transactionid);
                IList <CardRechargeRecord> list = QueryByWhere(where);
                if (list != null && list.Count > 0)
                {
                    obj = list[0];
                }
            }
            catch (Exception ex) { throw ex; }

            return(obj);
        }
        private IList <CardRechargeRecord> QueryByWhere(String where)
        {
            IList <CardRechargeRecord> list = null;

            String     sql = Select_Sql.Insert(Select_Sql.Length, where);
            SqlCommand cmd = new SqlCommand(sql);

            cmd.CommandType = CommandType.Text;

            DataSet ds = DBUtility.FillData(cmd, DBUtility.BestToneCenterConStr);

            if (ds != null && ds.Tables[0] != null)
            {
                list = new List <CardRechargeRecord>();
                foreach (DataRow row in ds.Tables[0].Rows)
                {
                    CardRechargeRecord entity = new CardRechargeRecord();
                    entity.ID = Convert.ToInt64(row["ID"]);
                    entity.PayTransactionID = row["PayTransactionID"].ToString();
                    entity.OrderSeq         = row["OrderSeq"].ToString();
                    entity.OrderDate        = row["OrderDate"].ToString();
                    entity.CurType          = row["CurType"].ToString();
                    entity.OrderAmount      = Convert.ToInt64(row["OrderAmount"]);
                    entity.OrderDesc        = row["OrderDesc"].ToString();
                    entity.CardNo           = row["CardNo"].ToString();
                    entity.CardPwd          = row["CardPwd"].ToString();
                    entity.CardType         = row["CardType"].ToString();
                    entity.TargetAccount    = row["TargetAccount"].ToString();
                    entity.Status           = Convert.ToInt32(row["Status"]);
                    entity.ReqTime          = Convert.ToDateTime(row["ReqTime"]);
                    entity.PayTime          = Convert.ToDateTime(row["PayTime"]);
                    entity.UptranSeq        = row["UptranSeq"].ToString();
                    entity.TranDate         = row["TranDate"].ToString();
                    entity.Sign             = row["Sign"].ToString();
                    entity.ReturnCode       = row["ReturnCode"].ToString();
                    entity.ReturnDesc       = row["ReturnDesc"].ToString();

                    list.Add(entity);
                }
            }

            return(list);
        }
        public bool Update(CardRechargeRecord obj)
        {
            bool result = false;

            try
            {
                SqlParameter[] parameters = new SqlParameter[] {
                    new SqlParameter("@ID", obj.ID),
                    new SqlParameter("@PayTransactionID", obj.PayTransactionID),
                    new SqlParameter("@OrderSeq", obj.OrderSeq),
                    new SqlParameter("@OrderDate", obj.OrderDate),
                    new SqlParameter("@CurType", obj.CurType),
                    new SqlParameter("@OrderAmount", obj.OrderAmount),
                    new SqlParameter("@OrderDesc", obj.OrderDesc),
                    new SqlParameter("@CardNo", obj.CardNo),
                    new SqlParameter("@CardPwd", obj.CardPwd),
                    new SqlParameter("@CardType", obj.CardType),
                    new SqlParameter("@TargetAccount", obj.TargetAccount),
                    new SqlParameter("@Status", obj.Status),
                    new SqlParameter("@ReqTime", obj.ReqTime),
                    new SqlParameter("@PayTime", obj.PayTime),
                    new SqlParameter("@UptranSeq", obj.UptranSeq),
                    new SqlParameter("@TranDate", obj.TranDate),
                    new SqlParameter("@Sign", obj.Sign),
                    new SqlParameter("@ReturnCode", obj.ReturnCode),
                    new SqlParameter("@ReturnDesc", obj.ReturnDesc)
                };

                SqlCommand cmd = new SqlCommand(Update_Sql);
                cmd.CommandType = CommandType.Text;
                cmd.Parameters.AddRange(parameters);

                result = DBUtility.Execute(cmd, DBUtility.BestToneCenterConStr);
            }
            catch (Exception ex) { throw ex; }

            return(result);
        }
Example #5
0
        public bool Insert(CardRechargeRecord obj)
        {
            bool result = false;
            try
            {
                SqlParameter[] parameters = new SqlParameter[]{
                    new SqlParameter("@PayTransactionID",obj.PayTransactionID),
                    new SqlParameter("@OrderSeq",obj.OrderSeq),
                    new SqlParameter("@OrderDate",obj.OrderDate),
                    new SqlParameter("@CurType",obj.CurType),
                    new SqlParameter("@OrderAmount",obj.OrderAmount),
                    new SqlParameter("@OrderDesc",obj.OrderDesc),
                    new SqlParameter("@CardNo",obj.CardNo),
                    new SqlParameter("@CardPwd",obj.CardPwd),
                    new SqlParameter("@CardType",obj.CardType),
                    new SqlParameter("@TargetAccount",obj.TargetAccount),
                    new SqlParameter("@Status",obj.Status),
                    new SqlParameter("@ReqTime",obj.ReqTime),
                    new SqlParameter("@PayTime",obj.PayTime),
                    new SqlParameter("@UptranSeq",obj.UptranSeq),
                    new SqlParameter("@TranDate",obj.TranDate),
                    new SqlParameter("@Sign",obj.Sign),
                    new SqlParameter("@ReturnCode",obj.ReturnCode),
                    new SqlParameter("@ReturnDesc",obj.ReturnDesc)
                };

                SqlCommand cmd = new SqlCommand(Insert_Sql);
                cmd.CommandType = CommandType.Text;
                cmd.Parameters.AddRange(parameters);

                result = DBUtility.Execute(cmd, DBUtility.BestToneCenterConStr);
            }
            catch (Exception ex) { throw ex; }

            return result;
        }
Example #6
0
    /// <summary>
    /// 卡充值
    /// </summary>
    protected String AccountRechargeByCard(out StringBuilder strLog)
    {
        Int32 Result = ErrorDefinition.CIP_IError_Result_UnknowError_Code;
        String ErrMsg = ErrorDefinition.CIP_IError_Result_UnknowError_Msg;

        strLog = new StringBuilder();
        strLog.AppendFormat("【消费卡充值,DateTime:{0}】\r\n[参数]:", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));

        //获取参数
        String spid = Request["SPID"];
        String custid = Request["CustID"];
        String cardNo = Request["CardNo"];
        String cardPwd = Request["CardPassword"];
        String cardType = Request["CardType"];
        strLog.AppendFormat("SPID:{0},CustID:{1},CardNo:{2},CardPwd:{3},CardType:{4}\r\n", spid, custid, cardNo, cardPwd, cardType);

        //String CheckCardErrMsg = "";
        //Int32 CheckCardResult = BesttoneAccountHelper.VerifyCardNo(cardNo, out CheckCardErrMsg);
        //if(CheckCardResult!=0)
        //    return "[{\"result\":\"false\",\"step\":\"query\",\"errorcode\":\"" + CheckCardResult + "\",\"info\":\"" + CheckCardErrMsg + "}]";

        long accountBalance = 0;        //账户余额
        long cardBalance = 0;           //卡余额
        String accountType = BesttoneAccountHelper.ConvertAccountType(cardType);            //转换卡类型
        /*********************************************查询账户信息*****************************************************/
        BesttoneAccountDAO _besttoneAccount_dao = new BesttoneAccountDAO();
        BesttoneAccount account_entity = _besttoneAccount_dao.QueryByCustID(custid);

        #region 卡余额查询

        //查询卡余额
        Result = BesttoneAccountHelper.QueryCardBalance(cardNo, accountType, out cardBalance, out ErrMsg);
        strLog.AppendFormat("[查询卡余额]:Result:{0},Balance:{1}\r\n", Result, cardBalance);

        //查询失败
        if (Result != 0)
            return "[{\"result\":\"false\",\"step\":\"query\",\"errorcode\":\"" + Result + "\",\"info\":\"查询余额失败\"}]";

        //卡余额为0
        if (cardBalance == 0)
            return "[{\"result\":\"false\",\"step\":\"query\",\"errorcode\":\"200020\",\"info\":\"卡内余额为0\"}]";

        #endregion

        #region 账户充值金额上限校验

        long OnceRechargeLimit = BesttoneAccountConstDefinition.DefaultInstance.AccountRechargeLimitedOne;              //单笔充值金额上限
        long RechargeAmountLimit = BesttoneAccountConstDefinition.DefaultInstance.AccountRechargeLimitedDay;            //账户单日充值额度上限
        long CurrentAmountLimit = BesttoneAccountConstDefinition.DefaultInstance.AccountBalanceLimited;                 //账户余额上限
        if (OnceRechargeLimit > 0)
        {
            //检测用户单笔充值金额是否超限(10000元)
            if (cardBalance > OnceRechargeLimit)
                return "[{\"result\":\"false\",\"step\":\"query\",\"errorcode\":\"100003\",\"rechargeamount\":\"" + BesttoneAccountHelper.ConvertAmountToYuan(cardBalance) + "\",\"rechargeamountlimit\":\"" + BesttoneAccountHelper.ConvertAmountToYuan(OnceRechargeLimit) + "\",\"info\":\"卡内余额为0\"}]";
        }
        if (RechargeAmountLimit > 0)
        {
            //检测用户当日充值是否超限(当日充值金额不能超过50000元)
            long hadRechargeAmount = _rechargeOrder_dao.QueryCurrentRechargeAmount(account_entity.BestPayAccount);
            if ((hadRechargeAmount + cardBalance) > RechargeAmountLimit)
                return "[{\"result\":\"false\",\"step\":\"query\",\"errorcode\":\"100001\",\"rechargeamount\":\"" + BesttoneAccountHelper.ConvertAmountToYuan(hadRechargeAmount) + "\",\"rechargeamountlimit\":\"" + BesttoneAccountHelper.ConvertAmountToYuan(RechargeAmountLimit) + "\",\"info\":\"卡内余额为0\"}]";
        }

        if (CurrentAmountLimit > 0)
        {
            //检测用户帐户余额(个人账户余额不能超过100000元)
            Result = BesttoneAccountHelper.QueryAccountBalance(account_entity.BestPayAccount, out accountBalance, out ErrMsg);
            if (Result != 0)
                return "[{\"result\":\"false\",\"step\":\"query\",\"errorcode\":\"" + Result + "\",\"info\":\"账户信息查询失败\"}]";

            if ((accountBalance + cardBalance) > CurrentAmountLimit)
                return "[{\"result\":\"false\",\"step\":\"query\",\"errorcode\":\"100002\",\"accountbalance\":\"" + BesttoneAccountHelper.ConvertAmountToYuan(accountBalance) + "\",\"CurrentAmountLimit\":\"" + BesttoneAccountHelper.ConvertAmountToYuan(CurrentAmountLimit) + "\",\"info\":\"卡内余额为0\"}]";
            accountBalance = 0;
        }

        #endregion

        #region 卡扣款

        String transactionID = BesttoneAccountHelper.CreateTransactionID();
        String orderSeq = BesttoneAccountHelper.CreateOrderSeq();
        DateTime reqTime = DateTime.Now;

        RechargeOrder _recharge_order;              //充值订单
        CardRechargeRecord cardrecharge_entity;     //卡扣款流水记录

        //初始化充值订单
        _recharge_order = new RechargeOrder(orderSeq, transactionID, reqTime.ToString("yyyyMMdd"), "RMB", cardBalance, cardBalance, 0, "消费卡向账户充值扣款",
            custid, account_entity.BestPayAccount, cardType, spid, reqTime, new DateTime(1900, 1, 1), new DateTime(1900, 1, 1), 1, 0, "", "", "","0");  //2013-04-13 add 最后一个字段 0 代表是否需要开票
        //初始化充值订单—测试
        //_recharge_order = new RechargeOrder(orderSeq, transactionID, reqTime.ToString("yyyyMMdd"), "RMB", 1, 1, 0, "消费卡向账户充值扣款",
        //    custid, account_entity.BestPayAccount, cardType, spid, reqTime, new DateTime(1900, 1, 1), new DateTime(1900, 1, 1), 1, 0, "", "", "");

        //初始化卡扣款流水
        cardrecharge_entity = new CardRechargeRecord(transactionID, orderSeq, reqTime.ToString("yyyyMMdd"), "RMB", cardBalance, "消费卡向账户充值扣款", cardNo, cardPwd, cardType,
            account_entity.BestPayAccount, 0, reqTime, new DateTime(1900, 1, 1), "", "", "", "", "");
        //初始化卡扣款流水—测试
        //cardrecharge_entity = new CardRechargeRecord(transactionID, orderSeq, reqTime.ToString("yyyyMMdd"), "RMB", 1, "消费卡向账户充值扣款", cardNo, cardPwd, cardType,
        //    account_entity.BestPayAccount, 0, reqTime, new DateTime(1900, 1, 1), "", "", "", "", "");

        strLog.AppendFormat("[订单信息]:TransactionID:{0},OrderSeq:{1},ReqTime:{2}\r\n", transactionID, orderSeq, reqTime.ToString("yyyy-MM-dd HH:mm:ss"));

        /***********************************************************开始扣款*******************************************************/
        String uptranSeq = String.Empty;                        //交易流水号,支付平台返回的,后期对账用
        Result = BesttoneAccountHelper.CardDeductionBalance(transactionID, orderSeq, cardNo, cardPwd, cardType, cardBalance, reqTime, "", out uptranSeq, out ErrMsg);
        //扣款—测试
        //Result = BesttoneAccountHelper.CardDeductionBalance(transactionID, orderSeq, cardNo, cardPwd, cardType, 1, reqTime, "", out uptranSeq, out ErrMsg);
        strLog.AppendFormat("[卡扣款]:Result:{0},ErrMsg:{1}\r\n", Result, ErrMsg);
        _recharge_order.UptranSeq = uptranSeq;
        cardrecharge_entity.UptranSeq = uptranSeq;
        if (Result != 0)
        {
            //修改订单信息
            _recharge_order.Status = 4;     // 这里要对调网关发生异常做分别处理 ,定位6
            if (Result == -3024)
            {
                _recharge_order.Status = 6;
            }

            _recharge_order.PayTime = DateTime.Now;
            _recharge_order.ReturnCode = Result.ToString();
            _recharge_order.ReturnDesc = ErrMsg;
            _rechargeOrder_dao.Insert(_recharge_order);

            //修改卡扣款记录信息
            //cardrecharge_entity.Status = 2;   //为统一rechargeorder 和 cardrechargerecord 的状态值,这里做修改 2013-05-15
            cardrecharge_entity.Status = 4;
            if (Result == -3024)
            {
                cardrecharge_entity.Status = 6;
            }
            //以上和rechargeorder 的状态处理方式统一

            cardrecharge_entity.PayTime = DateTime.Now;
            cardrecharge_entity.ReturnCode = Result.ToString();
            cardrecharge_entity.ReturnDesc = ErrMsg;
            _cardRechargeRecord_dao.Insert(cardrecharge_entity);
            return "[{\"result\":\"false\",\"step\":\"deduction\",\"errorcode\":\"" + Result + "\",\"info\":\"卡扣款失败\"}]";
        }
        else
        {
            //修改订单信息
            _recharge_order.Status = 2;
            _recharge_order.PayTime = DateTime.Now;
            _recharge_order.ReturnCode = "0000";
            _recharge_order.ReturnDesc = "已扣款待充值";   // 原:扣款成功
            _rechargeOrder_dao.Insert(_recharge_order);

            //修改卡充值记录信息
            //cardrecharge_entity.Status = 1;      // 这里为和 rechargeorder 状态统一 ,修改为2
            cardrecharge_entity.Status = 2;
            cardrecharge_entity.PayTime = DateTime.Now;
            cardrecharge_entity.ReturnCode = "0000";
            cardrecharge_entity.ReturnDesc = "已扣款待充值";   // 原:扣款成功
            _cardRechargeRecord_dao.Insert(cardrecharge_entity);
        }

        #endregion

        #region 充值

        transactionID = BesttoneAccountHelper.CreateTransactionID();        //充值流水记录
        DateTime rechargeTime = DateTime.Now;                               //充值请求时间
        String returnMsg = String.Empty;
        bool resultBoolean = false;

        //初始化充值流水类
        AccountRechargeRecord rechargeRecord_entity = new AccountRechargeRecord(transactionID, rechargeTime.ToString("yyyyMMdd"), orderSeq,
            cardBalance, cardType, "消费卡充值", rechargeTime, new DateTime(1900, 1, 1), 0, "", "");

        try
        {
            #region 开始充值

            //调用接口给账户充值
            Result = BesttoneAccountHelper.AccountRecharge(transactionID, account_entity.BestPayAccount, cardBalance, rechargeTime, out accountBalance, out ErrMsg);
            //调用接口给账户充值—测试
            //Result = BesttoneAccountHelper.AccountRecharge(transactionID, account_entity.BestPayAccount, 1, rechargeTime, out accountBalance, out ErrMsg);
            strLog.AppendFormat("[账户充值]:TransactionID:{0},Result:{1},ErrMsg:{2}\r\n", transactionID, Result, ErrMsg);
            if (Result == 0)
            {
                //修改订单信息
                _recharge_order = _rechargeOrder_dao.QueryByOrderSeq(orderSeq);
                _recharge_order.Status = 3;
                _recharge_order.RechargeCount = 1;
                _recharge_order.CompleteTime = DateTime.Now;
                _recharge_order.ReturnCode = "0000";
                _recharge_order.ReturnDesc = "已充值";    // 原:充值成功
                _recharge_order.RechargeTransactionID = transactionID;  // 回填充值流水号
                resultBoolean = _rechargeOrder_dao.Update(_recharge_order);

                //修改充值流水记录信息
                rechargeRecord_entity.Status = 3;    // 原: 1 ,为和总表rechargeorder 统一改为3
                rechargeRecord_entity.CompleteTime = DateTime.Now;
                rechargeRecord_entity.ReturnCode = "0000";
                rechargeRecord_entity.ReturnDesc = "已充值";  // 原:充值成功

                strLog.AppendFormat("[更新订单状态]ResultBoolean:{0}\r\n", resultBoolean);
                returnMsg = "[{\"result\":\"true\",\"info\":\"账户充值成功\",\"deductionBalance\":\"" + BesttoneAccountHelper.ConvertAmountToYuan(cardBalance) + "\",\"accountBalance\":\"" + BesttoneAccountHelper.ConvertAmountToYuan(accountBalance) + "\"}]";
            }
            else
            {
                //修改订单信息
                _recharge_order = _rechargeOrder_dao.QueryByOrderSeq(orderSeq);
                _recharge_order.RechargeCount = 1;
                _recharge_order.Status = 5; // 原:没有这句
                if (Result == -3025)
                {
                    _recharge_order.Status = 7;  //原:没有这句
                }
                _recharge_order.ReturnCode = Result.ToString();
                _recharge_order.ReturnDesc = ErrMsg;
                _recharge_order.RechargeTransactionID = transactionID;  // 回填充值流水号
                resultBoolean = _rechargeOrder_dao.Update(_recharge_order);

                //修改充值流水记录信息
                rechargeRecord_entity.Status = 5;    //   5 代表充值失败  原:2

                if (Result == -3025)
                {
                    rechargeRecord_entity.Status = 7;// 充值异常
                }
                rechargeRecord_entity.CompleteTime = DateTime.Now;
                rechargeRecord_entity.ReturnCode = Result.ToString();
                rechargeRecord_entity.ReturnDesc = ErrMsg;

                returnMsg = "[{\"result\":\"false\",\"step\":\"recharge\",\"errorcode\":\"" + Result + "\",\"info\":\"账户充值失败\"}]";
            }

            #endregion
        }
        catch (Exception ex)
        {
            rechargeRecord_entity.ReturnDesc += ex.Message;
            throw ex;
        }
        finally
        {
            _accountRechargeRecord_dao.Insert(rechargeRecord_entity);
        }

        #endregion

        return returnMsg;
    }
Example #7
0
        private IList<CardRechargeRecord> QueryByWhere(String where)
        {
            IList<CardRechargeRecord> list = null;

            String sql = Select_Sql.Insert(Select_Sql.Length, where);
            SqlCommand cmd = new SqlCommand(sql);
            cmd.CommandType = CommandType.Text;

            DataSet ds = DBUtility.FillData(cmd, DBUtility.BestToneCenterConStr);
            if (ds != null && ds.Tables[0] != null)
            {
                list = new List<CardRechargeRecord>();
                foreach (DataRow row in ds.Tables[0].Rows)
                {
                    CardRechargeRecord entity = new CardRechargeRecord();
                    entity.ID = Convert.ToInt64(row["ID"]);
                    entity.PayTransactionID = row["PayTransactionID"].ToString();
                    entity.OrderSeq = row["OrderSeq"].ToString();
                    entity.OrderDate = row["OrderDate"].ToString();
                    entity.CurType = row["CurType"].ToString();
                    entity.OrderAmount = Convert.ToInt64(row["OrderAmount"]);
                    entity.OrderDesc = row["OrderDesc"].ToString();
                    entity.CardNo = row["CardNo"].ToString();
                    entity.CardPwd = row["CardPwd"].ToString();
                    entity.CardType = row["CardType"].ToString();
                    entity.TargetAccount = row["TargetAccount"].ToString();
                    entity.Status = Convert.ToInt32(row["Status"]);
                    entity.ReqTime = Convert.ToDateTime(row["ReqTime"]);
                    entity.PayTime = Convert.ToDateTime(row["PayTime"]);
                    entity.UptranSeq = row["UptranSeq"].ToString();
                    entity.TranDate = row["TranDate"].ToString();
                    entity.Sign = row["Sign"].ToString();
                    entity.ReturnCode = row["ReturnCode"].ToString();
                    entity.ReturnDesc = row["ReturnDesc"].ToString();

                    list.Add(entity);
                }
            }

            return list;
        }
    public RechargeResult Recharge(String Request)
    {
        RechargeResult rechargeResult = new RechargeResult();

        int Result = 0;
        String ErrMsg = "";

        StringBuilder strLog = new StringBuilder();

        StringBuilder Response = new StringBuilder();
        Response.AppendFormat("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");

        #region 解析xml
        XmlDocument xmlDoc = new XmlDocument();
        xmlDoc.LoadXml(Request);
        XmlNode versionNode = xmlDoc.SelectNodes("/root/callinfo/version")[0];
        String version = versionNode.Attributes["value"].Value;

        XmlNode SPIDNode = xmlDoc.SelectNodes("/root/callinfo/SPID")[0];
        String SPID = SPIDNode.Attributes["value"].Value;

        XmlNode CardTypeNode = xmlDoc.SelectNodes("/root/srchcond/conds/CardType")[0];
        String CardType = CardTypeNode.Attributes["value"].Value;

        XmlNode CustIDNode = xmlDoc.SelectNodes("/root/srchcond/conds/CustID")[0];
        String CustID = CustIDNode.Attributes["value"].Value;

        XmlNode BesttoneAccountNode = xmlDoc.SelectNodes("/root/srchcond/conds/BesttoneAccount")[0];
        String BesttoneAccount = CustIDNode.Attributes["value"].Value;

        XmlNode CardNoNode = xmlDoc.SelectNodes("/root/srchcond/conds/CardNo")[0];
        String CardNo = CardNoNode.Attributes["value"].Value;

        XmlNode CardPasswordNode = xmlDoc.SelectNodes("/root/srchcond/conds/CardPassword")[0];
        String CardPassword = CardPasswordNode.Attributes["value"].Value;

        #endregion

        #region 请求数据校验

        if (String.IsNullOrEmpty(CustID) && String.IsNullOrEmpty(BesttoneAccount))
        {
            //返回错误
            rechargeResult.ReturnCode = "-10";
            rechargeResult.Msg = "CUSTID 和BesttoneAccount 不能同时为空! ";
            return rechargeResult;
        }

        #endregion

        #region 权限校验
        #endregion

        long accountBalance = 0;        //账户余额
        long cardBalance = 0;           //卡余额
        //String accountType = BesttoneAccountHelper.ConvertAccountType(cardType);            //转换卡类型
        /*********************************************查询账户信息*****************************************************/
        BesttoneAccountDAO _besttoneAccount_dao = new BesttoneAccountDAO();
        BesttoneAccount account_entity = null;
        //订单充值操作类
        RechargeOrderDAO _rechargeOrder_dao = new RechargeOrderDAO();
        //卡扣款记录操作类
        CardRechargeRecordDAO _cardRechargeRecord_dao = new CardRechargeRecordDAO();
        //充值操作类
        AccountRechargeRecordDAO _accountRechargeRecord_dao = new AccountRechargeRecordDAO();

        if (!String.IsNullOrEmpty(CustID))
        {
            account_entity = _besttoneAccount_dao.QueryByCustID(CustID);
        }

        if (!String.IsNullOrEmpty(BesttoneAccount))
        {
            account_entity = _besttoneAccount_dao.QueryByBestAccount(BesttoneAccount);
           }

        #region 卡余额查询

        //查询卡余额
        Result = BesttoneAccountHelper.QueryCardBalance(CardNo, CardType, out cardBalance, out ErrMsg);
        strLog.AppendFormat("[查询卡余额]:Result:{0},Balance:{1}\r\n", Result, cardBalance);

        //查询失败
        //if (Result != 0)
        //    return "[{\"result\":\"false\",\"step\":\"query\",\"errorcode\":\"" + Result + "\",\"info\":\"查询余额失败\"}]";
        //if (Result != 0)
        //    return "<?xml version=\"1.0\" encoding=\"UTF-8\"><Result ReturnCode='" + Result + "' Msg='" + 查询余额失败 + "'  />";

        if (Result != 0)
        {
            rechargeResult.ReturnCode = "-11";
            rechargeResult.Msg = "查询余额失败";
            return rechargeResult;
        }

        //卡余额为0
        //if (cardBalance == 0)
        //    return "[{\"result\":\"false\",\"step\":\"query\",\"errorcode\":\"200020\",\"info\":\"卡内余额为0\"}]";

        if (cardBalance == 0)
        {
            rechargeResult.ReturnCode = "200020";
            rechargeResult.Msg = "卡内余额为0";
            return rechargeResult;
        }

        //if (Result != 0)
        //    return "<?xml version=\"1.0\" encoding=\"UTF-8\"><Result ReturnCode='200020' Msg='" + 卡内余额为0 + "'  />";

        #endregion

        #region 账户充值金额上限校验

        long OnceRechargeLimit = BesttoneAccountConstDefinition.DefaultInstance.AccountRechargeLimitedOne;              //单笔充值金额上限
        long RechargeAmountLimit = BesttoneAccountConstDefinition.DefaultInstance.AccountRechargeLimitedDay;            //账户单日充值额度上限
        long CurrentAmountLimit = BesttoneAccountConstDefinition.DefaultInstance.AccountBalanceLimited;                 //账户余额上限
        if (OnceRechargeLimit > 0)
        {
            //检测用户单笔充值金额是否超限(10000元)
            //if (cardBalance > OnceRechargeLimit)
            //    return "[{\"result\":\"false\",\"step\":\"query\",\"errorcode\":\"100003\",\"rechargeamount\":\"" + BesttoneAccountHelper.ConvertAmountToYuan(cardBalance) + "\",\"rechargeamountlimit\":\"" + BesttoneAccountHelper.ConvertAmountToYuan(OnceRechargeLimit) + "\",\"info\":\"卡内余额为0\"}]";
            //if (Result != 0)
            //    return "<?xml version=\"1.0\" encoding=\"UTF-8\"><Result ReturnCode='100003' Rechargeamount='" + BesttoneAccountHelper.ConvertAmountToYuan(cardBalance) + "' Rechargeamountlimit='" + BesttoneAccountHelper.ConvertAmountToYuan(OnceRechargeLimit) + "' />";

            if (Result != 0)
            {
                rechargeResult.ReturnCode = "100003";
                rechargeResult.Msg = "单笔充值金额是否超限(10000元)";
                rechargeResult.Rechargeamount = BesttoneAccountHelper.ConvertAmountToYuan(cardBalance);
                rechargeResult.Rechargeamountlimit = BesttoneAccountHelper.ConvertAmountToYuan(OnceRechargeLimit);
                return rechargeResult;
            }

        }
        if (RechargeAmountLimit > 0)
        {
            //检测用户当日充值是否超限(当日充值金额不能超过50000元)
            long hadRechargeAmount = _rechargeOrder_dao.QueryCurrentRechargeAmount(account_entity.BestPayAccount);
            //if ((hadRechargeAmount + cardBalance) > RechargeAmountLimit)
            //    return "[{\"result\":\"false\",\"step\":\"query\",\"errorcode\":\"100001\",\"rechargeamount\":\"" + BesttoneAccountHelper.ConvertAmountToYuan(hadRechargeAmount) + "\",\"rechargeamountlimit\":\"" + BesttoneAccountHelper.ConvertAmountToYuan(RechargeAmountLimit) + "\",\"info\":\"卡内余额为0\"}]";
            //if (Result != 0)
            //    return "<?xml version=\"1.0\" encoding=\"UTF-8\"><Result ReturnCode='100001' Rechargeamount='" + BesttoneAccountHelper.ConvertAmountToYuan(hadRechargeAmount) + "' Rechargeamountlimit='" + BesttoneAccountHelper.ConvertAmountToYuan(OnceRechargeLimit) + "' />";
            rechargeResult.ReturnCode = "100001";
            rechargeResult.Msg = "当日充值金额不能超过50000元";
            rechargeResult.Rechargeamount = BesttoneAccountHelper.ConvertAmountToYuan(cardBalance);
            rechargeResult.Rechargeamountlimit = BesttoneAccountHelper.ConvertAmountToYuan(OnceRechargeLimit);
            return rechargeResult;

        }

        if (CurrentAmountLimit > 0)
        {
            //检测用户帐户余额(个人账户余额不能超过100000元)
            Result = BesttoneAccountHelper.QueryAccountBalance(account_entity.BestPayAccount, out accountBalance, out ErrMsg);
            //if (Result != 0)
            //    return "[{\"result\":\"false\",\"step\":\"query\",\"errorcode\":\"" + Result + "\",\"info\":\"账户信息查询失败\"}]";

            //if (Result != 0)
            //    return "<?xml version=\"1.0\" encoding=\"UTF-8\"><Result ReturnCode='" + Result + "' Msg='账户信息查询失败'  />";

            //if ((accountBalance + cardBalance) > CurrentAmountLimit)
            //    return "[{\"result\":\"false\",\"step\":\"query\",\"errorcode\":\"100002\",\"accountbalance\":\"" + BesttoneAccountHelper.ConvertAmountToYuan(accountBalance) + "\",\"CurrentAmountLimit\":\"" + BesttoneAccountHelper.ConvertAmountToYuan(CurrentAmountLimit) + "\",\"info\":\"卡内余额为0\"}]";
            //accountBalance = 0;

            //if ((accountBalance + cardBalance) > CurrentAmountLimit)
            //    return "<?xml version=\"1.0\" encoding=\"UTF-8\"><Result ReturnCode='100002' Accountbalance='" + BesttoneAccountHelper.ConvertAmountToYuan(accountBalance) + "' CurrentAmountLimit='" + BesttoneAccountHelper.ConvertAmountToYuan(CurrentAmountLimit) + "'  />";

            if ((accountBalance + cardBalance) > CurrentAmountLimit)
            {
                rechargeResult.ReturnCode = "100001";
                rechargeResult.Msg = "当日充值金额不能超过50000元";
                rechargeResult.Rechargeamount = BesttoneAccountHelper.ConvertAmountToYuan(cardBalance);
                rechargeResult.Rechargeamountlimit = BesttoneAccountHelper.ConvertAmountToYuan(OnceRechargeLimit);
                return rechargeResult;
            }

        }

        #endregion

        #region 卡扣款

        String transactionID = BesttoneAccountHelper.CreateTransactionID();
        String orderSeq = BesttoneAccountHelper.CreateOrderSeq();
        DateTime reqTime = DateTime.Now;

        RechargeOrder _recharge_order;              //充值订单
        CardRechargeRecord cardrecharge_entity;     //卡扣款流水记录

        //初始化充值订单
        _recharge_order = new RechargeOrder(orderSeq, transactionID, reqTime.ToString("yyyyMMdd"), "RMB", cardBalance, cardBalance, 0, "消费卡向账户充值扣款",
            account_entity.CustID, account_entity.BestPayAccount, CardType, SPID, reqTime, new DateTime(1900, 1, 1), new DateTime(1900, 1, 1), 1, 0, "", "", "", "0");  //2013-04-13 add 最后一个字段 0 代表是否需要开票

        //初始化卡扣款流水
        cardrecharge_entity = new CardRechargeRecord(transactionID, orderSeq, reqTime.ToString("yyyyMMdd"), "RMB", cardBalance, "消费卡向账户充值扣款", CardNo, CardPassword, CardType,
            account_entity.BestPayAccount, 0, reqTime, new DateTime(1900, 1, 1), "", "", "", "", "");

        /***********************************************************开始扣款*******************************************************/
        String uptranSeq = String.Empty;                        //交易流水号,支付平台返回的,后期对账用
        Result = BesttoneAccountHelper.CardDeductionBalance(transactionID, orderSeq, CardNo, CardPassword, CardType, cardBalance, reqTime, "", out uptranSeq, out ErrMsg);
        strLog.AppendFormat("[卡扣款]:Result:{0},ErrMsg:{1}\r\n", Result, ErrMsg);
        _recharge_order.UptranSeq = uptranSeq;
        cardrecharge_entity.UptranSeq = uptranSeq;
        if (Result != 0)
        {
            //修改订单信息
            _recharge_order.Status = 4;
            _recharge_order.PayTime = DateTime.Now;
            _recharge_order.ReturnCode = Result.ToString();
            _recharge_order.ReturnDesc = ErrMsg;
            _rechargeOrder_dao.Insert(_recharge_order);

            //修改卡扣款记录信息
            cardrecharge_entity.Status = 2;
            cardrecharge_entity.PayTime = DateTime.Now;
            cardrecharge_entity.ReturnCode = Result.ToString();
            cardrecharge_entity.ReturnDesc = ErrMsg;
            _cardRechargeRecord_dao.Insert(cardrecharge_entity);
            //return "<?xml version=\"1.0\" encoding=\"UTF-8\"><Result ReturnCode='" + Result + "' Msg='卡扣款失败'   />";

            //return "[{\"result\":\"false\",\"step\":\"deduction\",\"errorcode\":\"" + Result + "\",\"info\":\"卡扣款失败\"}]";
            rechargeResult.ReturnCode = Convert.ToString(Result);
            rechargeResult.Msg = "卡扣款失败!";

            return rechargeResult;
        }
        else
        {
            //修改订单信息
            _recharge_order.Status = 2;
            _recharge_order.PayTime = DateTime.Now;
            _recharge_order.ReturnCode = "0000";
            _recharge_order.ReturnDesc = "扣款成功";
            _rechargeOrder_dao.Insert(_recharge_order);

            //修改卡充值记录信息
            cardrecharge_entity.Status = 1;
            cardrecharge_entity.PayTime = DateTime.Now;
            cardrecharge_entity.ReturnCode = "0000";
            cardrecharge_entity.ReturnDesc = "扣款成功";
            _cardRechargeRecord_dao.Insert(cardrecharge_entity);
        }

        #endregion

        #region 充值

        transactionID = BesttoneAccountHelper.CreateTransactionID();        //充值流水记录
        DateTime rechargeTime = DateTime.Now;                               //充值请求时间
        String returnMsg = String.Empty;
        bool resultBoolean = false;

        //初始化充值流水类
        AccountRechargeRecord rechargeRecord_entity = new AccountRechargeRecord(transactionID, rechargeTime.ToString("yyyyMMdd"), orderSeq,
            cardBalance, CardType, "消费卡充值", rechargeTime, new DateTime(1900, 1, 1), 0, "", "");

        try
        {
            #region 开始充值

            //调用接口给账户充值
            Result = BesttoneAccountHelper.AccountRecharge(transactionID, account_entity.BestPayAccount, cardBalance, rechargeTime, out accountBalance, out ErrMsg);
            //调用接口给账户充值—测试
            //Result = BesttoneAccountHelper.AccountRecharge(transactionID, account_entity.BestPayAccount, 1, rechargeTime, out accountBalance, out ErrMsg);
            strLog.AppendFormat("[账户充值]:TransactionID:{0},Result:{1},ErrMsg:{2}\r\n", transactionID, Result, ErrMsg);
            if (Result == 0)
            {
                //修改订单信息
                _recharge_order = _rechargeOrder_dao.QueryByOrderSeq(orderSeq);
                _recharge_order.Status = 3;
                _recharge_order.RechargeCount = 1;
                _recharge_order.CompleteTime = DateTime.Now;
                _recharge_order.ReturnCode = "0000";
                _recharge_order.ReturnDesc = "充值成功";
                resultBoolean = _rechargeOrder_dao.Update(_recharge_order);

                //修改充值流水记录信息
                rechargeRecord_entity.Status = 1;
                rechargeRecord_entity.CompleteTime = DateTime.Now;
                rechargeRecord_entity.ReturnCode = "0000";
                rechargeRecord_entity.ReturnDesc = "充值成功";

                strLog.AppendFormat("[更新订单状态]ResultBoolean:{0}\r\n", resultBoolean);
                returnMsg = "[{\"result\":\"true\",\"info\":\"账户充值成功\",\"deductionBalance\":\"" + BesttoneAccountHelper.ConvertAmountToYuan(cardBalance) + "\",\"accountBalance\":\"" + BesttoneAccountHelper.ConvertAmountToYuan(accountBalance) + "\"}]";
                //return "<?xml version=\"1.0\" encoding=\"UTF-8\"><Result ReturnCode='" + Result + "' Msg='卡扣款失败'   />";
                //returnMsg = "<?xml version=\"1.0\" encoding=\"UTF-8\"><Result ReturnCode='" + 0 + "' Msg='账户充值成功'  deductionBalance='" + BesttoneAccountHelper.ConvertAmountToYuan(cardBalance) + "' accountBalance='" + BesttoneAccountHelper.ConvertAmountToYuan(accountBalance) + "' />";
                rechargeResult.Msg = "账户充值成功";
                rechargeResult.ReturnCode = "0";
                rechargeResult.Rechargeamount = BesttoneAccountHelper.ConvertAmountToYuan(accountBalance);
                return rechargeResult;
            }
            else
            {
                //修改订单信息
                _recharge_order = _rechargeOrder_dao.QueryByOrderSeq(orderSeq);
                _recharge_order.RechargeCount = 1;
                _recharge_order.ReturnCode = Result.ToString();
                _recharge_order.ReturnDesc = ErrMsg;
                resultBoolean = _rechargeOrder_dao.Update(_recharge_order);

                //修改充值流水记录信息
                rechargeRecord_entity.Status = 2;
                rechargeRecord_entity.CompleteTime = DateTime.Now;
                rechargeRecord_entity.ReturnCode = Result.ToString();
                rechargeRecord_entity.ReturnDesc = ErrMsg;

                returnMsg = "[{\"result\":\"false\",\"step\":\"recharge\",\"errorcode\":\"" + Result + "\",\"info\":\"账户充值失败\"}]";
                //returnMsg = "<?xml version=\"1.0\" encoding=\"UTF-8\"><Result ReturnCode='" + Result + "' Msg='账户充值失败'   />";
                rechargeResult.ReturnCode = "" + Result+"";
                rechargeResult.Msg = "账户充值失败";
                return rechargeResult;
            }

            #endregion
        }
        catch (Exception ex)
        {
            rechargeRecord_entity.ReturnDesc += ex.Message;
            throw ex;
        }
        finally
        {
            _accountRechargeRecord_dao.Insert(rechargeRecord_entity);
        }

        #endregion
        return rechargeResult;
    }