Exemplo n.º 1
0
        public void handler(IResponder responder)
        {
            int uid = SJSRequest.GetInt("Uid", 0);

            double balance = SJSRequest.GetFloat("Balancemoney", 0);
            string remarks = SJSRequest.GetString("Remarks");

            if (uid <= 0)
            {
                responder.WriteErroredMsg("请求参数错误!");
                return;
            }

            if (balance <= 0)
            {
                responder.WriteErroredMsg("充值金额不能小于或等于0!");
                return;
            }

            using (DbTransaction trans = DbHelper.BeginTransaction())
            {
                bool writeError = false;
                try
                {
                    User user = UserManager.GetUser(uid, trans);

                    if (user == null)
                    {
                        writeError = true;
                        trans.Rollback();
                        responder.WriteErroredMsg("此用户不存在,无法充值!");
                        return;
                    }

                    user.Balance += balance;

                    int rlt = UserManager.UpdateUserBalance(user.Uid, -balance, trans);

                    if (rlt <= 0)
                    {
                        writeError = true;
                        trans.Rollback();
                        responder.WriteErroredMsg("充值失败,数据库数据更新不成功!");
                        return;
                    }

                    Balance balances = new Balance();

                    balances.Uid = uid;
                    balances.Balances = balance;
                    balances.Remarks = remarks;
                    balances.Btime = DateTime.Now;// DateTime.UtcNow;

                    balances.Id = BalanceManager.AddBalance(balances, trans);

                    if (balances.Id <= 0)
                    {
                        writeError = true;
                        trans.Rollback();
                        responder.WriteErroredMsg(user.Realname + "充值记录失败!");
                        return;
                    }

                    trans.Commit();
                }
                catch (Exception ex)
                {
                    trans.Rollback();
                    if (writeError == false)
                    {
                        responder.WriteErroredMsg("充值失败,程序异常!");
                    }
                    return;
                }
            }

            responder.WriteSuccessedMsg("充值成功!");
        }
Exemplo n.º 2
0
 public static int AddBalance(Balance balances, System.Data.Common.DbTransaction trans)
 {
     return DatabaseProvider.GetInstance().AddBalance(balances, trans);
 }
Exemplo n.º 3
0
 /// <summary>
 /// 修改方法
 /// </summary>
 public static int UpdateBalance(Balance balance)
 {
     return DatabaseProvider.GetInstance().UpdateBalance(balance);
 }
Exemplo n.º 4
0
 /// <summary>
 /// 添加方法
 /// </summary>
 public static int AddBalance(Balance balance)
 {
     return DatabaseProvider.GetInstance().AddBalance(balance);
 }
Exemplo n.º 5
0
        public static Balance GetBalance(IDataReader reader)
        {
            Balance model = new Balance();

            model.Id = (reader["Id"] is DBNull ? Convert.ToInt32("0") : Convert.ToInt32(reader["Id"]));
            model.Uid = (reader["Uid"] is DBNull ? Convert.ToInt32("0") : Convert.ToInt32(reader["Uid"]));
            model.Balances = (reader["Balances"] is DBNull ? Convert.ToDouble("0") : Convert.ToDouble(reader["Balances"]));
            model.Btime = (reader["Btime"] is DBNull ? Convert.ToDateTime("1900-01-01") : Convert.ToDateTime(reader["Btime"]));
            model.Remarks = reader["Remarks"].ToString();

            return model;
        }