Files
KJD/KJDService/KJD_WebService/BLL/WXXD/WXUserManage.cs
T

965 lines
49 KiB
C#
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using KJD_Web.Model;
using KJD_Web.Utils;
using MySql.Data.MySqlClient;
using Mysqlx.Crud;
using NaiBa.Util.Extension;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Net;
using System.Reflection;
using System.Web;
using System.Web.ApplicationServices;
using System.Web.Security;
using System.Web.UI.WebControls;
namespace KJD_Web.BLL.WXXD
{
public class WXUserManage
{
public static bool GetSign(string signData, bool isUserLogin = false)
{
if (string.IsNullOrEmpty(signData)) { return false; }
var time = 0;
int.TryParse(RegexUtils.GetStringQuery(ref signData, "time"), out time);
string time1 = RegexUtils.GetStringQuery(ref signData, "code");
if (time1 != EncrypUtil.Encryption(time))
return false;
if (!isUserLogin)
{
var user_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref signData, "user_name"))?.ParseToString();
if (user_name.IsNullOrEmpty())
{
//return "{\"code\":500,\"msg\":\"请输入用户名\"}";
return false;
}
}
return true;
}
public string CheckUserLogin(string inputData)
{
if (!string.IsNullOrEmpty(inputData))
{
if (!GetSign(inputData, true))
return "{\"code\":999,\"msg\":\"校验失败\"}";
var mobile = RegexUtils.GetStringQuery(ref inputData, "mobile")?.Replace("'", "\\'");
var password = RegexUtils.GetStringQuery(ref inputData, "password")?.Replace("'", "\\'");
var version = RegexUtils.GetStringQuery(ref inputData, "version").ParseToInt();
if (version < (System.Configuration.ConfigurationManager.ConnectionStrings["LimitVersion"]?.ConnectionString).ParseToInt())
return "{\"code\":1,\"msg\":\"当前版本过于陈旧,请立即升级新版\"}";
int r2 = 0;
int.TryParse(RegexUtils.GetStringQuery(ref inputData, "r2"), out r2);
string conn = System.Configuration.ConfigurationManager.ConnectionStrings["ConnKJD"].ConnectionString;
MysqlUtils mySql = new MysqlUtils(conn);
string sql = "select u.*,uu.authority as main_authority " +
"FROM wxxd.user u LEFT JOIN wxxd.user uu ON uu.user_name=u.parent_user_name where u.user_name='"
+ mobile + "' and u.password='" + password + "'";
var dt = mySql.ExecuteDataTable(sql);
if (!string.IsNullOrEmpty(mySql.Message))
{
mySql.Close();
return "{\"code\":500,\"msg\":\"" + mySql.Message + "\"}";
}
if (dt == null)
dt = new DataTable();
foreach (DataRow row in dt.Rows)
{
UserLoginResultParam user = new UserLoginResultParam
{
id = Convert.ToInt32(row["id"]),
user_name = row["user_name"].ToString(),
nick_name = row["nick_name"].ToString(),
mobile = row["user_name"].ToString(),
password = row["password"].ToString(),
group_id = row["group_id"].ToString(),
card_id = row["card_id"].ToString(),
company_name = row["company_name"].ToString(),
is_sa = row.Table.Columns.Contains("is_sa") ? row["is_sa"].ParseToInt() : 0,
sa_level = row.Table.Columns.Contains("sa_level") ? row["sa_level"].ParseToInt() : 0,
authority = row.Table.Columns.Contains("authority") ? row["authority"].ParseToString() : "",
parent_user_name = row["parent_user_name"].ToString(),
points = row.Table.Columns.Contains("points") ? row["points"].ParseToInt() : 0,
};
var main_authority = row.Table.Columns.Contains("main_authority") ? row["main_authority"].ParseToString() : "";
// 子账号积分用户权限跟随
if (user.group_id != "3")
{
var userAuthLst = user.authority.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries).ToList();
if (!main_authority.Contains("积分用户"))
{
userAuthLst.Remove("积分用户");
user.authority = string.Join(",", userAuthLst);
}
else if (!user.authority.Contains("积分用户"))
{
user.authority = (user.authority + "," + "积分用户").Trim(',');
}
}
if (string.IsNullOrEmpty(user.company_name))
{
user.company_name = "-";
}
if (user.group_id != "3" && !string.IsNullOrEmpty(user.parent_user_name))
{
sql = "select authority from wxxd.user where user_name='" + user.parent_user_name + "'";
var rst = mySql.ExecuteFirst(sql);
if (mySql.Message.IsNullOrEmpty())
{
user.parent_authority = rst;
}
}
var data = JsonUtils.SerializeObjectToString(user);
mySql.Close();
return "{\"code\":200,\"msg\":\"success\",\"data\":" + data + ",\"c\":\"" + EncrypUtil.Encryption(r2) + "\"}";
}
mySql.Close();
return "{\"code\":1,\"msg\":\"用户名或密码错误\"}";
}
return "{\"code\":19999,\"msg\":\"输入为空\"}";
}
public string AddSubUser(string inputData)
{
if (!string.IsNullOrEmpty(inputData))
{
if (!GetSign(inputData))
return "{\"code\":999,\"msg\":\"校验失败\"}";
var parent_user_name = RegexUtils.GetStringQuery(ref inputData, "user_name")?.Replace("'", "\\'");
var nick_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "sub_nick_name"))?.Replace("'", "\\'");
var user_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "sub_name"))?.Replace("'", "\\'");
var mobile = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "sub_mobile"))?.Replace("'", "\\'");
var password = RegexUtils.GetStringQuery(ref inputData, "sub_password")?.Replace("'", "\\'");
var group_id = RegexUtils.GetStringQuery(ref inputData, "group_id")?.Replace("'", "\\'");
var card_id = RegexUtils.GetStringQuery(ref inputData, "card_id")?.Replace("'", "\\'");
var company_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "company"))?.Replace("'", "\\'");
var notes = RegexUtils.GetStringQuery(ref inputData, "notes")?.Replace("'", "\\'");
var authority = RegexUtils.GetStringQuery(ref inputData, "authority")?.Replace("'", "\\'");
int r2 = 0;
int.TryParse(RegexUtils.GetStringQuery(ref inputData, "r2"), out r2);
string conn = System.Configuration.ConfigurationManager.ConnectionStrings["ConnKJD"].ConnectionString;
MysqlUtils mySql = new MysqlUtils(conn);
string sql = "";
sql = "select exists (select 1 from wxxd.user where user_name='" + user_name + "')";
var exist = mySql.ExecuteFirstInt(sql);
if (exist > 0)
{
mySql.Close();
return "{\"code\":500,\"msg\":\"用户名已存在\"}";
}
sql = "insert into wxxd.user (nick_name,user_name,mobile,password,card_id,group_id,company_name,notes,parent_user_name,authority,add_time,mdy_time) " +
"values ('" + nick_name + "','" + user_name + "','" + mobile + "','" + password + "','" + card_id + "','" +
group_id + "','" + company_name + "','" + notes + "','" + parent_user_name + "','" + authority + "','" +
DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "','" +
DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "');";
var rst = mySql.ExecuteNonQuery(sql);
mySql.Close();
if (!rst)
return "{\"code\":501,\"msg\":\""+ mySql.Message + "\"}";
else
return "{\"code\":200,\"msg\":\"子账户创建成功!\"}";
}
return "{\"code\":19999,\"msg\":\"输入为空\"}";
}
public string GetSubUser(string inputData)
{
if (!string.IsNullOrEmpty(inputData))
{
if (!GetSign(inputData))
return "{\"code\":999,\"msg\":\"校验失败\"}";
var user_name = RegexUtils.GetStringQuery(ref inputData, "user_name");
var password = RegexUtils.GetStringQuery(ref inputData, "password");
var group = RegexUtils.GetStringQuery(ref inputData, "group");
int r2 = 0;
int.TryParse(RegexUtils.GetStringQuery(ref inputData, "r2"), out r2);
string conn = System.Configuration.ConfigurationManager.ConnectionStrings["ConnKJD"].ConnectionString;
MysqlUtils mySql = new MysqlUtils(conn);
string sql = "select * from wxxd.user where parent_user_name='"
+ user_name + "'";
var dt = mySql.ExecuteDataTable(sql);
mySql.Close();
if (dt != null)
{
List<UserLoginResultParam> userList = new List<UserLoginResultParam>();
foreach (DataRow row in dt.Rows)
{
UserLoginResultParam user = new UserLoginResultParam
{
id = Convert.ToInt32(row["id"]),
user_name = row["user_name"].ToString(),
nick_name = row["nick_name"].ToString(),
mobile = row["mobile"].ToString(),
password = row["password"].ToString(),
group_id = row["group_id"].ToString(),
card_id = row["card_id"].ToString(),
parent_user_name = row["parent_user_name"].ToString(),
company_name = row["company_name"].ToString(),
notes = row["notes"].ToString(),
authority = row.Table.Columns.Contains("authority") ? row["authority"].ParseToString() : "",
};
if (string.IsNullOrEmpty(user.mobile))
{
user.mobile = row["user_name"].ToString();
}
userList.Add(user);
}
var data = JsonUtils.SerializeObjectToString(userList);
return "{\"code\":200,\"msg\":\"success\",\"data\":" + data + ",\"c\":\"" + EncrypUtil.Encryption(r2) + "\"}";
}
}
return "{\"code\":19999,\"msg\":\"输入为空\"}";
}
public string UpdateSubUser(string inputData)
{
if (!string.IsNullOrEmpty(inputData))
{
if (!GetSign(inputData))
return "{\"code\":999,\"msg\":\"校验失败\"}";
var id = RegexUtils.GetStringQuery(ref inputData, "id")?.Replace("'", "\\'");
var parent_user_name = RegexUtils.GetStringQuery(ref inputData, "user_name")?.Replace("'", "\\'");
var nick_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "sub_nick_name"))?.Replace("'", "\\'");
var user_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "sub_name"))?.Replace("'", "\\'");
var mobile = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "sub_mobile"))?.Replace("'", "\\'");
var password = RegexUtils.GetStringQuery(ref inputData, "sub_password")?.Replace("'", "\\'");
var group_id = RegexUtils.GetStringQuery(ref inputData, "group_id")?.Replace("'", "\\'");
var card_id = RegexUtils.GetStringQuery(ref inputData, "card_id")?.Replace("'", "\\'");
var notes = RegexUtils.GetStringQuery(ref inputData, "notes")?.Replace("'", "\\'");
var authority = RegexUtils.GetStringQuery(ref inputData, "authority")?.Replace("'", "\\'");
int r2 = 0;
int.TryParse(RegexUtils.GetStringQuery(ref inputData, "r2"), out r2);
string conn = System.Configuration.ConfigurationManager.ConnectionStrings["ConnKJD"].ConnectionString;
MysqlUtils mySql = new MysqlUtils(conn);
string sql = "";
//sql = "select * from wxxd.user where parent_user_name='"
// + user_name + "'";
sql = "update wxxd.user set";
if (!string.IsNullOrEmpty(nick_name))
sql += " nick_name='" + nick_name + "',";
if (!string.IsNullOrEmpty(user_name))
sql += " user_name='" + user_name + "',";
if (!string.IsNullOrEmpty(mobile))
sql += " mobile='" + mobile + "',";
if (!string.IsNullOrEmpty(password))
sql += " password='" + password + "',";
if (!string.IsNullOrEmpty(group_id))
sql += " group_id=" + group_id + ",";
if (!string.IsNullOrEmpty(card_id))
sql += " card_id='" + card_id + "',";
if (!string.IsNullOrEmpty(notes))
sql += " notes='" + notes + "',";
if (authority != null)
sql += " authority='" + authority + "',";
sql = sql.TrimEnd(',');
sql += " where id=" + id + "";
var rst = mySql.ExecuteNonQuery(sql);
mySql.Close();
if (rst)
{
return "{\"code\":200,\"msg\":\"success\"}";
}
}
return "{\"code\":19999,\"msg\":\"输入为空\"}";
}
public string DelUser(string inputData)
{
if (!string.IsNullOrEmpty(inputData))
{
if (!GetSign(inputData))
return "{\"code\":999,\"msg\":\"校验失败\"}";
var user_name = RegexUtils.GetStringQuery(ref inputData, "user_name");
var id = RegexUtils.GetStringQuery(ref inputData, "id");
int r2 = 0;
int.TryParse(RegexUtils.GetStringQuery(ref inputData, "r2"), out r2);
string conn = System.Configuration.ConfigurationManager.ConnectionStrings["ConnKJD"].ConnectionString;
MysqlUtils mySql = new MysqlUtils(conn);
string sql = "delete from wxxd.user where id='"
+ id + "'";
var rst = mySql.ExecuteNonQuery(sql);
mySql.Close();
if (rst)
{
return "{\"code\":200,\"msg\":\"success\"}";
}
else
return "{\"code\":500,\"msg\":\"删除失败,请稍后重试\"}";
}
return "{\"code\":19999,\"msg\":\"输入为空\"}";
}
public string GetAllUser(string inputData)
{
if (!string.IsNullOrEmpty(inputData))
{
if (!GetSign(inputData))
return "{\"code\":999,\"msg\":\"校验失败\"}";
var user_name = RegexUtils.GetStringQuery(ref inputData, "user_name")?.Replace("'", "\\'");
var password = RegexUtils.GetStringQuery(ref inputData, "password")?.Replace("'", "\\'");
var group_id = RegexUtils.GetStringQuery(ref inputData, "group_id")?.Replace("'", "\\'");
var search = RegexUtils.GetStringQuery(ref inputData, "search")?.Replace("'", "\\'");
var sa_level = RegexUtils.GetStringQuery(ref inputData, "sa_level")?.Replace("'", "\\'");
int r2 = 0;
int.TryParse(RegexUtils.GetStringQuery(ref inputData, "r2"), out r2);
string conn = System.Configuration.ConfigurationManager.ConnectionStrings["ConnKJD"].ConnectionString;
MysqlUtils mySql = new MysqlUtils(conn);
//string sql = "select * from wxxd.user where group_id=3";
string sql = "select u.*,uu.authority as main_authority from wxxd.user u " +
"LEFT JOIN wxxd.user uu ON uu.user_name=u.parent_user_name WHERE 1=1";
if (!string.IsNullOrEmpty(group_id))
sql += " and u.group_id=" + group_id;
if (!string.IsNullOrEmpty(sa_level))
sql += " and u.sa_level=" + sa_level;
if (!string.IsNullOrEmpty(search))
sql += " and (u.user_name like '%" + search +
"%' or u.nick_name like '%" + search +
"%' or u.company_name like '%" + search + "%')";
sql += " order by u.id desc";
var dt = mySql.ExecuteDataTable(sql);
mySql.Close();
if (dt != null)
{
List<UserLoginResultParam> userList = new List<UserLoginResultParam>();
foreach (DataRow row in dt.Rows)
{
UserLoginResultParam user = new UserLoginResultParam
{
id = Convert.ToInt32(row["id"]),
user_name = row["user_name"].ToString(),
nick_name = row["nick_name"].ToString(),
mobile = row["mobile"].ToString(),
password = row["password"].ToString(),
group_id = row["group_id"].ToString(),
card_id = row["card_id"].ToString(),
parent_user_name = row["parent_user_name"].ToString(),
company_name = row["company_name"].ToString(),
notes = row["notes"].ToString(),
is_sa = row.Table.Columns.Contains("is_sa") ? row["is_sa"].ParseToInt() : 0,
sa_level = row.Table.Columns.Contains("sa_level") ? row["sa_level"].ParseToInt() : 0,
authority = row.Table.Columns.Contains("authority") ? row["authority"].ParseToString() : "",
points = row.Table.Columns.Contains("points") ? row["points"].ParseToInt() : 0,
};
var main_authority = row.Table.Columns.Contains("main_authority") ? row["main_authority"].ParseToString() : "";
// 子账号积分用户权限跟随
if (user.group_id != "3")
{
var userAuthLst = user.authority.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries).ToList();
if (!main_authority.Contains("积分用户"))
{
userAuthLst.Remove("积分用户");
user.authority = string.Join(",", userAuthLst);
}
else if (!user.authority.Contains("积分用户"))
{
user.authority = (user.authority + "," + "积分用户").Trim(',');
}
}
if (string.IsNullOrEmpty(user.mobile))
{
user.mobile = row["user_name"].ToString();
}
userList.Add(user);
}
var data = JsonUtils.SerializeObjectToString(userList);
return "{\"code\":200,\"msg\":\"success\",\"data\":" + data + ",\"c\":\"" + EncrypUtil.Encryption(r2) + "\"}";
}
}
return "{\"code\":19999,\"msg\":\"输入为空\"}";
}
public string AddUser(string inputData)
{
if (!string.IsNullOrEmpty(inputData))
{
if (!GetSign(inputData))
return "{\"code\":999,\"msg\":\"校验失败\"}";
var nick_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "add_nick_name"))?.Replace("'", "\\'");
var user_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "add_user_name"))?.Replace("'", "\\'");
var mobile = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "add_mobile"))?.Replace("'", "\\'");
var password = RegexUtils.GetStringQuery(ref inputData, "add_password")?.Replace("'", "\\'");
var company_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "add_company"))?.Replace("'", "\\'");
var group_id = RegexUtils.GetStringQuery(ref inputData, "group_id")?.Replace("'", "\\'"); ;
var card_id = RegexUtils.GetStringQuery(ref inputData, "card_id")?.Replace("'", "\\'");
var notes = RegexUtils.GetStringQuery(ref inputData, "notes")?.Replace("'", "\\'");
var sa_level = RegexUtils.GetStringQuery(ref inputData, "sa_level")?.Replace("'", "\\'");
var authority = RegexUtils.GetStringQuery(ref inputData, "authority")?.Replace("'", "\\'");
int r2 = 0;
int.TryParse(RegexUtils.GetStringQuery(ref inputData, "r2"), out r2);
string conn = System.Configuration.ConfigurationManager.ConnectionStrings["ConnKJD"].ConnectionString;
MysqlUtils mySql = new MysqlUtils(conn);
string sql = "";
sql = "select exists (select 1 from wxxd.user where user_name='" + user_name + "')";
var exist = mySql.ExecuteFirstInt(sql);
if (exist > 0)
{
mySql.Close();
return "{\"code\":500,\"msg\":\"用户名已存在\"}";
}
sql = "insert into wxxd.user (nick_name,user_name,mobile,password,card_id,group_id,company_name,notes,sa_level,authority,add_time,mdy_time) " +
"values ('" + nick_name + "','" + user_name + "','" + mobile + "','" + password + "','" + card_id + "','" +
group_id + "','" + company_name + "','" + notes + "'," + sa_level + ",'" + authority + "','" +
DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "','" +
DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "');";
var rst = mySql.ExecuteNonQuery(sql);
mySql.Close();
if (!rst)
return "{\"code\":501,\"msg\":\"" + mySql.Message + "\"}";
else
return "{\"code\":200,\"msg\":\"success\"}";
}
return "{\"code\":19999,\"msg\":\"输入为空\"}";
}
public string UpdateUser(string inputData)
{
if (!string.IsNullOrEmpty(inputData))
{
if (!GetSign(inputData))
return "{\"code\":999,\"msg\":\"校验失败\"}";
var id = RegexUtils.GetStringQuery(ref inputData, "id")?.Replace("'", "\\'");
var nick_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "add_nick_name"))?.Replace("'", "\\'");
var user_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "add_user_name"))?.Replace("'", "\\'");
var mobile = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "add_mobile"))?.Replace("'", "\\'");
var company_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "add_company"))?.Replace("'", "\\'");
var password = RegexUtils.GetStringQuery(ref inputData, "add_password")?.Replace("'", "\\'");
var group_id = RegexUtils.GetStringQuery(ref inputData, "group_id")?.Replace("'", "\\'");
var card_id = RegexUtils.GetStringQuery(ref inputData, "card_id")?.Replace("'", "\\'");
var notes = RegexUtils.GetStringQuery(ref inputData, "notes")?.Replace("'", "\\'");
var sa_level = RegexUtils.GetStringQuery(ref inputData, "sa_level")?.Replace("'", "\\'");
var authority = RegexUtils.GetStringQuery(ref inputData, "authority")?.Replace("'", "\\'");
int r2 = 0;
int.TryParse(RegexUtils.GetStringQuery(ref inputData, "r2"), out r2);
string conn = System.Configuration.ConfigurationManager.ConnectionStrings["ConnKJD"].ConnectionString;
MysqlUtils mySql = new MysqlUtils(conn);
string sql = "";
//sql = "select * from wxxd.user where parent_user_name='"
// + user_name + "'";
sql = "update wxxd.user set";
if (!string.IsNullOrEmpty(nick_name))
sql += " nick_name='" + nick_name + "',";
if (!string.IsNullOrEmpty(user_name))
sql += " user_name='" + user_name + "',";
if (!string.IsNullOrEmpty(mobile))
sql += " mobile='" + mobile + "',";
if (!string.IsNullOrEmpty(company_name))
sql += " company_name='" + company_name + "',";
if (!string.IsNullOrEmpty(password))
sql += " password='" + password + "',";
if (!string.IsNullOrEmpty(group_id))
sql += " group_id=" + group_id + ",";
if (!string.IsNullOrEmpty(card_id))
sql += " card_id='" + card_id + "',";
if (!string.IsNullOrEmpty(notes))
sql += " notes='" + notes + "',";
if (!string.IsNullOrEmpty(sa_level))
sql += " sa_level=" + sa_level + ",";
if (authority != null)
sql += " authority='" + authority + "',";
sql = sql.TrimEnd(',');
sql += " where id=" + id + "";
var rst = mySql.ExecuteNonQuery(sql);
mySql.Close();
if (rst)
{
return "{\"code\":200,\"msg\":\"success\"}";
}
else
{
return "{\"code\":500,\"msg\":\"" + mySql.Message + "\"}";
}
}
return "{\"code\":19999,\"msg\":\"输入为空\"}";
}
public string AddUserTopUpMsg(string inputData)
{
if (!string.IsNullOrEmpty(inputData))
{
if (!GetSign(inputData))
return "{\"code\":999,\"msg\":\"校验失败\"}";
var nick_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "add_nick_name"))?.Replace("'", "\\'");
var user_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "add_user_name"))?.Replace("'", "\\'");
var msg = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "msg"))?.Replace("'", "\\'");
if (string.IsNullOrEmpty(user_name))
return "{\"code\":501,\"msg\":\"请输入用户名\"}";
if (string.IsNullOrEmpty(msg))
return "{\"code\":501,\"msg\":\"请输入充值备注信息\"}";
string conn = System.Configuration.ConfigurationManager.ConnectionStrings["ConnKJD"].ConnectionString;
MysqlUtils mySql = new MysqlUtils(conn);
string sql;
sql = "INSERT INTO wxxd.user_points_top_up_msg (nick_name,user_name,msg) " +
"VALUES ('" + nick_name + "','" + user_name + "','" + msg + "');";
var rst = mySql.ExecuteNonQuery(sql);
mySql.Close();
if (!rst)
return "{\"code\":501,\"msg\":\"" + mySql.Message + "\"}";
else
return "{\"code\":200,\"msg\":\"success\"}";
}
return "{\"code\":19999,\"msg\":\"输入为空\"}";
}
public string UpdateUserTopUpMsg(string inputData)
{
if (!string.IsNullOrEmpty(inputData))
{
if (!GetSign(inputData))
return "{\"code\":999,\"msg\":\"校验失败\"}";
var id = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "id"))?.Replace("'", "\\'");
var op_rst = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "op_rst"))?.Replace("'", "\\'");
if (string.IsNullOrEmpty(id))
return "{\"code\":501,\"msg\":\"请输入要修改的记录\"}";
if (string.IsNullOrEmpty(op_rst))
return "{\"code\":501,\"msg\":\"请输入操作结果\"}";
string conn = System.Configuration.ConfigurationManager.ConnectionStrings["ConnKJD"].ConnectionString;
MysqlUtils mySql = new MysqlUtils(conn);
string sql;
sql = "UPDATE wxxd.user_points_top_up_msg SET op_rst='" + op_rst + "' WHERE id='" + id + "';";
var rst = mySql.ExecuteNonQuery(sql);
mySql.Close();
if (!rst)
return "{\"code\":501,\"msg\":\"" + mySql.Message + "\"}";
else
return "{\"code\":200,\"msg\":\"success\"}";
}
return "{\"code\":19999,\"msg\":\"输入为空\"}";
}
/// <summary>
/// 增加或减少用户积分
/// </summary>
/// <param name="inputData"></param>
/// <returns></returns>
public string UpdateUserPoints(string inputData)
{
if (!string.IsNullOrEmpty(inputData))
{
if (!GetSign(inputData))
return "{\"code\":999,\"msg\":\"校验失败\"}";
var user_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "update_user_name"))?.Replace("'", "\\'");
var user_nick = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "update_user_nick"))?.Replace("'", "\\'");
var delta_points = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "delta_points")).ParseToInt();
var option_type = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "option_type"))?.Replace("'", "\\'");
var operator_type = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "operator_type"))?.Replace("'", "\\'");
var operator_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "operator_name"))?.Replace("'", "\\'");
var shop_id = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "shop_id"))?.Replace("'", "\\'");
var shop_account = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "shop_account"))?.Replace("'", "\\'");
if (string.IsNullOrEmpty(user_name) || string.IsNullOrEmpty(user_nick))
{
return "{\"code\":500,\"msg\":\"操作对象不能为空\"}";
}
if (delta_points <= 0 && option_type == "续费")
{
return "{\"code\":500,\"msg\":\"续费金额错误,需大于0\"}";
}
if (delta_points == 0)
{
return "{\"code\":500,\"msg\":\"操作金额错误,不能等于0\"}";
}
if (string.IsNullOrEmpty(option_type) || string.IsNullOrEmpty(operator_type) || string.IsNullOrEmpty(operator_name))
{
return "{\"code\":500,\"msg\":\"操作或操作者信息错误\"}";
}
if (option_type != "充值" && option_type != "续费")
{
return "{\"code\":500,\"msg\":\"操作类型错误\"}";
}
string conn = System.Configuration.ConfigurationManager.ConnectionStrings["ConnKJD"].ConnectionString;
MysqlUtils mySql = new MysqlUtils(conn, true);
string sql;
int userPoints = 0;
int newUserPoints = 0;
#region 计算是否余额不足
sql = "SELECT points FROM `wxxd`.`user` WHERE user_name='" + user_name + "'";
userPoints = mySql.ExecuteFirstInt(sql);
newUserPoints = userPoints;
if (!string.IsNullOrEmpty(mySql.Message))
{
mySql.RollBack();
mySql.Close();
return "{\"code\":501,\"msg\":\"" + mySql.Message + "\"}";
}
if (option_type == "续费")
{
if (delta_points <= 0 || delta_points % 30 > 0)
{
mySql.RollBack();
mySql.Close();
return "{\"code\":501,\"msg\":\"续费点数必须是30的整倍数\"}";
}
else if (userPoints < delta_points)
{
mySql.RollBack();
mySql.Close();
return "{\"code\":500,\"msg\":\"余额不足\"}";
}
}
#endregion
sql = "UPDATE `wxxd`.`user` SET";
if (option_type == "充值")
{
sql += " points=points+" + delta_points.ParseToInt() + ",";
newUserPoints = userPoints + delta_points.ParseToInt();
}
else
{
sql += " points=points-" + delta_points.ParseToInt() + ",";
newUserPoints = userPoints - delta_points.ParseToInt();
}
sql = sql.TrimEnd(',');
sql += " WHERE user_name='" + user_name + "' AND points=" + userPoints + ";";
var changePointsRst = mySql.ExecuteAffectedRows(sql);
if (!string.IsNullOrEmpty(mySql.Message))
{
mySql.RollBack();
mySql.Close();
return "{\"code\":501,\"msg\":\"" + mySql.Message + "\"}";
}
else if (changePointsRst <= 0)
{
mySql.RollBack();
mySql.Close();
return "{\"code\":500,\"msg\":\"账户已发生改变,请刷新账户后重新操作\"}";
}
sql = " INSERT INTO wxxd.user_points_record(user_name,user_nick,points,option_type,operator_type,operator_name,shop_id,shop_account)";
sql += " VALUES(@user_name,@user_nick,@points,@option_type,@operator_type,@operator_name,@shop_id,@shop_account);";
List<MySqlParameter> paramLst = new List<MySqlParameter>();
paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "user_name", Value = user_name, });
paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "user_nick", Value = user_nick, });
paramLst.Add(new MySqlParameter() { DbType = DbType.Int32, ParameterName = "points", Value = delta_points, });
paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "option_type", Value = option_type, });
paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "operator_type", Value = operator_type, });
paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "operator_name", Value = operator_name, });
paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "shop_id", Value = shop_id, });
paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "shop_account", Value = shop_account, });
var addOptionRst = mySql.ExecuteAffectedRows(sql, paramLst.ToArray());
if (!string.IsNullOrEmpty(mySql.Message))
{
mySql.RollBack();
mySql.Close();
return "{\"code\":501,\"msg\":\"" + mySql.Message + "\"}";
}
else if (addOptionRst <= 0)
{
mySql.RollBack();
mySql.Close();
return "{\"code\":500,\"msg\":\"新增操作记录失败,请稍候重试\"}";
}
int expireTime = 0;
int newExpireTime = 0;
if (option_type == "续费")
{
sql = "SELECT expire_time‌ FROM `wxxd`.`user_points_shop_expire` WHERE shop_id='" + shop_id + "';";
expireTime = mySql.ExecuteFirstInt(sql);
if (!string.IsNullOrEmpty(mySql.Message))
{
mySql.RollBack();
mySql.Close();
return "{\"code\":501,\"msg\":\"" + mySql.Message + "\"}";
}
if (expireTime == 0)
{
newExpireTime = TimeUtils.DateTimeToTimestampSeconds(DateTime.Now.AddMonths(delta_points.ParseToInt() / 30));
sql = " INSERT INTO `wxxd`.`user_points_shop_expire` (shop_id,expire_time‌)" +
" VALUES ('" + shop_id + "'," + newExpireTime + ");";
}
else
{
DateTime expireDateTime = TimeUtils.StampToDateTime(expireTime);
if (expireDateTime < DateTime.Now)
expireDateTime = DateTime.Now.AddMonths(delta_points.ParseToInt() / 30);
else
expireDateTime = expireDateTime.AddMonths(delta_points.ParseToInt() / 30);
newExpireTime = TimeUtils.DateTimeToTimestampSeconds(expireDateTime);
sql = "UPDATE `wxxd`.`user_points_shop_expire` set expire_time‌=" + newExpireTime + " WHERE shop_id='" + shop_id + "' AND expire_time‌=" + expireTime;
}
var renewalRst = mySql.ExecuteAffectedRows(sql);
if (!string.IsNullOrEmpty(mySql.Message))
{
mySql.RollBack();
mySql.Close();
return "{\"code\":501,\"msg\":\"" + mySql.Message + "\"}";
}
else if (renewalRst <= 0)
{
mySql.RollBack();
mySql.Close();
return "{\"code\":500,\"msg\":\"店铺已发生改变,请刷新店铺后重新操作\"}";
}
}
mySql.Commit();
mySql.Close();
return "{\"code\":200,\"msg\":\"success\",\"newExpireTime\":" + newExpireTime + ",\"newUserPoints\":" + newUserPoints + "}";
}
return "{\"code\":19999,\"msg\":\"输入为空\"}";
}
public string ChangePassword(string inputData)
{
if (!GetSign(inputData))
return "{\"code\":999,\"msg\":\"校验失败\"}";
var userName = RegexUtils.GetStringJson(ref inputData, "user_name")?.Replace("'", "\\'");
var password = RegexUtils.GetStringJson(ref inputData, "password")?.Replace("'", "\\'");
var newPassword = RegexUtils.GetStringJson(ref inputData, "new_password")?.Replace("'", "\\'");
if (string.IsNullOrWhiteSpace(userName) || string.IsNullOrWhiteSpace(password) || string.IsNullOrWhiteSpace(newPassword))
{
return "{\"code\":500,\"msg\":\"输入不能为空\"}";
}
string conn = System.Configuration.ConfigurationManager.ConnectionStrings["Conn"].ConnectionString;
MysqlUtils mySql = new MysqlUtils(conn);
string sql = "select user_id,password from pepdtp.user where user_id='"
+ userName + "' and password='" + password + "'";
var dw = mySql.ExecuteDataTableRow(sql);
if (dw != null)
{
UserLoginResultParam user = new UserLoginResultParam
{
user_name = dw["user_id"].ToString(),
password = dw["password"].ToString(),
};
sql = "update pepdtp.user set password = '" + newPassword + "' where user_id='" + userName + "'";
var result = mySql.ExecuteNonQuery(sql);
mySql.Close();
if (result)
{
return "{\"code\":0,\"msg\":\"密码修改成功!\"}";
}
else
return "{\"code\":19999,\"msg\":\"密码修改失败!请稍后再试。\"}";
}
else
{
mySql.Close();
return "{\"code\":1,\"msg\":\"原密码错误。\"}";
}
}
public string UpdateWxSaleAssistantCookie(string inputData)
{
if (!string.IsNullOrEmpty(inputData))
{
var id = (RegexUtils.GetStringQuery(ref inputData, "db_id")?.Replace("'", "\\'")).ParseToInt();
if (id == 0)
id = 1;
var cookie = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "cookie"))?.Replace("'", "\\'");
var time = RegexUtils.GetStringQuery(ref inputData, "time").ParseToInt();
string time1 = RegexUtils.GetStringQuery(ref inputData, "code");
if (time1 != EncrypUtil.Encryption(time))
return "{\"code\":50000,\"msg\":\"校验失败\"}";
string conn = System.Configuration.ConfigurationManager.ConnectionStrings["ConnKJD"].ConnectionString;
MysqlUtils mySql = new MysqlUtils(conn);
string sql = "update wxxd.wx_sale_assistant_user set cookie='" + cookie + "' WHERE id=" + id + ";";
var rst = mySql.ExecuteNonQuery(sql);
mySql.Close();
if (rst && string.IsNullOrEmpty(mySql.Message))
{
return "{\"code\":200,\"msg\":\"success\"}";
}
if (!string.IsNullOrEmpty(mySql.Message))
{
return "{\"code\":500,\"msg\":\"" + mySql.Message + "\"}";
}
}
return "{\"code\":19999,\"msg\":\"输入为空\"}";
}
public string GetWxSaleAssistantCookie(string inputData)
{
if (!string.IsNullOrEmpty(inputData))
{
var id = (RegexUtils.GetStringQuery(ref inputData, "db_id")?.Replace("'", "\\'")).ParseToInt();
if (id == 0)
id = 1;
var time = RegexUtils.GetStringQuery(ref inputData, "time").ParseToInt();
string time1 = RegexUtils.GetStringQuery(ref inputData, "code");
if (time1 != EncrypUtil.Encryption(time))
return "{\"code\":50000,\"msg\":\"校验失败\"}";
string conn = System.Configuration.ConfigurationManager.ConnectionStrings["ConnKJD"].ConnectionString;
MysqlUtils mySql = new MysqlUtils(conn);
string sql = "select cookie from wxxd.wx_sale_assistant_user WHERE id=" + id + ";";
var rst = mySql.ExecuteDataTableRow(sql);
mySql.Close();
if (string.IsNullOrEmpty(mySql.Message))
{
return "{\"code\":200,\"cookie\":" + rst["cookie"] + "}";
}
if (!string.IsNullOrEmpty(mySql.Message))
{
return "{\"code\":500,\"msg\":\"" + mySql.Message + "\"}";
}
}
return "{\"code\":19999,\"msg\":\"输入为空\"}";
}
/// <summary>
/// 充值二维码
/// </summary>
/// <param name="inputData"></param>
/// <returns></returns>
public string UpdateTopUpQrcode(string inputData)
{
if (!string.IsNullOrEmpty(inputData))
{
if (!GetSign(inputData))
return "{\"code\":999,\"msg\":\"校验失败\"}";
var qrcode_base64 = (RegexUtils.GetStringQuery(ref inputData, "qrcode_base64")?.Replace("'", "\\'"));
string conn = System.Configuration.ConfigurationManager.ConnectionStrings["ConnKJD"].ConnectionString;
MysqlUtils mySql = new MysqlUtils(conn);
string sql = "UPDATE wxxd.user_top_up_qrcode SET qrcode_base64='" + qrcode_base64 + "' WHERE id=1;";
var rst = mySql.ExecuteAffectedRows(sql);
mySql.Close();
if (string.IsNullOrEmpty(mySql.Message))
{
return "{\"code\":200}";
}
if (!string.IsNullOrEmpty(mySql.Message))
{
return "{\"code\":500,\"msg\":\"" + mySql.Message + "\"}";
}
}
return "{\"code\":19999,\"msg\":\"输入为空\"}";
}
/// <summary>
/// 充值二维码
/// </summary>
/// <param name="inputData"></param>
/// <returns></returns>
public string GetTopUpQrcode(string inputData)
{
if (!string.IsNullOrEmpty(inputData))
{
if (!GetSign(inputData))
return "{\"code\":999,\"msg\":\"校验失败\"}";
string conn = System.Configuration.ConfigurationManager.ConnectionStrings["ConnKJD"].ConnectionString;
MysqlUtils mySql = new MysqlUtils(conn);
string sql = "SELECT qrcode_base64 from wxxd.user_top_up_qrcode WHERE id = 1;";
var qrcode_base64 = mySql.ExecuteFirst(sql);
mySql.Close();
if (string.IsNullOrEmpty(mySql.Message))
{
return "{\"code\":200, \"qrcode_base64\":\"" + qrcode_base64 + "\"}";
}
if (!string.IsNullOrEmpty(mySql.Message))
{
return "{\"code\":500,\"msg\":\"" + mySql.Message + "\"}";
}
}
return "{\"code\":19999,\"msg\":\"输入为空\"}";
}
/// <summary>
/// temu退回包裹的密钥
/// </summary>
public string return_package_secret_key { get; set; } = "aaMETt2bPe6YHzZ1ojbC+6wOvgtwehqc6A+/Rz+pCUU=";
/// <summary>
/// temu退回包裹的签名
/// </summary>
/// <param name="inputData"></param>
/// <returns></returns>
public string GetPackageSign(string inputData)
{
if (!string.IsNullOrEmpty(inputData))
{
var mobile = RegexUtils.GetStringQuery(ref inputData, "mobile")?.Replace("'", "\\'");
var password = RegexUtils.GetStringQuery(ref inputData, "password")?.Replace("'", "\\'");
var timestamp = RegexUtils.GetStringQuery(ref inputData, "timestamp")?.Replace("'", "\\'");
var mallId = RegexUtils.GetStringQuery(ref inputData, "mallId")?.Replace("'", "\\'");
var returnPackageNo = RegexUtils.GetStringQuery(ref inputData, "returnPackageNo")?.Replace("'", "\\'");
int r2 = RegexUtils.GetStringQuery(ref inputData, "r2").ParseToInt();
string c2 = RegexUtils.GetStringQuery(ref inputData, "c2");
if (EncrypUtil.Encryption(r2) != c2)
return "{\"code\":2,\"msg\":\"不合法的输入内容\"}";
string conn = System.Configuration.ConfigurationManager.ConnectionStrings["ConnKJD"].ConnectionString;
MysqlUtils mySql = new MysqlUtils(conn);
string sql = "select * from wxxd.user where user_name='"
+ mobile + "' and password='" + password + "'";
sql = "select * from wxxd.user where user_name='" + mobile + "'";
var dt = mySql.ExecuteDataTable(sql);
mySql.Close();
if (dt == null || dt.Rows.Count <=0)
{
return "{\"code\":1,\"msg\":\"用户不存在\"}";
}
string sign = EncrypUtil.GetMd5(timestamp + return_package_secret_key + mallId + returnPackageNo).ToLower();
return "{\"code\":200, \"sign\":\"" + sign + "\", \"msg\":\"\"}";
}
return "{\"code\":19999,\"msg\":\"输入为空\"}";
}
}
}