Files
StoreWeb/Store.KJDWebService/Services/WXUserService.cs
T

1735 lines
96 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 StoreHub.KJDWebService.Models;
using StoreHub.Framework.Repositorys;
using Microsoft.Extensions.Configuration;
using StoreHub.KJDWebService.Models.WxModel;
using StoreHub.KJDWebService.Commons;
using MySql.Data.MySqlClient;
using NaiBa.Util.Extension;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Net;
using System.Reflection;
using System.Threading;
namespace StoreHub.KJDWebService.Services
{
public class WXUserService : ServiceBase
{
public WXUserService(SqlRepository sqlRepository, IConfiguration configuration) : base(sqlRepository, configuration)
{
}
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 static DateTime dtAuthorizationExpireTime = DateTime.Now;
public static string e57Authorization = "";
public string GetE57Authorization(string inputData)
{
if (!string.IsNullOrEmpty(inputData))
{
if (!GetSign(inputData))
return "{\"code\":999,\"msg\":\"校验失败\"}";
if (dtAuthorizationExpireTime <= DateTime.Now || string.IsNullOrEmpty(e57Authorization))
{
//{"msg":"username required","code":500}
//{"msg":"操作成功","code":200,"token":"eyJhbGciOiJIUzUxMiJ9.eyJsb2dpbl91c2VyX2tleSI6ImIxYTU3OWI2LTM0NWUtNDQwOC05ZjFiLTk0ZTUyOTIxMzlmZCJ9.3qvRXiWeCo_cIOHs6gbCHqDrmfCrH6XDOrMY0BjuUOIu3yVsCwFGVO0hT0A5Wssh_VFPJLouyb1moTcODt0vow"}
var url = "https://po.e57.cn/prod-api/api/sys-api/internal/createTokenForUser";
var data = "{\"username\":\"admin\"}";
var html = HttpUtils.e57PostResponse(url, data, "");
e57Authorization = RegexUtils.GetStringJson(ref html, "token").ParseToString();
dtAuthorizationExpireTime = DateTime.Now.AddHours(2);
//dtAuthorizationExpireTime = DateTime.Now.AddMinutes(10);
return html.Replace("token", "authorization");
}
return "{\"code\":200,\"authorization\":\"" + e57Authorization + "\"}";
}
return "{\"code\":19999,\"msg\":\"输入为空\"}";
}
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")
{
if (version < (System.Configuration.ConfigurationManager.ConnectionStrings["WxFindOrderLimitVersion"]?.ConnectionString).ParseToInt())
return "{\"code\":1,\"msg\":\"当前版本过于陈旧,请立即升级新版\"}";
}
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 = "ConnKJD";
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," +
"uu.refund_postage_per_order as main_refund_postage_per_order,uu.gift_oem_amount_per_order as main_gift_oem_amount_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,
refund_postage_per_order = row.Table.Columns.Contains("refund_postage_per_order") ? row["refund_postage_per_order"].ParseToNullableDecimal() : null,
gift_oem_amount_per_order = row.Table.Columns.Contains("gift_oem_amount_per_order") ? row["gift_oem_amount_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;
var main_refund_postage_per_order = row.Table.Columns.Contains("main_refund_postage_per_order") ? row["main_refund_postage_per_order"].ParseToDecimal() : 0m;
var main_gift_oem_amount_per_order = row.Table.Columns.Contains("main_gift_oem_amount_per_order") ? row["main_gift_oem_amount_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);
user.refund_postage_per_order = Math.Max(2.5m, main_refund_postage_per_order);
user.gift_oem_amount_per_order = Math.Max(0m, main_gift_oem_amount_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 = "ConnKJD";
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 = "ConnKJD";
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 = "ConnKJD";
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 = "ConnKJD";
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("'", "\\'");
var is_not_count = RegexUtils.GetStringQuery(ref inputData, "is_not_count")?.Replace("'", "\\'");
int page = RegexUtils.GetStringQuery(ref inputData, "page").ParseToInt();
int page_size = RegexUtils.GetStringQuery(ref inputData, "page_size").ParseToInt(5000);
string conn = "ConnKJD";
MysqlUtils mySql = new MysqlUtils(conn);
//string sql = "select * from wxxd.user where group_id=3";
string sql = "select COUNT(*) " +
" 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;
int count = -1;
if (is_not_count != "true")
{
count = mySql.ExecuteFirstInt(sql);
if (!mySql.Message.IsNullOrEmpty())
{
mySql.Close();
return "{\"code\":500,\"msg\":\"" + mySql.Message + "\"}";
}
if (count == 0)
{
return "{\"code\":200,\"msg\":\"success\",\"data\":[]}";
}
}
sql = "select u.*,uu.authority as main_authority,uu.oem_id as main_oem_id," +
" uu.postage_per_order as main_postage_per_order," +
" uu.refund_postage_per_order as main_refund_postage_per_order," +
" uu.gift_oem_amount_per_order as main_gift_oem_amount_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";
sql += where;
sql += " ORDER BY u.id desc";
sql += " limit " + Math.Max(page - 1, 0) * page_size + "," + page_size;
var dt = mySql.ExecuteDataTable(sql);
mySql.Close();
if (!mySql.Message.IsNullOrEmpty())
{
mySql.Close();
return "{\"code\":500,\"msg\":\"" + mySql.Message + "\"}";
}
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,
refund_postage_per_order = row.Table.Columns.Contains("refund_postage_per_order") ? row["refund_postage_per_order"].ParseToNullableDecimal() : null,
gift_oem_amount_per_order = row.Table.Columns.Contains("gift_oem_amount_per_order") ? row["gift_oem_amount_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;
var main_refund_postage_per_order = row.Table.Columns.Contains("main_refund_postage_per_order") ? row["main_refund_postage_per_order"].ParseToDecimal() : 0m;
var main_gift_oem_amount_per_order = row.Table.Columns.Contains("main_gift_oem_amount_per_order") ? row["main_gift_oem_amount_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);
user.refund_postage_per_order = Math.Max(2.5m, main_refund_postage_per_order);
user.gift_oem_amount_per_order = Math.Max(0m, main_gift_oem_amount_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 + ",\"count\":" + count + "}";
}
}
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";
var refund_postage_per_order = RegexUtils.GetStringQuery(ref inputData, "refund_postage_per_order")?.Replace("'", "\\'");
if (refund_postage_per_order.ParseToDecimal() <= 2.5m) // 每单费用
refund_postage_per_order = "2.5";
var gift_oem_amount_per_order = RegexUtils.GetStringQuery(ref inputData, "gift_oem_amount_per_order")?.Replace("'", "\\'");
if (gift_oem_amount_per_order.ParseToDecimal() < 0m) // 每单费用
gift_oem_amount_per_order = "0";
string conn = "ConnKJD";
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,refund_postage_per_order,gift_oem_amount_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 + "," + refund_postage_per_order + "," + gift_oem_amount_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 refund_postage_per_order = RegexUtils.GetStringQuery(ref inputData, "refund_postage_per_order")?.Replace("'", "\\'");
var gift_oem_amount_per_order = RegexUtils.GetStringQuery(ref inputData, "gift_oem_amount_per_order")?.Replace("'", "\\'");
var oem_id = RegexUtils.GetStringQuery(ref inputData, "oem_id")?.Replace("'", "\\'");
string conn = "ConnKJD";
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 (refund_postage_per_order != null)
sql += " refund_postage_per_order=" + refund_postage_per_order + ",";
if (gift_oem_amount_per_order != null)
sql += " gift_oem_amount_per_order=" + gift_oem_amount_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 = "ConnKJD";
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 = "ConnKJD";
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 = "ConnKJD";
MysqlUtils mySql = new MysqlUtils(conn, true);
string sql;
decimal userPoints;
decimal userPointsNew;
decimal userTotalPoints;
decimal userTotalPointsNew;
decimal operatorPoints;
decimal operatorPointsNew;
decimal shopPointsPerMonth = 30;
// 账户之间的转移单独写
if (option_type == "转移")
{
// 转移查找自己账户及对方账户确定余额足够
sql = "SELECT points FROM `wxxd`.`user` WHERE user_name='" + operator_name + "'";
operatorPoints = mySql.ExecuteFirstDecimal(sql);
if (!mySql.Message.IsNullOrEmpty())
{
mySql.RollBack();
mySql.Close();
return "{\"code\":500,\"msg\":\"查询错误:" + mySql.Message + "\"}";
}
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.ExecuteFirstDecimal(sql);
if (!mySql.Message.IsNullOrEmpty())
{
mySql.RollBack();
mySql.Close();
return "{\"code\":500,\"msg\":\"查询错误:" + mySql.Message + "\"}";
}
if (userPoints < -delta_points)
{
mySql.RollBack();
mySql.Close();
return "{\"code\":500,\"msg\":\"对方账户余额不足\"}";
}
sql = "SELECT recharge_points_total FROM `wxxd`.`user` WHERE user_name='" + user_name + "'";
userTotalPoints = mySql.ExecuteFirstDecimal(sql);
if (!mySql.Message.IsNullOrEmpty())
{
mySql.RollBack();
mySql.Close();
return "{\"code\":500,\"msg\":\"查询错误:" + mySql.Message + "\"}";
}
userPointsNew = userPoints + delta_points;
userTotalPointsNew = userTotalPoints + delta_points;
sql = " UPDATE `wxxd`.`user` SET points=" + userPointsNew + ",recharge_points_total=" + userTotalPointsNew;
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\":\"收款账户已发生改变,请刷新账户后重新操作\"}";
}
operatorPointsNew = operatorPoints - delta_points;
sql = " UPDATE `wxxd`.`user` SET points=" + operatorPointsNew;
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,delta_points,new_points,option_type,operator_type,operator_name,shop_id,shop_account,counterparty_account_name)";
sql += " VALUES" +
" (@user_name,@user_nick,@delta_points,@new_points,@option_type,@operator_type,@operator_name,@shop_id,@shop_account,@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.String, ParameterName = "user_nick", Value = user_nick, });
paramLst.Add(new MySqlParameter() { DbType = DbType.Decimal, ParameterName = "delta_points", Value = delta_points, });
paramLst.Add(new MySqlParameter() { DbType = DbType.Decimal, ParameterName = "new_points", Value = userPointsNew, });
paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "option_type", Value = "转入" });
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, });
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\":\"新增操作记录失败,请稍候重试\"}";
}
// 转出
sql = " INSERT INTO wxxd.user_points_record" +
"(user_name,user_nick,delta_points,new_points,option_type,operator_type,operator_name,shop_id,shop_account,counterparty_account_name)";
sql += " VALUES" +
"(@user_name,@user_nick,@delta_points,@new_points,@option_type,@operator_type,@operator_name,@shop_id,@shop_account,@counterparty_account_name);";
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.Decimal, ParameterName = "delta_points", Value = delta_points, });
paramLst.Add(new MySqlParameter() { DbType = DbType.Decimal, ParameterName = "new_points", Value = operatorPointsNew, });
paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "option_type", Value = "转出" });
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, });
paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "counterparty_account_name", Value = user_name, });
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\":" + operatorPointsNew + ",\"newUserPoints\":" + userPointsNew + "}";
}
else
{
#region 计算是否余额不足
sql = "SELECT points FROM `wxxd`.`user` WHERE user_name='" + user_name + "'";
userPoints = mySql.ExecuteFirstDecimal(sql);
if (!string.IsNullOrEmpty(mySql.Message))
{
mySql.RollBack();
mySql.Close();
return "{\"code\":501,\"msg\":\"" + mySql.Message + "\"}";
}
sql = "SELECT recharge_points_total FROM `wxxd`.`user` WHERE user_name='" + user_name + "'";
userTotalPoints = mySql.ExecuteFirstDecimal(sql);
if (!mySql.Message.IsNullOrEmpty())
{
mySql.RollBack();
mySql.Close();
return "{\"code\":500,\"msg\":\"查询错误:" + mySql.Message + "\"}";
}
if (option_type == "续费")
{
sql = "SELECT shop_points_per_month FROM `wxxd`.`user` WHERE user_name='" + user_name + "'";
shopPointsPerMonth = mySql.ExecuteFirstDecimal(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.ParseToInt().ParseToDecimal() != delta_points || delta_points.ParseToInt() % shopPointsPerMonth.ParseToInt() > 0)
{
mySql.RollBack();
mySql.Close();
return "{\"code\":501,\"msg\":\"续费点数必须是" + shopPointsPerMonth.ParseToInt() + "的整倍数\"}";
}
else if (userPoints < delta_points)
{
mySql.RollBack();
mySql.Close();
return "{\"code\":500,\"msg\":\"余额不足\"}";
}
}
#endregion
sql = "UPDATE `wxxd`.`user` SET";
if (option_type == "充值")
{
userPointsNew = userPoints + delta_points;
sql += " points=" + userPointsNew + ",";
userTotalPointsNew = userTotalPoints + delta_points;
sql += " recharge_points_total=" + userTotalPointsNew + ",";
}
else
{
userPointsNew = userPoints - delta_points;
sql += " points=" + userPointsNew + ",";
}
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,delta_points,new_points,option_type,operator_type,operator_name,shop_id,shop_account)";
sql += " VALUES(@user_name,@user_nick,@delta_points,@new_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.Decimal, ParameterName = "delta_points", Value = delta_points, });
paramLst.Add(new MySqlParameter() { DbType = DbType.Decimal, ParameterName = "new_points", Value = userPointsNew, });
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.ParseToInt()));
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.ParseToInt());
else
expireDateTime = expireDateTime.AddMonths(delta_points.ParseToInt() / shopPointsPerMonth.ParseToInt());
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\":" + userPointsNew + "}";
}
}
return "{\"code\":19999,\"msg\":\"输入为空\"}";
}
public string GetUserPoints(string inputData)
{
if (!string.IsNullOrEmpty(inputData))
{
if (!GetSign(inputData))
return "{\"code\":999,\"msg\":\"校验失败\"}";
var option_type_in = RegexUtils.GetStringQuery(ref inputData, "option_type_in")?.Replace("'", "\\'");
var user_name_in = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "user_name_in"))?.Replace("'", "\\'");
var shop_id_in = RegexUtils.GetStringQuery(ref inputData, "shop_id_in")?.Replace("'", "\\'");
var shop_account_in = RegexUtils.GetStringQuery(ref inputData, "shop_account_in")?.Replace("'", "\\'");
var create_time_begin = RegexUtils.GetStringQuery(ref inputData, "create_time_begin")?.Replace("'", "\\'");
var create_time_end = RegexUtils.GetStringQuery(ref inputData, "create_time_end")?.Replace("'", "\\'");
var is_not_count = RegexUtils.GetStringQuery(ref inputData, "is_not_count")?.Replace("'", "\\'");
int page = RegexUtils.GetStringQuery(ref inputData, "page").ParseToInt();
int page_size = RegexUtils.GetStringQuery(ref inputData, "page_size").ParseToInt(200);
string conn = "ConnKJD";
MysqlUtils mySql = new MysqlUtils(conn);
string sql = "SELECT count(*) " +
" FROM wxxd.user_points_record up " +
" WHERE 1=1";
string where = "";
if (!string.IsNullOrEmpty(option_type_in))
where += " AND up.option_type in ('" + option_type_in + "')";
if (!string.IsNullOrEmpty(user_name_in))
where += " AND up.user_name in ('" + user_name_in.Replace(",", "','") + "')";
if (!string.IsNullOrEmpty(shop_id_in))
where += " AND up.shop_id in ('" + shop_id_in.Replace(",", "','") + "')";
if (!string.IsNullOrEmpty(shop_account_in))
where += " AND up.shop_account in ('" + shop_account_in.Replace(",", "','") + "')";
if (!string.IsNullOrEmpty(create_time_begin))
where += " AND up.add_time >= '" + create_time_begin + "'";
if (!string.IsNullOrEmpty(create_time_end))
where += " AND up.add_time <= '" + create_time_end + "'";
sql += where;
int count = -1;
if (is_not_count != "true")
{
count = mySql.ExecuteFirstInt(sql);
if (!mySql.Message.IsNullOrEmpty())
{
mySql.Close();
return "{\"code\":500,\"msg\":\"" + mySql.Message + "\"}";
}
}
sql = "SELECT * " +
" FROM wxxd.user_points_record up " +
" WHERE 1=1";
sql += where;
sql += " ORDER BY up.add_time desc ";
sql += " limit " + Math.Max(page - 1, 0) * page_size + "," + page_size;
var dt = mySql.ExecuteDataTable(sql);
mySql.Close();
if (!string.IsNullOrEmpty(mySql.Message))
{
return "{\"code\":500,\"msg\":\"" + mySql.Message + "\"}";
}
if (dt != null)
{
List<user_points_record_info> userPaymentList = new List<user_points_record_info>();
foreach (DataRow row in dt.Rows)
{
user_points_record_info userPayment = new user_points_record_info
{
id = Convert.ToInt32(row["id"]),
user_name = row["user_name"].ParseToString(),
delta_points = row["delta_points"].ParseToInt(),
new_points = row["new_points"].ParseToNullableInt(),
operator_name = row["operator_name"].ParseToString(),
operator_type = row["operator_type"].ParseToString(),
option_type = row["option_type"].ParseToString(),
shop_account = row["shop_account"].ParseToString(),
shop_id = row["shop_id"].ParseToString(),
user_nick = row["user_nick"].ParseToString(),
remark = row["remark"].ParseToString(),
add_time = row["add_time"].ParseToString().ParseToDateTime(),
counterparty_account_name = row["counterparty_account_name"].ParseToString(),
};
userPaymentList.Add(userPayment);
}
var data = JsonUtils.SerializeObjectToString(userPaymentList);
return "{\"code\":200,\"msg\":\"success\",\"data\":" + data + ",\"count\":\"" + count + "\"}";
}
}
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 = "ConnKJD";
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 GetUserBalance(string inputData)
{
// ALTER TABLE books ALTER INDEX idx_name INVISIBLE; --隐藏
// ALTER TABLE books ALTER INDEX idx_name VISIBLE; --恢复
// 双字匹配的全文索引 ALTER TABLE `user_payment_record` ADD FULLTEXT INDEX `remark_fulltext` (`remark`) WITH parser ngram
if (!string.IsNullOrEmpty(inputData))
{
if (!GetSign(inputData))
return "{\"code\":999,\"msg\":\"校验失败\"}";
var timeCalc = DateTime.Now;
var type_in = RegexUtils.GetStringQuery(ref inputData, "type_in")?.Replace("'", "\\'");
var user_name_in = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "user_name_in"))?.Replace("'", "\\'");
var order_id_in = RegexUtils.GetStringQuery(ref inputData, "order_id_in")?.Replace("'", "\\'");
var after_sale_id_in = RegexUtils.GetStringQuery(ref inputData, "after_sale_id_in")?.Replace("'", "\\'");
var create_time_begin = RegexUtils.GetStringQuery(ref inputData, "create_time_begin")?.Replace("'", "\\'");
var create_time_end = RegexUtils.GetStringQuery(ref inputData, "create_time_end")?.Replace("'", "\\'");
var is_not_count = RegexUtils.GetStringQuery(ref inputData, "is_not_count")?.Replace("'", "\\'");
var remark_fulltext = RegexUtils.GetStringQuery(ref inputData, "remark_fulltext")?.Replace("'", "\\'");
int page = RegexUtils.GetStringQuery(ref inputData, "page").ParseToInt();
int page_size = RegexUtils.GetStringQuery(ref inputData, "page_size").ParseToInt(200);
string conn = "ConnKJD";
MysqlUtils mySql = new MysqlUtils(conn);
string sql = "SELECT count(*) " +
" FROM wxxd.user_payment_record up " +
" WHERE 1=1";
string where = "";
if (!string.IsNullOrEmpty(type_in))
where += " AND up.type in (" + type_in + ")";
if (!string.IsNullOrEmpty(user_name_in))
where += " AND up.user_name in ('" + user_name_in.Replace(",", "','") + "')";
if (!string.IsNullOrEmpty(order_id_in))
where += " AND up.order_id in ('" + order_id_in.Replace(",", "','") + "')";
if (!string.IsNullOrEmpty(after_sale_id_in))
where += " AND up.after_sale_id in ('" + after_sale_id_in.Replace(",", "','") + "')";
if (!string.IsNullOrEmpty(create_time_begin))
where += " AND up.create_time >= '" + create_time_begin + "'";
if (!string.IsNullOrEmpty(create_time_end))
where += " AND up.create_time <= '" + create_time_end + "'";
//if (!string.IsNullOrEmpty(remark_fulltext))
//{
// List<string> fullTextSearchStr = new List<string>();
// var remark_fulltextLst = remark_fulltext.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
// foreach (var t in remark_fulltextLst)
// {
// var t1 = t;
// while (t1.Length >= 12)
// {
// fullTextSearchStr.Add(t1.Substring(0, 10));
// t1 = t1.Substring(10);
// }
// fullTextSearchStr.Add(t1);
// }
// where += " AND MATCH(remark) AGAINST('" + string.Join(" +", fullTextSearchStr) + "' IN BOOLEAN MODE) ";
// //where += " AND MATCH(remark) AGAINST('" + string.Join(" +", fullTextSearchStr) + "' IN NATURAL LANGUAGE MODE) ";
// //where += " AND MATCH(remark) AGAINST('" + remark_fulltext.Replace(",", " ") + "' IN NATURAL LANGUAGE MODE) ";
//}
if (!string.IsNullOrEmpty(remark_fulltext))
{
where += " AND MATCH(remark) AGAINST('" + remark_fulltext + "' IN BOOLEAN MODE)";
}
sql += where;
int count = -1;
if (is_not_count != "true")
{
count = mySql.ExecuteFirstInt(sql);
if (!mySql.Message.IsNullOrEmpty())
{
mySql.Close();
return "{\"code\":500,\"msg\":\"" + mySql.Message + "\"}";
}
}
sql = "SELECT * " +
" FROM wxxd.user_payment_record up " +
" WHERE 1=1";
sql += where;
sql += " ORDER BY up.create_time desc ";
sql += " limit " + Math.Max(page - 1, 0) * page_size + "," + page_size;
var dt = mySql.ExecuteDataTable(sql);
mySql.Close();
if (dt != null)
{
List<user_payment_record_info> userPaymentList = new List<user_payment_record_info>();
foreach (DataRow row in dt.Rows)
{
user_payment_record_info userPayment = new user_payment_record_info
{
id = Convert.ToInt32(row["id"]),
user_name = row["user_name"].ParseToString(),
after_sale_id = row["after_sale_id"].ParseToLong(),
amount = row["amount"].ParseToDecimal(),
counterparty_account_name = row["counterparty_account_name"].ParseToString(),
create_by = row["create_by"].ParseToString(),
balance = row["balance"].ParseToDecimal(),
create_time = row["create_time"].ParseToString().ParseToDateTime(),
is_deleted = row["is_deleted"].ParseToInt(),
order_id = row["order_id"].ParseToString(),
platform_code = row["platform_code"].ParseToString(),
remark = row["remark"].ParseToString(),
type = row["type"].ParseToInt(),
update_by = row["update_by"].ParseToString(),
update_time = row["update_time"].ParseToString().ParseToDateTime(),
};
userPaymentList.Add(userPayment);
}
var data = JsonUtils.SerializeObjectToString(userPaymentList);
var seconds = (DateTime.Now - timeCalc).TotalSeconds.ToString("0.000");
return "{\"code\":200,\"msg\":\"success\",\"data\":" + data + ",\"count\":\"" + count + "\",\"seconds\":\"" + seconds + "\"}";
}
}
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 = "Conn";
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 = "ConnKJD";
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 = "ConnKJD";
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 = "ConnKJD";
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 = "ConnKJD";
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\":\"输入为空\"}";
}
}
}