1383 lines
76 KiB
C#
1383 lines
76 KiB
C#
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 = RegexUtils.GetStringQuery(ref signData, "time").ParseToInt();
|
||
var 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 sub_soft_type = RegexUtils.GetStringQuery(ref inputData, "sub_soft_type")?.Replace("'", "\\'");
|
||
|
||
|
||
var version = RegexUtils.GetStringQuery(ref inputData, "version").ParseToInt();
|
||
if (sub_soft_type == "order")
|
||
{
|
||
|
||
}
|
||
else
|
||
{
|
||
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,uu.oem_id as main_oem_id,uu.postage_per_order as main_postage_per_order " +
|
||
"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() : "",
|
||
forbidden_page = row.Table.Columns.Contains("forbidden_page") ? row["forbidden_page"].ParseToString() : "",
|
||
parent_user_name = row["parent_user_name"].ToString(),
|
||
oem_id = row["oem_id"].ToString(),
|
||
points = row.Table.Columns.Contains("points") ? row["points"].ParseToInt() : 0,
|
||
shop_points_per_month = row.Table.Columns.Contains("shop_points_per_month") ? row["shop_points_per_month"].ParseToInt() : 30,
|
||
balance = row.Table.Columns.Contains("balance") ? row["balance"].ParseToDecimal() : 0,
|
||
recharge_amount_total = row.Table.Columns.Contains("recharge_amount_total") ? row["recharge_amount_total"].ParseToDecimal() : 0,
|
||
postage_per_order = row.Table.Columns.Contains("postage_per_order") ? row["postage_per_order"].ParseToNullableDecimal() : null,
|
||
};
|
||
var main_authority = row.Table.Columns.Contains("main_authority") ? row["main_authority"].ParseToString() : "";
|
||
var main_oem_id = row.Table.Columns.Contains("main_oem_id") ? row["main_oem_id"].ParseToString() : "";
|
||
var main_postage_per_order = row.Table.Columns.Contains("main_postage_per_order") ? row["main_postage_per_order"].ParseToDecimal() : 0m;
|
||
|
||
// 填写子账号的父账号权限
|
||
if (user.group_id != "3")
|
||
{
|
||
user.parent_authority = main_authority;
|
||
|
||
// 子账号积分用户权限跟随主账号
|
||
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(',');
|
||
}
|
||
|
||
// 子账号贴牌编号跟随主账号
|
||
user.oem_id = main_oem_id;
|
||
|
||
// 子账号每单扣费金额跟随主账号
|
||
user.postage_per_order = Math.Max(2.2m, main_postage_per_order);
|
||
}
|
||
if (string.IsNullOrEmpty(user.company_name))
|
||
{
|
||
user.company_name = "-";
|
||
}
|
||
|
||
if (!user.oem_id.IsNullOrEmpty())
|
||
{
|
||
sql = "select * from wxxd.oem where oem_id='" + user.oem_id + "'";
|
||
var dtr = mySql.ExecuteDataTableRow(sql);
|
||
if (!string.IsNullOrEmpty(mySql.Message) || dtr == null)
|
||
{
|
||
mySql.Close();
|
||
return "{\"code\":500,\"msg\":\"获取用户信息失败,请重试\"}";
|
||
}
|
||
user.oem_name = dtr["oem_name"].ParseToString();
|
||
user.is_oem_owner = dtr["oem_owner"].ParseToString() == user.user_name;
|
||
}
|
||
|
||
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\":\"输入为空\"}";
|
||
}
|
||
|
||
/// <summary>
|
||
/// 添加子账号
|
||
/// </summary>
|
||
/// <param name="inputData"></param>
|
||
/// <returns></returns>
|
||
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("'", "\\'");
|
||
var forbidden_page = RegexUtils.GetStringQuery(ref inputData, "forbidden_page")?.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,forbidden_page,add_time,mdy_time) " +
|
||
"VALUES ('" + nick_name + "','" + user_name + "','" + mobile + "','" + password + "','" + card_id + "','" +
|
||
group_id + "','" + company_name + "','" + notes + "','" + parent_user_name + "','" + authority + "','" + forbidden_page + "','" +
|
||
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() : "",
|
||
forbidden_page = row.Table.Columns.Contains("forbidden_page") ? row["forbidden_page"].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("'", "\\'");
|
||
var forbidden_page = RegexUtils.GetStringQuery(ref inputData, "forbidden_page")?.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 + "',";
|
||
if (forbidden_page != null)
|
||
sql += " forbidden_page='" + forbidden_page + "',";
|
||
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("'", "\\'");
|
||
var user_name_in = RegexUtils.GetStringQuery(ref inputData, "user_name_in")?.Replace("'", "\\'");
|
||
var search_user_name = RegexUtils.GetStringQuery(ref inputData, "search_user_name")?.Replace("'", "\\'");
|
||
var search_nick_name = RegexUtils.GetStringQuery(ref inputData, "search_nick_name")?.Replace("'", "\\'");
|
||
var search_company_name = RegexUtils.GetStringQuery(ref inputData, "search_company_name")?.Replace("'", "\\'");
|
||
var search_authoritys_and = RegexUtils.GetStringQuery(ref inputData, "search_authoritys_and")?.Replace("'", "\\'");
|
||
var search_authoritys_or = RegexUtils.GetStringQuery(ref inputData, "search_authoritys_or")?.Replace("'", "\\'");
|
||
var oem_id = RegexUtils.GetStringQuery(ref inputData, "oem_id")?.Replace("'", "\\'");
|
||
|
||
|
||
int page = RegexUtils.GetStringQuery(ref inputData, "page").ParseToInt();
|
||
int page_size = RegexUtils.GetStringQuery(ref inputData, "page_size").ParseToInt(20000);
|
||
|
||
|
||
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,uu.oem_id as main_oem_id,uu.postage_per_order as main_postage_per_order,o.oem_name " +
|
||
" FROM wxxd.user u " +
|
||
" LEFT JOIN wxxd.user uu ON uu.user_name=u.parent_user_name " +
|
||
" LEFT JOIN wxxd.oem o ON uu.oem_id=o.oem_id or u.oem_id=o.oem_id " +
|
||
" WHERE 1=1";
|
||
string where = "";
|
||
if (!string.IsNullOrEmpty(group_id))
|
||
where += " AND u.group_id=" + group_id;
|
||
if (!string.IsNullOrEmpty(sa_level))
|
||
where += " AND u.sa_level=" + sa_level;
|
||
if (!string.IsNullOrEmpty(user_name_in))
|
||
where += " AND u.user_name in ('" + user_name_in.Replace(",", "','") + "')";
|
||
if (!string.IsNullOrEmpty(search_user_name))
|
||
where += " AND u.user_name like '%" + search_user_name + "%'";
|
||
if (!string.IsNullOrEmpty(search_nick_name))
|
||
where += " AND u.nick_name like '%" + search_nick_name + "%'";
|
||
if (!string.IsNullOrEmpty(search_company_name))
|
||
where += " AND u.company_name like '%" + search_company_name + "%'";
|
||
if (!string.IsNullOrEmpty(search_authoritys_and))
|
||
{
|
||
var search_authority_list = search_authoritys_and.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries).Distinct().ToList();
|
||
foreach (var auth in search_authority_list)
|
||
{
|
||
where += " AND u.authority like '%" + auth + "%'";
|
||
}
|
||
}
|
||
if (!string.IsNullOrEmpty(search_authoritys_or))
|
||
{
|
||
where += " AND (";
|
||
var search_authority_list = search_authoritys_or.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries).Distinct().ToList();
|
||
int index = 0;
|
||
foreach (var auth in search_authority_list)
|
||
{
|
||
if (index == 0)
|
||
where += " u.authority like '%" + auth + "%'";
|
||
else
|
||
where += " or u.authority like '%" + auth + "%'";
|
||
index++;
|
||
}
|
||
where += " )";
|
||
}
|
||
|
||
if (!string.IsNullOrEmpty(search))
|
||
where += " AND (u.user_name like '%" + search +
|
||
"%' or u.nick_name like '%" + search +
|
||
"%' or u.company_name like '%" + search + "%')";
|
||
|
||
if (!string.IsNullOrEmpty(oem_id))
|
||
where += " AND (u.oem_id='" + oem_id + "' or uu.oem_id='" + oem_id + "')";
|
||
|
||
sql += where;
|
||
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(),
|
||
oem_id = row["oem_id"].ToString(),
|
||
oem_name = row["oem_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() : "",
|
||
forbidden_page = row.Table.Columns.Contains("forbidden_page") ? row["forbidden_page"].ParseToString() : "",
|
||
points = row.Table.Columns.Contains("points") ? row["points"].ParseToInt() : 0,
|
||
shop_points_per_month = row.Table.Columns.Contains("shop_points_per_month") ? row["shop_points_per_month"].ParseToInt() : 30,
|
||
balance = row.Table.Columns.Contains("balance") ? row["balance"].ParseToDecimal() : 0,
|
||
recharge_amount_total = row.Table.Columns.Contains("recharge_amount_total") ? row["recharge_amount_total"].ParseToDecimal() : 0,
|
||
postage_per_order = row.Table.Columns.Contains("postage_per_order") ? row["postage_per_order"].ParseToNullableDecimal() : null
|
||
};
|
||
var main_authority = row.Table.Columns.Contains("main_authority") ? row["main_authority"].ParseToString() : "";
|
||
var main_oem_id = row.Table.Columns.Contains("main_oem_id") ? row["main_oem_id"].ParseToString() : "";
|
||
var main_postage_per_order = row.Table.Columns.Contains("main_postage_per_order") ? row["main_postage_per_order"].ParseToDecimal() : 0m;
|
||
|
||
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(',');
|
||
}
|
||
|
||
// 子账号贴牌编号跟随主账号
|
||
user.oem_id = main_oem_id;
|
||
|
||
// 子账号每单扣费金额跟随主账号
|
||
user.postage_per_order = Math.Max(2.2m, main_postage_per_order);
|
||
}
|
||
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 + "}";
|
||
}
|
||
}
|
||
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("'", "\\'");
|
||
var forbidden_page = RegexUtils.GetStringQuery(ref inputData, "forbidden_page")?.Replace("'", "\\'");
|
||
var oem_id = RegexUtils.GetStringQuery(ref inputData, "oem_id")?.Replace("'", "\\'");
|
||
|
||
var shop_points_per_month = RegexUtils.GetStringQuery(ref inputData, "shop_points_per_month")?.Replace("'", "\\'");
|
||
if (shop_points_per_month.ParseToInt() <= 30) // 充值用户月积分消耗点数,最小30
|
||
shop_points_per_month = "30";
|
||
var postage_per_order = RegexUtils.GetStringQuery(ref inputData, "postage_per_order")?.Replace("'", "\\'");
|
||
if (postage_per_order.ParseToDecimal() <= 2.2m) // 每单费用
|
||
postage_per_order = "2.2";
|
||
|
||
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," +
|
||
"forbidden_page,shop_points_per_month,postage_per_order,oem_id,add_time,mdy_time) " +
|
||
"values ('" + nick_name + "','" + user_name + "','" + mobile + "','" + password + "','" + card_id + "','" +
|
||
group_id + "','" + company_name + "','" + notes + "'," + sa_level + ",'" + authority + "','" + forbidden_page + "'," +
|
||
shop_points_per_month + ",'" + postage_per_order + "',@oem_id,'" +
|
||
DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "','" +
|
||
DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "');";
|
||
|
||
List<MySqlParameter> paramLst = new List<MySqlParameter>();
|
||
paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "oem_id", Value = oem_id, });
|
||
|
||
var rst = mySql.ExecuteNonQuery(sql, paramLst.ToArray());
|
||
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("'", "\\'");
|
||
var forbidden_page = RegexUtils.GetStringQuery(ref inputData, "forbidden_page")?.Replace("'", "\\'");
|
||
var shop_points_per_month = RegexUtils.GetStringQuery(ref inputData, "shop_points_per_month")?.Replace("'", "\\'");
|
||
var postage_per_order = RegexUtils.GetStringQuery(ref inputData, "postage_per_order")?.Replace("'", "\\'");
|
||
var oem_id = RegexUtils.GetStringQuery(ref inputData, "oem_id")?.Replace("'", "\\'");
|
||
|
||
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 + "',";
|
||
if (forbidden_page != null)
|
||
sql += " forbidden_page='" + forbidden_page + "',";
|
||
if (shop_points_per_month != null)
|
||
sql += " shop_points_per_month=" + shop_points_per_month + ",";
|
||
if (postage_per_order != null)
|
||
sql += " postage_per_order=" + postage_per_order + ",";
|
||
if (oem_id != null)
|
||
sql += " oem_id='" + oem_id + "',";
|
||
sql = sql.TrimEnd(',');
|
||
sql += " where id=" + id + "";
|
||
|
||
var rst = mySql.ExecuteAffectedRows(sql);
|
||
mySql.Close();
|
||
if (!mySql.Message.IsNullOrEmpty())
|
||
{
|
||
return "{\"code\":500,\"msg\":\"" + mySql.Message + "\"}";
|
||
}
|
||
return "{\"code\":200,\"msg\":\"success\",\"affected_rows\":" + rst + "}";
|
||
}
|
||
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 operator_nick = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "operator_nick"))?.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 != "续费" && option_type != "转移")
|
||
{
|
||
return "{\"code\":500,\"msg\":\"操作类型错误\"}";
|
||
}
|
||
|
||
string conn = System.Configuration.ConfigurationManager.ConnectionStrings["ConnKJD"].ConnectionString;
|
||
MysqlUtils mySql = new MysqlUtils(conn, true);
|
||
string sql;
|
||
int userPoints;
|
||
int newUserPoints;
|
||
int operatorPoints;
|
||
int newOperatorPoints;
|
||
int shopPointsPerMonth = 30;
|
||
|
||
// 账户之间的转移单独写
|
||
if (option_type == "转移")
|
||
{
|
||
// 转移查找自己账户及对方账户确定余额足够
|
||
sql = "SELECT points FROM `wxxd`.`user` WHERE user_name='" + operator_name + "'";
|
||
operatorPoints = mySql.ExecuteFirstInt(sql);
|
||
if (operatorPoints < delta_points)
|
||
{
|
||
mySql.RollBack();
|
||
mySql.Close();
|
||
return "{\"code\":500,\"msg\":\"余额不足\"}";
|
||
}
|
||
sql = "SELECT points FROM `wxxd`.`user` WHERE user_name='" + user_name + "'";
|
||
userPoints = mySql.ExecuteFirstInt(sql);
|
||
if (userPoints < -delta_points)
|
||
{
|
||
mySql.RollBack();
|
||
mySql.Close();
|
||
return "{\"code\":500,\"msg\":\"对方账户余额不足\"}";
|
||
}
|
||
|
||
newUserPoints = userPoints + delta_points.ParseToInt();
|
||
sql = " UPDATE `wxxd`.`user` SET points=" + newUserPoints.ParseToInt();
|
||
sql += " WHERE user_name='" + user_name + "' AND points=" + userPoints + ";";
|
||
var toPointsRst = mySql.ExecuteAffectedRows(sql);
|
||
if (!string.IsNullOrEmpty(mySql.Message))
|
||
{
|
||
mySql.RollBack();
|
||
mySql.Close();
|
||
return "{\"code\":501,\"msg\":\"" + mySql.Message + "\"}";
|
||
}
|
||
else if (toPointsRst <= 0)
|
||
{
|
||
mySql.RollBack();
|
||
mySql.Close();
|
||
return "{\"code\":500,\"msg\":\"收款账户已发生改变,请刷新账户后重新操作\"}";
|
||
}
|
||
|
||
newOperatorPoints = operatorPoints - delta_points.ParseToInt();
|
||
sql = " UPDATE `wxxd`.`user` SET points=" + newOperatorPoints.ParseToInt();
|
||
sql += " WHERE user_name='" + operator_name + "' AND points=" + operatorPoints + ";";
|
||
var fromPointsRst = mySql.ExecuteAffectedRows(sql);
|
||
if (!string.IsNullOrEmpty(mySql.Message))
|
||
{
|
||
mySql.RollBack();
|
||
mySql.Close();
|
||
return "{\"code\":501,\"msg\":\"" + mySql.Message + "\"}";
|
||
}
|
||
else if (fromPointsRst <= 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 = delta_points > 0 ? "转入" : "转出", });
|
||
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\":\"新增操作记录失败,请稍候重试\"}";
|
||
}
|
||
|
||
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);";
|
||
paramLst = new List<MySqlParameter>();
|
||
paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "user_name", Value = operator_name, });
|
||
paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "user_nick", Value = operator_nick, });
|
||
paramLst.Add(new MySqlParameter() { DbType = DbType.Int32, ParameterName = "points", Value = delta_points, });
|
||
paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "option_type", Value = delta_points > 0 ? "转出" : "转入", });
|
||
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, });
|
||
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\":\"新增操作记录失败,请稍候重试\"}";
|
||
}
|
||
|
||
mySql.Commit();
|
||
mySql.Close();
|
||
return "{\"code\":200,\"msg\":\"success\",\"newOperatorPoints\":" + newOperatorPoints + ",\"newUserPoints\":" + newUserPoints + "}";
|
||
}
|
||
else
|
||
{
|
||
#region 计算是否余额不足
|
||
sql = "SELECT points FROM `wxxd`.`user` WHERE user_name='" + user_name + "'";
|
||
userPoints = mySql.ExecuteFirstInt(sql);
|
||
|
||
if (!string.IsNullOrEmpty(mySql.Message))
|
||
{
|
||
mySql.RollBack();
|
||
mySql.Close();
|
||
return "{\"code\":501,\"msg\":\"" + mySql.Message + "\"}";
|
||
}
|
||
if (option_type == "续费")
|
||
{
|
||
sql = "SELECT shop_points_per_month FROM `wxxd`.`user` WHERE user_name='" + user_name + "'";
|
||
shopPointsPerMonth = mySql.ExecuteFirstInt(sql); // 店铺续费一个月的点数,默认30,可以设置为其他值
|
||
if (!string.IsNullOrEmpty(mySql.Message))
|
||
{
|
||
mySql.RollBack();
|
||
mySql.Close();
|
||
return "{\"code\":501,\"msg\":\"" + mySql.Message + "\"}";
|
||
}
|
||
shopPointsPerMonth = Math.Max(30, shopPointsPerMonth);
|
||
|
||
if (delta_points <= 0 || delta_points % shopPointsPerMonth > 0)
|
||
{
|
||
mySql.RollBack();
|
||
mySql.Close();
|
||
return "{\"code\":501,\"msg\":\"续费点数必须是" + shopPointsPerMonth + "的整倍数\"}";
|
||
}
|
||
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() / shopPointsPerMonth));
|
||
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() / shopPointsPerMonth);
|
||
else
|
||
expireDateTime = expireDateTime.AddMonths(delta_points.ParseToInt() / shopPointsPerMonth);
|
||
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\":\"输入为空\"}";
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// 增加或减少用户积分
|
||
/// </summary>
|
||
/// <param name="inputData"></param>
|
||
/// <returns></returns>
|
||
public string UpdateUserBalance(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_balance = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "delta_balance")).ParseToDecimal();
|
||
var option_type = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "option_type"))?.Replace("'", "\\'");
|
||
var operator_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "operator_name"))?.Replace("'", "\\'");
|
||
|
||
if (string.IsNullOrEmpty(user_name) || string.IsNullOrEmpty(user_nick))
|
||
{
|
||
return "{\"code\":500,\"msg\":\"操作对象不能为空\"}";
|
||
}
|
||
if (delta_balance <= 0 && option_type == "消费")
|
||
{
|
||
return "{\"code\":500,\"msg\":\"消费金额错误,需大于0\"}";
|
||
}
|
||
if (delta_balance == 0)
|
||
{
|
||
return "{\"code\":500,\"msg\":\"操作金额错误,不能等于0\"}";
|
||
}
|
||
if (string.IsNullOrEmpty(option_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;
|
||
decimal balance = 0;
|
||
decimal recharge_amount_total = 0;
|
||
decimal newBalance = 0;
|
||
decimal newRechargeAmountTotal = 0;
|
||
|
||
#region 计算是否余额不足
|
||
sql = "SELECT balance,recharge_amount_total FROM `wxxd`.`user` WHERE user_name='" + user_name + "'";
|
||
var dataRow = mySql.ExecuteDataTableRow(sql);
|
||
if (!string.IsNullOrEmpty(mySql.Message))
|
||
{
|
||
mySql.RollBack();
|
||
mySql.Close();
|
||
return "{\"code\":501,\"msg\":\"" + mySql.Message + "\"}";
|
||
}
|
||
if (dataRow == null)
|
||
{
|
||
mySql.RollBack();
|
||
mySql.Close();
|
||
return "{\"code\":501,\"msg\":\"用户不存在\"}";
|
||
}
|
||
try
|
||
{
|
||
balance = dataRow["balance"].ParseToDecimal();
|
||
newBalance = balance;
|
||
recharge_amount_total = dataRow["recharge_amount_total"].ParseToDecimal();
|
||
newRechargeAmountTotal = recharge_amount_total;
|
||
}
|
||
catch
|
||
{
|
||
}
|
||
//if (option_type == "消费")
|
||
//{
|
||
// sql = "SELECT shop_points_per_month FROM `wxxd`.`user` WHERE user_name='" + user_name + "'";
|
||
// shopPointsPerMonth = mySql.ExecuteFirstInt(sql); // 店铺消费一个月的点数,默认30,可以设置为其他值
|
||
// if (!string.IsNullOrEmpty(mySql.Message))
|
||
// {
|
||
// mySql.RollBack();
|
||
// mySql.Close();
|
||
// return "{\"code\":501,\"msg\":\"" + mySql.Message + "\"}";
|
||
// }
|
||
// shopPointsPerMonth = Math.Max(30, shopPointsPerMonth);
|
||
|
||
// if (delta_balance <= 0 || delta_balance % shopPointsPerMonth > 0)
|
||
// {
|
||
// mySql.RollBack();
|
||
// mySql.Close();
|
||
// return "{\"code\":501,\"msg\":\"消费点数必须是" + shopPointsPerMonth + "的整倍数\"}";
|
||
// }
|
||
// else if (balance < delta_balance)
|
||
// {
|
||
// mySql.RollBack();
|
||
// mySql.Close();
|
||
// return "{\"code\":500,\"msg\":\"余额不足\"}";
|
||
// }
|
||
//}
|
||
#endregion
|
||
|
||
sql = "UPDATE `wxxd`.`user` SET";
|
||
if (option_type == "充值")
|
||
{
|
||
newBalance = balance + delta_balance;
|
||
sql += " balance=" + newBalance + ",";
|
||
newRechargeAmountTotal = recharge_amount_total + delta_balance;
|
||
sql += " recharge_amount_total=" + newRechargeAmountTotal + ",";
|
||
}
|
||
else
|
||
{
|
||
newBalance = balance - delta_balance.ParseToInt();
|
||
sql += " balance=" + newBalance + ",";
|
||
}
|
||
sql = sql.TrimEnd(',');
|
||
sql += " WHERE user_name='" + user_name + "' AND balance=" + balance + " AND recharge_amount_total=" + recharge_amount_total + ";";
|
||
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\":\"" + option_type + "失败,账户余额已发生改变,请刷新账户后重新操作\"}";
|
||
}
|
||
|
||
sql = " INSERT INTO wxxd.user_payment_record(type,amount,balance,user_name,create_by,create_time,update_by,update_time,counterparty_account_name)";
|
||
sql += " VALUES(@type,@amount,@balance,@user_name,@create_by,@create_time,@update_by,@update_time,@counterparty_account_name);";
|
||
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.Decimal, ParameterName = "amount", Value = delta_balance, });
|
||
paramLst.Add(new MySqlParameter() { DbType = DbType.Decimal, ParameterName = "balance", Value = newBalance, });
|
||
paramLst.Add(new MySqlParameter() { DbType = DbType.Int32, ParameterName = "type", Value = option_type == "充值" ? 1 : 0, });
|
||
paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "create_by", Value = operator_name, });
|
||
paramLst.Add(new MySqlParameter() { DbType = DbType.DateTime, ParameterName = "create_time", Value = DateTime.Now, });
|
||
paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "update_by", Value = operator_name, });
|
||
paramLst.Add(new MySqlParameter() { DbType = DbType.DateTime, ParameterName = "update_time", Value = DateTime.Now, });
|
||
paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "counterparty_account_name", Value = operator_name, });
|
||
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_balance.ParseToInt() / shopPointsPerMonth));
|
||
// 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_balance.ParseToInt() / shopPointsPerMonth);
|
||
// else
|
||
// expireDateTime = expireDateTime.AddMonths(delta_balance.ParseToInt() / shopPointsPerMonth);
|
||
// 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\",\"newRechargeAmountTotal\":" + newRechargeAmountTotal + ",\"newBalance\":" + newBalance + "}";
|
||
}
|
||
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("'", "\\'"));
|
||
var agent_code = (RegexUtils.GetStringQuery(ref inputData, "agent_code")?.Replace("'", "\\'")).ParseToString();
|
||
|
||
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 agent_code=" + agent_code + ";";
|
||
string sql = "INSERT INTO wxxd.user_top_up_qrcode (agent_code,qrcode_base64) VALUES('" + agent_code + "','" + qrcode_base64 + "')" +
|
||
"ON DUPLICATE KEY UPDATE agent_code=VALUES(agent_code),qrcode_base64=VALUES(qrcode_base64);";
|
||
|
||
var rst = mySql.ExecuteAffectedRows(sql);
|
||
mySql.Close();
|
||
|
||
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\":\"校验失败\"}";
|
||
|
||
var agent_code = (RegexUtils.GetStringQuery(ref inputData, "agent_code")?.Replace("'", "\\'")).ParseToString();
|
||
|
||
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 agent_code = '" + agent_code + "';";
|
||
|
||
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\":\"输入为空\"}";
|
||
}
|
||
}
|
||
} |