diff --git a/KJD_WebService.sln b/KJD_WebService.sln index 56d335f..84af2e3 100644 --- a/KJD_WebService.sln +++ b/KJD_WebService.sln @@ -1,10 +1,14 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 17 -VisualStudioVersion = 17.14.36221.1 d17.14 +# Visual Studio Version 18 +VisualStudioVersion = 18.9.12105.275 stable MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "KJD_WebService", "KJD_WebService\KJD_WebService.csproj", "{A6C03FE1-142A-4C97-99A9-67FD915836B6}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".test", ".test", "{AA240C1D-D687-4BC5-A195-4FA708BC7568}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebServiceTest", "test\WebServiceTest\WebServiceTest.csproj", "{348EB476-1813-419E-910F-0D27E58B3D19}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -15,10 +19,17 @@ Global {A6C03FE1-142A-4C97-99A9-67FD915836B6}.Debug|Any CPU.Build.0 = Debug|Any CPU {A6C03FE1-142A-4C97-99A9-67FD915836B6}.Release|Any CPU.ActiveCfg = Release|Any CPU {A6C03FE1-142A-4C97-99A9-67FD915836B6}.Release|Any CPU.Build.0 = Release|Any CPU + {348EB476-1813-419E-910F-0D27E58B3D19}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {348EB476-1813-419E-910F-0D27E58B3D19}.Debug|Any CPU.Build.0 = Debug|Any CPU + {348EB476-1813-419E-910F-0D27E58B3D19}.Release|Any CPU.ActiveCfg = Release|Any CPU + {348EB476-1813-419E-910F-0D27E58B3D19}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {348EB476-1813-419E-910F-0D27E58B3D19} = {AA240C1D-D687-4BC5-A195-4FA708BC7568} + EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {373F414C-6CDF-49C0-B074-A7D07D7B82B7} EndGlobalSection diff --git a/KJD_WebService/BLL/ImageService.cs b/KJD_WebService/BLL/ImageService.cs new file mode 100644 index 0000000..a764a17 --- /dev/null +++ b/KJD_WebService/BLL/ImageService.cs @@ -0,0 +1,131 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Threading.Tasks; +using System.Web; + +namespace KJD_Web.BLL +{ + public class ImageService + { + + + + /// + /// 接收Base64图片并保存 + /// + public static string SaveBase64Image(string base64String, string fileName = "", int maxsize = 5 * 1024 * 1024) + { + string savePath = string.Empty; + // 1. 验证请求 + if (string.IsNullOrWhiteSpace(base64String)) + return savePath; + + try + { + // 2. 处理Base64字符串(去除可能的前缀) + // 如果包含 data:image/xxx;base64, 前缀则去掉 + if (base64String.Contains(",")) + { + base64String = base64String.Substring(base64String.IndexOf(",") + 1); + } + + // 3. 转换为字节数组 + byte[] imageBytes = Convert.FromBase64String(base64String); + + // 4. 验证图片格式(可选) + if (!IsValidImage(imageBytes)) + return savePath; + + // 5. 检查大小(限制5MB) + if (imageBytes.Length > maxsize) + return savePath; + + // 6. 生成文件名并保存 + string extension = GetImageExtension(imageBytes); + if (string.IsNullOrEmpty(fileName)) + { + fileName = $"{DateTime.Now:yyyyMMdd_HHmmss}_{Guid.NewGuid():N}"; + } + fileName += extension; + string RelativePath = Path.Combine("upload"); + string uploadFolder = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, RelativePath); + + if (!Directory.Exists(uploadFolder)) + Directory.CreateDirectory(uploadFolder); + + string filePath = Path.Combine(uploadFolder, fileName); + File.WriteAllBytes(filePath, imageBytes); + savePath = "/" + Path.Combine(RelativePath, fileName).Replace("\\", "/"); + // 7. 返回 + return savePath; + } + catch (FormatException) + { + return savePath; + } + catch (Exception ex) + { + return savePath; + } + } + public static bool IsValidImage(string base64String) + { + if (string.IsNullOrEmpty(base64String)) return false; + byte[] imageBytes = Convert.FromBase64String(base64String); + return IsValidImage(imageBytes); + } + /// + /// 验证图片格式(检查文件头魔数) + /// + private static bool IsValidImage(byte[] bytes) + { + if (bytes.Length < 8) return false; + + // JPEG: FF D8 FF + if (bytes[0] == 0xFF && bytes[1] == 0xD8 && bytes[2] == 0xFF) + return true; + + // PNG: 89 50 4E 47 + if (bytes[0] == 0x89 && bytes[1] == 0x50 && bytes[2] == 0x4E && bytes[3] == 0x47) + return true; + + // GIF: 47 49 46 38 + if (bytes[0] == 0x47 && bytes[1] == 0x49 && bytes[2] == 0x46 && bytes[3] == 0x38) + return true; + + // BMP: 42 4D + if (bytes[0] == 0x42 && bytes[1] == 0x4D) + return true; + + // WebP: 52 49 46 46 + if (bytes[0] == 0x52 && bytes[1] == 0x49 && bytes[2] == 0x46 && bytes[3] == 0x46) + return true; + + return false; + } + + /// + /// 根据文件头获取扩展名 + /// + private static string GetImageExtension(byte[] bytes) + { + if (bytes.Length < 4) return ".jpg"; + + if (bytes[0] == 0xFF && bytes[1] == 0xD8 && bytes[2] == 0xFF) + return ".jpg"; + if (bytes[0] == 0x89 && bytes[1] == 0x50 && bytes[2] == 0x4E && bytes[3] == 0x47) + return ".png"; + if (bytes[0] == 0x47 && bytes[1] == 0x49 && bytes[2] == 0x46 && bytes[3] == 0x38) + return ".gif"; + if (bytes[0] == 0x42 && bytes[1] == 0x4D) + return ".bmp"; + if (bytes[0] == 0x52 && bytes[1] == 0x49 && bytes[2] == 0x46 && bytes[3] == 0x46) + return ".webp"; + + return ".jpg"; // 默认 + } + } + +} \ No newline at end of file diff --git a/KJD_WebService/BLL/WXXD/Dtos/OemWithdrawalDto.cs b/KJD_WebService/BLL/WXXD/Dtos/OemWithdrawalDto.cs new file mode 100644 index 0000000..9570fa9 --- /dev/null +++ b/KJD_WebService/BLL/WXXD/Dtos/OemWithdrawalDto.cs @@ -0,0 +1,123 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; + +namespace KJD_Web.BLL.WXXD.Dtos +{ + /// + /// 提现状态:0待审核 1审核通过 2审核拒绝 3打款中 4已打款 5打款失败 6已取消 + /// + public enum OemWithdrawalStatus + { + Pending = 0, //待审核 + Approved = 1, //审核通过 + Rejected = 2, //审核拒绝 + Paying = 3, //打款中 + Paid = 4, //已打款 + PayFailed = 5, //打款失败 + Cancelled = 6, //已取消 + } + + /// + /// OEM 提现记录 DTO + /// + public class OemWithdrawalDto + { + /// 提现单号(业务唯一号) + public string withdrawal_no { get; set; } + /// 关联oem_id + public string oem_id { get; set; } + /// 贴牌名称 + public string oem_name { get; set; } + /// 发起提现的用户/商户ID + public string apply_user_name { get; set; } + + /// 申请提现金额(分) + public long amount { get; set; } + /// 手续费(分) + public long fee { get; set; } + /// 实际到账金额(分) = amount - fee + public long actual_amount { get; set; } + /// 提现前余额快照(分) + public long balance_before { get; set; } + /// 提现后余额快照(分) + public long balance_after { get; set; } + + /// 提现方式:1银行卡 2支付宝 3微信 4其他 + public int withdrawal_type { get; set; } + /// 提现方式名称 + public string withdrawal_type_string { get; set; } + + /// 收款人姓名 + public string account_name { get; set; } + /// 收款账号(卡号/账号) + public string account_no { get; set; } + /// 开户行 + public string bank_name { get; set; } + /// 开户支行 + public string bank_branch { get; set; } + + /// 状态:0待审核 1审核通过 2审核拒绝 3打款中 4已打款 5打款失败 6已取消 + public int status { get; set; } + /// 状态名称 + public string status_string { get; set; } + + /// 审核人ID + public string audit_by { get; set; } + /// 审核时间 + public DateTime? audit_time { get; set; } + /// 审核备注/拒绝原因 + public string audit_remark { get; set; } + + /// 打款成功时间 + public DateTime? pay_time { get; set; } + /// 打款渠道/支付流水来源 + public string pay_channel { get; set; } + /// 第三方打款流水号 + public string pay_trade_no { get; set; } + /// 打款失败原因 + public string fail_reason { get; set; } + + /// 备注 + public string remark { get; set; } + /// 发起提现时的客户端IP + public string client_ip { get; set; } + + /// 创建时间 + public DateTime created_at { get; set; } + /// 更新时间 + public DateTime updated_at { get; set; } + } + + /// + /// OEM 提现记录分页结果 + /// + public class OemWithdrawalPageResultDto + { + public List list { get; set; } + public int count { get; set; } + /// + /// 贴牌账户余额信息(可提现/冻结/累计返利/累计提现) + /// + public List balances { get; set; } + } + + /// + /// OEM 贴牌账户余额信息 + /// + public class OemWithdrawalBalanceDto + { + public long oem_id { get; set; } + public string oem_code { get; set; } + public string oem_name { get; set; } + /// 当前可提现(分) + public long available_balance { get; set; } + /// 冻结金额(分) + public long frozen_balance { get; set; } + /// 历史累计返利(分) + public long total_rebate_amount { get; set; } + /// 历史累计提现(分) + public long total_withdraw_amount { get; set; } + } +} diff --git a/KJD_WebService/BLL/WXXD/Requests/OemWithdrawalAuditRequest.cs b/KJD_WebService/BLL/WXXD/Requests/OemWithdrawalAuditRequest.cs new file mode 100644 index 0000000..a89d64e --- /dev/null +++ b/KJD_WebService/BLL/WXXD/Requests/OemWithdrawalAuditRequest.cs @@ -0,0 +1,32 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; + +namespace KJD_Web.BLL.WXXD.Requests +{ + /// + /// OEM 提现审核请求 + /// + public class OemWithdrawalAuditRequest : SignRequestBase + { + /// + /// 提现单号 + /// + public string withdrawal_no { get; set; } + + /// + /// 审核结果:1审核通过 2审核拒绝 + /// + public int audit_result { get; set; } + + /// + /// 审核备注/拒绝原因 + /// + public string audit_remark { get; set; } + /// + /// 打款流水号 + /// + public string pay_trade_no { get; set; } + } +} diff --git a/KJD_WebService/BLL/WXXD/Requests/OemWithdrawalQueryRequest.cs b/KJD_WebService/BLL/WXXD/Requests/OemWithdrawalQueryRequest.cs new file mode 100644 index 0000000..ff78222 --- /dev/null +++ b/KJD_WebService/BLL/WXXD/Requests/OemWithdrawalQueryRequest.cs @@ -0,0 +1,49 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; + +namespace KJD_Web.BLL.WXXD.Requests +{ + /// + /// OEM 提现记录查询请求 + /// + public class OemWithdrawalQueryRequest: SignRequestBase + { + + /// + /// 贴牌编号(可选) + /// + public string oem_ids { get; set; } + + /// + /// 提现单号(可选) + /// + public string withdrawal_no { get; set; } + + /// + /// 状态(可选):0待审核 1审核通过 2审核拒绝 3打款中 4已打款 5打款失败 6已取消 + /// + public int? status { get; set; } + + /// + /// 创建开始时间 yyyy-MM-dd HH:mm:ss(可选) + /// + public string start_time { get; set; } + + /// + /// 创建结束时间 yyyy-MM-dd HH:mm:ss(可选) + /// + public string end_time { get; set; } + + /// + /// 页码,从1开始,默认1 + /// + public int page { get; set; } = 1; + + /// + /// 每页数量,默认20 + /// + public int page_size { get; set; } = 20; + } +} diff --git a/KJD_WebService/BLL/WXXD/Requests/OemWithdrawalRequest.cs b/KJD_WebService/BLL/WXXD/Requests/OemWithdrawalRequest.cs new file mode 100644 index 0000000..cd69832 --- /dev/null +++ b/KJD_WebService/BLL/WXXD/Requests/OemWithdrawalRequest.cs @@ -0,0 +1,66 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; + +namespace KJD_Web.BLL.WXXD.Requests +{ + /// + /// 提现方式:1银行卡 2支付宝 3微信 4其他 + /// + public enum WithdrawalType + { + Bank = 1, + Alipay = 2, + WeChat = 3, + Other = 4, + } + + /// + /// OEM 申请提现请求 + /// + public class OemWithdrawalRequest : SignRequestBase + { + + /// + /// 贴牌编号(可选) + /// + public string oem_id { get; set; } + + /// + /// 申请提现金额(分) + /// + public long amount { get; set; } + + /// + /// 提现方式:1银行卡 2支付宝 3微信 4其他 + /// + public WithdrawalType withdrawal_type { get; set; } = WithdrawalType.Bank; + + /// + /// 收款人姓名 + /// + public string account_name { get; set; } + + /// + /// 收款账号(卡号/账号) + /// + public string account_no { get; set; } + + /// + /// 开户行(银行卡时使用) + /// + public string bank_name { get; set; } + + /// + /// 开户支行 + /// + public string bank_branch { get; set; } + + /// + /// 备注 + /// + public string remark { get; set; } + + } +} diff --git a/KJD_WebService/BLL/WXXD/Requests/SignRequestBase.cs b/KJD_WebService/BLL/WXXD/Requests/SignRequestBase.cs new file mode 100644 index 0000000..acacb12 --- /dev/null +++ b/KJD_WebService/BLL/WXXD/Requests/SignRequestBase.cs @@ -0,0 +1,15 @@ +namespace KJD_Web.BLL.WXXD.Requests +{ + /// + /// 卡名请求 + /// + public class SignRequestBase + { + public string time { get; set; } + public string code { get; set; } + public string code_version { get; set; } + public string version { get; set; } + public string user_name { get; set; } + public string path { get; set; } + } +} diff --git a/KJD_WebService/BLL/WXXD/WXOemManage.cs b/KJD_WebService/BLL/WXXD/WXOemManage.cs index 619de20..884dc7e 100644 --- a/KJD_WebService/BLL/WXXD/WXOemManage.cs +++ b/KJD_WebService/BLL/WXXD/WXOemManage.cs @@ -1,7 +1,12 @@ -using KJD_Web.Model.WxModel; +using KJD_Web.BLL.WXXD.Dtos; +using KJD_Web.BLL.WXXD.Requests; +using KJD_Web.Model; +using KJD_Web.Model.WxModel; using KJD_Web.Utils; using NaiBa.Util.Extension; +using NaiBa.Util.Helper; using Newtonsoft.Json; +using Newtonsoft.Json.Serialization; using System; using System.Collections.Generic; using System.Data; @@ -10,130 +15,777 @@ using System.Web; namespace KJD_Web.BLL.WXXD { - public class WXOemManage - { - public string AddMdyOem(string inputData) - { - if (!string.IsNullOrEmpty(inputData)) - { - if (!WXUserManage.GetSign(inputData)) - return "{\"code\":999,\"msg\":\"校验失败\"}"; + public class WXOemManage + { + /// + /// 手续费 + /// + const long fee = 0; + public string AddMdyOem(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + if (!WXUserManage.GetSign(inputData)) + return "{\"code\":999,\"msg\":\"校验失败\"}"; - var oem_id = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "oem_id")?.Replace("'", "\\'")); - var oem_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "oem_name")?.Replace("'", "\\'")); - var oem_owner = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "oem_owner")?.Replace("'", "\\'")); - if (oem_id.IsNullOrEmpty() || oem_name.IsNullOrEmpty()) - return "{\"code\":500,\"msg\":\"oem信息不能为空\"}"; + var oem_id = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "oem_id")?.Replace("'", "\\'")); + var oem_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "oem_name")?.Replace("'", "\\'")); + var oem_owner = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "oem_owner")?.Replace("'", "\\'")); + if (oem_id.IsNullOrEmpty() || oem_name.IsNullOrEmpty()) + return "{\"code\":500,\"msg\":\"oem信息不能为空\"}"; - string conn = System.Configuration.ConfigurationManager.ConnectionStrings["ConnKJD"].ConnectionString; - MysqlUtils mySql = new MysqlUtils(conn); - string sql = "INSERT INTO wxxd.oem (oem_id,oem_name,oem_owner) VALUES('" + oem_id + "','" + oem_name + "','" + oem_owner + "')" + - "ON DUPLICATE KEY UPDATE oem_name=VALUES(oem_name),oem_owner=VALUES(oem_owner);"; + string conn = System.Configuration.ConfigurationManager.ConnectionStrings["ConnKJD"].ConnectionString; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = "INSERT INTO wxxd.oem (oem_id,oem_name,oem_owner) VALUES('" + oem_id + "','" + oem_name + "','" + oem_owner + "')" + + "ON DUPLICATE KEY UPDATE oem_name=VALUES(oem_name),oem_owner=VALUES(oem_owner);"; - var rst = mySql.ExecuteAffectedRows(sql); - mySql.Close(); + var rst = mySql.ExecuteAffectedRows(sql); + mySql.Close(); - if (!string.IsNullOrEmpty(mySql.Message)) - { - return "{\"code\":500,\"msg\":\"" + mySql.Message + "\"}"; - } - return "{\"code\":200,\"msg\":\"success\",\"affected_rows\":" + rst + "}"; - } - return "{\"code\":19999,\"msg\":\"输入为空\"}"; - } + if (!string.IsNullOrEmpty(mySql.Message)) + { + return "{\"code\":500,\"msg\":\"" + mySql.Message + "\"}"; + } + return "{\"code\":200,\"msg\":\"success\",\"affected_rows\":" + rst + "}"; + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } - public string DelOem(string inputData) - { - if (!string.IsNullOrEmpty(inputData)) - { - if (!WXUserManage.GetSign(inputData)) - return "{\"code\":999,\"msg\":\"校验失败\"}"; + public string DelOem(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + if (!WXUserManage.GetSign(inputData)) + return "{\"code\":999,\"msg\":\"校验失败\"}"; - var id = (RegexUtils.GetStringQuery(ref inputData, "db_id")?.Replace("'", "\\'")); - var oem_id = (RegexUtils.GetStringQuery(ref inputData, "oem_id")?.Replace("'", "\\'")); - if (oem_id.IsNullOrEmpty() && id.IsNullOrEmpty()) - return "{\"code\":500,\"msg\":\"oem信息不能为空\"}"; + var id = (RegexUtils.GetStringQuery(ref inputData, "db_id")?.Replace("'", "\\'")); + var oem_id = (RegexUtils.GetStringQuery(ref inputData, "oem_id")?.Replace("'", "\\'")); + if (oem_id.IsNullOrEmpty() && id.IsNullOrEmpty()) + return "{\"code\":500,\"msg\":\"oem信息不能为空\"}"; - string conn = System.Configuration.ConfigurationManager.ConnectionStrings["ConnKJD"].ConnectionString; - MysqlUtils mySql = new MysqlUtils(conn); - string sql = "UPDATE wxxd.oem SET is_del=1 WHERE id=" + id + " or oem_id='" + oem_id + "'"; + string conn = System.Configuration.ConfigurationManager.ConnectionStrings["ConnKJD"].ConnectionString; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = "UPDATE wxxd.oem SET is_del=1 WHERE id=" + id + " or oem_id='" + oem_id + "'"; - var rst = mySql.ExecuteAffectedRows(sql); - mySql.Close(); + var rst = mySql.ExecuteAffectedRows(sql); + mySql.Close(); - if (!string.IsNullOrEmpty(mySql.Message)) - { - return "{\"code\":500,\"msg\":\"" + mySql.Message + "\"}"; - } - return "{\"code\":200,\"msg\":\"success\"}"; - } - return "{\"code\":19999,\"msg\":\"输入为空\"}"; - } + if (!string.IsNullOrEmpty(mySql.Message)) + { + return "{\"code\":500,\"msg\":\"" + mySql.Message + "\"}"; + } + return "{\"code\":200,\"msg\":\"success\"}"; + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } - public string GetOem(string inputData) - { - if (!string.IsNullOrEmpty(inputData)) - { - if (!WXUserManage.GetSign(inputData)) - return "{\"code\":999,\"msg\":\"校验失败\"}"; + public string GetOem(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + if (!WXUserManage.GetSign(inputData)) + return "{\"code\":999,\"msg\":\"校验失败\"}"; - var timeCalc = DateTime.Now; - var oem_id = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "oem_id")?.Replace("'", "\\'")); - var oem_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "oem_name")?.Replace("'", "\\'")); - var oem_owner = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "oem_owner")?.Replace("'", "\\'")); + var timeCalc = DateTime.Now; + var oem_id = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "oem_id")?.Replace("'", "\\'")); + var oem_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "oem_name")?.Replace("'", "\\'")); + var oem_owner = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "oem_owner")?.Replace("'", "\\'")); - string conn = System.Configuration.ConfigurationManager.ConnectionStrings["ConnKJD"].ConnectionString; - MysqlUtils mySql = new MysqlUtils(conn); - string sql = "SELECT * FROM wxxd.oem WHERE is_del=0"; + string conn = System.Configuration.ConfigurationManager.ConnectionStrings["ConnKJD"].ConnectionString; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = "SELECT * FROM wxxd.oem WHERE is_del=0"; - string where = ""; - if (!string.IsNullOrEmpty(oem_id)) - where += " and oem_id in ('" + oem_id.Replace(",", "','") + "')"; - if (!string.IsNullOrEmpty(oem_name)) - where += " and oem_name in ('" + oem_name.Replace(",", "','") + "')"; - if (!string.IsNullOrEmpty(oem_owner)) - where += " and oem_owner in ('" + oem_owner.Replace(",", "','") + "')"; + string where = ""; + if (!string.IsNullOrEmpty(oem_id)) + where += " and oem_id in ('" + oem_id.Replace(",", "','") + "')"; + if (!string.IsNullOrEmpty(oem_name)) + where += " and oem_name in ('" + oem_name.Replace(",", "','") + "')"; + if (!string.IsNullOrEmpty(oem_owner)) + where += " and oem_owner in ('" + oem_owner.Replace(",", "','") + "')"; - sql += where; - sql += " ORDER BY add_time DESC;"; + sql += where; + sql += " ORDER BY add_time DESC;"; - var dt = mySql.ExecuteDataTable(sql); - mySql.Close(); + var dt = mySql.ExecuteDataTable(sql); + mySql.Close(); - if (!string.IsNullOrEmpty(mySql.Message) || dt == null) - { - return "{\"code\":500,\"msg\":\"" + mySql.Message + "\"}"; - } + if (!string.IsNullOrEmpty(mySql.Message) || dt == null) + { + return "{\"code\":500,\"msg\":\"" + mySql.Message + "\"}"; + } - try - { - List productLst = new List(); - foreach (DataRow row in dt.Rows) - { - oem prod = new oem - { - id = row["id"].ParseToInt(), - oem_icon = null, - oem_id = row["oem_id"].ParseToString(), - add_time = row["add_time"].ParseToString().ParseToDateTime(), - mdy_time = row["mdy_time"].ParseToString().ParseToDateTime(), - oem_img = null, - oem_name = row["oem_name"].ParseToString(), - oem_owner = row["oem_owner"].ParseToString(), - }; - productLst.Add(prod); - } - JsonSerializerSettings jsonSetting = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }; - var data = JsonUtils.SerializeObjectToString(productLst, jsonSetting); - var seconds = (DateTime.Now - timeCalc).TotalSeconds.ToString("0.000"); - return "{\"code\":200,\"msg\":\"success\",\"data\":" + data + ",\"count\":" + -1 + ",\"seconds\":" + seconds + "}"; - } - catch (Exception ex) - { - return "{\"code\":500,\"msg\":\"" + ex.Message + "\",\"data\":[],\"count\":" + 0 + "}"; - } - } - return "{\"code\":19999,\"msg\":\"输入为空\"}"; - } - } -} \ No newline at end of file + try + { + List productLst = new List(); + foreach (DataRow row in dt.Rows) + { + oem prod = new oem + { + id = row["id"].ParseToInt(), + oem_icon = null, + oem_id = row["oem_id"].ParseToString(), + add_time = row["add_time"].ParseToString().ParseToDateTime(), + mdy_time = row["mdy_time"].ParseToString().ParseToDateTime(), + oem_img = null, + oem_name = row["oem_name"].ParseToString(), + oem_owner = row["oem_owner"].ParseToString(), + available_balance = row.Table.Columns.Contains("available_balance") ? row["available_balance"].ParseToLong() : 0, + frozen_balance = row.Table.Columns.Contains("frozen_balance") ? row["frozen_balance"].ParseToLong() : 0, + total_rebate_amount = row.Table.Columns.Contains("total_rebate_amount") ? row["total_rebate_amount"].ParseToLong() : 0, + total_withdraw_amount = row.Table.Columns.Contains("total_withdraw_amount") ? row["total_withdraw_amount"].ParseToLong() : 0, + }; + productLst.Add(prod); + } + JsonSerializerSettings jsonSetting = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }; + var data = JsonUtils.SerializeObjectToString(productLst, jsonSetting); + var seconds = (DateTime.Now - timeCalc).TotalSeconds.ToString("0.000"); + return "{\"code\":200,\"msg\":\"success\",\"data\":" + data + ",\"count\":" + -1 + ",\"seconds\":" + seconds + "}"; + } + catch (Exception ex) + { + return "{\"code\":500,\"msg\":\"" + ex.Message + "\",\"data\":[],\"count\":" + 0 + "}"; + } + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + + /// + /// OEM 提现记录查询(分页) + /// + /// 查询请求 + /// + public string OemWithdrawals(OemWithdrawalQueryRequest request) + { + Result ret = Result.ArgumentNull(); + + try + { + if (request == null || request.user_name.IsNullOrEmpty()) + throw new Exception("参数错误:缺少用户名"); + + List oemIdLst = new List(); + var user = new WXUserManage().GetUserByUserName(request.user_name); + if (user.sa_level != 1)//非管理员 判断 是否Oem 管理员 + { + var oems = GetOems(new List { request.user_name }); + if (oems == null || oems.Any() == false) + { + throw new Exception("错误的账号"); + } + oemIdLst.AddRange(oems.Select(a => a.oem_id).ToArray()); + } + else + { + if (!string.IsNullOrWhiteSpace(request.oem_ids)) + { + oemIdLst.AddRange(request.oem_ids.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries)); + + } + } + + + + int page = request.page <= 0 ? 1 : request.page; + int page_size = request.page_size <= 0 ? 20 : request.page_size; + + string conn = System.Configuration.ConfigurationManager.ConnectionStrings["ConnKJD"].ConnectionString; + MysqlUtils mySql = new MysqlUtils(conn); + + string where = " WHERE w.is_deleted=0"; + if (oemIdLst.Any()) + where += " AND w.oem_id IN ('" + string.Join("','", oemIdLst) + "')"; + if (!request.withdrawal_no.IsNullOrEmpty()) + where += " AND w.withdrawal_no='" + MysqlUtils.ReplaceSqlSpecial(request.withdrawal_no) + "'"; + if (request.status.HasValue) + where += " AND w.status=" + request.status.Value; + if (!request.start_time.IsNullOrEmpty()) + where += " AND w.created_at >= '" + MysqlUtils.ReplaceSqlSpecial(request.start_time) + "'"; + if (!request.end_time.IsNullOrEmpty()) + where += " AND w.created_at <= '" + MysqlUtils.ReplaceSqlSpecial(request.end_time) + "'"; + + string countSql = "SELECT COUNT(*) FROM wxxd.oem_withdrawal w" + where; + int count = mySql.ExecuteFirstInt(countSql); + if (!string.IsNullOrEmpty(mySql.Message)) + throw new Exception(mySql.Message); + + string sql = "SELECT w.*, o.oem_name FROM wxxd.oem_withdrawal w " + + "LEFT JOIN wxxd.oem o ON w.oem_id = o.oem_id" + where + + " ORDER BY w.id DESC LIMIT " + Math.Max(page - 1, 0) * page_size + "," + page_size + ";"; + + var dt = mySql.ExecuteDataTable(sql); + mySql.Close(); + if (!string.IsNullOrEmpty(mySql.Message) || dt == null) + throw new Exception(mySql.Message); + + List list = new List(); + foreach (DataRow row in dt.Rows) + { + list.Add(BuildOemWithdrawalDto(row)); + } + + //// 贴牌账户余额信息 + //List balanceLst = oems.Where(x => oemIdLst.Contains(x.id)).Select(x => new OemWithdrawalBalanceDto + //{ + // oem_id = x.id, + // oem_code = x.oem_id, + // oem_name = x.oem_name, + // available_balance = x.available_balance, + // frozen_balance = x.frozen_balance, + // total_rebate_amount = x.total_rebate_amount, + // total_withdraw_amount = x.total_withdraw_amount, + //}).ToList(); + ret = new PageResult(); + ret.Code = 200; + ret.Msg = "success"; + ret.Data = list; + (ret as PageResult).Total = count; + } + catch (Exception ex) + { + ret = Result.Failure(ex.Message); + } + return JsonUtils.SerializeObjectToString(ret, new JsonSerializerSettings + { + ContractResolver = new CamelCasePropertyNamesContractResolver(), + }); + } + /// + /// 计算Oem 流水 + /// + /// + public string SettleOemFlows(SignRequestBase request) + { + Result ret = Result.ArgumentNull(); + + try + { + if (request == null || request.user_name.IsNullOrEmpty()) + throw new Exception("参数错误:缺少用户名"); + + + var oems = GetOems(new List { request.user_name }); + if (oems == null || oems.Any() == false) + { + throw new Exception("错误的账号"); + } + oem oemInfo = oems.First(); + string conn = System.Configuration.ConfigurationManager.ConnectionStrings["ConnKJD"].ConnectionString; + MysqlUtils mySql = new MysqlUtils(conn, true); + this.SettleOemFlows(mySql, oemInfo.oem_id); + + oems = GetOems(new List { request.user_name }); + if (oems == null || oems.Any() == false) + { + throw new Exception("错误的账号"); + } + oemInfo = oems.First(); + ret.Code = 200; + ret.Msg = "success"; + ret.Data = new + { + oemInfo.available_balance, + oemInfo.total_rebate_amount, + oemInfo.total_withdraw_amount, + }; + + } + catch (Exception ex) + { + ret = Result.Failure(ex.Message); + } + return JsonUtils.SerializeObjectToString(ret, new JsonSerializerSettings + { + ContractResolver = new CamelCasePropertyNamesContractResolver(), + }); + } + /// + /// OEM 申请提现 + /// 申请时先把该用户未结算(settlement=0)的流水 oem_amount 汇总结算到 oem 账户 + /// (available_balance 可提现、total_rebate_amount 累计返利),并把流水标记 settlement=1。 + /// 每次只允许一笔进行中的提现(状态0待审核/1审核通过/3打款中)。 + /// + /// 申请提现请求 + /// + public string ApplyOemWithdrawal(OemWithdrawalRequest request) + { + Result ret = Result.ArgumentNull(); + string client_ip = ""; + try + { + if (request == null || request.user_name.IsNullOrEmpty()) + throw new Exception("参数错误:缺少用户名"); + if (request.amount <= 0) + throw new Exception("提现金额必须大于0"); + if (fee < 0) + throw new Exception("手续费不能为负数"); + if (request.amount <= fee) + throw new Exception("提现金额必须大于手续费"); + if (request.withdrawal_type != WithdrawalType.Bank && + request.withdrawal_type != WithdrawalType.Alipay && + request.withdrawal_type != WithdrawalType.WeChat && + request.withdrawal_type != WithdrawalType.Other) + throw new Exception("提现方式不合法"); + if (request.account_no.IsNullOrEmpty()) + throw new Exception("收款账号不能为空"); + + var oems = GetOems(new List { request.user_name }); + if (oems == null || oems.Any() == false) + { + throw new Exception("错误的账号"); + } + + oem oemInfo = null; + if (!request.oem_id.IsNullOrEmpty()) + { + oemInfo = oems.FirstOrDefault(x => x.oem_id == request.oem_id); + if (oemInfo == null) + throw new Exception("未找到该贴牌信息"); + } + else + { + oemInfo = oems.First(); + } + + //// 收款人姓名默认取贴牌名称 + //if (request.account_name.IsNullOrEmpty()) + request.account_name = oemInfo.oem_name; + + + + string conn = System.Configuration.ConfigurationManager.ConnectionStrings["ConnKJD"].ConnectionString; + MysqlUtils mySql = new MysqlUtils(conn, true); + try + { + // 每次只能处理一笔提现申请 + string sql = "SELECT COUNT(*) FROM wxxd.oem_withdrawal WHERE oem_id='" + oemInfo.oem_id + + "' AND status IN (" + (int)OemWithdrawalStatus.Pending + "," + (int)OemWithdrawalStatus.Approved + "," + (int)OemWithdrawalStatus.Paying + ")" + + " AND is_deleted=0"; + int processingCount = mySql.ExecuteFirstInt(sql); + if (!string.IsNullOrEmpty(mySql.Message)) + throw new Exception(mySql.Message); + if (processingCount > 0) + throw new Exception("存在进行中的提现申请,请等待审核完成后再次申请"); + + ///申请编号 + string withdrawal_no = "TX" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + RandomUtils.GetNumber(4); + //保存图片 + if (ImageService.IsValidImage(request.account_no)) + { + string savePath = ImageService.SaveBase64Image(request.account_no, fileName: withdrawal_no); + request.account_no = savePath; + } + + + // 结算未结算流水到oem账户(独立方法,写oem金额与改流水状态在同一事务内) + long settled_fen = SettleOemFlows(mySql, oemInfo.oem_id); + + // 重新读取结算后的账户余额(分) + sql = "SELECT available_balance FROM wxxd.oem WHERE id=" + oemInfo.id; + var oemRow = mySql.ExecuteDataTableRow(sql); + if (!string.IsNullOrEmpty(mySql.Message) || oemRow == null) + throw new Exception("获取账户余额失败"); + + long available_fen = oemRow["available_balance"].ParseToLong(); + if (available_fen < request.amount) + throw new Exception("可提现余额不足"); + + long amount_fen = request.amount; + long fee_fen = fee; + long actual_fen = amount_fen - fee_fen; + long balance_after_fen = available_fen - amount_fen; + + // 冻结:扣减可提现,增加冻结金额(乐观锁) + sql = "UPDATE wxxd.oem SET available_balance=available_balance-" + amount_fen + + ", frozen_balance=frozen_balance+" + amount_fen + + " WHERE id=" + oemInfo.id + " AND available_balance>=" + amount_fen; + var freezeRst = mySql.ExecuteAffectedRows(sql); + if (!string.IsNullOrEmpty(mySql.Message) || freezeRst <= 0) + throw new Exception("冻结余额失败,账户余额已发生变化,请刷新后重试"); + + string now = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); + + sql = "INSERT INTO wxxd.oem_withdrawal " + + "(withdrawal_no,oem_id,apply_user_name,amount,fee,actual_amount,balance_before,balance_after," + + "withdrawal_type,account_name,account_no,bank_name,bank_branch," + + "status,audit_by,audit_time,audit_remark,remark,client_ip,version,is_deleted,created_at,updated_at) VALUES (" + + "'" + withdrawal_no + "','" + oemInfo.oem_id + "','" + MysqlUtils.ReplaceSqlSpecial(request.user_name) + "'," + + amount_fen + "," + fee_fen + "," + actual_fen + "," + available_fen + "," + balance_after_fen + "," + + (int)request.withdrawal_type + ",'" + MysqlUtils.ReplaceSqlSpecial(request.account_name) + "','" + MysqlUtils.ReplaceSqlSpecial(request.account_no) + "'," + + "'" + MysqlUtils.ReplaceSqlSpecial(request.bank_name) + "','" + MysqlUtils.ReplaceSqlSpecial(request.bank_branch) + "'," + + (int)OemWithdrawalStatus.Pending + ",'',NULL,NULL," + + "'" + MysqlUtils.ReplaceSqlSpecial(request.remark) + "','" + MysqlUtils.ReplaceSqlSpecial(client_ip) + "',0,0,'" + now + "','" + now + "');"; + + long insertId = mySql.ExecuteInsertId(sql); + if (!string.IsNullOrEmpty(mySql.Message) || insertId <= 0) + throw new Exception("创建提现记录失败"); + + mySql.Commit(); + + ret.Code = 200; + ret.Msg = "success"; + ret.Data = new { withdrawal_no = withdrawal_no, id = insertId, balance_after = balance_after_fen, actual_amount = actual_fen }; + } + catch (Exception) + { + mySql.RollBack(); + throw; + } + finally + { + mySql.Close(); + } + } + catch (Exception ex) + { + ret = Result.Failure(ex.Message); + } + return JsonUtils.SerializeObjectToString(ret, new JsonSerializerSettings + { + ContractResolver = new CamelCasePropertyNamesContractResolver(), + }); + } + + /// + /// OEM 提现审核 + /// 审核通过:冻结金额转历史累计提现;审核拒绝:冻结金额退回可提现余额。 + /// + /// 审核请求 + /// + public string AuditOemWithdrawal(OemWithdrawalAuditRequest request) + { + Result ret = Result.ArgumentNull(); + + try + { + if (string.IsNullOrEmpty(request.withdrawal_no)) + throw new Exception("参数错误:缺少提现单号"); + if (request.audit_result != (int)OemWithdrawalStatus.Approved && request.audit_result != (int)OemWithdrawalStatus.Rejected) + throw new Exception("审核结果不合法:1审核通过 2审核拒绝"); + if (request.user_name.IsNullOrEmpty()) + throw new Exception("审核人不能为空"); + var user = new WXUserManage().GetUserByUserName(request.user_name); + if (user.sa_level != 1) + { + throw new Exception("无权限审核"); + } + string audit_remark = HtmlUtils.UrlDecodeUtf8(request.audit_remark); + string conn = System.Configuration.ConfigurationManager.ConnectionStrings["ConnKJD"].ConnectionString; + MysqlUtils mySql = new MysqlUtils(conn, true); + try + { + string sql = "SELECT * FROM wxxd.oem_withdrawal WHERE withdrawal_no='" + request.withdrawal_no + "' AND is_deleted=0"; + var row = mySql.ExecuteDataTableRow(sql); + if (!string.IsNullOrEmpty(mySql.Message) || row == null) + throw new Exception("提现记录不存在"); + + int status = row["status"].ParseToInt(); + if (status != (int)OemWithdrawalStatus.Pending) + { + throw new Exception("当前状态不可审核"); + } + + //保存图片 + if (ImageService.IsValidImage(request.pay_trade_no)) + { + string savePath = ImageService.SaveBase64Image(request.pay_trade_no, fileName: "C" + request.withdrawal_no); + request.pay_trade_no = savePath; + } + + + string oem_id = row["oem_id"].ParseToString(); + long amount_fen = row["amount"].ParseToLong(); + string now = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); + + // 更新oem账户余额 + if (request.audit_result == (int)OemWithdrawalStatus.Approved) + { + // 审核通过:冻结金额减少,历史累计提现增加 + sql = "UPDATE wxxd.oem SET frozen_balance=frozen_balance-" + amount_fen + + ", total_withdraw_amount=total_withdraw_amount+" + amount_fen + + " WHERE oem_id='" + oem_id + "' AND frozen_balance>=" + amount_fen; + } + else + { + // 审核拒绝:冻结金额减少,退回可提现余额 + sql = "UPDATE wxxd.oem SET frozen_balance=frozen_balance-" + amount_fen + + ", available_balance=available_balance+" + amount_fen + + " WHERE oem_id='" + oem_id + "' AND frozen_balance>=" + amount_fen; + } + var oemRst = mySql.ExecuteAffectedRows(sql); + if (!string.IsNullOrEmpty(mySql.Message) || oemRst <= 0) + throw new Exception("更新账户余额失败"); + if (request.audit_result == 1) request.audit_result = (int)OemWithdrawalStatus.Paid; //已付款 + sql = "UPDATE wxxd.oem_withdrawal SET status=" + request.audit_result + + ",audit_by='" + MysqlUtils.ReplaceSqlSpecial(request.user_name) + + "',audit_time='" + now + + "',audit_remark='" + MysqlUtils.ReplaceSqlSpecial(audit_remark) + + "',updated_at='" + now + + "',pay_time='" + now + + "',pay_trade_no='" + request.pay_trade_no + + "' WHERE withdrawal_no='" + request.withdrawal_no + "' AND status=" + (int)OemWithdrawalStatus.Pending + ";"; + + var updateRst = mySql.ExecuteAffectedRows(sql); + if (!string.IsNullOrEmpty(mySql.Message) || updateRst <= 0) + throw new Exception("审核失败,请刷新后重试"); + + mySql.Commit(); + + ret.Code = 200; + ret.Msg = request.audit_result == (int)OemWithdrawalStatus.Approved ? "审核通过" : "审核拒绝"; + ret.Data = new { withdrawal_no = request.withdrawal_no, status = request.audit_result }; + } + catch (Exception) + { + mySql.RollBack(); + throw; + } + finally + { + mySql.Close(); + } + } + catch (Exception ex) + { + ret = Result.Failure(ex.Message); + } + return JsonUtils.SerializeObjectToString(ret, new JsonSerializerSettings + { + ContractResolver = new CamelCasePropertyNamesContractResolver(), + }); + } + + /// + /// 结算流水到oem账户(独立方法)。 + /// 根据 oem_id(贴牌编号) 找到该oem下所有账户(wxxd.user.oem_id 匹配), + /// 然后按流水id升序遍历 wxxd.user_payment_record 中未结算(settlement=0)流水,按公式计算: + /// type=20:amount - 2.2 + /// type=26:amount - 2.5 + /// type=16:oem_amount + /// type=31:oem_amount + /// type=23:- amount(同一个订单(order_id)只能减少一次) + /// 各项金额之和为总金额(元),写入 oem.available_balance(当前可提现); + /// 其中正数部分累计到 oem.total_rebate_amount(历史累计返利)。 + /// 写oem金额与更新流水settlement=1在同一个事务内执行(由调用方开启的事务)。 + /// + /// 事务连接(调用方已开启事务) + /// 贴牌编号(wxxd.oem.oem_id / wxxd.user.oem_id) + /// wxxd.oem.id 数字主键 + /// 本次结算总金额(分) + private long SettleOemFlows(MysqlUtils mySql, string oem_id) + { + if (oem_id.IsNullOrEmpty()) + return 0; + + // 1. 找到该oem下所有账户 + string sql = "SELECT user_name FROM wxxd.`user` WHERE oem_id='" + MysqlUtils.ReplaceSqlSpecial(oem_id) + "'"; + var userDt = mySql.ExecuteDataTable(sql); + if (!string.IsNullOrEmpty(mySql.Message) || userDt == null || userDt.Rows.Count == 0) + return 0; + + List userLst = userDt.Rows.Cast() + .Select(r => r["user_name"].ParseToString()) + .Where(x => !string.IsNullOrEmpty(x)) + .Distinct() + .ToList(); + if (userLst.Count == 0) + return 0; + + // 2. 该oem所有账户的未结算流水,按id升序 + sql = "SELECT * FROM wxxd.user_payment_record WHERE user_name IN ('" + string.Join("','", userLst) + "')" + + " AND type IN (20,23,26,16,31) AND settlement=0 AND is_deleted=0 ORDER BY id ASC"; + var flowDt = mySql.ExecuteDataTable(sql); + if (!string.IsNullOrEmpty(mySql.Message) || flowDt == null || flowDt.Rows.Count == 0) + return 0; + + decimal total_amount = 0m; // 总金额(元) + decimal rebate_amount = 0m; // 正数部分(累计返利) + HashSet deductedOrderSet = new HashSet(); // type=23 已扣减的订单 + List settleIdLst = new List(); // 参与结算的流水id + + foreach (DataRow row in flowDt.Rows) + { + int type = row["type"].ParseToInt(); + decimal amount = row["amount"].ParseToDecimal(); + decimal oem_amount = row["oem_amount"].ParseToDecimal(); + long flowId = row["id"].ParseToLong(); + + decimal itemAmount = 0m; + if (type == 20) + itemAmount = amount - 2.2m; + else if (type == 26) + itemAmount = amount - 2.5m; + else if (type == 16) + itemAmount = oem_amount; + else if (type == 31) + itemAmount = oem_amount; + else if (type == 23) + { + // 同一个订单只能减少一次 + string orderId = row["order_id"].ParseToString(); + if (orderId.IsNullOrEmpty() || deductedOrderSet.Contains(orderId)) + continue; + deductedOrderSet.Add(orderId); + itemAmount = -(amount - 2.2m); + } + else + { + continue; // 其他类型不计入 + } + + total_amount += itemAmount; + rebate_amount += itemAmount; + + settleIdLst.Add(flowId); + } + + if (settleIdLst.Count == 0) + return 0; + long total_fen = (long)Math.Round(total_amount * 100m); + long rebate_fen = (long)Math.Round(rebate_amount * 100m); + string now = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); + + // 3. 写oem金额 + 更新流水状态(同一事务) + sql = "UPDATE wxxd.oem SET available_balance=available_balance+" + total_fen + + ", total_rebate_amount=total_rebate_amount+" + rebate_fen + + " WHERE oem_id='" + oem_id + "'"; + var oemRst = mySql.ExecuteAffectedRows(sql); + if (!string.IsNullOrEmpty(mySql.Message) || oemRst <= 0) + throw new Exception("结算流水到账户失败"); + + sql = "UPDATE wxxd.user_payment_record SET settlement=1,settlement_time='" + now + "' WHERE id IN (" + string.Join(",", settleIdLst) + ")"; + var flowRst = mySql.ExecuteAffectedRows(sql); + if (!string.IsNullOrEmpty(mySql.Message) || flowRst <= 0) + throw new Exception("标记流水结算失败"); + + return total_fen; + } + + /// + /// 将数据行转换为提现记录DTO + /// + private OemWithdrawalDto BuildOemWithdrawalDto(DataRow row) + { + int withdrawal_type = row["withdrawal_type"].ParseToInt(); + int status = row["status"].ParseToInt(); + return new OemWithdrawalDto + { + withdrawal_no = row["withdrawal_no"].ParseToString(), + oem_id = row["oem_id"].ParseToString(), + oem_name = row.Table.Columns.Contains("oem_name") ? row["oem_name"].ParseToString() : "", + apply_user_name = row["apply_user_name"].ParseToString(), + amount = row["amount"].ParseToLong(), + fee = row["fee"].ParseToLong(), + actual_amount = row["actual_amount"].ParseToLong(), + balance_before = row["balance_before"].ParseToLong(), + balance_after = row["balance_after"].ParseToLong(), + withdrawal_type = withdrawal_type, + withdrawal_type_string = GetWithdrawalTypeString(withdrawal_type), + account_name = row["account_name"].ParseToString(), + account_no = row["account_no"].ParseToString(), + bank_name = row["bank_name"].ParseToString(), + bank_branch = row["bank_branch"].ParseToString(), + status = status, + status_string = GetWithdrawalStatusString(status), + audit_by = row["audit_by"].ParseToString(), + audit_time = row["audit_time"] == DBNull.Value ? (DateTime?)null : row["audit_time"].ParseToString().ParseToDateTime(), + audit_remark = row["audit_remark"].ParseToString(), + pay_time = row["pay_time"] == DBNull.Value ? (DateTime?)null : row["pay_time"].ParseToString().ParseToDateTime(), + pay_channel = row["pay_channel"].ParseToString(), + pay_trade_no = row["pay_trade_no"].ParseToString(), + fail_reason = row["fail_reason"].ParseToString(), + remark = row["remark"].ParseToString(), + client_ip = row["client_ip"].ParseToString(), + created_at = row["created_at"].ParseToString().ParseToDateTime(), + updated_at = row["updated_at"].ParseToString().ParseToDateTime(), + }; + } + + /// + /// 提现方式名称 + /// + private string GetWithdrawalTypeString(int withdrawal_type) + { + switch (withdrawal_type) + { + case (int)WithdrawalType.Bank: return "银行卡"; + case (int)WithdrawalType.Alipay: return "支付宝"; + case (int)WithdrawalType.WeChat: return "微信"; + case (int)WithdrawalType.Other: return "其他"; + default: return ""; + } + } + + /// + /// 提现状态名称 + /// + private string GetWithdrawalStatusString(int status) + { + switch (status) + { + case (int)OemWithdrawalStatus.Pending: return "待审核"; + case (int)OemWithdrawalStatus.Approved: return "审核通过"; + case (int)OemWithdrawalStatus.Rejected: return "审核拒绝"; + case (int)OemWithdrawalStatus.Paying: return "打款中"; + case (int)OemWithdrawalStatus.Paid: return "已打款"; + case (int)OemWithdrawalStatus.PayFailed: return "打款失败"; + case (int)OemWithdrawalStatus.Cancelled: return "已取消"; + default: return ""; + } + } + + private List GetOems(IEnumerable oem_owners) + { + List productLst = new List(); + string conn = System.Configuration.ConfigurationManager.ConnectionStrings["ConnKJD"].ConnectionString; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = "SELECT * FROM wxxd.oem WHERE is_del=0"; + + string where = ""; + if (oem_owners?.Any() ?? false) + where += $" and oem_owner in ('{string.Join("','", oem_owners)}')"; + + sql += where; + sql += " ORDER BY add_time DESC;"; + + var dt = mySql.ExecuteDataTable(sql); + mySql.Close(); + + if (!string.IsNullOrEmpty(mySql.Message) || dt == null) + { + return productLst; + } + + try + { + + foreach (DataRow row in dt.Rows) + { + oem prod = new oem + { + id = row["id"].ParseToInt(), + oem_icon = null, + oem_id = row["oem_id"].ParseToString(), + add_time = row["add_time"].ParseToString().ParseToDateTime(), + mdy_time = row["mdy_time"].ParseToString().ParseToDateTime(), + oem_img = null, + oem_name = row["oem_name"].ParseToString(), + oem_owner = row["oem_owner"].ParseToString(), + available_balance = row.Table.Columns.Contains("available_balance") ? row["available_balance"].ParseToLong() : 0, + frozen_balance = row.Table.Columns.Contains("frozen_balance") ? row["frozen_balance"].ParseToLong() : 0, + total_rebate_amount = row.Table.Columns.Contains("total_rebate_amount") ? row["total_rebate_amount"].ParseToLong() : 0, + total_withdraw_amount = row.Table.Columns.Contains("total_withdraw_amount") ? row["total_withdraw_amount"].ParseToLong() : 0, + }; + productLst.Add(prod); + } + + } + catch (Exception ex) + { + return null; + } + return productLst; + + } + } +} diff --git a/KJD_WebService/BLL/WXXD/WXUserManage.cs b/KJD_WebService/BLL/WXXD/WXUserManage.cs index 9377ab2..b85d78f 100644 --- a/KJD_WebService/BLL/WXXD/WXUserManage.cs +++ b/KJD_WebService/BLL/WXXD/WXUserManage.cs @@ -18,1717 +18,1805 @@ 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 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 = 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," + - "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\":\"输入为空\"}"; - } - - /// - /// 添加子账号 - /// - /// - /// - 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 userList = new List(); - 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 + "' and balance=0"; - - var rst = mySql.ExecuteAffectedRows(sql); - mySql.Close(); - if (rst > 0) - { - return "{\"code\":200,\"msg\":\"success\"}"; - } - if (rst == 0) - { - return "{\"code\":500,\"msg\":\"删除失败,请检查账户拍单余额是否还有剩余\"}"; - } - 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 = System.Configuration.ConfigurationManager.ConnectionStrings["ConnKJD"].ConnectionString; - 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 userList = new List(); - 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").ParseToDecimal(); - if (postage_per_order.ParseToDecimal() <= 2.2m) // 每单费用 - postage_per_order = 2.2m; - var refund_postage_per_order = RegexUtils.GetStringQuery(ref inputData, "refund_postage_per_order").ParseToDecimal().ParseToDecimal(); - if (refund_postage_per_order.ParseToDecimal() <= 2.5m) // 每单费用 - refund_postage_per_order = 2.5m; - var gift_oem_amount_per_order = RegexUtils.GetStringQuery(ref inputData, "gift_oem_amount_per_order").ParseToDecimal(); - if (gift_oem_amount_per_order.ParseToDecimal() < 0m) // 每单费用 - gift_oem_amount_per_order = 0; - - 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,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 paramLst = new List(); - 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 = 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 (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 = 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\":\"输入为空\"}"; - } - - /// - /// 增加或减少用户积分 - /// - /// - /// - 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; - 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 paramLst = new List(); - 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(); - 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 paramLst = new List(); - 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 = System.Configuration.ConfigurationManager.ConnectionStrings["ConnKJD"].ConnectionString; - 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 userPaymentList = new List(); - 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\":\"输入为空\"}"; - } - - - /// - /// 增加或减少用户积分 - /// - /// - /// - 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 paramLst = new List(); - 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 = System.Configuration.ConfigurationManager.ConnectionStrings["ConnKJD"].ConnectionString; - 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 fullTextSearchStr = new List(); - // 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 userPaymentList = new List(); - 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 = 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\":\"输入为空\"}"; - } - - /// - /// 添加充值二维码 - /// - /// - /// - 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\":\"输入为空\"}"; - } - - /// - /// 获取充值二维码 - /// - /// - /// - 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\":\"输入为空\"}"; - } - } + 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 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 = 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," + + "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\":\"输入为空\"}"; + } + + /// + /// 添加子账号 + /// + /// + /// + 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 userList = new List(); + 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 + "' and balance=0"; + + var rst = mySql.ExecuteAffectedRows(sql); + mySql.Close(); + if (rst > 0) + { + return "{\"code\":200,\"msg\":\"success\"}"; + } + if (rst == 0) + { + return "{\"code\":500,\"msg\":\"删除失败,请检查账户拍单余额是否还有剩余\"}"; + } + 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 = System.Configuration.ConfigurationManager.ConnectionStrings["ConnKJD"].ConnectionString; + 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 userList = new List(); + 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 UserLoginResultParam GetUserByUserName(string username) + { + + if (!string.IsNullOrEmpty(username)) + { + string conn = System.Configuration.ConfigurationManager.ConnectionStrings["ConnKJD"].ConnectionString; + MysqlUtils mySql = new MysqlUtils(conn); + + + string sql = "select * " + + " FROM wxxd.user u " + + $" WHERE user_name = '{username}'"; + + var dt = mySql.ExecuteDataTable(sql); + mySql.Close(); + if (!mySql.Message.IsNullOrEmpty()) + { + mySql.Close(); + return null; + } + if (dt != null) + { + 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(), + 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(); + } + return user; + } + } + } + + return null; + } + + 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").ParseToDecimal(); + if (postage_per_order.ParseToDecimal() <= 2.2m) // 每单费用 + postage_per_order = 2.2m; + var refund_postage_per_order = RegexUtils.GetStringQuery(ref inputData, "refund_postage_per_order").ParseToDecimal().ParseToDecimal(); + if (refund_postage_per_order.ParseToDecimal() <= 2.5m) // 每单费用 + refund_postage_per_order = 2.5m; + var gift_oem_amount_per_order = RegexUtils.GetStringQuery(ref inputData, "gift_oem_amount_per_order").ParseToDecimal(); + if (gift_oem_amount_per_order.ParseToDecimal() < 0m) // 每单费用 + gift_oem_amount_per_order = 0; + + 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,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 paramLst = new List(); + 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 = 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 (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 = 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\":\"输入为空\"}"; + } + + /// + /// 增加或减少用户积分 + /// + /// + /// + 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; + 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 paramLst = new List(); + 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(); + 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 paramLst = new List(); + 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 = System.Configuration.ConfigurationManager.ConnectionStrings["ConnKJD"].ConnectionString; + 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 userPaymentList = new List(); + 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\":\"输入为空\"}"; + } + + + /// + /// 增加或减少用户积分 + /// + /// + /// + 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 paramLst = new List(); + 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 = System.Configuration.ConfigurationManager.ConnectionStrings["ConnKJD"].ConnectionString; + 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 fullTextSearchStr = new List(); + // 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 userPaymentList = new List(); + 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 = 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\":\"输入为空\"}"; + } + + /// + /// 添加充值二维码 + /// + /// + /// + 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\":\"输入为空\"}"; + } + + /// + /// 获取充值二维码 + /// + /// + /// + 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\":\"输入为空\"}"; + } + } } \ No newline at end of file diff --git a/KJD_WebService/KJD_WebService.csproj b/KJD_WebService/KJD_WebService.csproj index 81e7388..f0b2aa6 100644 --- a/KJD_WebService/KJD_WebService.csproj +++ b/KJD_WebService/KJD_WebService.csproj @@ -1,4 +1,4 @@ - + @@ -108,6 +108,7 @@ + @@ -116,6 +117,11 @@ + + + + + diff --git a/KJD_WebService/Model/Result.cs b/KJD_WebService/Model/Result.cs index 0d25775..9ac1e2d 100644 --- a/KJD_WebService/Model/Result.cs +++ b/KJD_WebService/Model/Result.cs @@ -44,4 +44,10 @@ namespace KJD_Web.Model } } + + public class PageResult : Result + { + public int Page { get; set; } + public int Total { get; set; } + } } diff --git a/KJD_WebService/Model/WxModel/oem.cs b/KJD_WebService/Model/WxModel/oem.cs index 180cb3d..96100bd 100644 --- a/KJD_WebService/Model/WxModel/oem.cs +++ b/KJD_WebService/Model/WxModel/oem.cs @@ -1,19 +1,36 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace KJD_Web.Model.WxModel { - public class oem - { - public int id { get; set; } - public string oem_id { get; set; } - public string oem_name { get; set; } - public string oem_owner { get; set; } - public string oem_icon { get; set; } - public string oem_img { get; set; } - public DateTime add_time { get; set; } - public DateTime mdy_time { get; set; } - } + public class oem + { + public int id { get; set; } + public string oem_id { get; set; } + public string oem_name { get; set; } + public string oem_owner { get; set; } + public string oem_icon { get; set; } + public string oem_img { get; set; } + public DateTime add_time { get; set; } + public DateTime mdy_time { get; set; } + /// + /// 当前可提现 + /// + public long available_balance { get; set; } + /// + /// 冻结金额 + /// + public long frozen_balance { get; set; } + /// + /// 历史累计返利 + /// + public long total_rebate_amount { get; set; } + /// + /// 历史累计提现 + /// + public long total_withdraw_amount { get; set; } + + } } \ No newline at end of file diff --git a/KJD_WebService/Model/WxModel/user_payment_record_info.cs b/KJD_WebService/Model/WxModel/user_payment_record_info.cs index e5cb362..0bbc8e2 100644 --- a/KJD_WebService/Model/WxModel/user_payment_record_info.cs +++ b/KJD_WebService/Model/WxModel/user_payment_record_info.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Web; @@ -14,10 +14,14 @@ namespace KJD_Web.Model.WxModel public int? type { get; set; } /// - /// 充值或花费的金额(元) + /// 金额(元) /// public decimal amount { get; set; } /// + /// 归属oem用户的金额(元) + /// + public decimal oem_amount { get; set; } + /// /// 充值或花费后的当前账户余额(元) /// public decimal balance { get; set; } @@ -65,5 +69,13 @@ namespace KJD_Web.Model.WxModel /// 扣款的对方账户名称 /// public string counterparty_account_name { get; set; } + /// + /// OEM是否结算 0未结算 1已结算 + /// + public int? settlement { get; set; } + /// + /// 退款流水号 外采&订单号 + /// + public string refund_flow_no { get; set; } } } \ No newline at end of file diff --git a/KJD_WebService/Upload/CTX202608261802035458152.jpg b/KJD_WebService/Upload/CTX202608261802035458152.jpg new file mode 100644 index 0000000..41df718 Binary files /dev/null and b/KJD_WebService/Upload/CTX202608261802035458152.jpg differ diff --git a/KJD_WebService/Upload/CTX202608271429375274754.jpg b/KJD_WebService/Upload/CTX202608271429375274754.jpg new file mode 100644 index 0000000..41df718 Binary files /dev/null and b/KJD_WebService/Upload/CTX202608271429375274754.jpg differ diff --git a/KJD_WebService/Upload/TX202608271036009274190.jpg b/KJD_WebService/Upload/TX202608271036009274190.jpg new file mode 100644 index 0000000..41df718 Binary files /dev/null and b/KJD_WebService/Upload/TX202608271036009274190.jpg differ diff --git a/KJD_WebService/Upload/TX202608271044205743890.jpg b/KJD_WebService/Upload/TX202608271044205743890.jpg new file mode 100644 index 0000000..41df718 Binary files /dev/null and b/KJD_WebService/Upload/TX202608271044205743890.jpg differ diff --git a/KJD_WebService/Upload/TX202608271044310516004.jpg b/KJD_WebService/Upload/TX202608271044310516004.jpg new file mode 100644 index 0000000..41df718 Binary files /dev/null and b/KJD_WebService/Upload/TX202608271044310516004.jpg differ diff --git a/KJD_WebService/Upload/TX202608271429375274754.jpg b/KJD_WebService/Upload/TX202608271429375274754.jpg new file mode 100644 index 0000000..41df718 Binary files /dev/null and b/KJD_WebService/Upload/TX202608271429375274754.jpg differ diff --git a/KJD_WebService/Upload/TX202608271431545310545.jpg b/KJD_WebService/Upload/TX202608271431545310545.jpg new file mode 100644 index 0000000..41df718 Binary files /dev/null and b/KJD_WebService/Upload/TX202608271431545310545.jpg differ diff --git a/KJD_WebService/Upload/TX202608271437510909859.jpg b/KJD_WebService/Upload/TX202608271437510909859.jpg new file mode 100644 index 0000000..41df718 Binary files /dev/null and b/KJD_WebService/Upload/TX202608271437510909859.jpg differ diff --git a/KJD_WebService/Upload/TX202608271438406094349.jpg b/KJD_WebService/Upload/TX202608271438406094349.jpg new file mode 100644 index 0000000..41df718 Binary files /dev/null and b/KJD_WebService/Upload/TX202608271438406094349.jpg differ diff --git a/KJD_WebService/Utils/Extension/Extension.Convert.cs b/KJD_WebService/Utils/Extension/Extension.Convert.cs index 84f1f2b..8450cd1 100644 --- a/KJD_WebService/Utils/Extension/Extension.Convert.cs +++ b/KJD_WebService/Utils/Extension/Extension.Convert.cs @@ -12,96 +12,96 @@ using System.Threading.Tasks; namespace NaiBa.Util.Extension { - public static partial class Extensions - { - #region 转换为long - /// - /// 将object转换为long,若转换失败,则返回0。不抛出异常。 - /// - /// - /// - public static long ParseToLong(this object obj) - { - if (obj == null) - return 0L; + public static partial class Extensions + { + #region 转换为long + /// + /// 将object转换为long,若转换失败,则返回0。不抛出异常。 + /// + /// + /// + public static long ParseToLong(this object obj) + { + if (obj == null) + return 0L; - try - { - string str = obj.ParseToString(); - if (string.IsNullOrEmpty(str)) - { - return 0; - } - return long.Parse(str); - } - catch - { - return 0L; - } - } + try + { + string str = obj.ParseToString(); + if (string.IsNullOrEmpty(str)) + { + return 0; + } + return long.Parse(str); + } + catch + { + return 0L; + } + } - public static long? ParseToNullableLong(this object obj) - { - if (obj == null) - return null; + public static long? ParseToNullableLong(this object obj) + { + if (obj == null) + return null; - try - { - string str = obj.ParseToString(); - if (string.IsNullOrEmpty(str)) - { - return null; - } - return long.Parse(str); - } - catch - { - return null; - } - } + try + { + string str = obj.ParseToString(); + if (string.IsNullOrEmpty(str)) + { + return null; + } + return long.Parse(str); + } + catch + { + return null; + } + } - /// - /// 将object转换为long,若转换失败,则返回指定值。不抛出异常。 - /// - /// - /// - /// - public static long ParseToLong(this string str, long defaultValue) - { - if (str == null) - return defaultValue; + /// + /// 将object转换为long,若转换失败,则返回指定值。不抛出异常。 + /// + /// + /// + /// + public static long ParseToLong(this string str, long defaultValue) + { + if (str == null) + return defaultValue; - try - { - return long.Parse(str); - } - catch - { - return defaultValue; - } - } - #endregion + try + { + return long.Parse(str); + } + catch + { + return defaultValue; + } + } + #endregion - #region 转换为int - /// - /// 将object转换为int,若转换失败,则返回0。不抛出异常。 - /// - /// - /// - public static int ParseToInt(this object str) - { - if (str == null) - return 0; + #region 转换为int + /// + /// 将object转换为int,若转换失败,则返回0。不抛出异常。 + /// + /// + /// + public static int ParseToInt(this object str) + { + if (str == null) + return 0; - try - { - return Convert.ToInt32(str); - } - catch - { - return 0; - } - } + try + { + return Convert.ToInt32(str); + } + catch + { + return 0; + } + } public static int? ParseToNullableInt(this object str) { @@ -141,588 +141,590 @@ namespace NaiBa.Util.Extension } public static int DecimalPointParseToInt(this object str) - { - try - { - string temp = str.ParseToString(); - int i = temp.IndexOf('.'); - if (i > 0) - { - temp = temp.Substring(0, i); - } - return Convert.ToInt32(temp); - } - catch - { - return 0; - } - } + { + try + { + string temp = str.ParseToString(); + int i = temp.IndexOf('.'); + if (i > 0) + { + temp = temp.Substring(0, i); + } + return Convert.ToInt32(temp); + } + catch + { + return 0; + } + } - /// - /// 将object转换为int,若转换失败,则返回指定值。不抛出异常。 - /// null返回默认值 - /// - /// - /// - /// - public static int ParseToInt(this object str, int defaultValue) - { - if (str == null) - { - return defaultValue; - } - try - { - return Convert.ToInt32(str); - } - catch - { - return defaultValue; - } - } - #endregion + /// + /// 将object转换为int,若转换失败,则返回指定值。不抛出异常。 + /// null返回默认值 + /// + /// + /// + /// + public static int ParseToInt(this object str, int defaultValue) + { + if (str == null) + { + return defaultValue; + } + try + { + return Convert.ToInt32(str); + } + catch + { + return defaultValue; + } + } + #endregion - #region 转换为short - /// - /// 将object转换为short,若转换失败,则返回0。不抛出异常。 - /// - /// - /// - public static short ParseToShort(this object obj) - { - try - { - return short.Parse(obj.ToString()); - } - catch - { - return 0; - } - } + #region 转换为short + /// + /// 将object转换为short,若转换失败,则返回0。不抛出异常。 + /// + /// + /// + public static short ParseToShort(this object obj) + { + try + { + return short.Parse(obj.ToString()); + } + catch + { + return 0; + } + } - /// - /// 将object转换为short,若转换失败,则返回指定值。不抛出异常。 - /// - /// - /// - public static short ParseToShort(this object str, short defaultValue) - { - try - { - return short.Parse(str.ToString()); - } - catch - { - return defaultValue; - } - } - #endregion + /// + /// 将object转换为short,若转换失败,则返回指定值。不抛出异常。 + /// + /// + /// + public static short ParseToShort(this object str, short defaultValue) + { + try + { + return short.Parse(str.ToString()); + } + catch + { + return defaultValue; + } + } + #endregion - #region 转换为demical - /// - /// 将object转换为demical,若转换失败,则返回指定值。不抛出异常。 - /// - /// - /// - public static decimal ParseToDecimal(this object str, decimal defaultValue) - { - try - { - return decimal.Parse(str.ToString()); - } - catch - { - return defaultValue; - } - } + #region 转换为demical + /// + /// 将object转换为demical,若转换失败,则返回指定值。不抛出异常。 + /// + /// + /// + public static decimal ParseToDecimal(this object str, decimal defaultValue) + { + try + { + if (str is DBNull) { return defaultValue; } + return decimal.Parse(str.ToString()); + } + catch + { + return defaultValue; + } + } - /// - /// 将object转换为demical,若转换失败,则返回0。不抛出异常。 - /// - /// - /// - public static decimal ParseToDecimal(this object str) - { - try - { - return decimal.Parse(str.ToString()); - } - catch - { - return 0; - } - } - public static decimal? ParseToNullableDecimal(this object str) - { - try - { - return decimal.Parse(str.ToString()); - } - catch - { - return null; - } - } - #endregion + /// + /// 将object转换为demical,若转换失败,则返回0。不抛出异常。 + /// + /// + /// + public static decimal ParseToDecimal(this object str) + { + try + { + if (str is DBNull) { return 0; } + return decimal.Parse(str.ToString()); + } + catch + { + return 0; + } + } + public static decimal? ParseToNullableDecimal(this object str) + { + try + { + return decimal.Parse(str.ToString()); + } + catch + { + return null; + } + } + #endregion - #region 转化为bool - /// - /// 将object转换为bool,若转换失败,则返回false。不抛出异常。 - /// - /// - /// - public static bool ParseToBool(this object str) - { - try - { - if (str is null) - return false; - return bool.Parse(str.ToString()); - } - catch - { - return false; - } - } + #region 转化为bool + /// + /// 将object转换为bool,若转换失败,则返回false。不抛出异常。 + /// + /// + /// + public static bool ParseToBool(this object str) + { + try + { + if (str is null) + return false; + return bool.Parse(str.ToString()); + } + catch + { + return false; + } + } - /// - /// 将object转换为bool,若转换失败,则返回指定值。不抛出异常。 - /// - /// - /// - public static bool ParseToBool(this object str, bool result) - { - try - { - return bool.Parse(str.ToString()); - } - catch - { - return result; - } - } - #endregion + /// + /// 将object转换为bool,若转换失败,则返回指定值。不抛出异常。 + /// + /// + /// + public static bool ParseToBool(this object str, bool result) + { + try + { + return bool.Parse(str.ToString()); + } + catch + { + return result; + } + } + #endregion - #region 转换为float - /// - /// 将object转换为float,若转换失败,则返回0。不抛出异常。 - /// - /// - /// - public static float ParseToFloat(this object str) - { - try - { - return float.Parse(str.ToString()); - } - catch - { - return 0; - } - } + #region 转换为float + /// + /// 将object转换为float,若转换失败,则返回0。不抛出异常。 + /// + /// + /// + public static float ParseToFloat(this object str) + { + try + { + return float.Parse(str.ToString()); + } + catch + { + return 0; + } + } - /// - /// 将object转换为float,若转换失败,则返回指定值。不抛出异常。 - /// - /// - /// - public static float ParseToFloat(this object str, float result) - { - try - { - return float.Parse(str.ToString()); - } - catch - { - return result; - } - } - #endregion + /// + /// 将object转换为float,若转换失败,则返回指定值。不抛出异常。 + /// + /// + /// + public static float ParseToFloat(this object str, float result) + { + try + { + return float.Parse(str.ToString()); + } + catch + { + return result; + } + } + #endregion - #region 转换为Guid - /// - /// 将string转换为Guid,若转换失败,则返回Guid.Empty。不抛出异常。 - /// - /// - /// - public static Guid ParseToGuid(this string str) - { - try - { - return new Guid(str); - } - catch - { - return Guid.Empty; - } - } - #endregion + #region 转换为Guid + /// + /// 将string转换为Guid,若转换失败,则返回Guid.Empty。不抛出异常。 + /// + /// + /// + public static Guid ParseToGuid(this string str) + { + try + { + return new Guid(str); + } + catch + { + return Guid.Empty; + } + } + #endregion - #region 转换为DateTime + #region 转换为DateTime - public static DateTime? ParseToDateTimeNullable(this string str) - { - try - { - if (string.IsNullOrWhiteSpace(str)) - { - return null; - } + public static DateTime? ParseToDateTimeNullable(this string str) + { + try + { + if (string.IsNullOrWhiteSpace(str)) + { + return null; + } - try - { - return DateTime.Parse(str); - } - catch - { - } + try + { + return DateTime.Parse(str); + } + catch + { + } - if (str.Contains("年") && str.Contains("月") && str.Contains("日") && !str.Contains("周")) - str = str.Replace("年", "-").Replace("月", "-").Replace("日", "").Replace("时", ":").Replace("分", ":").Replace("秒", "").Trim(' ', ':'); - if (str.Contains("-") || str.Contains("/")) - { - return DateTime.Parse(str); - } - else - { - int length = str.Length; - switch (length) - { - case 4: - return DateTime.ParseExact(str, "yyyy", System.Globalization.CultureInfo.CurrentCulture); - case 6: - return DateTime.ParseExact(str, "yyyyMM", System.Globalization.CultureInfo.CurrentCulture); - case 8: - return DateTime.ParseExact(str, "yyyyMMdd", System.Globalization.CultureInfo.CurrentCulture); - case 10: - return DateTime.ParseExact(str, "yyyyMMddHH", System.Globalization.CultureInfo.CurrentCulture); - case 12: - return DateTime.ParseExact(str, "yyyyMMddHHmm", System.Globalization.CultureInfo.CurrentCulture); - case 14: - return DateTime.ParseExact(str, "yyyyMMddHHmmss", System.Globalization.CultureInfo.CurrentCulture); - default: - return DateTime.ParseExact(str, "yyyyMMddHHmmss", System.Globalization.CultureInfo.CurrentCulture); - } - } - } - catch - { - return null; - } - } + if (str.Contains("年") && str.Contains("月") && str.Contains("日") && !str.Contains("周")) + str = str.Replace("年", "-").Replace("月", "-").Replace("日", "").Replace("时", ":").Replace("分", ":").Replace("秒", "").Trim(' ', ':'); + if (str.Contains("-") || str.Contains("/")) + { + return DateTime.Parse(str); + } + else + { + int length = str.Length; + switch (length) + { + case 4: + return DateTime.ParseExact(str, "yyyy", System.Globalization.CultureInfo.CurrentCulture); + case 6: + return DateTime.ParseExact(str, "yyyyMM", System.Globalization.CultureInfo.CurrentCulture); + case 8: + return DateTime.ParseExact(str, "yyyyMMdd", System.Globalization.CultureInfo.CurrentCulture); + case 10: + return DateTime.ParseExact(str, "yyyyMMddHH", System.Globalization.CultureInfo.CurrentCulture); + case 12: + return DateTime.ParseExact(str, "yyyyMMddHHmm", System.Globalization.CultureInfo.CurrentCulture); + case 14: + return DateTime.ParseExact(str, "yyyyMMddHHmmss", System.Globalization.CultureInfo.CurrentCulture); + default: + return DateTime.ParseExact(str, "yyyyMMddHHmmss", System.Globalization.CultureInfo.CurrentCulture); + } + } + } + catch + { + return null; + } + } - /// - /// 将string转换为DateTime,若转换失败,则返回日期最小值。不抛出异常。 - /// - /// - /// - public static DateTime ParseToDateTime(this string str) - { - try - { - if (string.IsNullOrWhiteSpace(str)) - { - return DateTime.MinValue; - } - if (str.Contains("-") || str.Contains("/")) - { - return DateTime.Parse(str); - } - else - { - int length = str.Length; - switch (length) - { - case 4: - return DateTime.ParseExact(str, "yyyy", System.Globalization.CultureInfo.CurrentCulture); - case 6: - return DateTime.ParseExact(str, "yyyyMM", System.Globalization.CultureInfo.CurrentCulture); - case 8: - return DateTime.ParseExact(str, "yyyyMMdd", System.Globalization.CultureInfo.CurrentCulture); - case 10: - return DateTime.ParseExact(str, "yyyyMMddHH", System.Globalization.CultureInfo.CurrentCulture); - case 12: - return DateTime.ParseExact(str, "yyyyMMddHHmm", System.Globalization.CultureInfo.CurrentCulture); - case 14: - return DateTime.ParseExact(str, "yyyyMMddHHmmss", System.Globalization.CultureInfo.CurrentCulture); - default: - return DateTime.ParseExact(str, "yyyyMMddHHmmss", System.Globalization.CultureInfo.CurrentCulture); - } - } - } - catch - { - return DateTime.MinValue; - } - } + /// + /// 将string转换为DateTime,若转换失败,则返回日期最小值。不抛出异常。 + /// + /// + /// + public static DateTime ParseToDateTime(this string str) + { + try + { + if (string.IsNullOrWhiteSpace(str)) + { + return DateTime.MinValue; + } + if (str.Contains("-") || str.Contains("/")) + { + return DateTime.Parse(str); + } + else + { + int length = str.Length; + switch (length) + { + case 4: + return DateTime.ParseExact(str, "yyyy", System.Globalization.CultureInfo.CurrentCulture); + case 6: + return DateTime.ParseExact(str, "yyyyMM", System.Globalization.CultureInfo.CurrentCulture); + case 8: + return DateTime.ParseExact(str, "yyyyMMdd", System.Globalization.CultureInfo.CurrentCulture); + case 10: + return DateTime.ParseExact(str, "yyyyMMddHH", System.Globalization.CultureInfo.CurrentCulture); + case 12: + return DateTime.ParseExact(str, "yyyyMMddHHmm", System.Globalization.CultureInfo.CurrentCulture); + case 14: + return DateTime.ParseExact(str, "yyyyMMddHHmmss", System.Globalization.CultureInfo.CurrentCulture); + default: + return DateTime.ParseExact(str, "yyyyMMddHHmmss", System.Globalization.CultureInfo.CurrentCulture); + } + } + } + catch + { + return DateTime.MinValue; + } + } - /// - /// 将string转换为DateTime,若转换失败,则返回默认值。 - /// - /// - /// - /// - public static DateTime ParseToDateTime(this string str, DateTime? defaultValue) - { - try - { - if (string.IsNullOrWhiteSpace(str)) - { - return defaultValue.GetValueOrDefault(); - } - if (str.Contains("-") || str.Contains("/")) - { - return DateTime.Parse(str); - } - else - { - int length = str.Length; - switch (length) - { - case 4: - return DateTime.ParseExact(str, "yyyy", System.Globalization.CultureInfo.CurrentCulture); - case 6: - return DateTime.ParseExact(str, "yyyyMM", System.Globalization.CultureInfo.CurrentCulture); - case 8: - return DateTime.ParseExact(str, "yyyyMMdd", System.Globalization.CultureInfo.CurrentCulture); - case 10: - return DateTime.ParseExact(str, "yyyyMMddHH", System.Globalization.CultureInfo.CurrentCulture); - case 12: - return DateTime.ParseExact(str, "yyyyMMddHHmm", System.Globalization.CultureInfo.CurrentCulture); - case 14: - return DateTime.ParseExact(str, "yyyyMMddHHmmss", System.Globalization.CultureInfo.CurrentCulture); - default: - return DateTime.ParseExact(str, "yyyyMMddHHmmss", System.Globalization.CultureInfo.CurrentCulture); - } - } - } - catch - { - return defaultValue.GetValueOrDefault(); - } - } - #endregion + /// + /// 将string转换为DateTime,若转换失败,则返回默认值。 + /// + /// + /// + /// + public static DateTime ParseToDateTime(this string str, DateTime? defaultValue) + { + try + { + if (string.IsNullOrWhiteSpace(str)) + { + return defaultValue.GetValueOrDefault(); + } + if (str.Contains("-") || str.Contains("/")) + { + return DateTime.Parse(str); + } + else + { + int length = str.Length; + switch (length) + { + case 4: + return DateTime.ParseExact(str, "yyyy", System.Globalization.CultureInfo.CurrentCulture); + case 6: + return DateTime.ParseExact(str, "yyyyMM", System.Globalization.CultureInfo.CurrentCulture); + case 8: + return DateTime.ParseExact(str, "yyyyMMdd", System.Globalization.CultureInfo.CurrentCulture); + case 10: + return DateTime.ParseExact(str, "yyyyMMddHH", System.Globalization.CultureInfo.CurrentCulture); + case 12: + return DateTime.ParseExact(str, "yyyyMMddHHmm", System.Globalization.CultureInfo.CurrentCulture); + case 14: + return DateTime.ParseExact(str, "yyyyMMddHHmmss", System.Globalization.CultureInfo.CurrentCulture); + default: + return DateTime.ParseExact(str, "yyyyMMddHHmmss", System.Globalization.CultureInfo.CurrentCulture); + } + } + } + catch + { + return defaultValue.GetValueOrDefault(); + } + } + #endregion - #region 转换为string - /// - /// 将object转换为string,若转换失败,则返回""。不抛出异常。 - /// - /// - /// - public static string ParseToString(this object obj) - { - try - { - if (obj == null) - { - return string.Empty; - } - else - { - if (obj is DateTime) - return (obj as DateTime?).Value.ToString("yyyy-MM-dd HH:mm:ss"); - return obj.ToString(); - } - } - catch - { - return string.Empty; - } - } + #region 转换为string + /// + /// 将object转换为string,若转换失败,则返回""。不抛出异常。 + /// + /// + /// + public static string ParseToString(this object obj) + { + try + { + if (obj == null) + { + return string.Empty; + } + else + { + if (obj is DateTime) + return (obj as DateTime?).Value.ToString("yyyy-MM-dd HH:mm:ss"); + return obj.ToString(); + } + } + catch + { + return string.Empty; + } + } - public static string ParseToNullableString(this object obj) - { - try - { - if (obj == null) - { - return null; - } - else - { - if (obj is DateTime) - return (obj as DateTime?).Value.ToString("yyyy-MM-dd HH:mm:ss"); - return obj.ToString(); - } - } - catch - { - return null; - } - } + public static string ParseToNullableString(this object obj) + { + try + { + if (obj == null) + { + return null; + } + else + { + if (obj is DateTime) + return (obj as DateTime?).Value.ToString("yyyy-MM-dd HH:mm:ss"); + return obj.ToString(); + } + } + catch + { + return null; + } + } - public static string ParseToStrings(this object obj, string split = ",") - { - try - { - var list = obj as IEnumerable; - if (list != null) - { - return string.Join(split, list); - } - else - { - return obj.ToString(); - } - } - catch - { - return string.Empty; - } - } - #endregion + public static string ParseToStrings(this object obj, string split = ",") + { + try + { + var list = obj as IEnumerable; + if (list != null) + { + return string.Join(split, list); + } + else + { + return obj.ToString(); + } + } + catch + { + return string.Empty; + } + } + #endregion - #region 转换为double - /// - /// 将object转换为double,若转换失败,则返回0。不抛出异常。 - /// - /// - /// - public static double ParseToDouble(this object obj) - { - try - { - return double.Parse(obj.ToString()); - } - catch - { - return 0; - } - } + #region 转换为double + /// + /// 将object转换为double,若转换失败,则返回0。不抛出异常。 + /// + /// + /// + public static double ParseToDouble(this object obj) + { + try + { + return double.Parse(obj.ToString()); + } + catch + { + return 0; + } + } - /// - /// 将object转换为double,若转换失败,则返回指定值。不抛出异常。 - /// - /// - /// - /// - public static double ParseToDouble(this object str, double defaultValue) - { - try - { - return double.Parse(str.ToString()); - } - catch - { - return defaultValue; - } - } - #endregion + /// + /// 将object转换为double,若转换失败,则返回指定值。不抛出异常。 + /// + /// + /// + /// + public static double ParseToDouble(this object str, double defaultValue) + { + try + { + return double.Parse(str.ToString()); + } + catch + { + return defaultValue; + } + } + #endregion - #region 字符串转指定类型Array - public static T[] SplitToArray(this string value, string split = ",") - { - if (string.IsNullOrEmpty(value)) - { - return default(T[]); - } - var arr = value.Split(new string[] { split }, StringSplitOptions.RemoveEmptyEntries).CastSuper().ToArray(); - return arr; - } + #region 字符串转指定类型Array + public static T[] SplitToArray(this string value, string split = ",") + { + if (string.IsNullOrEmpty(value)) + { + return default(T[]); + } + var arr = value.Split(new string[] { split }, StringSplitOptions.RemoveEmptyEntries).CastSuper().ToArray(); + return arr; + } - public static T[] SplitToArray(this string value, string[] split) - { - if (string.IsNullOrEmpty(value)) - { - return default(T[]); - } - var arr = value.Split(split, StringSplitOptions.RemoveEmptyEntries).CastSuper().ToArray(); - return arr; - } - #endregion + public static T[] SplitToArray(this string value, string[] split) + { + if (string.IsNullOrEmpty(value)) + { + return default(T[]); + } + var arr = value.Split(split, StringSplitOptions.RemoveEmptyEntries).CastSuper().ToArray(); + return arr; + } + #endregion - #region 字符串转指定类型List - public static List SplitToList(this string value, string split = ",") - { - if (string.IsNullOrEmpty(value)) - { - return new List(); - } - var list = value.Split(new string[] { split }, StringSplitOptions.RemoveEmptyEntries).CastSuper().ToList(); - return list; - } + #region 字符串转指定类型List + public static List SplitToList(this string value, string split = ",") + { + if (string.IsNullOrEmpty(value)) + { + return new List(); + } + var list = value.Split(new string[] { split }, StringSplitOptions.RemoveEmptyEntries).CastSuper().ToList(); + return list; + } - public static List SplitToList(this string value, string[] split) - { - if (string.IsNullOrEmpty(value)) - { - return new List(); - } - var list = value.Split(split, StringSplitOptions.RemoveEmptyEntries).CastSuper().ToList(); - return list; - } - #endregion + public static List SplitToList(this string value, string[] split) + { + if (string.IsNullOrEmpty(value)) + { + return new List(); + } + var list = value.Split(split, StringSplitOptions.RemoveEmptyEntries).CastSuper().ToList(); + return list; + } + #endregion - #region 强制转换类型 - /// - /// 强制转换类型 - /// - /// - /// - /// - public static IEnumerable CastSuper(this IEnumerable source) - { - foreach (object item in source) - { - yield return (TResult)Convert.ChangeType(item, typeof(TResult)); - } - } - #endregion + #region 强制转换类型 + /// + /// 强制转换类型 + /// + /// + /// + /// + public static IEnumerable CastSuper(this IEnumerable source) + { + foreach (object item in source) + { + yield return (TResult)Convert.ChangeType(item, typeof(TResult)); + } + } + #endregion - #region Object转换为Json - public static string ParseToJson(this object obj) - { - return JsonConvert.SerializeObject(obj); - } - #endregion + #region Object转换为Json + public static string ParseToJson(this object obj) + { + return JsonConvert.SerializeObject(obj); + } + #endregion - #region Json转为Object - public static T ParseToObject(this string json) - { - if (string.IsNullOrEmpty(json)) - { - return Activator.CreateInstance(); - } - return JsonConvert.DeserializeObject(json); - } - #endregion + #region Json转为Object + public static T ParseToObject(this string json) + { + if (string.IsNullOrEmpty(json)) + { + return Activator.CreateInstance(); + } + return JsonConvert.DeserializeObject(json); + } + #endregion - #region 深拷贝(克隆出一个新对象,拷贝对象里面的数据和子对象) - public static T DeepClone(this T o) - { - return o.ParseToJson().ParseToObject(); - // 这种方式在用 Obfuscator 的时候有问题 - //using (MemoryStream stream = new MemoryStream()) - //{ - // BinaryFormatter formatter = new BinaryFormatter(); - // formatter.Serialize(stream, o); - // stream.Position = 0; - // return (T)formatter.Deserialize(stream); - //} - } - #endregion + #region 深拷贝(克隆出一个新对象,拷贝对象里面的数据和子对象) + public static T DeepClone(this T o) + { + return o.ParseToJson().ParseToObject(); + // 这种方式在用 Obfuscator 的时候有问题 + //using (MemoryStream stream = new MemoryStream()) + //{ + // BinaryFormatter formatter = new BinaryFormatter(); + // formatter.Serialize(stream, o); + // stream.Position = 0; + // return (T)formatter.Deserialize(stream); + //} + } + #endregion - #region 浅拷贝(拷贝对象里面的数据[property and field],但不拷贝对象里面的子对象) - public static void ShadowClone(this T1 source, ref T2 destination) - { - var sourceMembers = ReflectionHelper.GetMembers(source.GetType()); - var destinationMembers = ReflectionHelper.GetMembers(destination.GetType()); + #region 浅拷贝(拷贝对象里面的数据[property and field],但不拷贝对象里面的子对象) + public static void ShadowClone(this T1 source, ref T2 destination) + { + var sourceMembers = ReflectionHelper.GetMembers(source.GetType()); + var destinationMembers = ReflectionHelper.GetMembers(destination.GetType()); - // Copy data from source to destination - foreach (var sourceMember in sourceMembers) - { - if (!ReflectionHelper.CanRead(sourceMember)) - { - continue; - } - var destinationMember = destinationMembers.FirstOrDefault(x => x.Name.ToLower() == sourceMember.Name.ToLower()); - if (destinationMember == null || !ReflectionHelper.CanWrite(destinationMember)) - { - continue; - } - ReflectionHelper.SetObjectValue(ref destination, destinationMember, ReflectionHelper.GetMemberValue(source, sourceMember)); - } - } - #endregion - } + // Copy data from source to destination + foreach (var sourceMember in sourceMembers) + { + if (!ReflectionHelper.CanRead(sourceMember)) + { + continue; + } + var destinationMember = destinationMembers.FirstOrDefault(x => x.Name.ToLower() == sourceMember.Name.ToLower()); + if (destinationMember == null || !ReflectionHelper.CanWrite(destinationMember)) + { + continue; + } + ReflectionHelper.SetObjectValue(ref destination, destinationMember, ReflectionHelper.GetMemberValue(source, sourceMember)); + } + } + #endregion + } } diff --git a/KJD_WebService/WXUserService.asmx.cs b/KJD_WebService/WXUserService.asmx.cs index 57fb4b4..c140754 100644 --- a/KJD_WebService/WXUserService.asmx.cs +++ b/KJD_WebService/WXUserService.asmx.cs @@ -1,6 +1,7 @@ -using KJD_Web.BLL.BXX; +using KJD_Web.BLL.BXX; using KJD_Web.BLL.WXXD; using KJD_Web.Utils; +using NaiBa.Util.Extension; using System; using System.Collections.Generic; using System.IO; @@ -11,296 +12,344 @@ using System.Web.Services; namespace KJD_Web { - /// - /// UserService 的摘要说明 - /// - [WebService(Namespace = "http://tempuri.org/")] - [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] - [System.ComponentModel.ToolboxItem(false)] - // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消注释以下行。 - // [System.Web.Script.Services.ScriptService] - public class WXUserService : System.Web.Services.WebService - { - [WebMethod] - public string hello_world() - { - return "Hello World"; - } + /// + /// UserService 的摘要说明 + /// + [WebService(Namespace = "http://tempuri.org/")] + [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] + [System.ComponentModel.ToolboxItem(false)] + // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消注释以下行。 + // [System.Web.Script.Services.ScriptService] + public class WXUserService : System.Web.Services.WebService + { + [WebMethod] + public string hello_world() + { + return "Hello World"; + } - private string GetRequestJsonString() - { - Context.Response.ContentType = "text/html;charset=utf-8"; - Context.Response.ContentEncoding = System.Text.Encoding.GetEncoding("utf-8"); + private string GetRequestJsonString() + { + Context.Response.ContentType = "text/html;charset=utf-8"; + Context.Response.ContentEncoding = System.Text.Encoding.GetEncoding("utf-8"); - using (Stream s = HttpContext.Current.Request.InputStream) // 获得json 字符流 - { - // 还原数据流 - byte[] b = new byte[s.Length]; - s.Read(b, 0, (int)s.Length); - string jsonText = Encoding.UTF8.GetString(b); // JSON字符串 - if (string.IsNullOrEmpty(jsonText)) - { - var qs = HttpContext.Current.Request.QueryString; - if (qs != null && qs.Keys.Count > 0) - { - jsonText = "{"; - foreach (var key in qs.Keys) - { - jsonText += "\"" + key + "\":" + "\"" + qs[key.ToString()] + "\";"; - } - jsonText = jsonText.TrimEnd(';') + "}"; - } - } - return jsonText; - } - } - //GetE57Authorization - [WebMethod] - public void get_e57_authorization() - { - string jsontext = GetRequestJsonString(); + using (Stream s = HttpContext.Current.Request.InputStream) // 获得json 字符流 + { + // 还原数据流 + byte[] b = new byte[s.Length]; + s.Read(b, 0, (int)s.Length); + string jsonText = Encoding.UTF8.GetString(b); // JSON字符串 + if (string.IsNullOrEmpty(jsonText)) + { + var qs = HttpContext.Current.Request.QueryString; + if (qs != null && qs.Keys.Count > 0) + { + jsonText = "{"; + foreach (var key in qs.Keys) + { + jsonText += "\"" + key + "\":" + "\"" + qs[key.ToString()] + "\";"; + } + jsonText = jsonText.TrimEnd(';') + "}"; + } + } + return jsonText; + } + } + //GetE57Authorization + [WebMethod] + public void get_e57_authorization() + { + string jsontext = GetRequestJsonString(); - var result = jsontext; - result = new WXUserManage().GetE57Authorization(jsontext); + var result = jsontext; + result = new WXUserManage().GetE57Authorization(jsontext); - Context.Response.Write(result); - Context.Response.End(); - } - [WebMethod] - public void user_login() - { - string jsontext = GetRequestJsonString(); + Context.Response.Write(result); + Context.Response.End(); + } + [WebMethod] + public void user_login() + { + string jsontext = GetRequestJsonString(); - var result = jsontext; - result = new WXUserManage().CheckUserLogin(jsontext); + var result = jsontext; + result = new WXUserManage().CheckUserLogin(jsontext); - Context.Response.Write(result); - Context.Response.End(); - } + Context.Response.Write(result); + Context.Response.End(); + } - [WebMethod] - public void change_password() - { - string jsontext = GetRequestJsonString(); + [WebMethod] + public void change_password() + { + string jsontext = GetRequestJsonString(); - var result = jsontext; - result = new WXUserManage().ChangePassword(jsontext); + var result = jsontext; + result = new WXUserManage().ChangePassword(jsontext); - Context.Response.Write(result); - Context.Response.End(); - } + Context.Response.Write(result); + Context.Response.End(); + } - [WebMethod] - public void get_sub_user() - { - string jsontext = GetRequestJsonString(); + [WebMethod] + public void get_sub_user() + { + string jsontext = GetRequestJsonString(); - var result = jsontext; - result = new WXUserManage().GetSubUser(jsontext); + var result = jsontext; + result = new WXUserManage().GetSubUser(jsontext); - Context.Response.Write(result); - Context.Response.End(); - } + Context.Response.Write(result); + Context.Response.End(); + } - [WebMethod] - public void update_sub_user() - { - string jsontext = GetRequestJsonString(); + [WebMethod] + public void update_sub_user() + { + string jsontext = GetRequestJsonString(); - var result = jsontext; - result = new WXUserManage().UpdateSubUser(jsontext); + var result = jsontext; + result = new WXUserManage().UpdateSubUser(jsontext); - Context.Response.Write(result); - Context.Response.End(); - } + Context.Response.Write(result); + Context.Response.End(); + } - [WebMethod] - public void add_sub_user() - { - string jsontext = GetRequestJsonString(); + [WebMethod] + public void add_sub_user() + { + string jsontext = GetRequestJsonString(); - var result = jsontext; - result = new WXUserManage().AddSubUser(jsontext); + var result = jsontext; + result = new WXUserManage().AddSubUser(jsontext); - Context.Response.Write(result); - Context.Response.End(); - } + Context.Response.Write(result); + Context.Response.End(); + } - [WebMethod] - public void delete_user() - { - string jsontext = GetRequestJsonString(); + [WebMethod] + public void delete_user() + { + string jsontext = GetRequestJsonString(); - var result = jsontext; - result = new WXUserManage().DelUser(jsontext); + var result = jsontext; + result = new WXUserManage().DelUser(jsontext); - Context.Response.Write(result); - Context.Response.End(); - } + Context.Response.Write(result); + Context.Response.End(); + } - [WebMethod] - public void get_all_user() - { - string jsontext = GetRequestJsonString(); + [WebMethod] + public void get_all_user() + { + string jsontext = GetRequestJsonString(); - var result = jsontext; - result = new WXUserManage().GetAllUser(jsontext); + var result = jsontext; + result = new WXUserManage().GetAllUser(jsontext); - Context.Response.Write(result); - Context.Response.End(); - } + Context.Response.Write(result); + Context.Response.End(); + } - [WebMethod] - public void update_user() - { - string jsontext = GetRequestJsonString(); + [WebMethod] + public void update_user() + { + string jsontext = GetRequestJsonString(); - var result = jsontext; - result = new WXUserManage().UpdateUser(jsontext); + var result = jsontext; + result = new WXUserManage().UpdateUser(jsontext); - Context.Response.Write(result); - Context.Response.End(); - } + Context.Response.Write(result); + Context.Response.End(); + } - [WebMethod] - public void add_user() - { - string jsontext = GetRequestJsonString(); + [WebMethod] + public void add_user() + { + string jsontext = GetRequestJsonString(); - var result = jsontext; - result = new WXUserManage().AddUser(jsontext); + var result = jsontext; + result = new WXUserManage().AddUser(jsontext); - Context.Response.Write(result); - Context.Response.End(); - } + Context.Response.Write(result); + Context.Response.End(); + } - [WebMethod] - public void update_user_points() - { - string jsontext = GetRequestJsonString(); + [WebMethod] + public void update_user_points() + { + string jsontext = GetRequestJsonString(); - var result = jsontext; - result = new WXUserManage().UpdateUserPoints(jsontext); + var result = jsontext; + result = new WXUserManage().UpdateUserPoints(jsontext); - Context.Response.Write(result); - Context.Response.End(); - } + Context.Response.Write(result); + Context.Response.End(); + } - [WebMethod] - public void get_user_points() - { - string jsontext = GetRequestJsonString(); + [WebMethod] + public void get_user_points() + { + string jsontext = GetRequestJsonString(); - var result = jsontext; - result = new WXUserManage().GetUserPoints(jsontext); + var result = jsontext; + result = new WXUserManage().GetUserPoints(jsontext); - Context.Response.Write(result); - Context.Response.End(); - } + Context.Response.Write(result); + Context.Response.End(); + } - [WebMethod] - public void update_user_balance() - { - string jsontext = GetRequestJsonString(); + [WebMethod] + public void update_user_balance() + { + string jsontext = GetRequestJsonString(); - var result = jsontext; - result = new WXUserManage().UpdateUserBalance(jsontext); + var result = jsontext; + result = new WXUserManage().UpdateUserBalance(jsontext); - Context.Response.Write(result); - Context.Response.End(); - } + Context.Response.Write(result); + Context.Response.End(); + } - [WebMethod] - public void get_user_balance() - { - string jsontext = GetRequestJsonString(); + [WebMethod] + public void get_user_balance() + { + string jsontext = GetRequestJsonString(); - var result = jsontext; - result = new WXUserManage().GetUserBalance(jsontext); + var result = jsontext; + result = new WXUserManage().GetUserBalance(jsontext); - Context.Response.Write(result); - Context.Response.End(); - } + Context.Response.Write(result); + Context.Response.End(); + } - [WebMethod] - public void get_wx_sale_assistant_cookie() - { - string jsontext = GetRequestJsonString(); + [WebMethod] + public void get_wx_sale_assistant_cookie() + { + string jsontext = GetRequestJsonString(); - var result = jsontext; - result = new WXUserManage().GetWxSaleAssistantCookie(jsontext); + var result = jsontext; + result = new WXUserManage().GetWxSaleAssistantCookie(jsontext); - Context.Response.Write(result); - Context.Response.End(); - } - [WebMethod] - public void update_wx_sale_assistant_cookie() - { - string jsontext = GetRequestJsonString(); + Context.Response.Write(result); + Context.Response.End(); + } + [WebMethod] + public void update_wx_sale_assistant_cookie() + { + string jsontext = GetRequestJsonString(); - var result = jsontext; - result = new WXUserManage().UpdateWxSaleAssistantCookie(jsontext); + var result = jsontext; + result = new WXUserManage().UpdateWxSaleAssistantCookie(jsontext); - Context.Response.Write(result); - Context.Response.End(); - } + Context.Response.Write(result); + Context.Response.End(); + } - [WebMethod] - public void update_top_up_qrcode() - { - string jsontext = GetRequestJsonString(); + [WebMethod] + public void update_top_up_qrcode() + { + string jsontext = GetRequestJsonString(); - var result = jsontext; - result = new WXUserManage().UpdateTopUpQrcode(jsontext); + var result = jsontext; + result = new WXUserManage().UpdateTopUpQrcode(jsontext); - Context.Response.Write(result); - Context.Response.End(); - } - [WebMethod] - public void get_top_up_qrcode() - { - string jsontext = GetRequestJsonString(); + Context.Response.Write(result); + Context.Response.End(); + } + [WebMethod] + public void get_top_up_qrcode() + { + string jsontext = GetRequestJsonString(); - var result = jsontext; - result = new WXUserManage().GetTopUpQrcode(jsontext); + var result = jsontext; + result = new WXUserManage().GetTopUpQrcode(jsontext); - Context.Response.Write(result); - Context.Response.End(); - } + Context.Response.Write(result); + Context.Response.End(); + } - [WebMethod] - public void add_mdy_oem() - { - string jsontext = GetRequestJsonString(); + [WebMethod] + public void add_mdy_oem() + { + string jsontext = GetRequestJsonString(); - var result = jsontext; - result = new WXOemManage().AddMdyOem(jsontext); + var result = jsontext; + result = new WXOemManage().AddMdyOem(jsontext); - Context.Response.Write(result); - Context.Response.End(); - } - [WebMethod] - public void del_oem() - { - string jsontext = GetRequestJsonString(); + Context.Response.Write(result); + Context.Response.End(); + } + [WebMethod] + public void del_oem() + { + string jsontext = GetRequestJsonString(); - var result = jsontext; - result = new WXOemManage().DelOem(jsontext); + var result = jsontext; + result = new WXOemManage().DelOem(jsontext); - Context.Response.Write(result); - Context.Response.End(); - } - [WebMethod] - public void get_oem() - { - string jsontext = GetRequestJsonString(); + Context.Response.Write(result); + Context.Response.End(); + } + [WebMethod] + public void get_oem() + { + string jsontext = GetRequestJsonString(); - var result = jsontext; - result = new WXOemManage().GetOem(jsontext); + var result = jsontext; + result = new WXOemManage().GetOem(jsontext); - Context.Response.Write(result); - Context.Response.End(); - } - } + Context.Response.Write(result); + Context.Response.End(); + } + [WebMethod] + public void oem_withdrawals() + { + string jsontext = GetRequestJsonString(); + + var result = jsontext; + var request = jsontext.ParseToObject(); + result = new WXOemManage().OemWithdrawals(request); + + Context.Response.Write(result); + Context.Response.End(); + } + [WebMethod] + public void oem_settle_flows() + { + string jsontext = GetRequestJsonString(); + + var result = jsontext; + var request = jsontext.ParseToObject(); + result = new WXOemManage().SettleOemFlows(request); + + Context.Response.Write(result); + Context.Response.End(); + } + [WebMethod] + public void apply_oem_withdrawal() + { + string jsontext = GetRequestJsonString(); + + var result = jsontext; + var request = jsontext.ParseToObject(); + result = new WXOemManage().ApplyOemWithdrawal(request); + + Context.Response.Write(result); + Context.Response.End(); + } + [WebMethod] + public void oem_audit_withdrawal() + { + string jsontext = GetRequestJsonString(); + + var result = jsontext; + var request = jsontext.ParseToObject(); + result = new WXOemManage().AuditOemWithdrawal(request); + + Context.Response.Write(result); + Context.Response.End(); + } + } } diff --git a/KJD_WebService/Web.config b/KJD_WebService/Web.config index 6463865..f5f6e18 100644 --- a/KJD_WebService/Web.config +++ b/KJD_WebService/Web.config @@ -5,8 +5,8 @@ --> - - + + diff --git a/test/WebServiceTest/App.config b/test/WebServiceTest/App.config new file mode 100644 index 0000000..0c4a326 --- /dev/null +++ b/test/WebServiceTest/App.config @@ -0,0 +1,71 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/test/WebServiceTest/UnitTest1.cs b/test/WebServiceTest/UnitTest1.cs new file mode 100644 index 0000000..7b0624f --- /dev/null +++ b/test/WebServiceTest/UnitTest1.cs @@ -0,0 +1,100 @@ +using KJD_Web.BLL.WXXD; +using System.Xml.Linq; + +namespace WebServiceTest +{ + public class Tests + { + const string UserName = "13388889999"; + [SetUp] + public void Setup() + { + } + + [Test] + public void GetOemWithdrawalsTest() + { + try + { + + + WXOemManage manage = new WXOemManage(); + string ret = manage.OemWithdrawals(new KJD_Web.BLL.WXXD.Requests.OemWithdrawalQueryRequest + { + user_name = "18990991234", + }); + Console.WriteLine(ret); + } + catch (Exception ex) + { + + } + Assert.Pass(); + } + + [Test] + public void SettleOemFlowsTest() + { + WXOemManage manage = new WXOemManage(); + var ret = manage.SettleOemFlows(new KJD_Web.BLL.WXXD.Requests.OemWithdrawalRequest + { + user_name = "13388889999", + + }); + Console.WriteLine(ret); + } + + [Test] + [TestCase("15266666666")] + [TestCase("15698175212")] + [TestCase("18238114231")] + [TestCase("15870095938")] + [TestCase("13388889999")] + [TestCase("13860701921")] + [TestCase("15907090308")] + [TestCase("17837688880")] + [TestCase("13682525364")] + [TestCase("13048056467")] + [TestCase("18317672222")] + [TestCase("18500143331")] + [TestCase("17318585555")] + [TestCase("13459139999")] + [TestCase("15206200631")] + [TestCase("18737568536")] + [TestCase("18949822610")] + [TestCase("18165955361")] + [TestCase("18556577919")] + public void ApplyOemWithdrawalTest(string name) + { + WXOemManage manage = new WXOemManage(); + var ret = manage.ApplyOemWithdrawal(new KJD_Web.BLL.WXXD.Requests.OemWithdrawalRequest + { + user_name = name, + amount = 10, + withdrawal_type = KJD_Web.BLL.WXXD.Requests.WithdrawalType.Alipay, + account_name = UserName, + account_no = "https://qr.alipay.com/fkx17983kv07mbwpyz8jt81", + }); + Console.WriteLine(ret); + } + [Test] + public void AuditOemWithdrawalTest() + { + WXOemManage manage = new WXOemManage(); + var ret = manage.AuditOemWithdrawal(new KJD_Web.BLL.WXXD.Requests.OemWithdrawalAuditRequest + { + withdrawal_no = "TX202608261403434589545", + audit_by = UserName, + audit_result = 1 + }); + Console.WriteLine(ret); + } + + [Test] + public void GetUser() + { + var user = new WXUserManage().GetUserByUserName("18990991234"); + Console.WriteLine(user.sa_level); + } + } +} \ No newline at end of file diff --git a/test/WebServiceTest/WebServiceTest.csproj b/test/WebServiceTest/WebServiceTest.csproj new file mode 100644 index 0000000..2c061b2 --- /dev/null +++ b/test/WebServiceTest/WebServiceTest.csproj @@ -0,0 +1,32 @@ + + + + net462 + enable + enable + 12 + false + true + + + + + + + + + + + + + + + + + + + + + + +