public static string Insert(string gift_id, string sys_user_id, string USER, string TOKEN) { if (!AccessToken.Read(USER, TOKEN)) { return("登录超时"); } IDictionary <string, string> fdict = new Dictionary <string, string>(); fdict.Add("id", gift_id); fdict.Add("delete_flag", "IS NULL"); DataSet ds = DBHelper.Select("gift", "title,price,inventory,off_shelf_datetime", string.Empty, fdict, "and"); if (ds.Tables[0].Rows.Count == 0) { return("礼品不存在"); } string title = ds.Tables[0].Rows[0]["title"].ToString(); string price = ds.Tables[0].Rows[0]["price"].ToString(); string inventory = ds.Tables[0].Rows[0]["inventory"].ToString(); string off_shelf_datetime = ds.Tables[0].Rows[0]["off_shelf_datetime"].ToString(); if (inventory.Length > 0 && (Convert.ToInt32(inventory) < 1)) { return("礼品库存不足"); } if (off_shelf_datetime.Length > 0 && (Convert.ToDateTime(off_shelf_datetime) < DateTime.Today)) { return("礼品已下架"); } fdict = new Dictionary <string, string>(); fdict.Add("id", sys_user_id); fdict.Add("delete_flag", "IS NULL"); ds = DBHelper.Select("sys_user", "balance", string.Empty, fdict, "and"); if (ds.Tables[0].Rows.Count == 0) { return("用户不存在"); } if (Convert.ToInt32(ds.Tables[0].Rows[0]["balance"]) < Convert.ToInt32(price)) { return("爱心不足"); } using (MySqlConnection dbConnection = new MySqlConnection(DBHelper.strConnection)) { dbConnection.Open(); using (MySqlTransaction trans = dbConnection.BeginTransaction()) { IDictionary <string, string> dict = new Dictionary <string, string>(); dict.Add("gift_id", gift_id); dict.Add("sys_user_id", sys_user_id); dict.Add("buy_datetime", DateTime.Now.ToString()); DBHelper.Insert("gift_history", dict, dbConnection, trans); dict = new Dictionary <string, string>(); dict.Add("balance", "数字相减-" + price); fdict = new Dictionary <string, string>(); fdict.Add("id", sys_user_id); DBHelper.Update("sys_user", dict, fdict, "and", dbConnection, trans); sys_user_balance_change.Insert(sys_user_id, "4", "-" + price, "兑换“" + title + "”", "gift", gift_id, dbConnection, trans); if (inventory.Length > 0) { dict = new Dictionary <string, string>(); dict.Add("inventory", "数字相减-1"); fdict = new Dictionary <string, string>(); fdict.Add("id", gift_id); DBHelper.Update("gift", dict, fdict, "and", dbConnection, trans); } trans.Commit(); } } return(string.Empty); }
public static string Insert(string football_round_chain_id, string sys_user_id, string football_match_id, string match_result_id, string football_match_ids, string USER, string TOKEN) { if (!AccessToken.Read(USER, TOKEN)) { return("登录超时"); } IDictionary <string, string> fdict = new Dictionary <string, string>(); fdict.Add("id", football_round_chain_id); fdict.Add("delete_flag", "IS NULL"); DataSet ds = DBHelper.Select("football_round_chain", "participant_amount,name", string.Empty, fdict, "and"); if (ds.Tables[0].Rows.Count == 0) { return("竞猜不存在"); } string participant_amount = ds.Tables[0].Rows[0]["participant_amount"].ToString(); string football_round_chain_name = ds.Tables[0].Rows[0]["name"].ToString(); string[] football_match_idarr = football_match_ids.Split(','); if (football_match_idarr.Length != Convert.ToInt32(participant_amount)) { return("接龙长度异常"); } fdict = new Dictionary <string, string>(); fdict.Add("id", sys_user_id); fdict.Add("delete_flag", "IS NULL"); ds = DBHelper.Select("sys_user", "balance", string.Empty, fdict, "and"); if (ds.Tables[0].Rows.Count == 0) { return("用户不存在"); } if (Convert.ToInt32(ds.Tables[0].Rows[0]["balance"]) < 6) { return("爱心不足6元"); } using (MySqlConnection dbConnection = new MySqlConnection(DBHelper.strConnection)) { dbConnection.Open(); using (MySqlTransaction trans = dbConnection.BeginTransaction()) { IDictionary <string, string> dict = new Dictionary <string, string>(); dict.Add("football_round_chain_id", football_round_chain_id); dict.Add("sys_user_id", sys_user_id); dict.Add("participant_need", (Convert.ToInt32(participant_amount) - 1).ToString()); dict.Add("chain_vote_status_id", "1"); dict.Add("vote_datetime", DateTime.Now.ToString()); DBHelper.Insert("football_round_chain_vote", dict, dbConnection, trans); string football_round_chain_vote_id = DBHelper.SelectNewId(dbConnection, trans); dict = new Dictionary <string, string>(); dict.Add("football_round_chain_vote_id", football_round_chain_vote_id); dict.Add("sys_user_id", sys_user_id); dict.Add("football_match_id", football_match_id); dict.Add("match_result_id", match_result_id); dict.Add("vote_datetime", DateTime.Now.ToString()); DBHelper.Insert("football_round_chain_vote_invite", dict, dbConnection, trans); foreach (string football_match_idi in football_match_idarr) { if (football_match_idi.Equals(football_match_id)) { continue; } dict = new Dictionary <string, string>(); dict.Add("football_round_chain_vote_id", football_round_chain_vote_id); dict.Add("football_match_id", football_match_idi); DBHelper.Insert("football_round_chain_vote_invite", dict, dbConnection, trans); } dict = new Dictionary <string, string>(); dict.Add("balance", "数字相减-6"); fdict = new Dictionary <string, string>(); fdict.Add("id", sys_user_id); DBHelper.Update("sys_user", dict, fdict, "and", dbConnection, trans); sys_user_balance_change.Insert(sys_user_id, "2", "-6", "发起接龙“" + football_round_chain_name + "”", "football_round_chain_vote", football_round_chain_vote_id, dbConnection, trans); trans.Commit(); } } return(string.Empty); }
public static string End(string id, string USER, string TOKEN) { if (!AccessToken.Read(USER, TOKEN)) { return("登录超时"); } IDictionary <string, string> fdict = new Dictionary <string, string>(); fdict.Add("football_round_chain_vote_id", id); DataSet ds = DBHelper.Select("football_round_chain_vote_invite_view", "*", string.Empty, fdict, "and"); if (ds.Tables[0].Rows.Count == 0) { return("找不到该记录"); } string price = ds.Tables[0].Rows[0]["price"].ToString(); string title = ds.Tables[0].Rows[0]["football_round_name"] + " " + ds.Tables[0].Rows[0]["football_round_chain_name"]; string chain_vote_status_id = "2"; foreach (DataRow dr in ds.Tables[0].Rows) { if (dr["vote_sys_user_id"].ToString().Length == 0) { return("接龙未完成"); } if (dr["match_result_id"].ToString().Length == 0) { return("仍有比赛未完成"); } if (!dr["match_result_id"].Equals(dr["vote_match_result_id"])) { chain_vote_status_id = "3"; } } using (MySqlConnection dbConnection = new MySqlConnection(DBHelper.strConnection)) { dbConnection.Open(); using (MySqlTransaction trans = dbConnection.BeginTransaction()) { IDictionary <string, string> dict = new Dictionary <string, string>(); dict.Add("chain_vote_status_id", chain_vote_status_id); fdict = new Dictionary <string, string>(); fdict.Add("id", id); DBHelper.Update("football_round_chain_vote", dict, fdict, "and", dbConnection, trans); if (chain_vote_status_id.Equals("2") && (price.Length > 0)) { foreach (DataRow dr in ds.Tables[0].Rows) { dict = new Dictionary <string, string>(); dict.Add("balance", "数字相加+" + price); fdict = new Dictionary <string, string>(); fdict.Add("id", dr["vote_sys_user_id"].ToString()); DBHelper.Update("sys_user", dict, fdict, "and", dbConnection, trans); sys_user_balance_change.Insert(dr["vote_sys_user_id"].ToString(), "2", price, title, "football_round_chain_vote", id, dbConnection, trans); } } trans.Commit(); } } return(string.Empty); }
public static string Insert(string football_match_id, string sys_user_id, string match_result_id, string amount, string USER, string TOKEN) { if (!AccessToken.Read(USER, TOKEN)) { return("登录超时"); } if (amount.Length == 0 || Convert.ToInt32(amount) <= 0) { return("竞拍额异常"); } IDictionary <string, string> fdict = new Dictionary <string, string>(); fdict.Add("id", sys_user_id); fdict.Add("delete_flag", "IS NULL"); DataSet ds = DBHelper.Select("sys_user", "balance", string.Empty, fdict, "and"); if (ds.Tables[0].Rows.Count == 0) { return("用户不存在"); } if (Convert.ToInt32(ds.Tables[0].Rows[0]["balance"]) < Convert.ToInt32(amount)) { return("爱心不足"); } fdict = new Dictionary <string, string>(); fdict.Add("id", football_match_id); fdict.Add("vote_deadline", ">='" + DateTime.Now.ToString() + "'"); ds = DBHelper.Select("football_match_view", "id,football_round_name,home_football_team_name,away_football_team_name", string.Empty, fdict, "and"); if (ds.Tables[0].Rows.Count == 0) { return("竞猜已结束"); } string round_name = ds.Tables[0].Rows[0]["football_round_name"].ToString(); string home_football_team_name = ds.Tables[0].Rows[0]["home_football_team_name"].ToString(); string away_football_team_name = ds.Tables[0].Rows[0]["away_football_team_name"].ToString(); fdict = new Dictionary <string, string>(); fdict.Add("football_match_id", football_match_id); fdict.Add("sys_user_id", sys_user_id); ds = DBHelper.Select("football_match_vote", "id,match_result_id,amount", string.Empty, fdict, "and"); using (MySqlConnection dbConnection = new MySqlConnection(DBHelper.strConnection)) { dbConnection.Open(); using (MySqlTransaction trans = dbConnection.BeginTransaction()) { IDictionary <string, string> dict = new Dictionary <string, string>(); if (ds.Tables[0].Rows.Count == 0) { dict.Add("football_match_id", football_match_id); dict.Add("sys_user_id", sys_user_id); dict.Add("match_result_id", match_result_id); dict.Add("amount", amount); dict.Add("vote_datetime", DateTime.Now.ToString()); DBHelper.Insert("football_match_vote", dict, dbConnection, trans); } else { if (amount.Equals(ds.Tables[0].Rows[0]["amount"].ToString()) && match_result_id.Equals(ds.Tables[0].Rows[0]["match_result_id"].ToString())) { return(string.Empty); } dict.Add("match_result_id", match_result_id); dict.Add("amount", amount); dict.Add("vote_datetime", DateTime.Now.ToString()); fdict = new Dictionary <string, string>(); fdict.Add("id", ds.Tables[0].Rows[0]["id"].ToString()); DBHelper.Update("football_match_vote", dict, fdict, "and", dbConnection, trans); amount = (Convert.ToInt32(amount) - Convert.ToInt32(ds.Tables[0].Rows[0]["amount"])).ToString(); } dict = new Dictionary <string, string>(); dict.Add("balance", "数字相减-" + amount); fdict = new Dictionary <string, string>(); fdict.Add("id", sys_user_id); DBHelper.Update("sys_user", dict, fdict, "and", dbConnection, trans); sys_user_balance_change.Insert(sys_user_id, "3", "-" + amount, round_name + " " + home_football_team_name + "VS" + away_football_team_name + " " + dict_match_result.GetName(match_result_id), "football_match", football_match_id, dbConnection, trans); trans.Commit(); } } return(string.Empty); }