From 766afa2fb898f1ab77a5df78de9c8b5c89b431e3 Mon Sep 17 00:00:00 2001 From: chfei Date: Mon, 28 Sep 2026 17:06:23 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20shop=20=E6=B0=B8=E4=B8=8D?= =?UTF-8?q?=E8=BF=87=E6=9C=9FAPI?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- KJD_WebService/BLL/WXXD/WXShopManage.cs | 3813 +++++++++-------- .../Controllers/WX/WXShopController.cs | 2 +- .../Controllers/WX/WXShop_N_Controller.cs | 40 + KJD_WebService/KJD_WebService.csproj | 3 + KJD_WebService/Model/ShopModel/ShopParam.cs | 2 + KJD_WebService/Requests/ShopRequest.cs | 14 + KJD_WebService/Services/Shops/ShopService.cs | 42 + KJD_WebService/Services/Users/UserService.cs | 2 +- Store.Contracts/Shops/ShopEntity.cs | 350 +- Store.Framework/Commons/StoreAppTypeFinder.cs | 18 +- test/WebServiceTest/GiftLogisticsTest.cs | 4 +- 11 files changed, 2155 insertions(+), 2135 deletions(-) create mode 100644 KJD_WebService/Controllers/WX/WXShop_N_Controller.cs create mode 100644 KJD_WebService/Requests/ShopRequest.cs create mode 100644 KJD_WebService/Services/Shops/ShopService.cs diff --git a/KJD_WebService/BLL/WXXD/WXShopManage.cs b/KJD_WebService/BLL/WXXD/WXShopManage.cs index 8b156c0..043d639 100644 --- a/KJD_WebService/BLL/WXXD/WXShopManage.cs +++ b/KJD_WebService/BLL/WXXD/WXShopManage.cs @@ -21,1907 +21,1916 @@ using System.Web.Security; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; -namespace KJD_Web.BLL.WXXD +namespace KJD_Web.BLL.WXXD { - public class WXShopManage - { - public string GetShop(string inputData, bool isAdmin = false) - { - if (!string.IsNullOrEmpty(inputData)) - { - var timeCalc = DateTime.Now; - var user_name = RegexUtils.GetStringQuery(ref inputData, "user_name"); - var password = RegexUtils.GetStringQuery(ref inputData, "password"); - var search_id = RegexUtils.GetStringQuery(ref inputData, "search_id"); - var search_user_name = RegexUtils.GetStringQuery(ref inputData, "search_user_name"); - var search_login_name = RegexUtils.GetStringQuery(ref inputData, "search_login_name"); - var search_notes = RegexUtils.GetStringQuery(ref inputData, "search_notes"); - var search_name = RegexUtils.GetStringQuery(ref inputData, "search_name"); - var operate_sub_sa_name = RegexUtils.GetStringQuery(ref inputData, "operate_sub_sa_name")?.Replace("'", "\\'"); - var shop_ids = RegexUtils.GetStringQuery(ref inputData, "shop_ids")?.Replace("'", ""); - var is_show_expire = RegexUtils.GetStringQuery(ref inputData, "is_show_expire")?.ParseToBool(); - var is_get_erp_shop_id = RegexUtils.GetStringQuery(ref inputData, "is_get_erp_shop_id")?.ParseToBool(); - - if (!string.IsNullOrWhiteSpace(shop_ids)) - { - List shopIdLst = shop_ids.Split(',').ToList(); - shop_ids = "'" + string.Join("','", shopIdLst) + "'"; - } - var shop_names = RegexUtils.GetStringQuery(ref inputData, "shop_names"); - if (!string.IsNullOrWhiteSpace(shop_names)) - { - List shopNameLst = shop_names.Split(',').ToList(); - shop_names = "'" + string.Join("','", shopNameLst) + "'"; - } - var shop_notes = RegexUtils.GetStringQuery(ref inputData, "shop_notes"); - if (!string.IsNullOrWhiteSpace(shop_notes)) - { - List shopNotesLst = shop_notes.Split(',').ToList(); - shop_notes = "'" + string.Join("','", shopNotesLst) + "'"; - } - - var page = RegexUtils.GetStringQuery(ref inputData, "page").ParseToInt(); - var page_size = RegexUtils.GetStringQuery(ref inputData, "page_size").ParseToInt(); - - if (page_size == 0) - page_size = 50; - - string conn = System.Configuration.ConfigurationManager.ConnectionStrings["ConnKJD"].ConnectionString; - MysqlUtils mySql = new MysqlUtils(conn); - string sql; - bool isPayUser = false; - if (!isAdmin) - { - sql = "select u.authority,uu.authority as main_authority " + - "FROM wxxd.user u LEFT JOIN wxxd.user uu ON uu.user_name=u.parent_user_name where u.user_name='" - + user_name + "'"; - - var dtRow = mySql.ExecuteDataTableRow(sql); - if (!string.IsNullOrEmpty(mySql.Message)) - { - mySql.Close(); - return "{\"code\":501,\"msg\":\"" + mySql.Message + "\",\"data\":null}"; - } - if (dtRow == null) - { - mySql.Close(); - return "{\"code\":501,\"msg\":\"" + mySql.Message + "\",\"data\":null}"; - } - isPayUser = dtRow["authority"].ToString().Contains("充值用户") || dtRow["main_authority"].ToString().Contains("充值用户"); - } - - sql = "SELECT COUNT(*) FROM wxxd.shop s WHERE 1=1"; - - //where子句 - string where = ""; - if (isAdmin) - where += " and (s.cookie='' or s.shop_id!='')"; - if (!isAdmin) - where += " and (s.user_name='" + user_name + "' or s.sub_user_name like '%" + user_name + "%')"; - if (!string.IsNullOrWhiteSpace(operate_sub_sa_name)) - where += " and s.operate_sub_sa_name='" + operate_sub_sa_name + "'"; - if (!string.IsNullOrWhiteSpace(search_user_name)) - where += " and s.user_name like '%" + search_user_name + "%'"; - if (!string.IsNullOrWhiteSpace(search_login_name)) - where += " and s.login_name like '%" + search_login_name + "%'"; - if (!string.IsNullOrWhiteSpace(search_notes)) - where += " and s.notes like '%" + search_notes + "%'"; - if (!string.IsNullOrWhiteSpace(search_id)) - where += " and s.shop_id like '%" + search_id + "%'"; - if (!string.IsNullOrWhiteSpace(search_name)) - where += " and s.shop_account like '%" + search_name + "%'"; - if (!string.IsNullOrWhiteSpace(shop_ids)) - where += " and s.shop_id in (" + shop_ids + ")"; - if (!string.IsNullOrWhiteSpace(shop_names)) - where += " and s.shop_account in (" + shop_names + ")"; - if (!string.IsNullOrWhiteSpace(shop_notes)) - where += " and s.notes in (" + shop_notes + ")"; - sql += where; - - var count = mySql.ExecuteRowCount(sql); - - DataTable dt; - if (count == 0) - { - dt = new DataTable(); - } - else - { - sql = " SELECT s.*,se.expire_time‌ " + - " FROM wxxd.shop s" + - " LEFT JOIN wxxd.user_points_shop_expire se ON s.shop_id=se.shop_id" + - " WHERE 1=1"; - sql += where; // where 子句 - - sql += " ORDER BY s.id DESC"; - sql += " LIMIT " + Math.Max(page - 1, 0) * page_size + "," + page_size; - dt = mySql.ExecuteDataTable(sql); - } - - mySql.Close(); - if (!string.IsNullOrEmpty(mySql.Message)) - { - return "{\"code\":501,\"msg\":\"" + mySql.Message + "\",\"data\":null}"; - } - if (dt != null) - { - List shopList = new List(); - foreach (DataRow row in dt.Rows) - { - ShopParam shop = new ShopParam - { - id = Convert.ToInt32(row["id"]), - login_name = row["login_name"].ToString(), - login_pass = row["login_pass"].ToString(), - cookie = row["cookie"].ToString(), - cookie2 = row["cookie2"].ToString(), - anti_contents = row["anti_contents"].ToString(), - shop_id = row["shop_id"].ToString(), - shop_account = row["shop_account"].ToString(), - sub_user_name = row["sub_user_name"].ToString(), - user_name = row["user_name"].ToString(), - company_name = row["company_name"].ToString(), - notes = row["notes"].ToString(), - login_status = row["login_status"].ToString(), - login_status2 = row["login_status2"].ToString(), - add_product_remaining = row["add_product_remaining"].ParseToInt(), - add_product_month = row["add_product_month"].ParseToInt(), - operate_sub_sa_name = row["operate_sub_sa_name"].ParseToString(), - openid = row["openid"].ParseToString(), - group_name = row["group_name"].ParseToString(), - add_time = row["add_time"].IsNullOrEmpty() ? DateTime.MinValue : Convert.ToDateTime(row["add_time"]), - //mdy_time = row["mdy_time"].IsNullOrEmpty() ? DateTime.MinValue : Convert.ToDateTime(row["mdy_time"]), - expire_time = row["expire_time"].ParseToInt(), - }; - if (shop.shop_id == "wx2543ce37a0009883") - { - var exp = row["expire_time"].ParseToString(); - } - var expire_datetime = TimeUtils.StampToDateTime(shop.expire_time.Value); - if (isPayUser && expire_datetime < DateTime.Now) - shop.is_point_shop_expire = true; - - shopList.Add(shop); - } - - if (is_get_erp_shop_id == true) - { - conn = System.Configuration.ConfigurationManager.ConnectionStrings["ConnKJD"].ConnectionString; - mySql = new MysqlUtils(conn); - sql = " SELECT app_key,id,corporate_account_user_id,manage_user_id " + - " FROM erp.o_shop" + - " WHERE app_key in ('" + string.Join ("','", shopList.Select(s=>s.shop_id)) + "');"; - dt = mySql.ExecuteDataTable(sql); - - mySql.Close(); - if (!string.IsNullOrEmpty(mySql.Message)) - { - return "{\"code\":501,\"msg\":\"" + mySql.Message + "\",\"data\":null}"; - } - if (dt != null) - { - foreach (DataRow row in dt.Rows) - { - var erpDbId = row["id"].ParseToNullableLong(); - var erpCorporateUserId = row["corporate_account_user_id"].ParseToNullableLong(); - var erpManageUserId = row["manage_user_id"].ParseToNullableLong(); - var appKey = row["app_key"].ParseToString(); - var shop = shopList.FirstOrDefault(s => s.shop_id == appKey && !s.shop_id.IsNullOrEmpty()); - if (shop != null) - { - shop.erp_corporate_account_user_id = erpCorporateUserId; - shop.erp_manage_user_id = erpManageUserId; - shop.erp_shop_id = erpDbId; - } - } - } - } - - var data = JsonUtils.SerializeObjectToString(shopList); - var seconds = (DateTime.Now - timeCalc).TotalSeconds.ToString("0.000"); - - return "{\"code\":200,\"msg\":\"success\",\"data\":" + data + ",\"count\":" + count + ",\"seconds\":" + seconds + "}"; - } - } - return "{\"code\":19999,\"msg\":\"未知错误\"}"; - } - - /// - /// 获取erp店铺对应账户的余额 - /// - /// - /// - /// - public string GetShopErpMerchant(string inputData, bool isAdmin = false) - { - if (!string.IsNullOrEmpty(inputData)) - { - var timeCalc = DateTime.Now; - if (!WXUserManage.GetSign(inputData)) - return "{\"code\":999,\"msg\":\"校验失败\"}"; - - var corporate_account_user_id = RegexUtils.GetStringQuery(ref inputData, "corporate_account_user_id")?.Replace("'", "\\'"); - var manage_user_id = RegexUtils.GetStringQuery(ref inputData, "manage_user_id")?.Replace("'", "\\'"); - var shop_id = RegexUtils.GetStringQuery(ref inputData, "shop_id")?.Replace("'", "\\'"); - if (corporate_account_user_id.IsNullOrEmpty() && manage_user_id.IsNullOrEmpty()) - return "{\"code\":500,\"msg\":\"未指定商户\"}"; - - var page = RegexUtils.GetStringQuery(ref inputData, "page").ParseToInt(); - var page_size = RegexUtils.GetStringQuery(ref inputData, "page_size").ParseToInt(); - - if (page_size == 0) - page_size = 200; - - var manage_user_ids = new List(); - if (!manage_user_id.IsNullOrEmpty()) - manage_user_ids.Add(manage_user_id); - - string conn = System.Configuration.ConfigurationManager.ConnectionStrings["ConnKJD"].ConnectionString; - MysqlUtils mySql = new MysqlUtils(conn); - string sql; - - if (!string.IsNullOrEmpty(corporate_account_user_id)) - { - sql = "SELECT manage_user_id FROM erp.o_shop_group WHERE corporate_account_user_id = '" + corporate_account_user_id + "';"; - var manage_user_id_tb = mySql.ExecuteDataTable(sql); - if (!string.IsNullOrEmpty(mySql.Message)) - { - mySql.Close(); - return "{\"code\":501,\"msg\":\"" + mySql.Message + "\",\"data\":null}"; - } - if (manage_user_id_tb == null) - { - mySql.Close(); - var seconds = (DateTime.Now - timeCalc).TotalSeconds.ToString("0.000"); - return "{\"code\":200,\"msg\":\"success\",\"data\":[],\"count\":-2,\"seconds\":" + seconds + "}"; - } - manage_user_ids.AddRange(manage_user_id_tb.Rows.Cast().Select(t => t["manage_user_id"].ToString())); - if (manage_user_ids.Count == 0) - { - mySql.Close(); - var seconds = (DateTime.Now - timeCalc).TotalSeconds.ToString("0.000"); - return "{\"code\":200,\"msg\":\"success\",\"data\":[],\"count\":-2,\"seconds\":" + seconds + "}"; - } - } - - sql = "select * FROM erp.o_user_account u where u.user_id in ('" + string.Join("','", manage_user_ids) + "')"; - 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\":501,\"msg\":\"" + mySql.Message + "\",\"data\":null}"; - } - if (dt != null) - { - List erpAccountInfo = new List(); - foreach (DataRow row in dt.Rows) - { - ErpMerchantInfo shop = new ErpMerchantInfo - { - id = Convert.ToInt32(row["id"]), - account_name = row["account_name"].ToString(), - account_status = row["account_status"].ParseToInt(), - account_type = row["account_type"].ParseToInt(), - balance = row["balance"].ParseToDecimal(), - create_by = row["create_by"].ParseToNullableLong(), - create_time = row["create_time"].ParseToString().ParseToDateTime(), - frozen_amount = row["frozen_amount"].ParseToDecimal(), - recharge_amount_total = row["recharge_amount_total"].ParseToDecimal(), - update_by = row["update_by"].ParseToNullableLong(), - update_time = row["update_time"].ParseToString().ParseToDateTime(), - user_id = row["user_id"].ParseToLong(), - withdrawn_amount = row["withdrawn_amount"].ParseToDecimal(), - withdraw_account_image_url = row["withdraw_account_image_url"].ParseToString(), - }; - erpAccountInfo.Add(shop); - } - erpAccountInfo = erpAccountInfo.OrderByDescending(s => s.balance).ToList(); - var count = -1; - var data = JsonUtils.SerializeObjectToString(erpAccountInfo); - 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 SubSaGetSelectProdShop(string inputData) - { - if (!string.IsNullOrEmpty(inputData)) - { - var user_name = RegexUtils.GetStringQuery(ref inputData, "user_name"); - var password = RegexUtils.GetStringQuery(ref inputData, "password"); - var search_id = RegexUtils.GetStringQuery(ref inputData, "search_id"); - var search_user_name = RegexUtils.GetStringQuery(ref inputData, "search_user_name"); - var search_login_name = RegexUtils.GetStringQuery(ref inputData, "search_login_name"); - var search_notes = RegexUtils.GetStringQuery(ref inputData, "search_notes"); - var search_name = RegexUtils.GetStringQuery(ref inputData, "search_name"); - var operate_sub_sa_name = RegexUtils.GetStringQuery(ref inputData, "operate_sub_sa_name")?.Replace("'", "\\'"); - var shop_ids = RegexUtils.GetStringQuery(ref inputData, "shop_ids")?.Replace("'", ""); - if (!string.IsNullOrWhiteSpace(shop_ids)) - { - List shopIdLst = shop_ids.Split(',').ToList(); - shop_ids = "'" + string.Join("','", shopIdLst) + "'"; - } - var shop_names = RegexUtils.GetStringQuery(ref inputData, "shop_names"); - if (!string.IsNullOrWhiteSpace(shop_names)) - { - List shopNameLst = shop_names.Split(',').ToList(); - shop_names = "'" + string.Join("','", shopNameLst) + "'"; - } - var shop_notes = RegexUtils.GetStringQuery(ref inputData, "shop_notes"); - if (!string.IsNullOrWhiteSpace(shop_notes)) - { - List shopNotesLst = shop_notes.Split(',').ToList(); - shop_notes = "'" + string.Join("','", shopNotesLst) + "'"; - } - - var page = RegexUtils.GetStringQuery(ref inputData, "page").ParseToInt(); - var page_size = RegexUtils.GetStringQuery(ref inputData, "page_size").ParseToInt(); - - if (page_size == 0) - page_size = 50; - 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 COUNT(s.id) FROM wxxd.shop s WHERE 1=1"; - - //where子句 - string where = ""; - if (!string.IsNullOrWhiteSpace(operate_sub_sa_name)) - where += " and (s.shop_id in (SELECT DISTINCT shop_id From wxxd.product_select WHERE operate_sub_sa_name='" + operate_sub_sa_name + "') or " + - "s.shop_id in (SELECT DISTINCT shop_id From wxxd.third_product_select WHERE operate_sub_sa_name='" + operate_sub_sa_name + "'))"; - where += " and (s.cookie='' or s.shop_id!='')"; - //if (!string.IsNullOrWhiteSpace(operate_sub_sa_name)) - // where += " and s.operate_sub_sa_name='" + operate_sub_sa_name + "'"; - if (!string.IsNullOrWhiteSpace(search_user_name)) - where += " and s.user_name like '%" + search_user_name + "%'"; - if (!string.IsNullOrWhiteSpace(search_login_name)) - where += " and s.login_name like '%" + search_login_name + "%'"; - if (!string.IsNullOrWhiteSpace(search_notes)) - where += " and s.notes like '%" + search_notes + "%'"; - if (!string.IsNullOrWhiteSpace(search_id)) - where += " and s.shop_id like '%" + search_id + "%'"; - if (!string.IsNullOrWhiteSpace(search_name)) - where += " and s.shop_account like '%" + search_name + "%'"; - if (!string.IsNullOrWhiteSpace(shop_ids)) - where += " and s.shop_id in (" + shop_ids + ")"; - if (!string.IsNullOrWhiteSpace(shop_names)) - where += " and s.shop_account in (" + shop_names + ")"; - if (!string.IsNullOrWhiteSpace(shop_notes)) - where += " and s.notes in (" + shop_notes + ")"; - sql += where; - - var count = mySql.ExecuteRowCount(sql); - - DataTable dt; - if (count == 0) - { - dt = new DataTable(); - } - else - { - sql = "SELECT s.id,s.login_name,s.login_pass,s.cookie,s.cookie2,s.anti_contents,s.shop_id,s.openid,s.shop_account,s.sub_user_name,s.user_name," + - "s.company_name,s.notes,s.group_name,s.login_status,s.login_status2,c.add_product_remaining,c.add_product_month,s.add_time,s.mdy_time," + - "s.add_sub_sa_time,s.operate_sub_sa_name"; - sql += " FROM wxxd.shop s LEFT JOIN wxxd.shop_add_prod_count c ON s.shop_id=c.shop_id WHERE 1=1"; - - sql += where; // where 子句 - - sql += " ORDER BY s.id DESC"; - sql += " LIMIT " + Math.Max(page - 1, 0) * page_size + "," + page_size; - dt = mySql.ExecuteDataTable(sql); - } - - mySql.Close(); - if (dt != null) - { - List shopList = new List(); - foreach (DataRow row in dt.Rows) - { - ShopParam shop = new ShopParam - { - id = Convert.ToInt32(row["id"]), - login_name = row["login_name"].ToString(), - login_pass = row["login_pass"].ToString(), - cookie = row["cookie"].ToString(), - cookie2 = row["cookie2"].ToString(), - anti_contents = row["anti_contents"].ToString(), - shop_id = row["shop_id"].ToString(), - shop_account = row["shop_account"].ToString(), - sub_user_name = row["sub_user_name"].ToString(), - user_name = row["user_name"].ToString(), - company_name = row["company_name"].ToString(), - notes = row["notes"].ToString(), - login_status = row["login_status"].ToString(), - login_status2 = row["login_status2"].ToString(), - add_product_remaining = row["add_product_remaining"].ParseToInt(), - add_product_month = row["add_product_month"].ParseToInt(), - operate_sub_sa_name = row["operate_sub_sa_name"].ParseToString(), - openid = row["openid"].ToString(), - group_name = row["group_name"].ToString(), - }; - shopList.Add(shop); - } - - //sql = "\r\nINSERT INTO wxxd.shop_add_prod_count(shop_id,shop_account,add_product_remaining,add_product_month) VALUES "; - //foreach (var shop in shopList) - //{ - // sql += "\r\n('" + shop.shop_id + "','" + shop.shop_account + "'," + shop.add_product_remaining + "," + shop.add_product_month + "),"; - //} - //sql = sql.TrimEnd(',') + " \r\n"; - //sql += "ON DUPLICATE KEY UPDATE " + - // "shop_account=VALUES(shop_account)," + - // "add_product_remaining=VALUES(add_product_remaining)," + - // "add_product_month=VALUES(add_product_month);"; - //var result = mySql.ExecuteNonQuery(sql); - //mySql.Close(); - - int month = DateTime.Now.Month; - var shopMonthList = shopList.Where(s => s.add_product_month != month); - if (shopMonthList.Count() > 0) - { - int remainCount = 300; - var shopMonthIdList = shopMonthList.Select(s => s.id); - mySql = new MysqlUtils(conn); - string ids = string.Join(",", shopMonthIdList); - sql = ""; - sql += "update wxxd.shop set add_product_remaining=" + remainCount + ", add_product_month=" + month + - " where 1=1 and id in (" + ids + ");"; - - sql += "\r\nINSERT INTO wxxd.shop_add_prod_count(shop_id,shop_account,add_product_remaining,add_product_month) VALUES "; - foreach (var shop in shopMonthList) - { - sql += "\r\n('" + shop.shop_id + "','" + shop.shop_account + "'," + remainCount + "," + month + "),"; - } - sql = sql.TrimEnd(',') + " \r\n"; - sql += "ON DUPLICATE KEY UPDATE " + - "shop_account=VALUES(shop_account)," + - "add_product_remaining=VALUES(add_product_remaining)," + - "add_product_month=VALUES(add_product_month);"; - var rst = mySql.ExecuteNonQuery(sql); - mySql.Close(); - - if (rst) - { - foreach (var shop in shopMonthList) - { - shop.add_product_month = month; - shop.add_product_remaining = remainCount; - } - } - } - var data = JsonUtils.SerializeObjectToString(shopList); - - - //return "{\"code\":200,\"msg\":\"success\",\"data\":" + data + ",\"c\":\"" + EncrypUtil.Encryption(r2) + "\"}"; - return "{\"code\":200,\"msg\":\"success\",\"data\":" + data + ",\"count\":" + count + "}"; - } - } - return "{\"code\":19999,\"msg\":\"未知错误\"}"; - } - - - - public string UpdateAddProdRemaining(string inputData) - { - if (!string.IsNullOrEmpty(inputData)) - { - var time = RegexUtils.GetStringQuery(ref inputData, "time").ParseToInt(); - string time1 = RegexUtils.GetStringQuery(ref inputData, "code"); - if (time1 != EncrypUtil.Encryption(time)) - return "{\"code\":50000,\"msg\":\"校验失败\"}"; - - var user_name = RegexUtils.GetStringQuery(ref inputData, "user_name"); - var password = RegexUtils.GetStringQuery(ref inputData, "password"); - var remainCount = RegexUtils.GetStringQuery(ref inputData, "remain_count"); - var shop_ids = RegexUtils.GetStringQuery(ref inputData, "shop_ids")?.Replace("'", ""); - if (!string.IsNullOrWhiteSpace(shop_ids)) - { - List shopIdLst = shop_ids.Split(',').ToList(); - shop_ids = "'" + string.Join("','", shopIdLst) + "'"; - } - - string conn = System.Configuration.ConfigurationManager.ConnectionStrings["ConnKJD"].ConnectionString; - MysqlUtils mySql = new MysqlUtils(conn); - string sql = ""; - sql += "update wxxd.shop_add_prod_count set add_product_remaining=" + remainCount + - " where 1=1 and shop_id in (" + shop_ids + ");"; - - var rst = mySql.ExecuteNonQuery(sql); - var msg = mySql.Message; - mySql.Close(); - - if (rst) - return "{\"code\":200,\"msg\":\"success\"}"; - else - return "{\"code\":50000,\"msg\":\"" + msg + "\"}"; - } - else - { - return "{\"code\":19999,\"msg\":\"输入为空\"}"; - } - } - - //获取一个手机登录号码下的所有店铺(以便有则更新,无则新增) - public string GetOneLoginNameShop(string inputData) - { - if (!string.IsNullOrEmpty(inputData)) - { - var user_name = RegexUtils.GetStringQuery(ref inputData, "user_name"); - var login_name = RegexUtils.GetStringQuery(ref inputData, "login_name"); - var password = RegexUtils.GetStringQuery(ref inputData, "password"); - 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 id,login_name,login_pass,cookie,cookie2,anti_contents,shop_id,openid,shop_account,sub_user_name,user_name from wxxd.shop where user_name='" - + user_name + "' and login_name='" + login_name + "'"; - - var dt = mySql.ExecuteDataTable(sql); - mySql.Close(); - if (dt != null) - { - List shopList = new List(); - foreach (DataRow row in dt.Rows) - { - ShopParam shop = new ShopParam - { - id = Convert.ToInt32(row["id"]), - login_name = row["login_name"].ToString(), - login_pass = row["login_pass"].ToString(), - cookie = row["cookie"].ToString(), - cookie2 = row["cookie2"].ToString(), - anti_contents = row["anti_contents"].ToString(), - shop_id = row["shop_id"].ToString(), - shop_account = row["shop_account"].ToString(), - sub_user_name = row["sub_user_name"].ToString(), - user_name = row["user_name"].ToString(), - company_name = row["company_name"].ToString(), - notes = row["notes"].ToString(), - login_status = row["login_status"].ToString(), - openid = row["openid"].ToString(), - }; - shopList.Add(shop); - } - var data = JsonUtils.SerializeObjectToString(shopList); - return "{\"code\":200,\"msg\":\"success\",\"data\":" + data + ",\"c\":\"" + EncrypUtil.Encryption(r2) + "\"}"; - } - } - return "{\"code\":19999,\"msg\":\"未知错误\"}"; - } - - //获取一个手机登录号码下特定ID的店铺 - public string GetOneIdShop(string inputData) - { - if (!string.IsNullOrEmpty(inputData)) - { - var user_name = RegexUtils.GetStringQuery(ref inputData, "user_name"); - var login_name = RegexUtils.GetStringQuery(ref inputData, "login_name"); - var shop_id = RegexUtils.GetStringQuery(ref inputData, "shop_id"); - var password = RegexUtils.GetStringQuery(ref inputData, "password"); - 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 id,login_name,login_pass,cookie,cookie2,anti_contents,shop_id,openid,shop_account,sub_user_name,user_name from wxxd.shop where user_name='" - + user_name + "' and login_name='" + login_name + "' and shop_id='" + shop_id + "'"; - - var dt = mySql.ExecuteDataTable(sql); - mySql.Close(); - if (dt != null) - { - List shopList = new List(); - foreach (DataRow row in dt.Rows) - { - ShopParam shop = new ShopParam - { - id = Convert.ToInt32(row["id"]), - login_name = row["login_name"].ToString(), - login_pass = row["login_pass"].ToString(), - cookie = row["cookie"].ToString(), - cookie2 = row["cookie2"].ToString(), - anti_contents = row["anti_contents"].ToString(), - shop_id = row["shop_id"].ToString(), - shop_account = row["shop_account"].ToString(), - sub_user_name = row["sub_user_name"].ToString(), - user_name = row["user_name"].ToString(), - company_name = row["company_name"].ToString(), - notes = row["notes"].ToString(), - login_status = row["login_status"].ToString(), - openid = row["openid"].ToString(), - }; - shopList.Add(shop); - } - var data = JsonUtils.SerializeObjectToString(shopList); - return "{\"code\":200,\"msg\":\"success\",\"data\":" + data + ",\"c\":\"" + EncrypUtil.Encryption(r2) + "\"}"; - } - } - return "{\"code\":19999,\"msg\":\"未知错误\"}"; - } - - /// - /// ai api - /// - /// - /// - public string GetOneShopCookieByAppId(string inputData) - { - if (!string.IsNullOrEmpty(inputData)) - { - var shop_id = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "shop_id"))?.Replace("'", "\\'"); - if (shop_id.IsNullOrEmpty()) - return "{\"code\":500,\"msg\":\"未指定店铺\"}"; - var sign = RegexUtils.GetStringQuery(ref inputData, "sign"); - if (!GetTimeSign(sign)) - return "{\"code\":500,\"msg\":\"校验失败\"}"; - - string conn = System.Configuration.ConfigurationManager.ConnectionStrings["ConnKJD"].ConnectionString; - MysqlUtils mySql = new MysqlUtils(conn); - string sql = "select shop_id,cookie from wxxd.shop where shop_id in ('" + shop_id.Replace(",", "','") + "');"; - - var dt = mySql.ExecuteDataTable(sql); - mySql.Close(); - if (dt != null) - { - JArray jArr = new JArray(); - foreach (DataRow row in dt.Rows) - { - if (!jArr.Any(o => o["shop_id"].ParseToString() == row["shop_id"].ToString())) - { - JObject jObj = new JObject(); - jObj["shop_id"] = row["shop_id"].ToString(); - jObj["cookies"] = row["cookie"].ToString(); - jArr.Add(jObj); - } - } - return "{\"code\":200,\"msg\":\"success\",\"data\":" + JsonUtils.SerializeObject(jArr) + "}"; - } - } - return "{\"code\":19999,\"msg\":\"未知错误\"}"; - } - - public string AddShop(string inputData, bool isAdmin=false) - { - if (!string.IsNullOrEmpty(inputData)) - { - string user_name = RegexUtils.GetStringQuery(ref inputData, "user_name"); - if (isAdmin) - user_name = RegexUtils.GetStringQuery(ref inputData, "shop_user_name"); - string login_name = RegexUtils.GetStringQuery(ref inputData, "login_name"); - string login_pass = RegexUtils.GetStringQuery(ref inputData, "login_pass"); - string sub_user_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "sub_user_name")); - string cookie = RegexUtils.GetStringQuery(ref inputData, "cookie"); - string cookie2 = RegexUtils.GetStringQuery(ref inputData, "cookie2"); - string anti_contents = RegexUtils.GetStringQuery(ref inputData, "anti_contents"); - string shop_id = RegexUtils.GetStringQuery(ref inputData, "shop_id"); - string shop_account = RegexUtils.GetStringQuery(ref inputData, "shop_account"); - string group_name = RegexUtils.GetStringQuery(ref inputData, "group_name"); - string notes = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "notes")); - int r2 = 0; - int.TryParse(RegexUtils.GetStringQuery(ref inputData, "r2"), out r2); - - if (string.IsNullOrEmpty(user_name)) - { - return "{\"code\":500,\"msg\":\"没有用户名\"}"; - } - if (string.IsNullOrEmpty(login_name)) - { - return "{\"code\":501,\"msg\":\"没有店铺登录名\"}"; - } - - string conn = System.Configuration.ConfigurationManager.ConnectionStrings["ConnKJD"].ConnectionString; - MysqlUtils mySql = new MysqlUtils(conn); - string sql = ""; - if (string.IsNullOrEmpty(shop_id)) - sql = "select exists (select 1 from wxxd.shop where login_name='" + login_name + "' and user_name='" + user_name + "')"; - else - sql = "select exists (select 1 from wxxd.shop where login_name='" + login_name + "' and user_name='" + user_name + - "' and shop_id='" + shop_id + "')"; - var exist = mySql.ExecuteFirstInt(sql); - if (exist>0) - { - mySql.Close(); - return "{\"code\":500,\"msg\":\"店铺" + login_name +" " + shop_account + "已存在\"}"; - } - - sql = "insert into wxxd.shop (login_name,login_pass,cookie,cookie2,anti_contents,shop_account,shop_id,sub_user_name,user_name,group_name,notes,add_time,mdy_time) " + - "values ('" + login_name + "','" + login_pass + "','" + cookie + "','" + cookie2 + "','" + anti_contents + "','" + shop_account + "','" + shop_id + "','" + - sub_user_name + "','" + user_name + "','" + group_name + "','" + notes + "','" + - 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\":200,\"msg\":\"success\"}"; - } - } - return "{\"code\":19999,\"msg\":\"未知错误\"}"; - } - - public string MdyShop(string inputData, bool isAdmin=false) - { - if (!string.IsNullOrEmpty(inputData)) - { - string user_name = RegexUtils.GetStringQuery(ref inputData, "user_name"); - if (isAdmin) - user_name = RegexUtils.GetStringQuery(ref inputData, "shop_user_name"); - string login_name = RegexUtils.GetStringQuery(ref inputData, "login_name"); - string login_pass = RegexUtils.GetStringQuery(ref inputData, "login_pass"); - string sub_user_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "sub_user_name")); - string cookie = RegexUtils.GetStringQuery(ref inputData, "cookie"); - string cookie2 = RegexUtils.GetStringQuery(ref inputData, "cookie2"); - string anti_contents = RegexUtils.GetStringQuery(ref inputData, "anti_contents"); - string new_shop_id = RegexUtils.GetStringQuery(ref inputData, "new_shop_id"); - string old_shop_id = RegexUtils.GetStringQuery(ref inputData, "shop_id"); - string shop_account = RegexUtils.GetStringQuery(ref inputData, "shop_account"); - string group_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "group_name")); - string notes = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "notes")); - string login_status = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "login_status")); - - int r2 = 0; - int.TryParse(RegexUtils.GetStringQuery(ref inputData, "r2"), out r2); - - if (string.IsNullOrEmpty(user_name)) - { - return "{\"code\":500,\"msg\":\"没有用户名\"}"; - } - if (string.IsNullOrEmpty(login_name)) - { - return "{\"code\":501,\"msg\":\"没有店铺登录名\"}"; - } - - string conn = System.Configuration.ConfigurationManager.ConnectionStrings["ConnKJD"].ConnectionString; - MysqlUtils mySql = new MysqlUtils(conn); - string sql = "update wxxd.shop set"; - if (login_pass != null) - sql += " login_pass='" + login_pass + "',"; - if (cookie != null) - sql += " cookie='" + cookie + "',"; - if (cookie2 != null) - sql += " cookie2='" + cookie2 + "',"; - if (anti_contents != null) - sql += " anti_contents='" + anti_contents + "',"; - if (new_shop_id != null) - sql += " shop_id='" + new_shop_id + "',"; - if (shop_account != null) - sql += " shop_account='" + shop_account + "',"; - if (sub_user_name != null) - sql += " sub_user_name='" + sub_user_name + "',"; - if (group_name != null) - sql += " group_name='" + group_name + "',"; - if (notes != null) - sql += " notes='" + notes + "',"; - if (login_status != null) - sql += " login_status='" + login_status + "',"; - sql = sql.TrimEnd(','); - sql += " where login_name='" + login_name + "' and (user_name='" + user_name + "' or sub_user_name like '%" + user_name + "%')"; - if (!string.IsNullOrEmpty(old_shop_id)) - sql += " and shop_id='" + old_shop_id + "'"; - - var rst = mySql.ExecuteNonQuery(sql); - mySql.Close(); - if (rst) - { - return "{\"code\":200,\"msg\":\"success\"}"; - } - } - return "{\"code\":19999,\"msg\":\"未知错误\"}"; - } - - public string MdyCookieAndLoginStatus(string inputData) - { - if (!string.IsNullOrEmpty(inputData)) - { - string login_name = RegexUtils.GetStringQuery(ref inputData, "login_name"); - string cookie = RegexUtils.GetStringQuery(ref inputData, "cookie"); - string cookie2 = RegexUtils.GetStringQuery(ref inputData, "cookie2"); - string login_status = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "login_status")); - string login_status2 = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "login_status2")); - string openid = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "openid")); - - int r2 = 0; - int.TryParse(RegexUtils.GetStringQuery(ref inputData, "r2"), out r2); - - if (string.IsNullOrEmpty(login_name)) - { - return "{\"code\":500,\"msg\":\"店铺没有登录名\"}"; - } - - string conn = System.Configuration.ConfigurationManager.ConnectionStrings["ConnKJD"].ConnectionString; - MysqlUtils mySql = new MysqlUtils(conn); - string sql = "update wxxd.shop set"; - if (cookie != null) - sql += " cookie='" + cookie + "',"; - if (cookie2 != null) - sql += " cookie2='" + cookie2 + "',"; - if (login_status != null) - sql += " login_status='" + login_status + "',"; - if (login_status2 != null) - sql += " login_status2='" + login_status2 + "',"; - if (openid != null) - sql += " openid='" + openid + "',"; - sql = sql.TrimEnd(','); - sql += " where login_name='" + login_name + "'"; - - var rst = mySql.ExecuteNonQuery(sql); - mySql.Close(); - if (rst) - { - return "{\"code\":200,\"msg\":\"success\"}"; - } - } - return "{\"code\":19999,\"msg\":\"未知错误\"}"; - } - - - public string DelShop(string inputData, bool isAdmin=false) - { - if (!string.IsNullOrEmpty(inputData)) - { - var login_name = RegexUtils.GetStringQuery(ref inputData, "login_name"); - var user_name = RegexUtils.GetStringQuery(ref inputData, "user_name"); - if (isAdmin) - user_name = RegexUtils.GetStringQuery(ref inputData, "shop_user_name"); - var shop_id = RegexUtils.GetStringQuery(ref inputData, "shop_id"); - var password = RegexUtils.GetStringQuery(ref inputData, "password"); - int r2 = 0; - int.TryParse(RegexUtils.GetStringQuery(ref inputData, "r2"), out r2); - - if (string.IsNullOrEmpty(user_name)) - { - return "{\"code\":500,\"msg\":\"没有用户名\"}"; - } - if (string.IsNullOrEmpty(login_name)) - { - return "{\"code\":501,\"msg\":\"没有店铺登录名\"}"; - } - - string conn = System.Configuration.ConfigurationManager.ConnectionStrings["ConnKJD"].ConnectionString; - MysqlUtils mySql = new MysqlUtils(conn); - string sql = "delete from wxxd.shop where user_name='" + user_name + "' and login_name='" + login_name + "'"; - if (!string.IsNullOrEmpty(shop_id)) - sql += " and shop_id='" + shop_id + "'"; - - var rst = mySql.ExecuteNonQuery(sql); - mySql.Close(); - if (rst) - { - return "{\"code\":200,\"msg\":\"success\"}"; - } - } - return "{\"code\":19999,\"msg\":\"未知错误\"}"; - } - - /// - /// 设置店铺的二级超管 - /// - /// - public string SetShopSubSa(string inputData) - { - if (!string.IsNullOrEmpty(inputData)) - { - var time = RegexUtils.GetStringQuery(ref inputData, "time").ParseToInt(); - string time1 = RegexUtils.GetStringQuery(ref inputData, "code"); - if (time1 != EncrypUtil.Encryption(time)) - return "{\"code\":50000,\"msg\":\"校验失败\"}"; - - var user_name = RegexUtils.GetStringQuery(ref inputData, "user_name")?.Replace("'", "\\'"); - if (string.IsNullOrEmpty(user_name)) - { - return "{\"code\":50001,\"msg\":\"没有用户名\"}"; - } - - var id = RegexUtils.GetStringQuery(ref inputData, "db_id")?.Replace("'", "\\'"); - var login_name = RegexUtils.GetStringQuery(ref inputData, "shop_login_name")?.Replace("'", "\\'"); - var operate_sub_sa_name = RegexUtils.GetStringQuery(ref inputData, "operate_sub_sa_name")?.Replace("'", "\\'"); - - if (string.IsNullOrEmpty(id) && string.IsNullOrEmpty(login_name)) - { - return "{\"code\":50002,\"msg\":\"未选择任何待上传\"}"; - } - - string conn = System.Configuration.ConfigurationManager.ConnectionStrings["ConnKJD"].ConnectionString; - MysqlUtils mySql = new MysqlUtils(conn); - string sql = "update wxxd.shop set"; - if (operate_sub_sa_name != null) - sql += " operate_sub_sa_name='" + operate_sub_sa_name + "',"; - sql += " add_sub_sa_time='" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "',"; - sql = sql.TrimEnd(','); - if (!string.IsNullOrEmpty(id)) - sql += " where id in (" + id + ")"; - else if (!string.IsNullOrEmpty(login_name)) - sql += " where login_name in ('" + login_name.Replace(",", "','") + "')"; - else - sql += " where 1=2"; - var rst = mySql.ExecuteNonQuery(sql); - mySql.Close(); - if (rst) - { - return "{\"code\":200,\"msg\":\"success\"}"; - } - else - { - return "{\"code\":500,\"msg\":\"" + mySql.Message + "\"}"; - } - } - return "{\"code\":19999,\"msg\":\"输入为空\"}"; - } - - public string WXAddMdyShopDefaultAddress(string inputData) - { - if (!string.IsNullOrEmpty(inputData)) - { - if (!WXUserManage.GetSign(inputData)) - return "{\"code\":999,\"msg\":\"校验失败\"}"; - - // 软件用户名 - string user_id = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "user_name"))?.Replace("'", "\\'"); - string shop_id = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "shop_id"))?.Replace("'", "\\'"); - string province_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "province_name"))?.Replace("'", "\\'"); - string city_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "city_name"))?.Replace("'", "\\'"); - string county_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "county_name"))?.Replace("'", "\\'"); - string detail_info = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "detail_info"))?.Replace("'", "\\'"); - string tel_number = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "tel_number"))?.Replace("'", "\\'"); - // 收件人 - string user_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "receiver"))?.Replace("'", "\\'"); - if (string.IsNullOrEmpty(user_id)) - return "{\"code\":500,\"msg\":\"缺少用户编号\"}"; - if (string.IsNullOrEmpty(shop_id)) - return "{\"code\":500,\"msg\":\"缺少店铺编号\"}"; - if (string.IsNullOrEmpty(province_name) || string.IsNullOrEmpty(city_name) || string.IsNullOrEmpty(county_name) || string.IsNullOrEmpty(detail_info)) - return "{\"code\":500,\"msg\":\"省市区或详细地址不完整\"}"; - if (string.IsNullOrEmpty(user_name)) - return "{\"code\":500,\"msg\":\"缺少收件人\"}"; - if (string.IsNullOrEmpty(tel_number)) - return "{\"code\":500,\"msg\":\"缺少收件人电话\"}"; - - string conn = System.Configuration.ConfigurationManager.ConnectionStrings["ConnKJD"].ConnectionString; - MysqlUtils mySql = new MysqlUtils(conn); - - string sql = "SELECT 1 FROM `wxxd`.`wx_shop_default_address` where user_id='" + user_id + "' AND shop_id='" + shop_id + "'"; - string where = ""; - sql += where; - var exist = mySql.ExecuteFirstInt(sql); - if (!mySql.Message.IsNullOrEmpty()) - { - mySql.Close(); - return "{\"code\":501,\"msg\":\"" + mySql.Message + "\"}"; - } - - if (exist == 0) - { - sql = " INSERT INTO `wxxd`.`wx_shop_default_address` (user_id,shop_id,province_name,city_name,county_name,detail_info,tel_number,user_name)" + - " VALUES (@user_id,@shop_id,@province_name,@city_name,@county_name,@detail_info,@tel_number,@user_name);"; - } - else - { - sql = "UPDATE `wxxd`.`wx_shop_default_address` SET "; - if (province_name != null) - sql += " province_name=@province_name,"; - if (city_name != null) - sql += " city_name=@city_name,"; - if (county_name != null) - sql += " county_name=@county_name,"; - if (detail_info != null) - sql += " detail_info=@detail_info,"; - if (tel_number != null) - sql += " tel_number=@tel_number,"; - if (user_name != null) - sql += " user_name=@user_name,"; - sql = sql.TrimEnd(','); - sql += " WHERE user_id=@user_id and shop_id=@shop_id;"; - } - - List paramLst = new List(); - paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "province_name", Value = province_name, }); - paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "city_name", Value = city_name, }); - paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "county_name", Value = county_name, }); - paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "detail_info", Value = detail_info, }); - paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "tel_number", Value = tel_number, }); - paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "user_name", Value = user_name, }); - paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "user_id", Value = user_id, }); - paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "shop_id", Value = shop_id, }); - mySql.ExecuteNonQuery(sql, paramLst.ToArray()); - mySql.Close(); - if (string.IsNullOrEmpty(mySql.Message)) - { - return "{\"code\":200,\"msg\":\"success\",\"data\":\"\"}"; - } - else - { - return "{\"code\":50003,\"msg\":\"" + mySql.Message + "\",\"data\":\"\"}"; - } - } - return "{\"code\":19999,\"msg\":\"输入为空\"}"; - } - - public string WXGetShopDefaultAddressList(string inputData) - { - if (!string.IsNullOrEmpty(inputData)) - { - var timeCalc = DateTime.Now; - if (!WXUserManage.GetSign(inputData)) - return "{\"code\":999,\"msg\":\"校验失败\"}"; - - int page = RegexUtils.GetStringQuery(ref inputData, "page").ParseToInt(); - int page_size = RegexUtils.GetStringQuery(ref inputData, "page_size").ParseToInt(200); - string user_id = RegexUtils.GetStringQuery(ref inputData, "user_name")?.Replace("'", "\\'"); - string shop_ids = RegexUtils.GetStringQuery(ref inputData, "shop_ids")?.Replace("'", "\\'"); - string not_count = RegexUtils.GetStringQuery(ref inputData, "not_count")?.Replace("'", "\\'"); - - string conn = System.Configuration.ConfigurationManager.ConnectionStrings["ConnKJD"].ConnectionString; - MysqlUtils mySql = new MysqlUtils(conn); - - string sql = ""; - var count = -1; - - sql = "SELECT count(*) FROM `wxxd`.`wx_shop_default_address` where 1=1"; - string where = ""; - if (user_id != null) - where += " and user_id='" + user_id + "'"; - if (shop_ids != null) - where += " and shop_id IN ('" + shop_ids.Replace(",", "','") + "')"; - sql += where; - sql += ";"; - - if (not_count != "true") - count = mySql.ExecuteRowCount(sql); - - DataTable dt; - if (count == 0) - { - dt = new DataTable(); - } - else - { - sql = "SELECT * FROM `wxxd`.`wx_shop_default_address` where 1=1"; - sql += where; - sql += " order by id desc limit " + Math.Max(0, page - 1) * page_size + "," + page_size + ";"; - dt = mySql.ExecuteDataTable(sql); - } - mySql.Close(); - - if (dt != null) - { - try - { - List WXShopDefaultAddressInfoLst = new List(); - foreach (DataRow row in dt.Rows) - { - WXShopDefaultAddressInfoLst.Add(new WXShopDefaultAddressInfo() - { - id = row["id"].ParseToInt(), - city_name = row["city_name"].ParseToString(), - county_name = row["county_name"].ParseToString(), - detail_info = row["detail_info"].ParseToString(), - province_name = row["province_name"].ParseToString(), - shop_id = row["shop_id"].ParseToString(), - tel_number = row["tel_number"].ParseToString(), - user_id = row["user_id"].ParseToString(), - user_name = row["user_name"].ParseToString(), - add_time = Convert.ToDateTime(row["add_time"]), - mdy_time = Convert.ToDateTime(row["mdy_time"]), - }); - } - JsonSerializerSettings jsonSetting = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }; - var data = JsonUtils.SerializeObjectToString(WXShopDefaultAddressInfoLst, jsonSetting); - var seconds = (DateTime.Now - timeCalc).TotalSeconds.ToString("0.000"); - return "{\"code\":200,\"msg\":\"success\",\"data\":" + data + ",\"count\":" + count + ",\"seconds\":" + seconds + "}"; - } - catch (Exception ex) - { - return "{\"code\":500,\"msg\":\"" + ex.Message + "\",\"data\":[],\"count\":" + 0 + "}"; - } - } - else - { - return "{\"code\":500,\"msg\":\"" + mySql.Message + "\",\"data\":[],\"count\":" + 0 + "}"; - } - } - return "{\"code\":19999,\"msg\":\"输入为空\"}"; - } - - public string WXDelShopDefaultAddress(string inputData) - { - if (!string.IsNullOrEmpty(inputData)) - { - var timeCalc = DateTime.Now; - if (!WXUserManage.GetSign(inputData)) - return "{\"code\":999,\"msg\":\"校验失败\"}"; - - int page = RegexUtils.GetStringQuery(ref inputData, "page").ParseToInt(); - int page_size = RegexUtils.GetStringQuery(ref inputData, "page_size").ParseToInt(200); - string user_id = RegexUtils.GetStringQuery(ref inputData, "user_name")?.Replace("'", "\\'"); - string shop_ids = RegexUtils.GetStringQuery(ref inputData, "shop_ids")?.Replace("'", "\\'"); - if (shop_ids.IsNullOrEmpty() || user_id.IsNullOrEmpty()) - { - return "{\"code\":500,\"msg\":\"店铺编号不能为空\"}"; - } - - string conn = System.Configuration.ConfigurationManager.ConnectionStrings["ConnKJD"].ConnectionString; - MysqlUtils mySql = new MysqlUtils(conn); - - string sql = ""; - - sql = "Delete FROM `wxxd`.`wx_shop_default_address` where user_id = '" + user_id + "' AND shop_id in ('" + shop_ids.Replace(",", "','") + "')"; - sql += ";"; - - var rst = mySql.ExecuteNonQuery(sql); - mySql.Close(); - if (rst) - { - return "{\"code\":200,\"msg\":\"success\"}"; - } - else - { - return "{\"code\":500,\"msg\":\"" + mySql.Message + "\"}"; - } - } - return "{\"code\":19999,\"msg\":\"输入为空\"}"; - } - - - - public string WXAddMdyOrderDecryptAddress(string inputData) - { - if (!string.IsNullOrEmpty(inputData)) - { - if (!WXUserManage.GetSign(inputData)) - return "{\"code\":999,\"msg\":\"校验失败\"}"; - - // 软件用户名 - string shop_id = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "shop_id"))?.Replace("'", "\\'"); - string order_id = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "order_id"))?.Replace("'", "\\'"); - string order_address = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "order_address"))?.Replace("'", "\\'"); - - if (string.IsNullOrEmpty(shop_id)) - return "{\"code\":500,\"msg\":\"缺少店铺编号\"}"; - if (string.IsNullOrEmpty(order_id)) - return "{\"code\":500,\"msg\":\"缺少订单编号\"}"; - if (string.IsNullOrEmpty(order_address)) - return "{\"code\":500,\"msg\":\"缺少地址信息\"}"; - - string conn = System.Configuration.ConfigurationManager.ConnectionStrings["ConnKJD"].ConnectionString; - MysqlUtils mySql = new MysqlUtils(conn); - - string sql = "SELECT 1 FROM `wxxd`.`order_decrypt_address` where order_id='" + order_id + "' AND shop_id='" + shop_id + "'"; - string where = ""; - sql += where; - var exist = mySql.ExecuteFirstInt(sql); - if (!mySql.Message.IsNullOrEmpty()) - { - mySql.Close(); - return "{\"code\":501,\"msg\":\"" + mySql.Message + "\"}"; - } - - if (exist == 0) - { - sql = " INSERT INTO `wxxd`.`order_decrypt_address` (shop_id,order_id,order_address)" + - " VALUES (@shop_id,@order_id,@order_address);"; - } - else - { - sql = "UPDATE `wxxd`.`order_decrypt_address` SET "; - if (order_address != null) - sql += " order_address=@order_address,"; - sql = sql.TrimEnd(','); - sql += " WHERE order_id=@order_id and shop_id=@shop_id;"; - } - - List paramLst = new List(); - paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "order_address", Value = order_address, }); - paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "order_id", Value = order_id, }); - paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "shop_id", Value = shop_id, }); - mySql.ExecuteNonQuery(sql, paramLst.ToArray()); - mySql.Close(); - if (string.IsNullOrEmpty(mySql.Message)) - { - return "{\"code\":200,\"msg\":\"success\",\"data\":\"\"}"; - } - else - { - return "{\"code\":50003,\"msg\":\"" + mySql.Message + "\",\"data\":\"\"}"; - } - } - return "{\"code\":19999,\"msg\":\"输入为空\"}"; - } - - public string WXGetOrderDecryptAddress(string inputData) - { - if (!string.IsNullOrEmpty(inputData)) - { - var timeCalc = DateTime.Now; - if (!WXUserManage.GetSign(inputData)) - return "{\"code\":999,\"msg\":\"校验失败\"}"; - - int page = RegexUtils.GetStringQuery(ref inputData, "page").ParseToInt(); - int page_size = RegexUtils.GetStringQuery(ref inputData, "page_size").ParseToInt(200); - string order_ids = RegexUtils.GetStringQuery(ref inputData, "order_ids")?.Replace("'", "\\'"); - string not_count = RegexUtils.GetStringQuery(ref inputData, "not_count")?.Replace("'", "\\'"); - if (string.IsNullOrEmpty(order_ids)) - return "{\"code\":500,\"msg\":\"订单编号不能为空\"}"; - - string conn = System.Configuration.ConfigurationManager.ConnectionStrings["ConnKJD"].ConnectionString; - MysqlUtils mySql = new MysqlUtils(conn); - - string sql = ""; - var count = -1; - - sql = "SELECT count(*) FROM `wxxd`.`order_decrypt_address` where 1=1"; - string where = ""; - if (order_ids != null) - where += " and order_id IN ('" + order_ids.Replace(",", "','") + "')"; - sql += where; - sql += ";"; - - if (not_count != "true") - count = mySql.ExecuteRowCount(sql); - - DataTable dt; - if (count == 0) - { - dt = new DataTable(); - } - else - { - sql = "SELECT * FROM `wxxd`.`order_decrypt_address` where 1=1"; - sql += where; - sql += " order by id desc limit " + Math.Max(0, page - 1) * page_size + "," + page_size + ";"; - dt = mySql.ExecuteDataTable(sql); - } - mySql.Close(); - - if (dt != null) - { - try - { - List WXOrderAddressInfoLst = new List(); - foreach (DataRow row in dt.Rows) - { - WXOrderAddressInfoLst.Add(new WXOrderDecryptAddressInfo() - { - id = row["id"].ParseToInt(), - shop_id = row["shop_id"].ParseToString(), - order_address = row["order_address"].ParseToString(), - order_id = row["order_id"].ParseToString(), - add_time = Convert.ToDateTime(row["add_time"]), - mdy_time = Convert.ToDateTime(row["mdy_time"]), - }); - } - JsonSerializerSettings jsonSetting = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }; - var data = JsonUtils.SerializeObjectToString(WXOrderAddressInfoLst, jsonSetting); - var seconds = (DateTime.Now - timeCalc).TotalSeconds.ToString("0.000"); - return "{\"code\":200,\"msg\":\"success\",\"data\":" + data + ",\"count\":" + count + ",\"seconds\":" + seconds + "}"; - } - catch (Exception ex) - { - return "{\"code\":500,\"msg\":\"" + ex.Message + "\",\"data\":[],\"count\":" + 0 + "}"; - } - } - else - { - return "{\"code\":500,\"msg\":\"" + mySql.Message + "\",\"data\":[],\"count\":" + 0 + "}"; - } - } - return "{\"code\":19999,\"msg\":\"输入为空\"}"; - } - - - public string WXAddMdyBuyUrlNotes(string inputData) - { - if (!string.IsNullOrEmpty(inputData)) - { - if (!WXUserManage.GetSign(inputData)) - return "{\"code\":999,\"msg\":\"校验失败\"}"; - - // 软件用户名 - string spu_code = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "spu_code"))?.Replace("'", "\\'"); - string user_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "main_user_name"))?.Replace("'", "\\'"); - string buy_url_notes = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "buy_url_notes"))?.Replace("'", "\\'"); - - if (string.IsNullOrEmpty(spu_code)) - return "{\"code\":500,\"msg\":\"缺少店铺编号\"}"; - if (string.IsNullOrEmpty(user_name)) - return "{\"code\":500,\"msg\":\"缺少用户名\"}"; - if (string.IsNullOrEmpty(buy_url_notes)) - return "{\"code\":500,\"msg\":\"缺少地址信息\"}"; - - string conn = System.Configuration.ConfigurationManager.ConnectionStrings["ConnKJD"].ConnectionString; - MysqlUtils mySql = new MysqlUtils(conn); - - string sql = "SELECT 1 FROM `bxx`.`product_buy_url_notes` where user_name='" + user_name + "' AND spu_code='" + spu_code + "'"; - string where = ""; - sql += where; - var exist = mySql.ExecuteFirstInt(sql); - if (!mySql.Message.IsNullOrEmpty()) - { - mySql.Close(); - return "{\"code\":501,\"msg\":\"" + mySql.Message + "\"}"; - } - - if (exist == 0) - { - sql = " INSERT INTO `bxx`.`product_buy_url_notes` (spu_code,user_name,buy_url_notes)" + - " VALUES (@spu_code,@user_name,@buy_url_notes);"; - } - else - { - sql = "UPDATE `bxx`.`product_buy_url_notes` SET "; - if (buy_url_notes != null) - sql += " buy_url_notes=@buy_url_notes,"; - sql = sql.TrimEnd(','); - sql += " WHERE user_name=@user_name and spu_code=@spu_code;"; - } - - List paramLst = new List(); - paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "buy_url_notes", Value = buy_url_notes, }); - paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "user_name", Value = user_name, }); - paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "spu_code", Value = spu_code, }); - mySql.ExecuteNonQuery(sql, paramLst.ToArray()); - mySql.Close(); - if (string.IsNullOrEmpty(mySql.Message)) - { - return "{\"code\":200,\"msg\":\"success\",\"data\":\"\"}"; - } - else - { - return "{\"code\":50003,\"msg\":\"" + mySql.Message + "\",\"data\":\"\"}"; - } - } - return "{\"code\":19999,\"msg\":\"输入为空\"}"; - } - - public string WXGetBuyUrlNotes(string inputData) - { - if (!string.IsNullOrEmpty(inputData)) - { - var timeCalc = DateTime.Now; - if (!WXUserManage.GetSign(inputData)) - return "{\"code\":999,\"msg\":\"校验失败\"}"; - - int page = RegexUtils.GetStringQuery(ref inputData, "page").ParseToInt(); - int page_size = RegexUtils.GetStringQuery(ref inputData, "page_size").ParseToInt(200); - string spu_codes = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "spu_codes"))?.Replace("'", "\\'"); - string user_name = RegexUtils.GetStringQuery(ref inputData, "main_user_name")?.Replace("'", "\\'"); - string not_count = RegexUtils.GetStringQuery(ref inputData, "not_count")?.Replace("'", "\\'"); - if (string.IsNullOrEmpty(spu_codes)) - return "{\"code\":500,\"msg\":\"商品编码不能为空\"}"; - if (string.IsNullOrEmpty(user_name)) - return "{\"code\":500,\"msg\":\"用户名不能为空\"}"; - - string conn = System.Configuration.ConfigurationManager.ConnectionStrings["ConnKJD"].ConnectionString; - MysqlUtils mySql = new MysqlUtils(conn); - - string sql = ""; - var count = -1; - - sql = "SELECT COUNT(*) FROM `bxx`.`product_buy_url_notes` WHERE 1=1"; - string where = ""; - if (spu_codes != null) - where += " and spu_code IN ('" + spu_codes.Replace(",", "','") + "')"; - if (user_name != null) - where += " and user_name='" + user_name + "'"; - sql += where; - sql += ";"; - - if (not_count != "true") - count = mySql.ExecuteRowCount(sql); - - DataTable dt; - if (count == 0) - { - dt = new DataTable(); - } - else - { - sql = "SELECT * FROM `bxx`.`product_buy_url_notes` WHERE 1=1"; - sql += where; - sql += " order by id desc limit " + Math.Max(0, page - 1) * page_size + "," + page_size + ";"; - dt = mySql.ExecuteDataTable(sql); - } - mySql.Close(); - - if (dt != null) - { - try - { - List WXBuyUrlNotesInfoLst = new List(); - foreach (DataRow row in dt.Rows) - { - WXBuyUrlNotesInfoLst.Add(new WXBuyUrlNotesInfo() - { - id = row["id"].ParseToInt(), - user_name = row["user_name"].ParseToString(), - spu_code = row["spu_code"].ParseToString(), - buy_url_notes = row["buy_url_notes"].ParseToString(), - add_time = Convert.ToDateTime(row["add_time"]), - mdy_time = Convert.ToDateTime(row["mdy_time"]), - }); - } - JsonSerializerSettings jsonSetting = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }; - var data = JsonUtils.SerializeObjectToString(WXBuyUrlNotesInfoLst, jsonSetting); - var seconds = (DateTime.Now - timeCalc).TotalSeconds.ToString("0.000"); - return "{\"code\":200,\"msg\":\"success\",\"data\":" + data + ",\"count\":" + count + ",\"seconds\":" + seconds + "}"; - } - catch (Exception ex) - { - return "{\"code\":500,\"msg\":\"" + ex.Message + "\",\"data\":[],\"count\":" + 0 + "}"; - } - } - else - { - return "{\"code\":500,\"msg\":\"" + mySql.Message + "\",\"data\":[],\"count\":" + 0 + "}"; - } - } - return "{\"code\":19999,\"msg\":\"输入为空\"}"; - } - - public string WXAddMdy29WxPddShop(string inputData, bool isAdmin = false) - { - if (!string.IsNullOrEmpty(inputData)) - { - string user_name = RegexUtils.GetStringQuery(ref inputData, "user_name"); - if (isAdmin) - user_name = RegexUtils.GetStringQuery(ref inputData, "shop_user_name"); - string login_name = RegexUtils.GetStringQuery(ref inputData, "login_name"); - string login_pass = RegexUtils.GetStringQuery(ref inputData, "login_pass"); - string sub_user_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "sub_user_name")); - string cookie = RegexUtils.GetStringQuery(ref inputData, "cookie"); - string cookie2 = RegexUtils.GetStringQuery(ref inputData, "cookie2"); - string anti_contents = RegexUtils.GetStringQuery(ref inputData, "anti_contents"); - string shop_id = RegexUtils.GetStringQuery(ref inputData, "shop_id"); - string mall_id = RegexUtils.GetStringQuery(ref inputData, "mall_id"); - string shop_account = RegexUtils.GetStringQuery(ref inputData, "shop_account"); - string group_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "group_name")); - string notes = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "notes")); - int r2 = 0; - int.TryParse(RegexUtils.GetStringQuery(ref inputData, "r2"), out r2); - - if (string.IsNullOrEmpty(user_name)) - { - return "{\"code\":500,\"msg\":\"没有用户名\"}"; - } - if (string.IsNullOrEmpty(login_name)) - { - return "{\"code\":501,\"msg\":\"没有店铺登录名\"}"; - } - - string conn = System.Configuration.ConfigurationManager.ConnectionStrings["ConnKJD"].ConnectionString; - MysqlUtils mySql = new MysqlUtils(conn); - string sql = ""; - if (string.IsNullOrEmpty(shop_id)) - sql = "select exists (select 1 from wxxd.pdd_shop where login_name='" + login_name + "' and user_name='" + user_name + "')"; - else - sql = "select exists (select 1 from wxxd.pdd_shop where login_name='" + login_name + "' and user_name='" + user_name + - "' and shop_id='" + shop_id + "')"; - var exist = mySql.ExecuteFirstInt(sql); - if (exist > 0) - { - mySql.Close(); - //return "{\"code\":500,\"msg\":\"店铺" + login_name + " " + shop_account + "已存在\"}"; - return WXMdy29WxPddShop(inputData); - } - - sql = "insert into wxxd.pdd_shop (login_name,login_pass,cookie,cookie2,anti_contents,shop_account,shop_id," + - "mall_id,sub_user_name,user_name,group_name,notes,add_time,mdy_time) " + - "values ('" + login_name + "','" + login_pass + "','" + cookie + "','" + cookie2 + "','" + anti_contents + "','" + shop_account + "','" + shop_id + - "','" + mall_id + "','" + sub_user_name + "','" + user_name + "','" + group_name + "','" + notes + "','" + - 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\":200,\"msg\":\"success\"}"; - } - } - return "{\"code\":19999,\"msg\":\"未知错误\"}"; - } - - public string WXMdy29WxPddShop(string inputData, bool isAdmin = false) - { - if (!string.IsNullOrEmpty(inputData)) - { - string user_name = RegexUtils.GetStringQuery(ref inputData, "user_name"); - if (isAdmin) - user_name = RegexUtils.GetStringQuery(ref inputData, "shop_user_name"); - string login_name = RegexUtils.GetStringQuery(ref inputData, "login_name"); - string login_pass = RegexUtils.GetStringQuery(ref inputData, "login_pass"); - string sub_user_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "sub_user_name")); - //string cookie = RegexUtils.GetStringQuery(ref inputData, "cookie"); - //string cookie2 = RegexUtils.GetStringQuery(ref inputData, "cookie2"); - string anti_contents = RegexUtils.GetStringQuery(ref inputData, "anti_contents"); - string new_shop_id = RegexUtils.GetStringQuery(ref inputData, "new_shop_id"); - string old_shop_id = RegexUtils.GetStringQuery(ref inputData, "shop_id"); - string mall_id = RegexUtils.GetStringQuery(ref inputData, "mall_id"); - string shop_account = RegexUtils.GetStringQuery(ref inputData, "shop_account"); - string group_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "group_name")); - string notes = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "notes")); - string login_status = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "login_status")); - - int r2 = 0; - int.TryParse(RegexUtils.GetStringQuery(ref inputData, "r2"), out r2); - - if (string.IsNullOrEmpty(user_name)) - { - return "{\"code\":500,\"msg\":\"没有用户名\"}"; - } - if (string.IsNullOrEmpty(login_name)) - { - return "{\"code\":501,\"msg\":\"没有店铺登录名\"}"; - } - - string conn = System.Configuration.ConfigurationManager.ConnectionStrings["ConnKJD"].ConnectionString; - MysqlUtils mySql = new MysqlUtils(conn); - string sql = "update wxxd.pdd_shop set"; - if (login_pass != null) - sql += " login_pass='" + login_pass + "',"; - //if (cookie != null) - // sql += " cookie='" + cookie + "',"; - //if (cookie2 != null) - // sql += " cookie2='" + cookie2 + "',"; - if (anti_contents != null) - sql += " anti_contents='" + anti_contents + "',"; - if (new_shop_id != null) - sql += " shop_id='" + new_shop_id + "',"; - if (mall_id != null) - sql += " mall_id='" + mall_id + "',"; - if (shop_account != null) - sql += " shop_account='" + shop_account + "',"; - if (sub_user_name != null) - sql += " sub_user_name='" + sub_user_name + "',"; - if (group_name != null) - sql += " group_name='" + group_name + "',"; - if (notes != null) - sql += " notes='" + notes + "',"; - if (login_status != null) - sql += " login_status='" + login_status + "',"; - sql = sql.TrimEnd(','); - sql += " where login_name='" + login_name + "' and (user_name='" + user_name + "' or sub_user_name like '%" + user_name + "%')"; - if (!string.IsNullOrEmpty(old_shop_id)) - sql += " and shop_id='" + old_shop_id + "'"; - - var rst = mySql.ExecuteNonQuery(sql); - mySql.Close(); - if (rst) - { - return "{\"code\":200,\"msg\":\"success\"}"; - } - } - return "{\"code\":19999,\"msg\":\"未知错误\"}"; - } - - public string WXMdy29WxPddCookieAndLoginStatus(string inputData) - { - if (!string.IsNullOrEmpty(inputData)) - { - string login_name = RegexUtils.GetStringQuery(ref inputData, "login_name"); - string cookie = RegexUtils.GetStringQuery(ref inputData, "cookie"); - string cookie2 = RegexUtils.GetStringQuery(ref inputData, "cookie2"); - string login_status = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "login_status")); - string login_status2 = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "login_status2")); - string pddid = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "pddid")); - - int r2 = 0; - int.TryParse(RegexUtils.GetStringQuery(ref inputData, "r2"), out r2); - - if (string.IsNullOrWhiteSpace(login_name)) - { - return "{\"code\":500,\"msg\":\"店铺没有登录名\"}"; - } - - string conn = System.Configuration.ConfigurationManager.ConnectionStrings["ConnKJD"].ConnectionString; - MysqlUtils mySql = new MysqlUtils(conn); - string sql = "update wxxd.pdd_shop set"; - if (cookie != null) - sql += " cookie='" + cookie + "',"; - if (cookie2 != null) - sql += " cookie2='" + cookie2 + "',"; - if (login_status != null) - sql += " login_status='" + login_status + "',"; - if (login_status2 != null) - sql += " login_status2='" + login_status2 + "',"; - if (pddid != null) - sql += " pddid='" + pddid + "',"; - sql = sql.TrimEnd(','); - sql += " where login_name='" + login_name + "'"; - - var rst = mySql.ExecuteNonQuery(sql); - mySql.Close(); - if (rst) - { - return "{\"code\":200,\"msg\":\"success\"}"; - } - } - return "{\"code\":19999,\"msg\":\"未知错误\"}"; - } - - public string WXDel29WxPddShop(string inputData, bool isAdmin = false) - { - if (!string.IsNullOrEmpty(inputData)) - { - var login_name = RegexUtils.GetStringQuery(ref inputData, "login_name"); - var user_name = RegexUtils.GetStringQuery(ref inputData, "user_name"); - if (isAdmin) - user_name = RegexUtils.GetStringQuery(ref inputData, "shop_user_name"); - var shop_id = RegexUtils.GetStringQuery(ref inputData, "shop_id"); - var password = RegexUtils.GetStringQuery(ref inputData, "password"); - int r2 = 0; - int.TryParse(RegexUtils.GetStringQuery(ref inputData, "r2"), out r2); - - if (string.IsNullOrEmpty(user_name)) - { - return "{\"code\":500,\"msg\":\"没有用户名\"}"; - } - if (string.IsNullOrEmpty(login_name)) - { - return "{\"code\":501,\"msg\":\"没有店铺登录名\"}"; - } - - string conn = System.Configuration.ConfigurationManager.ConnectionStrings["ConnKJD"].ConnectionString; - MysqlUtils mySql = new MysqlUtils(conn); - string sql = "delete from wxxd.pdd_shop where user_name='" + user_name + "' and login_name='" + login_name + "'"; - if (!string.IsNullOrEmpty(shop_id)) - sql += " and shop_id='" + shop_id + "'"; - - var rst = mySql.ExecuteNonQuery(sql); - mySql.Close(); - if (rst) - { - return "{\"code\":200,\"msg\":\"success\"}"; - } - } - return "{\"code\":19999,\"msg\":\"未知错误\"}"; - } - - public string WXGet29WxPddShop(string inputData, bool isAdmin = false) - { - if (!string.IsNullOrEmpty(inputData)) - { - var user_name = RegexUtils.GetStringQuery(ref inputData, "user_name"); - var password = RegexUtils.GetStringQuery(ref inputData, "password"); - var search_id = RegexUtils.GetStringQuery(ref inputData, "search_id"); - var search_user_name = RegexUtils.GetStringQuery(ref inputData, "search_user_name"); - var search_login_name = RegexUtils.GetStringQuery(ref inputData, "search_login_name"); - var search_notes = RegexUtils.GetStringQuery(ref inputData, "search_notes"); - var search_name = RegexUtils.GetStringQuery(ref inputData, "search_name"); - var operate_sub_sa_name = RegexUtils.GetStringQuery(ref inputData, "operate_sub_sa_name")?.Replace("'", "\\'"); - - // 特殊处理一下修复客户端店铺导入没有立即登录导致的cookie串的bug - //var shop_ids = RegexUtils.GetStringQuery(ref inputData, "shop_ids")?.Replace("'", ""); - var shop_ids = RegexUtils.GetStringQuery(ref inputData, "shop_ids"); - if (shop_ids == "''") - shop_ids = "999999999999999"; - shop_ids = shop_ids?.Replace("'", ""); - if (!string.IsNullOrWhiteSpace(shop_ids)) - { - List shopIdLst = shop_ids.Split(',').ToList(); - shop_ids = "'" + string.Join("','", shopIdLst) + "'"; - } - var shop_names = RegexUtils.GetStringQuery(ref inputData, "shop_names"); - if (!string.IsNullOrWhiteSpace(shop_names)) - { - List shopNameLst = shop_names.Split(',').ToList(); - shop_names = "'" + string.Join("','", shopNameLst) + "'"; - } - var shop_notes = RegexUtils.GetStringQuery(ref inputData, "shop_notes"); - if (!string.IsNullOrWhiteSpace(shop_notes)) - { - List shopNotesLst = shop_notes.Split(',').ToList(); - shop_notes = "'" + string.Join("','", shopNotesLst) + "'"; - } - - var page = RegexUtils.GetStringQuery(ref inputData, "page").ParseToInt(); - var page_size = RegexUtils.GetStringQuery(ref inputData, "page_size").ParseToInt(); - - if (page_size == 0) - page_size = 50; - 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 COUNT(s.id) FROM wxxd.pdd_shop s WHERE 1=1"; - - //where子句 - string where = ""; - if (isAdmin) - where += " and (s.cookie='' or s.shop_id!='')"; - if (!isAdmin) - where += " and (s.user_name='" + user_name + "' or s.sub_user_name like '%" + user_name + "%')"; - if (!string.IsNullOrWhiteSpace(operate_sub_sa_name)) - where += " and s.operate_sub_sa_name='" + operate_sub_sa_name + "'"; - if (!string.IsNullOrWhiteSpace(search_user_name)) - where += " and s.user_name like '%" + search_user_name + "%'"; - if (!string.IsNullOrWhiteSpace(search_login_name)) - where += " and s.login_name like '%" + search_login_name + "%'"; - if (!string.IsNullOrWhiteSpace(search_notes)) - where += " and s.notes like '%" + search_notes + "%'"; - if (!string.IsNullOrWhiteSpace(search_id)) - where += " and s.shop_id like '%" + search_id + "%'"; - if (!string.IsNullOrWhiteSpace(search_name)) - where += " and s.shop_account like '%" + search_name + "%'"; - if (!string.IsNullOrWhiteSpace(shop_ids)) - where += " and s.shop_id in (" + shop_ids + ")"; - if (!string.IsNullOrWhiteSpace(shop_names)) - where += " and s.shop_account in (" + shop_names + ")"; - if (!string.IsNullOrWhiteSpace(shop_notes)) - where += " and s.notes in (" + shop_notes + ")"; - sql += where; - - var count = mySql.ExecuteRowCount(sql); - - DataTable dt; - if (count == 0) - { - dt = new DataTable(); - } - else - { - sql = "SELECT s.id,s.login_name,s.login_pass,s.cookie,s.cookie2,s.anti_contents,s.pddid,s.mall_id,s.shop_id,s.shop_account,s.sub_user_name," + - "s.user_name,s.company_name,s.notes,s.login_status,s.login_status2," + - "s.add_time,s.mdy_time,s.add_sub_sa_time,s.operate_sub_sa_name"; - //sql += " FROM bxx.shop s WHERE 1=1"; - sql += " FROM wxxd.pdd_shop s WHERE 1=1"; - - sql += where; // where 子句 - - sql += " ORDER BY s.id DESC"; - sql += " LIMIT " + Math.Max(page - 1, 0) * page_size + "," + page_size; - dt = mySql.ExecuteDataTable(sql); - } - - mySql.Close(); - if (dt != null) - { - List shopList = new List(); - foreach (DataRow row in dt.Rows) - { - ShopParam shop = new ShopParam - { - id = Convert.ToInt32(row["id"]), - login_name = row["login_name"].ToString(), - login_pass = row["login_pass"].ToString(), - cookie = row["cookie"].ToString(), - cookie2 = row["cookie2"].ToString(), - anti_contents = row["anti_contents"].ToString(), - shop_id = row["shop_id"].ToString(), - shop_account = row["shop_account"].ToString(), - sub_user_name = row["sub_user_name"].ToString(), - user_name = row["user_name"].ToString(), - company_name = row["company_name"].ToString(), - notes = row["notes"].ToString(), - login_status = row["login_status"].ToString(), - login_status2 = row["login_status2"].ToString(), - operate_sub_sa_name = row["operate_sub_sa_name"].ParseToString(), - pddid = row["pddid"].ParseToString(), - mall_id = row["mall_id"].ParseToString(), - }; - shopList.Add(shop); - } - - var data = JsonUtils.SerializeObjectToString(shopList); - //return "{\"code\":200,\"msg\":\"success\",\"data\":" + data + ",\"c\":\"" + EncrypUtil.Encryption(r2) + "\"}"; - return "{\"code\":200,\"msg\":\"success\",\"data\":" + data + ",\"count\":" + count + "}"; - } - } - return "{\"code\":19999,\"msg\":\"未知错误\"}"; - } - - public string E57GetWxTokens(string inputData) - { - if (!string.IsNullOrEmpty(inputData)) - { - var time = RegexUtils.GetStringQuery(ref inputData, "time").ParseToInt(); - string time1 = RegexUtils.GetStringQuery(ref inputData, "code"); - if (time1 != EncrypUtil.Encryption(time)) - return "{\"code\":50000,\"msg\":\"校验失败\"}"; - - var id = (RegexUtils.GetStringQuery(ref inputData, "db_id")?.Replace("'", "\\'")).ParseToInt(); - if (id == 0) - id = 1; - - string conn = System.Configuration.ConfigurationManager.ConnectionStrings["ConnKJD"].ConnectionString; - MysqlUtils mySql = new MysqlUtils(conn); - string sql = "select tokens,mdy_time from wxxd.wx_token WHERE id=" + id + ";"; - var rst = mySql.ExecuteDataTableRow(sql); - mySql.Close(); - - if (!string.IsNullOrEmpty(mySql.Message)) - { - return "{\"code\":500,\"msg\":\"" + mySql.Message + "\"}"; - } - - try - { - string tokens = rst["tokens"].ParseToString(); - var mdyTime = Convert.ToDateTime(rst["mdy_time"]); - if (mdyTime.AddMinutes(60) < DateTime.Now) - { - //var tokenRst = HttpUtils.e57GetResponse("https://po.e57.cn/prod-api/api/sys-api/system/open/api/shop/list?userName=阿杰账户", ""); - var tokenRst = HttpUtils.e57GetResponse("https://po.e57.cn/prod-api/api/sys-api/system/open/api/shop/list?userName=合肥测试一组", ""); - if (!tokenRst.Contains("\"code\":0")) - tokenRst = HttpUtils.e57GetResponse("https://po.e57.cn/prod-api/api/sys-api/system/open/api/shop/list?userName=合肥测试一组", ""); - //https://po.e57.cn/prod-api/api/sys-api/system/open/api/shop/list?userName=pdd用户 - if (!tokenRst.Contains("\"code\":0")) - { - var errMsg = RegexUtils.GetStringJson(ref tokenRst, "msg"); - if (string.IsNullOrEmpty(errMsg)) - errMsg = tokenRst; - return "{\"code\":500,\"msg\":\"" + errMsg + "\"}"; - } - mdyTime = DateTime.Now; - tokens = JsonUtils.SerializeObjectToString(JObject.Parse(tokenRst)["list"]); - - conn = System.Configuration.ConfigurationManager.ConnectionStrings["ConnKJD"].ConnectionString; - mySql = new MysqlUtils(conn); - sql = "update wxxd.wx_token set tokens='" + tokens + "' where id=1;"; - bool su = mySql.ExecuteNonQuery(sql); - mySql.Close(); - - if (!string.IsNullOrEmpty(mySql.Message)) - { - return "{\"code\":500,\"msg\":\"" + mySql.Message + "\"}"; - } - } - return "{\"code\":200,\"tokens\":" + tokens + ",\"mdy_time\":\"" + mdyTime.ToString("yyyy-MM-dd HH:mm:ss") + "\"}"; - } - catch (Exception ex) - { - return "{\"code\":500,\"msg\":\"" + ex.Message + "\"}"; - } - } - return "{\"code\":19999,\"msg\":\"输入为空\"}"; - } - - public string E57GetWxShopToken(string inputData) - { - if (!string.IsNullOrEmpty(inputData)) - { - var time = RegexUtils.GetStringQuery(ref inputData, "time").ParseToInt(); - string time1 = RegexUtils.GetStringQuery(ref inputData, "code"); - if (time1 != EncrypUtil.Encryption(time)) - return "{\"code\":50000,\"msg\":\"校验失败\"}"; - - var shop_id = RegexUtils.GetStringQuery(ref inputData, "shop_id")?.Replace("'", "\\'"); - var url = "https://po.e57.cn/prod-api/api/sys-api/system/open/api/shop/info?appId=" + shop_id; - - var tokenRst = HttpUtils.e57GetResponse(url, ""); - if (!tokenRst.Contains("\"code\":0")) - tokenRst = HttpUtils.e57GetResponse(url, ""); - return tokenRst; - } - return "{\"code\":19999,\"msg\":\"输入为空\"}"; - } - - public static bool GetTimeSign(string sign) - { - bool isSign = false; - for (int i = 0; i <= 5; i++) - { - if (EncrypUtil.GetMd5(DateTime.Now.AddMinutes(i).ToString("yyyyMMddHHmm") + "wxxd").ToLower() == sign.ToLower()) - { - isSign = true; - break; - } - else if (i > 0 && EncrypUtil.GetMd5(DateTime.Now.AddMinutes(-i).ToString("yyyyMMddHHmm") + "wxxd").ToLower() == sign.ToLower()) - { - isSign = true; - break; - } - } - return isSign; - } - } + public class WXShopManage + { + public string GetShop(string inputData, bool isAdmin = false) + { + if (!string.IsNullOrEmpty(inputData)) + { + var timeCalc = DateTime.Now; + var user_name = RegexUtils.GetStringQuery(ref inputData, "user_name"); + var password = RegexUtils.GetStringQuery(ref inputData, "password"); + var search_id = RegexUtils.GetStringQuery(ref inputData, "search_id"); + var search_user_name = RegexUtils.GetStringQuery(ref inputData, "search_user_name"); + var search_login_name = RegexUtils.GetStringQuery(ref inputData, "search_login_name"); + var search_notes = RegexUtils.GetStringQuery(ref inputData, "search_notes"); + var search_name = RegexUtils.GetStringQuery(ref inputData, "search_name"); + var operate_sub_sa_name = RegexUtils.GetStringQuery(ref inputData, "operate_sub_sa_name")?.Replace("'", "\\'"); + var shop_ids = RegexUtils.GetStringQuery(ref inputData, "shop_ids")?.Replace("'", ""); + var is_show_expire = RegexUtils.GetStringQuery(ref inputData, "is_show_expire")?.ParseToBool(); + var is_get_erp_shop_id = RegexUtils.GetStringQuery(ref inputData, "is_get_erp_shop_id")?.ParseToBool(); + + if (!string.IsNullOrWhiteSpace(shop_ids)) + { + List shopIdLst = shop_ids.Split(',').ToList(); + shop_ids = "'" + string.Join("','", shopIdLst) + "'"; + } + var shop_names = RegexUtils.GetStringQuery(ref inputData, "shop_names"); + if (!string.IsNullOrWhiteSpace(shop_names)) + { + List shopNameLst = shop_names.Split(',').ToList(); + shop_names = "'" + string.Join("','", shopNameLst) + "'"; + } + var shop_notes = RegexUtils.GetStringQuery(ref inputData, "shop_notes"); + if (!string.IsNullOrWhiteSpace(shop_notes)) + { + List shopNotesLst = shop_notes.Split(',').ToList(); + shop_notes = "'" + string.Join("','", shopNotesLst) + "'"; + } + + var page = RegexUtils.GetStringQuery(ref inputData, "page").ParseToInt(); + var page_size = RegexUtils.GetStringQuery(ref inputData, "page_size").ParseToInt(); + + if (page_size == 0) + page_size = 50; + + string conn = System.Configuration.ConfigurationManager.ConnectionStrings["ConnKJD"].ConnectionString; + MysqlUtils mySql = new MysqlUtils(conn); + string sql; + bool isPayUser = false; + if (!isAdmin) + { + sql = "select u.authority,uu.authority as main_authority " + + "FROM wxxd.user u LEFT JOIN wxxd.user uu ON uu.user_name=u.parent_user_name where u.user_name='" + + user_name + "'"; + + var dtRow = mySql.ExecuteDataTableRow(sql); + if (!string.IsNullOrEmpty(mySql.Message)) + { + mySql.Close(); + return "{\"code\":501,\"msg\":\"" + mySql.Message + "\",\"data\":null}"; + } + if (dtRow == null) + { + mySql.Close(); + return "{\"code\":501,\"msg\":\"" + mySql.Message + "\",\"data\":null}"; + } + isPayUser = dtRow["authority"].ToString().Contains("充值用户") || dtRow["main_authority"].ToString().Contains("充值用户"); + } + + sql = "SELECT COUNT(*) FROM wxxd.shop s WHERE 1=1"; + + //where子句 + string where = ""; + if (isAdmin) + where += " and (s.cookie='' or s.shop_id!='')"; + if (!isAdmin) + where += " and (s.user_name='" + user_name + "' or s.sub_user_name like '%" + user_name + "%')"; + if (!string.IsNullOrWhiteSpace(operate_sub_sa_name)) + where += " and s.operate_sub_sa_name='" + operate_sub_sa_name + "'"; + if (!string.IsNullOrWhiteSpace(search_user_name)) + where += " and s.user_name like '%" + search_user_name + "%'"; + if (!string.IsNullOrWhiteSpace(search_login_name)) + where += " and s.login_name like '%" + search_login_name + "%'"; + if (!string.IsNullOrWhiteSpace(search_notes)) + where += " and s.notes like '%" + search_notes + "%'"; + if (!string.IsNullOrWhiteSpace(search_id)) + where += " and s.shop_id like '%" + search_id + "%'"; + if (!string.IsNullOrWhiteSpace(search_name)) + where += " and s.shop_account like '%" + search_name + "%'"; + if (!string.IsNullOrWhiteSpace(shop_ids)) + where += " and s.shop_id in (" + shop_ids + ")"; + if (!string.IsNullOrWhiteSpace(shop_names)) + where += " and s.shop_account in (" + shop_names + ")"; + if (!string.IsNullOrWhiteSpace(shop_notes)) + where += " and s.notes in (" + shop_notes + ")"; + sql += where; + + var count = mySql.ExecuteRowCount(sql); + + DataTable dt; + if (count == 0) + { + dt = new DataTable(); + } + else + { + sql = " SELECT s.*,se.expire_time‌ " + + " FROM wxxd.shop s" + + " LEFT JOIN wxxd.user_points_shop_expire se ON s.shop_id=se.shop_id" + + " WHERE 1=1"; + sql += where; // where 子句 + + sql += " ORDER BY s.id DESC"; + sql += " LIMIT " + Math.Max(page - 1, 0) * page_size + "," + page_size; + dt = mySql.ExecuteDataTable(sql); + } + + mySql.Close(); + if (!string.IsNullOrEmpty(mySql.Message)) + { + return "{\"code\":501,\"msg\":\"" + mySql.Message + "\",\"data\":null}"; + } + if (dt != null) + { + List shopList = new List(); + foreach (DataRow row in dt.Rows) + { + ShopParam shop = new ShopParam + { + id = Convert.ToInt32(row["id"]), + login_name = row["login_name"].ToString(), + login_pass = row["login_pass"].ToString(), + cookie = row["cookie"].ToString(), + cookie2 = row["cookie2"].ToString(), + anti_contents = row["anti_contents"].ToString(), + shop_id = row["shop_id"].ToString(), + shop_account = row["shop_account"].ToString(), + sub_user_name = row["sub_user_name"].ToString(), + user_name = row["user_name"].ToString(), + company_name = row["company_name"].ToString(), + notes = row["notes"].ToString(), + login_status = row["login_status"].ToString(), + login_status2 = row["login_status2"].ToString(), + add_product_remaining = row["add_product_remaining"].ParseToInt(), + add_product_month = row["add_product_month"].ParseToInt(), + operate_sub_sa_name = row["operate_sub_sa_name"].ParseToString(), + openid = row["openid"].ParseToString(), + group_name = row["group_name"].ParseToString(), + add_time = row["add_time"].IsNullOrEmpty() ? DateTime.MinValue : Convert.ToDateTime(row["add_time"]), + //mdy_time = row["mdy_time"].IsNullOrEmpty() ? DateTime.MinValue : Convert.ToDateTime(row["mdy_time"]), + expire_time = row["expire_time"].ParseToInt(), + never_expires = row["never_expires"].ParseToBool(), + }; + if (shop.shop_id == "wx2543ce37a0009883") + { + var exp = row["expire_time"].ParseToString(); + } + var expire_datetime = TimeUtils.StampToDateTime(shop.expire_time.Value); + if (isPayUser && expire_datetime < DateTime.Now) + shop.is_point_shop_expire = true; + + shopList.Add(shop); + } + + if (is_get_erp_shop_id == true) + { + conn = System.Configuration.ConfigurationManager.ConnectionStrings["ConnKJD"].ConnectionString; + mySql = new MysqlUtils(conn); + sql = " SELECT app_key,id,corporate_account_user_id,manage_user_id " + + " FROM erp.o_shop" + + " WHERE app_key in ('" + string.Join("','", shopList.Select(s => s.shop_id)) + "');"; + dt = mySql.ExecuteDataTable(sql); + + mySql.Close(); + if (!string.IsNullOrEmpty(mySql.Message)) + { + return "{\"code\":501,\"msg\":\"" + mySql.Message + "\",\"data\":null}"; + } + if (dt != null) + { + foreach (DataRow row in dt.Rows) + { + var erpDbId = row["id"].ParseToNullableLong(); + var erpCorporateUserId = row["corporate_account_user_id"].ParseToNullableLong(); + var erpManageUserId = row["manage_user_id"].ParseToNullableLong(); + var appKey = row["app_key"].ParseToString(); + var shop = shopList.FirstOrDefault(s => s.shop_id == appKey && !s.shop_id.IsNullOrEmpty()); + if (shop != null) + { + shop.erp_corporate_account_user_id = erpCorporateUserId; + shop.erp_manage_user_id = erpManageUserId; + shop.erp_shop_id = erpDbId; + } + } + } + } + + foreach (var item in shopList) + { + if (item.never_expires) + { + item.expire_time = 1893427200; + item.is_point_shop_expire = false; + } + } + var data = JsonUtils.SerializeObjectToString(shopList); + var seconds = (DateTime.Now - timeCalc).TotalSeconds.ToString("0.000"); + + return "{\"code\":200,\"msg\":\"success\",\"data\":" + data + ",\"count\":" + count + ",\"seconds\":" + seconds + "}"; + } + } + return "{\"code\":19999,\"msg\":\"未知错误\"}"; + } + + /// + /// 获取erp店铺对应账户的余额 + /// + /// + /// + /// + public string GetShopErpMerchant(string inputData, bool isAdmin = false) + { + if (!string.IsNullOrEmpty(inputData)) + { + var timeCalc = DateTime.Now; + if (!WXUserManage.GetSign(inputData)) + return "{\"code\":999,\"msg\":\"校验失败\"}"; + + var corporate_account_user_id = RegexUtils.GetStringQuery(ref inputData, "corporate_account_user_id")?.Replace("'", "\\'"); + var manage_user_id = RegexUtils.GetStringQuery(ref inputData, "manage_user_id")?.Replace("'", "\\'"); + var shop_id = RegexUtils.GetStringQuery(ref inputData, "shop_id")?.Replace("'", "\\'"); + if (corporate_account_user_id.IsNullOrEmpty() && manage_user_id.IsNullOrEmpty()) + return "{\"code\":500,\"msg\":\"未指定商户\"}"; + + var page = RegexUtils.GetStringQuery(ref inputData, "page").ParseToInt(); + var page_size = RegexUtils.GetStringQuery(ref inputData, "page_size").ParseToInt(); + + if (page_size == 0) + page_size = 200; + + var manage_user_ids = new List(); + if (!manage_user_id.IsNullOrEmpty()) + manage_user_ids.Add(manage_user_id); + + string conn = System.Configuration.ConfigurationManager.ConnectionStrings["ConnKJD"].ConnectionString; + MysqlUtils mySql = new MysqlUtils(conn); + string sql; + + if (!string.IsNullOrEmpty(corporate_account_user_id)) + { + sql = "SELECT manage_user_id FROM erp.o_shop_group WHERE corporate_account_user_id = '" + corporate_account_user_id + "';"; + var manage_user_id_tb = mySql.ExecuteDataTable(sql); + if (!string.IsNullOrEmpty(mySql.Message)) + { + mySql.Close(); + return "{\"code\":501,\"msg\":\"" + mySql.Message + "\",\"data\":null}"; + } + if (manage_user_id_tb == null) + { + mySql.Close(); + var seconds = (DateTime.Now - timeCalc).TotalSeconds.ToString("0.000"); + return "{\"code\":200,\"msg\":\"success\",\"data\":[],\"count\":-2,\"seconds\":" + seconds + "}"; + } + manage_user_ids.AddRange(manage_user_id_tb.Rows.Cast().Select(t => t["manage_user_id"].ToString())); + if (manage_user_ids.Count == 0) + { + mySql.Close(); + var seconds = (DateTime.Now - timeCalc).TotalSeconds.ToString("0.000"); + return "{\"code\":200,\"msg\":\"success\",\"data\":[],\"count\":-2,\"seconds\":" + seconds + "}"; + } + } + + sql = "select * FROM erp.o_user_account u where u.user_id in ('" + string.Join("','", manage_user_ids) + "')"; + 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\":501,\"msg\":\"" + mySql.Message + "\",\"data\":null}"; + } + if (dt != null) + { + List erpAccountInfo = new List(); + foreach (DataRow row in dt.Rows) + { + ErpMerchantInfo shop = new ErpMerchantInfo + { + id = Convert.ToInt32(row["id"]), + account_name = row["account_name"].ToString(), + account_status = row["account_status"].ParseToInt(), + account_type = row["account_type"].ParseToInt(), + balance = row["balance"].ParseToDecimal(), + create_by = row["create_by"].ParseToNullableLong(), + create_time = row["create_time"].ParseToString().ParseToDateTime(), + frozen_amount = row["frozen_amount"].ParseToDecimal(), + recharge_amount_total = row["recharge_amount_total"].ParseToDecimal(), + update_by = row["update_by"].ParseToNullableLong(), + update_time = row["update_time"].ParseToString().ParseToDateTime(), + user_id = row["user_id"].ParseToLong(), + withdrawn_amount = row["withdrawn_amount"].ParseToDecimal(), + withdraw_account_image_url = row["withdraw_account_image_url"].ParseToString(), + }; + erpAccountInfo.Add(shop); + } + erpAccountInfo = erpAccountInfo.OrderByDescending(s => s.balance).ToList(); + var count = -1; + var data = JsonUtils.SerializeObjectToString(erpAccountInfo); + 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 SubSaGetSelectProdShop(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + var user_name = RegexUtils.GetStringQuery(ref inputData, "user_name"); + var password = RegexUtils.GetStringQuery(ref inputData, "password"); + var search_id = RegexUtils.GetStringQuery(ref inputData, "search_id"); + var search_user_name = RegexUtils.GetStringQuery(ref inputData, "search_user_name"); + var search_login_name = RegexUtils.GetStringQuery(ref inputData, "search_login_name"); + var search_notes = RegexUtils.GetStringQuery(ref inputData, "search_notes"); + var search_name = RegexUtils.GetStringQuery(ref inputData, "search_name"); + var operate_sub_sa_name = RegexUtils.GetStringQuery(ref inputData, "operate_sub_sa_name")?.Replace("'", "\\'"); + var shop_ids = RegexUtils.GetStringQuery(ref inputData, "shop_ids")?.Replace("'", ""); + if (!string.IsNullOrWhiteSpace(shop_ids)) + { + List shopIdLst = shop_ids.Split(',').ToList(); + shop_ids = "'" + string.Join("','", shopIdLst) + "'"; + } + var shop_names = RegexUtils.GetStringQuery(ref inputData, "shop_names"); + if (!string.IsNullOrWhiteSpace(shop_names)) + { + List shopNameLst = shop_names.Split(',').ToList(); + shop_names = "'" + string.Join("','", shopNameLst) + "'"; + } + var shop_notes = RegexUtils.GetStringQuery(ref inputData, "shop_notes"); + if (!string.IsNullOrWhiteSpace(shop_notes)) + { + List shopNotesLst = shop_notes.Split(',').ToList(); + shop_notes = "'" + string.Join("','", shopNotesLst) + "'"; + } + + var page = RegexUtils.GetStringQuery(ref inputData, "page").ParseToInt(); + var page_size = RegexUtils.GetStringQuery(ref inputData, "page_size").ParseToInt(); + + if (page_size == 0) + page_size = 50; + 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 COUNT(s.id) FROM wxxd.shop s WHERE 1=1"; + + //where子句 + string where = ""; + if (!string.IsNullOrWhiteSpace(operate_sub_sa_name)) + where += " and (s.shop_id in (SELECT DISTINCT shop_id From wxxd.product_select WHERE operate_sub_sa_name='" + operate_sub_sa_name + "') or " + + "s.shop_id in (SELECT DISTINCT shop_id From wxxd.third_product_select WHERE operate_sub_sa_name='" + operate_sub_sa_name + "'))"; + where += " and (s.cookie='' or s.shop_id!='')"; + //if (!string.IsNullOrWhiteSpace(operate_sub_sa_name)) + // where += " and s.operate_sub_sa_name='" + operate_sub_sa_name + "'"; + if (!string.IsNullOrWhiteSpace(search_user_name)) + where += " and s.user_name like '%" + search_user_name + "%'"; + if (!string.IsNullOrWhiteSpace(search_login_name)) + where += " and s.login_name like '%" + search_login_name + "%'"; + if (!string.IsNullOrWhiteSpace(search_notes)) + where += " and s.notes like '%" + search_notes + "%'"; + if (!string.IsNullOrWhiteSpace(search_id)) + where += " and s.shop_id like '%" + search_id + "%'"; + if (!string.IsNullOrWhiteSpace(search_name)) + where += " and s.shop_account like '%" + search_name + "%'"; + if (!string.IsNullOrWhiteSpace(shop_ids)) + where += " and s.shop_id in (" + shop_ids + ")"; + if (!string.IsNullOrWhiteSpace(shop_names)) + where += " and s.shop_account in (" + shop_names + ")"; + if (!string.IsNullOrWhiteSpace(shop_notes)) + where += " and s.notes in (" + shop_notes + ")"; + sql += where; + + var count = mySql.ExecuteRowCount(sql); + + DataTable dt; + if (count == 0) + { + dt = new DataTable(); + } + else + { + sql = "SELECT s.id,s.login_name,s.login_pass,s.cookie,s.cookie2,s.anti_contents,s.shop_id,s.openid,s.shop_account,s.sub_user_name,s.user_name," + + "s.company_name,s.notes,s.group_name,s.login_status,s.login_status2,c.add_product_remaining,c.add_product_month,s.add_time,s.mdy_time," + + "s.add_sub_sa_time,s.operate_sub_sa_name"; + sql += " FROM wxxd.shop s LEFT JOIN wxxd.shop_add_prod_count c ON s.shop_id=c.shop_id WHERE 1=1"; + + sql += where; // where 子句 + + sql += " ORDER BY s.id DESC"; + sql += " LIMIT " + Math.Max(page - 1, 0) * page_size + "," + page_size; + dt = mySql.ExecuteDataTable(sql); + } + + mySql.Close(); + if (dt != null) + { + List shopList = new List(); + foreach (DataRow row in dt.Rows) + { + ShopParam shop = new ShopParam + { + id = Convert.ToInt32(row["id"]), + login_name = row["login_name"].ToString(), + login_pass = row["login_pass"].ToString(), + cookie = row["cookie"].ToString(), + cookie2 = row["cookie2"].ToString(), + anti_contents = row["anti_contents"].ToString(), + shop_id = row["shop_id"].ToString(), + shop_account = row["shop_account"].ToString(), + sub_user_name = row["sub_user_name"].ToString(), + user_name = row["user_name"].ToString(), + company_name = row["company_name"].ToString(), + notes = row["notes"].ToString(), + login_status = row["login_status"].ToString(), + login_status2 = row["login_status2"].ToString(), + add_product_remaining = row["add_product_remaining"].ParseToInt(), + add_product_month = row["add_product_month"].ParseToInt(), + operate_sub_sa_name = row["operate_sub_sa_name"].ParseToString(), + openid = row["openid"].ToString(), + group_name = row["group_name"].ToString(), + }; + shopList.Add(shop); + } + + //sql = "\r\nINSERT INTO wxxd.shop_add_prod_count(shop_id,shop_account,add_product_remaining,add_product_month) VALUES "; + //foreach (var shop in shopList) + //{ + // sql += "\r\n('" + shop.shop_id + "','" + shop.shop_account + "'," + shop.add_product_remaining + "," + shop.add_product_month + "),"; + //} + //sql = sql.TrimEnd(',') + " \r\n"; + //sql += "ON DUPLICATE KEY UPDATE " + + // "shop_account=VALUES(shop_account)," + + // "add_product_remaining=VALUES(add_product_remaining)," + + // "add_product_month=VALUES(add_product_month);"; + //var result = mySql.ExecuteNonQuery(sql); + //mySql.Close(); + + int month = DateTime.Now.Month; + var shopMonthList = shopList.Where(s => s.add_product_month != month); + if (shopMonthList.Count() > 0) + { + int remainCount = 300; + var shopMonthIdList = shopMonthList.Select(s => s.id); + mySql = new MysqlUtils(conn); + string ids = string.Join(",", shopMonthIdList); + sql = ""; + sql += "update wxxd.shop set add_product_remaining=" + remainCount + ", add_product_month=" + month + + " where 1=1 and id in (" + ids + ");"; + + sql += "\r\nINSERT INTO wxxd.shop_add_prod_count(shop_id,shop_account,add_product_remaining,add_product_month) VALUES "; + foreach (var shop in shopMonthList) + { + sql += "\r\n('" + shop.shop_id + "','" + shop.shop_account + "'," + remainCount + "," + month + "),"; + } + sql = sql.TrimEnd(',') + " \r\n"; + sql += "ON DUPLICATE KEY UPDATE " + + "shop_account=VALUES(shop_account)," + + "add_product_remaining=VALUES(add_product_remaining)," + + "add_product_month=VALUES(add_product_month);"; + var rst = mySql.ExecuteNonQuery(sql); + mySql.Close(); + + if (rst) + { + foreach (var shop in shopMonthList) + { + shop.add_product_month = month; + shop.add_product_remaining = remainCount; + } + } + } + var data = JsonUtils.SerializeObjectToString(shopList); + + + //return "{\"code\":200,\"msg\":\"success\",\"data\":" + data + ",\"c\":\"" + EncrypUtil.Encryption(r2) + "\"}"; + return "{\"code\":200,\"msg\":\"success\",\"data\":" + data + ",\"count\":" + count + "}"; + } + } + return "{\"code\":19999,\"msg\":\"未知错误\"}"; + } + + + + public string UpdateAddProdRemaining(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + var time = RegexUtils.GetStringQuery(ref inputData, "time").ParseToInt(); + string time1 = RegexUtils.GetStringQuery(ref inputData, "code"); + if (time1 != EncrypUtil.Encryption(time)) + return "{\"code\":50000,\"msg\":\"校验失败\"}"; + + var user_name = RegexUtils.GetStringQuery(ref inputData, "user_name"); + var password = RegexUtils.GetStringQuery(ref inputData, "password"); + var remainCount = RegexUtils.GetStringQuery(ref inputData, "remain_count"); + var shop_ids = RegexUtils.GetStringQuery(ref inputData, "shop_ids")?.Replace("'", ""); + if (!string.IsNullOrWhiteSpace(shop_ids)) + { + List shopIdLst = shop_ids.Split(',').ToList(); + shop_ids = "'" + string.Join("','", shopIdLst) + "'"; + } + + string conn = System.Configuration.ConfigurationManager.ConnectionStrings["ConnKJD"].ConnectionString; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = ""; + sql += "update wxxd.shop_add_prod_count set add_product_remaining=" + remainCount + + " where 1=1 and shop_id in (" + shop_ids + ");"; + + var rst = mySql.ExecuteNonQuery(sql); + var msg = mySql.Message; + mySql.Close(); + + if (rst) + return "{\"code\":200,\"msg\":\"success\"}"; + else + return "{\"code\":50000,\"msg\":\"" + msg + "\"}"; + } + else + { + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + } + + //获取一个手机登录号码下的所有店铺(以便有则更新,无则新增) + public string GetOneLoginNameShop(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + var user_name = RegexUtils.GetStringQuery(ref inputData, "user_name"); + var login_name = RegexUtils.GetStringQuery(ref inputData, "login_name"); + var password = RegexUtils.GetStringQuery(ref inputData, "password"); + 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 id,login_name,login_pass,cookie,cookie2,anti_contents,shop_id,openid,shop_account,sub_user_name,user_name from wxxd.shop where user_name='" + + user_name + "' and login_name='" + login_name + "'"; + + var dt = mySql.ExecuteDataTable(sql); + mySql.Close(); + if (dt != null) + { + List shopList = new List(); + foreach (DataRow row in dt.Rows) + { + ShopParam shop = new ShopParam + { + id = Convert.ToInt32(row["id"]), + login_name = row["login_name"].ToString(), + login_pass = row["login_pass"].ToString(), + cookie = row["cookie"].ToString(), + cookie2 = row["cookie2"].ToString(), + anti_contents = row["anti_contents"].ToString(), + shop_id = row["shop_id"].ToString(), + shop_account = row["shop_account"].ToString(), + sub_user_name = row["sub_user_name"].ToString(), + user_name = row["user_name"].ToString(), + company_name = row["company_name"].ToString(), + notes = row["notes"].ToString(), + login_status = row["login_status"].ToString(), + openid = row["openid"].ToString(), + }; + shopList.Add(shop); + } + var data = JsonUtils.SerializeObjectToString(shopList); + return "{\"code\":200,\"msg\":\"success\",\"data\":" + data + ",\"c\":\"" + EncrypUtil.Encryption(r2) + "\"}"; + } + } + return "{\"code\":19999,\"msg\":\"未知错误\"}"; + } + + //获取一个手机登录号码下特定ID的店铺 + public string GetOneIdShop(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + var user_name = RegexUtils.GetStringQuery(ref inputData, "user_name"); + var login_name = RegexUtils.GetStringQuery(ref inputData, "login_name"); + var shop_id = RegexUtils.GetStringQuery(ref inputData, "shop_id"); + var password = RegexUtils.GetStringQuery(ref inputData, "password"); + 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 id,login_name,login_pass,cookie,cookie2,anti_contents,shop_id,openid,shop_account,sub_user_name,user_name from wxxd.shop where user_name='" + + user_name + "' and login_name='" + login_name + "' and shop_id='" + shop_id + "'"; + + var dt = mySql.ExecuteDataTable(sql); + mySql.Close(); + if (dt != null) + { + List shopList = new List(); + foreach (DataRow row in dt.Rows) + { + ShopParam shop = new ShopParam + { + id = Convert.ToInt32(row["id"]), + login_name = row["login_name"].ToString(), + login_pass = row["login_pass"].ToString(), + cookie = row["cookie"].ToString(), + cookie2 = row["cookie2"].ToString(), + anti_contents = row["anti_contents"].ToString(), + shop_id = row["shop_id"].ToString(), + shop_account = row["shop_account"].ToString(), + sub_user_name = row["sub_user_name"].ToString(), + user_name = row["user_name"].ToString(), + company_name = row["company_name"].ToString(), + notes = row["notes"].ToString(), + login_status = row["login_status"].ToString(), + openid = row["openid"].ToString(), + }; + shopList.Add(shop); + } + var data = JsonUtils.SerializeObjectToString(shopList); + return "{\"code\":200,\"msg\":\"success\",\"data\":" + data + ",\"c\":\"" + EncrypUtil.Encryption(r2) + "\"}"; + } + } + return "{\"code\":19999,\"msg\":\"未知错误\"}"; + } + + /// + /// ai api + /// + /// + /// + public string GetOneShopCookieByAppId(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + var shop_id = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "shop_id"))?.Replace("'", "\\'"); + if (shop_id.IsNullOrEmpty()) + return "{\"code\":500,\"msg\":\"未指定店铺\"}"; + var sign = RegexUtils.GetStringQuery(ref inputData, "sign"); + if (!GetTimeSign(sign)) + return "{\"code\":500,\"msg\":\"校验失败\"}"; + + string conn = System.Configuration.ConfigurationManager.ConnectionStrings["ConnKJD"].ConnectionString; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = "select shop_id,cookie from wxxd.shop where shop_id in ('" + shop_id.Replace(",", "','") + "');"; + + var dt = mySql.ExecuteDataTable(sql); + mySql.Close(); + if (dt != null) + { + JArray jArr = new JArray(); + foreach (DataRow row in dt.Rows) + { + if (!jArr.Any(o => o["shop_id"].ParseToString() == row["shop_id"].ToString())) + { + JObject jObj = new JObject(); + jObj["shop_id"] = row["shop_id"].ToString(); + jObj["cookies"] = row["cookie"].ToString(); + jArr.Add(jObj); + } + } + return "{\"code\":200,\"msg\":\"success\",\"data\":" + JsonUtils.SerializeObject(jArr) + "}"; + } + } + return "{\"code\":19999,\"msg\":\"未知错误\"}"; + } + + public string AddShop(string inputData, bool isAdmin = false) + { + if (!string.IsNullOrEmpty(inputData)) + { + string user_name = RegexUtils.GetStringQuery(ref inputData, "user_name"); + if (isAdmin) + user_name = RegexUtils.GetStringQuery(ref inputData, "shop_user_name"); + string login_name = RegexUtils.GetStringQuery(ref inputData, "login_name"); + string login_pass = RegexUtils.GetStringQuery(ref inputData, "login_pass"); + string sub_user_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "sub_user_name")); + string cookie = RegexUtils.GetStringQuery(ref inputData, "cookie"); + string cookie2 = RegexUtils.GetStringQuery(ref inputData, "cookie2"); + string anti_contents = RegexUtils.GetStringQuery(ref inputData, "anti_contents"); + string shop_id = RegexUtils.GetStringQuery(ref inputData, "shop_id"); + string shop_account = RegexUtils.GetStringQuery(ref inputData, "shop_account"); + string group_name = RegexUtils.GetStringQuery(ref inputData, "group_name"); + string notes = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "notes")); + int r2 = 0; + int.TryParse(RegexUtils.GetStringQuery(ref inputData, "r2"), out r2); + + if (string.IsNullOrEmpty(user_name)) + { + return "{\"code\":500,\"msg\":\"没有用户名\"}"; + } + if (string.IsNullOrEmpty(login_name)) + { + return "{\"code\":501,\"msg\":\"没有店铺登录名\"}"; + } + + string conn = System.Configuration.ConfigurationManager.ConnectionStrings["ConnKJD"].ConnectionString; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = ""; + if (string.IsNullOrEmpty(shop_id)) + sql = "select exists (select 1 from wxxd.shop where login_name='" + login_name + "' and user_name='" + user_name + "')"; + else + sql = "select exists (select 1 from wxxd.shop where login_name='" + login_name + "' and user_name='" + user_name + + "' and shop_id='" + shop_id + "')"; + var exist = mySql.ExecuteFirstInt(sql); + if (exist > 0) + { + mySql.Close(); + return "{\"code\":500,\"msg\":\"店铺" + login_name + " " + shop_account + "已存在\"}"; + } + + sql = "insert into wxxd.shop (login_name,login_pass,cookie,cookie2,anti_contents,shop_account,shop_id,sub_user_name,user_name,group_name,notes,add_time,mdy_time) " + + "values ('" + login_name + "','" + login_pass + "','" + cookie + "','" + cookie2 + "','" + anti_contents + "','" + shop_account + "','" + shop_id + "','" + + sub_user_name + "','" + user_name + "','" + group_name + "','" + notes + "','" + + 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\":200,\"msg\":\"success\"}"; + } + } + return "{\"code\":19999,\"msg\":\"未知错误\"}"; + } + + public string MdyShop(string inputData, bool isAdmin = false) + { + if (!string.IsNullOrEmpty(inputData)) + { + string user_name = RegexUtils.GetStringQuery(ref inputData, "user_name"); + if (isAdmin) + user_name = RegexUtils.GetStringQuery(ref inputData, "shop_user_name"); + string login_name = RegexUtils.GetStringQuery(ref inputData, "login_name"); + string login_pass = RegexUtils.GetStringQuery(ref inputData, "login_pass"); + string sub_user_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "sub_user_name")); + string cookie = RegexUtils.GetStringQuery(ref inputData, "cookie"); + string cookie2 = RegexUtils.GetStringQuery(ref inputData, "cookie2"); + string anti_contents = RegexUtils.GetStringQuery(ref inputData, "anti_contents"); + string new_shop_id = RegexUtils.GetStringQuery(ref inputData, "new_shop_id"); + string old_shop_id = RegexUtils.GetStringQuery(ref inputData, "shop_id"); + string shop_account = RegexUtils.GetStringQuery(ref inputData, "shop_account"); + string group_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "group_name")); + string notes = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "notes")); + string login_status = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "login_status")); + + int r2 = 0; + int.TryParse(RegexUtils.GetStringQuery(ref inputData, "r2"), out r2); + + if (string.IsNullOrEmpty(user_name)) + { + return "{\"code\":500,\"msg\":\"没有用户名\"}"; + } + if (string.IsNullOrEmpty(login_name)) + { + return "{\"code\":501,\"msg\":\"没有店铺登录名\"}"; + } + + string conn = System.Configuration.ConfigurationManager.ConnectionStrings["ConnKJD"].ConnectionString; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = "update wxxd.shop set"; + if (login_pass != null) + sql += " login_pass='" + login_pass + "',"; + if (cookie != null) + sql += " cookie='" + cookie + "',"; + if (cookie2 != null) + sql += " cookie2='" + cookie2 + "',"; + if (anti_contents != null) + sql += " anti_contents='" + anti_contents + "',"; + if (new_shop_id != null) + sql += " shop_id='" + new_shop_id + "',"; + if (shop_account != null) + sql += " shop_account='" + shop_account + "',"; + if (sub_user_name != null) + sql += " sub_user_name='" + sub_user_name + "',"; + if (group_name != null) + sql += " group_name='" + group_name + "',"; + if (notes != null) + sql += " notes='" + notes + "',"; + if (login_status != null) + sql += " login_status='" + login_status + "',"; + sql = sql.TrimEnd(','); + sql += " where login_name='" + login_name + "' and (user_name='" + user_name + "' or sub_user_name like '%" + user_name + "%')"; + if (!string.IsNullOrEmpty(old_shop_id)) + sql += " and shop_id='" + old_shop_id + "'"; + + var rst = mySql.ExecuteNonQuery(sql); + mySql.Close(); + if (rst) + { + return "{\"code\":200,\"msg\":\"success\"}"; + } + } + return "{\"code\":19999,\"msg\":\"未知错误\"}"; + } + + public string MdyCookieAndLoginStatus(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + string login_name = RegexUtils.GetStringQuery(ref inputData, "login_name"); + string cookie = RegexUtils.GetStringQuery(ref inputData, "cookie"); + string cookie2 = RegexUtils.GetStringQuery(ref inputData, "cookie2"); + string login_status = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "login_status")); + string login_status2 = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "login_status2")); + string openid = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "openid")); + + int r2 = 0; + int.TryParse(RegexUtils.GetStringQuery(ref inputData, "r2"), out r2); + + if (string.IsNullOrEmpty(login_name)) + { + return "{\"code\":500,\"msg\":\"店铺没有登录名\"}"; + } + + string conn = System.Configuration.ConfigurationManager.ConnectionStrings["ConnKJD"].ConnectionString; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = "update wxxd.shop set"; + if (cookie != null) + sql += " cookie='" + cookie + "',"; + if (cookie2 != null) + sql += " cookie2='" + cookie2 + "',"; + if (login_status != null) + sql += " login_status='" + login_status + "',"; + if (login_status2 != null) + sql += " login_status2='" + login_status2 + "',"; + if (openid != null) + sql += " openid='" + openid + "',"; + sql = sql.TrimEnd(','); + sql += " where login_name='" + login_name + "'"; + + var rst = mySql.ExecuteNonQuery(sql); + mySql.Close(); + if (rst) + { + return "{\"code\":200,\"msg\":\"success\"}"; + } + } + return "{\"code\":19999,\"msg\":\"未知错误\"}"; + } + + + public string DelShop(string inputData, bool isAdmin = false) + { + if (!string.IsNullOrEmpty(inputData)) + { + var login_name = RegexUtils.GetStringQuery(ref inputData, "login_name"); + var user_name = RegexUtils.GetStringQuery(ref inputData, "user_name"); + if (isAdmin) + user_name = RegexUtils.GetStringQuery(ref inputData, "shop_user_name"); + var shop_id = RegexUtils.GetStringQuery(ref inputData, "shop_id"); + var password = RegexUtils.GetStringQuery(ref inputData, "password"); + int r2 = 0; + int.TryParse(RegexUtils.GetStringQuery(ref inputData, "r2"), out r2); + + if (string.IsNullOrEmpty(user_name)) + { + return "{\"code\":500,\"msg\":\"没有用户名\"}"; + } + if (string.IsNullOrEmpty(login_name)) + { + return "{\"code\":501,\"msg\":\"没有店铺登录名\"}"; + } + + string conn = System.Configuration.ConfigurationManager.ConnectionStrings["ConnKJD"].ConnectionString; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = "delete from wxxd.shop where user_name='" + user_name + "' and login_name='" + login_name + "'"; + if (!string.IsNullOrEmpty(shop_id)) + sql += " and shop_id='" + shop_id + "'"; + + var rst = mySql.ExecuteNonQuery(sql); + mySql.Close(); + if (rst) + { + return "{\"code\":200,\"msg\":\"success\"}"; + } + } + return "{\"code\":19999,\"msg\":\"未知错误\"}"; + } + + /// + /// 设置店铺的二级超管 + /// + /// + public string SetShopSubSa(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + var time = RegexUtils.GetStringQuery(ref inputData, "time").ParseToInt(); + string time1 = RegexUtils.GetStringQuery(ref inputData, "code"); + if (time1 != EncrypUtil.Encryption(time)) + return "{\"code\":50000,\"msg\":\"校验失败\"}"; + + var user_name = RegexUtils.GetStringQuery(ref inputData, "user_name")?.Replace("'", "\\'"); + if (string.IsNullOrEmpty(user_name)) + { + return "{\"code\":50001,\"msg\":\"没有用户名\"}"; + } + + var id = RegexUtils.GetStringQuery(ref inputData, "db_id")?.Replace("'", "\\'"); + var login_name = RegexUtils.GetStringQuery(ref inputData, "shop_login_name")?.Replace("'", "\\'"); + var operate_sub_sa_name = RegexUtils.GetStringQuery(ref inputData, "operate_sub_sa_name")?.Replace("'", "\\'"); + + if (string.IsNullOrEmpty(id) && string.IsNullOrEmpty(login_name)) + { + return "{\"code\":50002,\"msg\":\"未选择任何待上传\"}"; + } + + string conn = System.Configuration.ConfigurationManager.ConnectionStrings["ConnKJD"].ConnectionString; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = "update wxxd.shop set"; + if (operate_sub_sa_name != null) + sql += " operate_sub_sa_name='" + operate_sub_sa_name + "',"; + sql += " add_sub_sa_time='" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "',"; + sql = sql.TrimEnd(','); + if (!string.IsNullOrEmpty(id)) + sql += " where id in (" + id + ")"; + else if (!string.IsNullOrEmpty(login_name)) + sql += " where login_name in ('" + login_name.Replace(",", "','") + "')"; + else + sql += " where 1=2"; + var rst = mySql.ExecuteNonQuery(sql); + mySql.Close(); + if (rst) + { + return "{\"code\":200,\"msg\":\"success\"}"; + } + else + { + return "{\"code\":500,\"msg\":\"" + mySql.Message + "\"}"; + } + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + public string WXAddMdyShopDefaultAddress(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + if (!WXUserManage.GetSign(inputData)) + return "{\"code\":999,\"msg\":\"校验失败\"}"; + + // 软件用户名 + string user_id = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "user_name"))?.Replace("'", "\\'"); + string shop_id = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "shop_id"))?.Replace("'", "\\'"); + string province_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "province_name"))?.Replace("'", "\\'"); + string city_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "city_name"))?.Replace("'", "\\'"); + string county_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "county_name"))?.Replace("'", "\\'"); + string detail_info = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "detail_info"))?.Replace("'", "\\'"); + string tel_number = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "tel_number"))?.Replace("'", "\\'"); + // 收件人 + string user_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "receiver"))?.Replace("'", "\\'"); + if (string.IsNullOrEmpty(user_id)) + return "{\"code\":500,\"msg\":\"缺少用户编号\"}"; + if (string.IsNullOrEmpty(shop_id)) + return "{\"code\":500,\"msg\":\"缺少店铺编号\"}"; + if (string.IsNullOrEmpty(province_name) || string.IsNullOrEmpty(city_name) || string.IsNullOrEmpty(county_name) || string.IsNullOrEmpty(detail_info)) + return "{\"code\":500,\"msg\":\"省市区或详细地址不完整\"}"; + if (string.IsNullOrEmpty(user_name)) + return "{\"code\":500,\"msg\":\"缺少收件人\"}"; + if (string.IsNullOrEmpty(tel_number)) + return "{\"code\":500,\"msg\":\"缺少收件人电话\"}"; + + string conn = System.Configuration.ConfigurationManager.ConnectionStrings["ConnKJD"].ConnectionString; + MysqlUtils mySql = new MysqlUtils(conn); + + string sql = "SELECT 1 FROM `wxxd`.`wx_shop_default_address` where user_id='" + user_id + "' AND shop_id='" + shop_id + "'"; + string where = ""; + sql += where; + var exist = mySql.ExecuteFirstInt(sql); + if (!mySql.Message.IsNullOrEmpty()) + { + mySql.Close(); + return "{\"code\":501,\"msg\":\"" + mySql.Message + "\"}"; + } + + if (exist == 0) + { + sql = " INSERT INTO `wxxd`.`wx_shop_default_address` (user_id,shop_id,province_name,city_name,county_name,detail_info,tel_number,user_name)" + + " VALUES (@user_id,@shop_id,@province_name,@city_name,@county_name,@detail_info,@tel_number,@user_name);"; + } + else + { + sql = "UPDATE `wxxd`.`wx_shop_default_address` SET "; + if (province_name != null) + sql += " province_name=@province_name,"; + if (city_name != null) + sql += " city_name=@city_name,"; + if (county_name != null) + sql += " county_name=@county_name,"; + if (detail_info != null) + sql += " detail_info=@detail_info,"; + if (tel_number != null) + sql += " tel_number=@tel_number,"; + if (user_name != null) + sql += " user_name=@user_name,"; + sql = sql.TrimEnd(','); + sql += " WHERE user_id=@user_id and shop_id=@shop_id;"; + } + + List paramLst = new List(); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "province_name", Value = province_name, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "city_name", Value = city_name, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "county_name", Value = county_name, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "detail_info", Value = detail_info, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "tel_number", Value = tel_number, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "user_name", Value = user_name, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "user_id", Value = user_id, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "shop_id", Value = shop_id, }); + mySql.ExecuteNonQuery(sql, paramLst.ToArray()); + mySql.Close(); + if (string.IsNullOrEmpty(mySql.Message)) + { + return "{\"code\":200,\"msg\":\"success\",\"data\":\"\"}"; + } + else + { + return "{\"code\":50003,\"msg\":\"" + mySql.Message + "\",\"data\":\"\"}"; + } + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + public string WXGetShopDefaultAddressList(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + var timeCalc = DateTime.Now; + if (!WXUserManage.GetSign(inputData)) + return "{\"code\":999,\"msg\":\"校验失败\"}"; + + int page = RegexUtils.GetStringQuery(ref inputData, "page").ParseToInt(); + int page_size = RegexUtils.GetStringQuery(ref inputData, "page_size").ParseToInt(200); + string user_id = RegexUtils.GetStringQuery(ref inputData, "user_name")?.Replace("'", "\\'"); + string shop_ids = RegexUtils.GetStringQuery(ref inputData, "shop_ids")?.Replace("'", "\\'"); + string not_count = RegexUtils.GetStringQuery(ref inputData, "not_count")?.Replace("'", "\\'"); + + string conn = System.Configuration.ConfigurationManager.ConnectionStrings["ConnKJD"].ConnectionString; + MysqlUtils mySql = new MysqlUtils(conn); + + string sql = ""; + var count = -1; + + sql = "SELECT count(*) FROM `wxxd`.`wx_shop_default_address` where 1=1"; + string where = ""; + if (user_id != null) + where += " and user_id='" + user_id + "'"; + if (shop_ids != null) + where += " and shop_id IN ('" + shop_ids.Replace(",", "','") + "')"; + sql += where; + sql += ";"; + + if (not_count != "true") + count = mySql.ExecuteRowCount(sql); + + DataTable dt; + if (count == 0) + { + dt = new DataTable(); + } + else + { + sql = "SELECT * FROM `wxxd`.`wx_shop_default_address` where 1=1"; + sql += where; + sql += " order by id desc limit " + Math.Max(0, page - 1) * page_size + "," + page_size + ";"; + dt = mySql.ExecuteDataTable(sql); + } + mySql.Close(); + + if (dt != null) + { + try + { + List WXShopDefaultAddressInfoLst = new List(); + foreach (DataRow row in dt.Rows) + { + WXShopDefaultAddressInfoLst.Add(new WXShopDefaultAddressInfo() + { + id = row["id"].ParseToInt(), + city_name = row["city_name"].ParseToString(), + county_name = row["county_name"].ParseToString(), + detail_info = row["detail_info"].ParseToString(), + province_name = row["province_name"].ParseToString(), + shop_id = row["shop_id"].ParseToString(), + tel_number = row["tel_number"].ParseToString(), + user_id = row["user_id"].ParseToString(), + user_name = row["user_name"].ParseToString(), + add_time = Convert.ToDateTime(row["add_time"]), + mdy_time = Convert.ToDateTime(row["mdy_time"]), + }); + } + JsonSerializerSettings jsonSetting = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }; + var data = JsonUtils.SerializeObjectToString(WXShopDefaultAddressInfoLst, jsonSetting); + var seconds = (DateTime.Now - timeCalc).TotalSeconds.ToString("0.000"); + return "{\"code\":200,\"msg\":\"success\",\"data\":" + data + ",\"count\":" + count + ",\"seconds\":" + seconds + "}"; + } + catch (Exception ex) + { + return "{\"code\":500,\"msg\":\"" + ex.Message + "\",\"data\":[],\"count\":" + 0 + "}"; + } + } + else + { + return "{\"code\":500,\"msg\":\"" + mySql.Message + "\",\"data\":[],\"count\":" + 0 + "}"; + } + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + public string WXDelShopDefaultAddress(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + var timeCalc = DateTime.Now; + if (!WXUserManage.GetSign(inputData)) + return "{\"code\":999,\"msg\":\"校验失败\"}"; + + int page = RegexUtils.GetStringQuery(ref inputData, "page").ParseToInt(); + int page_size = RegexUtils.GetStringQuery(ref inputData, "page_size").ParseToInt(200); + string user_id = RegexUtils.GetStringQuery(ref inputData, "user_name")?.Replace("'", "\\'"); + string shop_ids = RegexUtils.GetStringQuery(ref inputData, "shop_ids")?.Replace("'", "\\'"); + if (shop_ids.IsNullOrEmpty() || user_id.IsNullOrEmpty()) + { + return "{\"code\":500,\"msg\":\"店铺编号不能为空\"}"; + } + + string conn = System.Configuration.ConfigurationManager.ConnectionStrings["ConnKJD"].ConnectionString; + MysqlUtils mySql = new MysqlUtils(conn); + + string sql = ""; + + sql = "Delete FROM `wxxd`.`wx_shop_default_address` where user_id = '" + user_id + "' AND shop_id in ('" + shop_ids.Replace(",", "','") + "')"; + sql += ";"; + + var rst = mySql.ExecuteNonQuery(sql); + mySql.Close(); + if (rst) + { + return "{\"code\":200,\"msg\":\"success\"}"; + } + else + { + return "{\"code\":500,\"msg\":\"" + mySql.Message + "\"}"; + } + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + + + public string WXAddMdyOrderDecryptAddress(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + if (!WXUserManage.GetSign(inputData)) + return "{\"code\":999,\"msg\":\"校验失败\"}"; + + // 软件用户名 + string shop_id = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "shop_id"))?.Replace("'", "\\'"); + string order_id = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "order_id"))?.Replace("'", "\\'"); + string order_address = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "order_address"))?.Replace("'", "\\'"); + + if (string.IsNullOrEmpty(shop_id)) + return "{\"code\":500,\"msg\":\"缺少店铺编号\"}"; + if (string.IsNullOrEmpty(order_id)) + return "{\"code\":500,\"msg\":\"缺少订单编号\"}"; + if (string.IsNullOrEmpty(order_address)) + return "{\"code\":500,\"msg\":\"缺少地址信息\"}"; + + string conn = System.Configuration.ConfigurationManager.ConnectionStrings["ConnKJD"].ConnectionString; + MysqlUtils mySql = new MysqlUtils(conn); + + string sql = "SELECT 1 FROM `wxxd`.`order_decrypt_address` where order_id='" + order_id + "' AND shop_id='" + shop_id + "'"; + string where = ""; + sql += where; + var exist = mySql.ExecuteFirstInt(sql); + if (!mySql.Message.IsNullOrEmpty()) + { + mySql.Close(); + return "{\"code\":501,\"msg\":\"" + mySql.Message + "\"}"; + } + + if (exist == 0) + { + sql = " INSERT INTO `wxxd`.`order_decrypt_address` (shop_id,order_id,order_address)" + + " VALUES (@shop_id,@order_id,@order_address);"; + } + else + { + sql = "UPDATE `wxxd`.`order_decrypt_address` SET "; + if (order_address != null) + sql += " order_address=@order_address,"; + sql = sql.TrimEnd(','); + sql += " WHERE order_id=@order_id and shop_id=@shop_id;"; + } + + List paramLst = new List(); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "order_address", Value = order_address, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "order_id", Value = order_id, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "shop_id", Value = shop_id, }); + mySql.ExecuteNonQuery(sql, paramLst.ToArray()); + mySql.Close(); + if (string.IsNullOrEmpty(mySql.Message)) + { + return "{\"code\":200,\"msg\":\"success\",\"data\":\"\"}"; + } + else + { + return "{\"code\":50003,\"msg\":\"" + mySql.Message + "\",\"data\":\"\"}"; + } + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + public string WXGetOrderDecryptAddress(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + var timeCalc = DateTime.Now; + if (!WXUserManage.GetSign(inputData)) + return "{\"code\":999,\"msg\":\"校验失败\"}"; + + int page = RegexUtils.GetStringQuery(ref inputData, "page").ParseToInt(); + int page_size = RegexUtils.GetStringQuery(ref inputData, "page_size").ParseToInt(200); + string order_ids = RegexUtils.GetStringQuery(ref inputData, "order_ids")?.Replace("'", "\\'"); + string not_count = RegexUtils.GetStringQuery(ref inputData, "not_count")?.Replace("'", "\\'"); + if (string.IsNullOrEmpty(order_ids)) + return "{\"code\":500,\"msg\":\"订单编号不能为空\"}"; + + string conn = System.Configuration.ConfigurationManager.ConnectionStrings["ConnKJD"].ConnectionString; + MysqlUtils mySql = new MysqlUtils(conn); + + string sql = ""; + var count = -1; + + sql = "SELECT count(*) FROM `wxxd`.`order_decrypt_address` where 1=1"; + string where = ""; + if (order_ids != null) + where += " and order_id IN ('" + order_ids.Replace(",", "','") + "')"; + sql += where; + sql += ";"; + + if (not_count != "true") + count = mySql.ExecuteRowCount(sql); + + DataTable dt; + if (count == 0) + { + dt = new DataTable(); + } + else + { + sql = "SELECT * FROM `wxxd`.`order_decrypt_address` where 1=1"; + sql += where; + sql += " order by id desc limit " + Math.Max(0, page - 1) * page_size + "," + page_size + ";"; + dt = mySql.ExecuteDataTable(sql); + } + mySql.Close(); + + if (dt != null) + { + try + { + List WXOrderAddressInfoLst = new List(); + foreach (DataRow row in dt.Rows) + { + WXOrderAddressInfoLst.Add(new WXOrderDecryptAddressInfo() + { + id = row["id"].ParseToInt(), + shop_id = row["shop_id"].ParseToString(), + order_address = row["order_address"].ParseToString(), + order_id = row["order_id"].ParseToString(), + add_time = Convert.ToDateTime(row["add_time"]), + mdy_time = Convert.ToDateTime(row["mdy_time"]), + }); + } + JsonSerializerSettings jsonSetting = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }; + var data = JsonUtils.SerializeObjectToString(WXOrderAddressInfoLst, jsonSetting); + var seconds = (DateTime.Now - timeCalc).TotalSeconds.ToString("0.000"); + return "{\"code\":200,\"msg\":\"success\",\"data\":" + data + ",\"count\":" + count + ",\"seconds\":" + seconds + "}"; + } + catch (Exception ex) + { + return "{\"code\":500,\"msg\":\"" + ex.Message + "\",\"data\":[],\"count\":" + 0 + "}"; + } + } + else + { + return "{\"code\":500,\"msg\":\"" + mySql.Message + "\",\"data\":[],\"count\":" + 0 + "}"; + } + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + + public string WXAddMdyBuyUrlNotes(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + if (!WXUserManage.GetSign(inputData)) + return "{\"code\":999,\"msg\":\"校验失败\"}"; + + // 软件用户名 + string spu_code = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "spu_code"))?.Replace("'", "\\'"); + string user_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "main_user_name"))?.Replace("'", "\\'"); + string buy_url_notes = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "buy_url_notes"))?.Replace("'", "\\'"); + + if (string.IsNullOrEmpty(spu_code)) + return "{\"code\":500,\"msg\":\"缺少店铺编号\"}"; + if (string.IsNullOrEmpty(user_name)) + return "{\"code\":500,\"msg\":\"缺少用户名\"}"; + if (string.IsNullOrEmpty(buy_url_notes)) + return "{\"code\":500,\"msg\":\"缺少地址信息\"}"; + + string conn = System.Configuration.ConfigurationManager.ConnectionStrings["ConnKJD"].ConnectionString; + MysqlUtils mySql = new MysqlUtils(conn); + + string sql = "SELECT 1 FROM `bxx`.`product_buy_url_notes` where user_name='" + user_name + "' AND spu_code='" + spu_code + "'"; + string where = ""; + sql += where; + var exist = mySql.ExecuteFirstInt(sql); + if (!mySql.Message.IsNullOrEmpty()) + { + mySql.Close(); + return "{\"code\":501,\"msg\":\"" + mySql.Message + "\"}"; + } + + if (exist == 0) + { + sql = " INSERT INTO `bxx`.`product_buy_url_notes` (spu_code,user_name,buy_url_notes)" + + " VALUES (@spu_code,@user_name,@buy_url_notes);"; + } + else + { + sql = "UPDATE `bxx`.`product_buy_url_notes` SET "; + if (buy_url_notes != null) + sql += " buy_url_notes=@buy_url_notes,"; + sql = sql.TrimEnd(','); + sql += " WHERE user_name=@user_name and spu_code=@spu_code;"; + } + + List paramLst = new List(); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "buy_url_notes", Value = buy_url_notes, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "user_name", Value = user_name, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "spu_code", Value = spu_code, }); + mySql.ExecuteNonQuery(sql, paramLst.ToArray()); + mySql.Close(); + if (string.IsNullOrEmpty(mySql.Message)) + { + return "{\"code\":200,\"msg\":\"success\",\"data\":\"\"}"; + } + else + { + return "{\"code\":50003,\"msg\":\"" + mySql.Message + "\",\"data\":\"\"}"; + } + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + public string WXGetBuyUrlNotes(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + var timeCalc = DateTime.Now; + if (!WXUserManage.GetSign(inputData)) + return "{\"code\":999,\"msg\":\"校验失败\"}"; + + int page = RegexUtils.GetStringQuery(ref inputData, "page").ParseToInt(); + int page_size = RegexUtils.GetStringQuery(ref inputData, "page_size").ParseToInt(200); + string spu_codes = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "spu_codes"))?.Replace("'", "\\'"); + string user_name = RegexUtils.GetStringQuery(ref inputData, "main_user_name")?.Replace("'", "\\'"); + string not_count = RegexUtils.GetStringQuery(ref inputData, "not_count")?.Replace("'", "\\'"); + if (string.IsNullOrEmpty(spu_codes)) + return "{\"code\":500,\"msg\":\"商品编码不能为空\"}"; + if (string.IsNullOrEmpty(user_name)) + return "{\"code\":500,\"msg\":\"用户名不能为空\"}"; + + string conn = System.Configuration.ConfigurationManager.ConnectionStrings["ConnKJD"].ConnectionString; + MysqlUtils mySql = new MysqlUtils(conn); + + string sql = ""; + var count = -1; + + sql = "SELECT COUNT(*) FROM `bxx`.`product_buy_url_notes` WHERE 1=1"; + string where = ""; + if (spu_codes != null) + where += " and spu_code IN ('" + spu_codes.Replace(",", "','") + "')"; + if (user_name != null) + where += " and user_name='" + user_name + "'"; + sql += where; + sql += ";"; + + if (not_count != "true") + count = mySql.ExecuteRowCount(sql); + + DataTable dt; + if (count == 0) + { + dt = new DataTable(); + } + else + { + sql = "SELECT * FROM `bxx`.`product_buy_url_notes` WHERE 1=1"; + sql += where; + sql += " order by id desc limit " + Math.Max(0, page - 1) * page_size + "," + page_size + ";"; + dt = mySql.ExecuteDataTable(sql); + } + mySql.Close(); + + if (dt != null) + { + try + { + List WXBuyUrlNotesInfoLst = new List(); + foreach (DataRow row in dt.Rows) + { + WXBuyUrlNotesInfoLst.Add(new WXBuyUrlNotesInfo() + { + id = row["id"].ParseToInt(), + user_name = row["user_name"].ParseToString(), + spu_code = row["spu_code"].ParseToString(), + buy_url_notes = row["buy_url_notes"].ParseToString(), + add_time = Convert.ToDateTime(row["add_time"]), + mdy_time = Convert.ToDateTime(row["mdy_time"]), + }); + } + JsonSerializerSettings jsonSetting = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }; + var data = JsonUtils.SerializeObjectToString(WXBuyUrlNotesInfoLst, jsonSetting); + var seconds = (DateTime.Now - timeCalc).TotalSeconds.ToString("0.000"); + return "{\"code\":200,\"msg\":\"success\",\"data\":" + data + ",\"count\":" + count + ",\"seconds\":" + seconds + "}"; + } + catch (Exception ex) + { + return "{\"code\":500,\"msg\":\"" + ex.Message + "\",\"data\":[],\"count\":" + 0 + "}"; + } + } + else + { + return "{\"code\":500,\"msg\":\"" + mySql.Message + "\",\"data\":[],\"count\":" + 0 + "}"; + } + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + public string WXAddMdy29WxPddShop(string inputData, bool isAdmin = false) + { + if (!string.IsNullOrEmpty(inputData)) + { + string user_name = RegexUtils.GetStringQuery(ref inputData, "user_name"); + if (isAdmin) + user_name = RegexUtils.GetStringQuery(ref inputData, "shop_user_name"); + string login_name = RegexUtils.GetStringQuery(ref inputData, "login_name"); + string login_pass = RegexUtils.GetStringQuery(ref inputData, "login_pass"); + string sub_user_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "sub_user_name")); + string cookie = RegexUtils.GetStringQuery(ref inputData, "cookie"); + string cookie2 = RegexUtils.GetStringQuery(ref inputData, "cookie2"); + string anti_contents = RegexUtils.GetStringQuery(ref inputData, "anti_contents"); + string shop_id = RegexUtils.GetStringQuery(ref inputData, "shop_id"); + string mall_id = RegexUtils.GetStringQuery(ref inputData, "mall_id"); + string shop_account = RegexUtils.GetStringQuery(ref inputData, "shop_account"); + string group_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "group_name")); + string notes = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "notes")); + int r2 = 0; + int.TryParse(RegexUtils.GetStringQuery(ref inputData, "r2"), out r2); + + if (string.IsNullOrEmpty(user_name)) + { + return "{\"code\":500,\"msg\":\"没有用户名\"}"; + } + if (string.IsNullOrEmpty(login_name)) + { + return "{\"code\":501,\"msg\":\"没有店铺登录名\"}"; + } + + string conn = System.Configuration.ConfigurationManager.ConnectionStrings["ConnKJD"].ConnectionString; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = ""; + if (string.IsNullOrEmpty(shop_id)) + sql = "select exists (select 1 from wxxd.pdd_shop where login_name='" + login_name + "' and user_name='" + user_name + "')"; + else + sql = "select exists (select 1 from wxxd.pdd_shop where login_name='" + login_name + "' and user_name='" + user_name + + "' and shop_id='" + shop_id + "')"; + var exist = mySql.ExecuteFirstInt(sql); + if (exist > 0) + { + mySql.Close(); + //return "{\"code\":500,\"msg\":\"店铺" + login_name + " " + shop_account + "已存在\"}"; + return WXMdy29WxPddShop(inputData); + } + + sql = "insert into wxxd.pdd_shop (login_name,login_pass,cookie,cookie2,anti_contents,shop_account,shop_id," + + "mall_id,sub_user_name,user_name,group_name,notes,add_time,mdy_time) " + + "values ('" + login_name + "','" + login_pass + "','" + cookie + "','" + cookie2 + "','" + anti_contents + "','" + shop_account + "','" + shop_id + + "','" + mall_id + "','" + sub_user_name + "','" + user_name + "','" + group_name + "','" + notes + "','" + + 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\":200,\"msg\":\"success\"}"; + } + } + return "{\"code\":19999,\"msg\":\"未知错误\"}"; + } + + public string WXMdy29WxPddShop(string inputData, bool isAdmin = false) + { + if (!string.IsNullOrEmpty(inputData)) + { + string user_name = RegexUtils.GetStringQuery(ref inputData, "user_name"); + if (isAdmin) + user_name = RegexUtils.GetStringQuery(ref inputData, "shop_user_name"); + string login_name = RegexUtils.GetStringQuery(ref inputData, "login_name"); + string login_pass = RegexUtils.GetStringQuery(ref inputData, "login_pass"); + string sub_user_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "sub_user_name")); + //string cookie = RegexUtils.GetStringQuery(ref inputData, "cookie"); + //string cookie2 = RegexUtils.GetStringQuery(ref inputData, "cookie2"); + string anti_contents = RegexUtils.GetStringQuery(ref inputData, "anti_contents"); + string new_shop_id = RegexUtils.GetStringQuery(ref inputData, "new_shop_id"); + string old_shop_id = RegexUtils.GetStringQuery(ref inputData, "shop_id"); + string mall_id = RegexUtils.GetStringQuery(ref inputData, "mall_id"); + string shop_account = RegexUtils.GetStringQuery(ref inputData, "shop_account"); + string group_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "group_name")); + string notes = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "notes")); + string login_status = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "login_status")); + + int r2 = 0; + int.TryParse(RegexUtils.GetStringQuery(ref inputData, "r2"), out r2); + + if (string.IsNullOrEmpty(user_name)) + { + return "{\"code\":500,\"msg\":\"没有用户名\"}"; + } + if (string.IsNullOrEmpty(login_name)) + { + return "{\"code\":501,\"msg\":\"没有店铺登录名\"}"; + } + + string conn = System.Configuration.ConfigurationManager.ConnectionStrings["ConnKJD"].ConnectionString; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = "update wxxd.pdd_shop set"; + if (login_pass != null) + sql += " login_pass='" + login_pass + "',"; + //if (cookie != null) + // sql += " cookie='" + cookie + "',"; + //if (cookie2 != null) + // sql += " cookie2='" + cookie2 + "',"; + if (anti_contents != null) + sql += " anti_contents='" + anti_contents + "',"; + if (new_shop_id != null) + sql += " shop_id='" + new_shop_id + "',"; + if (mall_id != null) + sql += " mall_id='" + mall_id + "',"; + if (shop_account != null) + sql += " shop_account='" + shop_account + "',"; + if (sub_user_name != null) + sql += " sub_user_name='" + sub_user_name + "',"; + if (group_name != null) + sql += " group_name='" + group_name + "',"; + if (notes != null) + sql += " notes='" + notes + "',"; + if (login_status != null) + sql += " login_status='" + login_status + "',"; + sql = sql.TrimEnd(','); + sql += " where login_name='" + login_name + "' and (user_name='" + user_name + "' or sub_user_name like '%" + user_name + "%')"; + if (!string.IsNullOrEmpty(old_shop_id)) + sql += " and shop_id='" + old_shop_id + "'"; + + var rst = mySql.ExecuteNonQuery(sql); + mySql.Close(); + if (rst) + { + return "{\"code\":200,\"msg\":\"success\"}"; + } + } + return "{\"code\":19999,\"msg\":\"未知错误\"}"; + } + + public string WXMdy29WxPddCookieAndLoginStatus(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + string login_name = RegexUtils.GetStringQuery(ref inputData, "login_name"); + string cookie = RegexUtils.GetStringQuery(ref inputData, "cookie"); + string cookie2 = RegexUtils.GetStringQuery(ref inputData, "cookie2"); + string login_status = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "login_status")); + string login_status2 = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "login_status2")); + string pddid = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "pddid")); + + int r2 = 0; + int.TryParse(RegexUtils.GetStringQuery(ref inputData, "r2"), out r2); + + if (string.IsNullOrWhiteSpace(login_name)) + { + return "{\"code\":500,\"msg\":\"店铺没有登录名\"}"; + } + + string conn = System.Configuration.ConfigurationManager.ConnectionStrings["ConnKJD"].ConnectionString; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = "update wxxd.pdd_shop set"; + if (cookie != null) + sql += " cookie='" + cookie + "',"; + if (cookie2 != null) + sql += " cookie2='" + cookie2 + "',"; + if (login_status != null) + sql += " login_status='" + login_status + "',"; + if (login_status2 != null) + sql += " login_status2='" + login_status2 + "',"; + if (pddid != null) + sql += " pddid='" + pddid + "',"; + sql = sql.TrimEnd(','); + sql += " where login_name='" + login_name + "'"; + + var rst = mySql.ExecuteNonQuery(sql); + mySql.Close(); + if (rst) + { + return "{\"code\":200,\"msg\":\"success\"}"; + } + } + return "{\"code\":19999,\"msg\":\"未知错误\"}"; + } + + public string WXDel29WxPddShop(string inputData, bool isAdmin = false) + { + if (!string.IsNullOrEmpty(inputData)) + { + var login_name = RegexUtils.GetStringQuery(ref inputData, "login_name"); + var user_name = RegexUtils.GetStringQuery(ref inputData, "user_name"); + if (isAdmin) + user_name = RegexUtils.GetStringQuery(ref inputData, "shop_user_name"); + var shop_id = RegexUtils.GetStringQuery(ref inputData, "shop_id"); + var password = RegexUtils.GetStringQuery(ref inputData, "password"); + int r2 = 0; + int.TryParse(RegexUtils.GetStringQuery(ref inputData, "r2"), out r2); + + if (string.IsNullOrEmpty(user_name)) + { + return "{\"code\":500,\"msg\":\"没有用户名\"}"; + } + if (string.IsNullOrEmpty(login_name)) + { + return "{\"code\":501,\"msg\":\"没有店铺登录名\"}"; + } + + string conn = System.Configuration.ConfigurationManager.ConnectionStrings["ConnKJD"].ConnectionString; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = "delete from wxxd.pdd_shop where user_name='" + user_name + "' and login_name='" + login_name + "'"; + if (!string.IsNullOrEmpty(shop_id)) + sql += " and shop_id='" + shop_id + "'"; + + var rst = mySql.ExecuteNonQuery(sql); + mySql.Close(); + if (rst) + { + return "{\"code\":200,\"msg\":\"success\"}"; + } + } + return "{\"code\":19999,\"msg\":\"未知错误\"}"; + } + + public string WXGet29WxPddShop(string inputData, bool isAdmin = false) + { + if (!string.IsNullOrEmpty(inputData)) + { + var user_name = RegexUtils.GetStringQuery(ref inputData, "user_name"); + var password = RegexUtils.GetStringQuery(ref inputData, "password"); + var search_id = RegexUtils.GetStringQuery(ref inputData, "search_id"); + var search_user_name = RegexUtils.GetStringQuery(ref inputData, "search_user_name"); + var search_login_name = RegexUtils.GetStringQuery(ref inputData, "search_login_name"); + var search_notes = RegexUtils.GetStringQuery(ref inputData, "search_notes"); + var search_name = RegexUtils.GetStringQuery(ref inputData, "search_name"); + var operate_sub_sa_name = RegexUtils.GetStringQuery(ref inputData, "operate_sub_sa_name")?.Replace("'", "\\'"); + + // 特殊处理一下修复客户端店铺导入没有立即登录导致的cookie串的bug + //var shop_ids = RegexUtils.GetStringQuery(ref inputData, "shop_ids")?.Replace("'", ""); + var shop_ids = RegexUtils.GetStringQuery(ref inputData, "shop_ids"); + if (shop_ids == "''") + shop_ids = "999999999999999"; + shop_ids = shop_ids?.Replace("'", ""); + if (!string.IsNullOrWhiteSpace(shop_ids)) + { + List shopIdLst = shop_ids.Split(',').ToList(); + shop_ids = "'" + string.Join("','", shopIdLst) + "'"; + } + var shop_names = RegexUtils.GetStringQuery(ref inputData, "shop_names"); + if (!string.IsNullOrWhiteSpace(shop_names)) + { + List shopNameLst = shop_names.Split(',').ToList(); + shop_names = "'" + string.Join("','", shopNameLst) + "'"; + } + var shop_notes = RegexUtils.GetStringQuery(ref inputData, "shop_notes"); + if (!string.IsNullOrWhiteSpace(shop_notes)) + { + List shopNotesLst = shop_notes.Split(',').ToList(); + shop_notes = "'" + string.Join("','", shopNotesLst) + "'"; + } + + var page = RegexUtils.GetStringQuery(ref inputData, "page").ParseToInt(); + var page_size = RegexUtils.GetStringQuery(ref inputData, "page_size").ParseToInt(); + + if (page_size == 0) + page_size = 50; + 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 COUNT(s.id) FROM wxxd.pdd_shop s WHERE 1=1"; + + //where子句 + string where = ""; + if (isAdmin) + where += " and (s.cookie='' or s.shop_id!='')"; + if (!isAdmin) + where += " and (s.user_name='" + user_name + "' or s.sub_user_name like '%" + user_name + "%')"; + if (!string.IsNullOrWhiteSpace(operate_sub_sa_name)) + where += " and s.operate_sub_sa_name='" + operate_sub_sa_name + "'"; + if (!string.IsNullOrWhiteSpace(search_user_name)) + where += " and s.user_name like '%" + search_user_name + "%'"; + if (!string.IsNullOrWhiteSpace(search_login_name)) + where += " and s.login_name like '%" + search_login_name + "%'"; + if (!string.IsNullOrWhiteSpace(search_notes)) + where += " and s.notes like '%" + search_notes + "%'"; + if (!string.IsNullOrWhiteSpace(search_id)) + where += " and s.shop_id like '%" + search_id + "%'"; + if (!string.IsNullOrWhiteSpace(search_name)) + where += " and s.shop_account like '%" + search_name + "%'"; + if (!string.IsNullOrWhiteSpace(shop_ids)) + where += " and s.shop_id in (" + shop_ids + ")"; + if (!string.IsNullOrWhiteSpace(shop_names)) + where += " and s.shop_account in (" + shop_names + ")"; + if (!string.IsNullOrWhiteSpace(shop_notes)) + where += " and s.notes in (" + shop_notes + ")"; + sql += where; + + var count = mySql.ExecuteRowCount(sql); + + DataTable dt; + if (count == 0) + { + dt = new DataTable(); + } + else + { + sql = "SELECT s.id,s.login_name,s.login_pass,s.cookie,s.cookie2,s.anti_contents,s.pddid,s.mall_id,s.shop_id,s.shop_account,s.sub_user_name," + + "s.user_name,s.company_name,s.notes,s.login_status,s.login_status2," + + "s.add_time,s.mdy_time,s.add_sub_sa_time,s.operate_sub_sa_name"; + //sql += " FROM bxx.shop s WHERE 1=1"; + sql += " FROM wxxd.pdd_shop s WHERE 1=1"; + + sql += where; // where 子句 + + sql += " ORDER BY s.id DESC"; + sql += " LIMIT " + Math.Max(page - 1, 0) * page_size + "," + page_size; + dt = mySql.ExecuteDataTable(sql); + } + + mySql.Close(); + if (dt != null) + { + List shopList = new List(); + foreach (DataRow row in dt.Rows) + { + ShopParam shop = new ShopParam + { + id = Convert.ToInt32(row["id"]), + login_name = row["login_name"].ToString(), + login_pass = row["login_pass"].ToString(), + cookie = row["cookie"].ToString(), + cookie2 = row["cookie2"].ToString(), + anti_contents = row["anti_contents"].ToString(), + shop_id = row["shop_id"].ToString(), + shop_account = row["shop_account"].ToString(), + sub_user_name = row["sub_user_name"].ToString(), + user_name = row["user_name"].ToString(), + company_name = row["company_name"].ToString(), + notes = row["notes"].ToString(), + login_status = row["login_status"].ToString(), + login_status2 = row["login_status2"].ToString(), + operate_sub_sa_name = row["operate_sub_sa_name"].ParseToString(), + pddid = row["pddid"].ParseToString(), + mall_id = row["mall_id"].ParseToString(), + }; + shopList.Add(shop); + } + + var data = JsonUtils.SerializeObjectToString(shopList); + //return "{\"code\":200,\"msg\":\"success\",\"data\":" + data + ",\"c\":\"" + EncrypUtil.Encryption(r2) + "\"}"; + return "{\"code\":200,\"msg\":\"success\",\"data\":" + data + ",\"count\":" + count + "}"; + } + } + return "{\"code\":19999,\"msg\":\"未知错误\"}"; + } + + public string E57GetWxTokens(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + var time = RegexUtils.GetStringQuery(ref inputData, "time").ParseToInt(); + string time1 = RegexUtils.GetStringQuery(ref inputData, "code"); + if (time1 != EncrypUtil.Encryption(time)) + return "{\"code\":50000,\"msg\":\"校验失败\"}"; + + var id = (RegexUtils.GetStringQuery(ref inputData, "db_id")?.Replace("'", "\\'")).ParseToInt(); + if (id == 0) + id = 1; + + string conn = System.Configuration.ConfigurationManager.ConnectionStrings["ConnKJD"].ConnectionString; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = "select tokens,mdy_time from wxxd.wx_token WHERE id=" + id + ";"; + var rst = mySql.ExecuteDataTableRow(sql); + mySql.Close(); + + if (!string.IsNullOrEmpty(mySql.Message)) + { + return "{\"code\":500,\"msg\":\"" + mySql.Message + "\"}"; + } + + try + { + string tokens = rst["tokens"].ParseToString(); + var mdyTime = Convert.ToDateTime(rst["mdy_time"]); + if (mdyTime.AddMinutes(60) < DateTime.Now) + { + //var tokenRst = HttpUtils.e57GetResponse("https://po.e57.cn/prod-api/api/sys-api/system/open/api/shop/list?userName=阿杰账户", ""); + var tokenRst = HttpUtils.e57GetResponse("https://po.e57.cn/prod-api/api/sys-api/system/open/api/shop/list?userName=合肥测试一组", ""); + if (!tokenRst.Contains("\"code\":0")) + tokenRst = HttpUtils.e57GetResponse("https://po.e57.cn/prod-api/api/sys-api/system/open/api/shop/list?userName=合肥测试一组", ""); + //https://po.e57.cn/prod-api/api/sys-api/system/open/api/shop/list?userName=pdd用户 + if (!tokenRst.Contains("\"code\":0")) + { + var errMsg = RegexUtils.GetStringJson(ref tokenRst, "msg"); + if (string.IsNullOrEmpty(errMsg)) + errMsg = tokenRst; + return "{\"code\":500,\"msg\":\"" + errMsg + "\"}"; + } + mdyTime = DateTime.Now; + tokens = JsonUtils.SerializeObjectToString(JObject.Parse(tokenRst)["list"]); + + conn = System.Configuration.ConfigurationManager.ConnectionStrings["ConnKJD"].ConnectionString; + mySql = new MysqlUtils(conn); + sql = "update wxxd.wx_token set tokens='" + tokens + "' where id=1;"; + bool su = mySql.ExecuteNonQuery(sql); + mySql.Close(); + + if (!string.IsNullOrEmpty(mySql.Message)) + { + return "{\"code\":500,\"msg\":\"" + mySql.Message + "\"}"; + } + } + return "{\"code\":200,\"tokens\":" + tokens + ",\"mdy_time\":\"" + mdyTime.ToString("yyyy-MM-dd HH:mm:ss") + "\"}"; + } + catch (Exception ex) + { + return "{\"code\":500,\"msg\":\"" + ex.Message + "\"}"; + } + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + public string E57GetWxShopToken(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + var time = RegexUtils.GetStringQuery(ref inputData, "time").ParseToInt(); + string time1 = RegexUtils.GetStringQuery(ref inputData, "code"); + if (time1 != EncrypUtil.Encryption(time)) + return "{\"code\":50000,\"msg\":\"校验失败\"}"; + + var shop_id = RegexUtils.GetStringQuery(ref inputData, "shop_id")?.Replace("'", "\\'"); + var url = "https://po.e57.cn/prod-api/api/sys-api/system/open/api/shop/info?appId=" + shop_id; + + var tokenRst = HttpUtils.e57GetResponse(url, ""); + if (!tokenRst.Contains("\"code\":0")) + tokenRst = HttpUtils.e57GetResponse(url, ""); + return tokenRst; + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + public static bool GetTimeSign(string sign) + { + bool isSign = false; + for (int i = 0; i <= 5; i++) + { + if (EncrypUtil.GetMd5(DateTime.Now.AddMinutes(i).ToString("yyyyMMddHHmm") + "wxxd").ToLower() == sign.ToLower()) + { + isSign = true; + break; + } + else if (i > 0 && EncrypUtil.GetMd5(DateTime.Now.AddMinutes(-i).ToString("yyyyMMddHHmm") + "wxxd").ToLower() == sign.ToLower()) + { + isSign = true; + break; + } + } + return isSign; + } + } } \ No newline at end of file diff --git a/KJD_WebService/Controllers/WX/WXShopController.cs b/KJD_WebService/Controllers/WX/WXShopController.cs index 3d5c525..58a9cdf 100644 --- a/KJD_WebService/Controllers/WX/WXShopController.cs +++ b/KJD_WebService/Controllers/WX/WXShopController.cs @@ -11,7 +11,7 @@ namespace KJD_Web.Controllers.WX { [RoutePrefix("wxxd_shop")] [Route("{action}")] - public class WXShopController:AsmxApiController + public partial class WXShopController:AsmxApiController { public IHttpActionResult get_shop_list() diff --git a/KJD_WebService/Controllers/WX/WXShop_N_Controller.cs b/KJD_WebService/Controllers/WX/WXShop_N_Controller.cs new file mode 100644 index 0000000..e7b22de --- /dev/null +++ b/KJD_WebService/Controllers/WX/WXShop_N_Controller.cs @@ -0,0 +1,40 @@ +using KJD_Web.Requests; +using KJD_Web.Services.Shops; +using Store.Framework.Dtos; +using Store.Framework.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; +using System.Web.Http; + +namespace KJD_Web.Controllers.WX; + +public partial class WXShopController : AsmxApiController +{ + private readonly ShopService _shopService; + + public WXShopController(ShopService shopService) + { + _shopService = shopService; + } + + /// + /// 更新商铺永久续费 + /// + /// + [HttpPost] + public IHttpActionResult UpdateShopNeverExpires(ShopNeverExpiresRequest request) + { + try + { + var ret = _shopService.UpdateShopNeverExpires(request.UserName, request.ShopId, request.OwnerUser, request.IsNever); + return Ok(ApiResult.Success(ret)); + } + catch (Exception ex) + { + return Ok(ApiResult.Fail(ex.Message)); + } + + } +} \ No newline at end of file diff --git a/KJD_WebService/KJD_WebService.csproj b/KJD_WebService/KJD_WebService.csproj index 9429ab1..14fa6d8 100644 --- a/KJD_WebService/KJD_WebService.csproj +++ b/KJD_WebService/KJD_WebService.csproj @@ -193,6 +193,7 @@ + @@ -218,6 +219,7 @@ + @@ -264,6 +266,7 @@ + diff --git a/KJD_WebService/Model/ShopModel/ShopParam.cs b/KJD_WebService/Model/ShopModel/ShopParam.cs index cfcd62f..fab4f5a 100644 --- a/KJD_WebService/Model/ShopModel/ShopParam.cs +++ b/KJD_WebService/Model/ShopModel/ShopParam.cs @@ -76,6 +76,8 @@ namespace KJD_Web.Model.ShopModel public long? erp_shop_id { get; internal set; } public long? erp_corporate_account_user_id { get; internal set; } public long? erp_manage_user_id { get; internal set; } + + public bool never_expires { get; internal set; } } public class AuthInfo diff --git a/KJD_WebService/Requests/ShopRequest.cs b/KJD_WebService/Requests/ShopRequest.cs new file mode 100644 index 0000000..aaacbd2 --- /dev/null +++ b/KJD_WebService/Requests/ShopRequest.cs @@ -0,0 +1,14 @@ +using Store.Framework.Dtos; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; + +namespace KJD_Web.Requests; + +public class ShopNeverExpiresRequest : SignRequestBase +{ + public string ShopId { get; set; } + public string OwnerUser { get; set; } + public bool IsNever { get; set; } +} diff --git a/KJD_WebService/Services/Shops/ShopService.cs b/KJD_WebService/Services/Shops/ShopService.cs new file mode 100644 index 0000000..43a15e9 --- /dev/null +++ b/KJD_WebService/Services/Shops/ShopService.cs @@ -0,0 +1,42 @@ +using MAX.Core.DependencyInjection; +using MAX.Core.Logger; +using Store.Contracts.Shops; +using Store.Contracts.User.Interfaces; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; + +namespace KJD_Web.Services.Shops; + +public class ShopService : ITransientDependency +{ + private readonly IFreeSql _freeSql; + private readonly ILoggerFacade _logger; + private readonly IUserService _userService; + + public ShopService(IFreeSql freeSql, ILoggerFacade logger, IUserService userService) + { + _freeSql = freeSql; + _logger = logger; + _userService = userService; + } + + /// + /// 修改商铺永不过期 + /// + public bool UpdateShopNeverExpires(string userName, string shopId,string ownerUser, bool isNever) + { + if (string.IsNullOrEmpty(userName)) return false; + if (string.IsNullOrEmpty(shopId)) return false; + var user = _userService.GetUserByUserName(userName); + if (user == null) return false; + if (user.SaLevel != 1) return false; + + var affrows = _freeSql.Update() + .Set(a => a.NeverExpires, isNever) + .Where(a => a.ShopId == shopId && a.UserName == ownerUser) + .ExecuteAffrows(); + return affrows == 1; + } +} \ No newline at end of file diff --git a/KJD_WebService/Services/Users/UserService.cs b/KJD_WebService/Services/Users/UserService.cs index de47e2e..1fe3926 100644 --- a/KJD_WebService/Services/Users/UserService.cs +++ b/KJD_WebService/Services/Users/UserService.cs @@ -44,7 +44,7 @@ namespace KJD_Web.Services.Users { return GetOEMByUserName(userName) != null; } - + public UserEntity GetUserByUserName(string userName) { if (string.IsNullOrEmpty(userName)) return null; diff --git a/Store.Contracts/Shops/ShopEntity.cs b/Store.Contracts/Shops/ShopEntity.cs index 470e17d..670d6af 100644 --- a/Store.Contracts/Shops/ShopEntity.cs +++ b/Store.Contracts/Shops/ShopEntity.cs @@ -1,255 +1,149 @@ using FreeSql.DataAnnotations; using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -namespace Store.Contracts.Shops; - -/// -/// 店铺表 -/// -[Table(Name = "erp.o_shop")] -public class ShopEntity +namespace Store.Contracts.Shops { /// - /// 主键 + /// 店铺表 /// - [Column(Name = "id", IsPrimary = true, IsIdentity = true)] - public long Id { get; set; } + [Table(Name = "wxxd.shop")] + public class ShopEntity + { + /// + /// 表id + /// + [Column(Name = "id", IsPrimary = true, IsIdentity = true)] + public int Id { get; set; } - /// - /// 店铺名 - /// - [Column(Name = "name")] - public string Name { get; set; } + /// + /// login_name + /// + [Column(Name = "login_name")] + public string LoginName { get; set; } - /// - /// 对应第三方平台Id - /// - [Column(Name = "type")] - public int Type { get; set; } + /// + /// login_pass + /// + [Column(Name = "login_pass")] + public string LoginPass { get; set; } - /// - /// 登录获取的Cookie信息 - /// - [Column(Name = "login_cookie")] - public string LoginCookie { get; set; } + /// + /// cookie + /// + [Column(Name = "cookie")] + public string Cookie { get; set; } - /// - /// 访问需要的header参数 - /// - [Column(Name = "header_params")] - public string HeaderParams { get; set; } + /// + /// cookie2 + /// + [Column(Name = "cookie2")] + public string Cookie2 { get; set; } - /// - /// 店铺url - /// - [Column(Name = "url")] - public string Url { get; set; } + /// + /// anti_contents + /// + [Column(Name = "anti_contents")] + public string AntiContents { get; set; } - /// - /// 排序 - /// - [Column(Name = "sort")] - public int Sort { get; set; } + /// + /// openid + /// + [Column(Name = "openid")] + public string Openid { get; set; } - /// - /// 状态(1正常2已删除) - /// - [Column(Name = "status")] - public int? Status { get; set; } + /// + /// shop_id + /// + [Column(Name = "shop_id")] + public string ShopId { get; set; } - /// - /// 描述 - /// - [Column(Name = "remark")] - public string Remark { get; set; } + /// + /// shop_account + /// + [Column(Name = "shop_account")] + public string ShopAccount { get; set; } - /// - /// 第三方平台店铺id,淘宝天猫开放平台使用 - /// - [Column(Name = "seller_id")] - public long? SellerId { get; set; } + /// + /// sub_user_name + /// + [Column(Name = "sub_user_name")] + public string SubUserName { get; set; } - /// - /// 授权时间 - /// - [Column(Name = "auth_time")] - public long? AuthTime { get; set; } + /// + /// user_name + /// + [Column(Name = "user_name")] + public string UserName { get; set; } - /// - /// 服务市场授权到期时间 - /// - [Column(Name = "expire_time")] - public long? ExpireTime { get; set; } + /// + /// 店铺分组名称(非子账号分组) + /// + [Column(Name = "group_name")] + public string GroupName { get; set; } - /// - /// Appkey - /// - [Column(Name = "app_key")] - public string AppKey { get; set; } + /// + /// add_time + /// + [Column(Name = "add_time")] + public DateTime? AddTime { get; set; } - /// - /// Appsercet - /// - [Column(Name = "app_secret")] - public string AppSecret { get; set; } + /// + /// mdy_time + /// + [Column(Name = "mdy_time")] + public DateTime? MdyTime { get; set; } - /// - /// 小红椒的access_token - /// - [Column(Name = "access_token_xhj")] - public string AccessTokenXhj { get; set; } + /// + /// 店铺所属公司 + /// + [Column(Name = "company_name")] + public string CompanyName { get; set; } - /// - /// 第三方平台sessionKey(access_token) - /// - [Column(Name = "access_token")] - public string AccessToken { get; set; } + /// + /// 备注 + /// + [Column(Name = "notes")] + public string Notes { get; set; } - /// - /// 小红椒多久到期 - /// - [Column(Name = "expires_in_xhj")] - public long? ExpiresInXhj { get; set; } + /// + /// login_status + /// + [Column(Name = "login_status")] + public string LoginStatus { get; set; } - /// - /// 到期 - /// - [Column(Name = "expires_in")] - public long? ExpiresIn { get; set; } + /// + /// 店铺每月商品上传限额剩余 + /// + [Column(Name = "add_product_remaining")] + public int AddProductRemaining { get; set; } - /// - /// 小红椒access_token开始时间 - /// - [Column(Name = "access_token_begin_xhj")] - public long? AccessTokenBeginXhj { get; set; } + /// + /// 上传限额所处月份 + /// + [Column(Name = "add_product_month")] + public byte AddProductMonth { get; set; } - /// - /// access_token开始时间 - /// - [Column(Name = "access_token_begin")] - public long? AccessTokenBegin { get; set; } + /// + /// 分配的二级超管的user_name + /// + [Column(Name = "operate_sub_sa_name")] + public string OperateSubSaName { get; set; } - /// - /// 刷新token - /// - [Column(Name = "refresh_token")] - public string RefreshToken { get; set; } + /// + /// 分配二级超管的时间 + /// + [Column(Name = "add_sub_sa_time")] + public DateTime? AddSubSaTime { get; set; } - /// - /// 刷新token过期时间 - /// - [Column(Name = "refresh_token_timeout")] - public long? RefreshTokenTimeout { get; set; } - - /// - /// 代理api请求凭证 - /// - [Column(Name = "session")] - public string Session { get; set; } - - /// - /// 代理api获取请求凭证的shopkey字段 - /// - [Column(Name = "shop_key")] - public string ShopKey { get; set; } - - /// - /// 请求url - /// - [Column(Name = "api_request_url")] - public string ApiRequestUrl { get; set; } - - /// - /// 回掉URL - /// - [Column(Name = "api_callback_url")] - public string ApiCallbackUrl { get; set; } - - /// - /// 负责人id - /// - [Column(Name = "manage_user_id")] - public long? ManageUserId { get; set; } - - /// - /// 默认运费模板id,抖店上传商品使用 - /// - [Column(Name = "default_freight_template_id")] - public long? DefaultFreightTemplateId { get; set; } - - /// - /// 默认品牌id,抖店上传商品使用 - /// - [Column(Name = "default_brand_id")] - public long? DefaultBrandId { get; set; } - - /// - /// 店铺是否已开启尺码自动优化,0:不需要开启,1:未开启,2:已开启 - /// - [Column(Name = "auto_size_template_optimize")] - public byte? AutoSizeTemplateOptimize { get; set; } - - /// - /// 店铺分组 - /// - [Column(Name = "shop_group_id")] - public long? ShopGroupId { get; set; } - - /// - /// 企业账号用户id - /// - [Column(Name = "corporate_account_user_id")] - public long? CorporateAccountUserId { get; set; } - - /// - /// 国家/地区 - /// - [Column(Name = "region_id")] - public long? RegionId { get; set; } - - /// - /// 商户ID - /// - [Column(Name = "merchant_id")] - public long? MerchantId { get; set; } - - /// - /// 创建时间 - /// - [Column(Name = "create_time")] - public DateTime? CreateTime { get; set; } - - /// - /// 创建人 - /// - [Column(Name = "create_by")] - public string CreateBy { get; set; } - - /// - /// 更新时间 - /// - [Column(Name = "update_time")] - public DateTime? UpdateTime { get; set; } - - /// - /// 更新人 - /// - [Column(Name = "update_by")] - public string UpdateBy { get; set; } - - /// - /// api调用状态0未开启1已开启 - /// - [Column(Name = "api_status")] - public int ApiStatus { get; set; } - - /// - /// 是否开启自动购买外采礼物单,0:未开启,1:已开启 - /// - [Column(Name = "auto_purchase_external_gift")] - public int? AutoPurchaseExternalGift { get; set; } -} + /// + /// login_status2 + /// + [Column(Name = "login_status2")] + public string LoginStatus2 { get; set; } + /// + /// + /// + [Column(Name = "never_expires")] + public bool NeverExpires { get; set; } + } +} \ No newline at end of file diff --git a/Store.Framework/Commons/StoreAppTypeFinder.cs b/Store.Framework/Commons/StoreAppTypeFinder.cs index 1622644..6cc6a17 100644 --- a/Store.Framework/Commons/StoreAppTypeFinder.cs +++ b/Store.Framework/Commons/StoreAppTypeFinder.cs @@ -14,7 +14,7 @@ namespace Store.Framework.Commons /// public override List GetAssemblies() { - LoadAssemblies(HttpRuntime.BinDirectory); + LoadAssemblies(BinDirectory); return GetAssembliesFromCurrentAppDomain(); } @@ -22,5 +22,21 @@ namespace Store.Framework.Commons { return ["Max", "Store"]; } + + + public string BinDirectory + { + get + { + // 传统 ASP.NET Web 环境(IIS 或 VS 调试的 Web 应用) + if (HttpRuntime.AppDomainAppVirtualPath != null) + { + return HttpRuntime.BinDirectory; + } + + // 测试环境或非 Web 环境:返回当前程序集所在目录 + return AppDomain.CurrentDomain.BaseDirectory; + } + } } } diff --git a/test/WebServiceTest/GiftLogisticsTest.cs b/test/WebServiceTest/GiftLogisticsTest.cs index b8a61b1..761d9c0 100644 --- a/test/WebServiceTest/GiftLogisticsTest.cs +++ b/test/WebServiceTest/GiftLogisticsTest.cs @@ -97,7 +97,7 @@ internal class GiftLogisticsTest public void BuyTest() { var logisticsService = _container.Resolve(); - var ret = logisticsService.Buy("15222220006", "260923-573109716621688", "4439363558732480512"); + var ret = logisticsService.Buy("16603999396", "260924-061299770880192", "4439386298687207168"); if (ret != null) { Console.WriteLine(string.Join(" ", ret.Select(a => $"{a.OrderId}:{a.TrackingNumber}"))); @@ -129,7 +129,7 @@ internal class GiftLogisticsTest public void GetOrderStatus() { var logisticsService = _container.Resolve(); - var data = logisticsService.GetOrderStatus(["260923-407759756800192"]); + var data = logisticsService.GetOrderStatus(["260927-623588227382767"]); Console.WriteLine(string.Join(" ", data.Select(a => $"{a.OrderSn}:{a.KuaidiSn}:{a.ShopOrder}:{a.DeliveryStatus}"))); } }