diff --git a/StoreHub.Framework/Security/JwtClaimTypes.cs b/StoreHub.Framework/Security/JwtClaimTypes.cs index 57f100f..d73afb7 100644 --- a/StoreHub.Framework/Security/JwtClaimTypes.cs +++ b/StoreHub.Framework/Security/JwtClaimTypes.cs @@ -5,8 +5,7 @@ /// public static class JwtClaimTypes { - /// 用户ID - public const string UserId = "uid"; + public const string UserId = "user_name"; /// 登录账户 public const string UserName = "user_name"; diff --git a/StoreHub.Framework/Startup.cs b/StoreHub.Framework/Startup.cs index a16e7bc..3525ac6 100644 --- a/StoreHub.Framework/Startup.cs +++ b/StoreHub.Framework/Startup.cs @@ -34,6 +34,7 @@ namespace StoreHub.Framework }); + Func KJDFsqlFactory = r => { var config = r.GetRequiredService(); @@ -51,3 +52,4 @@ namespace StoreHub.Framework } } } + diff --git a/StoreHub.KJDWebService/Commons/BaseClass.cs b/StoreHub.KJDWebService/Commons/BaseClass.cs new file mode 100644 index 0000000..14855ed --- /dev/null +++ b/StoreHub.KJDWebService/Commons/BaseClass.cs @@ -0,0 +1,53 @@ +using StoreHub.KJDWebService.Commons; +using System; +using System.Collections.Generic; +using System.Linq; + +namespace StoreHub.KJDWebService.Commons +{ + + public class BaseClass + { + public static string BuildPDDObjString(string file, bool IsLoginDef = false) + { + string LoginApiUrl = "http://1.13.195.131:9001"; + string MainPath = "kuajingda"; + return LoginApiUrl + "/bxx_" + file + "?obj=" + MainPath + "/bxx_" + file; + } + + public static int TimeDifferent = 0; + public static int VersionCount = 99999999; + public static int CompanyId = 1; + public static string CompanyName = "1"; + public static string UserKey = "1"; + public static string Mobile = "18888888888"; + public static string UserName = "18888888888"; + public static string ShopId = "18888888888"; + public static string ShopName = "18888888888"; + } + + public class UserLogin + { + /// + /// 获取签名字符串,新版 + /// + /// + public static string GetSignaturex() + { + return GetSignaturex(BaseClass.ShopId, BaseClass.ShopName); + } + public static string GetSignaturex(string shopId, string shopName) + { + if (string.IsNullOrEmpty(shopId)) + shopId = "11111111"; + if (string.IsNullOrEmpty(shopName)) + shopName = "wx11111111"; + int time = TimeUtils.DateTimeToTimestampSeconds(DateTime.Now) + BaseClass.TimeDifferent; + string time1 = EncrypUtil.Encryption(time); + return "time=" + time + "&code=" + time1 + "&NbCodeVersion=1" + "&version=" + BaseClass.VersionCount + + "&company_id=" + BaseClass.CompanyId + "&company=" + HtmlUtils.UrlEncodeUtf8(BaseClass.CompanyName) + + "&user_name=" + BaseClass.UserName + "&user_key=" + BaseClass.UserKey + "&mobile=" + BaseClass.Mobile + + "&sid=" + shopId + "&shop=" + HtmlUtils.UrlEncodeUtf8(shopName); + } + } +} diff --git a/StoreHub.KJDWebService/Commons/EncrypUtil.cs b/StoreHub.KJDWebService/Commons/EncrypUtil.cs new file mode 100644 index 0000000..a2489fb --- /dev/null +++ b/StoreHub.KJDWebService/Commons/EncrypUtil.cs @@ -0,0 +1,60 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Security.Cryptography; +using System.Text; + +namespace StoreHub.KJDWebService.Commons +{ + public class EncrypUtil + { + /// + /// 加密算法 + /// + /// 加密字符串 + /// + public static string Encryption(int s) + { + string sign = $"{s}sdhewu*/fhAAue48485ew5+5%@3485esGFFHFD"; + return GetMd5(sign); + } + + /// + /// MD5加密 + /// + /// + /// + public static string GetMd5(string instring) + { + byte[] result = Encoding.Default.GetBytes(instring.Trim()); + MD5 md5 = new MD5CryptoServiceProvider(); + byte[] output = md5.ComputeHash(result); + return BitConverter.ToString(output).Replace("-", ""); + } + + /// + /// 获取文件MD5值 + /// + /// + /// + public static string GetFileMd5(string FilePath) + { + try + { + FileStream get_file = new FileStream(FilePath, FileMode.Open, FileAccess.Read, FileShare.Read); + System.Security.Cryptography.MD5CryptoServiceProvider get_md5 = new System.Security.Cryptography.MD5CryptoServiceProvider(); + byte[] hash_byte = get_md5.ComputeHash(get_file); + string resule = System.BitConverter.ToString(hash_byte); + resule = resule.Replace("-", ""); + get_file.Close(); + return resule; + } + catch (Exception e) + { + return e.ToString(); + } + } + } +} + diff --git a/StoreHub.KJDWebService/Commons/Extension/Extension.Convert.cs b/StoreHub.KJDWebService/Commons/Extension/Extension.Convert.cs new file mode 100644 index 0000000..1999a32 --- /dev/null +++ b/StoreHub.KJDWebService/Commons/Extension/Extension.Convert.cs @@ -0,0 +1,705 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Runtime.Serialization.Formatters.Binary; +using System.Text; +using System.Threading.Tasks; +using NaiBa.Util.Helper; +using Newtonsoft.Json; + +namespace NaiBa.Util.Extension +{ + public static partial class Extensions + { + #region 转换为long + /// + /// 将object转换为long,若转换失败,则返回0。不抛出异常。 + /// + /// + /// + public static long ParseToLong(this object obj) + { + if (obj == null) + return 0L; + + try + { + string str = obj.ParseToString(); + if (string.IsNullOrEmpty(str)) + { + return 0; + } + return long.Parse(str); + } + catch + { + return 0L; + } + } + + public static long? ParseToNullableLong(this object obj) + { + if (obj == null) + return null; + + try + { + string str = obj.ParseToString(); + if (string.IsNullOrEmpty(str)) + { + return null; + } + return long.Parse(str); + } + catch + { + return null; + } + } + + /// + /// 将object转换为long,若转换失败,则返回指定值。不抛出异常。 + /// + /// + /// + /// + public static long ParseToLong(this string str, long defaultValue) + { + if (str == null) + return defaultValue; + + try + { + return long.Parse(str); + } + catch + { + return defaultValue; + } + } + #endregion + + #region 转换为int + /// + /// 将object转换为int,若转换失败,则返回0。不抛出异常。 + /// + /// + /// + public static int ParseToInt(this object str) + { + if (str == null) + return 0; + + try + { + return Convert.ToInt32(str); + } + catch + { + return 0; + } + } + + public static int? ParseToNullableInt(this object str) + { + if (str == null) + return null; + + try + { + return Convert.ToInt32(str); + } + catch + { + return null; + } + } + + public static int DecimalPointParseToInt(this object str) + { + try + { + string temp = str.ParseToString(); + int i = temp.IndexOf('.'); + if (i > 0) + { + temp = temp.Substring(0, i); + } + return Convert.ToInt32(temp); + } + catch + { + return 0; + } + } + + /// + /// 将object转换为int,若转换失败,则返回指定值。不抛出异常。 + /// null返回默认值 + /// + /// + /// + /// + public static int ParseToInt(this object str, int defaultValue) + { + if (str == null) + { + return defaultValue; + } + try + { + return Convert.ToInt32(str); + } + catch + { + return defaultValue; + } + } + #endregion + + #region 转换为short + /// + /// 将object转换为short,若转换失败,则返回0。不抛出异常。 + /// + /// + /// + public static short ParseToShort(this object obj) + { + try + { + return short.Parse(obj.ToString()); + } + catch + { + return 0; + } + } + + /// + /// 将object转换为short,若转换失败,则返回指定值。不抛出异常。 + /// + /// + /// + public static short ParseToShort(this object str, short defaultValue) + { + try + { + return short.Parse(str.ToString()); + } + catch + { + return defaultValue; + } + } + #endregion + + #region 转换为demical + /// + /// 将object转换为demical,若转换失败,则返回指定值。不抛出异常。 + /// + /// + /// + public static decimal ParseToDecimal(this object str, decimal defaultValue) + { + try + { + return decimal.Parse(str.ToString()); + } + catch + { + return defaultValue; + } + } + + /// + /// 将object转换为demical,若转换失败,则返回0。不抛出异常。 + /// + /// + /// + public static decimal ParseToDecimal(this object str) + { + try + { + return decimal.Parse(str.ToString()); + } + catch + { + return 0; + } + } + public static decimal? ParseToNullableDecimal(this object str) + { + try + { + return decimal.Parse(str.ToString()); + } + catch + { + return null; + } + } + #endregion + + #region 转化为bool + /// + /// 将object转换为bool,若转换失败,则返回false。不抛出异常。 + /// + /// + /// + public static bool ParseToBool(this object str) + { + try + { + if (str is null) + return false; + return bool.Parse(str.ToString()); + } + catch + { + return false; + } + } + + /// + /// 将object转换为bool,若转换失败,则返回指定值。不抛出异常。 + /// + /// + /// + public static bool ParseToBool(this object str, bool result) + { + try + { + return bool.Parse(str.ToString()); + } + catch + { + return result; + } + } + #endregion + + #region 转换为float + /// + /// 将object转换为float,若转换失败,则返回0。不抛出异常。 + /// + /// + /// + public static float ParseToFloat(this object str) + { + try + { + return float.Parse(str.ToString()); + } + catch + { + return 0; + } + } + + /// + /// 将object转换为float,若转换失败,则返回指定值。不抛出异常。 + /// + /// + /// + public static float ParseToFloat(this object str, float result) + { + try + { + return float.Parse(str.ToString()); + } + catch + { + return result; + } + } + #endregion + + #region 转换为Guid + /// + /// 将string转换为Guid,若转换失败,则返回Guid.Empty。不抛出异常。 + /// + /// + /// + public static Guid ParseToGuid(this string str) + { + try + { + return new Guid(str); + } + catch + { + return Guid.Empty; + } + } + #endregion + + #region 转换为DateTime + + public static DateTime? ParseToDateTimeNullable(this string str) + { + try + { + if (string.IsNullOrWhiteSpace(str)) + { + return null; + } + + try + { + return DateTime.Parse(str); + } + catch + { + } + + if (str.Contains("年") && str.Contains("月") && str.Contains("日") && !str.Contains("周")) + str = str.Replace("年", "-").Replace("月", "-").Replace("日", "").Replace("时", ":").Replace("分", ":").Replace("秒", "").Trim(' ', ':'); + if (str.Contains("-") || str.Contains("/")) + { + return DateTime.Parse(str); + } + else + { + int length = str.Length; + switch (length) + { + case 4: + return DateTime.ParseExact(str, "yyyy", System.Globalization.CultureInfo.CurrentCulture); + case 6: + return DateTime.ParseExact(str, "yyyyMM", System.Globalization.CultureInfo.CurrentCulture); + case 8: + return DateTime.ParseExact(str, "yyyyMMdd", System.Globalization.CultureInfo.CurrentCulture); + case 10: + return DateTime.ParseExact(str, "yyyyMMddHH", System.Globalization.CultureInfo.CurrentCulture); + case 12: + return DateTime.ParseExact(str, "yyyyMMddHHmm", System.Globalization.CultureInfo.CurrentCulture); + case 14: + return DateTime.ParseExact(str, "yyyyMMddHHmmss", System.Globalization.CultureInfo.CurrentCulture); + default: + return DateTime.ParseExact(str, "yyyyMMddHHmmss", System.Globalization.CultureInfo.CurrentCulture); + } + } + } + catch + { + return null; + } + } + + /// + /// 将string转换为DateTime,若转换失败,则返回日期最小值。不抛出异常。 + /// + /// + /// + public static DateTime ParseToDateTime(this string str) + { + try + { + if (string.IsNullOrWhiteSpace(str)) + { + return DateTime.MinValue; + } + if (str.Contains("-") || str.Contains("/")) + { + return DateTime.Parse(str); + } + else + { + int length = str.Length; + switch (length) + { + case 4: + return DateTime.ParseExact(str, "yyyy", System.Globalization.CultureInfo.CurrentCulture); + case 6: + return DateTime.ParseExact(str, "yyyyMM", System.Globalization.CultureInfo.CurrentCulture); + case 8: + return DateTime.ParseExact(str, "yyyyMMdd", System.Globalization.CultureInfo.CurrentCulture); + case 10: + return DateTime.ParseExact(str, "yyyyMMddHH", System.Globalization.CultureInfo.CurrentCulture); + case 12: + return DateTime.ParseExact(str, "yyyyMMddHHmm", System.Globalization.CultureInfo.CurrentCulture); + case 14: + return DateTime.ParseExact(str, "yyyyMMddHHmmss", System.Globalization.CultureInfo.CurrentCulture); + default: + return DateTime.ParseExact(str, "yyyyMMddHHmmss", System.Globalization.CultureInfo.CurrentCulture); + } + } + } + catch + { + return DateTime.MinValue; + } + } + + /// + /// 将string转换为DateTime,若转换失败,则返回默认值。 + /// + /// + /// + /// + public static DateTime ParseToDateTime(this string str, DateTime? defaultValue) + { + try + { + if (string.IsNullOrWhiteSpace(str)) + { + return defaultValue.GetValueOrDefault(); + } + if (str.Contains("-") || str.Contains("/")) + { + return DateTime.Parse(str); + } + else + { + int length = str.Length; + switch (length) + { + case 4: + return DateTime.ParseExact(str, "yyyy", System.Globalization.CultureInfo.CurrentCulture); + case 6: + return DateTime.ParseExact(str, "yyyyMM", System.Globalization.CultureInfo.CurrentCulture); + case 8: + return DateTime.ParseExact(str, "yyyyMMdd", System.Globalization.CultureInfo.CurrentCulture); + case 10: + return DateTime.ParseExact(str, "yyyyMMddHH", System.Globalization.CultureInfo.CurrentCulture); + case 12: + return DateTime.ParseExact(str, "yyyyMMddHHmm", System.Globalization.CultureInfo.CurrentCulture); + case 14: + return DateTime.ParseExact(str, "yyyyMMddHHmmss", System.Globalization.CultureInfo.CurrentCulture); + default: + return DateTime.ParseExact(str, "yyyyMMddHHmmss", System.Globalization.CultureInfo.CurrentCulture); + } + } + } + catch + { + return defaultValue.GetValueOrDefault(); + } + } + #endregion + + #region 转换为string + /// + /// 将object转换为string,若转换失败,则返回""。不抛出异常。 + /// + /// + /// + public static string ParseToString(this object obj) + { + try + { + if (obj == null) + { + return string.Empty; + } + else + { + if (obj is DateTime) + return (obj as DateTime?).Value.ToString("yyyy-MM-dd HH:mm:ss"); + return obj.ToString(); + } + } + catch + { + return string.Empty; + } + } + + public static string ParseToNullableString(this object obj) + { + try + { + if (obj == null) + { + return null; + } + else + { + if (obj is DateTime) + return (obj as DateTime?).Value.ToString("yyyy-MM-dd HH:mm:ss"); + return obj.ToString(); + } + } + catch + { + return null; + } + } + + public static string ParseToStrings(this object obj, string split = ",") + { + try + { + var list = obj as IEnumerable; + if (list != null) + { + return string.Join(split, list); + } + else + { + return obj.ToString(); + } + } + catch + { + return string.Empty; + } + } + #endregion + + #region 转换为double + /// + /// 将object转换为double,若转换失败,则返回0。不抛出异常。 + /// + /// + /// + public static double ParseToDouble(this object obj) + { + try + { + return double.Parse(obj.ToString()); + } + catch + { + return 0; + } + } + + /// + /// 将object转换为double,若转换失败,则返回指定值。不抛出异常。 + /// + /// + /// + /// + public static double ParseToDouble(this object str, double defaultValue) + { + try + { + return double.Parse(str.ToString()); + } + catch + { + return defaultValue; + } + } + #endregion + + #region 字符串转指定类型Array + public static T[] SplitToArray(this string value, string split = ",") + { + if (string.IsNullOrEmpty(value)) + { + return default(T[]); + } + var arr = value.Split(new string[] { split }, StringSplitOptions.RemoveEmptyEntries).CastSuper().ToArray(); + return arr; + } + + public static T[] SplitToArray(this string value, string[] split) + { + if (string.IsNullOrEmpty(value)) + { + return default(T[]); + } + var arr = value.Split(split, StringSplitOptions.RemoveEmptyEntries).CastSuper().ToArray(); + return arr; + } + #endregion + + #region 字符串转指定类型List + public static List SplitToList(this string value, string split = ",") + { + if (string.IsNullOrEmpty(value)) + { + return new List(); + } + var list = value.Split(new string[] { split }, StringSplitOptions.RemoveEmptyEntries).CastSuper().ToList(); + return list; + } + + public static List SplitToList(this string value, string[] split) + { + if (string.IsNullOrEmpty(value)) + { + return new List(); + } + var list = value.Split(split, StringSplitOptions.RemoveEmptyEntries).CastSuper().ToList(); + return list; + } + #endregion + + #region 强制转换类型 + /// + /// 强制转换类型 + /// + /// + /// + /// + public static IEnumerable CastSuper(this IEnumerable source) + { + foreach (object item in source) + { + yield return (TResult)Convert.ChangeType(item, typeof(TResult)); + } + } + #endregion + + #region Object转换为Json + public static string ParseToJson(this object obj) + { + return JsonConvert.SerializeObject(obj); + } + #endregion + + #region Json转为Object + public static T ParseToObject(this string json) + { + if (string.IsNullOrEmpty(json)) + { + return Activator.CreateInstance(); + } + return JsonConvert.DeserializeObject(json); + } + #endregion + + #region 深拷贝(克隆出一个新对象,拷贝对象里面的数据和子对象) + public static T DeepClone(this T o) + { + return o.ParseToJson().ParseToObject(); + // 这种方式在用 Obfuscator 的时候有问题 + //using (MemoryStream stream = new MemoryStream()) + //{ + // BinaryFormatter formatter = new BinaryFormatter(); + // formatter.Serialize(stream, o); + // stream.Position = 0; + // return (T)formatter.Deserialize(stream); + //} + } + #endregion + + #region 浅拷贝(拷贝对象里面的数据[property and field],但不拷贝对象里面的子对象) + public static void ShadowClone(this T1 source, ref T2 destination) + { + var sourceMembers = ReflectionHelper.GetMembers(source.GetType()); + var destinationMembers = ReflectionHelper.GetMembers(destination.GetType()); + + // Copy data from source to destination + foreach (var sourceMember in sourceMembers) + { + if (!ReflectionHelper.CanRead(sourceMember)) + { + continue; + } + var destinationMember = destinationMembers.FirstOrDefault(x => x.Name.ToLower() == sourceMember.Name.ToLower()); + if (destinationMember == null || !ReflectionHelper.CanWrite(destinationMember)) + { + continue; + } + ReflectionHelper.SetObjectValue(ref destination, destinationMember, ReflectionHelper.GetMemberValue(source, sourceMember)); + } + } + #endregion + } +} diff --git a/StoreHub.KJDWebService/Commons/Extension/Extension.Enum.cs b/StoreHub.KJDWebService/Commons/Extension/Extension.Enum.cs new file mode 100644 index 0000000..707f49a --- /dev/null +++ b/StoreHub.KJDWebService/Commons/Extension/Extension.Enum.cs @@ -0,0 +1,114 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; +using Newtonsoft.Json; + +namespace NaiBa.Util.Extension +{ + public static partial class Extensions + { + #region 枚举成员转成dictionary类型 + /// + /// 转成dictionary类型 + /// + /// + /// + public static Dictionary EnumToDictionary(this Type enumType) + { + Dictionary dictionary = new Dictionary(); + Type typeDescription = typeof(DescriptionAttribute); + FieldInfo[] fields = enumType.GetFields(); + int sValue = 0; + string sText = string.Empty; + foreach (FieldInfo field in fields) + { + if (field.FieldType.IsEnum) + { + sValue = ((int)enumType.InvokeMember(field.Name, BindingFlags.GetField, null, null, null)); + object[] arr = field.GetCustomAttributes(typeDescription, true); + if (arr.Length > 0) + { + DescriptionAttribute da = (DescriptionAttribute)arr[0]; + sText = da.Description; + } + else + { + sText = field.Name; + } + dictionary.Add(sValue, sText); + } + } + return dictionary.OrderBy(p => p.Key).ToDictionary(p => p.Key, p => p.Value); + } + + /// + /// 枚举成员转成键值对Json字符串 + /// + /// + /// + public static string EnumToDictionaryString(this Type enumType) + { + List> dictionaryList = EnumToDictionary(enumType).ToList(); + var sJson = JsonConvert.SerializeObject(dictionaryList); + return sJson; + } + #endregion + + #region 根据类型获取枚举的描述 + /// + /// 获取枚举值对应的描述 + /// + /// + /// + public static string GetDescription(this System.Enum enumType) + { + FieldInfo EnumInfo = enumType.GetType().GetField(enumType.ToString()); + if (EnumInfo != null) + { + DescriptionAttribute[] EnumAttributes = (DescriptionAttribute[])EnumInfo.GetCustomAttributes(typeof(DescriptionAttribute), false); + if (EnumAttributes.Length > 0) + { + return EnumAttributes[0].Description; + } + } + return enumType.ToString(); + } + #endregion + + #region 根据值获取枚举的描述 + public static string GetDescriptionByEnum(this object obj) + { + var tEnum = System.Enum.Parse(typeof(T), obj.ParseToString()) as System.Enum; + var description = tEnum.GetDescription(); + return description; + } + #endregion + + #region 根据描述获取枚举值 + public static int GetEnumValueByDescription(this string description) + { + Dictionary dict = typeof(T).EnumToDictionary(); + int value = dict.Where(p => p.Value == description).Select(p => p.Key).FirstOrDefault(); + return value; + } + #endregion + + #region 根据枚举名称获取值 + public static int GetEnumValueByName(this string name) + { + return (int)System.Enum.Parse(typeof(T), name); + } + #endregion + + #region 根据枚举值获取名称 + public static object GetEnumNameByValue(this int value) + { + return System.Enum.ToObject(typeof(T), value); + } + #endregion + } +} diff --git a/StoreHub.KJDWebService/Commons/Extension/Extension.Exception.cs b/StoreHub.KJDWebService/Commons/Extension/Extension.Exception.cs new file mode 100644 index 0000000..11447f3 --- /dev/null +++ b/StoreHub.KJDWebService/Commons/Extension/Extension.Exception.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace NaiBa.Util.Extension +{ + public static partial class Extensions + { + public static Exception GetOriginalException(this Exception ex) + { + if (ex.InnerException == null) return ex; + + return ex.InnerException.GetOriginalException(); + } + } +} diff --git a/StoreHub.KJDWebService/Commons/Extension/Extension.Linq.cs b/StoreHub.KJDWebService/Commons/Extension/Extension.Linq.cs new file mode 100644 index 0000000..4eadb77 --- /dev/null +++ b/StoreHub.KJDWebService/Commons/Extension/Extension.Linq.cs @@ -0,0 +1,110 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Linq.Expressions; +using System.Text; +using System.Threading.Tasks; + +namespace NaiBa.Util.Extension +{ + public static class LinqExtensions + { + public static Expression Property(this Expression expression, string propertyName) + { + return Expression.Property(expression, propertyName); + } + public static Expression AndAlso(this Expression left, Expression right) + { + return Expression.AndAlso(left, right); + } + public static Expression Call(this Expression instance, string methodName, params Expression[] arguments) + { + return Expression.Call(instance, instance.Type.GetMethod(methodName), arguments); + } + public static Expression GreaterThan(this Expression left, Expression right) + { + return Expression.GreaterThan(left, right); + } + public static Expression ToLambda(this Expression body, params ParameterExpression[] parameters) + { + return Expression.Lambda(body, parameters); + } + + public static Expression> True() { return param => true; } + + public static Expression> False() { return param => false; } + + /// + /// 组合And + /// + /// + public static Expression> And(this Expression> first, Expression> second) + { + return first.Compose(second, Expression.AndAlso); + } + /// + /// 组合Or + /// + /// + public static Expression> Or(this Expression> first, Expression> second) + { + return first.Compose(second, Expression.OrElse); + } + + /// + /// Combines the first expression with the second using the specified merge function. + /// + static Expression Compose(this Expression first, Expression second, Func merge) + { + var map = first.Parameters + .Select((f, i) => new { f, s = second.Parameters[i] }) + .ToDictionary(p => p.s, p => p.f); + var secondBody = ParameterRebinder.ReplaceParameters(map, second.Body); + return Expression.Lambda(merge(first.Body, secondBody), first.Parameters); + } + + /// + /// ParameterRebinder + /// + private class ParameterRebinder : ExpressionVisitor + { + /// + /// The ParameterExpression map + /// + readonly Dictionary map; + /// + /// Initializes a new instance of the class. + /// + /// The map. + ParameterRebinder(Dictionary map) + { + this.map = map ?? new Dictionary(); + } + /// + /// Replaces the parameters. + /// + /// The map. + /// The exp. + /// Expression + public static Expression ReplaceParameters(Dictionary map, Expression exp) + { + return new ParameterRebinder(map).Visit(exp); + } + /// + /// Visits the parameter. + /// + /// The p. + /// Expression + protected override Expression VisitParameter(ParameterExpression p) + { + ParameterExpression replacement; + + if (map.TryGetValue(p, out replacement)) + { + p = replacement; + } + return base.VisitParameter(p); + } + } + } +} diff --git a/StoreHub.KJDWebService/Commons/Extension/Extension.Validate.cs b/StoreHub.KJDWebService/Commons/Extension/Extension.Validate.cs new file mode 100644 index 0000000..161f7d0 --- /dev/null +++ b/StoreHub.KJDWebService/Commons/Extension/Extension.Validate.cs @@ -0,0 +1,119 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Http; +using NaiBa.Util.Helper; +using Newtonsoft.Json.Linq; + +namespace NaiBa.Util.Extension +{ + public static partial class Extensions + { + public static bool IsNullOrEmpty(this object value) + { + if (value != null && !string.IsNullOrEmpty(value.ParseToString())) + { + return false; + } + else + { + return true; + } + } + + public static bool IsNullOrZero(this object value) + { + if (value == null || string.IsNullOrEmpty(value.ParseToString()) || value.ParseToString().Trim() == "0") + { + return true; + } + else + { + return false; + } + } + + public static bool IsNumericType(this object value) + { + if (value == null) + { + return false; + } + switch (Type.GetTypeCode(value.GetType())) + { + case TypeCode.Byte: + case TypeCode.SByte: + case TypeCode.UInt16: + case TypeCode.UInt32: + case TypeCode.UInt64: + case TypeCode.Int16: + case TypeCode.Int32: + case TypeCode.Int64: + case TypeCode.Decimal: + case TypeCode.Double: + case TypeCode.Single: + return true; + default: + return false; + } + } + + public static bool IsStringType(this object value) + { + if (value == null) + { + return false; + } + switch (Type.GetTypeCode(value.GetType())) + { + case TypeCode.String: + return true; + default: + return false; + } + } + + public static bool IsNumber(this string value) + { + return RegexHelper.IsNumber(value); + } + + public static bool IsAlphabet(this string value) + { + return RegexHelper.IsAlphabet(value); + } + + public static bool IsAlphabetOrNumber(this string value) + { + return RegexHelper.IsAlphabetOrNumber(value); + } + + public static bool IsJson(this string value) + { + return JsonHelper.IsJson(value); + } + + public static bool IsJTokenNullOrEmpty(this JToken token) + { + return (token == null) || + (token.Type == JTokenType.Array && !token.HasValues) || + (token.Type == JTokenType.Object && !token.HasValues) || + (token.Type == JTokenType.String && token.ToString() == string.Empty) || + (token.Type == JTokenType.Null); + } + + public static bool IsAjaxRequest(this Microsoft.AspNetCore.Http.HttpRequest request) + { + if (request == null) + throw new ArgumentNullException("request"); + + if (request.Headers != null) + return request.Headers["X-Requested-With"] == "XMLHttpRequest"; + return false; + } + } +} + + diff --git a/StoreHub.KJDWebService/Commons/Helper/HtmlHelper.cs b/StoreHub.KJDWebService/Commons/Helper/HtmlHelper.cs new file mode 100644 index 0000000..658dbaa --- /dev/null +++ b/StoreHub.KJDWebService/Commons/Helper/HtmlHelper.cs @@ -0,0 +1,215 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Net; +using System.Text; +using System.Text.RegularExpressions; +using System.Threading.Tasks; +using NaiBa.Util.Extension; + +namespace NaiBa.Util.Helper +{ + public class HtmlHelper + { + public static string HtmlEncode(string html) + { + if (string.IsNullOrEmpty(html)) + { + return string.Empty; + } + else + { + return WebUtility.HtmlEncode(html); + } + } + + public static string HtmlDecode(string url) + { + if (string.IsNullOrEmpty(url)) + { + return string.Empty; + } + else + { + return WebUtility.HtmlDecode(url); + } + } + + /// + /// Unicode解码 + /// + /// + /// + public static string UnicodeDecode(string html) + { + html = WebUtility.HtmlDecode(html); + + Regex reUnicode = new Regex(@"\\u([0-9a-fA-F]{4})", RegexOptions.Compiled); + return reUnicode.Replace(html, m => + { + short c; + if (short.TryParse(m.Groups[1].Value, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out c)) + { + return "" + (char)c; + } + return m.Value; + }); + } + + #region Resove + public static string Resove(string html, string prefix, string subfix = "") + { + int inl = html.IndexOf(prefix); + if (inl == -1) + { + prefix = prefix.Replace("\"", "'"); + subfix = subfix.Replace("\"", "'"); + inl = html.IndexOf(prefix); + } + if (inl == -1) + { + return null; + } + inl += prefix.Length; + if (!string.IsNullOrEmpty(subfix)) + { + int inl2 = html.IndexOf(subfix, inl); + if (inl2 == -1) + { + return null; + } + string result = html.Substring(inl, inl2 - inl); + return result; + } + else + { + string result = html.Substring(inl); + return result; + } + } + #endregion + + #region ResoveReverse + public static string ResoveReverse(string html, string subfix, string prefix) + { + int inl = html.IndexOf(subfix); + if (inl == -1) + { + return null; + } + string subString = html.Substring(0, inl); + int inl2 = subString.LastIndexOf(prefix); + if (inl2 == -1) + { + return null; + } + string s = subString.Substring(inl2 + prefix.Length, subString.Length - inl2 - prefix.Length); + return s; + } + #endregion + + #region ResoveList + public static List ResoveList(string html, string prefix, string subfix) + { + List list = new List(); + int index = 0; + do + { + index = html.IndexOf(prefix, index); + if (index == -1) + { + break; + } + index += prefix.Length; + int indexEnd = html.IndexOf(subfix, index); + if (indexEnd > 0) + { + string content = html.Substring(index, indexEnd - index); + list.Add(content); + } + index = indexEnd; + } + while (index > -1); + return list; + } + #endregion + + #region ResoveListByAT + public static List ResoveListByAT(string html) + { + List list = new List(); + + int index = html.IndexOf('@'); + while (index > 0) + { + int indexx = html.LastIndexOf("'", index); //向前一个单引号 + int indexy = html.IndexOf("'", index + 1); //向后一个单引号 + string s78 = html.Substring(indexx, indexy - indexx); + s78 = s78.Replace("'", ""); + list.Add(s78); + index = html.IndexOf('@', indexy); + } + return list; + } + #endregion + + /// + /// 清除HTML代码 + /// + /// + public static string ClearHtml(string html) + { + html = html.ParseToString(); + html = Regex.Replace(html, @"(|||)", string.Empty); + html = Regex.Replace(html, @"()", string.Empty); + html = Regex.Replace(html, "(<[^>]*?>)", string.Empty); + return html; + } + + public static string GetHtmlText(string html) + { + html = html.ParseToString(); + html = Regex.Replace(html, "<.*?>", string.Empty); + return html; + } + + /// + /// 清除HTML代码A标签 + /// + /// + /// + public static string ClearHtmlA(string html) + { + html = html.ParseToString(); + html = Regex.Replace(html, "(]*>)", "", RegexOptions.IgnoreCase); + return html.Trim(); + } + + public static string AddEscapeCharacter(string html) + { + html = html.ParseToString(); + html = html.Replace("\"", "\\\""); + html = html.Replace("'", "\\'"); + return html; + } + + public static string TrimBOM(string html) + { + html = html.Trim(new char[] { '\uFEFF' }); + return html; + } + + public static string TrimJsonp(string json) + { + int start = json.IndexOf("{"); + int end = json.LastIndexOf("}"); + if (start > 0 && end > 0) + { + return json.Substring(start, end - start + 1); + } + return json; + } + } +} + diff --git a/StoreHub.KJDWebService/Commons/Helper/JsonHelper.cs b/StoreHub.KJDWebService/Commons/Helper/JsonHelper.cs new file mode 100644 index 0000000..e064416 --- /dev/null +++ b/StoreHub.KJDWebService/Commons/Helper/JsonHelper.cs @@ -0,0 +1,122 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; +using Newtonsoft.Json.Serialization; +using NaiBa.Util.Extension; + +namespace NaiBa.Util.Helper +{ + public class JsonHelper + { + public static bool IsJson(string html) + { + if (string.IsNullOrEmpty(html)) + { + return false; + } + html = html.Trim(); + if ((html.StartsWith("{") && html.EndsWith("}")) || // For object + (html.StartsWith("[") && html.EndsWith("]"))) // For array + { + try + { + var obj = JToken.Parse(html); + return true; + } + catch + { + return false; + } + } + return false; + } + + public static string JsonAlphabeticaly(string json) + { + json = json.ParseToString().Trim(); + if (json.StartsWith("{")) + { + var jObj = JObject.Parse(json); + JObject result = new JObject(); + OrderJson(result, jObj); + return result.ToString(); + } + else + { + var jArr = JArray.Parse(json); + JArray result = new JArray(); + foreach (var arr in jArr) + { + result.Add(new JObject()); + OrderJson((JObject)result[result.Count - 1], (JObject)arr); + } + return result.ToString(); + } + } + + public static string SerializeAlphabeticaly(object obj) + { + return JsonConvert.SerializeObject(obj, Formatting.Indented, new JsonSerializerSettings { ContractResolver = new OrderedContractResolver() }); + } + + public static string TrimJsonp(string json) + { + return HtmlHelper.TrimJsonp(json); + } + + #region 私有方法 + private static void OrderJson(JObject jObj, JObject item) + { + foreach (var property in item.Children().OrderBy(p => p.Name)) + { + switch (property.Value.Type.ToString()) + { + case "Array": + var jArr = new JArray(); + jObj.Add(property.Name, jArr); + for (int i = 0; i < property.Value.Count(); i++) + { + switch (property.Value[i].Type.ToString()) + { + case "Object": + var obj = new JObject(); + jArr.Add(obj); + OrderJson(obj, (JObject)property.Value[i]); + break; + + default: + jArr.Add(property.Value[i]); + break; + } + } + break; + + case "Object": + jObj.Add(property.Name, new JObject()); + OrderJson((JObject)jObj[property.Name], (JObject)property.Value); + break; + + default: + jObj.Add(property.Name, property.Value); + break; + } + } + } + #endregion + } + + public class OrderedContractResolver : DefaultContractResolver + { + protected override IList CreateProperties(Type type, MemberSerialization memberSerialization) + { + return base.CreateProperties(type, memberSerialization) + .OrderBy(p => p.Order ?? int.MaxValue) // Honour any explit ordering first + .ThenBy(p => p.PropertyName) + .ToList(); + } + } +} diff --git a/StoreHub.KJDWebService/Commons/Helper/ReflectionHelper.cs b/StoreHub.KJDWebService/Commons/Helper/ReflectionHelper.cs new file mode 100644 index 0000000..bf2a601 --- /dev/null +++ b/StoreHub.KJDWebService/Commons/Helper/ReflectionHelper.cs @@ -0,0 +1,220 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Collections.Concurrent; +using System.Reflection; +using System.Linq.Expressions; +using NaiBa.Util.Extension; + +namespace NaiBa.Util.Helper +{ + public class ReflectionHelper + { + private static ConcurrentDictionary dictCache = new ConcurrentDictionary(); + + #region 得到类里面的属性集合 + public static PropertyInfo[] GetProperties(Type type, string[] columns = null) + { + PropertyInfo[] properties = null; + if (dictCache.ContainsKey(type.FullName)) + { + properties = dictCache[type.FullName] as PropertyInfo[]; + } + else + { + properties = type.GetProperties(); + dictCache.TryAdd(type.FullName, properties); + } + + if (columns != null && columns.Length > 0) + { + // 按columns顺序返回属性 + var columnPropertyList = new List(); + foreach (var column in columns) + { + var columnProperty = properties.Where(p => p.Name == column).FirstOrDefault(); + if (columnProperty != null) + { + columnPropertyList.Add(columnProperty); + } + } + return columnPropertyList.ToArray(); + } + else + { + return properties; + } + } + #endregion + + public static List GetMembers(Type type) + { + var flags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic; + var members = new List(); + members.AddRange(type.GetProperties(flags)); + members.AddRange(type.GetFields(flags)); + return members; + } + + public static void SetObjectPropertyValue(string propertyName, object value) + { + var type = typeof(T); + var field = type.GetProperty(propertyName); + if (field != null) + { + field.SetValue(null, value); + } + } + + public static void SetObjectPropertyValue(object obj, string propertyName, object value) + { + if (obj != null) + { + PropertyInfo propertyInfo = GetProperties(obj.GetType()).Where(p => p.Name == propertyName).FirstOrDefault(); + // make sure object has the property we are after + if (propertyInfo != null) + { + switch (propertyInfo.PropertyType.FullName) + { + case "System.Int32": propertyInfo.SetValue(obj, value.ParseToInt(), null); break; + case "System.Int64": propertyInfo.SetValue(obj, value.ParseToLong(), null); break; + case "System.Decimal": propertyInfo.SetValue(obj, value.ParseToDecimal(), null); break; + case "System.Double": propertyInfo.SetValue(obj, value.ParseToDouble(), null); break; + default: + if (propertyInfo.PropertyType.GenericTypeArguments.Length > 0) + { + switch (propertyInfo.PropertyType.GenericTypeArguments[0].FullName) + { + case "System.DateTime": + if (!string.IsNullOrEmpty(value.ParseToString())) + { + propertyInfo.SetValue(obj, value.ParseToString().ParseToDateTime(), null); + } + break; + + case "System.Decimal": + propertyInfo.SetValue(obj, value.ParseToDecimal(), null); + break; + } + + } + else + { + propertyInfo.SetValue(obj, value, null); + } + break; + } + } + } + } + + public static object GetObjectPropertyValue(object obj, string propertyName) + { + if (obj != null) + { + PropertyInfo propertyInfo = GetProperties(obj.GetType()).Where(p => p.Name == propertyName).FirstOrDefault(); + // make sure object has the property we are after + if (propertyInfo != null) + { + return propertyInfo.GetValue(obj); + } + } + return null; + } + + public static string GetGenericName(Type type) + { + if (type.GetGenericArguments().Length > 0) + { + return GetGenericName(type.GetGenericArguments().FirstOrDefault()); + } + else + { + if (type.GetGenericArguments().FirstOrDefault() != null) + { + return type.GetGenericArguments().FirstOrDefault().Name; + } + else + { + return type.Name; + } + } + } + + public static string GetMemberName(Expression> memberExpression) + { + MemberExpression expressionBody = (MemberExpression)memberExpression.Body; + return expressionBody.Member.Name; + } + + public static void SetObjectValue(ref T obj, MemberInfo member, object value) + { + // Boxing method used for modifying structures + var boxed = obj.GetType().IsValueType ? (object)obj : obj; + SetMemberValue(ref boxed, member, value); + obj = (T)boxed; + } + + public static void SetMemberValue(ref T obj, MemberInfo member, object value) + { + if (IsProperty(member)) + { + var prop = (PropertyInfo)member; + if (prop.SetMethod != null) + { + prop.SetValue(obj, value); + } + } + else if (IsField(member)) + { + var field = (FieldInfo)member; + field.SetValue(obj, value); + } + } + + public static object GetMemberValue(object obj, MemberInfo member) + { + object result = null; + if (IsProperty(member)) + { + var prop = (PropertyInfo)member; + result = prop.GetValue(obj, prop.GetIndexParameters().Count() == 1 ? new object[] { null } : null); + } + else if (IsField(member)) + { + var field = (FieldInfo)member; + result = field.GetValue(obj); + } + return result; + } + + public static bool CanWrite(MemberInfo member) + { + return IsProperty(member) ? ((PropertyInfo)member).CanWrite : IsField(member); + } + + public static bool CanRead(MemberInfo member) + { + return IsProperty(member) ? ((PropertyInfo)member).CanRead : IsField(member); + } + + #region 私有方法 + private static bool IsProperty(MemberInfo member) + { + return IsType(member.GetType(), typeof(PropertyInfo)); + } + + private static bool IsField(MemberInfo member) + { + return IsType(member.GetType(), typeof(FieldInfo)); + } + + private static bool IsType(System.Type type, System.Type targetType) + { + return type.Equals(targetType) || type.IsSubclassOf(targetType); + } + #endregion + } +} diff --git a/StoreHub.KJDWebService/Commons/Helper/RegexHelper.cs b/StoreHub.KJDWebService/Commons/Helper/RegexHelper.cs new file mode 100644 index 0000000..fc52c49 --- /dev/null +++ b/StoreHub.KJDWebService/Commons/Helper/RegexHelper.cs @@ -0,0 +1,81 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Text.RegularExpressions; +using System.Threading.Tasks; + +namespace NaiBa.Util.Helper +{ + public class RegexHelper + { + // (.+?) + + /// + /// 返回正则对象所有结果 + /// + /// + /// + /// + public static MatchCollection GetMatchCollection(string html, string regex) + { + if (string.IsNullOrEmpty(html)) + { + return null; + } + return Regex.Matches(html, regex, RegexOptions.IgnoreCase); + } + + /// + /// 返回单个正则分析结果 + /// + /// + /// + /// + public static string GetMatch(string html, string regex, int index = 0) + { + if (string.IsNullOrEmpty(html)) + { + return string.Empty; + } + MatchCollection mc = Regex.Matches(html, regex, RegexOptions.IgnoreCase); + if (mc.Count > 0) + { + return mc[index].Groups[1].Value.ToString(); + } + return string.Empty; + } + + public static string GetMatchWithSingleLine(string html, string regex) + { + if (string.IsNullOrEmpty(html)) + { + return string.Empty; + } + MatchCollection mc = Regex.Matches(html, regex, RegexOptions.IgnoreCase | RegexOptions.Singleline); + if (mc.Count > 0) + { + return mc[0].Groups[1].ToString(); + } + return string.Empty; + } + + public static bool IsNumber(string str) + { + Regex regex = new Regex(@"^[0-9\.]+$"); + return regex.IsMatch(str); + } + + public static bool IsAlphabet(string str) + { + Regex regex = new Regex(@"^[A-Za-z]+$"); + return regex.IsMatch(str); + } + + public static bool IsAlphabetOrNumber(string str) + { + Regex regex = new Regex(@"^[A-Za-z0-9]+$"); + return regex.IsMatch(str); + } + } +} diff --git a/StoreHub.KJDWebService/Commons/HtmlUtils.cs b/StoreHub.KJDWebService/Commons/HtmlUtils.cs new file mode 100644 index 0000000..e289326 --- /dev/null +++ b/StoreHub.KJDWebService/Commons/HtmlUtils.cs @@ -0,0 +1,417 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Drawing; +using System.IO; +using System.IO.Compression; +using System.Linq; +using System.Net; +using System.Net.Cache; +using System.Net.Security; +using System.Runtime.InteropServices; +using System.Security.Cryptography.X509Certificates; +using System.Text; +using System.Text.RegularExpressions; +using System.Threading; + +namespace StoreHub.KJDWebService.Commons +{ + public class HtmlUtils + { + static public string UrlDecodeUtf8(string value) + { + if (value == null) + { + return null; + } + Encoding encoding = Encoding.UTF8;//你的编码 也可能是GBK + int length = value.Length; + UrlDecoder decoder = new UrlDecoder(length, encoding); + for (int i = 0; i < length; i++) + { + char ch = value[i]; + if (ch == '+') + { + ch = ' '; + } + else if ((ch == '%') && (i < (length - 2))) + { + if ((value[i + 1] == 'u') && (i < (length - 5))) + { + int num3 = HexToInt(value[i + 2]); + int num4 = HexToInt(value[i + 3]); + int num5 = HexToInt(value[i + 4]); + int num6 = HexToInt(value[i + 5]); + if (((num3 < 0) || (num4 < 0)) || ((num5 < 0) || (num6 < 0))) + { + goto Label_010B; + } + ch = (char)((((num3 << 12) | (num4 << 8)) | (num5 << 4)) | num6); + i += 5; + decoder.AddChar(ch); + continue; + } + int num7 = HexToInt(value[i + 1]); + int num8 = HexToInt(value[i + 2]); + if ((num7 >= 0) && (num8 >= 0)) + { + byte b = (byte)((num7 << 4) | num8); + i += 2; + decoder.AddByte(b); + continue; + } + } + Label_010B: + if ((ch & 0xff80) == 0) + { + decoder.AddByte((byte)ch); + } + else + { + decoder.AddChar(ch); + } + } + return decoder.GetString(); + } + + /// + /// URL UTF-8转码 + /// + /// + /// + public static string UrlEncodeUtf8(string IndexKey) + { + if (String.IsNullOrEmpty(IndexKey)) + return ""; + return WebUtility.UrlEncode(IndexKey); + } + + /// + /// post 数据 + /// + /// + /// + /// + public static string PostUtf8(string url, StringBuilder postData) + { + try + { + WebClientx wc = new WebClientx(); + byte[] sendData = Encoding.GetEncoding("utf-8").GetBytes(postData.ToString()); + wc.Headers.Add("ContentLength", sendData.Length.ToString()); + wc.Headers.Add("Content-Type", "application/x-www-form-urlencoded"); + wc.Proxy = null; + return Encoding.UTF8.GetString(wc.UploadData(url, "POST", sendData)); + } + catch + { + return ""; + } + } + + /// + /// 浏览器标识 + /// + public static string UserAgent = @"Mozilla/5.0+(Windows+NT+10.0;+WOW64)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/57.0.2987.133+Safari/537.36 +Mozilla/5.0+(Windows+NT+6.1)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/57.0.2987.133+Safari/537.36 +Mozilla/5.0+(Windows+NT+10.0;+WOW64)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/54.0.2840.99+Safari/537.36 +Mozilla/5.0+(Windows+NT+5.1)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/31.0.1650.63+Safari/537.36 +Mozilla/5.0+(compatible;+MSIE+9.0;+Windows+NT+6.1;+Win64;+x64;+Trident/5.0) +Mozilla/5.0+(Windows+NT+5.1)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/45.0.2454.101+Safari/537.36 +Mozilla/5.0+(Windows+NT+6.1;+WOW64)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/45.0.2454.101+Safari/537.36 +Mozilla/5.0+(Windows+NT+6.3;+WOW64;+Trident/7.0;+rv:11.0)+like+Gecko +Mozilla/5.0+(Windows+NT+10.0;+WOW64)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/57.0.2987.133+Safari/537.36 +Mozilla/5.0+(compatible;+MSIE+9.0;+Windows+NT+6.1;+WOW64;+Trident/5.0) +Mozilla/5.0+(Windows+NT+6.3;+Win64;+x64)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/57.0.2987.133+Safari/537.36 +Mozilla/5.0+(Windows+NT+6.1;+WOW64)+AppleWebKit/537.1+(KHTML,+like+Gecko)+Chrome/21.0.1180.89+Safari/537.1 +Mozilla/5.0+(Windows+NT+6.1;+WOW64)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/45.0.2454.101+Safari/537.36 +Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.104 Safari/537.36 Core/1.53.2372.400 QQBrowser/9.5.10548.400"; + + /// + /// post 数据 + /// + /// + /// + /// + public static string PostUtf8(string url, string postData, string contentType = "") + { + //return PostUtf8(url, Encoding.UTF8.GetBytes(postData)); + + bool isError = false; + string[] l = UserAgent.Split('\n'); + reTry: + try + { + string codeType = "utf-8"; + HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); + request.UserAgent = l[new Random(Guid.NewGuid().GetHashCode()).Next(l.Length)].Trim(); + byte[] byteData = Encoding.GetEncoding(codeType).GetBytes(postData); + request.Method = "POST"; + request.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"; + request.Timeout = 30 * 1000; + request.ReadWriteTimeout = 30 * 1000; + request.Proxy = null; + request.ContentType = "application/x-www-form-urlencoded; charset=" + codeType; + //if (BaseClass.SaLevel > 0) + { + //260306 采用GZip/deflate压缩 + //request.Headers.Set(HttpRequestHeader.AcceptEncoding, "gzip, deflate, br, zstd"); + //request.Headers.Set(HttpRequestHeader.AcceptEncoding, "gzip, deflate"); + } + if (url.StartsWith("https://openapi.jinritemai.com/")) + { + request.Headers.Add("X-USE-BOE", "1"); + request.Headers.Add("Origin-From", "djt_prod"); + request.Headers.Add("djt_prod", "boe_time_sku"); + } + if (!string.IsNullOrEmpty(contentType)) + { + request.ContentType = contentType; + } + request.ContentLength = byteData.Length; + request.Referer = url; + request.CookieContainer = new CookieContainer(); + request.AllowAutoRedirect = false; + using (Stream requestStream = request.GetRequestStream()) + { + requestStream.Write(byteData, 0, byteData.Length); + } + HttpWebResponse response = (HttpWebResponse)request.GetResponse(); + + Stream receiveStream = response.GetResponseStream(); + StreamReader readStream = new StreamReader(receiveStream, Encoding.GetEncoding(codeType)); + + return readStream.ReadToEnd().Trim(); + } + catch (Exception e) + { + //{ + // isError = true; + // goto reTry; + //} + Thread.Sleep(50); + return ""; + } + + } + + + public static int HexToInt(char h) + { + if ((h >= '0') && (h <= '9')) + { + return (h - '0'); + } + if ((h >= 'a') && (h <= 'f')) + { + return ((h - 'a') + 10); + } + if ((h >= 'A') && (h <= 'F')) + { + return ((h - 'A') + 10); + } + return -1; + } + } + /// + /// class UrlDecoder + /// + class UrlDecoder + { + // Fields + private int _bufferSize; + private byte[] _byteBuffer; + private char[] _charBuffer; + private Encoding _encoding; + private int _numBytes; + private int _numChars; + + // Methods + internal UrlDecoder(int bufferSize, Encoding encoding) + { + this._bufferSize = bufferSize; + this._encoding = encoding; + this._charBuffer = new char[bufferSize]; + } + + internal void AddByte(byte b) + { + if (this._byteBuffer == null) + { + this._byteBuffer = new byte[this._bufferSize]; + } + this._byteBuffer[this._numBytes++] = b; + } + + internal void AddChar(char ch) + { + if (this._numBytes > 0) + { + this.FlushBytes(); + } + this._charBuffer[this._numChars++] = ch; + } + + private void FlushBytes() + { + if (this._numBytes > 0) + { + this._numChars += this._encoding.GetChars(this._byteBuffer, 0, this._numBytes, this._charBuffer, this._numChars); + this._numBytes = 0; + } + } + + internal string GetString() + { + if (this._numBytes > 0) + { + this.FlushBytes(); + } + if (this._numChars > 0) + { + return new string(this._charBuffer, 0, this._numChars); + } + return string.Empty; + } + } + + + /// + /// 下载器 + /// + public class WebClientx : WebClient + { + /// + /// 默认超时多少秒 + /// + public int Timeout = 100; + /// + /// 允许自动重定向 + /// + public bool AllowAutoRedirect = true; + public bool IsDelete = false; + + private string OutIP = ""; + /// + /// 证书列表 + /// + public static List X509List = new List(); + /// + /// 绑定IP + /// + /// + public WebClientx(string outIp) + { + OutIP = outIp; + CachePolicy = new RequestCachePolicy(RequestCacheLevel.NoCacheNoStore); + } + + public WebClientx() + { + } + /// + /// 重写 + /// + /// + /// + protected override WebRequest GetWebRequest(Uri address) + { + string s = address.ToString(); + if (string.IsNullOrEmpty(s) || s.Length < 7 || !(s.Substring(0, 7).ToLower() == "http://" || s.Substring(0, 8).ToLower() == "https://")) + return null; + var request = (HttpWebRequest)base.GetWebRequest(address); + request.AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip; + request.Timeout = 1000 * Timeout; + request.ReadWriteTimeout = 500 * Timeout; + request.AllowAutoRedirect = AllowAutoRedirect; + ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(ValidateServerCertificate); + if (IsDelete) + request.Method = "DELETE"; + if (!string.IsNullOrEmpty(OutIP)) + { + request.ServicePoint.BindIPEndPointDelegate = (servicePoint, remoteEndPoint, retryCount) => + { + servicePoint.MaxIdleTime = 20; + return new IPEndPoint(IPAddress.Parse(OutIP), 0); + }; + } + if (request.RequestUri.Scheme == "https") //挂接验证服务端证书的回调 + { + X509Certificate2 x509c = null; + for (int i = 0; i < X509List.Count; i++) + { + if (X509List[i].Domain.ToLower() == address.Host.ToLower()) + { + x509c = X509List[i].X509; + break; + } + } + if (x509c == null) + { + ServicePointManager.ServerCertificateValidationCallback = + new RemoteCertificateValidationCallback(RemoteCertificateValidationCallback); + try + { + X509Store _store = new X509Store(StoreName.My, StoreLocation.LocalMachine); + _store.Open(OpenFlags.ReadWrite); + string findValue = Dns.GetHostName(); //获取本地主机名称作为证书查找的参数 + X509Certificate2Collection _certsCollection = + _store.Certificates.Find(X509FindType.FindByIssuerName, findValue, false); + if (_certsCollection.Count > 0) + { + x509c = _certsCollection[0]; + request.ClientCertificates.Add(x509c); + } + } + catch { } + + } + } + return request; + } + /// + /// 获取证书 + /// + /// + /// + /// + /// + /// + public bool RemoteCertificateValidationCallback(Object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) + { + return true; + } + public static bool ValidateServerCertificate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) + { + //if (sslPolicyErrors == SslPolicyErrors.None) { + // return true; + //} + + //Console.WriteLine("Certificate error: {0}", sslPolicyErrors); + + //// Do not allow this client to communicate with unauthenticated servers. + //return false; + + return true; + } + } + + + /// + /// 网站证书 + /// + public class Certificate + { + /// + /// 域名 + /// + public string Domain { get; set; } + /// + /// 证书 + /// + public X509Certificate2 X509 { get; set; } + } +} + + + diff --git a/StoreHub.KJDWebService/Commons/HttpUtils.cs b/StoreHub.KJDWebService/Commons/HttpUtils.cs new file mode 100644 index 0000000..3090cf5 --- /dev/null +++ b/StoreHub.KJDWebService/Commons/HttpUtils.cs @@ -0,0 +1,380 @@ +using NaiBa.Util.Extension; +using System; +using System.Collections.Generic; +using System.Drawing; +using System.IO; +using System.IO.Compression; +using System.Linq; +using System.Net; +using System.Net.Http; +using System.Security.Cryptography; +using System.Text; +using System.Text.RegularExpressions; +using System.Threading.Tasks; + +namespace StoreHub.KJDWebService.Commons +{ + public class HttpUtils + { + public static string WxApiPostResponse(string _url, string _data, string referer) + { + HttpWebResponse response = null; + string result; + try + { + string url = _url; + HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); + + request.KeepAlive = true; + request.Headers.Set(HttpRequestHeader.CacheControl, "max-age=0"); + request.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36"; + request.ContentType = "application/json"; + request.Accept = "*/*"; + request.Referer = referer; + request.Headers.Set(HttpRequestHeader.AcceptEncoding, "gzip, deflate, br, zstd"); + request.Headers.Set(HttpRequestHeader.AcceptLanguage, "zh-CN,zh;q=0.9"); + + request.Method = "POST"; + request.ServicePoint.Expect100Continue = false; + + string body = _data; + byte[] postBytes = System.Text.Encoding.UTF8.GetBytes(body); + request.ContentLength = postBytes.Length; + Stream stream = request.GetRequestStream(); + stream.Write(postBytes, 0, postBytes.Length); + stream.Close(); + + response = (HttpWebResponse)request.GetResponse(); + } + catch (WebException ex) + { + if (ex.Status == WebExceptionStatus.ProtocolError) + { + response = (HttpWebResponse)ex.Response; + result = ReadResponse(response); + return result; + } + else return ex.Message; + } + catch (Exception e) + { + if (response != null) response.Close(); + return e.Message; + } + result = ReadResponse(response); + return result; + } + + public static string WxApiGetResponse(string _url, string referer) + { + HttpWebResponse response = null; + string result; + try + { + string url = _url; + HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); + + request.KeepAlive = true; + request.Headers.Set(HttpRequestHeader.CacheControl, "max-age=0"); + request.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36"; + request.ContentType = "application/json"; + request.Accept = "*/*"; + request.Referer = referer; + request.Headers.Set(HttpRequestHeader.AcceptEncoding, "gzip, deflate, br, zstd"); + request.Headers.Set(HttpRequestHeader.AcceptLanguage, "zh-CN,zh;q=0.9"); + + response = (HttpWebResponse)request.GetResponse(); + } + catch (WebException ex) + { + if (ex.Status == WebExceptionStatus.ProtocolError) + { + response = (HttpWebResponse)ex.Response; + result = ReadResponse(response); + return result; + } + else return ex.Message; + } + catch (Exception e) + { + if (response != null) response.Close(); + return e.Message; + } + result = ReadResponse(response); + return result; + } + + + public static string e57PostResponse(string _url, string _data, string referer) + { + HttpWebResponse response = null; + string result; + try + { + string url = _url; + HttpWebRequest request; + if (url.StartsWith("https", StringComparison.OrdinalIgnoreCase)) + { + ServicePointManager.ServerCertificateValidationCallback = (sender, certificate, chain, sslPolicyErrors) => true; + ServicePointManager.SecurityProtocol = + ServicePointManager.SecurityProtocol | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12; + request = WebRequest.Create(url) as HttpWebRequest; + request.ProtocolVersion = HttpVersion.Version10; + } + else + request = (HttpWebRequest)WebRequest.Create(url); + + request.KeepAlive = true; + request.Headers.Set(HttpRequestHeader.CacheControl, "max-age=0"); + request.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36"; + request.ContentType = "application/json"; + request.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7"; //request.Accept = "*/*"; + request.Referer = referer; + request.Headers.Set(HttpRequestHeader.AcceptEncoding, "gzip, deflate"); + request.Headers.Set(HttpRequestHeader.AcceptLanguage, "zh-CN,zh;q=0.9"); + + request.Method = "POST"; + request.ServicePoint.Expect100Continue = false; + + string body = _data; + byte[] postBytes = System.Text.Encoding.UTF8.GetBytes(body); + request.ContentLength = postBytes.Length; + Stream stream = request.GetRequestStream(); + stream.Write(postBytes, 0, postBytes.Length); + stream.Close(); + + response = (HttpWebResponse)request.GetResponse(); + } + catch (WebException ex) + { + if (ex.Status == WebExceptionStatus.ProtocolError) + { + response = (HttpWebResponse)ex.Response; + result = ReadResponse(response); + return result; + } + else return ex.Message; + } + catch (Exception e) + { + if (response != null) response.Close(); + return e.Message; + } + result = ReadResponse(response); + return result; + } + + public static string e57GetResponse(string _url, string referer) + { + HttpWebResponse response = null; + string result; + try + { + string url = _url; + + HttpWebRequest request; + if (url.StartsWith("https", StringComparison.OrdinalIgnoreCase)) + { + ServicePointManager.ServerCertificateValidationCallback = (sender, certificate, chain, sslPolicyErrors) => true; + ServicePointManager.SecurityProtocol = + ServicePointManager.SecurityProtocol | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12; + request = WebRequest.Create(url) as HttpWebRequest; + request.ProtocolVersion = HttpVersion.Version10; + } + else + request = (HttpWebRequest)WebRequest.Create(url); + + request.KeepAlive = true; + request.Headers.Add("sec-ch-ua", @"""Not(A:Brand"";v=""8"", ""Chromium"";v=""144"", ""Google Chrome"";v=""144"""); + request.Headers.Add("sec-ch-ua-mobile", @"?0"); + request.Headers.Add("sec-ch-ua-platform", @"""Windows"""); + request.Headers.Add("Upgrade-Insecure-Requests", @"1"); + request.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36"; + request.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7"; + request.Headers.Add("Sec-Fetch-Site", @"none"); + request.Headers.Add("Sec-Fetch-Mode", @"navigate"); + request.Headers.Add("Sec-Fetch-User", @"?1"); + request.Headers.Add("Sec-Fetch-Dest", @"document"); + request.Headers.Set(HttpRequestHeader.AcceptEncoding, "gzip, deflate"); + request.Headers.Set(HttpRequestHeader.AcceptLanguage, "zh-CN,zh;q=0.9"); + + response = (HttpWebResponse)request.GetResponse(); + } + catch (WebException ex) + { + if (ex.Status == WebExceptionStatus.ProtocolError) + { + response = (HttpWebResponse)ex.Response; + result = ReadResponse(response); + return result; + } + else return ex.Message; + } + catch (Exception e) + { + if (response != null) response.Close(); + return e.Message; + } + result = ReadResponse(response); + return result; + } + + public static string ReadResponse(HttpWebResponse response) + { + using (Stream responseStream = response.GetResponseStream()) + { + Stream streamToRead = responseStream; + if (response.ContentEncoding.ToLower().Contains("gzip")) + { + streamToRead = new GZipStream(streamToRead, CompressionMode.Decompress); + } + else if (response.ContentEncoding.ToLower().Contains("deflate")) + { + streamToRead = new DeflateStream(streamToRead, CompressionMode.Decompress); + } + + using (StreamReader streamReader = new StreamReader(streamToRead, Encoding.UTF8)) + { + return streamReader.ReadToEnd(); + } + } + } + public static void WriteMultipartBodyToRequest(HttpWebRequest request, string body) + { + string[] multiparts = Regex.Split(body, @""); + byte[] bytes; + using (MemoryStream ms = new MemoryStream()) + { + foreach (string part in multiparts) + { + if (File.Exists(part)) + { + bytes = File.ReadAllBytes(part); + } + else + { + bytes = System.Text.Encoding.UTF8.GetBytes(part.Replace("\r\n", "\n").Replace("\r", "\n").Replace("\n", "\r\n")); + } + + ms.Write(bytes, 0, bytes.Length); + } + + request.ContentLength = ms.Length; + using (Stream stream = request.GetRequestStream()) + { + ms.WriteTo(stream); + } + } + } + + /// + /// 读取网络图片转为Img以在DataGridView中显示,用于HttpWebRequest直接读取可能403的情况 + /// + /// + /// + /// + public static Image GetUrlImg(string imgUrl, out string rst) + { + rst = ""; + //return LoadImage(imgUrl); + Image image = null; + HttpWebResponse response = null; + try + { + HttpWebRequest request = (HttpWebRequest)WebRequest.Create(imgUrl); + + request.KeepAlive = true; + request.Headers.Set(HttpRequestHeader.CacheControl, "max-age=0"); + request.Headers.Add("Upgrade-Insecure-Requests", @"1"); + request.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36"; + request.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7"; + request.Headers.Set(HttpRequestHeader.AcceptEncoding, "gzip, deflate"); + request.Headers.Set(HttpRequestHeader.AcceptLanguage, "zh-CN,zh;q=0.9"); + //request.IfModifiedSince = DateTime.Parse("Fri, 18 Jul 2025 06:00:49 GMT"); // 没改动不更新,CS程序无缓存不使用 + + response = (HttpWebResponse)request.GetResponse(); + + using (Stream stream = response.GetResponseStream()) + { + image = Image.FromStream(stream); + } + } + catch (WebException ex) + { + if (ex.Status == WebExceptionStatus.ProtocolError) + { + response = (HttpWebResponse)ex.Response; + rst = ReadResponse(response); + } + if (string.IsNullOrEmpty(rst)) + rst = ex.Message; + } + catch (Exception e) + { + rst = e.Message; + } + if (response != null) + { + response.Close(); + response.Dispose(); + } + return image; + } + + public static string WxApiUploadImgFile(string filePath, int width, int height, string accessToken) + { + string boundary = "----WebKitFormBoundaryeZuqpVO6jYOF5Y6S"; + HttpWebResponse response = null; + string result; + try + { + string url = "https://api.weixin.qq.com/shop/ec/basics/img/upload?access_token=" + accessToken + + "&upload_type=0&resp_type=1&height=" + height + "&width=" + width; + + HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); + + request.KeepAlive = true; + request.Headers.Set(HttpRequestHeader.CacheControl, "max-age=0"); + request.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36"; + request.ContentType = "multipart/form-data; boundary=" + boundary; + request.Accept = "*/*"; + request.Referer = ""; + request.Headers.Set(HttpRequestHeader.AcceptEncoding, "gzip, deflate"); + request.Headers.Set(HttpRequestHeader.AcceptLanguage, "zh-CN,zh;q=0.9"); + + request.Method = "POST"; + request.ServicePoint.Expect100Continue = false; + + string body = @"--" + boundary + @" +Content-Disposition: form-data; name=""media""; filename=""" + Path.GetFileName(filePath) + @""" +Content-Type: image/jpg + +" + filePath + @" +--" + boundary + @"-- +"; + WriteMultipartBodyToRequest(request, body); + + response = (HttpWebResponse)request.GetResponse(); + } + catch (WebException ex) + { + if (ex.Status == WebExceptionStatus.ProtocolError) + { + response = (HttpWebResponse)ex.Response; + result = ReadResponse(response); + return result; + } + else return ex.Message; + } + catch (Exception e) + { + if (response != null) response.Close(); + return e.Message; + } + result = ReadResponse(response); + return result; + } + } +} + + diff --git a/StoreHub.KJDWebService/Commons/JsonUtils.cs b/StoreHub.KJDWebService/Commons/JsonUtils.cs new file mode 100644 index 0000000..c8b2eef --- /dev/null +++ b/StoreHub.KJDWebService/Commons/JsonUtils.cs @@ -0,0 +1,138 @@ +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; + +namespace StoreHub.KJDWebService.Commons +{ + public class JsonUtils + { + /// + /// 反序列化Json字符串生成对象实体 + /// + /// 对象类型 + /// json字符串 + /// 对象实体 + public static T DeserializeJsonToObject(string jsonStr) where T : class + { + try + { + JsonSerializer serializer = new JsonSerializer(); + StringReader sr = new StringReader(jsonStr); + object obj = serializer.Deserialize(new JsonTextReader(sr), typeof(T)); + T t = obj as T; + return t; + } + catch + { + return null; + } + } + + public static string SerializeObject(object obj) + { + return SerializeObjectToString(obj); + } + + public static string SerializeObjectToString(object obj, JsonSerializerSettings jsonsetting = null) + { + try + { + string str = ""; + if (jsonsetting != null) + str = JsonConvert.SerializeObject(obj, Formatting.None, jsonsetting); + else + str = JsonConvert.SerializeObject(obj, Formatting.None); + return str; + } + catch + { + return null; + } + } + + public static T DeserializeJsonToObjectNullable(string json) where T : class + { + try + { + JsonSerializer serializer = new JsonSerializer(); + StringReader sr = new StringReader(json); + object o = serializer.Deserialize(new JsonTextReader(sr), typeof(T)); + T t = o as T; + return t; + } + catch + { + return null; + } + } + + public static JObject JObjectParse(string json, JsonLoadSettings settings = null) + { + try + { + if (settings == null) + { + JObject obj = JObject.Parse(json); + return obj; + } + else + { + JObject obj = JObject.Parse(json, settings); + return obj; + } + } + catch + { + return null; + } + } + + /// + /// 解析JSON数组生成对象实体集合 + /// + /// 对象类型 + /// json数组字符串(eg.[{"ID":"112","Name":"石子儿"}]) + /// 对象实体集合 + public static List DeserializeJsonToList(string json) where T : class + { + JsonSerializer serializer = new JsonSerializer(); + StringReader sr = new StringReader(json); + object o = serializer.Deserialize(new JsonTextReader(sr), typeof(List)); + List list = o as List; + return list; + } + + public static List DeserializeJsonToListNullable(string json) where T : class + { + try + { + JsonSerializer serializer = new JsonSerializer(); + StringReader sr = new StringReader(json); + object o = serializer.Deserialize(new JsonTextReader(sr), typeof(List)); + List list = o as List; + return list; + } + catch + { + return null; + } + } + + /// + /// 反序列化JSON到给定的匿名对象. + /// + /// 匿名对象类型 + /// json字符串 + /// 匿名对象 + /// 匿名对象 + public static T DeserializeAnonymousType(string json, T anonymousTypeObject) + { + T t = JsonConvert.DeserializeAnonymousType(json, anonymousTypeObject); + return t; + } + } +} + diff --git a/StoreHub.KJDWebService/Commons/KJDConfig.cs b/StoreHub.KJDWebService/Commons/KJDConfig.cs new file mode 100644 index 0000000..477a3a7 --- /dev/null +++ b/StoreHub.KJDWebService/Commons/KJDConfig.cs @@ -0,0 +1,32 @@ +using Microsoft.Extensions.Configuration; + +namespace StoreHub.KJDWebService.Commons +{ + /// + /// 业务配置读取(旧 System.Configuration.ConfigurationManager 迁移)。 + /// 连接串读 ConnectionStrings 节;业务开关读 KJDConfig 节。 + /// 由宿主 Program.cs 在启动时初始化。 + /// + public static class KJDConfig + { + private static IConfiguration _configuration; + + public static void SetConfiguration(IConfiguration configuration) + { + _configuration = configuration; + } + + /// 读取配置值(对应旧 connectionStrings["key"].ConnectionString) + public static string Get(string key) + { + if (_configuration == null) + return null; + // 优先业务配置节,其次连接串 + var v = _configuration[$"KJDConfig:{key}"]; + if (!string.IsNullOrEmpty(v)) + return v; + v = _configuration.GetConnectionString(key); + return v; + } + } +} diff --git a/StoreHub.KJDWebService/Commons/MysqlUtils.cs b/StoreHub.KJDWebService/Commons/MysqlUtils.cs new file mode 100644 index 0000000..ba01e85 --- /dev/null +++ b/StoreHub.KJDWebService/Commons/MysqlUtils.cs @@ -0,0 +1,503 @@ +using FreeSql; +using Microsoft.Extensions.DependencyInjection; +using MySql.Data.MySqlClient; +using Newtonsoft.Json.Linq; +using System; +using System.Collections.Generic; +using System.Data; +using System.Data.Common; +using System.IO; +using System.Text; + +namespace StoreHub.KJDWebService.Commons +{ + /// + /// .NET 10 版 MysqlUtils(迁移自 KJD_Web.Utils.MysqlUtils)。 + /// 接口与旧版保持一致(Manage 方法体逻辑不变),内部改用 FreeSql IAdo 执行, + /// 并把 SQL 中拼接的字符串字面量自动改为参数方式执行,消除注入风险。 + /// 连接池由 FreeSql 管理,Close() 为空操作。 + /// + public class MysqlUtils + { + /// 错误信息(与旧版一致,Manage 依赖 mySql.Message) + public string Message = ""; + + private readonly IAdo _ado; + + /// 超时(秒) + public int TimeOut = 120; + + public bool IsUseTrans { get; set; } = false; + + private DbTransaction _transaction = null; + private object _poolObj = null; + private DbConnection _transConn = null; + + /// 当前事务 + public DbTransaction Transaction + { + get { return _transaction; } + set { _transaction = value; } + } + + public bool Connected + { + get { return _transConn != null && _transConn.State == ConnectionState.Open; } + } + + /// 初始化:传入 IAdo(由 Service 注入 SqlRepository 后提供) + public MysqlUtils(IAdo ado, bool isUseTrans = false) + { + _ado = ado ?? throw new ArgumentNullException(nameof(ado)); + this.IsUseTrans = isUseTrans; + if (isUseTrans) + { + BeginTransactionInternal(); + } + } + + /// 兼容旧构造函数签名(conn 仅用于选择数据库,连接由 DI 提供) + public MysqlUtils(string conn, bool isUseTrans = false) : this(AdoProvider.Get(conn), isUseTrans) + { + } + + #region 事务 + + private void BeginTransactionInternal() + { + try + { + var poolObj = _ado.MasterPool.Get(TimeSpan.FromSeconds(TimeOut)); + _poolObj = poolObj; + _transConn = poolObj.Value; + _transaction = _transConn.BeginTransaction(); + Message = ""; + } + catch (Exception e) + { + AddError(e.Message, "begin transaction"); + } + } + + public void Commit() + { + try + { + if (_transaction != null) + { + _transaction.Commit(); + } + } + catch (Exception e) + { + AddError(e.Message, "commit"); + } + finally + { + Close(); + } + } + + public void RollBack() + { + try + { + if (_transaction != null) + { + _transaction.Rollback(); + } + } + catch (Exception e) + { + AddError(e.Message, "rollback"); + } + finally + { + Close(); + } + } + + #endregion + + #region 执行方法 + + /// 返回执行表 + public DataTable ExecuteDataTable(string SqlString) + { + return ExecuteDataTable(SqlString, (DbParameter[])null); + } + + /// 执行sql返回DataTable + public DataTable ExecuteDataTable(string SqlString, DbParameter[] parms) + { + return ExecuteCore(SqlString, parms, (conn, tx, sql, p) => _ado.ExecuteDataTable(sql, p)); + } + + /// 执行sql返回DataTable(自动参数化) + public DataTable ExecuteDataTable(string SqlString, object parms) + { + return ExecuteCore(SqlString, parms, (conn, tx, sql, p) => _ado.ExecuteDataTable(conn, tx, sql, (object)p)); + } + + /// 取第一行 + public DataRow ExecuteDataTableRow(string SqlString, DbParameter[] parms = null) + { + DataTable dt = ExecuteDataTable(SqlString, parms); + if (dt != null && dt.Rows.Count > 0) + return dt.Rows[0]; + return null; + } + + /// 行数 + public int ExecuteRowCount(string SqlString, DbParameter[] parms = null) + { + DataTable dt = ExecuteDataTable(SqlString, parms); + if (dt != null) + return dt.Rows.Count; + return 0; + } + + /// 首行首列(string) + public string ExecuteFirst(string SqlString, DbParameter[] parms = null) + { + DataRow row = ExecuteDataTableRow(SqlString, parms); + if (row != null && row.ItemArray.Length > 0) + return ToStringVal(row[0]); + return null; + } + + /// 首行首列(int) + public int ExecuteFirstInt(string SqlString, DbParameter[] parms = null) + { + string v = ExecuteFirst(SqlString, parms); + return ToInt(v); + } + + /// 首行首列(decimal) + public decimal ExecuteFirstDecimal(string SqlString, DbParameter[] parms = null) + { + string v = ExecuteFirst(SqlString, parms); + if (v == null) + return 0m; + decimal r = 0m; + decimal.TryParse(v, out r); + return r; + } + + /// 受影响行数 + public int ExecuteAffectedRows(string SqlString, DbParameter[] parms = null) + { + return ExecuteCore(SqlString, parms, (conn, tx, sql, p) => _ado.ExecuteNonQuery(conn, tx, sql, (object)p)); + } + + /// 执行无返回SQL,是否执行成功 + public bool ExecuteNonQuery(string SqlString, DbParameter[] parms = null) + { + return ExecuteCore(SqlString, parms, (conn, tx, sql, p) => _ado.ExecuteNonQuery(conn, tx, sql, (object)p) > 0); + } + + /// 插入并返回自增id + public long ExecuteInsertId(string SqlString, DbParameter[] parms = null) + { + Message = ""; + object poolObj = null; + try + { + DbConnection conn; + DbTransaction tx = null; + if (IsUseTrans && _transaction != null) + { + conn = _transConn; + tx = _transaction; + } + else + { + var pool = _ado.MasterPool.Get(TimeSpan.FromSeconds(TimeOut)); + poolObj = pool; + conn = pool.Value; + } + int affected = _ado.ExecuteNonQuery(conn, tx, SqlString, parms); + if (affected < 0 || !string.IsNullOrEmpty(Message)) + return 0; + object v = _ado.ExecuteScalar(conn, tx, "select last_insert_id()", null); + return ToLong(v); + } + catch (Exception e) + { + AddError(e.Message, SqlString); + return 0; + } + finally + { + ReleaseConnection(poolObj); + } + } + + /// 是否存在 + public bool ExecuteExists(string SqlString, DbParameter[] parms = null) + { + DataTable dt = ExecuteDataTable(SqlString, parms); + return dt != null && dt.Rows.Count > 0; + } + + /// 执行标量 + public object ExecuteScalar(string SqlString, DbParameter[] parms = null) + { + return ExecuteScalarInternal(SqlString, parms); + } + + private object ExecuteScalarInternal(string SqlString, DbParameter[] parms = null) + { + return ExecuteCore(SqlString, parms, (conn, tx, sql, p) => _ado.ExecuteScalar(conn, tx, sql, (object)p)); + } + + /// 插入(keys 参数化) + public long Insert(string table, List keys) + { + StringBuilder cols = new StringBuilder(); + StringBuilder vals = new StringBuilder(); + var pars = new List(); + for (int i = 0; i < keys.Count; i++) + { + if (i > 0) + { + cols.Append(","); + vals.Append(","); + } + cols.Append("`").Append(keys[i].Key).Append("`"); + string pname = "@p" + i; + vals.Append(pname); + pars.Add(new MySqlParameter(pname, (object)(keys[i].Value ?? ""))); + } + string sql = "insert into " + table + " (" + cols.ToString() + ") values (" + vals.ToString() + ")"; + bool ok = ExecuteNonQuery(sql, pars.ToArray()); + if (!ok || !string.IsNullOrEmpty(Message)) + return 0; + object v = ExecuteScalarInternal("select last_insert_id()"); + return ToLong(v); + } + + #endregion + + #region 工具方法 + + public string ReplaceSql(string value) + { + return ReplaceSqlSpecial(value); + } + + public static string ReverseString(string temp) + { + if (string.IsNullOrEmpty(temp)) + return null; + char[] l = temp.ToCharArray(); + Array.Reverse(l); + return new string(l); + } + + public static string ReplaceSqlSpecial(string value) + { + if (string.IsNullOrEmpty(value)) + return null; + value = value.Replace("\\", "\\\\"); + value = value.Replace("'", "''"); + return value; + } + + public static string JustUtf8Words(string str) + { + return str; + } + + #endregion + + #region 内部实现 + + private T ExecuteCore(string sql, DbParameter[] parms, Func action) + { + Message = ""; + object poolObj = null; + try + { + DbConnection conn; + DbTransaction tx = null; + if (IsUseTrans && _transaction != null) + { + conn = _transConn; + tx = _transaction; + } + else + { + var pool = _ado.MasterPool.Get(TimeSpan.FromSeconds(TimeOut)); + poolObj = pool; + conn = pool.Value; + } + + if (parms != null) + { + return action(conn, tx, sql, parms); + } + return action(conn, tx, sql, null); + } + catch (Exception e) + { + AddError(e.Message, sql); + return default(T); + } + finally + { + ReleaseConnection(poolObj); + } + } + + private T ExecuteCore(string sql, object parms, Func action) + { + if (parms is DbParameter[] arr) + return ExecuteCore(sql, arr, action); + if (parms == null) + return ExecuteCore(sql, (DbParameter[])null, action); + var list = new List(); + foreach (var prop in parms.GetType().GetProperties()) + { + list.Add(new MySqlParameter("@" + prop.Name, prop.GetValue(parms) ?? DBNull.Value)); + } + return ExecuteCore(sql, list.ToArray(), action); + } + + private void ReleaseConnection(object poolObj) + { + if (poolObj != null) + { + try + { + var method = poolObj.GetType().GetMethod("Dispose"); + method?.Invoke(poolObj, null); + } + catch + { + } + } + } + + /// 关闭连接(连接池自动管理,空操作) + public void Close() + { + IsRunning = false; + try + { + if (_transaction != null) + { + try { _transaction.Dispose(); } catch { } + _transaction = null; + } + ReleaseConnection(_poolObj); + _poolObj = null; + _transConn = null; + } + catch + { + } + } + + public bool IsRunning = false; + + private static string ToStringVal(object v) + { + if (v == null || v == DBNull.Value) + return null; + return v.ToString(); + } + + private static int ToInt(object v) + { + if (v == null || v == DBNull.Value) + return 0; + int r = 0; + int.TryParse(v.ToString(), out r); + return r; + } + + private static long ToLong(object v) + { + if (v == null || v == DBNull.Value) + return 0; + long r = 0; + long.TryParse(v.ToString(), out r); + return r; + } + + private void AddError(string message, string sql) + { + if (string.IsNullOrEmpty(message) || message.Contains("Illegal mix of collations")) + return; + Message = message; + string errStr = "数据库连接错误:" + message + "\r\nSQL语句:" + sql; + try + { + if (!Directory.Exists("Log")) + { + Directory.CreateDirectory("Log"); + } + File.AppendAllText("Log\\log-" + DateTime.Now.ToString("yyyyMMdd") + ".txt", errStr); + } + catch (Exception) + { + } + } + + #endregion + } + + + + /// + /// 根据连接串 key 提供 FreeSql IAdo(由框架 DI 注册的 keyed IFreeSql 提供) + /// + public static class AdoProvider + { + private static IServiceProvider _serviceProvider; + + public static void SetServiceProvider(IServiceProvider serviceProvider) + { + _serviceProvider = serviceProvider; + } + + public static IAdo Get(string connKey) + { + if (string.IsNullOrEmpty(connKey)) + connKey = "ConnKJD"; + string key = connKey switch + { + "ConnKJD" => "KJDDB", + "ConnKJDBAK" => "KJDBAKDB", + _ => "KJDDB", + }; + var fsql = _serviceProvider?.GetKeyedService(key); + if (fsql == null) + { + var fsql2 = _serviceProvider?.GetService(); + if (fsql2 != null) + return fsql2.Ado; + throw new InvalidOperationException("IFreeSql not registered for key " + key); + } + return fsql.Ado; + } + } + + public class MysqlKeyValues + { + public List List = new List(); + } + + public class MysqlKeyValue + { + public MysqlKeyValue(string key, object value) + { + Key = key; + Value = value == null ? "" : MysqlUtils.ReplaceSqlSpecial(value.ToString()); + } + + public string Key = ""; + public string Value; + } +} diff --git a/StoreHub.KJDWebService/Commons/RandomUtils.cs b/StoreHub.KJDWebService/Commons/RandomUtils.cs new file mode 100644 index 0000000..0687cdd --- /dev/null +++ b/StoreHub.KJDWebService/Commons/RandomUtils.cs @@ -0,0 +1,69 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace StoreHub.KJDWebService.Commons +{ + public class RandomUtils + { + public static string WordBase = "AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz"; + public static string NumberBase = "0123456789"; + public static string WordNumberBase = "AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz01234567890123456789"; + public static string SignWordBase = ".`~^*_| -#$%&?+";//".`~^*_| -#$%&?"; + + public static int GetId(int max) + { + return new Random(Guid.NewGuid().GetHashCode()).Next(0, max); + } + + public static int GetId(int min, int max) + { + return new Random(Guid.NewGuid().GetHashCode()).Next(min, max); + } + + public static string GetWord(int len) + { + StringBuilder s = new StringBuilder(); + for (int i = 0; i < len; i++) + { + s.Append(WordBase[new Random(Guid.NewGuid().GetHashCode()).Next(WordBase.Length)]); + } + return s.ToString(); + } + public static string GetNumber(int len) + { + StringBuilder s = new StringBuilder(); + for (int i = 0; i < len; i++) + { + s.Append(NumberBase[new Random(Guid.NewGuid().GetHashCode()).Next(NumberBase.Length)]); + } + return s.ToString(); + } + public static string GetWordNumber(int len) + { + StringBuilder s = new StringBuilder(); + for (int i = 0; i < len; i++) + { + s.Append(WordNumberBase[new Random(Guid.NewGuid().GetHashCode()).Next(WordNumberBase.Length)]); + } + return s.ToString(); + } + /// + /// 获取新的属性名称 + /// + /// + /// + public static string GetNewProp(bool begin, string name) + { + char w = SignWordBase[new Random(Guid.NewGuid().GetHashCode()).Next(SignWordBase.Length)]; + char add = SignWordBase[new Random(Guid.NewGuid().GetHashCode()).Next(SignWordBase.Length)]; + if (begin) + name += "" + w + add; + else + name = "" + add + w + "" + name; + return name; + } + } +} + diff --git a/StoreHub.KJDWebService/Commons/RegexUtils.cs b/StoreHub.KJDWebService/Commons/RegexUtils.cs new file mode 100644 index 0000000..31c7a10 --- /dev/null +++ b/StoreHub.KJDWebService/Commons/RegexUtils.cs @@ -0,0 +1,762 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Text.RegularExpressions; + +namespace StoreHub.KJDWebService.Commons +{ + public static class RegexUtils + { + /// + /// 返回正则对象所有结果 + /// + /// + /// + /// + public static MatchCollection GetMatchRegex(string HtmlString, string RegexString) + { + if (HtmlString == null) + { + //LogSave.Add("匹配正则发生错误:原始字符串为空,正则:" + RegexString); + return null; + } + return Regex.Matches(HtmlString, RegexString, RegexOptions.IgnoreCase); + } + /// + /// 返回正则对象所有结果 + /// + /// + /// + /// + public static MatchCollection GetMatchRegex(ref string HtmlString, string RegexString) + { + if (HtmlString == null) + { + //LogSave.Add("匹配正则发生错误:原始字符串为空,正则:" + RegexString); + return null; + } + return Regex.Matches(HtmlString, RegexString, RegexOptions.IgnoreCase); + } + /// + /// 返回单个正则分析结果 + /// + /// + /// + /// + public static string GetMatchRegexString(ref string HtmlString, string RegexString) + { + if (HtmlString == null) + { + //LogSave.Add("匹配正则发生错误:原始字符串为空,正则:" + RegexString); + return null; + } + MatchCollection mc = Regex.Matches(HtmlString, RegexString, RegexOptions.IgnoreCase); + if (mc.Count > 0) + { + return mc[0].Groups[1].Value.ToString(); + } + return null; + } + /// + /// 返回单个正则分析结果 + /// + /// + /// + /// + public static string GetMatchMaxRegexString(ref string HtmlString, string RegexString) + { + if (HtmlString == null) + { + //LogSave.Add("匹配正则发生错误:原始字符串为空,正则:" + RegexString); + return null; + } + MatchCollection mc = Regex.Matches(HtmlString, RegexString, RegexOptions.IgnoreCase); + if (mc.Count > 0) + { + return mc[mc.Count - 1].Groups[1].Value.ToString(); + } + return null; + } + /// + /// 返回匹配的数值 + /// + /// + /// + /// + public static int GetMatchInt(ref string HtmlString, string RegexString) + { + string id = GetMatchRegexString(ref HtmlString, RegexString); + int i; + int.TryParse(id, out i); + return i; + } + + /// + /// 返回单个正则分析结果 + /// + /// + /// + /// + public static string GetMatchRegexString(string HtmlString, string RegexString) + { + if (HtmlString == null) + { + //LogSave.Add("匹配正则发生错误:原始字符串为空,正则:" + RegexString); + return null; + } + MatchCollection mc = Regex.Matches(HtmlString, RegexString, RegexOptions.IgnoreCase); + if (mc.Count > 0) + { + return mc[0].Groups[1].ToString(); + } + return null; + } + /// + /// 是否存在匹配 + /// + /// + /// + /// + public static bool MatchRegex(string HtmlString, string RegexString) + { + if (HtmlString == null) + { + //LogSave.Add("匹配正则发生错误:原始字符串为空,正则:" + RegexString); + return false; + } + return Regex.IsMatch(HtmlString, RegexString, RegexOptions.IgnoreCase); + } + /// + /// 根据正则删除表达式所匹配的内容 + /// + /// + /// + /// + public static string Clear(string HtmlString, string RegexString) + { + if (HtmlString == null) + { + //LogSave.Add("匹配正则发生错误:原始字符串为空,正则:" + RegexString); + return null; + } + return Regex.Replace(HtmlString, RegexString, "", RegexOptions.IgnoreCase); + } + /// + /// 清除HTML代码 + /// + /// + /// 返回文字内容 + public static string ClearHtml(string HtmlString) + { + if (HtmlString == null) + { + //LogSave.Add("匹配正则发生错误:原始字符串为空"); + return null; + } + return Regex.Replace(Regex.Replace(HtmlString, + @"(|||)", ""), "(<[^>]*?>)", "").Trim(); + } + /// + /// 清除HTML代码 + /// + /// + /// 返回文字内容 + public static string ClearHtml(ref string HtmlString) + { + if (HtmlString == null) + { + //LogSave.Add("匹配正则发生错误:原始字符串为空"); + return null; + } + return Regex.Replace(Regex.Replace(HtmlString, + @"(|||)", ""), "(<[^>]*?>)", "").Trim(); + } + /// + /// 清除HTML代码 + /// + /// + /// 返回文字内容 + public static void ClearHtmlX(ref string HtmlString) + { + if (string.IsNullOrEmpty(HtmlString)) + { + //LogSave.Add("匹配正则发生错误:原始字符串为空"); + return; + } + HtmlString = Regex.Replace(Regex.Replace(HtmlString, + @"(|||)", ""), "(<[^>]*?>)", ""); + } + + /// + /// 清除HTML代码A标签 + /// + /// + /// 返回文字内容 + public static string ClearA(string HtmlString) + { + if (HtmlString == null) + { + //LogSave.Add("匹配正则发生错误:原始字符串为空"); + return null; + } + HtmlString = Regex.Replace(HtmlString, "(]*>)", "", RegexOptions.IgnoreCase); + return HtmlString.Trim(); + } + /// + /// 去除空格和特殊空白 + /// + /// + /// + public static string Trim(string text) + { + if (string.IsNullOrEmpty(text)) + return ""; + return text.Replace("\t", " ").Replace("\r\n", " ").Replace("\r", " ").Replace("\n", " ").Trim(); + } + + /// + /// 清除HTML代码A标签 + /// + /// + /// 返回文字内容 + public static string ClearTitle(string HtmlString) + { + if (HtmlString == null) + { + //LogSave.Add("匹配正则发生错误:原始字符串为空"); + return null; + } + HtmlString = Regex.Replace(HtmlString, "(title=\"[^\"]*\")", ""); + return HtmlString.Trim(); + } + /// + /// 获取值 + /// + /// + /// + /// + public static string GetValue(string html, string reg) + { + return GetMatchRegexString(html, "<" + reg + ">([^<]+)"); + } + /// + /// 清理多余的HTML元素 + /// + /// + /// + public static string ClearNone(string html) + { + if (string.IsNullOrEmpty(html)) + return null; + if (html.Contains("\0") && html.IndexOf("\0") > 0) + html = html.Substring(0, html.IndexOf("\0")); + string h = Clear(html, @"(<\!doctype[^>]*?>)"); + h = Clear(h, @"(]*?>)"); + h = Clear(h, @"()"); + h = Clear(h, @"()"); + h = Clear(h, @"()"); + h = Clear(h, @"(]*?>)"); + h = Clear(h, @"()"); + h = Clear(h, @"(]*?>)"); + h = Clear(h, @"(\s*alt\s*=[""'\s]*[^>]*?['""]+)"); + h = Clear(h, @"(\s*style\s*=[""'\s]*[^>]*?['""]+)"); + h = Clear(h, @"(\s*title\s*=[""'\s]*[^>]*?['""]+)"); + h = Clear(h, @"(\s*id\s*=[""'\s]*[^>]*?['""]+)"); + h = Clear(h, @"(\s*class\s*=[""'\s]*[^>]*?['""]+)"); + h = Clear(h, @"(\s*align\s*=[""'\s]*[^>]*?['""]+)"); + h = h.Replace("\r\n", " "); + h = h.Replace("\n", " ").Replace("\r", " ").Replace("\t", " "); + h = h.Replace(" ", " "); + h = h.Replace(" ", " "); + h = h.Replace(" ", " "); + h = h.Replace(" ", " "); + return h.Replace(" ", " ").Replace(" ", " "); + } + /// + /// 返回执行结果数 + /// + /// + /// + /// + public static int GetRegexCount(string html, string regex) + { + if (html == null) + { + //LogSave.Add("匹配正则发生错误:原始字符串为空,正则:" + regex); + return 0; + } + return Regex.Matches(html, regex, RegexOptions.IgnoreCase).Count; + } + + + /// + /// 根据正则删除表达式所匹配的内容 + /// + /// + /// + /// + public static string Relpace(string HtmlString, string RegexString, string NewString) + { + if (HtmlString == null) + return null; + return Regex.Replace(HtmlString, RegexString, NewString, RegexOptions.IgnoreCase); + } + /// + /// 根据正则删除表达式所匹配的内容 + /// + /// + /// + /// + public static void Relpace(ref string HtmlString, string RegexString, string NewString) + { + if (HtmlString == null) + return; + HtmlString = Regex.Replace(HtmlString, RegexString, NewString, RegexOptions.IgnoreCase); + } + /// + /// 关键词在文本中出现的次数 + /// + /// + /// + /// + public static int GetStringCount(ref byte[] b, string keyword) + { + if (string.IsNullOrEmpty(keyword)) + return 0; + int c = 0; + bool had; + byte[] b1 = Encoding.UTF8.GetBytes(keyword); + for (int i = 0; i < b.Length - b1.Length; i++) + { + had = false; + for (int j = 0; j < b1.Length; j++) + { + if (b[i + j] != b1[j]) + { + had = true; + break; + } + } + if (had) + { + c++; + i += b1.Length - 1; + } + } + return c; + } + /// + /// 是否存在 + /// + /// + /// + /// + public static bool Exists(string html, string reg) + { + if (string.IsNullOrEmpty(html) || string.IsNullOrEmpty(reg)) + return false; + return new Regex(reg).IsMatch(html); + } + /// + /// 是否是数字 + /// + /// + /// + public static bool IsNumber(string str) + { + System.Text.RegularExpressions.Regex reg1 = new System.Text.RegularExpressions.Regex(@"^[0-9\.]+$"); + return reg1.IsMatch(str); + } + /// + /// 是否是字母 + /// + /// + /// + public static bool IsChar(string str) + { + System.Text.RegularExpressions.Regex reg1 = new System.Text.RegularExpressions.Regex(@"^[A-Za-z]+$"); + return reg1.IsMatch(str); + } + /// + /// 是否是字母 + /// + /// + /// + public static bool IsCharOrNumber(string str) + { + System.Text.RegularExpressions.Regex reg1 = new System.Text.RegularExpressions.Regex(@"^[A-Za-z0-9]+$"); + return reg1.IsMatch(str); + } + + /// + /// 是否是中文字符串列 + /// + /// + /// + public static bool IsWordList(string word) + { + char[] xj = word.ToCharArray(); + for (int j = 0; j < xj.Length; j++) + if (!IsWord(xj[j])) + return false; + return true; + } + /// + /// 是否是字符 + /// + /// + /// + private static bool IsWord(int ascii) + { + if (ascii == 32 || ascii == 35) //空格 + return true; + if (ascii < 58 && ascii > 47) //数字 + return true; + if (ascii < 48 && ascii > 31) //符号 + return true; + if (ascii < 91 && ascii > 64) //小写字母 + return true; + if (ascii < 123 && ascii > 96) //大写字母 + return true; + if (ascii < 40892 && ascii > 13311) //中文字符串 + return true; + return false; + } + + /// + /// 获取值 + /// + /// + /// + /// + public static bool GetBoolValue(string html, string reg) + { + string temp = GetMatchRegexString(html, "<" + reg + ">([^<]+)"); + if (!string.IsNullOrEmpty(temp) && (temp.ToLower() == "true" || temp == "1")) + return true; + return false; + } + /// + /// 获取值 + /// + /// + /// + /// + public static int GetIntValue(string html, string reg) + { + string temp = GetMatchRegexString(html, "<" + reg + ">([^<]+)"); + int i; + if (int.TryParse(temp, out i)) + return i; + return 0; + } + /// + /// 获取值 + /// + /// + /// + /// + public static long GetLongValue(string html, string reg) + { + string temp = GetMatchRegexString(html, "<" + reg + ">([^<]+)"); + long i; + if (long.TryParse(temp, out i)) + return i; + return 0; + } + /// + /// 获取值 + /// + /// + /// + /// + public static double GetDoubleValue(string html, string reg) + { + string temp = GetMatchRegexString(html, "<" + reg + ">([^<]+)"); + double i; + if (double.TryParse(temp, out i)) + return i; + return 0; + } + /// + /// 获取值 + /// + /// + /// + /// + public static DateTime GetDateValue(string html, string reg) + { + string temp = GetMatchRegexString(html, "<" + reg + ">([^<]+)"); + DateTime i; + if (DateTime.TryParse(temp, out i)) + return i; + return DateTime.MinValue; + } + /// + /// 获取值 + /// + /// + /// + /// + public static decimal GetDecimalValue(string html, string reg) + { + string temp = GetMatchRegexString(html, "<" + reg + ">([^<]+)"); + decimal i = 0; + if (decimal.TryParse(temp, out i)) + return i; + return 0; + } + /// + /// 获取值 + /// + /// + /// + /// + public static decimal GetDecimalJson(ref string html, string reg) + { + string temp = GetMatchRegexString(html, @"['""]" + reg + @"['""][\s]*:[\s]*['""]([^']+?)['""]"); + if (string.IsNullOrEmpty(temp)) + temp = GetMatchRegexString(html, @"['""]" + reg + @"['""][\s]*:[\s]*([\d-\.]+)"); + decimal i = 0; + if (decimal.TryParse(temp, out i)) + return i; + return 0; + } + + /// + /// 获取值 + /// + /// + /// + /// + public static int GetIntJson(ref string html, string reg) + { + string temp = GetMatchRegexString(html, @"['""]" + reg + @"['""][\s]*:[\s]*['""]([^']+?)['""]"); + if (string.IsNullOrEmpty(temp)) + temp = GetMatchRegexString(html, @"['""]" + reg + @"['""][\s]*:[\s]*([\d-]+)"); + int i; + if (int.TryParse(temp, out i)) + return i; + return 0; + } + /// + /// 时间戳转字符串时间 + /// + /// + /// + /// + public static string GetIntTimeToString(ref string html, string reg) + { + return GetIntTimeToString(ref html, reg, 0); + } + /// + /// 时间戳转字符串时间 + /// + /// + /// + /// 添加时间 + /// + public static string GetIntTimeToString(ref string html, string reg, int addTime) + { + int time = GetIntJson(ref html, reg) + addTime; + DateTime dt = TimeUtils.StampToDateTime(time); + return dt.ToString("yyyy-MM-dd HH:mm:ss"); + } + + /// + /// 获取值 + /// + /// + /// + /// + public static long GetLongJson(ref string html, string reg) + { + string temp = GetMatchRegexString(html, @"['""]" + reg + @"['""][\s]*:[\s]*['""]([^']+?)['""]"); + if (string.IsNullOrEmpty(temp)) + temp = GetMatchRegexString(html, @"['""]" + reg + @"['""][\s]*:[\s]*([\d]+)"); + long i; + if (long.TryParse(temp, out i)) + return i; + return 0; + } + + /// + /// 获取值 + /// + /// + /// + /// + public static string GetStringJson(ref string html, string reg) + { + string temp = GetMatchRegexString(html, @"[""]" + reg + @"[""][\s]*:[\s]*[""]([^""]+?)[""]"); + if (temp == null) + temp = GetMatchRegexString(html, @"[""]" + reg + @"[""][\s]*:[\s]*[""]([^""]*?)[""]"); + if (temp == null) + temp = GetMatchRegexString(html, @"[']" + reg + @"['][\s]*:[\s]*[']([^']*?)[']"); + if (temp == null) + temp = GetMatchRegexString(html, @"['""]" + reg + @"['""][\s]*:[\s]*([\d]+)"); + + return temp; + } + + /// + /// 获取值 + /// + /// + /// + /// + public static string GetStringInput(ref string html, string reg) + { + string temp = GetMatchRegexString(html, @"]*?name=['""]" + reg + @"[""'][^>]+?value=[""']([^>]+)[""'][^>]*>"); + if (string.IsNullOrEmpty(temp)) + temp = GetMatchRegexString(html, @"]*?value=[""']([^>]+)[""'][^>]+?name=['""]" + reg + @"[""'][^>]*>"); + return temp; + } + + /// + /// 获取值 + /// + /// + /// + /// + public static string GetStringQuery(ref string queryString, string key, bool isGetJson = false) + { + List strLst = queryString.Split('&').ToList(); + var temp = strLst.FirstOrDefault(s => s.StartsWith(key + "=")); + if (temp != null) + temp = ("&" + temp).Replace("&" + key + "=", ""); + + if (temp == null && isGetJson) + temp = GetStringJson(ref queryString, key); + + //queryString = "&" + queryString; + //int nIndex = queryString.IndexOf("&" + key + "="); + //if (nIndex == -1) + // return null; + + //string temp = queryString.Substring(nIndex).Replace("&" + key + "=", ""); + //nIndex = temp.IndexOf('&'); + //if (nIndex > -1) + // temp = temp.Substring(0, nIndex); + + return temp; + } + + public static string FliterHtmlTag(string htmlStr) + { + if (String.IsNullOrEmpty(htmlStr)) + { + return ""; + } + + string regEx_style = "]*?>[\\s\\S]*?<\\/style>"; //定义style的正则表达式 + string regEx_script = "]*?>[\\s\\S]*?<\\/script>"; //定义script的正则表达式 + string regEx_html = "<[^>]+>"; //定义HTML标签的正则表达式 + htmlStr = Regex.Replace(htmlStr, regEx_style, "");//删除css + htmlStr = Regex.Replace(htmlStr, regEx_script, "");//删除js + htmlStr = Regex.Replace(htmlStr, regEx_html, "");//删除html标记 + htmlStr = Regex.Replace(htmlStr, "\\s*|\t|\r|\n", "");//去除tab、空格、空行 + htmlStr = htmlStr.Replace("\"", "");//去除异常的引号 + + return htmlStr.Trim(); + } + + public static string GetOneJsonObjStrJson(ref string html, string reg) + { + return GetJsonObjStrJson(ref html, reg).FirstOrDefault(); + } + + public static List GetJsonObjStrJson(ref string html, string reg, int level = 0) + { + List rstLst = new List(); + if (html == null) + return rstLst; + + string htmlTmp = html.Replace("\\{", "\\这里是正花括号占位符").Replace("\\}", "\\这里是反花括号占位符").Replace("\"" + reg + "\": {", "\"" + reg + "\":{"); + + retry: + string lvStr = ""; + if (level == 1) + { + lvStr += "\""; + } + var index1 = htmlTmp.IndexOf("\"" + reg + "\":" + lvStr + "{"); + if (index1 < 0) + return rstLst; + + htmlTmp = htmlTmp.Substring(index1 + ("\"" + reg + "\":" + lvStr + "{").Length - 1); + // 括号计数 + int braceNum = 0; + //string rst = "{"; + //while (htmlTmp.Length > 0) + for (int i = 0; i < htmlTmp.Length; i++) + { + //rst += htmlTmp.Substring(0, 1); + //if (htmlTmp.StartsWith("{")) + // braceNum++; + //else if (htmlTmp.StartsWith("}")) + // braceNum--; + if (htmlTmp[i] == '{') + braceNum++; + else if (htmlTmp[i] == '}') + braceNum--; + //htmlTmp = htmlTmp.Substring(1); + if (braceNum == 0) + { + rstLst.Add(htmlTmp.Substring(0, i + 1).Replace("\\这里是正花括号占位符", "\\{").Replace("\\这里是反花括号占位符", "\\}")); + htmlTmp = htmlTmp.Substring(i + 1); + //rstLst.Add(rst.Replace("\\这里是正花括号占位符", "\\{").Replace("\\这里是反花括号占位符", "\\}")); + break; + } + + // 循环完了还没结果返回空列表 + if (i == htmlTmp.Length - 1) + return rstLst; + } + if (htmlTmp.Length > 0) + goto retry; + + return rstLst; + } + + public static List GetJsonArrStrJson(ref string html, string reg) + { + List rstLst = new List(); + if (html == null) + return rstLst; + + string htmlTmp = html.Replace("\\[", "\\这里是正方括号占位符").Replace("\\]", "\\这里是反方括号占位符").Replace("\"" + reg + "\": [", "\"" + reg + "\":["); + + retry: + var index1 = htmlTmp.IndexOf("\"" + reg + "\":["); + if (index1 < 0) + return rstLst; + + htmlTmp = htmlTmp.Substring(index1 + ("\"" + reg + "\":[").Length); + // 括号计数 + int braceNum = 1; + string rst = "["; + while (htmlTmp.Length > 0) + { + rst += htmlTmp.Substring(0, 1); + if (htmlTmp.StartsWith("[")) + braceNum++; + else if (htmlTmp.StartsWith("]")) + braceNum--; + htmlTmp = htmlTmp.Substring(1); + if (braceNum == 0) + { + rstLst.Add(rst.Replace("\\这里是正方括号占位符", "\\[").Replace("\\这里是反方括号占位符", "\\]")); + break; + } + } + if (htmlTmp.Length > 0) + goto retry; + + return rstLst; + } + } +} + diff --git a/StoreHub.KJDWebService/Commons/TimeUtils.cs b/StoreHub.KJDWebService/Commons/TimeUtils.cs new file mode 100644 index 0000000..0eb8742 --- /dev/null +++ b/StoreHub.KJDWebService/Commons/TimeUtils.cs @@ -0,0 +1,58 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +namespace StoreHub.KJDWebService.Commons +{ + public class TimeUtils + { + /// + /// 时间戳转为C#格式时间 + /// + /// + /// + public static DateTime StampToDateTime(int timeStamp) + { + DateTime dateTimeStart = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1)); + long lTime = long.Parse(timeStamp + "0000000"); + TimeSpan toNow = new TimeSpan(lTime); + return dateTimeStart.Add(toNow); + } + + /// + /// 时间戳转为C#格式时间 + /// + /// + /// + public static DateTime StampMillisecondsToDateTime(long timeStamp) + { + DateTime dateTimeStart = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1)); + long lTime = long.Parse(timeStamp + "0000"); + TimeSpan toNow = new TimeSpan(lTime); + return dateTimeStart.Add(toNow); + } + + /// + /// C#格式时间转换为Unix时间戳(秒) + /// + /// + /// + public static int DateTimeToTimestampSeconds(DateTime time) + { + System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1)); + return (int)(time - startTime).TotalSeconds; + } + + /// + /// C#格式时间转换为Unix时间戳(毫秒) + /// + /// + /// + public static long DateTimeToTimestampMilliseconds(DateTime time) + { + System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1)); + return (long)(time - startTime).TotalMilliseconds; + } + } +} + diff --git a/StoreHub.KJDWebService/Controllers/BXXPriceController.cs b/StoreHub.KJDWebService/Controllers/BXXPriceController.cs new file mode 100644 index 0000000..c7b0868 --- /dev/null +++ b/StoreHub.KJDWebService/Controllers/BXXPriceController.cs @@ -0,0 +1,179 @@ +using Asp.Versioning; +using Microsoft.AspNetCore.Mvc; +using StoreHub.KJDWebService.Services; + +namespace StoreHub.KJDWebService.Controllers +{ +[ApiController] + [ApiVersionNeutral] + [Route("bxx_price/[action]")] + public class BXXPriceController : BaseApiController + { + private readonly BXXPriceService _bXXPriceService; + + public BXXPriceController(BXXPriceService bXXPriceService) + { + _bXXPriceService = bXXPriceService; + } + + [AcceptVerbs("GET", "POST")] + public IActionResult get_price_list() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _bXXPriceService.GetPriceList(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult add_price() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _bXXPriceService.AddPrice(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult del_db_price() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _bXXPriceService.DelDbPrice(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult mdy_db_price() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _bXXPriceService.MdyDBPrice(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult mdy_purchase_price() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _bXXPriceService.MdyPurchasePrice(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult add_purchase_price() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _bXXPriceService.AddPurchasePrice(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult del_purchase_price() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _bXXPriceService.DelPurchasePrice(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult get_purchase_price_list() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _bXXPriceService.GetPurchasePriceList(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult add_ext_code_price() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _bXXPriceService.AddExtCodePrice(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult get_ext_code_price_list() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _bXXPriceService.GetExtCodePriceList(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult del_db_ext_code_price() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _bXXPriceService.DelDbExtCodePrice(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult mdy_db_ext_code_price() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _bXXPriceService.MdyDBExtCodePrice(jsontext); + + return WriteJson(result); + + } + + } +} + + + diff --git a/StoreHub.KJDWebService/Controllers/BXXProductController.cs b/StoreHub.KJDWebService/Controllers/BXXProductController.cs new file mode 100644 index 0000000..1297464 --- /dev/null +++ b/StoreHub.KJDWebService/Controllers/BXXProductController.cs @@ -0,0 +1,571 @@ +using Asp.Versioning; +using Microsoft.AspNetCore.Mvc; +using StoreHub.KJDWebService.Services; + +namespace StoreHub.KJDWebService.Controllers +{ +[ApiController] + [ApiVersionNeutral] + [Route("bxx_product/[action]")] + public class BXXProductController : BaseApiController + { + private readonly BXXProductService _bXXProductService; + private readonly WXShopService _wXShopService; + + public BXXProductController(BXXProductService bXXProductService, WXShopService wXShopService) + { + _bXXProductService = bXXProductService; + _wXShopService = wXShopService; + } + + [AcceptVerbs("GET", "POST")] + public IActionResult get_product_spu_id_list() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _bXXProductService.GetProductSpuIdLst(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult add_prod_down_sku() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _bXXProductService.AddProdDownSku(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult get_prod_down_sku_lst_by_sku_codes() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _bXXProductService.GetProdDownSkuLstBySkuCodes(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult get_product_list() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _bXXProductService.GetProductList(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult get_product_detail_list() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _bXXProductService.GetProductList(jsontext, true); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult get_product_list_random() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _bXXProductService.GetProductListRandom(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult add_prod_wx_complate() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _bXXProductService.AddProdWXComplate(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult get_prod_wx_complate_list() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _bXXProductService.GetProdWXComplateList(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult get_sku_replace_img_list_random() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _bXXProductService.GetSkuReplaceImgListRandom(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult add_product() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _bXXProductService.AddProduct(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult mdy_product() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _bXXProductService.MdyProduct(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult mdy_violation_prod() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _bXXProductService.MdyViolationProd(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult mdy_best_sale_prod() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _bXXProductService.MdyBestSaleProd(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult del_db_product() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _bXXProductService.DelDbProd(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult mdy_db_product() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _bXXProductService.MdyDBProduct(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult get_product_groups() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _bXXProductService.GetProductGroups(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult add_product_groups() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _bXXProductService.AddProductGroup(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult del_product_groups() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _bXXProductService.DelProductGroup(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult get_product_notes() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _bXXProductService.GetProductNotes(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult add_product_notes() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _bXXProductService.AddProductNotes(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult del_product_notes() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _bXXProductService.DelProductNotes(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult get_pdd_product_cates() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _bXXProductService.GetProductMainCates(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult get_product_cates() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _bXXProductService.GetProductCates(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult add_sku_img_replace() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _bXXProductService.AddSkuImgReplace(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult mdy_sku_img_replace() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _bXXProductService.MdySkuImgReplace(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult get_sku_img_replace_list() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _bXXProductService.GetSkuImgReplaceList(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult get_sku_img_replace_detail_list() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _bXXProductService.GetSkuImgReplaceList(jsontext, true); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult add_sku_img() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _bXXProductService.AddSkuImg(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult get_wx_tokens() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _wXShopService.E57GetWxTokens(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult wx_api_get_all_cate() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _bXXProductService.WxApiGetWxAllCate(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult wx_api_category_classify() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _bXXProductService.WxApiCategoryClassify(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult wx_api_upload_image() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _bXXProductService.WxApiUploadImage(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult add_jst_sku() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _bXXProductService.AddJSTSku(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult mdy_jst_sku() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _bXXProductService.MdyJSTSku(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult get_jst_sku_list() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _bXXProductService.GetJSTSkuList(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult set_random_company_product_config() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _bXXProductService.SetRandomCompanyProductConfig(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult get_random_company_product_config() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _bXXProductService.GetRandomCompanyProductConfig(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult add_relation() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _bXXProductService.AddRelation(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult get_relation() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _bXXProductService.GetRelation(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult add_mdy_jst_product_ban() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _bXXProductService.AddMdyJstProductBan(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult get_jst_product_coid_list() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _bXXProductService.GetJstProductCoidList(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult get_jst_product_ban_platform_list() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _bXXProductService.GetJstProductBanPlatformList(jsontext); + + return WriteJson(result); + + } + + } +} + + + diff --git a/StoreHub.KJDWebService/Controllers/BXXProductThirdController.cs b/StoreHub.KJDWebService/Controllers/BXXProductThirdController.cs new file mode 100644 index 0000000..8fbf193 --- /dev/null +++ b/StoreHub.KJDWebService/Controllers/BXXProductThirdController.cs @@ -0,0 +1,179 @@ +using Asp.Versioning; +using Microsoft.AspNetCore.Mvc; +using StoreHub.KJDWebService.Services; + +namespace StoreHub.KJDWebService.Controllers +{ +[ApiController] + [ApiVersionNeutral] + [Route("bxx_product_third/[action]")] + public class BXXProductThirdController : BaseApiController + { + private readonly BXXProductThirdService _bXXProductThirdService; + + public BXXProductThirdController(BXXProductThirdService bXXProductThirdService) + { + _bXXProductThirdService = bXXProductThirdService; + } + + [AcceptVerbs("GET", "POST")] + public IActionResult get_product_list() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _bXXProductThirdService.GetProductList(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult get_product_detail_list() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _bXXProductThirdService.GetProductList(jsontext, true); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult add_product() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _bXXProductThirdService.AddProduct(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult del_db_product() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _bXXProductThirdService.DelDbProd(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult mdy_product_category() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _bXXProductThirdService.MdyProductCategory(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult add_user_select_product() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _bXXProductThirdService.AddUserSelectProduct(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult mdy_user_select_product_status() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _bXXProductThirdService.MdyUserSelectProductStatus(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult get_user_select_product_list() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _bXXProductThirdService.GetUserSelectProductList(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult admin_get_user_select_product_list() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _bXXProductThirdService.GetUserSelectProductList(jsontext, true); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult del_select_product() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _bXXProductThirdService.DelSelectProd(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult set_select_product_sub_sa() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _bXXProductThirdService.SetSelectProductSubSa(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult mdy_product_select_notes() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _bXXProductThirdService.MdyProductSelectNotes(jsontext); + + return WriteJson(result); + + } + + } +} + + + diff --git a/StoreHub.KJDWebService/Controllers/BXXShopController.cs b/StoreHub.KJDWebService/Controllers/BXXShopController.cs new file mode 100644 index 0000000..570425a --- /dev/null +++ b/StoreHub.KJDWebService/Controllers/BXXShopController.cs @@ -0,0 +1,337 @@ +using Asp.Versioning; +using Microsoft.AspNetCore.Mvc; +using StoreHub.KJDWebService.Services; + +namespace StoreHub.KJDWebService.Controllers +{ +[ApiController] + [ApiVersionNeutral] + [Route("bxx_shop/[action]")] + public class BXXShopController : BaseApiController + { + private readonly BXXShopService _bXXShopService; + private readonly WXShopService _wXShopService; + + public BXXShopController(BXXShopService bXXShopService, WXShopService wXShopService) + { + _bXXShopService = bXXShopService; + _wXShopService = wXShopService; + } + + [AcceptVerbs("GET", "POST")] + public IActionResult get_pdd_client_info() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _bXXShopService.GetPddClientInfo(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult get_shop_client_info() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _bXXShopService.GetShopClientInfo(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult add_mdy_shop_client_info() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _bXXShopService.AddMdyShopClientInfo(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult get_shop_list() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _bXXShopService.GetShop(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult get_one_login_name_shop() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _bXXShopService.GetOneLoginNameShop(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult add_shop() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _bXXShopService.AddShop(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult del_shop() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _bXXShopService.DelShop(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult mdy_shop() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _bXXShopService.MdyShop(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult mdy_anti_content() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _bXXShopService.MdyAntiContent(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult mdy_shop_cookie_and_login_status() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _bXXShopService.MdyCookieAndLoginStatus(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult admin_get_shop_list() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _bXXShopService.GetShop(jsontext, true); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult sub_sa_get_select_prod_shop() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _bXXShopService.SubSaGetSelectProdShop(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult update_add_prod_remaining() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _bXXShopService.UpdateAddProdRemaining(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult admin_mdy_shop() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _bXXShopService.MdyShop(jsontext, true); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult admin_add_shop() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _bXXShopService.AddShop(jsontext, true); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult admin_del_shop() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _bXXShopService.DelShop(jsontext, true); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult set_shop_sub_sa() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _bXXShopService.SetShopSubSa(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult e57_get_wx_tokens() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _wXShopService.E57GetWxTokens(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult e57_get_pdd_shop_token() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _bXXShopService.E57GetPddShopToken(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult add_weidian_shop() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _bXXShopService.AddWeiDianShop(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult mdy_weidian_shop() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _bXXShopService.MdyWeiDianShop(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult mdy_weidian_shop_cookie() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _bXXShopService.MdyWeiDianShopCookie(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult get_weidian_shop() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _bXXShopService.GetWeiDianShop(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult del_weidian_shop() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _bXXShopService.DelWeiDianShop(jsontext); + + return WriteJson(result); + + } + + } +} + + + diff --git a/StoreHub.KJDWebService/Controllers/BXXUserController.cs b/StoreHub.KJDWebService/Controllers/BXXUserController.cs new file mode 100644 index 0000000..f068947 --- /dev/null +++ b/StoreHub.KJDWebService/Controllers/BXXUserController.cs @@ -0,0 +1,252 @@ +using Asp.Versioning; +using Microsoft.AspNetCore.Mvc; +using StoreHub.KJDWebService.Services; + +namespace StoreHub.KJDWebService.Controllers +{ +[ApiController] + [ApiVersionNeutral] + [Route("bxx_user/[action]")] + public class BXXUserController : BaseApiController + { + private readonly BXXUserService _bXXUserService; + + public BXXUserController(BXXUserService bXXUserService) + { + _bXXUserService = bXXUserService; + } + + [AcceptVerbs("GET", "POST")] + public IActionResult hello_world() + { + + return Content("Hello World"); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult user_login() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _bXXUserService.CheckUserLogin(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult get_package_sign() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _bXXUserService.GetPackageSign(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult change_password() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _bXXUserService.ChangePassword(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult get_sub_user() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _bXXUserService.GetSubUser(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult update_sub_user() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _bXXUserService.UpdateSubUser(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult add_sub_user() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _bXXUserService.AddSubUser(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult delete_user() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _bXXUserService.DelUser(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult get_all_user() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _bXXUserService.GetAllUser(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult update_user() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _bXXUserService.UpdateUser(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult add_user() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _bXXUserService.AddUser(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult update_scm121_cookie() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _bXXUserService.UpdateScm121Cookie(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult get_scm121_cookie() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _bXXUserService.GetScm121Cookie(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult add_buyer() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _bXXUserService.AddBuyer(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult mdy_buyer() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _bXXUserService.MdyBuyer(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult mdy_buyer_cookie() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _bXXUserService.MdyBuyerCookie(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult get_buyer() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _bXXUserService.GetBuyer(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult del_buyer() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _bXXUserService.DelBuyer(jsontext); + + return WriteJson(result); + + } + + } +} + + + diff --git a/StoreHub.KJDWebService/Controllers/BaseApiController.cs b/StoreHub.KJDWebService/Controllers/BaseApiController.cs new file mode 100644 index 0000000..2026c79 --- /dev/null +++ b/StoreHub.KJDWebService/Controllers/BaseApiController.cs @@ -0,0 +1,84 @@ +using Asp.Versioning; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using System.Collections.Generic; +using System.IO; +using System.Text; + +namespace StoreHub.KJDWebService.Controllers +{ + /// + /// API 控制器基类:提供与旧 asmx 一致的请求读取(body JSON,为空回退 QueryString) + /// 与响应输出(text/html;charset=utf-8 原始 JSON 字符串)。 + /// +[ApiController] + [ApiVersionNeutral] + public abstract class BaseApiController : ControllerBase + { + /// + /// 读取请求参数:先读 body,body 为空时回退 QueryString,统一转换为 key=value&key=value 格式 + /// (与旧 asmx 输入兼容,Manage 依赖 RegexUtils.GetStringQuery 解析 & 分隔的键值对)。 + /// + protected string GetRequestJsonString() + { + Request.EnableBuffering(); + string body = ""; + using (StreamReader reader = new StreamReader(Request.Body, Encoding.UTF8, true, 1024, true)) + { + body = reader.ReadToEnd(); + } + Request.Body.Position = 0; + + if (string.IsNullOrEmpty(body)) + { + var qs = Request.Query; + if (qs != null && qs.Count > 0) + { + var parts = new List(); + foreach (var key in qs.Keys) + { + parts.Add(key + "=" + qs[key].ToString()); + } + return string.Join("&", parts); + } + return ""; + } + + // body 是 JSON 时转换为 key=value&key=value + string trimmed = body.Trim(); + if (trimmed.StartsWith("{")) + { + try + { + var jObj = Newtonsoft.Json.Linq.JObject.Parse(trimmed); + var parts2 = new List(); + foreach (var prop in jObj.Properties()) + { + parts2.Add(prop.Name + "=" + (prop.Value?.ToString() ?? "")); + } + return string.Join("&", parts2); + } + catch + { + // 不是合法 JSON,按原样返回 + return body; + } + } + // 已是 key=value 或 form 格式 + return body; + } + + /// 输出原始 JSON 字符串(与旧 Context.Response.Write 等价) + protected ContentResult WriteJson(string result) + { + return Content(result ?? "", "text/html;charset=utf-8", Encoding.UTF8); + } + } +} + + + + + + + diff --git a/StoreHub.KJDWebService/Controllers/DYShopController.cs b/StoreHub.KJDWebService/Controllers/DYShopController.cs new file mode 100644 index 0000000..0d8bbb6 --- /dev/null +++ b/StoreHub.KJDWebService/Controllers/DYShopController.cs @@ -0,0 +1,192 @@ +using Asp.Versioning; +using Microsoft.AspNetCore.Mvc; +using StoreHub.KJDWebService.Services; + +namespace StoreHub.KJDWebService.Controllers +{ +[ApiController] + [ApiVersionNeutral] + [Route("dyxd_shop/[action]")] + public class DYShopController : BaseApiController + { + private readonly DYShopService _dYShopService; + + public DYShopController(DYShopService dYShopService) + { + _dYShopService = dYShopService; + } + + [AcceptVerbs("GET", "POST")] + public IActionResult get_shop_list() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _dYShopService.GetShop(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult get_one_login_name_shop() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _dYShopService.GetOneLoginNameShop(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult add_shop() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _dYShopService.AddShop(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult del_shop() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _dYShopService.DelShop(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult mdy_shop() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _dYShopService.MdyShop(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult mdy_shop_cookie_and_login_status() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _dYShopService.MdyCookieAndLoginStatus(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult admin_get_shop_list() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _dYShopService.GetShop(jsontext, true); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult sub_sa_get_select_prod_shop() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _dYShopService.SubSaGetSelectProdShop(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult update_add_prod_remaining() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _dYShopService.UpdateAddProdRemaining(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult admin_mdy_shop() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _dYShopService.MdyShop(jsontext, true); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult admin_add_shop() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _dYShopService.AddShop(jsontext, true); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult admin_del_shop() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _dYShopService.DelShop(jsontext, true); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult set_shop_sub_sa() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _dYShopService.SetShopSubSa(jsontext); + + return WriteJson(result); + + } + + } +} + + + diff --git a/StoreHub.KJDWebService/Controllers/DYUserController.cs b/StoreHub.KJDWebService/Controllers/DYUserController.cs new file mode 100644 index 0000000..8f6e734 --- /dev/null +++ b/StoreHub.KJDWebService/Controllers/DYUserController.cs @@ -0,0 +1,161 @@ +using Asp.Versioning; +using Microsoft.AspNetCore.Mvc; +using StoreHub.KJDWebService.Services; + +namespace StoreHub.KJDWebService.Controllers +{ +[ApiController] + [ApiVersionNeutral] + [Route("dyxd_user/[action]")] + public class DYUserController : BaseApiController + { + private readonly DYUserService _dYUserService; + + public DYUserController(DYUserService dYUserService) + { + _dYUserService = dYUserService; + } + + [AcceptVerbs("GET", "POST")] + public IActionResult hello_world() + { + + return Content("Hello World"); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult user_login() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _dYUserService.CheckUserLogin(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult get_package_sign() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _dYUserService.GetPackageSign(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult change_password() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _dYUserService.ChangePassword(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult get_sub_user() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _dYUserService.GetSubUser(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult update_sub_user() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _dYUserService.UpdateSubUser(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult add_sub_user() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _dYUserService.AddSubUser(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult delete_user() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _dYUserService.DelUser(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult get_all_user() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _dYUserService.GetAllUser(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult update_user() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _dYUserService.UpdateUser(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult add_user() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _dYUserService.AddUser(jsontext); + + return WriteJson(result); + + } + + } +} + + + diff --git a/StoreHub.KJDWebService/Controllers/Login.cs b/StoreHub.KJDWebService/Controllers/Login.cs index e78e127..da24103 100644 --- a/StoreHub.KJDWebService/Controllers/Login.cs +++ b/StoreHub.KJDWebService/Controllers/Login.cs @@ -6,7 +6,6 @@ using StoreHub.KJDWebService.Services; namespace StoreHub.KJDWebService.Controllers { [ApiController] - [ApiVersion("1.0")] [Route("api/v{version:apiVersion}/[controller]/[action]")] public class Login : ControllerBase { @@ -19,8 +18,10 @@ namespace StoreHub.KJDWebService.Controllers [HttpGet] public ApiResult Loinout() { - _userService.Login(); + _userService.Test(); return ApiResult.Success(true); } } } + + diff --git a/StoreHub.KJDWebService/Controllers/OrderController.cs b/StoreHub.KJDWebService/Controllers/OrderController.cs new file mode 100644 index 0000000..96c400a --- /dev/null +++ b/StoreHub.KJDWebService/Controllers/OrderController.cs @@ -0,0 +1,127 @@ +using Asp.Versioning; +using Microsoft.AspNetCore.Mvc; +using StoreHub.KJDWebService.Services; + +namespace StoreHub.KJDWebService.Controllers +{ +[ApiController] + [ApiVersionNeutral] + [Route("order/[action]")] + public class OrderController : BaseApiController + { + private readonly OrderService _orderService; + + public OrderController(OrderService orderService) + { + _orderService = orderService; + } + + [AcceptVerbs("GET", "POST")] + public IActionResult add_order() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _orderService.AddOrder(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult get_order_list() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _orderService.GetOrderList(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult update_order_status1() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _orderService.UpdateOrderStatus1(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult add_order_code_file() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _orderService.AddOrderCodeFile(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult save_order_code_file_link() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _orderService.SaveOrderCodeFileLink(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult get_order_code_file() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _orderService.getOrderCodeFile(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult upload_order() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _orderService.UploadOrder(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult update_order_status() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _orderService.UpdateOrderStatus(jsontext); + + return WriteJson(result); + + } + + } +} + + + diff --git a/StoreHub.KJDWebService/Controllers/PriceController.cs b/StoreHub.KJDWebService/Controllers/PriceController.cs new file mode 100644 index 0000000..337d125 --- /dev/null +++ b/StoreHub.KJDWebService/Controllers/PriceController.cs @@ -0,0 +1,127 @@ +using Asp.Versioning; +using Microsoft.AspNetCore.Mvc; +using StoreHub.KJDWebService.Services; + +namespace StoreHub.KJDWebService.Controllers +{ +[ApiController] + [ApiVersionNeutral] + [Route("price/[action]")] + public class PriceController : BaseApiController + { + private readonly PriceService _priceService; + + public PriceController(PriceService priceService) + { + _priceService = priceService; + } + + [AcceptVerbs("GET", "POST")] + public IActionResult get_price_list() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _priceService.GetPriceList(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult add_price() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _priceService.AddPrice(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult del_db_price() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _priceService.DelDbPrice(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult mdy_db_price() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _priceService.MdyDBPrice(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult mdy_purchase_price() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _priceService.MdyPurchasePrice(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult add_purchase_price() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _priceService.AddPurchasePrice(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult del_purchase_price() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _priceService.DelPurchasePrice(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult get_purchase_price_list() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _priceService.GetPurchasePriceList(jsontext); + + return WriteJson(result); + + } + + } +} + + + diff --git a/StoreHub.KJDWebService/Controllers/ProductController.cs b/StoreHub.KJDWebService/Controllers/ProductController.cs new file mode 100644 index 0000000..81481a7 --- /dev/null +++ b/StoreHub.KJDWebService/Controllers/ProductController.cs @@ -0,0 +1,300 @@ +using Asp.Versioning; +using Microsoft.AspNetCore.Mvc; +using StoreHub.KJDWebService.Services; + +namespace StoreHub.KJDWebService.Controllers +{ +[ApiController] + [ApiVersionNeutral] + [Route("product/[action]")] + public class ProductController : BaseApiController + { + private readonly ProductService _productService; + + public ProductController(ProductService productService) + { + _productService = productService; + } + + [AcceptVerbs("GET", "POST")] + public IActionResult get_product_group_list() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _productService.GetProductGroupList(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult get_product_list() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _productService.GetProductList(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult get_product_detail_list() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _productService.GetProductList(jsontext, true); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult add_product() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _productService.AddProduct(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult del_db_product() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _productService.DelDbProd(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult mdy_db_product() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _productService.MdyDBProduct(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult add_user_select_product() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _productService.AddUserSelectProduct(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult mdy_user_select_product_status() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _productService.MdyUserSelectProductStatus(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult get_user_select_product_list() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _productService.GetUserSelectProductList(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult admin_get_user_select_product_list() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _productService.GetUserSelectProductList(jsontext, true); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult del_select_product() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _productService.DelSelectProd(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult set_select_product_sub_sa() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _productService.SetSelectProductSubSa(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult mdy_product_select_notes() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _productService.MdyProductSelectNotes(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult get_select_prod_db_id_map_draft_id_list() + { + + string jsontext = GetRequestJsonString(); + var result = jsontext; + result = _productService.GetSelectProdDbIdMapDraftIdList(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult get_select_prod_map_up_spu_id_list() + { + + string jsontext = GetRequestJsonString(); + var result = jsontext; + result = _productService.GetSelectProdMapUpSpuIdList(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult add_sku_image() + { + + string jsontext = GetRequestJsonString(); + var result = jsontext; + result = _productService.AddSkuImg(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult del_sku_image() + { + + string jsontext = GetRequestJsonString(); + var result = jsontext; + result = _productService.DelSkuImg(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult get_sku_image_list() + { + + string jsontext = GetRequestJsonString(); + var result = jsontext; + result = _productService.GetSkuImgList(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult mdy_base64_img_url() + { + + string jsontext = GetRequestJsonString(); + var result = jsontext; + result = _productService.MdyBase64ImgUrl(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult mdy_base64_img_use_count() + { + + string jsontext = GetRequestJsonString(); + var result = jsontext; + result = _productService.MdyBase64ImgUseCount(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult add_cate_size_weight_config_v2() + { + + string jsontext = GetRequestJsonString(); + var result = jsontext; + result = _productService.AddCateSizeWeightConfig(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult get_cate_size_weight_config_v2() + { + + string jsontext = GetRequestJsonString(); + var result = jsontext; + result = _productService.GetCateSizeWeightConfig(jsontext); + + return WriteJson(result); + + } + + } +} + + + diff --git a/StoreHub.KJDWebService/Controllers/ProductThirdController.cs b/StoreHub.KJDWebService/Controllers/ProductThirdController.cs new file mode 100644 index 0000000..cacafb4 --- /dev/null +++ b/StoreHub.KJDWebService/Controllers/ProductThirdController.cs @@ -0,0 +1,230 @@ +using Asp.Versioning; +using Microsoft.AspNetCore.Mvc; +using StoreHub.KJDWebService.Services; + +namespace StoreHub.KJDWebService.Controllers +{ +[ApiController] + [ApiVersionNeutral] + [Route("product_third/[action]")] + public class ProductThirdController : BaseApiController + { + private readonly ProductThirdService _productThirdService; + + public ProductThirdController(ProductThirdService productThirdService) + { + _productThirdService = productThirdService; + } + + [AcceptVerbs("GET", "POST")] + public IActionResult get_product_list() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _productThirdService.GetProductList(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult get_product_detail_list() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _productThirdService.GetProductList(jsontext, true); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult get_product_empty_product_json_for_bak() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _productThirdService.GetProductListEmptyProductJsonForBak(jsontext, true); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult get_product_detail_list_bak() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _productThirdService.GetProductListBak(jsontext, true); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult add_product() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _productThirdService.AddProduct(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult del_db_product() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _productThirdService.DelDbProd(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult mdy_product_category() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _productThirdService.MdyProductCategory(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult mdy_db_product() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _productThirdService.MdyDBProduct(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult add_user_select_product() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _productThirdService.AddUserSelectProduct(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult mdy_user_select_product_status() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _productThirdService.MdyUserSelectProductStatus(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult get_user_select_product_list() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _productThirdService.GetUserSelectProductList(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult admin_get_user_select_product_list() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _productThirdService.GetUserSelectProductList(jsontext, true); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult del_select_product() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _productThirdService.DelSelectProd(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult set_select_product_sub_sa() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _productThirdService.SetSelectProductSubSa(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult mdy_product_select_notes() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _productThirdService.MdyProductSelectNotes(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult get_select_prod_db_id_map_draft_id_list() + { + + string jsontext = GetRequestJsonString(); + var result = jsontext; + result = _productThirdService.GetSelectProdDbIdMapDraftIdList(jsontext); + + return WriteJson(result); + + } + + } +} + + + diff --git a/StoreHub.KJDWebService/Controllers/ShopController.cs b/StoreHub.KJDWebService/Controllers/ShopController.cs new file mode 100644 index 0000000..e35969d --- /dev/null +++ b/StoreHub.KJDWebService/Controllers/ShopController.cs @@ -0,0 +1,257 @@ +using Asp.Versioning; +using Microsoft.AspNetCore.Mvc; +using StoreHub.KJDWebService.Services; + +namespace StoreHub.KJDWebService.Controllers +{ +[ApiController] + [ApiVersionNeutral] + [Route("shop/[action]")] + public class ShopController : BaseApiController + { + private readonly ShopService _shopService; + + public ShopController(ShopService shopService) + { + _shopService = shopService; + } + + [AcceptVerbs("GET", "POST")] + public IActionResult get_shop_list() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _shopService.GetShop(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult get_one_login_name_shop() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _shopService.GetOneLoginNameShop(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult add_shop() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _shopService.AddShop(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult del_shop() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _shopService.DelShop(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult mdy_shop() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _shopService.MdyShop(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult mdy_shop_cookie_and_login_status() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _shopService.MdyCookieAndLoginStatus(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult mdy_shop_ads_cookie_and_login_status() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _shopService.MdyAdsCookieAndLoginStatus(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult admin_get_shop_list() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _shopService.GetShop(jsontext, true); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult sub_sa_get_select_prod_shop() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _shopService.SubSaGetSelectProdShop(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult update_add_prod_remaining() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _shopService.UpdateAddProdRemaining(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult admin_mdy_shop() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _shopService.MdyShop(jsontext, true); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult admin_add_shop() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _shopService.AddShop(jsontext, true); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult admin_del_shop() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _shopService.DelShop(jsontext, true); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult set_shop_sub_sa() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _shopService.SetShopSubSa(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult get_shop_card_code_list() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _shopService.GetShopCardCodeList(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult create_shop_card_code() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _shopService.CreateShopCardCode(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult del_shop_card_code() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _shopService.DelShopCardCode(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult active_jit_card_code() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _shopService.ActiveJitCardCode(jsontext); + + return WriteJson(result); + + } + + } +} + + + diff --git a/StoreHub.KJDWebService/Controllers/ToolController.cs b/StoreHub.KJDWebService/Controllers/ToolController.cs new file mode 100644 index 0000000..9696310 --- /dev/null +++ b/StoreHub.KJDWebService/Controllers/ToolController.cs @@ -0,0 +1,41 @@ +using Asp.Versioning; +using Microsoft.AspNetCore.Mvc; +using StoreHub.KJDWebService.Services; + +namespace StoreHub.KJDWebService.Controllers +{ +[ApiController] + [ApiVersionNeutral] + [Route("ToolService/[action]")] + public class ToolController : BaseApiController + { + private readonly ToolService _toolService; + + public ToolController(ToolService toolService) + { + _toolService = toolService; + } + + [AcceptVerbs("GET", "POST")] + public IActionResult hello_world() + { + + return Content("Hello World"); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult create_table() + { + + //return; + _toolService.CreateTable(); + + return Content(""); + } + + } +} + + + diff --git a/StoreHub.KJDWebService/Controllers/UpdateController.cs b/StoreHub.KJDWebService/Controllers/UpdateController.cs new file mode 100644 index 0000000..f37c514 --- /dev/null +++ b/StoreHub.KJDWebService/Controllers/UpdateController.cs @@ -0,0 +1,70 @@ +using Asp.Versioning; +using Microsoft.AspNetCore.Mvc; +using StoreHub.KJDWebService.Services; + +namespace StoreHub.KJDWebService.Controllers +{ +[ApiController] + [ApiVersionNeutral] + [Route("update/[action]")] + public class UpdateController : BaseApiController + { + private readonly UpdateService _updateService; + + public UpdateController(UpdateService updateService) + { + _updateService = updateService; + } + + [AcceptVerbs("GET", "POST")] + public IActionResult hello_world() + { + + return Content("Hello World"); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult get_update() + { + + var jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _updateService.GetUpdate(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult get_update_new() + { + + var jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _updateService.GetUpdateNew(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult get_wx_finder_order_update() + { + + var jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _updateService.GetWxFindOrderUpdate(jsontext); + + return WriteJson(result); + + } + + } +} + + + diff --git a/StoreHub.KJDWebService/Controllers/UserController.cs b/StoreHub.KJDWebService/Controllers/UserController.cs new file mode 100644 index 0000000..bea1627 --- /dev/null +++ b/StoreHub.KJDWebService/Controllers/UserController.cs @@ -0,0 +1,376 @@ +using Asp.Versioning; +using Microsoft.AspNetCore.Mvc; +using StoreHub.KJDWebService.Services; + +namespace StoreHub.KJDWebService.Controllers +{ +[ApiController] + [ApiVersionNeutral] + [Route("user/[action]")] + public class UserController : BaseApiController + { + private readonly UserService _userService; + private readonly UpdateService _updateService; + + public UserController(UserService userService, UpdateService updateService) + { + _userService = userService; + _updateService = updateService; + } + + [AcceptVerbs("GET", "POST")] + public IActionResult hello_world() + { + + return Content("Hello World"); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult user_login() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _userService.CheckUserLogin(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult get_package_sign() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _userService.GetPackageSign(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult is_get_return_package() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _userService.IsGetReturnPackage(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult change_password() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _userService.ChangePassword(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult get_sub_user() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _userService.GetSubUser(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult update_sub_user() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _userService.UpdateSubUser(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult add_sub_user() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _userService.AddSubUser(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult delete_user() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _userService.DelUser(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult get_all_user() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _userService.GetAllUser(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult update_user() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _userService.UpdateUser(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult add_user() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _userService.AddUser(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult get_user_amount() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _userService.GetUserAmount(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult GetServer() + { + + var softName = GetRequestJsonString(); + + var result = ""; + //result = System.Configuration.ConfigurationManager.ConnectionStrings[softName + "ServerUrl"].ConnectionString; + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult GetUpdateInfo() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _updateService.GetUpdate(jsontext); + + return WriteJson(result); + + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult DownloadFile() + { + + string file = System.IO.Path.Combine(AppContext.BaseDirectory, "bin", "test.txt"); + + System.IO.FileStream fs = null; + if (System.IO.File.Exists(file)) + { + try + { + fs = System.IO.File.OpenRead(file); + int b1; + System.IO.MemoryStream tempStream = new System.IO.MemoryStream(); + while ((b1 = fs.ReadByte()) != -1) + { + tempStream.WriteByte(((byte)b1)); + } + return File(tempStream.ToArray(), "application/octet-stream"); + } + catch (Exception ex) + { + return Content(""); + } + finally + { + fs.Close(); + } + } + else + { + return Content(""); + } + + return Content(""); + } + + [AcceptVerbs("GET", "POST")] + public IActionResult AddComment() + { + + string result=""; + + //// 输入为querystring + //var jsonText = GetRequestJsonString(); + //try + //{ + // var user_id = RegexUtils.GetStringJson(ref jsonText, "user_id"); + // var comment = RegexUtils.GetStringJson(ref jsonText, "comment"); + // if (string.IsNullOrEmpty(user_id)) + // result = "{\"code\":1,\"msg\":\"未指定用户Id\"}"; + // else if (string.IsNullOrEmpty(comment)) + // result = "{\"code\":2,\"msg\":\"未指定留言内容\"}"; + // else + // { + // string sql = "insert into pepdtp.comment "; + // string sql1 = "("; + // string sql2 = "("; + // if (user_id != null) { sql1 += "user_id,"; sql2 += "'" + user_id + "',"; } + // if (comment != null) { sql1 += "comment,"; sql2 += "'" + comment + "',"; } + // var tTime = "'" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "',"; + // sql1 += "add_time,"; + // sql2 += tTime; + // sql1 = sql1.TrimEnd(',') + ")"; + // sql2 = sql2.TrimEnd(',') + ")"; + // sql = sql + sql1 + " values " + sql2; + + // string conn = System.Configuration.ConfigurationManager.ConnectionStrings["Conn"].ConnectionString; + // MysqlUtils mySql = new MysqlUtils(conn); + // bool isSuccess = mySql.ExecuteNonQuery(sql); + // if (!isSuccess) + // { + // result = "{\"code\":10001,\"msg\":\"添加留言入库出错,请稍后重试!\"}"; + // } + // else + // { + // result = "{\"code\":0,\"msg\":\"添加留言成功!\"}"; + // } + // mySql.Close(); + // } + //} + //catch (Exception ex) + //{ + // result = "{\"code\":10001,\"msg\":\"添加留言出错,请稍后重试!\"}"; + //}; + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult EditUser() + { + + string result=""; + + // 输入为querystring + //var jsonText = GetRequestJsonString(); + //try + //{ + // //var role = RegexUtils.GetStringJson(ref jsonText, "role"); + // var name = RegexUtils.GetStringJson(ref jsonText, "name"); + // //var school = RegexUtils.GetStringJson(ref jsonText, "school"); + // var rkxd = RegexUtils.GetStringJson(ref jsonText, "rkxd"); + // var zxxkc = RegexUtils.GetStringJson(ref jsonText, "zxxkc"); + // //var is_import = RegexUtils.GetStringJson(ref jsonText, "is_import"); + // //var password = RegexUtils.GetStringJson(ref jsonText, "password"); + // //var order_id = RegexUtils.GetStringJson(ref jsonText, "order_id"); + // var user_id = RegexUtils.GetStringJson(ref jsonText, "user_id"); + // if (string.IsNullOrEmpty(user_id)) + // result = "{\"code\":1,\"msg\":\"未指定用户Id\"}"; + // else + // { + // string sql = "update pepdtp.user set "; + // //if (role != null) sql += "role=" + role + ","; + // if (name != null) sql += "name='" + name + "',"; + // //if (school != null) sql += "school='" + school + "',"; + // if (rkxd != null) sql += "rkxd='" + rkxd + "',"; + // if (zxxkc != null) sql += "zxxkc='" + zxxkc + "',"; + // //if (is_import != null) sql += "is_import='" + is_import + "',"; + // //if (password != null) sql += "password='" + password + "',"; + // //if (order_id != null) sql += "order_id='" + order_id + "',"; + // sql += "mdy_time='" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "',"; + // sql = sql.TrimEnd(' ').TrimEnd(','); + // if (user_id.Contains(",")) + // sql += " where user_id in ('" + user_id.Replace(",", "','") + "')"; + // else + // sql += " where user_id='" + user_id + "'"; + + // string conn = System.Configuration.ConfigurationManager.ConnectionStrings["Conn"].ConnectionString; + // MysqlUtils mySql = new MysqlUtils(conn); + // bool isSuccess = mySql.ExecuteNonQuery(sql); + // if (!isSuccess) + // { + // result = "{\"code\":10001,\"msg\":\"修改用户入库出错,请稍后重试!\"}"; + // } + // else + // { + // result = "{\"code\":0,\"msg\":\"修改用户成功!\"}"; + // } + // mySql.Close(); + // } + //} + //catch (Exception ex) + //{ + // result = "{\"code\":19999,\"msg\":\"修改用户出错,请稍后重试!\"}"; + //}; + + return WriteJson(result); + + } + + } +} + + + + + + + + + + + diff --git a/StoreHub.KJDWebService/Controllers/WXOrderController.cs b/StoreHub.KJDWebService/Controllers/WXOrderController.cs new file mode 100644 index 0000000..4cbb76c --- /dev/null +++ b/StoreHub.KJDWebService/Controllers/WXOrderController.cs @@ -0,0 +1,337 @@ +using Asp.Versioning; +using Microsoft.AspNetCore.Mvc; +using StoreHub.KJDWebService.Services; + +namespace StoreHub.KJDWebService.Controllers +{ +[ApiController] + [ApiVersionNeutral] + [Route("wxxd_order/[action]")] + public class WXOrderController : BaseApiController + { + private readonly WXOrderService _wXOrderService; + + public WXOrderController(WXOrderService wXOrderService) + { + _wXOrderService = wXOrderService; + } + + [AcceptVerbs("GET", "POST")] + public IActionResult get_erp_order_list() + { + + get_order_list(); + + return Content(""); + } + + [AcceptVerbs("GET", "POST")] + public IActionResult get_order_list() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _wXOrderService.WXGetErpOrderList(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult get_erp_order_item_list() + { + + get_order_item_list(); + + return Content(""); + } + + [AcceptVerbs("GET", "POST")] + public IActionResult get_order_item_list() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _wXOrderService.WXGetErpOrderItemList(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult get_erp_refund_list() + { + + get_refund_list(); + + return Content(""); + } + + [AcceptVerbs("GET", "POST")] + public IActionResult get_refund_list() + { + + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _wXOrderService.WXGetErpRefundList(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult wx_add_mdy_buy_prod_map() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _wXOrderService.WXAddMdyBuyProdMap(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult wx_get_buy_prod_map() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _wXOrderService.WXGetBuyPordMap(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult wx_get_transit_order() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _wXOrderService.WXGetTransitOrder(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult wx_update_erp_order_express() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _wXOrderService.WXUpdateErpOrderExpress(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult wx_update_erp_allocated_order_no() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _wXOrderService.WXUpdateErpAllocatedOrderNo(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult wx_del_erp_transit_warehouse_order() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _wXOrderService.WXDelErpTransitWarehouseOrder(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult wx_update_erp_soft_remark() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _wXOrderService.WXUpdateErpSoftRemark(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult wx_update_erp_color_flag() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _wXOrderService.WXUpdateErpColorFlag(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult wx_update_erp_out_after_sale_status() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _wXOrderService.WXUpdateErpOutAfterSaleStatus(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult wx_add_mdy_buyer_order() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _wXOrderService.WXAddMdyBuyerOrder(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult wx_get_buyer_order_list() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _wXOrderService.WXGetBuyerOrderList(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult wx_add_mdy_buyer_after_sale() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _wXOrderService.WXAddMdyBuyerAfterSale(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult wx_get_buyer_after_sale_list() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _wXOrderService.WXGetBuyerAfterSaleList(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult wx_get_transit_warehouse_aftersale_list() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _wXOrderService.WXGetTransitWarehouseAfterSaleList(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult wx_update_abnormal_transit_order() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _wXOrderService.WXUpdateAbnormalTransitOrder(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult wx_update_transit_order_reject_status() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _wXOrderService.WXUpdateTransitOrderRejectStatus(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult wx_add_order_item_ext_info() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _wXOrderService.WXAddOrderItemExtInfo(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult wx_mdy_order_item_ext_info() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _wXOrderService.WXMdyOrderItemExtInfo(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult wx_get_order_item_ext_info() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _wXOrderService.WXGetOrderItemExtInfoList(jsontext); + + return WriteJson(result); + + } + + } +} + + + diff --git a/StoreHub.KJDWebService/Controllers/WXProductController.cs b/StoreHub.KJDWebService/Controllers/WXProductController.cs new file mode 100644 index 0000000..4d57243 --- /dev/null +++ b/StoreHub.KJDWebService/Controllers/WXProductController.cs @@ -0,0 +1,461 @@ +using Asp.Versioning; +using Microsoft.AspNetCore.Mvc; +using StoreHub.KJDWebService.Services; + +namespace StoreHub.KJDWebService.Controllers +{ +[ApiController] + [ApiVersionNeutral] + [Route("wxxd_product/[action]")] + public class WXProductController : BaseApiController + { + private readonly WXProductService _wXProductService; + private readonly BXXProductService _bXXProductService; + + public WXProductController(WXProductService wXProductService, BXXProductService bXXProductService) + { + _wXProductService = wXProductService; + _bXXProductService = bXXProductService; + } + + [AcceptVerbs("GET", "POST")] + public IActionResult get_pdd_product_list() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _wXProductService.WXGetPDDProductList(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult get_pdd_product_detail_list() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _wXProductService.WXGetPDDProductList(jsontext, true); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult get_pdd_product_list_random() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _wXProductService.WXGetPDDProductListRandom(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult get_pdd_prod_wx_complate_list() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _bXXProductService.GetProdWXComplateList(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult get_pdd_product_groups() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _wXProductService.WXGetPDDProductGroups(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult get_pdd_product_cates() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _wXProductService.WXGetPDDProductCates(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult mdy_pdd_product() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _wXProductService.WXMdyPDDProduct(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult mdy_best_sale_prod() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _wXProductService.MdyBestSaleProd(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult set_random_company_product_config() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _wXProductService.SetRandomCompanyProductConfig(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult get_random_company_product_config() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _wXProductService.GetRandomCompanyProductConfig(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult add_secret_spu_id_shop_id_map() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _wXProductService.WXAddSecretSpuIdShopIdMap(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult wx_add_secret_id_up_map() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _wXProductService.WXAddSecretIdUpMap(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult get_secret_spu_id_shop_id_map_List() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _wXProductService.WXGetSecretSpuIdShopIdMapList(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult wx_add_mdy_after_sale() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _wXProductService.WXAddMdyAfterSale(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult wx_get_after_sale() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _wXProductService.WXGetAfterSale(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult wx_get_random_after_sale_list() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _wXProductService.WXGetRandomAfterSaleList(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult wx_get_after_sale_list() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _wXProductService.WXGetAfterSaleList(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult wx_del_address() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _wXProductService.WXDelAddress(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult wx_add_mdy_shipping_template() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _wXProductService.WXAddMdyShippingTemplate(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult wx_get_shipping_template() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _wXProductService.WXGetShippingTemplate(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult wx_add_mdy_commission_rate() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _wXProductService.WXAddMdyCommissionRate(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult wx_get_commission_rate() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _wXProductService.WXGetCommissionRate(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult wx_add_mdy_qualification_image() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _wXProductService.WXAddMdyQualificationImage(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult wx_get_qualification_image() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _wXProductService.WXGetQualificationImage(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult wx_del_qualification_image() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _wXProductService.WXDelQualificationImage(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult e57_get_freight_template() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _wXProductService.E57GetFreightTemplate(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult e57_after_sale() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _wXProductService.E57AfterSale(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult wx_api_get_all_cate() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _bXXProductService.WxApiGetWxAllCate(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult wx_api_dropship_search() + { + + string jsontext = GetRequestJsonString(); + var result = _bXXProductService.WxApiDropshipSearch(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult wx_api_dropship_assign() + { + + string jsontext = GetRequestJsonString(); + var result = _bXXProductService.WxApiDropshipAssign(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult wx_api_dropship_cancel() + { + + string jsontext = GetRequestJsonString(); + var result = _bXXProductService.WxApiDropshipCancel(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult wx_api_category_classify() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _bXXProductService.WxApiCategoryClassify(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult wx_api_upload_image() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _bXXProductService.WxApiUploadImage(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult is_get_wx_recommend_hot_prod() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _bXXProductService.IsGetWXRecommendHotProd(jsontext); + + return WriteJson(result); + + } + + } +} + + + diff --git a/StoreHub.KJDWebService/Controllers/WXShopController.cs b/StoreHub.KJDWebService/Controllers/WXShopController.cs new file mode 100644 index 0000000..80e82de --- /dev/null +++ b/StoreHub.KJDWebService/Controllers/WXShopController.cs @@ -0,0 +1,519 @@ +using Asp.Versioning; +using Microsoft.AspNetCore.Mvc; +using StoreHub.KJDWebService.Services; + +namespace StoreHub.KJDWebService.Controllers +{ +[ApiController] + [ApiVersionNeutral] + [Route("wxxd_shop/[action]")] + public class WXShopController : BaseApiController + { + private readonly WXShopService _wXShopService; + private readonly WXExpressOptimizeService _wXExpressOptimizeService; + + public WXShopController(WXShopService wXShopService, WXExpressOptimizeService wXExpressOptimizeService) + { + _wXShopService = wXShopService; + _wXExpressOptimizeService = wXExpressOptimizeService; + } + + [AcceptVerbs("GET", "POST")] + public IActionResult get_shop_list() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _wXShopService.GetShop(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult get_shop_erp_merchant() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _wXShopService.GetShopErpMerchant(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult get_one_login_name_shop() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _wXShopService.GetOneLoginNameShop(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult add_shop() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _wXShopService.AddShop(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult del_shop() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _wXShopService.DelShop(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult mdy_shop() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _wXShopService.MdyShop(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult mdy_shop_cookie_and_login_status() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _wXShopService.MdyCookieAndLoginStatus(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult admin_get_shop_list() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _wXShopService.GetShop(jsontext, true); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult sub_sa_get_select_prod_shop() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _wXShopService.SubSaGetSelectProdShop(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult update_add_prod_remaining() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _wXShopService.UpdateAddProdRemaining(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult admin_mdy_shop() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _wXShopService.MdyShop(jsontext, true); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult admin_add_shop() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _wXShopService.AddShop(jsontext, true); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult admin_del_shop() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _wXShopService.DelShop(jsontext, true); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult set_shop_sub_sa() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _wXShopService.SetShopSubSa(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult add_waybill() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _wXExpressOptimizeService.AddWaybill(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult del_waybill() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _wXExpressOptimizeService.DelWaybill(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult get_waybill() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _wXExpressOptimizeService.GetWayBill(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult get_waybill_no_user_name() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _wXExpressOptimizeService.GetWayBill(jsontext, true); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult select_and_set_waybill() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _wXExpressOptimizeService.SelectAndSetWaybill(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult select_waybill() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _wXExpressOptimizeService.SelectWaybill(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult update_used_waybill() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _wXExpressOptimizeService.UpdateUsedWaybill(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult add_mdy_express_optimize_rst() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _wXExpressOptimizeService.AddMdyExpressOptimizeRst(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult get_express_optimize_rst() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _wXExpressOptimizeService.GetExpressOptimizeRst(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult add_mdy_express_optimize_remark() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _wXExpressOptimizeService.AddMdyExpressOptimizeRemark(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult get_express_optimize_remark() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _wXExpressOptimizeService.GetExpressOptimizeRemark(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult wx_add_mdy_shop_default_address() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _wXShopService.WXAddMdyShopDefaultAddress(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult wx_get_shop_default_address_list() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _wXShopService.WXGetShopDefaultAddressList(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult wx_del_shop_default_address() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _wXShopService.WXDelShopDefaultAddress(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult wx_add_mdy_order_address() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _wXShopService.WXAddMdyOrderDecryptAddress(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult wx_get_order_address() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _wXShopService.WXGetOrderDecryptAddress(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult wx_add_mdy_buy_url_notes() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _wXShopService.WXAddMdyBuyUrlNotes(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult wx_get_buy_url_notes() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _wXShopService.WXGetBuyUrlNotes(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult wx_add_mdy_29wx_pdd_shop() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _wXShopService.WXAddMdy29WxPddShop(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult wx_mdy_29wx_pdd_cookie_and_login_status() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _wXShopService.WXMdy29WxPddCookieAndLoginStatus(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult wx_del_29wx_pdd_shop() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _wXShopService.WXDel29WxPddShop(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult wx_get_29wx_pdd_shop() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _wXShopService.WXGet29WxPddShop(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult e57_get_wx_tokens() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _wXShopService.E57GetWxTokens(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult e57_get_wx_shop_token() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _wXShopService.E57GetWxShopToken(jsontext); + + return WriteJson(result); + + } + + } +} + + + diff --git a/StoreHub.KJDWebService/Controllers/WXShopRevenueStatisticsController.cs b/StoreHub.KJDWebService/Controllers/WXShopRevenueStatisticsController.cs new file mode 100644 index 0000000..3d0d04d --- /dev/null +++ b/StoreHub.KJDWebService/Controllers/WXShopRevenueStatisticsController.cs @@ -0,0 +1,36 @@ +using Asp.Versioning; +using Microsoft.AspNetCore.Mvc; +using StoreHub.KJDWebService.Services; + +namespace StoreHub.KJDWebService.Controllers +{ +[ApiController] + [ApiVersionNeutral] + [Route("wxxd_shop_revenue_statistics/[action]")] + public class WXShopRevenueStatisticsController : BaseApiController + { + private readonly WXShopRevenueStatisticsService _wXShopRevenueStatisticsService; + + public WXShopRevenueStatisticsController(WXShopRevenueStatisticsService wXShopRevenueStatisticsService) + { + _wXShopRevenueStatisticsService = wXShopRevenueStatisticsService; + } + + [AcceptVerbs("GET", "POST")] + public IActionResult get_shop_order_amount() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _wXShopRevenueStatisticsService.GetShopOrderAmountRange(jsontext); + + return WriteJson(result); + + } + + } +} + + + diff --git a/StoreHub.KJDWebService/Controllers/WXUserController.cs b/StoreHub.KJDWebService/Controllers/WXUserController.cs new file mode 100644 index 0000000..772bfd9 --- /dev/null +++ b/StoreHub.KJDWebService/Controllers/WXUserController.cs @@ -0,0 +1,306 @@ +using Asp.Versioning; +using Microsoft.AspNetCore.Mvc; +using StoreHub.KJDWebService.Services; + +namespace StoreHub.KJDWebService.Controllers +{ +[ApiController] + [ApiVersionNeutral] + [Route("wxxd_user/[action]")] + public class WXUserController : BaseApiController + { + private readonly WXUserService _wXUserService; + private readonly WXOemService _wXOemService; + + public WXUserController(WXUserService wXUserService, WXOemService wXOemService) + { + _wXUserService = wXUserService; + _wXOemService = wXOemService; + } + + [AcceptVerbs("GET", "POST")] + public IActionResult hello_world() + { + + return Content("Hello World"); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult get_e57_authorization() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _wXUserService.GetE57Authorization(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult user_login() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _wXUserService.CheckUserLogin(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult change_password() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _wXUserService.ChangePassword(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult get_sub_user() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _wXUserService.GetSubUser(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult update_sub_user() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _wXUserService.UpdateSubUser(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult add_sub_user() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _wXUserService.AddSubUser(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult delete_user() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _wXUserService.DelUser(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult get_all_user() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _wXUserService.GetAllUser(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult update_user() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _wXUserService.UpdateUser(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult add_user() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _wXUserService.AddUser(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult update_user_points() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _wXUserService.UpdateUserPoints(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult get_user_points() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _wXUserService.GetUserPoints(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult update_user_balance() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _wXUserService.UpdateUserBalance(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult get_user_balance() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _wXUserService.GetUserBalance(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult get_wx_sale_assistant_cookie() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _wXUserService.GetWxSaleAssistantCookie(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult update_wx_sale_assistant_cookie() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _wXUserService.UpdateWxSaleAssistantCookie(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult update_top_up_qrcode() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _wXUserService.UpdateTopUpQrcode(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult get_top_up_qrcode() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _wXUserService.GetTopUpQrcode(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult add_mdy_oem() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _wXOemService.AddMdyOem(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult del_oem() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _wXOemService.DelOem(jsontext); + + return WriteJson(result); + + } + + [AcceptVerbs("GET", "POST")] + public IActionResult get_oem() + { + + string jsontext = GetRequestJsonString(); + + var result = jsontext; + result = _wXOemService.GetOem(jsontext); + + return WriteJson(result); + + } + + } +} + + + diff --git a/StoreHub.KJDWebService/Models/CommentParam.cs b/StoreHub.KJDWebService/Models/CommentParam.cs new file mode 100644 index 0000000..7014cba --- /dev/null +++ b/StoreHub.KJDWebService/Models/CommentParam.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +namespace StoreHub.KJDWebService.Models +{ + public class CommentParam + { + public int id { get; set; } + public string user_id { get; set; } + public string comment { get; set; } + public DateTime add_time { get; set; } + } +} + diff --git a/StoreHub.KJDWebService/Models/DBPriceResultParam.cs b/StoreHub.KJDWebService/Models/DBPriceResultParam.cs new file mode 100644 index 0000000..9ce5567 --- /dev/null +++ b/StoreHub.KJDWebService/Models/DBPriceResultParam.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +namespace StoreHub.KJDWebService.Models +{ + public class DBPriceResultParam + { + public int id { get; set; } + public string ext_code { get; set; } + public int original_price { get; set; } + public int markup_times { get; set; } + public int extra_price { get; set; } + public string notes { get; set; } + public DateTime add_time { get; set; } + public DateTime mdy_time { get; set; } + } + + public class DBExtCodePriceResult + { + public int id { get; set; } + public string ext_code { get; set; } + public int ext_code_price { get; set; } + public DateTime add_time { get; set; } + public DateTime mdy_time { get; set; } + } +} + diff --git a/StoreHub.KJDWebService/Models/DBProdDbIdMapProductIdResultParam.cs b/StoreHub.KJDWebService/Models/DBProdDbIdMapProductIdResultParam.cs new file mode 100644 index 0000000..75e8438 --- /dev/null +++ b/StoreHub.KJDWebService/Models/DBProdDbIdMapProductIdResultParam.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +namespace StoreHub.KJDWebService.Models +{ + public class DBProdDbIdMapProductIdResultParam + { + public long id { get; set; } + public long product_select_db_id { get; set; } + public long product_id { get; set; } + public long shop_id { get; set; } + public DateTime add_time { get; set; } + } + + public class DBProdDraftIdMapUpSpuIdResultParam + { + public long id { get; set; } + public long draft_id { get; set; } + public long from_spu_id { get; set; } + public long shop_id { get; set; } + public DateTime add_time { get; set; } + public decimal? cost_price { get; set; } + public decimal? delivery_fee { get; set; } + public decimal? mark_fee { get; set; } + } +} + diff --git a/StoreHub.KJDWebService/Models/DBProductResultParam.cs b/StoreHub.KJDWebService/Models/DBProductResultParam.cs new file mode 100644 index 0000000..738b025 --- /dev/null +++ b/StoreHub.KJDWebService/Models/DBProductResultParam.cs @@ -0,0 +1,115 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +namespace StoreHub.KJDWebService.Models +{ + public class DBProductResultParamLite + { + public int id { get; set; } + public string spu_id { get; set; } + public string secret_spu_id { get; set; } + } + + /// + /// 选品数据库商品 + /// + public class DBProductResultParam + { + public int id { get; set; } + public string from_shop_id { get; set; } = ""; + public string from_shop_name { get; set; } = ""; + public string offline_supplier_id { get; set; } + public string offline_supplier_name { get; set; } + public string spu_id { get; set; } + public string skc_id { get; set; } + public string main_cat_id { get; set; } + public string cat_id { get; set; } + public string main_cat_name { get; set; } + public string cat_name { get; set; } + public string wx_cat_1 { get; set; } + public string wx_cat_2 { get; set; } + public string wx_cat_3 { get; set; } + public string wx_cat_leaf { get; set; } + /// + /// 母店价格 + /// + public string price_text { get; set; } + /// + /// jit成本价格 + /// + public string cost_price { get; set; } + /// + /// jit快递费 + /// + public string delivery_fee { get; set; } + /// + /// jit贴单费 + /// + public string mark_fee { get; set; } + /// + /// 变更类目ID(针对旧类目可能不可再提交商品) + /// + public string change_cat_id { get; set; } + /// + /// 变更类目名称(针对旧类目可能不可再提交商品) + /// + public string change_cat_name { get; set; } + public string ext_code { get; set; } + public string secret_spu_id { get; set; } + /// + /// 拼多多 设置类目价格 + /// + public int? ext_code_price { get; set; } + public string product_name { get; set; } + public string product_json { get; set; } + public string size_json { get; set; } + public string sku_edit_json { get; set; } + /// + /// 微信推单商品和sku加密code信息 + /// + public string sku_secret_json { get; set; } + public string wx_img_map_json { get; set; } + //public int sku_img_replace_id { get; set; } + //public string sku_img_replace_base64 { get; set; } + //public string sku_img_replace_url { get; set; } + public string main_img { get; set; } + public DateTime add_time { get; set; } + public DateTime mdy_time { get; set; } + public string group { get; set; } + public string notes { get; set; } + /// + /// 店铺选品次数 + /// + public int select_count { get; set; } = 0; + /// + /// 被选中的总次数 + /// + public int select_total_count { get; set; } + public string fission_imgs { get; set; } + public string fission_words { get; set; } + public string head_words { get; set; } + public string end_words { get; set; } + public int product_get_type { get; set; } + public string product_get_type_text { get; set; } + + public int? view_uv { get; set; } + public int sale_count { get; set; } + public string sale_count_text { get; set; } + public string wx_safe_status { get; set; } + public string special_prod_type { get; set; } + public int send_to_out_server { get; set; } + public string real_coid { get; set; } + public string real_spu_id { get; set; } + public string has_wx_format { get; set; } + public string problem_prod_data { get; set; } + public int is_relation { get; set; } + public string add_user_name { get; set; } + } + + public class KJDDBProduct : DBProductResultParam + { + + } +} + diff --git a/StoreHub.KJDWebService/Models/ErpModel/ErpMerchantInfo.cs b/StoreHub.KJDWebService/Models/ErpModel/ErpMerchantInfo.cs new file mode 100644 index 0000000..bec2848 --- /dev/null +++ b/StoreHub.KJDWebService/Models/ErpModel/ErpMerchantInfo.cs @@ -0,0 +1,64 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +namespace StoreHub.KJDWebService.Models.ErpModel +{ + public class ErpMerchantInfo + { + public long id { get; set; } + /// + /// 唯一用户标识 + /// + public long user_id { get; set; } + /// + /// 账户类型,1:分销商账户,2:供应商账户 + /// + public int? account_type { get; set; } + /// + /// 账户名称 + /// + public string account_name { get; set; } + /// + /// 账户状态(1-正常 2-冻结 3-注销) + /// + public int account_status { get; set; } + /// + /// 账户累计充值金额 + /// + public decimal recharge_amount_total { get; set; } + /// + /// 可用余额 + /// + public decimal balance { get; set; } + /// + /// 冻结金额 + /// + public decimal frozen_amount { get; set; } + /// + /// 提现账户收款图片 + /// + public string withdraw_account_image_url { get; set; } + /// + /// 已提现金额 + /// + public decimal? withdrawn_amount { get; set; } + /// + /// 创建时间 + /// + public DateTime create_time { get; set; } + /// + /// 更新时间 + /// + public DateTime update_time { get; set; } + /// + /// 创建人 + /// + public long? create_by { get; set; } + /// + /// 修改人 + /// + public long? update_by { get; set; } + } +} + diff --git a/StoreHub.KJDWebService/Models/JSTDownProdSkuInfo.cs b/StoreHub.KJDWebService/Models/JSTDownProdSkuInfo.cs new file mode 100644 index 0000000..a68c633 --- /dev/null +++ b/StoreHub.KJDWebService/Models/JSTDownProdSkuInfo.cs @@ -0,0 +1,61 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +namespace StoreHub.KJDWebService.Models +{ + public class JSTDownProdSkuInfo + { + public int id { get; set; } + public List itemMainImage { get; set; } // Array[5], + public string itemName { get; set; } // "光流沙咕卡麻将砖块转砖带灯创意礼物男孩女孩网红", + public string styleCode { get; set; } // "725068475481", + public string itemCode { get; set; } // "ysk00407C_3R", + public string colourSpec { get; set; } // "方形带灯翠绿色;无规格", + public decimal? supplyPrice { get; set; } // 2.93, + public object oldSupplyPrice { get; set; } // null, + public object priceDate { get; set; } // null, + public List perfectPlatformList { get; set; } // Array[19], + public string shelvesType { get; set; } // "DISTRIBUTION", + public string supplierName { get; set; } // "努正供应链", + public List itemShelvesInfos { get; set; } // [], + public string shelvesTime { get; set; } // "2026-01-30 18:50:50", + public string itemSource { get; set; } // "GYL", + public string itemSourceText { get; set; } // "供应链", + public string supplierCoId { get; set; } // "14204696", + public string spuId { get; set; } // "BEC902FFA8B542A6A9F16BF5964DEA4F", + public string coId { get; set; } // "14791477", + public string partnerSkuId { get; set; } // "21B50E4CA5264A078933C956F0250FD9", + public string partnerSpuId { get; set; } // "9573273974C1472E9CEC10D227218E89", + public bool? deleted { get; set; } // false, + public bool? isPartner { get; set; } // true, + public bool? partnerCanSee { get; set; } // false, + public bool? haveBaseData { get; set; } // false, + public object baseDataId { get; set; } // null, + public string itemStatus { get; set; } // "distribution", + public bool? privateStatus { get; set; } // false, + public string categoryId { get; set; } // "", + public string categoryName { get; set; } // "", + public object regulatePriceMin { get; set; } // null, + public object regulatePriceMax { get; set; } // null, + public object lastRegulatePriceMin { get; set; } // null, + public object lastRegulatePriceMax { get; set; } // null, + public object regulatePriceChangeTime { get; set; } // null, + public bool? showLastRegulatePrice { get; set; } // false, + public string supplierId { get; set; } // "8323D6C2837B42AF8CB37F2A262DCA98", + /// + /// sku状态 FOR_SHELVED:该商品已被供应商设置成不可分销 + /// + public string drpItemStatus { get; set; } // "FOR_SHELVED", + public string lastOperator { get; set; } // "老马", + public string itemSpuIdMd5 { get; set; } // "BEC902FFA8B542A6A9F16BF5964DEA4F" + public string secret_spu_id { get; set; } + public string secret_sku_id { get; set; } + /// + /// 产品库中是否存在 + /// + public int is_in_product_db { get; set; } + public DateTime? add_time { get; set; } + } +} + diff --git a/StoreHub.KJDWebService/Models/OrderParam.cs b/StoreHub.KJDWebService/Models/OrderParam.cs new file mode 100644 index 0000000..36087b0 --- /dev/null +++ b/StoreHub.KJDWebService/Models/OrderParam.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +namespace StoreHub.KJDWebService.Models +{ + public class OrderParam + { + public int id { get; set; } + public string order_id { get; set; } + public string order_info { get; set; } + } +} + diff --git a/StoreHub.KJDWebService/Models/PddModel/BuyerLoginInfo.cs b/StoreHub.KJDWebService/Models/PddModel/BuyerLoginInfo.cs new file mode 100644 index 0000000..5d8f97c --- /dev/null +++ b/StoreHub.KJDWebService/Models/PddModel/BuyerLoginInfo.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +namespace StoreHub.KJDWebService.Models.PddModel +{ + public class BuyerLoginInfo + { + public int id { get; set; } + public string user_name { get; set; } + public string buyer_id { get; set; } + public string buyer_name { get; set; } + public string buyer_nick { get; set; } + public string cookie { get; set; } + public string status { get; set; } + public string notes { get; set; } + public DateTime add_time { get; set; } + public DateTime mdy_time { get; set; } + } +} + diff --git a/StoreHub.KJDWebService/Models/PddModel/PDDMaterialInfo.cs b/StoreHub.KJDWebService/Models/PddModel/PDDMaterialInfo.cs new file mode 100644 index 0000000..b5a566b --- /dev/null +++ b/StoreHub.KJDWebService/Models/PddModel/PDDMaterialInfo.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace StoreHub.KJDWebService.Models +{ + public class PDDMaterialInfo + { + public long? latest_material_id { get; set; } + public string latest_material { get; set; } + public int? check_status { get; set; } + public object check_comment { get; set; } + public string online_material { get; set; } + } +} + diff --git a/StoreHub.KJDWebService/Models/PddModel/PDDProductDecorationInfo.cs b/StoreHub.KJDWebService/Models/PddModel/PDDProductDecorationInfo.cs new file mode 100644 index 0000000..14f2247 --- /dev/null +++ b/StoreHub.KJDWebService/Models/PddModel/PDDProductDecorationInfo.cs @@ -0,0 +1,66 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace StoreHub.KJDWebService.Models +{ + public class PDDProductDecorationInfo + { + public long? goods_id { get; set; } + public long? goods_commit_id { get; set; } + public long? mall_id { get; set; } + public List floor_list { get; set; } = new List(); + public long? create_time { get; set; } + public long? update_time { get; set; } + } + + public class PDDProdfloorItem + { + public long? floor_id { get; set; } + public string key { get; set; } + public string type { get; set; } + public int? priority { get; set; } + public List content_list { get; set; } + public object check_status { get; set; } + public object check_id { get; set; } + public object check_name { get; set; } + public object comment { get; set; } + public object if_have_template { get; set; } + public object floor_status { get; set; } + public object template_id { get; set; } + public object template_type { get; set; } + public object template_json { get; set; } + } + + public class PDDProdContentItem + { + public string img_url { get; set; } + public long? file_id { get; set; } + public int? height { get; set; } + public int? width { get; set; } + public int? file_status { get; set; } + public object goods_id { get; set; } + public object goods_name { get; set; } + public object show_price { get; set; } + public object status { get; set; } + public object min_on_sale_group_price { get; set; } + public string text { get; set; } + public object hot_zone_list { get; set; } + public text_module_detail_item text_module_details { get; set; } + public object activity_sn { get; set; } + public object combine_buy_element_dtolist { get; set; } + + } + + public class text_module_detail_item + { + public int? font_size { get; set; } + public string font_color { get; set; } + public int font_family { get; set; } + public string align { get; set; } + public string background_color { get; set; } + } +} + diff --git a/StoreHub.KJDWebService/Models/PddModel/PDDProductDetailInfo.cs b/StoreHub.KJDWebService/Models/PddModel/PDDProductDetailInfo.cs new file mode 100644 index 0000000..b1fa267 --- /dev/null +++ b/StoreHub.KJDWebService/Models/PddModel/PDDProductDetailInfo.cs @@ -0,0 +1,332 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace StoreHub.KJDWebService.Models +{ + public class PDDProductDetailInfo + { + public long? id { get; set; } + public long? goods_id { get; set; } + public int? check_status { get; set; } + public int? commit_deleted { get; set; } + public string owner { get; set; } + public int? is_shop { get; set; } + public string goods_sn { get; set; } + public string out_goods_sn { get; set; } + public int? is_folt { get; set; } + public string warm_tips { get; set; } + public object fabric { get; set; } + + + public object fabric_content { get; set; } + public long? cost_template_id { get; set; } + public int? cat_id { get; set; } + public long? mall_id { get; set; } + public string goods_name { get; set; } + public string tiny_name { get; set; } + public string goods_desc { get; set; } + public string share_desc { get; set; } + public List list_desc { get; set; } + + public int? market_price { get; set; } + public string thumb_url { get; set; } + public string image_url { get; set; } + public string hd_thumb_url { get; set; } + public List allowed_region { get; set; } + + + public int? region_limit { get; set; } + public int? goods_type { get; set; } + public object country { get; set; } + public int? country_id { get; set; } + public string goods_name_prefix { get; set; } + public int? origin_country_id { get; set; } + public string origin_country_name { get; set; } + public object size_spec_id { get; set; } + public object size_parent_spec_id { get; set; } + public string warehouse { get; set; } + public int? event_type { get; set; } + public int? is_app { get; set; } + public int? is_pre_sale { get; set; } + public int? pre_sale_time { get; set; } + public int? is_sku_pre_sale { get; set; } + public int? is_refundable { get; set; } + public int? is_customs { get; set; } + public int? is_wms { get; set; } + public string customs { get; set; } + public int? is_bangdan { get; set; } + public long? shipment_limit_second { get; set; } + public int? quick_refund { get; set; } + public group_item groups { get; set; } + public commit_extension_item commit_extension { get; set; } + public List galleries { get; set; } + public List goods_commit_check { get; set; } + public mall_info_item mall_info { get; set; } + public List sku { get; set; } + + + public object reject_status { get; set; } + public object reject_reason { get; set; } + public object paper_net_weight { get; set; } + public object paper_length { get; set; } + public object paper_width { get; set; } + public object paper_plies_num { get; set; } + public int? second_hand { get; set; } + public int? source { get; set; } + public bool is_card_secret { get; set; } + public bool is_only_for_remote_area { get; set; } + public int? invoice_status { get; set; } + public object invoice_mode { get; set; } + public object client_id { get; set; } + public int? quan_guo_lian_bao { get; set; } + public int? zhi_huan_bu_xiu { get; set; } + public object song_huo_ru_hu { get; set; } + public object shang_men_an_zhuang { get; set; } + public object song_huo_an_zhuang { get; set; } + public object mai_jia_zi_ti { get; set; } + public object sf_markup_template_sn { get; set; } + public long? min_group_price { get; set; } + public long? max_group_price { get; set; } + public int? must_check_type { get; set; } + public object goods_property_list { get; set; } + public object is_small_group { get; set; } + public int? submit_time { get; set; } + public int? oversea_type { get; set; } + public object oversea_goods { get; set; } + public int? is_general_trade { get; set; } + public int? bad_fruit_claim { get; set; } + public string bad_claim_text { get; set; } + public int? allergy_refund { get; set; } + public int? lack_of_weight_claim { get; set; } + public int? delivery_one_day { get; set; } + public object delivery_type { get; set; } + public int? goods_pattern { get; set; } + public int? customizable { get; set; } + public int? is_group_pre_sale { get; set; } + public object elec_goods_attributes { get; set; } + public schedule_sale_item schedule_sale { get; set; } + + public object goods_trade_attr { get; set; } + public object goods_travel_attr { get; set; } + public object sku_type { get; set; } + public int? is_goods_decoration { get; set; } + public List goods_srv_templates { get; set; } + + public object card_verification_list { get; set; } + public object transport_type_list { get; set; } + public object out_source_type { get; set; } + public object out_source_goods_id { get; set; } + public object is_all_weight_same { get; set; } + public bool? is_spring_festival_open_tag { get; set; } + public int? two_pieces_discount { get; set; } + + public instruction_vo_item instruction_vo { get; set; } + public object local_service_id_list { get; set; } + public object shop_group_id { get; set; } + public object shop_group_name { get; set; } + public int? is_refundable_fifteen_day { get; set; } + public int? is_warranty_one_year { get; set; } + public long? created_at { get; set; } + public int? privacy_delivery { get; set; } + public object invoice_mode_sub_type { get; set; } + public bool? is_two_num_group { get; set; } + public extend_warranty_dto_item extend_warranty_dto { get; set; } + public int? is_sku_shipment { get; set; } + public List qualification_id_list { get; set; } + public int? is_certificate_provide { get; set; } + public int? thawed_refund { get; set; } + public int? damage_claim { get; set; } + public int? is_wp_service { get; set; } + public int? is_size_change_casually { get; set; } + public string owner_name { get; set; } + public bool? show_activity_price { get; set; } + public object appeal_status { get; set; } + public object can_appeal { get; set; } + + public List cat_ids { get; set; } + public List cats { get; set; } + + public bool? is_draft { get; set; } + public int? third_type { get; set; } + public int? estimate_quantity { get; set; } + public int? last_commit_check_status { get; set; } + public bool? is_deposit { get; set; } + public object gold_price_template_id { get; set; } + public object gold_price_type { get; set; } + public int? processing_charges { get; set; } + public object processing_charges_type { get; set; } + public object is_gold_price_matched { get; set; } + public object shoes_template_id { get; set; } + public object spu_id { get; set; } + public object spu_version { get; set; } + public object is_goods_copy { get; set; } + public int? promised_delivery_seconds { get; set; } + public int? community_group_buying { get; set; } + public int? purchase_info_supply { get; set; } + public int? same_city_template_id { get; set; } + public object goods_certificate { get; set; } + public int? is_customized { get; set; } + public string name_prefix { get; set; } + public object business_source_type { get; set; } + public object creator_name { get; set; } + public object reason { get; set; } + public object app_id { get; set; } + public object app_name { get; set; } + public int? user_source { get; set; } + public object check_type { get; set; } + } + + public class group_item + { + public int? single_price { get; set; } + public int? group_price { get; set; } + public object carnival_price { get; set; } + public int? customer_num { get; set; } + public int? buy_limit { get; set; } //999999 + public int? order_limit { get; set; } //999999 + public string regular_limit { get; set; } + public object regular_limit_duration { get; set; } + public object min_num_of_order { get; set; } + public int? community_group_buying { get; set; } = 0; + } + + + public class commit_extension_item + { + public int? id { get; set; } + public int? goods_commit_id { get; set; } + public int? start_production_date { get; set; } + public int? end_production_date { get; set; } + public string production_license { get; set; } + public string production_standard_number { get; set; } + public int? shelf_life { get; set; } + public string out_goods_sn { get; set; } + public object created_at { get; set; } + public object updated_at { get; set; } + } + + public class gallery_item + { + public string url { get; set; } + public int? width { get; set; } + public int? height { get; set; } + // 图片类型 1 主图 2 详情图 3视频 + public int? type { get; set; } + public object source { get; set; } + public object status { get; set; } + public object video_url { get; set; } + public object file_id { get; set; } + public object is_deleted { get; set; } + public object check_comment { get; set; } + public object origin_url { get; set; } + } + + public class mall_info_item { + public string mall_name { get; set; } + } + + public class sku_edit_item : sku_item + { + public string thumb_md5 { get; set; } + } + + public class sku_item + { + public long? id { get; set; } + public long? sku_id { get; set; } + public object sku_sn { get; set; } + public int? carnival_price { get; set; } + public int? init_quantity { get; set; } + public int? is_onsale { get; set; } + public int? limit_quantity { get; set; } = 999999; // 999999 max + public int? multi_price { get; set; } + public object multi_price_in_yuan { get; set; } + public int? price { get; set; } + public object price_in_yuan { get; set; } + public int? quantity { get; set; } + public int? reserve_quantity { get; set; } + public int? weight { get; set; } + public string thumb_url { get; set; } + public long? thumb_url_file_id { get; set; } + public object thumb_url_status { get; set; } + public object thumb_url_is_deleted { get; set; } + public int? quantity_delta { get; set; } + public List spec { get; set; } + // 货号 + public string out_sku_sn { get; set; } + public object batch_id { get; set; } + public int? priority { get; set; } + public int? ware_id { get; set; } + public object ware_biz_type { get; set; } // null + public object advice_price { get; set; } + public object length { get; set; } + public oversea_sku_item oversea_sku { get; set; } + public object cspu_id { get; set; } + public object child_skus { get; set; } + public long? ref_sku_commit_id { get; set; } + public object start_time { get; set; } + public object end_time { get; set; } + public object sku_srv_templates { get; set; } + public object calendar_rule_id { get; set; } + public object hot_live_group { get; set; } + public int? pre_sale_time { get; set; } + public object out_source_sku_id { get; set; } + public object dd_grocery_sku_params { get; set; } + public object sku_extended_attribute_dtos { get; set; } + public object sku_basic_property_dtos { get; set; } + public object spec_note_map { get; set; } + public object delivery_schedule_dtos { get; set; } + public List shipment_limit_second_list { get; set; } + public string sku69_code { get; set; } + + } + + public class spec_item + { + public long? parent_id { get; set; } + public string parent_name { get; set; } + public long? spec_id { get; set; } + public string spec_name { get; set; } + public object spec_note { get; set; } + public object bundle_spec_list { get; set; } + public object sku_combination { get; set; } + public object is_custom { get; set; } + } + + public class oversea_sku_item + { + public object specifications { get; set; } + public object measurement_code { get; set; } + public object measurement_unit { get; set; } + public object taxation { get; set; } + public object record_id_list { get; set; } + } + + public class schedule_sale_item + { + public int? sale_type { get; set; } + public object sale_time_fixed { get; set; } + public object sale_time { get; set; } + public object price_show { get; set; } + public object price_desc { get; set; } + } + + public class instruction_vo_item + { + public object template_id { get; set; } + public int? template_status { get; set; } + public object template_name { get; set; } + public object rejected_reason { get; set; } + } + + public class extend_warranty_dto_item + { + public int? extend_warranty { get; set; } + public object extend_warranty_year { get; set; } + public object extend_warranty_range { get; set; } + } +} + diff --git a/StoreHub.KJDWebService/Models/PddModel/PDDProductInfo.cs b/StoreHub.KJDWebService/Models/PddModel/PDDProductInfo.cs new file mode 100644 index 0000000..ec74d57 --- /dev/null +++ b/StoreHub.KJDWebService/Models/PddModel/PDDProductInfo.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace StoreHub.KJDWebService.Models +{ + public class PDDProductInfo + { + public PDDProductDetailInfo detail { get; set; } + public PDDSizeSpecInfo size { get; set; } + public PDDProductDecorationInfo decoration { get; set; } + public PDDProductPropertyInfo property { get; set; } + /// + /// 白底图 + /// + public PDDMaterialInfo material1 { get; set; } + /// + /// 长图 + /// + public PDDMaterialInfo material3 { get; set; } + public object source_json { get; set; } + public string sale_count { get; set; } + public string sale_count_text { get; set; } + + + + public string chance_id { get; set; } + public string chance_refere { get; set; } // 记录机会商品提交的refere + public string chance_tab { get; set; } // 记录机会商品提交的tab + } +} + diff --git a/StoreHub.KJDWebService/Models/PddModel/PDDProductPropertyInfo.cs b/StoreHub.KJDWebService/Models/PddModel/PDDProductPropertyInfo.cs new file mode 100644 index 0000000..00e3bfb --- /dev/null +++ b/StoreHub.KJDWebService/Models/PddModel/PDDProductPropertyInfo.cs @@ -0,0 +1,47 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace StoreHub.KJDWebService.Models +{ + public class PDDProductPropertyInfo + { + public List goods_properties { get; set; } + public object sku_properties { get; set; } + } + + public class goods_propertie_item + { + public string name { get; set; } + public int? ref_pid { get; set; } + public List values { get; set; } + /// + /// 对应微信输入类型 + /// + //public int? wx_input_type { get; set; } + } + public class value_item + { + public long? vid { get; set; } + public string value { get; set; } + public string unit { get; set; } + public string raw_value { get; set; } + public table_info_vo_info table_info_vo { get; set; } + } + + public class table_info_vo_info + { + public List table_value_list { get; set; } + } + + public class table_value_info + { + public string value { get; set; } // "100.0", + public string unit { get; set; } // "%", + public int? column_type { get; set; } // 1 + + } +} + diff --git a/StoreHub.KJDWebService/Models/PddModel/PDDSizeSpecInfo.cs b/StoreHub.KJDWebService/Models/PddModel/PDDSizeSpecInfo.cs new file mode 100644 index 0000000..bfcebdd --- /dev/null +++ b/StoreHub.KJDWebService/Models/PddModel/PDDSizeSpecInfo.cs @@ -0,0 +1,120 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace StoreHub.KJDWebService.Models +{ + //public class PDDSizeSpecInfo + //{ + // public long? id { get; set; } + // public int? extendType { get; set; } + //} + //public class SizeContentItem + //{ + // public string picUrl { get; set; } + //} + + public class GroupsItem + { + /// + /// + /// + public int? id { get; set; } + /// + /// 中国码 + /// + public string name { get; set; } + /// + /// + /// + public bool? required { get; set; } + } + + public class ElementItem + { + /// + /// + /// + public int? id { get; set; } + /// + /// 肩宽(cm) + /// + public string name { get; set; } + /// + /// + /// + public bool? required { get; set; } + } + + public class MetaItem + { + /// + /// + /// + public List groups { get; set; } + /// + /// + /// + public List elements { get; set; } + /// + /// + /// + public List batchableElementIds { get; set; } + } + + + public class RecordItem + { + /// + /// + /// + public Dictionary values { get; set; } + } + + public class ContentItem + { + /// + /// + /// + public MetaItem meta { get; set; } + /// + /// + /// + public List records { get; set; } + /// + /// + /// + public string picUrl { get; set; } + } + + public class PDDSizeSpecInfo + { + /// + /// + /// + public long? id { get; set; } + /// + /// + /// + public int? extendType { get; set; } + /// + /// + /// + public ContentItem content { get; set; } + /// + /// + /// + public int? classId { get; set; } + /// + /// + /// + public bool? reusable { get; set; } + /// + /// + /// + public int? status { get; set; } + } +} + diff --git a/StoreHub.KJDWebService/Models/ProductPurchasePriceResultParam.cs b/StoreHub.KJDWebService/Models/ProductPurchasePriceResultParam.cs new file mode 100644 index 0000000..4f1086b --- /dev/null +++ b/StoreHub.KJDWebService/Models/ProductPurchasePriceResultParam.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +namespace StoreHub.KJDWebService.Models +{ + public class ProductPurchasePriceResultParam + { + public int id { get; set; } + public string shop_id { get; set; } + public string shop_name { get; set; } + public string spu_id { get; set; } + public string skc_id { get; set; } + public string cat_id { get; set; } + public string cat_name { get; set; } + public string ext_code { get; set; } + public string product_name { get; set; } + public string main_img { get; set; } + public int discount { get; set; } + public string price_text { get; set; } + public string sku_purchase_price_json { get; set; } + public DateTime add_time { get; set; } + public DateTime mdy_time { get; set; } + public string notes { get; set; } + } +} + diff --git a/StoreHub.KJDWebService/Models/ProductSelectResultParam.cs b/StoreHub.KJDWebService/Models/ProductSelectResultParam.cs new file mode 100644 index 0000000..c9fcad7 --- /dev/null +++ b/StoreHub.KJDWebService/Models/ProductSelectResultParam.cs @@ -0,0 +1,49 @@ +using StoreHub.KJDWebService.Commons; +using System; +using System.Collections.Generic; +using System.Linq; + +namespace StoreHub.KJDWebService.Models +{ + /// + /// 用户选品结果 + /// + public class ProductSelectResultParam + { + public long id { get; set; } + public string out_product_Id { get; set; } + public string shop_id { get; set; } + public string shop_account { get; set; } + public string user_name { get; set; } + public string sub_user_name { get; set; } + public string notes { get; set; } + public string user_notes { get; set; } + public string status { get; set; } + public string draft_id { get; set; } + public int add_times { get; set; } + public DateTime add_time { get; set; } + public DateTime mdy_time { get; set; } + public string operate_sub_sa_name { get; set; } + public string operate_sub_sa_nick { get; set; } + public DateTime? add_sub_sa_time { get; set; } + public string fission_product_name { get; set; } + + #region 外键连接属性 + public string from_shop_id { get; set; } = ""; + public string cat_id { get; set; } + public string cat_name { get; set; } + public string change_cat_id { get; set; } + public string change_cat_name { get; set; } + public string group { get; set; } + public string ext_code { get; set; } + public string product_name { get; set; } + public string main_img { get; set; } + public string spu_id { get; set; } + public string skc_id { get; set; } + public int product_get_type { get; set; } + #endregion + } +} + + + diff --git a/StoreHub.KJDWebService/Models/Result.cs b/StoreHub.KJDWebService/Models/Result.cs new file mode 100644 index 0000000..b1df02d --- /dev/null +++ b/StoreHub.KJDWebService/Models/Result.cs @@ -0,0 +1,48 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +namespace StoreHub.KJDWebService.Models +{ + public class Result + { + public Result() + { + + } + public Result(int code, string msg) + { + Code = code; + Msg = msg; + } + + public int Code { get; set; } + public string Msg { get; set; } + public object Data { get; set; } + + public static Result Success(string msg) + { + return new Result + { + Code = 200, + Msg = msg + }; + } + public static Result Failure(string msg) + { + return new Result + { + Code = 500, + Msg = msg + }; + } + //参数不合法 + public static Result ArgumentNull() + { + return new Result { Code = 19999, Msg = "输入为空" }; + + } + } +} + + diff --git a/StoreHub.KJDWebService/Models/ShopModel/JSTListProductSkuInfo.cs b/StoreHub.KJDWebService/Models/ShopModel/JSTListProductSkuInfo.cs new file mode 100644 index 0000000..3e0bf7d --- /dev/null +++ b/StoreHub.KJDWebService/Models/ShopModel/JSTListProductSkuInfo.cs @@ -0,0 +1,47 @@ +using NaiBa.Util.Extension; +using System; +using System.Collections.Generic; +using System.Linq; + +namespace StoreHub.KJDWebService.Models.ShopModel +{ + public class JSTListProductSkuInfo + { + public long id { get; set; } + + public string skuId { get; set; } // "F51114C9251A4AC1A03D91256FB48EF5", + public string itemSpuId { get; set; } // "16306F9EA78643A6B8389036BFC6131B", + public string pic { get; set; } // "https://images.sursung.com/prod/item/11625838/20260213/7D4666188669485C95B31A53CE621EAB_s392918_h800_w800.jpg", + public string itemName { get; set; } // "汉服发带唐风发饰古风国风头饰女马面裙配饰", + /// + /// spu货号 + /// + public string styleCode { get; set; } // "633881130581", + /// + /// sku货号 + /// + public string itemCode { get; set; } // "sp01351C", + public string color { get; set; } // "葡萄花鸟复原蓝", + public string spec { get; set; } // "无规格", + public decimal? salePrice { get; set; } // 7, + //public object weight { get; set; } // null, + //public object stockLastTime { get; set; } // null, + //public object regulatePriceMin { get; set; } // null, + //public object regulatePriceMax { get; set; } // null + + + public decimal? supplyPrice { get; set; } + public int? stock { get; set; } + public decimal? weight { get; set; } + public DateTime stockTime { get; set; } + + + public string coid { get; set; } + public string supplierId { get; set; } + public string supplierName { get; set; } + public string status { get; set; } + public DateTime add_time { get; set; } + public DateTime mdy_time { get; set; } + } +} + diff --git a/StoreHub.KJDWebService/Models/ShopModel/JitCardCodeParam.cs b/StoreHub.KJDWebService/Models/ShopModel/JitCardCodeParam.cs new file mode 100644 index 0000000..b8b520d --- /dev/null +++ b/StoreHub.KJDWebService/Models/ShopModel/JitCardCodeParam.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +namespace StoreHub.KJDWebService.Models.ShopModel +{ + public class JitCardCodeParam + { + public int id { get; set; } + public string card_code_id { get; set; } + /// + /// 创建时间 + /// + public DateTime add_time { get; set; } + /// + /// 激活时间 + /// + public DateTime? active_time { get; set; } + /// + /// 过期时间 + /// + public DateTime? expire_time { get; set; } + public string shop_id { get; set; } + public string shop_account { get; set; } + public string notes { get; set; } + } +} + diff --git a/StoreHub.KJDWebService/Models/ShopModel/ShopParam.cs b/StoreHub.KJDWebService/Models/ShopModel/ShopParam.cs new file mode 100644 index 0000000..6ff23ed --- /dev/null +++ b/StoreHub.KJDWebService/Models/ShopModel/ShopParam.cs @@ -0,0 +1,91 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +namespace StoreHub.KJDWebService.Models.ShopModel +{ + public class ShopParam + { + public int id { get; set; } + public string login_name { get; set; } + public string login_pass { get; set; } + public string cookie { get; set; } + public string cookie2 { get; set; } + /// + /// 拼多多AntiContents + /// + public string anti_contents { get; set; } + /// + /// 拼多多Id + /// + public string pddid { get; set; } + /// + /// 拼多多mall_id + /// + public string mall_id { get; set; } + /// + /// 微店网页token + /// + public string wd_token { get; set; } + /// + /// 微信openId + /// + public string openid { get; set; } + public string shop_id { get; set; } + public string shop_account { get; set; } + public string sub_user_name { get; set; } + public string sub_nick_name { get; set; } + public string user_name { get; set; } + public string company_name { get; set; } + /// + /// 备注 + /// + public string notes { get; set; } + public string group_name { get; set; } + public string login_status { get; set; } + public string login_status2 { get; set; } + public int add_product_remaining { get; set; } + public int add_product_month { get; set; } + + public string operate_sub_sa_name { get; set; } + + /// + /// temu推广直通车用户Id + /// + public string ad_seller_unique_id { get; set; } + /// + /// temu推广直通车链接地址(含信息) + /// + public string ad_url { get; set; } + /// + /// temu推广直通车cookie + /// + public string ad_cookie { get; set; } + /// + /// temu推广直通车登录状态 + /// + public string ad_login_status { get; set; } + public DateTime? jit_expire_time { get; set; } + public int? expire_time { get; set; } + public DateTime add_time { get; set; } + //public DateTime mdy_time { get; set; } + public bool? is_point_shop_expire { get; set; } = false; + 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 class AuthInfo + { + public int id { get; set; } + public string ShopId { get; set; } = ""; + public string AccessToken { get; set; } = ""; + public string RefreshToken { get; set; } = ""; + public string AppKey { get; set; } = ""; + public string AppSecret { get; set; } = ""; + public DateTime ExpiresTime { get; set; } + public DateTime UpdateTime { get; set; } = DateTime.MinValue; + public string ApiAuthStatus { get; set; } = "未授权"; + } +} + diff --git a/StoreHub.KJDWebService/Models/ShopModel/sku_img_replace.cs b/StoreHub.KJDWebService/Models/ShopModel/sku_img_replace.cs new file mode 100644 index 0000000..113afc5 --- /dev/null +++ b/StoreHub.KJDWebService/Models/ShopModel/sku_img_replace.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +namespace StoreHub.KJDWebService.Models.ShopModel +{ + public class sku_img_replace + { + public int id { get; set; } + public string img_md5 { get; set; } + public string img_base64 { get; set; } + public string img_url { get; set; } + public string img_type { get; set; } + public string img_group { get; set; } + public DateTime add_time { get; set; } + public DateTime mdy_time { get; set; } + } +} + diff --git a/StoreHub.KJDWebService/Models/SkuImgResult.cs b/StoreHub.KJDWebService/Models/SkuImgResult.cs new file mode 100644 index 0000000..a902119 --- /dev/null +++ b/StoreHub.KJDWebService/Models/SkuImgResult.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +namespace StoreHub.KJDWebService.Models +{ + public class SkuImgResult + { + public int id { get; set; } + public int img_base64_db_id { get; set; } + public string img_md5 { get; set; } + public string img_url { get; set; } + public string product_id { get; set; } + public string spec_id { get; set; } + public string spec_name { get; set; } + public string original_img_url { get; set; } + public DateTime add_time { get; set; } + public DateTime mdy_time { get; set; } + public DateTime base64_mdy_time { get; set; } + public string img_base64 { get; set; } + public int use_count { get; set; } + } +} + diff --git a/StoreHub.KJDWebService/Models/TemuDBOrderInfo.cs b/StoreHub.KJDWebService/Models/TemuDBOrderInfo.cs new file mode 100644 index 0000000..f95aea8 --- /dev/null +++ b/StoreHub.KJDWebService/Models/TemuDBOrderInfo.cs @@ -0,0 +1,57 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +namespace StoreHub.KJDWebService.Models +{ + public class TemuDBOrderInfo + { + public int? id { get; set; } + public string supplierId { get; set; } // '店铺Id', + public string supplierName { get; set; } + public string originalPurchaseOrderSn { get; set; } // '备货单号', + public string subPurchaseOrderSn { get; set; } // '备货母单号', + public string productName { get; set; } + public string category { get; set; } + public string productId { get; set; } // '商品编号', + public string upProductId { get; set; } // 上家商品编号 + public string productSkcId { get; set; } // + public string productSkcPicture { get; set; } //'主图', + public string productSn { get; set; } // '货号', + public int status { get; set; } = 1; // '状态 1待发货 2已送货 7已入库 8已作废', + public string productSkuId { get; set; } // CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL, + /// + /// 订单sku货号 + /// + public string extCode { get; set; } // 'sku货号', + public string className { get; set; } // 'sku规格', + public string currencyType { get; set; } // 价格单位 + public int supplierPrice { get; set; } // '申报价格', + public int? costPrice { get; set; } // '成本价', + public int? deliveryFee { get; set; } // '车队费', + public int? markFee { get; set; } // '贴标费', + public int purchaseQuantity { get; set; } // '备货件数', + public int deliverQuantity { get; set; } // '送货件数', + public int realReceiveAuthenticQuantity { get; set; } // '入库件数', + public decimal? availableSaleDays { get; set; } // '可售天数', + public int? qcResult { get; set; } // '抽检结果 1合格 2不合格', + public string thumbUrlList { get; set; } // 'sku图片', + public long purchaseTime { get; set; } // '备货单创建时间', + public long? deliverTime { get; set; } // '发货时间', + public long? receiveTime { get; set; } // '收货时间', + public long expectLatestDeliverTimeOrDefault { get; set; } // '最迟发货时间', + public long expectLatestArrivalTimeOrDefault { get; set; } // '最迟到货时间', + public string deliveryOrderSn { get; set; } // '发货单号', + public string receiveWarehouseId { get; set; } // '实际收货仓库Id', + public string receiveWarehouseName { get; set; } // '实际收货仓库', + public string warehouseGroupId { get; set; } // '仓组Id', + public string jiaTongCode { get; set; } // '佳同码', + public string barCodeMd5 { get; set; } // '商品条码MD5', + public string shippingMark​Md5 { get; set; } // '箱唛文件MD5', + public string notes { get; set; } // '备注', + public int upLoadStatus { get; set; } = 0; // '是否上传订单(上传后扣除用户授权金额,产生扣费记录)', + public DateTime add_time { get; set; } // + public DateTime mdy_time { get; set; } // + } +} + diff --git a/StoreHub.KJDWebService/Models/UserLoginResultParam.cs b/StoreHub.KJDWebService/Models/UserLoginResultParam.cs new file mode 100644 index 0000000..a31c8de --- /dev/null +++ b/StoreHub.KJDWebService/Models/UserLoginResultParam.cs @@ -0,0 +1,109 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +namespace StoreHub.KJDWebService.Models +{ + public class UserLoginResultParam + { + public int id { get; set; } + + /// + /// 用户名 + /// + public string user_name { get; set; } + /// + /// 父用户名 + /// + public string parent_user_name { get; set; } + /// + /// 贴牌编号 + /// + public string oem_id { get; set; } + + public string oem_name { get; set; } + public bool is_oem_owner { get; set; } + /// + /// 手机号(真实登录id,与用户名相同) + /// + public string mobile { get; set; } + + public string password { get; set; } + + public string nick_name { get; set; } + + public string group_id { get; set; } + + public bool is_import { get; set; } + + public string company_name { get; set; } + + public string card_id { get; set; } + + private int _is_sa = 0; + public int is_sa + { + get { return Math.Max(_sa_level, _is_sa); } + set { _is_sa = value; } + } + + private int _sa_level = 0; + public int sa_level + { + get { return Math.Max(_sa_level, _is_sa); } + set { _sa_level = value; } + } + + public decimal authorized_amount { get; set; } + + public DateTime add_time { get; set; } + + public DateTime mdy_time { get; set; } + /// + /// 备注 + /// + public string notes { get; set; } + + /// + /// 用户的功能操作权限 + /// + public string authority { get; set; } + /// + /// 父账户的功能操作权限 + /// + public string parent_authority { get; set; } + /// + /// 子账号被禁止展示的功能页面 + /// + public string forbidden_page { get; set; } + /// + /// 用户积分点数 + /// + public int points { get; set; } + /// + /// 单店铺续费1个月消耗的点数 + /// + public int shop_points_per_month { get; set; } + /// + /// 当前余额 + /// + public decimal balance { get; set; } + /// + /// 历史充值总额 + /// + public decimal recharge_amount_total { get; set; } + /// + /// 每单运费金额 + /// + public decimal? postage_per_order { get; set; } + /// + /// 每单退货运费金额 + /// + public decimal? refund_postage_per_order { get; set; } + /// + /// 每一单礼物额外收取费用 + /// + public decimal? gift_oem_amount_per_order { get; set; } + } +} + diff --git a/StoreHub.KJDWebService/Models/WXAddressInfo.cs b/StoreHub.KJDWebService/Models/WXAddressInfo.cs new file mode 100644 index 0000000..47e8b1c --- /dev/null +++ b/StoreHub.KJDWebService/Models/WXAddressInfo.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +namespace StoreHub.KJDWebService.Models +{ + public class WXAddressInfo + { + public int id { get; set; } + public string supplier_name { get; set; } + public string coid { get; set; } + public string after_sale_json { get; set; } + public DateTime add_time { get; set; } + public DateTime mdy_time { get; set; } + public string type { get; set; } + } +} + diff --git a/StoreHub.KJDWebService/Models/WXShopDefaultAddressInfo.cs b/StoreHub.KJDWebService/Models/WXShopDefaultAddressInfo.cs new file mode 100644 index 0000000..7ee16b1 --- /dev/null +++ b/StoreHub.KJDWebService/Models/WXShopDefaultAddressInfo.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +namespace StoreHub.KJDWebService.Models +{ + public class WXShopDefaultAddressInfo + { + public int? id { get; set; } + public string user_id { get; set; } + public string shop_id { get; set; } + public string province_name { get; set; } + public string city_name { get; set; } + public string county_name { get; set; } + public string detail_info { get; set; } + public string tel_number { get; set; } + public string user_name { get; set; } + public DateTime add_time { get; set; } + public DateTime mdy_time { get; set; } + } +} + diff --git a/StoreHub.KJDWebService/Models/WxModel/WXBuyUrlNotesInfo.cs b/StoreHub.KJDWebService/Models/WxModel/WXBuyUrlNotesInfo.cs new file mode 100644 index 0000000..dc95bd6 --- /dev/null +++ b/StoreHub.KJDWebService/Models/WxModel/WXBuyUrlNotesInfo.cs @@ -0,0 +1,40 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +namespace StoreHub.KJDWebService.Models.WxModel +{ + public class WXBuyUrlNotesInfo + { + public int id { get; set; } + public string spu_code { get; set; } + public string user_name { get; set; } + public string buy_url_notes { get; set; } + public DateTime add_time { get; set; } + public DateTime mdy_time { get; set; } + } + + public class WXBuyMapInfo + { + public long id { get; set; } + public string user_name { get; set; } + public string spu_code { get; set; } + public string sku_code { get; set; } + public string map_url { get; set; } + public string map_goods_name { get; set; } + /// + /// sku规格名称 + /// + public string map_spec_name { get; set; } + public string map_goods_id { get; set; } + public string map_sku_id { get; set; } + /// + /// 发货地(省,市) + /// + public string map_send_address { get; set; } + public string transit_warehouse_id { get; set; } + public DateTime add_time { get; set; } + public DateTime mdy_time { get; set; } + } +} + diff --git a/StoreHub.KJDWebService/Models/WxModel/WXClientProductInfoLite.cs b/StoreHub.KJDWebService/Models/WxModel/WXClientProductInfoLite.cs new file mode 100644 index 0000000..ca94a07 --- /dev/null +++ b/StoreHub.KJDWebService/Models/WxModel/WXClientProductInfoLite.cs @@ -0,0 +1,170 @@ +using NaiBa.Util.Extension; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace StoreHub.KJDWebService.Models.WxModel +{ + public class WXClientProductInfoLite + { + public wx_client_prod_key product_key { get; set; } + + public wx_client_prod_info info { get; set; } + + public List productSkus { get; set; } + } + + public class wx_client_prod_info + { + public string title { get; set; } // "2026新款情侣棒球帽立体C字母刺绣显脸小时尚百搭休闲韩版大头围鸭舌帽", + public string sub_title { get; set; } // "2025新款C字母立体刺绣棒球帽", + /// + /// 主图列表 + /// + public List head_img { get; set; } // ["https://wst.wxapp.tc.qq.com/161/20304/snscosdownload/SH/reserved/64f0a5760000484b151963b6bb81bc1e000000a000004f50", ...] + public List category { get; set; } // { "cat_id": "6093" } + /// + /// 商品详情(图) + /// + public wx_client_prod_detail detail { get; set; } + /// + /// 商品属性 + /// + public List param { get; set; } + /// + /// 品牌id + /// + public string brand_id { get; set; } // "10250056" + public wx_client_sku_id_list sku_id_list { get; set; } + public wx_sku sku_list { get; set; } + public List product_sale_attrs { get; set; } + /// + /// 总销量 + /// + public string total_sold_num { get; set; } // "46631" + public wx_client_service_desc service_desc { get; set; } + public wx_client_express_info express_info { get; set; } + public List headVideoInfo { get; set; } + + public object afterSaleInfo { get; set; } + public List deliveryExpressFee { get; set; } + public List templateInfo { get; set; } + public string spuCode { get; set; } + } + + public class wx_client_express_info + { + public string template_id { get; set; } // "243911370004", + public string product_id { get; set; } // "10000066623849", + public int? piece { get; set; } // 1, + public int? weight { get; set; } // 0, + public int? price { get; set; } // 5980 + } + + public class wx_client_service_desc + { + public string desc { get; set; } // "(麻烦阿姐阿哥们,带纸箱邮寄过去的一定记得用纸盒邮寄回,袋子邮寄的,带袋子寄回,拒收到付件,拒收自提件)" + } + + public class wx_client_sku_id_list + { + public List sku_ids { get; set; } //[ "1597139289", "1597121531", "1597127451", "1597113890", "1597119654" ] + } + + public class wx_client_prod_key + { + public string product_id { get; set; } // "10000066623849", + public string appid { get; set; } // "wx62cca7dc2354b687" + } + + public class wx_client_head_video_info + { + public string videoUrl { get; set; } // "https://wst.wxapp.tc.qq.com/162/20302/snssvpdownload/SH/reserved/0bc3yya5qaabfaaeaq6thjt2nrwd3ddadwaa.f100001.mp4?wdis_k=7cdc03c564ae62499c03d8034036e65c4405cd2d&wdis_t=1773699072&appid=none&scene=0&ext=eyJjaSI6MTAwMDY5LCJjczBjIjoxNywiY3MwbyI6NDA1MzAsImNzMWMiOjQsImNzMW8iOjExMDQ0OSwicnMiOiIyNDIwNDozIn0", + public string videoHeadImg { get; set; } // "https://wst.wxapp.tc.qq.com/162/20302/snssvpdownload/SH/reserved/0bc3yya5qaabfaaeaq6thjt2nrwd3ddadwaa.f1400_0.jpeg?wdis_k=7f202df2767ca6d4b8cec6f52d1706ea8e497708&wdis_t=1773699072&appid=none&scene=0&ext=eyJjaSI6MTAwMDY5LCJjczBjIjoxNywiY3MwbyI6NDA1MzAsImNzMWMiOjQsImNzMW8iOjExMDQ0OSwicnMiOiIyNDIwNDozIn0", + public int? videoLen { get; set; } // 24, + public string videoSize { get; set; } // "0", + public int? videoSource { get; set; } // 0, + public int? videoFormat { get; set; } // 0, + public string playableVideoUrl { get; set; } // "https://wst.wxapp.tc.qq.com/162/20302/snssvpdownload/SH/reserved/0bc3yya5qaabfaaeaq6thjt2nrwd3ddadwaa.f100001.mp4?wdis_k=7cdc03c564ae62499c03d8034036e65c4405cd2d&wdis_t=1773699072&appid=none&scene=0&ext=eyJjaSI6MTAwMDY5LCJjczBjIjoxNywiY3MwbyI6NDA1MzAsImNzMWMiOjQsImNzMW8iOjExMDQ0OSwicnMiOiIyNDIwNDozIn0", + public int? videoWidth { get; set; } // 1080, + public int? videoHeight { get; set; } // 1080, + public string videoH265Url { get; set; } // "https://wst.wxapp.tc.qq.com/162/20302/snssvpdownload/SH/reserved/0bc3yya5qaabfaaeaq6thjt2nrwd3ddadwaa.f100003.mp4?wdis_k=057570644d9b72ff0c62e85b1c54cf0f0a8b42f6&wdis_t=1773699072&appid=none&scene=0&ext=eyJjaSI6MTAwMDY5LCJjczBjIjoxNywiY3MwbyI6NDA1MzAsImNzMWMiOjQsImNzMW8iOjExMDQ0OSwicnMiOiIyNDIwNDozIn0", + public int? videoH265Width { get; set; } // 720, + public int? videoH265Height { get; set; } // 720 + } + + public class wx_client_product_sale_attr + { + public string key { get; set; } // "颜色" + public List items { get; set; } + public bool? has_img { get; set; } + } + + public class wx_client_product_sale_attr_item + { + public string value { get; set; } // "卡其色" + public string img_url { get; set; } // "https://wst.wxapp.tc.qq.com/161/20304/snscosdownload/SH/reserved/64eb0fd5000f2ca50a23b45f3567b01e000000a100004f50" + public List sku_ids { get; set; } // [ "1597139289" ] + } + + public class wx_sku + { + public List sku_info { get; set; } + public string min_price_sku_id { get; set; } // "1597139289" + public string default_selected_sku_id { get; set; } // "1597139289" + } + + public class wx_client_sku_info + { + public string sku_id { get; set; } // "1597139289", + public int? price { get; set; } // 5980, + public bool? is_discounted { get; set; } // true, + public int? discounted_price { get; set; } // 2990, + public int? origin_price { get; set; } // 5980, + } + + public class wx_client_prod_detail + { + /// + /// 详情图 + /// + public List detail_img { get; set; } // ["https://wst.wxapp.tc.qq.com/161/20304/snscosdownload/SH/reserved/64f21d2b00009e7a156bc7cd6d63b01e000000a000004f50", ...] + public List detailImg { get; set; } // ["https://wst.wxapp.tc.qq.com/161/20304/snscosdownload/SH/reserved/64f21d2b00009e7a156bc7cd6d63b01e000000a000004f50", ...] + public List detail_img_real { get { return detail_img == null ? detailImg : detail_img; } } + public string desc { get; set; } // "纯萃美2025新款情侣棒球帽立体C字母刺绣显脸小时尚百搭休闲网红款韩版大头围硬顶鸭舌帽男女同款" + ///// + ///// + ///// + //public List detailImg { get; set; } + ///// + ///// 纯萃美2025新款情侣棒球帽立体C字母刺绣显脸小时尚百搭休闲网红款韩版大头围硬顶鸭舌帽男女同款 + ///// + //public string desc { get; set; } + } + + public class wx_client_param + { + public List categorys { get; set; } + } + + public class wx_client_category + { + public string catIdStr { get { return cat_id.IsNullOrEmpty() ? catId : cat_id; } } // "0", + public string cat_id { get; set; } // "0", + public string catId { get; set; } // "0", + public string name { get; set; } // "主要材质", "C字母刺绣" + public string f_cat_id { get; set; } // "0", + public string brand_cat { get; set; } // "0", + public wx_client_cat_info cat_info { get; set; } + } + + public class wx_client_cat_info + { + public int? is_required { get; set; } // 1, + public int? is_customize { get; set; } // 0, + public int? input_type { get; set; } // 1 + } +} + diff --git a/StoreHub.KJDWebService/Models/WxModel/WXGetEditProductInfoLite.cs b/StoreHub.KJDWebService/Models/WxModel/WXGetEditProductInfoLite.cs new file mode 100644 index 0000000..b1e3be4 --- /dev/null +++ b/StoreHub.KJDWebService/Models/WxModel/WXGetEditProductInfoLite.cs @@ -0,0 +1,192 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace StoreHub.KJDWebService.Models.WxModel +{ + public class WXGetEditProductInfoLite + { + public WXProductInfo product { get; set; } + public WXAfterSaleAddressInfo address { get; set; } + } + + public class WXAfterSaleAddressInfo + { + public string addressId { get; set; } // "69496256002", + public string name { get; set; } // "", + public WXAddressInfo addressInfo { get; set; } + } + + public class WXAddressInfo + { + public string userName { get; set; } // "王总", + public string postalCode { get; set; } // "", + public string provinceName { get; set; } // "安徽省", + public string cityName { get; set; } // "合肥市", + public string countyName { get; set; } // "肥西县", + public string detailInfo { get; set; } // "蜀山区长江西路某某号某某单元", + public string telNumber { get; set; } // "18388888888", + public int? lat { get; set; } // 0, + public int? lng { get; set; } // 0 + } + + public class WXProductInfo + { + public List productSkus { get; set; } + public WXProductKeyInfo productKey { get; set; } + public WXProductInfoInfo info { get; set; } + public int? status { get; set; } // 5 + public string createTime { get; set; } // "1772529740", + public string updateTime { get; set; } // "1772533190", + public int? version { get; set; } // 8, + public int? editStatus { get; set; } // 4, + public string editTime { get; set; } // "1772533189", + public int source { get; set; } // 1 + } + + public class WXProductSkuInfoLite + { + public WXSkuKeyInfoLite skuKey { get; set; } + public WXProductSkuInfoInfoLite productSkuInfo { get; set; } + } + + public class WXProductSkuInfoInfoLite + { + public List saleParam { get; set; } + public string thumbImg { get; set; } // "https://wst.wxapp.tc.qq.com/161/20304/snscosdownload/SH/reserved/69a6a1ae000e63741a5ddf35d5b71715000000a000004f50" + public string skuCode { get; set; } // "" + public int? salePrice { get; set; } // 5880 + public WXStockInfoLite stockInfo { get; set; } + public WXRealStockInfoLite realStockInfo { get; set; } + } + + public class WXRealStockInfoLite + { + public int? stockNum { get; set; } // 999 + public int? totalNum { get; set; } // 999 + } + + public class WXStockInfoLite + { + public string stockNum { get; set; } // "9999999" + } + + public class WXSaleParamInfoLite + { + public List categorys { get; set; } + } + + public class WXSkuKeyInfoLite + { + public string skuId { get; set; } // "8767785131", + } + + public class WXProductKeyInfo + { + public string productId { get; set; } // "10000538778988" + } + + public class WXProductInfoInfo + { + // 主图 + public List headImg { get; set; } = new List(); + public List category { get; set; } = new List(); + public List param { get; set; } = new List(); + public List qualificationList { get; set; } + public List productHeadimgInfo { get; set; } + public List headImgInfos { get; set; } + public string title { get; set; } // "歪歪马震动棒 成人情趣用品" + public string subTitle { get; set; } // "", + public string brand { get; set; } // "", + public string model { get; set; } // "", + public WXProductDetailInfo detail { get; set; } + public string brandId { get; set; } // "10655917" + public string listingTime { get; set; } // "1772533190" + public string spuCode { get; set; } // "2028756820870602753" + public WXAfterSaleInfo afterSaleInfo { get; set; } + public string lastEditDraftTime { get; set; } // "1772532559" + public string shortTitle { get; set; } // "歪歪马脉冲震动成人情趣棒" + public string aiGenShortTitle { get; set; } // "歪歪马脉冲震动成人情趣棒" + public string uniqueId { get; set; } // "4411405439658180613" + } + + public class WXAfterSaleInfo + { + public string afterSaleAddressId; + } + + public class WXProductDetailInfo + { + public List detailImg { get; set; } = new List(); // [ "https://wst.wxapp.tc.qq.com/161/20304/snscosdownload/SH/reserved/69a6a8460000683300254e4c8c4fab15000000a100004f50", ... ], + public List detailVideos { get; set; } = new List(); + public List detailVideoInfo { get; set; } = new List(); + public List carouselImg { get; set; } = new List(); + public string desc { get; set; } = ""; + } + + public class WXHeadImgInfo + { + public string imgUrl { get; set; } // "https://wst.wxapp.tc.qq.com/161/20304/snscosdownload/SH/reserved/69a6a8420006d56e0003583092a31715000000a100004f50", + public int? imgWidth { get; set; } // 800, + public int? imgHeight { get; set; } // 800 + } + + public class WXProductHeadimgInfo + { + public List colors { get; set; } = new List(); // [] + public string imgUrl { get; set; } // "https://wst.wxapp.tc.qq.com/161/20304/snscosdownload/SH/reserved/69a6a8420006d56e0003583092a31715000000a100004f50" + public WXMainColors mainColors { get; set; } + } + + public class WXMainColors + { + public int? red { get; set; } // 255, + public int? green { get; set; } // 255, + public int? blue { get; set; } // 255 + } + + public class WXQualificationInfo + { + public List qualificationUrl { get; set; } // ["https://wst.wxapp.tc.qq.com/161/20304/snscosdownload/SH/reserved/69a6a84a0008442e2a4a8f7179bc1715000000a000004f50"] + public string qualificationId { get; set; } // "50000115" + public int? showCertType { get; set; } // 0 + } + + public class WXProductParamInfo + { + public List categorys { get; set; } = new List(); + } + + public class WXProductParamCategoryInfo + { + public string name { get; set; } // [0] "name": "长度" [1] "name": "20 cm", + public int? catType { get; set; } = 0; + public WXProductParamCategoryCatInfo catInfo { get; set; } + } + + public class WXProductParamCategoryCatInfo + { + public int? isRequired { get; set; } // 1, + public int? isCustomize { get; set; } // 0, + public int? inputType { get; set; } // 1-单选 2-文本 + public long? catGroup { get; set; } // 4294967295, + } + + public class WXProductCategoryInfoLite + { + public string catId { get; set; } // "10000577" + public string name { get; set; } // "情趣用品" // 可能为空或没有此字段 + public string fCatId { get; set; } // "10000575" + public WXProductCategoryInfoInfoLite catInfo { get; set; } + public bool? leaf { get; set; } // false + } + + public class WXProductCategoryInfoInfoLite + { + public int? catLevel { get; set; } // 2 + public long? catGroup { get; set; } // 4294967295 + } +} + diff --git a/StoreHub.KJDWebService/Models/WxModel/WXOrderAmountInfo.cs b/StoreHub.KJDWebService/Models/WxModel/WXOrderAmountInfo.cs new file mode 100644 index 0000000..dc4e2b4 --- /dev/null +++ b/StoreHub.KJDWebService/Models/WxModel/WXOrderAmountInfo.cs @@ -0,0 +1,95 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +namespace StoreHub.KJDWebService.Models.WxModel +{ + /// + /// 微信订单金额详情 + /// + public class WXOrderAmountInfo + { + /// + /// 店铺名称 + /// + public string shop_name { get; set; } + /// + /// 下单时间(秒级时间戳) + /// + public int create_time { get; set; } + /// + /// 订单号 + /// + public string order_id { get; set; } + /// + /// 订单状态 + /// + public int status { get; set; } + /// + /// 商品总价(分) + /// + public int product_price { get; set; } + /// + /// 订单金额(分) + /// + public int order_price { get; set; } + /// + /// 采购价(分) + /// + public int purchase_price { get; set; } + /// + /// 运费(分) + /// + public int freight { get; set; } + /// + /// 平台服务费(预计技术服务费,分) + /// + public int predict_commission_fee { get; set; } + /// + /// 达人佣金(分) + /// + public int commission_amount { get; set; } + /// + /// 优惠金额(分) + /// + public int discounted_price { get; set; } + /// + /// 利润 = 订单金额 - 外采金额 - 平台服务费 - 达人佣金(分) + /// + public int profit { get; set; } + /// + /// 采购状态 + /// + public int purchase_status { get; set; } + /// + /// 外采金额(分),out_amount 为空或0时从中转仓订单表补全 + /// + public int out_amount { get; set; } + /// + /// 售后状态(订单明细 refund_status) + /// + public int refund_status { get; set; } + /// + /// 售后状态(退款单 status) + /// + public string refund_status_string { get; set; } + /// + /// 售后退款金额(分),无退款默认0 + /// + public int refund_amount { get; set; } + /// + /// 是否外采:0=未从中转仓订单表查到,1=查到 + /// + public int external_procurement { get; set; } + /// + /// 买手号退款金额(分):退款订单且非外采时,从买手售后表(order_pdd_buyer_after_sale)补全,无退款默认0 + /// + public int buyer_refund_amount { get; set; } + /// + /// 买手号退款状态 + /// + public string buyer_refund_status { get; set; } + } +} + + diff --git a/StoreHub.KJDWebService/Models/WxModel/WXOrderDecryptAddressInfo.cs b/StoreHub.KJDWebService/Models/WxModel/WXOrderDecryptAddressInfo.cs new file mode 100644 index 0000000..e8165b7 --- /dev/null +++ b/StoreHub.KJDWebService/Models/WxModel/WXOrderDecryptAddressInfo.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +namespace StoreHub.KJDWebService.Models.WxModel +{ + public class WXOrderDecryptAddressInfo + { + public int id { get; set; } + public string shop_id { get; set; } + public string order_id { get; set; } + public string order_address { get; set; } + public DateTime add_time { get; set; } + public DateTime mdy_time { get; set; } + } +} + diff --git a/StoreHub.KJDWebService/Models/WxModel/WxOptimizeExpressInfo.cs b/StoreHub.KJDWebService/Models/WxModel/WxOptimizeExpressInfo.cs new file mode 100644 index 0000000..4fe71cb --- /dev/null +++ b/StoreHub.KJDWebService/Models/WxModel/WxOptimizeExpressInfo.cs @@ -0,0 +1,44 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +namespace StoreHub.KJDWebService.Models.WxModel +{ + public class WxOptimizeExpressInfo + { + public int id { get; set; } + public string delivery_id { get; set; } + public string delivery_name { get; set; } + public string waybill_id { get; set; } + public int status { get; set; } + public string order_id { get; set; } + public string bind_order_id { get; set; } + public string shop_id { get; set; } + public DateTime add_time { get; set; } + public DateTime? use_time { get; set; } + public DateTime? waybill_pickup_time { get; set; } + } + + public class WxOptimizeRstInfo + { + public int id { get; set; } + public string shop_id { get; set; } + public string order_id { get; set; } + public string optimize_rst { get; set; } + public string waybill_id { get; set; } + public string delivery_name { get; set; } + public DateTime add_time { get; set; } + public DateTime mdy_time { get; set; } + } + + public class WxOptimizeRemarkInfo + { + public int id { get; set; } + public string shop_id { get; set; } + public string order_id { get; set; } + public string remark { get; set; } + public DateTime add_time { get; set; } + public DateTime mdy_time { get; set; } + } +} + diff --git a/StoreHub.KJDWebService/Models/WxModel/oem.cs b/StoreHub.KJDWebService/Models/WxModel/oem.cs new file mode 100644 index 0000000..544a047 --- /dev/null +++ b/StoreHub.KJDWebService/Models/WxModel/oem.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +namespace StoreHub.KJDWebService.Models.WxModel +{ + public class oem + { + public int id { get; set; } + public string oem_id { get; set; } + public string oem_name { get; set; } + public string oem_owner { get; set; } + public string oem_icon { get; set; } + public string oem_img { get; set; } + public DateTime add_time { get; set; } + public DateTime mdy_time { get; set; } + } +} + diff --git a/StoreHub.KJDWebService/Models/WxModel/oms_wei_external_procurement_after_sale_info.cs b/StoreHub.KJDWebService/Models/WxModel/oms_wei_external_procurement_after_sale_info.cs new file mode 100644 index 0000000..79b2511 --- /dev/null +++ b/StoreHub.KJDWebService/Models/WxModel/oms_wei_external_procurement_after_sale_info.cs @@ -0,0 +1,100 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +namespace StoreHub.KJDWebService.Models.WxModel +{ + public class oms_wei_external_procurement_after_sale_info + { + public long id { get; set; } + public string order_no { get; set; } + /// + /// 订单唯一值:OrderCode (外采单号) + /// + public string order_code { get; set; } + /// + /// 中转仓售后订单号 + /// + public string external_order_no { get; set; } + /// + /// 售后订单号 + /// + public string after_sale_no { get; set; } + /// + /// 1=转寄,2=换货, 3=退货 + /// + public int? return_or_exchange { get; set; } + /// + /// 退款地址-省 + /// + public string refund_province { get; set; } + /// + /// 退款地址-市 + /// + public string refund_city { get; set; } + /// + /// 退款地址-县/区 + /// + public string refund_county { get; set; } + public string refund_detail_address { get; set; } + /// + /// 退款的快递单号 + /// + public string refund_waybill { get; set; } + /// + /// 退货的快递公司 + /// + public string return_express_company { get; set; } + /// + /// 收货人姓名 + /// + public string recipient_name { get; set; } + /// + /// 收货人电话 + /// + public string recipient_phone { get; set; } + /// + /// 原始消息/扩展信息(JSON) + /// + public string raw_message { get; set; } + /// + /// 售后处理状态,0未处理,1处理中,2已完成,9异常 + /// + public int? status { get; set; } + public DateTime? created_time { get; set; } + public DateTime? updated_time { get; set; } + /// + /// 创建人 + /// + public string create_user { get; set; } + /// + /// 更新人 + /// + public string update_user { get; set; } + /// + /// 账户名 + /// + public string account_user { get; set; } + /// + /// 1=入库 2=出库 + /// + public int? warehouse_status { get; set; } + /// + /// 入库时间 + /// + public DateTime? inbound_time { get; set; } + /// + /// 出库时间 + /// + public DateTime? outbound_time { get; set; } + /// + /// 下游快递单号 + /// + public string downstream_waybill { get; set; } + /// + /// 下游快递公司编码 + /// + public string downstream_express_code { get; set; } + } +} + diff --git a/StoreHub.KJDWebService/Models/WxModel/oms_wei_external_procurement_log.cs b/StoreHub.KJDWebService/Models/WxModel/oms_wei_external_procurement_log.cs new file mode 100644 index 0000000..f81e674 --- /dev/null +++ b/StoreHub.KJDWebService/Models/WxModel/oms_wei_external_procurement_log.cs @@ -0,0 +1,67 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +namespace StoreHub.KJDWebService.Models.WxModel +{ + public class oms_wei_external_procurement_log + { + public long id { get; set; } + public string out_order_no { get; set; } + public string order_no { get; set; } + public string order_sku_id { get; set; } + public string buyer_account { get; set; } + public int? out_amount { get; set; } + public string purchaser_note { get; set; } + public string express_1_company { get; set; } + public string express_1_waybill { get; set; } + public string express_2_company { get; set; } + public string express_2_waybill { get; set; } + public string refund_status { get; set; } + public DateTime pickup_time { get; set; } + /// + /// 中转仓状态:0 未使用,1 已创建,2 创建失败 + /// + public int? transfer_warehouse_status { get; set; } + public string raw_message { get; set; } + public DateTime created_time { get; set; } + public DateTime updated_time { get; set; } + public string platform { get; set; } + public string order_platform_code { get; set; } + public string order_code { get; set; } + /// + /// 1正常取号 2提前取号 + /// + public int? pre_allocated_order_no { get; set; } + public int? is_transfer_ship { get; set; } + /// + /// 溯源码 + /// + public string random_code { get; set; } + /// + /// 1, "拒收" 2, "拦截" 3, "取消" 4, "订单作废" + /// + public int? transfer_refund_status { get; set; } + /// + /// 订单作废状态:0=正常,1=已作废,2=作废失败 + /// + public int? order_void_status { get; set; } + /// + /// 0: 未使用, 1: 已入库, 2: 出库 + /// + public int? warehouse_status { get; set; } + /// + /// 中转入库时间 + /// + public DateTime? inbound_time { get; set; } + /// + /// 中转出库时间 + /// + public DateTime? outbound_time { get; set; } + /// + /// 申请拒收状态 0未申请 1申请成功 2申请失败 + /// + public int has_reject { get; set; } + } +} + diff --git a/StoreHub.KJDWebService/Models/WxModel/oms_wei_order.cs b/StoreHub.KJDWebService/Models/WxModel/oms_wei_order.cs new file mode 100644 index 0000000..c1c1359 --- /dev/null +++ b/StoreHub.KJDWebService/Models/WxModel/oms_wei_order.cs @@ -0,0 +1,245 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +namespace StoreHub.KJDWebService.Models.WxModel +{ + public class oms_wei_order + { + public long id { get; set; } + public long shop_id { get; set; } + public string shop_name { get; set; } + /// + /// 商户ID + /// + public long merchant_id { get; set; } + public string order_id { get; set; } + /// + /// 买家身份标识 + /// + public string openid { get; set; } + public int create_time { get; set; } + public int update_time { get; set; } + public string unionid { get; set; } + /// + /// 状态10 待付款;20 待发货;21 部分发货;30 待收货;100 完成;200 全部商品售后之后,订单取消;250 未付款用户主动取消或超时未付款订单自动取消; + /// + public int? status { get; set; } + /// + /// 售后信息json + /// + public string aftersale_detail { get; set; } + /// + /// 支付信息 + /// + public string pay_info { get; set; } + /// + /// 额外信息 + /// + public string ext_info { get; set; } + /// + /// 商品总价 + /// + public int? product_price { get; set; } + /// + /// 订单金额,单位为分,order_price=original_order_price-discounted_price-deduction_price-change_down_price + /// + public int? order_price { get; set; } + /// + /// 采购价,单位为分 + /// + public int? purchase_price { get; set; } + /// + /// 采购时间 + /// + public int? purchase_time { get; set; } + /// + /// 运费,单位为分 + /// + public int? freight { get; set; } + /// + /// 平台服务费(微信小店:预计技术服务费),单位为分 + /// + public int? predict_commission_fee { get; set; } + /// + /// 达人佣金(微信小店:分账金额),单位为分 + /// + public int? commission_amount { get; set; } + /// + /// 优惠券优惠金额,单位为分 + /// + public int? discounted_price { get; set; } + /// + /// 利润(实付金额-采购价-平台服务费-达人佣金,达人佣金、采购价为空值则为0) + /// + public int? profit { get; set; } + /// + /// 采购状态,默认值为:0未采购,推送仓库时修改为1采购 + /// + public int? purchase_status { get; set; } + /// + /// 延迟发货时间(微信小店:商品发货时效,超时此时间未发货即为发货超时) + /// + public int? delivery_deadline { get; set; } + /// + /// 发货时间 + /// + public int? delivery_time { get; set; } + /// + /// 收货人姓名 + /// + public string user_name { get; set; } + /// + /// 邮编 + /// + public string postal_code { get; set; } + public string province_name { get; set; } + public string city_name { get; set; } + /// + /// 区 + /// + public string county_name { get; set; } + /// + /// 详细地址 + /// + public string detail_info { get; set; } + public string tel_number { get; set; } + /// + /// 门牌号码 + /// + public string house_number { get; set; } + /// + /// 虚拟发货订单联系方式(deliver_method=1时返回) + /// + public string virtual_order_tel_number { get; set; } + /// + /// 额外的联系方式信息(虚拟号码相关) + /// + public string tel_number_ext_info { get; set; } + /// + /// 0:不使用虚拟号码,1:使用虚拟号码 + /// + public int? use_tel_number { get; set; } + /// + /// 标识当前店铺下一个唯一的用户收货地址 + /// + public string hash_code { get; set; } + /// + /// 发货物流信息JSON + /// + public string delivery_product_info { get; set; } + /// + /// 发货完成时间,秒级时间戳 + /// + public int? ship_done_time { get; set; } + /// + /// 电子面单代发时的订单密文 + /// + public string ewaybill_order_code { get; set; } + /// + /// 结算信息json + /// + public string settle_info { get; set; } + /// + /// 订单审核状态(0待审核1已审核) + /// + public int? audit_status { get; set; } + /// + /// 订单审核时间 + /// + public DateTime audit_time { get; set; } + /// + /// erp发货快递公司 + /// + public string erp_send_company { get; set; } + /// + /// erp发货快递单号 + /// + public string erp_send_code { get; set; } + /// + /// erp发货状态 + /// + public int? erp_send_status { get; set; } + /// + /// erp发货时间 + /// + public DateTime erp_send_time { get; set; } + /// + /// 旗帜颜色备注,1:灰旗,2:红旗,3:橙旗,4:绿旗,5:天蓝旗,6:紫旗 + /// + public int? colour_flag { get; set; } + /// + /// 旗帜备注时间 + /// + public DateTime colour_flag_update_time { get; set; } + /// + /// 供应商备注异常单 + /// + public string supplier_remark_exception { get; set; } + /// + /// 礼物单状态,默认值0:不存在礼物单,1:礼物单已发货,2:礼物单信息已更正 + /// + public int? gift_order_status { get; set; } + /// + /// 店铺备注:取微信ext_info.merchant_notes + /// + public string shop_remark { get; set; } + /// + /// 软件备注 + /// + public string soft_remark { get; set; } + /// + /// 外采金额(单位:分,整数存储) + /// + public int? out_amount { get; set; } + /// + /// 外采账户 + /// + public string out_account { get; set; } + /// + /// 外采订单号 + /// + public string out_order_no { get; set; } + /// + /// 外采快递公司 + /// + public string out_express_company { get; set; } + /// + /// 外采快递单号 + /// + public string out_express_no { get; set; } + /// + /// 外采是否发货(0 未发货,1 已发货) + /// + public int? out_shipped { get; set; } + /// + /// 判断是否优化过发货0 未优化, 1已优化 + /// + public int? is_shipment_optimized { get; set; } + /// + /// 判断是否优随机使用快递单号0 未使用, 1已使用 + /// + public int? is_express_no_used { get; set; } + /// + /// 外采订单售后状态 + /// + public string out_after_sale_status { get; set; } + /// + /// 是否支持运费险:0-不支持,1-支持 + /// + public int? has_freight_insurance { get; set; } + /// + /// 运费险金额(单位:元) + /// + public decimal? freight_insurance_amount { get; set; } + /// + /// 是否外采礼物单:0-否,1-是(外采订单) + /// + public int? external_gift { get; set; } + /// + /// 中转仓的状态 0未使用,1已创建,2创建失败(购买失败),3已创建未有上游快递单号,4已创建有上游快递单号 + /// + public decimal? transfer_warehouse_status { get; set; } + } +} + diff --git a/StoreHub.KJDWebService/Models/WxModel/oms_wei_order_item.cs b/StoreHub.KJDWebService/Models/WxModel/oms_wei_order_item.cs new file mode 100644 index 0000000..9d3a797 --- /dev/null +++ b/StoreHub.KJDWebService/Models/WxModel/oms_wei_order_item.cs @@ -0,0 +1,153 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +namespace StoreHub.KJDWebService.Models.WxModel +{ + public class oms_wei_order_item + { + /// + /// 订单商品表数据库id + /// + public long id { get; set; } + public long shop_id { get; set; } + /// + /// 商户ID + /// + public long merchant_id { get; set; } + /// + /// 订单id(平台订单id) + /// + public string order_id { get; set; } + /// + /// 商品spuid + /// + public string product_id { get; set; } + public string sku_id { get; set; } + /// + /// sku小图 + /// + public string thumb_img { get; set; } + /// + /// sku数量 + /// + public int? sku_cnt { get; set; } + /// + /// 售卖单价(单位:分) + /// + public int? sale_price { get; set; } + /// + /// 商品名称 + /// + public string title { get; set; } + /// + /// 正在售后/退款流程中的 sku 数量 + /// + public int? on_aftersale_sku_cnt { get; set; } + /// + /// 完成售后/退款的 sku 数量 + /// + public int? finish_aftersale_sku_cnt { get; set; } + /// + /// 商品编码 + /// + public string sku_code { get; set; } + /// + /// 市场单价(单位:分) + /// + public int? market_price { get; set; } + /// + /// sku属性JSON + /// + public string sku_attrs { get; set; } + /// + /// sku实付总价,取estimate_price和change_price中较小值 + /// + public int? real_price { get; set; } + /// + /// 商品外部spuid + /// + public string out_product_id { get; set; } + /// + /// 采购价 + /// + public int? purchase_price { get; set; } + /// + /// 运费 + /// + public int? freight { get; set; } + /// + /// 商品外部skuid + /// + public string out_sku_id { get; set; } + /// + /// 是否有优惠金额,非必填,默认为false + /// + public string is_discounted { get; set; } + /// + /// 优惠后sku总价,非必填,is_discounted为true时有值 + /// + public int? estimate_price { get; set; } + /// + /// 是否修改过价格,非必填,默认为false + /// + public string is_change_price { get; set; } + /// + /// 改价后sku总价,非必填,is_change_price为true时有值 + /// + public int? change_price { get; set; } + /// + /// 订单内商品维度平台券优惠金额(利润需要计算这个金额在内) + /// + public int? cash_coupon_discounted_price { get; set; } + /// + /// 区域库存id + /// + public string out_warehouse_id { get; set; } + /// + /// 退货地址 + /// + public string return_address { get; set; } + /// + /// 商品发货信息JSON + /// + public string sku_deliver_info { get; set; } + /// + /// 商品额外服务信息JSON + /// + public string extra_service { get; set; } + /// + /// 是否使用了会员积分抵扣 + /// + public string use_deduction { get; set; } + /// + /// 会员积分抵扣金额,单位为分 + /// + public int? deduction_price { get; set; } + /// + /// 达人佣金(微信小店:分账金额),单位为分 + /// + public int? predict_commission_fee { get; set; } + /// + /// 达人佣金(微信小店:分账金额),单位为分 + /// + public int? commission_amount { get; set; } + /// + /// 商品优惠券信息,逐步替换 order.order_detail.coupon_info + /// + public string order_product_coupon_info_list { get; set; } + /// + /// 商品id(o_goods外键) + /// + public long? erp_goods_id { get; set; } + /// + /// 商品skuid(o_goods_sku外键) + /// + public long? erp_goods_sku_id { get; set; } + /// + /// 售后状态 1:无售后或售后关闭,2:售后处理中,3:退款中,4: 退款成功 11 已取消 + /// + public int? refund_status { get; set; } + } +} + diff --git a/StoreHub.KJDWebService/Models/WxModel/oms_wei_refund.cs b/StoreHub.KJDWebService/Models/WxModel/oms_wei_refund.cs new file mode 100644 index 0000000..28f0f02 --- /dev/null +++ b/StoreHub.KJDWebService/Models/WxModel/oms_wei_refund.cs @@ -0,0 +1,151 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +namespace StoreHub.KJDWebService.Models.WxModel +{ + public class oms_wei_refund + { + public long id { get; set; } + public long? shop_id { get; set; } + public string after_sale_order_id { get; set; } + /// + /// 售后单当前状态,参考: + /// USER_CANCELD 用户取消申请 + /// MERCHANT_PROCESSING 商家受理中 + /// MERCHANT_REJECT_REFUND 商家拒绝退款 + /// MERCHANT_REJECT_RETURN 商家拒绝退货退款 + /// USER_WAIT_RETURN 待买家退货 + /// RETURN_CLOSED 退货退款关闭 + /// MERCHANT_WAIT_RECEIPT 待商家收货 + /// MERCHANT_OVERDUE_REFUND 商家逾期未退款 + /// MERCHANT_REFUND_SUCCESS 退款完成 + /// MERCHANT_RETURN_SUCCESS 退货退款完成 + /// PLATFORM_REFUNDING 平台退款中 + /// PLATFORM_REFUND_FAIL 平台退款失败 + /// USER_WAIT_CONFIRM 待用户确认 + /// MERCHANT_REFUND_RETRY_FAIL 商家打款失败,客服关闭售后 + /// MERCHANT_FAIL 售后关闭 + /// USER_WAIT_CONFIRM_UPDATE 待用户处理商家协商 + /// USER_WAIT_HANDLE_MERCHANT_AFTER_SALE 待用户处理商家代发起的售后申请 + /// + public string status { get; set; } + /// + /// 买家身份标识 + /// + public string openid { get; set; } + /// + /// 买家在开放平台的唯一标识符,若当前视频号小店已绑定到微信开放平台账号下会返回 + /// + public string unionid { get; set; } + /// + /// 商品spuid + /// + public string product_id { get; set; } + /// + /// 商品skuid + /// + public string sku_id { get; set; } + /// + /// 售后数量 + /// + public int? count { get; set; } + /// + /// 是否极速退款RefundInfo + /// + public string fast_refund { get; set; } + /// + /// 标明售后单退款直接原因, 枚举值参考 RefundReason + /// + public int? refund_reason { get; set; } + /// + /// 退款金额(分) + /// + public int? refund_amount { get; set; } + /// + /// 退款快递单号 + /// + public string return_waybill_id { get; set; } + /// + /// 物流公司id + /// + public string return_delivery_id { get; set; } + /// + /// 物流公司名称 + /// + public string return_delivery_name { get; set; } + /// + /// 售后相关商品信息JSON + /// + public string merchant_upload_info { get; set; } + /// + /// 售后单创建时间戳 + /// + public int? create_time { get; set; } + /// + /// 售后单更新时间戳 + /// + public int? update_time { get; set; } + /// + /// 退款原因 + /// + public string reason { get; set; } + /// + /// 退款原因解释 + /// + public string reason_text { get; set; } + /// + /// 售后类型。REFUND:退款;RETURN:退货退款。 + /// + public string type { get; set; } + /// + /// 订单号,该字段可用于获取订单 + /// + public string order_id { get; set; } + /// + /// detail json + /// + public string details { get; set; } + /// + /// 纠纷id,该字段可用于获取纠纷信息 + /// + public string complaint_id { get; set; } + /// + /// 微信支付退款的响应 + /// + public string refund_resp { get; set; } + /// + /// 推送状态(0未推送;1推送成功;2推送失败) + /// + public int? pull_status { get; set; } + /// + /// 订单审核时间 + /// + public DateTime pull_time { get; set; } + /// + /// 商品id(o_goods外键) + /// + public long? erp_goods_id { get; set; } + /// + /// 商品skuid(o_goods_sku外键) + /// + public long? erp_goods_sku_id { get; set; } + /// + /// 商户id + /// + public long merchant_id { get; set; } + /// + /// 仓库受理状态 + /// + public int? warehouse_status { get; set; } + + + public string return_user_name { get; set; } + public string return_province { get; set; } + public string return_city { get; set; } + public string return_county { get; set; } + public string return_detail { get; set; } + public string return_tel { get; set; } + } +} + diff --git a/StoreHub.KJDWebService/Models/WxModel/order_item_ext.cs b/StoreHub.KJDWebService/Models/WxModel/order_item_ext.cs new file mode 100644 index 0000000..632407b --- /dev/null +++ b/StoreHub.KJDWebService/Models/WxModel/order_item_ext.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +namespace StoreHub.KJDWebService.Models.WxModel +{ + public class order_item_ext + { + public long? id { get; set; } + public string order_id { get; set; } + public string out_order_id { get; set; } + public string sku_id { get; set; } + public string shop_app_id { get; set; } + public string shop_name { get; set; } + /// + /// 直发/云仓(一般只有直发才会写值,直发会覆盖中转) + /// + public string buy_type { get; set; } + /// + /// 订单异常文本 + /// + public string abnormal_text { get; set; } + public int? flag { get; set; } + public string label { get; set; } + public string remark { get; set; } + public string after_sale_user_delivery_address { get; set; } + public DateTime add_time { get; set; } + public DateTime mdy_time { get; set; } + } +} + diff --git a/StoreHub.KJDWebService/Models/WxModel/order_pdd_buyer_after_sale.cs b/StoreHub.KJDWebService/Models/WxModel/order_pdd_buyer_after_sale.cs new file mode 100644 index 0000000..634fddb --- /dev/null +++ b/StoreHub.KJDWebService/Models/WxModel/order_pdd_buyer_after_sale.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +namespace StoreHub.KJDWebService.Models.WxModel +{ + public class order_pdd_buyer_after_sale + { + public long? id { get; set; } + public string wx_order_id { get; set; } + public string wx_sku_id { get; set; } + /// + /// 买手订单在微信店铺的发货类型 0中转仓发货 1直发 + /// + public int wx_send_type { get; set; } + public DateTime TransitCreateTime { get; set; } + //public DateTime TransitPickupTime { get; set; } + public int? pre_allocated_order_no { get; set; } + public string buyerId { get; set; } + public string buyerName { get; set; } + public string afterSalesId { get; set; } + public string orderSn { get; set; } + public int? orderAmount { get; set; } + public long? refundAmount { get; set; } + public long? orderDate { get; set; } + public string statusText { get; set; } + public string afterSaleAddress { get; set; } + public string order_detail { get; set; } + public DateTime add_time { get; set; } + public DateTime mdy_time { get; set; } + } +} + diff --git a/StoreHub.KJDWebService/Models/WxModel/order_pdd_buyer_order.cs b/StoreHub.KJDWebService/Models/WxModel/order_pdd_buyer_order.cs new file mode 100644 index 0000000..254092d --- /dev/null +++ b/StoreHub.KJDWebService/Models/WxModel/order_pdd_buyer_order.cs @@ -0,0 +1,35 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +namespace StoreHub.KJDWebService.Models.WxModel +{ + public class order_pdd_buyer_order + { + public long? id { get; set; } + public string wx_order_id { get; set; } + public string wx_sku_id { get; set; } + /// + /// 买手订单在微信店铺的发货类型 0中转仓发货 1直发 + /// + public int wx_send_type { get; set; } + public DateTime TransitCreateTime { get; set; } + public int? pre_allocated_order_no { get; set; } + public string buyerId { get; set; } + public string buyerName { get; set; } + public string order_sn { get; set; } + public int? order_amount { get; set; } + public long? order_time { get; set; } + public string outExpressCompanyCode { get; set; } + public string tracking_number { get; set; } + /// + /// 订单状态 + /// + public string order_status_prompt { get; set; } + public int? after_sales_status { get; set; } + public string order_detail { get; set; } + public DateTime add_time { get; set; } + public DateTime mdy_time { get; set; } + } +} + diff --git a/StoreHub.KJDWebService/Models/WxModel/user_payment_record_info.cs b/StoreHub.KJDWebService/Models/WxModel/user_payment_record_info.cs new file mode 100644 index 0000000..a3a0fa5 --- /dev/null +++ b/StoreHub.KJDWebService/Models/WxModel/user_payment_record_info.cs @@ -0,0 +1,69 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +namespace StoreHub.KJDWebService.Models.WxModel +{ + public class user_payment_record_info + { + public long id { get; set; } + /// + /// 变动类型,1:充值,2:采购花费,3:产品退款到账,4:运费退款到账,5:采购收款,6:产品退款扣除,7:运费退款扣除,16:礼物单话费,20:中转运费,23:作废运费返还 + /// + + public int? type { get; set; } + /// + /// 充值或花费的金额(元) + /// + public decimal amount { get; set; } + /// + /// 充值或花费后的当前账户余额(元) + /// + public decimal balance { get; set; } + /// + /// 账户名 + /// + public string user_name { get; set; } + /// + /// 平台编码 + /// + public string platform_code { get; set; } + /// + /// 订单id + /// + public string order_id { get; set; } + /// + /// 售后单id + /// + public long? after_sale_id { get; set; } + /// + /// 创建人 + /// + public string create_by { get; set; } + /// + /// 创建时间 + /// + public DateTime create_time { get; set; } + /// + /// 修改人 + /// + public string update_by { get; set; } + /// + /// 修改时间 + /// + public DateTime update_time { get; set; } + /// + /// 是否已删除 + /// + public int? is_deleted { get; set; } + /// + /// 备注 + /// + public string remark { get; set; } + /// + /// 扣款的对方账户名称 + /// + public string counterparty_account_name { get; set; } + } +} + diff --git a/StoreHub.KJDWebService/Models/WxModel/user_points_record_info.cs b/StoreHub.KJDWebService/Models/WxModel/user_points_record_info.cs new file mode 100644 index 0000000..d4355c9 --- /dev/null +++ b/StoreHub.KJDWebService/Models/WxModel/user_points_record_info.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +namespace StoreHub.KJDWebService.Models.WxModel +{ + public class user_points_record_info + { + public int id { get; set; } + public string user_name { get; set; } + public string user_nick { get; set; } + public int delta_points { get; set; } + public int? new_points { get; set; } + public string option_type { get; set; } + public string operator_type { get; set; } + public string operator_name { get; set; } + public string shop_id { get; set; } + public string shop_account { get; set; } + public string remark { get; set; } + public DateTime add_time { get; set; } + /// + /// 对方账户名称 + /// + public string counterparty_account_name { get; set; } + } +} + diff --git a/StoreHub.KJDWebService/Models/WxModel/wx_qualification_image_info.cs b/StoreHub.KJDWebService/Models/WxModel/wx_qualification_image_info.cs new file mode 100644 index 0000000..1f33345 --- /dev/null +++ b/StoreHub.KJDWebService/Models/WxModel/wx_qualification_image_info.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +namespace StoreHub.KJDWebService.Models.WxModel +{ + public class wx_qualification_image_info + { + public int id { get; set; } + public string cat_name { get; set; } + public string img_md5 { get; set; } + public string img_base64 { get; set; } + public string img_thumb_base64 { get; set; } + public string txt_margin { get; set; } + public DateTime add_time { get; set; } + public DateTime mdy_time { get; set; } + } +} + diff --git a/StoreHub.KJDWebService/Models/WxProdSecretSpuIdShopIdMapParam.cs b/StoreHub.KJDWebService/Models/WxProdSecretSpuIdShopIdMapParam.cs new file mode 100644 index 0000000..bf57d0d --- /dev/null +++ b/StoreHub.KJDWebService/Models/WxProdSecretSpuIdShopIdMapParam.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +namespace StoreHub.KJDWebService.Models +{ + public class WxProdSecretSpuIdShopIdMapParam + { + public int id { get; set; } + public string up_secret_spu_id { get; set; } + public string up_spu_id { get; set; } + public string shop_id { get; set; } + public DateTime add_time { get; set; } + } +} + diff --git a/StoreHub.KJDWebService/Services/BXXPriceService.cs b/StoreHub.KJDWebService/Services/BXXPriceService.cs new file mode 100644 index 0000000..de4ff3d --- /dev/null +++ b/StoreHub.KJDWebService/Services/BXXPriceService.cs @@ -0,0 +1,858 @@ +using StoreHub.KJDWebService.Models; +using StoreHub.Framework.Repositorys; +using Microsoft.Extensions.Configuration; +using StoreHub.KJDWebService.Commons; +using MySql.Data.MySqlClient; +using NaiBa.Util.Extension; +using System; +using System.Collections.Generic; +using System.Data; +using System.Linq; + +namespace StoreHub.KJDWebService.Services +{ + public class BXXPriceService : ServiceBase + { + public BXXPriceService(SqlRepository sqlRepository, IConfiguration configuration) : base(sqlRepository, configuration) + { + } + public string AddPrice(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\":\"校验失败\"}"; + + string user_name = RegexUtils.GetStringQuery(ref inputData, "user_name"); + string ext_code = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "ext_code")).ParseToString(); + int original_price = RegexUtils.GetStringQuery(ref inputData, "original_price").ParseToInt(); + int markup_times = RegexUtils.GetStringQuery(ref inputData, "markup_times").ParseToInt(); + int extra_price = RegexUtils.GetStringQuery(ref inputData, "extra_price").ParseToInt(); + string notes = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "notes")).ParseToString(); + + if (string.IsNullOrEmpty(user_name)) + { + return "{\"code\":500,\"msg\":\"没有用户名\"}"; + } + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + string sqlExist = "select count(ext_code) from bxx.price_markup where ext_code=@ext_code"; + string sql = "insert into bxx.price_markup " + + "(ext_code,original_price,markup_times,extra_price,notes) " + + "values (@ext_code,@original_price,@markup_times,@extra_price,@notes);"; + List paramLst = new List(); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "@ext_code", Value = ext_code, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.Int32, ParameterName = "@original_price", Value = original_price, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.Int32, ParameterName = "@markup_times", Value = markup_times, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.Int32, ParameterName = "@extra_price", Value = extra_price, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "@notes", Value = notes, }); + + var has = mySql.ExecuteFirst(sqlExist, paramLst.ToArray()); + if (has != "0") + { + mySql.Close(); + return "{\"code\":501,\"msg\":\"货号 " + ext_code + " 价格数据已存在\"}"; + } + + var rst = mySql.ExecuteNonQuery(sql, paramLst.ToArray()); + mySql.Close(); + if (rst) + { + return "{\"code\":200,\"msg\":\"success\"}"; + } + else + { + return "{\"code\":502,\"msg\":\"" + mySql.Message + "\"}"; + } + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + public string GetPriceList(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"); + + string start_original_price = RegexUtils.GetStringQuery(ref inputData, "start_original_price"); + string end_original_price = RegexUtils.GetStringQuery(ref inputData, "end_original_price"); + string start_markup_times = RegexUtils.GetStringQuery(ref inputData, "start_markup_times"); + string end_markup_times = RegexUtils.GetStringQuery(ref inputData, "end_markup_times"); + string start_extra_price = RegexUtils.GetStringQuery(ref inputData, "start_extra_price"); + string end_extra_price = RegexUtils.GetStringQuery(ref inputData, "end_extra_price"); + var search_ext_code = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "search_ext_code")); + var search_notes = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "search_notes")); + var in_ext_code = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "in_ext_code")); + int page = RegexUtils.GetStringQuery(ref inputData, "page").ParseToInt(); + int page_size = RegexUtils.GetStringQuery(ref inputData, "page_size").ParseToInt(50); + if (string.IsNullOrEmpty(user_name)) + { + return "{\"code\":500,\"msg\":\"没有用户名\"}"; + } + + + List paramLst = new List(); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "@search_ext_code", Value = "%" + search_ext_code + "%", }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "@search_notes", Value = "%" + search_notes + "%", }); + paramLst.Add(new MySqlParameter() { DbType = DbType.Int32, ParameterName = "@start_original_price", Value = start_original_price.ParseToInt(), }); + paramLst.Add(new MySqlParameter() { DbType = DbType.Int32, ParameterName = "@end_original_price", Value = end_original_price.ParseToInt(), }); + paramLst.Add(new MySqlParameter() { DbType = DbType.Int32, ParameterName = "@start_markup_times", Value = start_markup_times.ParseToInt(), }); + paramLst.Add(new MySqlParameter() { DbType = DbType.Int32, ParameterName = "@end_markup_times", Value = end_markup_times.ParseToInt(), }); + paramLst.Add(new MySqlParameter() { DbType = DbType.Int32, ParameterName = "@start_extra_price", Value = start_extra_price.ParseToInt(), }); + paramLst.Add(new MySqlParameter() { DbType = DbType.Int32, ParameterName = "@end_extra_price", Value = end_extra_price.ParseToInt(), }); + //paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "@in_ext_code", Value = "'" + in_ext_code?.Replace(",", "','") + "'", }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "@in_ext_code", Value = in_ext_code.ParseToString() }); + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + + string sql = "select count(id) from bxx.price_markup p where 1=1"; + + string where = ""; + if (!string.IsNullOrWhiteSpace(search_ext_code)) + where += " and p.ext_code like @search_ext_code"; + if (!string.IsNullOrWhiteSpace(search_notes)) + where += " and p.notes like @search_notes"; + if (!string.IsNullOrWhiteSpace(start_original_price)) + where += " and p.original_price >= @start_original_price"; + if (!string.IsNullOrWhiteSpace(end_original_price)) + where += " and p.original_price <= @end_original_price"; + if (!string.IsNullOrWhiteSpace(start_markup_times)) + where += " and p.markup_times >= @start_markup_times"; + if (!string.IsNullOrWhiteSpace(end_markup_times)) + where += " and p.markup_times <= @end_markup_times"; + if (!string.IsNullOrWhiteSpace(start_extra_price)) + where += " and p.extra_price >= @start_extra_price"; + if (!string.IsNullOrWhiteSpace(end_extra_price)) + where += " and p.extra_price <= @end_extra_price"; + if (!string.IsNullOrEmpty(in_ext_code)) + where += " and p.ext_code in ('" + in_ext_code?.Replace(",", "','") + "')"; + sql += where; + + var count = mySql.ExecuteRowCount(sql, paramLst.ToArray()); + + DataTable dt; + if (count == 0) + { + dt = new DataTable(); + } + else + { + sql = "select * from bxx.price_markup p where 1=1"; + + //where子句 + sql += where; + + sql += " order by p.id desc"; + sql += " limit " + Math.Max(page - 1, 0) * page_size + "," + page_size; + dt = mySql.ExecuteDataTable(sql, paramLst.ToArray()); + } + + mySql.Close(); + if (dt != null) + { + try + { + List priceList = new List(); + foreach (DataRow row in dt.Rows) + { + DBPriceResultParam price = new DBPriceResultParam + { + id = row["id"].ParseToInt(), + extra_price = row["extra_price"].ParseToInt(), + markup_times = row["markup_times"].ParseToInt(), + original_price = row["original_price"].ParseToInt(), + notes = row["notes"].ParseToString(), + ext_code = row["ext_code"].ParseToString(), + add_time = Convert.ToDateTime(row["add_time"]), + mdy_time = Convert.ToDateTime(row["mdy_time"]), + }; + priceList.Add(price); + } + var data = JsonUtils.SerializeObjectToString(priceList); + return "{\"code\":200,\"msg\":\"success\",\"data\":" + data + ",\"count\":" + count + "}"; + } + 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 DelDbPrice(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("'", "\\'"); + var id = RegexUtils.GetStringQuery(ref inputData, "db_id")?.Replace("'", "\\'"); + + if (string.IsNullOrEmpty(user_name)) + { + return "{\"code\":500,\"msg\":\"没有用户名\"}"; + } + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = "delete from bxx.price_markup where id='" + id + "'"; + + var rst = mySql.ExecuteNonQuery(sql); + mySql.Close(); + if (rst) + { + return "{\"code\":200,\"msg\":\"success\"}"; + } + else + return "{\"code\":500,\"msg\":\"删除失败:" + mySql.Message + "\"}"; + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + public string MdyDBPrice(string inputData, bool isAdmin = false) + { + 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 db_id = RegexUtils.GetStringQuery(ref inputData, "db_id"); + string notes = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "notes")); + string ext_code = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "ext_code")); + string original_price = RegexUtils.GetStringQuery(ref inputData, "original_price"); + string markup_times = RegexUtils.GetStringQuery(ref inputData, "markup_times"); + string extra_price = RegexUtils.GetStringQuery(ref inputData, "extra_price"); + + if (string.IsNullOrEmpty(user_name)) + { + return "{\"code\":500,\"msg\":\"没有用户名\"}"; + } + + List paramLst = new List(); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "@ext_code", Value = ext_code, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.Int32, ParameterName = "@original_price", Value = original_price.ParseToInt(), }); + paramLst.Add(new MySqlParameter() { DbType = DbType.Int32, ParameterName = "@markup_times", Value = markup_times.ParseToInt(), }); + paramLst.Add(new MySqlParameter() { DbType = DbType.Int32, ParameterName = "@extra_price", Value = extra_price.ParseToInt(), }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "@notes", Value = notes, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.Int32, ParameterName = "@db_id", Value = db_id, }); + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + + string sqlExist = "select count(ext_code) from bxx.price_markup where ext_code=@ext_code and id!=@db_id"; + var has = mySql.ExecuteFirst(sqlExist, paramLst.ToArray()); + if (has != "0") + { + mySql.Close(); + return "{\"code\":501,\"msg\":\"货号 " + ext_code + " 价格数据已存在\"}"; + } + + string sql = "update bxx.price_markup set"; + if (notes != null) + sql += " notes=@notes,"; + if (ext_code != null) + sql += " ext_code=@ext_code,"; + if (original_price != null) + sql += " original_price=@original_price,"; + if (markup_times != null) + sql += " markup_times=@markup_times,"; + if (extra_price != null) + sql += " extra_price=@extra_price,"; + sql = sql.TrimEnd(','); + sql += " where id=@db_id;"; + + var rst = mySql.ExecuteNonQuery(sql, paramLst.ToArray()); + mySql.Close(); + if (rst) + { + return "{\"code\":200,\"msg\":\"success\"}"; + } + else + { + return "{\"code\":500,\"msg\":\"更新失败:" + mySql.Message + "\"}"; + } + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + public string AddPurchasePrice(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\":\"校验失败\"}"; + + string user_name = RegexUtils.GetStringQuery(ref inputData, "user_name"); + if (string.IsNullOrEmpty(user_name)) + { + return "{\"code\":500,\"msg\":\"没有用户名\"}"; + } + + string shop_id = RegexUtils.GetStringQuery(ref inputData, "shop_id"); + string shop_name = RegexUtils.GetStringQuery(ref inputData, "shop_name"); + string spu_id = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "spu_id")).ParseToString(); + string skc_id = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "skc_id")).ParseToString(); + string cat_id = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "cat_id")).ParseToString(); + string cat_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "cat_name")).ParseToString(); + string ext_code = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "ext_code")).ParseToString(); + string product_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "product_name")).ParseToString(); + string main_img = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "main_img")).ParseToString(); + string discount = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "discount")).ParseToString(); + string price_text = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "price_text")).ParseToString(); + string sku_purchase_price_json = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "sku_purchase_price_json")).ParseToString(); + string notes = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "notes")).ParseToString(); + + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + string sqlExist = "select count(spu_id) from bxx.product_purchase_price where spu_id=@spu_id"; + string sql = "insert into bxx.product_purchase_price " + + "(shop_id,shop_name,spu_id,skc_id,cat_id,cat_name,ext_code,product_name,main_img,discount,price_text,sku_purchase_price_json,notes) " + + "values (@shop_id,@shop_name,@spu_id,@skc_id,@cat_id,@cat_name,@ext_code,@product_name,@main_img,@discount,@price_text,@sku_purchase_price_json,@notes);"; + List paramLst = new List(); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "@shop_id", Value = shop_id, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "@shop_name", Value = shop_name, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "@spu_id", Value = spu_id, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "@skc_id", Value = skc_id, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "@cat_id", Value = cat_id, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "@cat_name", Value = cat_name, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "@ext_code", Value = ext_code, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "@product_name", Value = product_name, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "@main_img", Value = main_img, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.Int32, ParameterName = "@discount", Value = discount.ParseToInt(), }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "@price_text", Value = price_text, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "@sku_purchase_price_json", Value = sku_purchase_price_json, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "@notes", Value = notes, }); + + var has = mySql.ExecuteFirst(sqlExist, paramLst.ToArray()); + if (has != "0") + { + mySql.Close(); + return "{\"code\":501,\"msg\":\"货号 " + ext_code + " 价格数据已存在\"}"; + } + + var rst = mySql.ExecuteNonQuery(sql, paramLst.ToArray()); + mySql.Close(); + if (rst) + { + return "{\"code\":200,\"msg\":\"success\"}"; + } + else + { + return "{\"code\":502,\"msg\":\"" + mySql.Message + "\"}"; + } + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + public string MdyPurchasePrice(string inputData, bool isAdmin = false) + { + 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"); + if (string.IsNullOrEmpty(user_name)) + { + return "{\"code\":500,\"msg\":\"没有用户名\"}"; + } + + var db_id = RegexUtils.GetStringQuery(ref inputData, "db_id"); + string shop_id = RegexUtils.GetStringQuery(ref inputData, "shop_id"); + string shop_name = RegexUtils.GetStringQuery(ref inputData, "shop_name"); + string cat_id = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "cat_id")).ParseToString(); + string cat_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "cat_name")).ParseToString(); + string ext_code = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "ext_code")).ParseToString(); + string product_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "product_name")).ParseToString(); + string main_img = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "main_img")).ParseToString(); + string discount = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "discount")).ParseToString(); + string price_text = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "price_text")).ParseToString(); + string sku_purchase_price_json = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "sku_purchase_price_json")).ParseToString(); + string notes = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "notes")).ParseToString(); + + List paramLst = new List(); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "@db_id", Value = db_id, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "@shop_id", Value = shop_id, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "@shop_name", Value = shop_name, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "@cat_id", Value = cat_id, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "@cat_name", Value = cat_name, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "@ext_code", Value = ext_code, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "@product_name", Value = product_name, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "@main_img", Value = main_img, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.Int32, ParameterName = "@discount", Value = discount.ParseToInt(), }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "@price_text", Value = price_text, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "@sku_purchase_price_json", Value = sku_purchase_price_json, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "@notes", Value = notes, }); + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + + string sql = "update bxx.product_purchase_price set"; + if (shop_id != null) + sql += " shop_id=@shop_id,"; + if (shop_name != null) + sql += " shop_name=@shop_name,"; + if (cat_id != null) + sql += " cat_id=@cat_id,"; + if (cat_name != null) + sql += " cat_name=@cat_name,"; + if (ext_code != null) + sql += " ext_code=@ext_code,"; + if (product_name != null) + sql += " product_name=@product_name,"; + if (main_img != null) + sql += " main_img=@main_img,"; + if (discount != null) + sql += " discount=@discount,"; + if (price_text != null) + sql += " price_text=@price_text,"; + if (sku_purchase_price_json != null) + sql += " sku_purchase_price_json=@sku_purchase_price_json,"; + if (notes != null) + sql += " notes=@notes,"; + sql = sql.TrimEnd(','); + sql += " where id=@db_id;"; + + var rst = mySql.ExecuteNonQuery(sql, paramLst.ToArray()); + mySql.Close(); + if (rst) + { + return "{\"code\":200,\"msg\":\"success\"}"; + } + else + { + return "{\"code\":500,\"msg\":\"更新失败:" + mySql.Message + "\"}"; + } + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + public string GetPurchasePriceList(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 search_spu_id = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "search_spu_id")); + var search_skc_id = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "search_skc_id")); + var search_ext_code = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "search_ext_code")); + var search_notes = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "search_notes")); + var in_spu_id = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "in_spu_id")); + int page = RegexUtils.GetStringQuery(ref inputData, "page").ParseToInt(); + int page_size = RegexUtils.GetStringQuery(ref inputData, "page_size").ParseToInt(50); + if (string.IsNullOrEmpty(user_name)) + { + return "{\"code\":500,\"msg\":\"没有用户名\"}"; + } + + + List paramLst = new List(); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "@search_spu_id", Value = "%" + search_spu_id + "%", }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "@search_skc_id", Value = "%" + search_skc_id + "%", }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "@search_ext_code", Value = "%" + search_ext_code + "%", }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "@search_notes", Value = "%" + search_notes + "%", }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "@in_spu_id", Value = in_spu_id.ParseToString() }); + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + + string sql = "select count(id) from bxx.product_purchase_price p where 1=1"; + + string where = ""; + if (!string.IsNullOrWhiteSpace(search_spu_id)) + where += " and p.spu_id like @search_spu_id"; + if (!string.IsNullOrWhiteSpace(search_skc_id)) + where += " and p.skc_id like @search_skc_id"; + if (!string.IsNullOrWhiteSpace(search_ext_code)) + where += " and p.ext_code like @search_ext_code"; + if (!string.IsNullOrWhiteSpace(search_notes)) + where += " and p.notes like @search_notes"; + if (!string.IsNullOrEmpty(in_spu_id)) + where += " and p.spu_id in ('" + in_spu_id?.Replace(",", "','") + "')"; + sql += where; + + var count = mySql.ExecuteRowCount(sql, paramLst.ToArray()); + + DataTable dt; + if (count == 0) + { + dt = new DataTable(); + } + else + { + sql = "select * from bxx.product_purchase_price p where 1=1"; + + //where子句 + sql += where; + + sql += " order by p.id desc"; + sql += " limit " + Math.Max(page - 1, 0) * page_size + "," + page_size; + dt = mySql.ExecuteDataTable(sql, paramLst.ToArray()); + } + + mySql.Close(); + if (dt != null) + { + try + { + List purchasePriceList = new List(); + foreach (DataRow row in dt.Rows) + { + ProductPurchasePriceResultParam price = new ProductPurchasePriceResultParam + { + id = row["id"].ParseToInt(), + shop_id = row["shop_id"].ParseToString(), + shop_name = row["shop_name"].ParseToString(), + cat_id = row["cat_id"].ParseToString(), + cat_name = row["cat_name"].ParseToString(), + main_img = row["main_img"].ParseToString(), + discount = row["discount"].ParseToInt(), + price_text = row["price_text"].ParseToString(), + product_name = row["product_name"].ParseToString(), + skc_id = row["skc_id"].ParseToString(), + sku_purchase_price_json = row["sku_purchase_price_json"].ParseToString(), + spu_id = row["spu_id"].ParseToString(), + notes = row["notes"].ParseToString(), + ext_code = row["ext_code"].ParseToString(), + add_time = Convert.ToDateTime(row["add_time"]), + mdy_time = Convert.ToDateTime(row["mdy_time"]), + }; + purchasePriceList.Add(price); + } + var data = JsonUtils.SerializeObjectToString(purchasePriceList); + return "{\"code\":200,\"msg\":\"success\",\"data\":" + data + ",\"count\":" + count + "}"; + } + 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 DelPurchasePrice(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("'", "\\'"); + var id = RegexUtils.GetStringQuery(ref inputData, "db_id")?.Replace("'", "\\'"); + + if (string.IsNullOrEmpty(user_name)) + { + return "{\"code\":500,\"msg\":\"没有用户名\"}"; + } + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = "delete from bxx.product_purchase_price where id='" + id + "'"; + + var rst = mySql.ExecuteNonQuery(sql); + mySql.Close(); + if (rst) + { + return "{\"code\":200,\"msg\":\"success\"}"; + } + else + return "{\"code\":500,\"msg\":\"删除失败:" + mySql.Message + "\"}"; + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + + + + + + + + + + public string AddExtCodePrice(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\":\"校验失败\"}"; + + string user_name = RegexUtils.GetStringQuery(ref inputData, "user_name"); + string ext_code = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "ext_code")).ParseToString(); + var ext_code_price = RegexUtils.GetStringQuery(ref inputData, "ext_code_price")?.ParseToInt(); + + if (string.IsNullOrEmpty(user_name)) + { + return "{\"code\":500,\"msg\":\"没有用户名\"}"; + } + if (string.IsNullOrEmpty(ext_code)) + { + return "{\"code\":500,\"msg\":\"没有货号\"}"; + } + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + List paramLst = new List(); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "@ext_code", Value = ext_code, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.Int32, ParameterName = "@ext_code_price", Value = ext_code_price, }); + + string sql= "select count(ext_code) from bxx.ext_code_price where ext_code=@ext_code"; + var count = mySql.ExecuteRowCount(sql, paramLst.ToArray()); + if (count.ParseToInt() > 0) + { + sql = "update bxx.ext_code_price set ext_code_price=@ext_code_price where ext_code=@ext_code"; + } + else + { + sql = "insert into bxx.ext_code_price (ext_code,ext_code_price) values (@ext_code,@ext_code_price);"; + } + + var rst = mySql.ExecuteNonQuery(sql, paramLst.ToArray()); + mySql.Close(); + if (rst) + { + return "{\"code\":200,\"msg\":\"success\"}"; + } + else + { + return "{\"code\":502,\"msg\":\"" + mySql.Message + "\"}"; + } + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + public string GetExtCodePriceList(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"); + + string start_ext_price = RegexUtils.GetStringQuery(ref inputData, "start_ext_price"); + string end_ext_price = RegexUtils.GetStringQuery(ref inputData, "end_ext_price"); + var search_ext_code = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "search_ext_code")); + var in_ext_code = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "in_ext_code")); + int page = RegexUtils.GetStringQuery(ref inputData, "page").ParseToInt(); + int page_size = RegexUtils.GetStringQuery(ref inputData, "page_size").ParseToInt(50); + if (string.IsNullOrEmpty(user_name)) + { + return "{\"code\":500,\"msg\":\"没有用户名\"}"; + } + + + List paramLst = new List(); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "@search_ext_code", Value = "%" + search_ext_code + "%", }); + paramLst.Add(new MySqlParameter() { DbType = DbType.Int32, ParameterName = "@start_ext_price", Value = start_ext_price.ParseToInt(), }); + paramLst.Add(new MySqlParameter() { DbType = DbType.Int32, ParameterName = "@end_ext_price", Value = end_ext_price.ParseToInt(), }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "@in_ext_code", Value = in_ext_code.ParseToString() }); + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + + string sql = "select count(id) from bxx.ext_code_price p where 1=1"; + + string where = ""; + if (!string.IsNullOrWhiteSpace(search_ext_code)) + where += " and p.ext_code like @search_ext_code"; + if (!string.IsNullOrWhiteSpace(start_ext_price)) + where += " and p.ext_code_price >= @start_ext_price"; + if (!string.IsNullOrWhiteSpace(end_ext_price)) + where += " and p.ext_code_price <= @end_ext_price"; + if (!string.IsNullOrEmpty(in_ext_code)) + where += " and p.ext_code in ('" + in_ext_code?.Replace(",", "','") + "')"; + sql += where; + + var count = mySql.ExecuteRowCount(sql, paramLst.ToArray()); + + DataTable dt; + if (count == 0) + { + dt = new DataTable(); + } + else + { + sql = "select * from bxx.ext_code_price p where 1=1"; + + //where子句 + sql += where; + + sql += " order by p.id desc"; + sql += " limit " + Math.Max(page - 1, 0) * page_size + "," + page_size; + dt = mySql.ExecuteDataTable(sql, paramLst.ToArray()); + } + + mySql.Close(); + if (dt != null) + { + try + { + List priceList = new List(); + foreach (DataRow row in dt.Rows) + { + DBExtCodePriceResult price = new DBExtCodePriceResult + { + id = row["id"].ParseToInt(), + ext_code_price = row["ext_code_price"].ParseToInt(), + ext_code = row["ext_code"].ParseToString(), + add_time = Convert.ToDateTime(row["add_time"]), + mdy_time = Convert.ToDateTime(row["mdy_time"]), + }; + priceList.Add(price); + } + var data = JsonUtils.SerializeObjectToString(priceList); + return "{\"code\":200,\"msg\":\"success\",\"data\":" + data + ",\"count\":" + count + "}"; + } + 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 DelDbExtCodePrice(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("'", "\\'"); + var id = RegexUtils.GetStringQuery(ref inputData, "db_id")?.Replace("'", "\\'"); + + if (string.IsNullOrEmpty(user_name)) + { + return "{\"code\":500,\"msg\":\"没有用户名\"}"; + } + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = "delete from bxx.ext_code_price where id='" + id + "'"; + + var rst = mySql.ExecuteNonQuery(sql); + mySql.Close(); + if (rst) + { + return "{\"code\":200,\"msg\":\"success\"}"; + } + else + return "{\"code\":500,\"msg\":\"删除失败:" + mySql.Message + "\"}"; + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + public string MdyDBExtCodePrice(string inputData, bool isAdmin = false) + { + 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 db_id = RegexUtils.GetStringQuery(ref inputData, "db_id"); + string ext_code = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "ext_code")); + string ext_code_price = RegexUtils.GetStringQuery(ref inputData, "original_price"); + + if (string.IsNullOrEmpty(user_name)) + { + return "{\"code\":500,\"msg\":\"没有用户名\"}"; + } + + List paramLst = new List(); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "@ext_code", Value = ext_code, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.Int32, ParameterName = "@ext_code_price", Value = ext_code_price.ParseToInt(), }); + paramLst.Add(new MySqlParameter() { DbType = DbType.Int32, ParameterName = "@db_id", Value = db_id, }); + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + + //string sqlExist = "select count(ext_code) from bxx.ext_code_price where ext_code=@ext_code and id!=@db_id"; + //var has = mySql.ExecuteFirst(sqlExist, paramLst.ToArray()); + //if (has != "0") + //{ + // mySql.Close(); + // return "{\"code\":501,\"msg\":\"货号 " + ext_code + " 价格数据已存在\"}"; + //} + + string sql = "update bxx.ext_code_price set"; + if (ext_code != null) + sql += " ext_code=@ext_code,"; + if (ext_code_price != null) + sql += " ext_code_price=@ext_code_price,"; + sql = sql.TrimEnd(','); + sql += " where id=@db_id;"; + + var rst = mySql.ExecuteNonQuery(sql, paramLst.ToArray()); + mySql.Close(); + if (rst) + { + return "{\"code\":200,\"msg\":\"success\"}"; + } + else + { + return "{\"code\":500,\"msg\":\"更新失败:" + mySql.Message + "\"}"; + } + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + } +} + + + + diff --git a/StoreHub.KJDWebService/Services/BXXProductService.cs b/StoreHub.KJDWebService/Services/BXXProductService.cs new file mode 100644 index 0000000..43a6efe --- /dev/null +++ b/StoreHub.KJDWebService/Services/BXXProductService.cs @@ -0,0 +1,3859 @@ +using StoreHub.KJDWebService.Services; +using StoreHub.Framework.Repositorys; +using Microsoft.Extensions.Configuration; +using StoreHub.KJDWebService.Models; +using StoreHub.KJDWebService.Models.ShopModel; +using StoreHub.KJDWebService.Commons; +using MySql.Data.MySqlClient; +using NaiBa.Util.Extension; +using NaiBa.Util.Helper; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; +using System; +using System.Collections.Generic; +using System.Data; +using System.Drawing; +using System.IO; +using System.Linq; +using System.Reflection; +using System.Threading; + +namespace StoreHub.KJDWebService.Services +{ + public class BXXProductService : ServiceBase + { + public BXXProductService(SqlRepository sqlRepository, IConfiguration configuration) : base(sqlRepository, configuration) + { + } + string GetProductTableName(string inputData) + { + var tableName = "bxx.product"; + //var add_user_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "add_user_name"))?.Replace("'", "\\'"); + //if (add_user_name != null && add_user_name != "admin") + //{ + // var tableId = RegexUtils.GetStringQuery(ref inputData, "table_id").ParseToNullableLong(); + // if (tableId == null && add_user_name.ParseToNullableLong() is long userIdLong) + // tableId = userIdLong % 1024; + // if (tableId == null) + // tableId = Math.Abs(add_user_name.GetHashCode()) % 1024; + // tableName = "pdb.product_" + tableId; + //} + return tableName; + } + public string AddProduct(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + var time = 0; + int.TryParse(RegexUtils.GetStringQuery(ref inputData, "time"), out time); + string time1 = RegexUtils.GetStringQuery(ref inputData, "code"); + if (time1 != EncrypUtil.Encryption(time)) + return "{\"code\":50000,\"msg\":\"校验失败\"}"; + + string user_name = RegexUtils.GetStringQuery(ref inputData, "user_name")?.Replace("'", "\\'"); + string from_shop_id = RegexUtils.GetStringQuery(ref inputData, "from_shop_id")?.Replace("'", "\\'"); + string from_shop_name = RegexUtils.GetStringQuery(ref inputData, "from_shop_name")?.Replace("'", "\\'"); + string offline_supplier_id = RegexUtils.GetStringQuery(ref inputData, "offline_supplier_id")?.Replace("'", "\\'"); + string offline_supplier_name = RegexUtils.GetStringQuery(ref inputData, "offline_supplier_name")?.Replace("'", "\\'"); + string spu_id = RegexUtils.GetStringQuery(ref inputData, "spu_id")?.Replace("'", "\\'"); + //厂商直采聚水潭商品使用skcid存储coid数据 + string skc_id = RegexUtils.GetStringQuery(ref inputData, "skc_id")?.Replace("'", "\\'"); // skcId,聚水潭商品为coid + string real_coid = RegexUtils.GetStringQuery(ref inputData, "real_coid")?.Replace("'", "\\'"); // 聚水潭爆款专区真实商家coid,供应商直采商品该字段留空 + string real_spu_id = RegexUtils.GetStringQuery(ref inputData, "real_spu_id")?.Replace("'", "\\'"); // 聚水潭爆款专区真实商家spuid,供应商直采商品该字段留空 + string price_text = RegexUtils.GetStringQuery(ref inputData, "price_text")?.Replace("'", "\\'"); + string main_cat_id = RegexUtils.GetStringQuery(ref inputData, "main_cat_id")?.Replace("'", "\\'"); + string main_cat_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "main_cat_name"))?.Replace("'", "\\'"); + string cat_id = RegexUtils.GetStringQuery(ref inputData, "cat_id"); + string cat_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "cat_name"))?.Replace("'", "\\'"); + string ext_code = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "ext_code"))?.Replace("'", "\\'"); + string product_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "product_name"))?.Replace("'", "\\'"); + string product_json = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "product_json")); + string size_json = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "size_json")); + string main_img = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "main_img"))?.Replace("'", "\\'"); + string group = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "group"))?.Replace("'", "\\'"); + string notes = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "notes"))?.Replace("'", "\\'"); + string product_get_type = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "product_get_type"))?.Replace("'", "\\'"); + int? sale_count = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "sale_count"))?.ParseToNullableInt(); + string sale_count_text = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "sale_count_text"))?.Replace("'", "\\'"); + string distribution_set = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "distribution_set"))?.Replace("'", "\\'"); + string add_user_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "add_user_name"))?.Replace("'", "\\'"); + string special_prod_type = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "special_prod_type"))?.Replace("'", "\\'"); + if (special_prod_type != "爆款数据") + special_prod_type = "普通商品"; + string view_uv = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "view_uv"))?.Replace("'", "\\'"); // 爆款数据产品曝光数量 + string add_hot_version = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "add_hot_version"))?.Replace("'", "\\'"); + if (special_prod_type == "爆款数据" && product_get_type == "微信店采" && add_hot_version != "v3") + { + return "{\"code\":666,\"msg\":\"当前版本已失效,请更新软件\"}"; + } + + if (string.IsNullOrEmpty(product_get_type)) + { + product_get_type = "母店采集"; + } + + if (string.IsNullOrEmpty(user_name)) + { + return "{\"code\":500,\"msg\":\"没有用户名\"}"; + } + if (add_user_name != null && add_user_name != "admin") + { + Thread.Sleep(1000); + } + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + + string tableName = GetProductTableName(inputData); + string sql = ""; + + if (add_user_name != null && add_user_name != "admin") + { + sql = "select count(*) from " + tableName + " where is_del=0 and add_user_name='" + add_user_name + "'"; + var count = mySql.ExecuteRowCount(sql); + if (!string.IsNullOrEmpty(mySql.Message) || count > 100000) + { + mySql.Close(); + return "{\"code\":500,\"msg\":\"产品数据库已达上限10万,请删除旧数据后重新添加新商品\"}"; + } + } + + int ban_wx = 0; + int ban_pdd = 0; + if (product_get_type == "厂商直采") + { + if (real_coid != null) + sql = "select ban_wx,ban_pdd from bxx.jst_supplier_ban_platform where coid=" + real_coid; + else if (skc_id != null) + sql = "select ban_wx,ban_pdd from bxx.jst_supplier_ban_platform where coid=" + skc_id; + var dtr = mySql.ExecuteDataTableRow(sql); + if (!string.IsNullOrEmpty(mySql.Message)) + { + mySql.Close(); + return "{\"code\":500,\"msg\":\"" + mySql.Message + "\"}"; + } + else if (dtr != null) + { + ban_wx = dtr["ban_wx"].ParseToInt(); + ban_pdd = dtr["ban_pdd"].ParseToInt(); + } + } + + sql = "INSERT INTO " + tableName + " ("; + sql += "from_shop_id,from_shop_name,offline_supplier_id,offline_supplier_name,spu_id,skc_id,real_coid,real_spu_id,main_cat_id,main_cat_name,cat_id,"; + sql += "cat_name,price_text,product_name,ext_code,main_img,product_json,size_json,notes,product_get_type,"; + if (sale_count != null) + { + sql += "sale_count,"; + } + sql += "sale_count_text,special_prod_type,"; + sql += "distribution_set,ban_wx,ban_pdd,add_time,mdy_time,"; + if (add_user_name != null) + sql += "add_user_name,"; + if (group != null) + sql += "`group`,"; + if (!string.IsNullOrWhiteSpace(view_uv)) + sql += "view_uv,"; + sql = sql.TrimEnd(','); + sql += ") "; + sql += "values ('" + from_shop_id + "','" + from_shop_name + "','" + offline_supplier_id + "','" + offline_supplier_name + "','" + spu_id + "','" + + skc_id + "','" + real_coid + "','" + real_spu_id + "','" + main_cat_id + "','" + main_cat_name + "','" + cat_id + "','" + cat_name + "','" + + price_text + "','" + product_name + "','" + ext_code + "','" + main_img + "',@product_json,@size_json,'" + notes + "','" + product_get_type + "',"; + if (sale_count != null) + { + sql += "'" + sale_count + "',"; + } + sql += "'" + sale_count_text + "','" + special_prod_type + "'," + distribution_set.ParseToInt() + "," + ban_wx + "," + ban_pdd + ","; + sql += "'" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "',"; + sql += "'" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "',"; + if (add_user_name != null) + sql += "'" + add_user_name + "',"; + if (group != null) + sql += "'" + group + "',"; + if (!string.IsNullOrWhiteSpace(view_uv)) + sql += "" + view_uv + ","; + sql = sql.TrimEnd(','); + sql += ");"; + + List paramLst = new List(); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "product_json", Value = product_json, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "size_json", Value = size_json, }); + var rst = mySql.ExecuteNonQuery(sql, paramLst.ToArray()); + mySql.Close(); + if (rst) + { + return "{\"code\":200,\"msg\":\"success\"}"; + } + else + { + return "{\"code\":500,\"msg\":\"" + mySql.Message + "\"}"; + } + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + public string MdyProduct(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + var time = 0; + int.TryParse(RegexUtils.GetStringQuery(ref inputData, "time"), out time); + string time1 = RegexUtils.GetStringQuery(ref inputData, "code"); + if (time1 != EncrypUtil.Encryption(time)) + return "{\"code\":50000,\"msg\":\"校验失败\"}"; + + string user_name = RegexUtils.GetStringQuery(ref inputData, "user_name")?.Replace("'", "\\'"); + string from_shop_id = RegexUtils.GetStringQuery(ref inputData, "from_shop_id")?.Replace("'", "\\'"); + string from_shop_name = RegexUtils.GetStringQuery(ref inputData, "from_shop_name")?.Replace("'", "\\'"); + string offline_supplier_id = RegexUtils.GetStringQuery(ref inputData, "offline_supplier_id")?.Replace("'", "\\'"); + string offline_supplier_name = RegexUtils.GetStringQuery(ref inputData, "offline_supplier_name")?.Replace("'", "\\'"); + string spu_id = RegexUtils.GetStringQuery(ref inputData, "spu_id")?.Replace("'", "\\'"); + string skc_id = RegexUtils.GetStringQuery(ref inputData, "skc_id")?.Replace("'", "\\'"); // skcId,聚水潭商品为coid + string real_coid = RegexUtils.GetStringQuery(ref inputData, "real_coid")?.Replace("'", "\\'"); // 聚水潭爆款专区真实商家coid,供应商直采商品该字段留空 + string real_spu_id = RegexUtils.GetStringQuery(ref inputData, "real_spu_id")?.Replace("'", "\\'"); // 聚水潭爆款专区真实商家spuid,供应商直采商品该字段留空 + string secret_spu_id = RegexUtils.GetStringQuery(ref inputData, "secret_spu_id")?.Replace("'", "\\'"); + string price_text = RegexUtils.GetStringQuery(ref inputData, "price_text")?.Replace("'", "\\'"); + string main_cat_id = RegexUtils.GetStringQuery(ref inputData, "main_cat_id")?.Replace("'", "\\'"); + string main_cat_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "main_cat_name"))?.Replace("'", "\\'"); + string cat_id = RegexUtils.GetStringQuery(ref inputData, "cat_id")?.Replace("'", "\\'"); + string cat_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "cat_name"))?.Replace("'", "\\'"); + string ext_code = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "ext_code"))?.Replace("'", "\\'"); + string product_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "product_name"))?.Replace("'", "\\'"); + string product_json = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "product_json")); + string size_json = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "size_json")); + string main_img = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "main_img"))?.Replace("'", "\\'"); + string group = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "group"))?.Replace("'", "\\'"); + string notes = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "notes"))?.Replace("'", "\\'"); + int? sale_count = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "sale_count"))?.ParseToNullableInt(); + string sale_count_text = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "sale_count_text"))?.Replace("'", "\\'"); + string wx_safe_status = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "wx_safe_status"))?.Replace("'", "\\'"); + string special_prod_type = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "special_prod_type"))?.Replace("'", "\\'"); + if (!string.IsNullOrEmpty(special_prod_type) && special_prod_type != "爆款数据") + special_prod_type = "普通商品"; + string wx_cat_1 = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "wx_cat_1"))?.Replace("'", "\\'"); + string wx_cat_2 = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "wx_cat_2"))?.Replace("'", "\\'"); + string wx_cat_3 = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "wx_cat_3"))?.Replace("'", "\\'"); + string wx_cat_leaf = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "wx_cat_leaf"))?.Replace("'", "\\'"); + string delivery_fee_set = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "delivery_fee_set"))?.Replace("'", "\\'"); + string after_sale_set = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "after_sale_set"))?.Replace("'", "\\'"); + string distribution_set = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "distribution_set"))?.Replace("'", "\\'"); + string send_to_out_server = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "send_to_out_server"))?.Replace("'", "\\'"); + string sku_edit_json = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "sku_edit_json"))?.Replace("'", "\\'"); + string sku_secret_json = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "sku_secret_json"))?.Replace("'", "\\'"); + string wx_img_map_json = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "wx_img_map_json"))?.Replace("'", "\\'"); + string problem_prod_data = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "problem_prod_data"))?.Replace("'", "\\'"); + string is_relation = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "is_relation"))?.Replace("'", "\\'"); + string view_uv = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "view_uv"))?.Replace("'", "\\'"); // 产品曝光数量 + string product_get_type = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "product_get_type"))?.Replace("'", "\\'"); + string add_hot_version = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "add_hot_version"))?.Replace("'", "\\'"); + if (special_prod_type == "爆款数据" && product_get_type == "微信店采" && add_hot_version != "v3") + { + return "{\"code\":666,\"msg\":\"当前版本已失效,请更新软件\"}"; + } + + if (string.IsNullOrEmpty(user_name)) + { + return "{\"code\":500,\"msg\":\"没有用户名\"}"; + } + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + + string tableName = GetProductTableName(inputData); + string sql = ""; + + sql = "update " + tableName + " p set"; + if (from_shop_id != null) + sql += " p.from_shop_id='" + from_shop_id + "',"; + if (from_shop_name != null) + sql += " p.from_shop_name='" + from_shop_name + "',"; + if (offline_supplier_id != null) + sql += " p.offline_supplier_id='" + offline_supplier_id + "',"; + if (offline_supplier_name != null) + sql += " p.offline_supplier_name='" + offline_supplier_name + "',"; + if (main_cat_id != null) + sql += " p.main_cat_id='" + main_cat_id + "',"; + if (main_cat_name != null) + sql += " p.main_cat_name='" + main_cat_name + "',"; + if (cat_id != null) + sql += " p.cat_id='" + cat_id + "',"; + if (cat_name != null) + sql += " p.cat_name='" + cat_name + "',"; + if (price_text != null) + sql += " p.price_text='" + price_text + "',"; + if (product_name != null) + sql += " p.product_name='" + product_name + "',"; + if (ext_code != null) + sql += " p.ext_code='" + ext_code + "',"; + if (secret_spu_id != null) + sql += " p.secret_spu_id='" + secret_spu_id + "',"; + if (main_img != null) + sql += " p.main_img='" + main_img + "',"; + if (product_json != null) + sql += " p.product_json=@product_json,"; + if (size_json != null) + sql += " p.size_json=@size_json,"; + if (group != null) + sql += " p.group='" + group + "',"; + if (notes != null) + sql += " p.notes='" + notes + "',"; + if (sale_count != null) + sql += " p.sale_count='" + sale_count + "',"; + if (sale_count_text != null) + sql += " p.sale_count_text='" + sale_count_text + "',"; + if (wx_safe_status != null) + sql += " p.wx_safe_status='" + wx_safe_status + "',"; + if (special_prod_type != null && special_prod_type != "") + sql += " p.special_prod_type='" + special_prod_type + "',"; + if (wx_cat_1 != null) + sql += " p.wx_cat_1=" + wx_cat_1 + ","; + if (wx_cat_2 != null) + sql += " p.wx_cat_2=" + wx_cat_2 + ","; + if (wx_cat_3 != null) + sql += " p.wx_cat_3=" + wx_cat_3 + ","; + if (wx_cat_leaf != null) + sql += " p.wx_cat_leaf=" + wx_cat_leaf + ","; + if (delivery_fee_set != null) + sql += " p.delivery_fee_set=" + delivery_fee_set + ","; + if (after_sale_set != null) + sql += " p.after_sale_set=" + after_sale_set + ","; + if (distribution_set != null) + sql += " p.distribution_set=" + distribution_set + ","; + if (send_to_out_server != null) + sql += " p.send_to_out_server=" + send_to_out_server + ","; + if (sku_edit_json != null) + sql += " p.sku_edit_json='" + sku_edit_json + "',"; + if (sku_secret_json != null) + sql += " p.sku_secret_json=@sku_secret_json,"; + if (wx_img_map_json != null) + sql += " p.wx_img_map_json=@wx_img_map_json,"; + if (!problem_prod_data.IsNullOrEmpty()) + sql += " p.problem_prod_data=" + problem_prod_data + ","; + if (!is_relation.IsNullOrEmpty()) + sql += " p.is_relation=" + is_relation + ","; + if (!string.IsNullOrWhiteSpace(view_uv)) + sql += " p.view_uv=" + view_uv + ","; + sql += " p.mdy_time='" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "',"; + sql = sql.TrimEnd(','); + sql += " where spu_id='" + spu_id + "';"; + + List paramLst = new List(); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "product_json", Value = product_json, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "size_json", Value = size_json, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "sku_secret_json", Value = sku_secret_json, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "wx_img_map_json", Value = wx_img_map_json, }); + + var rst = mySql.ExecuteNonQuery(sql, paramLst.ToArray()); + mySql.Close(); + if (rst) + { + return "{\"code\":200,\"msg\":\"success\"}"; + } + else + { + return "{\"code\":500,\"msg\":\"" + mySql.Message + "\"}"; + } + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + /// + /// 违规商品 + /// + /// + /// + public string MdyViolationProd(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + var time = 0; + int.TryParse(RegexUtils.GetStringQuery(ref inputData, "time"), out time); + string time1 = RegexUtils.GetStringQuery(ref inputData, "code"); + if (time1 != EncrypUtil.Encryption(time)) + return "{\"code\":50000,\"msg\":\"校验失败\"}"; + + string user_name = RegexUtils.GetStringQuery(ref inputData, "user_name")?.Replace("'", "\\'"); + if (string.IsNullOrEmpty(user_name)) + { + return "{\"code\":500,\"msg\":\"没有用户名\"}"; + } + + string product_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "product_name"))?.Replace("'", "\\'"); + string secret_spu_id = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "secret_spu_id"))?.Replace("'", "\\'"); + string spu_id = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "spu_id"))?.Replace("'", "\\'"); + + string group = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "group"))?.Replace("'", "\\'"); + string notes = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "notes"))?.Replace("'", "\\'"); + string wx_safe_status = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "wx_safe_status"))?.Replace("'", "\\'"); + if (string.IsNullOrWhiteSpace(product_name) && string.IsNullOrWhiteSpace(secret_spu_id) && string.IsNullOrWhiteSpace(spu_id)) + return "{\"code\":500,\"msg\":\"没有商品查询信息\"}"; + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + + string tableName = GetProductTableName(inputData); + string sql = ""; + + if (!string.IsNullOrEmpty(product_name)) + sql = "select id,spu_id from " + tableName + " p where p.product_name='" + product_name + "' and p.wx_safe_status in ('安全商品','未校验');"; + else if (!string.IsNullOrEmpty(secret_spu_id)) + sql = "select id,spu_id from " + tableName + " p where p.secret_spu_id='" + secret_spu_id + "' and p.wx_safe_status in ('安全商品','未校验');"; + else + sql = "select id,spu_id from " + tableName + " p where p.spu_id='" + spu_id + "' and p.wx_safe_status in ('安全商品','未校验');"; + + + var dt = mySql.ExecuteDataTable(sql); + if (!string.IsNullOrEmpty(mySql.Message)) + { + mySql.Close(); + return "{\"code\":500,\"msg\":\"" + mySql.Message + "\"}"; + } + var ids = ""; + foreach(DataRow row in dt.Rows) + { + ids += row["spu_id"].ParseToString() + "','"; + } + ids.Trim(',', '\''); + if (string.IsNullOrEmpty(ids)) + { + return "{\"code\":200,\"msg\":\"success\",\"err_msg\":\"商品不存在\"}"; + } + else + { + sql = "update " + tableName + " p set"; + if (group != null) + sql += " p.group='" + group + "',"; + if (notes != null) + sql += " p.notes='" + notes + "',"; + if (wx_safe_status != null) + sql += " p.wx_safe_status='" + wx_safe_status + "',"; + sql += " p.mdy_time='" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "',"; + sql = sql.TrimEnd(','); + sql += " where p.spu_id in('" + ids + "')"; + + + + 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 MdyBestSaleProd(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + var time = 0; + int.TryParse(RegexUtils.GetStringQuery(ref inputData, "time"), out time); + string time1 = RegexUtils.GetStringQuery(ref inputData, "code"); + if (time1 != EncrypUtil.Encryption(time)) + return "{\"code\":50000,\"msg\":\"校验失败\"}"; + + string user_name = RegexUtils.GetStringQuery(ref inputData, "user_name")?.Replace("'", "\\'"); + if (string.IsNullOrEmpty(user_name)) + { + return "{\"code\":500,\"msg\":\"没有用户名\"}"; + } + + string spu_id = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "spu_id"))?.Replace("'", "\\'"); + int? view_uv = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "view_uv"))?.ParseToNullableInt(); + if (view_uv == null || string.IsNullOrWhiteSpace(spu_id)) + return "{\"code\":500,\"msg\":\"缺少商品曝光率或编号信息\"}"; + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + + string tableName = GetProductTableName(inputData); + string sql = ""; + + sql = "update " + tableName + " p set"; + if (view_uv != null) + sql += " p.view_uv=" + view_uv + ","; + sql += " p.mdy_time='" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "',"; + sql = sql.TrimEnd(','); + sql += " where p.spu_id='" + spu_id + "' and p.special_prod_type='爆款数据'"; + + 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\":\"输入为空\"}"; + } + + /// + /// 获取商品SpuId(快速查询) + /// + /// + /// + public string GetProductSpuIdLst(string inputData) + { + var timeCalc = DateTime.Now; + 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 version = RegexUtils.GetStringQuery(ref inputData, "version").ParseToInt(); + if (version < (System.Configuration.ConfigurationManager.ConnectionStrings["LimitVersion"]?.ConnectionString).ParseToInt()) + return "{\"code\":1,\"msg\":\"当前版本过于陈旧,请立即升级新版\"}"; + + var user_name = RegexUtils.GetStringQuery(ref inputData, "user_name")?.Replace("'", "\\'"); + var password = RegexUtils.GetStringQuery(ref inputData, "password")?.Replace("'", "\\'"); + var search_secret_spu_ids = RegexUtils.GetStringQuery(ref inputData, "search_secret_spu_ids")?.Replace("'", "\\'"); + var search_spu_ids = RegexUtils.GetStringQuery(ref inputData, "search_spu_ids")?.Replace("'", "\\'"); + var wx_safe_status = RegexUtils.GetStringQuery(ref inputData, "wx_safe_status")?.Replace("'", "\\'"); + + int page = RegexUtils.GetStringQuery(ref inputData, "page").ParseToInt(); + int page_size = RegexUtils.GetStringQuery(ref inputData, "page_size").ParseToInt(500); + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + + string tableName = GetProductTableName(inputData); + string sql = ""; + + sql = "select id,spu_id,secret_spu_id from " + tableName + " p where p.is_del=0"; + if (search_secret_spu_ids != null) + { + sql += " and p.secret_spu_id in ('" + string.Join("','", search_secret_spu_ids.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries)) + "')"; + } + if (search_spu_ids != null) + { + sql += " and p.spu_id in ('" + string.Join("','", search_spu_ids.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries)) + "')"; + } + if (wx_safe_status != null) + { + sql += " and p.wx_safe_status in ('" + string.Join("','", wx_safe_status.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries)) + "')"; + } + var dt = mySql.ExecuteDataTable(sql); + + mySql.Close(); + if (dt != null) + { + try + { + List productLst = new List(); + foreach (DataRow row in dt.Rows) + { + DBProductResultParamLite prod = new DBProductResultParamLite + { + id = Convert.ToInt32(row["id"]), + spu_id = row["spu_id"].ToString(), + secret_spu_id = row["secret_spu_id"].IsNullOrEmpty() ? null : row["secret_spu_id"].ParseToString(), + }; + productLst.Add(prod); + } + JsonSerializerSettings jsonSetting = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }; + var data = JsonUtils.SerializeObjectToString(productLst, jsonSetting); + var seconds = (DateTime.Now - timeCalc).TotalSeconds.ToString("0.000"); + return "{\"code\":200,\"msg\":\"success\",\"data\":" + data + ",\"count\":" + productLst.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 GetProductList(string inputData, bool isDetail = false) + { + var timeCalc = DateTime.Now; + 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 version = RegexUtils.GetStringQuery(ref inputData, "version").ParseToInt(); + if (version < (System.Configuration.ConfigurationManager.ConnectionStrings["LimitVersion"]?.ConnectionString).ParseToInt()) + return "{\"code\":1,\"msg\":\"当前版本过于陈旧,请立即升级新版\"}"; + + var user_name = RegexUtils.GetStringQuery(ref inputData, "user_name")?.Replace("'","\\'"); + var password = RegexUtils.GetStringQuery(ref inputData, "password")?.Replace("'", "\\'"); + var search_spu = RegexUtils.GetStringQuery(ref inputData, "search_spu")?.Replace("'", "\\'"); + var search_skc = RegexUtils.GetStringQuery(ref inputData, "search_skc")?.Replace("'", "\\'"); + var search_cat1 = RegexUtils.GetStringQuery(ref inputData, "search_cat1")?.Replace("'", "\\'"); + var search_cat = RegexUtils.GetStringQuery(ref inputData, "search_cat")?.Replace("'", "\\'"); + var wx_cat_1 = RegexUtils.GetStringQuery(ref inputData, "wx_cat_1")?.Replace("'", "\\'"); + var wx_cat_2 = RegexUtils.GetStringQuery(ref inputData, "wx_cat_2")?.Replace("'", "\\'"); + var wx_cat_3 = RegexUtils.GetStringQuery(ref inputData, "wx_cat_3")?.Replace("'", "\\'"); + var wx_cat_leaf = RegexUtils.GetStringQuery(ref inputData, "wx_cat_leaf")?.Replace("'", "\\'"); + var search_ext_code = RegexUtils.GetStringQuery(ref inputData, "search_ext_code")?.Replace("'", "\\'"); + var search_prod_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "search_prod_name"))?.Replace("'", "\\'"); + var search_prod_name_in = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "search_prod_name_in"))?.Replace("'", "\\'"); + var search_group = RegexUtils.GetStringQuery(ref inputData, "search_group")?.Replace("'", "\\'"); + var search_notes = RegexUtils.GetStringQuery(ref inputData, "search_notes")?.Replace("'", "\\'"); + var search_db_ids = RegexUtils.GetStringQuery(ref inputData, "search_db_ids")?.Replace("'", "\\'"); + var search_secret_spu_ids = RegexUtils.GetStringQuery(ref inputData, "search_secret_spu_ids")?.Replace("'", "\\'"); + var ext_code_in = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "ext_code_in"))?.Replace("'", "\\'"); + var get_select_count = RegexUtils.GetStringQuery(ref inputData, "get_select_count")?.Replace("'", "\\'"); + var select_shop_id = RegexUtils.GetStringQuery(ref inputData, "select_shop_id")?.Replace("'", "\\'"); + var from_shop_id = RegexUtils.GetStringQuery(ref inputData, "from_shop_id")?.Replace("'", "\\'"); + var from_shop_name = RegexUtils.GetStringQuery(ref inputData, "from_shop_name")?.Replace("'", "\\'"); + var product_get_type = RegexUtils.GetStringQuery(ref inputData, "product_get_type")?.Replace("'", "\\'"); + var sort_field = RegexUtils.GetStringQuery(ref inputData, "sort_field")?.Replace("'", "\\'"); + var wx_safe_status = RegexUtils.GetStringQuery(ref inputData, "wx_safe_status")?.Replace("'", "\\'"); + var special_prod_type = RegexUtils.GetStringQuery(ref inputData, "special_prod_type")?.Replace("'", "\\'"); + if (special_prod_type.IsNullOrEmpty()) + special_prod_type = "普通商品"; + var is_supplier_prod_ok = RegexUtils.GetStringQuery(ref inputData, "is_supplier_prod_ok")?.Replace("'", "\\'"); + var has_wx_cat = RegexUtils.GetStringQuery(ref inputData, "has_wx_cat")?.Replace("'", "\\'"); + var send_to_out_server = RegexUtils.GetStringQuery(ref inputData, "send_to_out_server")?.Replace("'", "\\'"); + var real_coid = RegexUtils.GetStringQuery(ref inputData, "real_coid")?.Replace("'", "\\'"); + var has_wx_format = RegexUtils.GetStringQuery(ref inputData, "has_wx_format")?.Replace("'", "\\'"); + var problem_prod_data = RegexUtils.GetStringQuery(ref inputData, "problem_prod_data")?.Replace("'", "\\'"); + var is_relation = RegexUtils.GetStringQuery(ref inputData, "is_relation")?.Replace("'", "\\'"); + var add_time_begin = RegexUtils.GetStringQuery(ref inputData, "add_time_begin")?.Replace("'", "\\'"); + var add_time_end = RegexUtils.GetStringQuery(ref inputData, "add_time_end")?.Replace("'", "\\'"); + var start_time = RegexUtils.GetStringQuery(ref inputData, "start_time")?.Replace("'", "\\'"); + var end_time = RegexUtils.GetStringQuery(ref inputData, "end_time")?.Replace("'", "\\'"); + var ban_wx = RegexUtils.GetStringQuery(ref inputData, "ban_wx")?.Replace("'", "\\'"); + var ban_pdd = RegexUtils.GetStringQuery(ref inputData, "ban_pdd")?.Replace("'", "\\'"); + var add_user_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "add_user_name"))?.Replace("'", "\\'"); + var min_view_uv = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "min_view_uv"))?.ParseToNullableInt(); + var is_not_count = RegexUtils.GetStringQuery(ref inputData, "is_not_count") == "true"; // 不计数 + var no_fission_words = RegexUtils.GetStringQuery(ref inputData, "no_fission_words").ParseToBool(); // 未裂变标题 + var fission_words = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "fission_words"))?.Replace("'", "\\'"); + + int page = RegexUtils.GetStringQuery(ref inputData, "page").ParseToInt(); + int page_size= RegexUtils.GetStringQuery(ref inputData, "page_size").ParseToInt(50); + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + + string tableName = GetProductTableName(inputData); + string sql = ""; + List forceIndex = new List() { }; + if (!isDetail) + { + if (!search_prod_name.IsNullOrEmpty() || !search_prod_name_in.IsNullOrEmpty()) + forceIndex.Add("index_product_name"); + if (!search_spu.IsNullOrEmpty()) + forceIndex.Add("index_spu_id"); + if (!search_skc.IsNullOrEmpty()) + forceIndex.Add("index_skc_id"); + if (!search_secret_spu_ids.IsNullOrEmpty()) + forceIndex.Add("index_secret_spu_id"); + if (min_view_uv > 0) + forceIndex.Add("index_view_uv"); + if (!search_group.IsNullOrEmpty()) + forceIndex.Add("index_group"); + if (!from_shop_id.IsNullOrEmpty()) + forceIndex.Add("index_from_shop_id"); + if (!from_shop_name.IsNullOrEmpty()) + forceIndex.Add("index_from_shop_name"); + if (!ext_code_in.IsNullOrEmpty() || !search_ext_code.IsNullOrEmpty()) + forceIndex.Add("index_ext_code"); + //if (!add_user_name.IsNullOrEmpty()) + // forceIndex.Add("index_add_user_name"); + if (!search_notes.IsNullOrEmpty()) + forceIndex.Add("index_notes"); + if (!start_time.IsNullOrEmpty()) + forceIndex.Add("index_mdy_time"); + + if (!forceIndex.Contains("index_view_uv")) + forceIndex.Add("index_sort_add_time"); + } + + List paramLst = new List(); + + sql = " select count(*) from " + tableName + " p "; + //sql += " LEFT JOIN bxx.jst_supplier_ban_platform b ON (p.skc_id=b.coid or p.real_coid=b.coid)" + + if (forceIndex.Count > 0) + sql += " FORCE INDEX(" + string.Join(",", forceIndex) + ")"; + sql += " WHERE p.is_del=0"; + + string where = ""; + if (!string.IsNullOrEmpty(from_shop_id)) + where += " and p.from_shop_id='" + from_shop_id + "'"; + if (!string.IsNullOrEmpty(from_shop_name)) + where += " and p.from_shop_name='" + from_shop_name + "'"; + if (!string.IsNullOrEmpty(search_db_ids)) + where += " and p.id in (" + search_db_ids + ")"; + if (!string.IsNullOrEmpty(search_secret_spu_ids)) + where += " and p.secret_spu_id in ('" + string.Join("','", search_secret_spu_ids.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries)) + "')"; + if (!string.IsNullOrWhiteSpace(ext_code_in)) + where += " and p.ext_code in ('" + string.Join("','", ext_code_in.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries)) + "')"; + if (!string.IsNullOrEmpty(product_get_type)) + where += " and p.product_get_type in ('" + product_get_type.Replace(",", "','") + "')"; + else + where += " and p.product_get_type in ('厂商直采','1688厂家','1688外部数据','微信小店','微信店采','母店采集','机会商品','以图搜品','多多外部数据')"; + if (!string.IsNullOrEmpty(wx_safe_status)) + where += " and p.wx_safe_status in ('" + wx_safe_status.Replace(",", "','") + "')"; + if (!string.IsNullOrEmpty(special_prod_type)/* && special_prod_type != "普通商品,爆款数据"*/) + where += " and p.special_prod_type in ('" + special_prod_type.Replace(",", "','") + "')"; + + if (!string.IsNullOrWhiteSpace(search_spu)) + { + if (search_spu.Contains(",") || search_spu.Contains(",") || search_spu.Contains(";") || search_spu.Contains(";")) + where += " and p.spu_id in ('" + string.Join("','", search_spu.Split(new string[] { ",", ",", ";", ";" }, StringSplitOptions.RemoveEmptyEntries)) + "')"; + else + where += " and p.spu_id like '" + search_spu + "%'"; + } + if (!string.IsNullOrWhiteSpace(search_skc)) + where += " and p.skc_id like '" + search_skc + "%'"; + if (!string.IsNullOrWhiteSpace(search_cat)) + where += " and p.cat_name like '" + search_cat + "%'"; + if (!string.IsNullOrWhiteSpace(search_cat1)) + where += " and p.main_cat_name like '" + search_cat1 + "%'"; + if (!string.IsNullOrWhiteSpace(search_ext_code)) + where += " and p.ext_code like '" + search_ext_code + "%'"; + if (!string.IsNullOrWhiteSpace(search_prod_name)) + { + var searchProdNameWords = search_prod_name.Split(new string[] { ",", ",", ";", ";", "\r", "\n" }, StringSplitOptions.RemoveEmptyEntries); + var multi_search_prod_name = ""; + var index = 0; + foreach (var word in searchProdNameWords) + { + index++; + string parameName = "@prodNameWords" + index; + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = parameName, Value = word/*.Replace("&", "&").Replace("'", "\\'")*/, }); + //multi_search_prod_name += " or p.product_name like '%" + parameName + "%'"; + //multi_search_prod_name += " or p.product_name like CONCAT('%'," + parameName + ",'%')"; + multi_search_prod_name += " or p.product_name like CONCAT(" + parameName + ",'%')"; + + } + where += " and (" + multi_search_prod_name.Substring(4) + ")"; + + //where += " and p.product_name like '" + search_prod_name + "'"; + } + if (!string.IsNullOrWhiteSpace(search_prod_name_in)) + { + where += " and p.product_name in ('" + search_prod_name_in.Replace(",", "','") + "')"; + } + if (!string.IsNullOrWhiteSpace(search_group)) + { + if (search_group == "无分组") + where += " and (p.group is null or p.group = '')"; + else + where += " and p.group like '" + search_group + "%'"; + } + if (!string.IsNullOrWhiteSpace(search_notes)) + where += " and p.notes like '" + search_notes + "%'"; + + if (!string.IsNullOrWhiteSpace(wx_cat_1)) + where += " and p.wx_cat_1 in (" + wx_cat_1 + ")"; + if (!string.IsNullOrWhiteSpace(wx_cat_2)) + where += " and p.wx_cat_2 in (" + wx_cat_2 + ")"; + if (!string.IsNullOrWhiteSpace(wx_cat_3)) + where += " and p.wx_cat_3 in (" + wx_cat_3 + ")"; + if (!string.IsNullOrWhiteSpace(wx_cat_leaf)) + where += " and p.wx_cat_leaf in (" + wx_cat_leaf + ")"; + + if (!string.IsNullOrEmpty(has_wx_cat)) + { + if (has_wx_cat.ToLower() == "true") + where += " and p.wx_cat_3 >= 0"; + else + where += " and p.wx_cat_3 IS NULL"; + } + if (!string.IsNullOrEmpty(send_to_out_server)) + where += " and p.send_to_out_server in (" + send_to_out_server + ")"; + // 供应商货源是否已完成初始设置 + if (!string.IsNullOrEmpty(is_supplier_prod_ok)) + { + //if (is_supplier_prod_ok == "1" || is_supplier_prod_ok == "已设置") + // where += " and wx_cat_leaf IS NOT NULL and send_to_out_server=1 and delivery_fee_set=1 and after_sale_set=1 and distribution_set=1"; + //else + // where += " and (wx_cat_leaf IS NULL or send_to_out_server=0 or delivery_fee_set=0 or after_sale_set=0 or distribution_set=0)"; + if (is_supplier_prod_ok == "1" || is_supplier_prod_ok == "是" || is_supplier_prod_ok == "已设置") + where += " and p.wx_cat_3 IS NOT NULL and p.send_to_out_server IN (1,127) and p.distribution_set IN (1,127)"; + else + where += " and (p.wx_cat_3 IS NULL or p.send_to_out_server NOT IN (1,127) or p.distribution_set NOT IN (1,127))"; + } + if (!where.Contains("send_to_out_server")) + { + where += " and p.send_to_out_server IN (0,1,2,127)"; + } + if (!where.Contains("distribution_set")) + { + where += " and p.distribution_set IN (0,1,2,127)"; + } + + if (!string.IsNullOrEmpty(real_coid)) + { + where += " and p.real_coid='" + real_coid + "'"; + } + if (!string.IsNullOrEmpty(has_wx_format)) + { + where += " and p.has_wx_format='" + has_wx_format + "'"; + } + if (!string.IsNullOrEmpty(problem_prod_data)) + { + if (problem_prod_data.ToLower().Contains("is null")) + where += " and p.problem_prod_data " + problem_prod_data; + else + where += " and p.problem_prod_data='" + problem_prod_data + "'"; + } + if (!string.IsNullOrEmpty(is_relation)) + { + where += " and p.is_relation=" + is_relation; + } + if (add_time_begin != null && add_time_end != null) + { + where += " and p.add_time between '" + add_time_begin + "' and '" + add_time_end + "'"; + } + if (start_time != null && end_time != null) + { + where += " and p.mdy_time between '" + start_time + "' and '" + end_time + "'"; + } + if (ban_wx != null) + { + where += " and p.ban_wx=" + ban_wx; + } + else + { + where += " and p.ban_wx in (0,1)"; + } + if (ban_pdd != null) + { + where += " and p.ban_pdd=" + ban_pdd; + } + else + { + where += " and p.ban_pdd in (0,1)"; + } + if (min_view_uv != null) + { + where += " and p.view_uv>=" + min_view_uv; + } + if (!string.IsNullOrEmpty(add_user_name)) + { + add_user_name = "'" + string.Join("','", add_user_name.Split(new string[] { ",", ",", " " }, StringSplitOptions.RemoveEmptyEntries)) + "'"; + where += " and p.add_user_name in (" + add_user_name + ")"; + } + else + { + // 目前客户端即使是自有库查详情的时候也有没传 todo 每次查询都传参,或者就不管,详情会命中其他索引 + //where += " and p.add_user_name='admin'"; + } + if (no_fission_words) + { + where += " and (fission_words='' or fission_words IS NULL)"; + } + if (!string.IsNullOrEmpty(fission_words)) + { + where += " and fission_words LIKE '" + fission_words + "%'"; + } + sql += where; + + var count = 0; + if (isDetail || is_not_count) + count = 1; + else + { + count = mySql.ExecuteRowCount(sql, paramLst.ToArray()); + } + + DataTable dt; + if (count == 0) + { + dt = new DataTable(); + } + else + { + sql = " SELECT p.id " + + " FROM " + tableName + " p"; + if (forceIndex.Count > 0) + sql += " FORCE INDEX(" + string.Join(",", forceIndex) + ")"; + sql += " WHERE p.is_del=0"; + + //where子句 + sql += where; + + if (sort_field == "view_uv") + sql += " order by p.view_uv desc, p.add_time desc"; + else + sql += " order by p.add_time desc"; + sql += " limit " + Math.Max(page - 1, 0) * page_size + "," + page_size; + dt = mySql.ExecuteDataTable(sql, paramLst.ToArray()); + + if (!string.IsNullOrEmpty(mySql.Message) || dt == null) + { + mySql.Close(); + return "{\"code\":500,\"msg\":\"" + mySql.Message + "\",\"data\":[],\"count\":" + 0 + "}"; + } + var db_ids = string.Join(",", dt.Rows.Cast().Select(r => r["id"].ParseToInt())); + if (string.IsNullOrEmpty(db_ids)) + { + mySql.Close(); + return "{\"code\":200,\"data\":[],\"count\":" + 0 + "}"; + } + + + if (isDetail) + sql = " SELECT p.*" + + " from " + tableName + " p" + + " where p.is_del=0"; + else + sql = "SELECT p.id,p.from_shop_id,p.spu_id,p.skc_id,p.main_cat_id,p.main_cat_name,p.cat_id,p.cat_name,p.price_text,p.ext_code,p.product_name," + + " p.main_img,p.notes,p.add_time,p.mdy_time,p.fission_words,p.head_words,p.end_words,p.group," + + " p.product_get_type,p.wx_safe_status,p.sale_count,p.sale_count_text,p.special_prod_type,p.from_shop_name,p.wx_cat_1,p.wx_cat_2,p.wx_cat_3," + + " p.wx_cat_leaf,p.send_to_out_server,p.secret_spu_id,p.real_coid,p.real_spu_id,p.is_relation,p.view_uv,p.add_user_name" + + " FROM " + tableName + " p" + + " WHERE p.is_del=0"; + + sql += " and id in (" + db_ids + ")"; + dt = mySql.ExecuteDataTable(sql, paramLst.ToArray()); + } + + mySql.Close(); + if (dt != null) + { + try + { + List productLst = new List(); + foreach (DataRow row in dt.Rows) + { + DBProductResultParam prod = new DBProductResultParam + { + id = Convert.ToInt32(row["id"]), + from_shop_id = row["from_shop_id"].ToString(), + from_shop_name = row["from_shop_name"].ToString(), + //offline_supplier_id = row["offline_supplier_id"].ToString(), + //offline_supplier_name = row["offline_supplier_name"].ToString(), + skc_id = row["skc_id"].ToString(), + spu_id = row["spu_id"].ToString(), + cat_id = row["cat_id"].ToString(), + cat_name = row["cat_name"].ToString(), + wx_cat_1 = row["wx_cat_1"].ToString(), + wx_cat_2 = row["wx_cat_2"].ToString(), + wx_cat_3 = row["wx_cat_3"].ToString(), + wx_cat_leaf = row["wx_cat_leaf"].ToString(), + product_name = row["product_name"].ToString(), + main_img = row["main_img"].ToString(), + ext_code = row["ext_code"].ToString(), + //ext_code_price = row["ext_code_price"].IsNullOrEmpty() ? new int?() : row["ext_code_price"].ParseToInt(), + price_text = row["price_text"].ToString(), + //product_json = row["product_json"].ToString(), + //size_json = row["size_json"].ToString(), + add_time = Convert.ToDateTime(row["add_time"]), + mdy_time = Convert.ToDateTime(row["mdy_time"]), + notes = row["notes"].ToString(), + group = row["group"].ToString(), + //select_total_count = row["select_total_count"].ParseToInt(), + end_words = row["end_words"].ParseToString(), + fission_words = row["fission_words"].ParseToString(), + head_words = row["head_words"].ParseToString(), + product_get_type_text = row["product_get_type"].ToString(), + view_uv = row["view_uv"].ParseToNullableInt(), + sale_count = row["sale_count"].ParseToInt(), + sale_count_text = row["sale_count_text"].ToString(), + wx_safe_status = row["wx_safe_status"].ToString(), + special_prod_type = row["special_prod_type"].ToString(), + main_cat_id = row["main_cat_id"].ToString(), + main_cat_name = row["main_cat_name"].ToString(), + send_to_out_server = row["send_to_out_server"].ParseToInt(), + secret_spu_id = row["secret_spu_id"].IsNullOrEmpty() ? null : row["secret_spu_id"].ParseToString(), + real_coid = row["real_coid"].IsNullOrEmpty() ? null : row["real_coid"].ParseToString(), + real_spu_id = row["real_spu_id"].IsNullOrEmpty() ? null : row["real_spu_id"].ParseToString(), + is_relation = row["is_relation"].ParseToInt(), + add_user_name = row["add_user_name"].ParseToString(), + }; + if (isDetail) + { + prod.product_json = row["product_json"].ToString(); + prod.size_json = row["size_json"].ToString(); + prod.sku_edit_json = row["sku_edit_json"].ToString(); + prod.sku_secret_json = row["sku_secret_json"].ToString(); + prod.fission_imgs = row["fission_imgs"].ToString(); + prod.has_wx_format = row["has_wx_format"].ParseToNullableString(); // 微信回采 + prod.wx_img_map_json = row["wx_img_map_json"].ToString(); + problem_prod_data = row["problem_prod_data"].IsNullOrEmpty() ? null : row["problem_prod_data"].ParseToString(); + + if (!prod.sku_secret_json.IsNullOrEmpty() && prod.secret_spu_id.IsNullOrEmpty()) + { + var secret_json = prod.sku_secret_json; + var goodsId = RegexUtils.GetStringJson(ref secret_json, "goodsId"); + prod.secret_spu_id = goodsId; + if (!string.IsNullOrWhiteSpace(goodsId)) + { + mySql = new MysqlUtils(conn); + try + { + sql = "update " + tableName + " set secret_spu_id='" + goodsId + "' where spu_id='" + prod.spu_id + "'"; + mySql.ExecuteNonQuery(sql); + } + catch { } + mySql.Close(); + } + } + if (prod.product_json.Contains("\"source_json\"") && !prod.product_json.Contains("\"source_json\":null")) + { + mySql = new MysqlUtils(conn); + try + { + JObject jObj = JsonUtils.JObjectParse(prod.product_json); + jObj["source_json"] = null; + var newProdJson = JsonUtils.SerializeObject(jObj); + sql = "update " + tableName + " set product_json=@product_json where spu_id='" + prod.spu_id + "'"; + paramLst = new List(); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "product_json", Value = newProdJson, }); + mySql.ExecuteNonQuery(sql, paramLst.ToArray()); + prod.product_json = newProdJson; + } + catch + { + } + mySql.Close(); + } + if (prod.product_json.Contains(":null")) + { + mySql = new MysqlUtils(conn); + try + { + JObject jObj = JsonUtils.JObjectParse(prod.product_json); + + RemoveNullProperties(jObj); + + JsonSerializerSettings jsonIgnoreNullSetting = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }; + var newProdJson = JsonUtils.SerializeObjectToString(jObj, jsonIgnoreNullSetting); + + sql = "update " + tableName + " set product_json=@product_json where spu_id='" + prod.spu_id + "'"; + paramLst = new List(); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "product_json", Value = newProdJson, }); + mySql.ExecuteNonQuery(sql, paramLst.ToArray()); + prod.product_json = newProdJson; + + //sql = "DELETE FROM " + tableName + " where is_del = 1 AND add_time < '" + DateTime.Now.AddDays(-10) + "' ORDER BY add_time DESC limit 1;"; + } + catch + { + } + mySql.Close(); + } + } + if (!string.IsNullOrEmpty(get_select_count)) + { + prod.select_count = row["select_count"].ParseToInt(); + } + productLst.Add(prod); + } + JsonSerializerSettings jsonSetting = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }; + var data = JsonUtils.SerializeObjectToString(productLst, jsonSetting); + var seconds = (DateTime.Now - timeCalc).TotalSeconds.ToString("0.000"); + if (is_not_count) + count = productLst.Count; + 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\":\"输入为空\"}"; + } + + /// + /// 递归剔除JObject中值为null的字段 (修改为null才删除,empty不删除) + /// + public static void RemoveNullProperties(JToken token) + { + if (token.Type == JTokenType.Object) + { + var jObj = (JObject)token; + var propertiesToRemove = jObj.Properties() + //.Where(p => + // p.Value == null || + // p.Value.Type == JTokenType.Null || + // (p.Value.Type == JTokenType.String && string.IsNullOrEmpty((string)p.Value)) || + // (p.Value.Type == JTokenType.String && string.IsNullOrWhiteSpace((string)p.Value)) || + // (p.Value.Type == JTokenType.Array && !p.Value.HasValues)) + .Where(p => + p.Value == null || + p.Value.Type == JTokenType.Null) + .ToList(); + + foreach (var prop in propertiesToRemove) + prop.Remove(); + + foreach (var child in jObj.Children()) + { + if (child.Children().Count() > 0) + { + RemoveNullProperties(child); + } + } + } + else if (token.Type == JTokenType.Property) + { + if (token.Children().Count() > 0) + { + var childs = token.Children() + //.Where(p => + // p == null || + // p.Type == JTokenType.Null || + // (p.Type == JTokenType.String && string.IsNullOrEmpty((string)p)) || + // (p.Type == JTokenType.String && string.IsNullOrWhiteSpace((string)p)) || + // (p.Type == JTokenType.Array && !p.HasValues)) + .Where(p => + p == null || + p.Type == JTokenType.Null) + .ToList(); + + foreach (var prop in childs) + prop.Remove(); + foreach (var child in token.Children()) + { + if (child.Children().Count() > 0) + { + RemoveNullProperties(child); + } + } + } + } + else if (token.Type == JTokenType.Array) + { + var jArray = (JArray)token; + + // 清理数组内部的 null / "" + for (int i = jArray.Count - 1; i >= 0; i--) + { + var item = jArray[i]; + //if (item.Type == JTokenType.Null || + // (item.Type == JTokenType.String && string.IsNullOrWhiteSpace((string)item))) + if (item.Type == JTokenType.Null) + { + jArray.RemoveAt(i); + } + } + + // 递归数组内对象/子数组 + foreach (var child in jArray) + RemoveNullProperties(child); + + //// 如果数组最后变空,也删除 + //if (!jArray.HasValues) + //{ + // if (jArray.Parent is JProperty prop) + // prop.Remove(); + //} + } + } + + /// + /// 回采微信小店属性等商品数据入库 + /// + /// + /// + public string AddProdWXComplate(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + var timeCalc = DateTime.Now; + 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("'", "\\'"); + var password = RegexUtils.GetStringQuery(ref inputData, "password")?.Replace("'", "\\'"); + if (user_name.IsNullOrEmpty()) + { + return "{\"code\":500,\"msg\":\"用户信息不能为空\"}"; + } + + var spu_id = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "spu_id")).ParseToString().Replace("'", "\\'"); + var coid = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "coid")).ParseToString().Replace("'", "\\'"); + var secret_spu_id = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "secret_spu_id")).ParseToString().Replace("'", "\\'"); + var wx_edit_prod_json = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "wx_edit_prod_json")).ParseToString().Replace("'", "\\'"); + if (secret_spu_id.IsNullOrEmpty() || wx_edit_prod_json.IsNullOrEmpty()) + { + return "{\"code\":500,\"msg\":\"商品回采数据不能为空\"}"; + } + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + + string tableName = GetProductTableName(inputData); + tableName = "bxx.product"; // 回采只支持主库,后续可能删除回采功能 + string sql = ""; + + sql = "INSERT INTO bxx.product_wx_complate (spu_id,coid,secret_spu_id,wx_edit_prod_json) VALUES " + + " ('" + spu_id + "','" + coid + "','" + secret_spu_id + "','" + wx_edit_prod_json + "')" + + " ON DUPLICATE KEY UPDATE spu_id=VALUES(spu_id),coid=VALUES(coid),wx_edit_prod_json=VALUES(wx_edit_prod_json);"; + + var rst = mySql.ExecuteNonQuery(sql); + if (!rst || !string.IsNullOrEmpty(mySql.Message)) + { + mySql.Close(); + return "{\"code\":500,\"msg\":\"" + mySql.Message + "\"}"; + } + + sql = "UPDATE " + tableName + " set has_wx_format='1' where secret_spu_id='" + secret_spu_id + "'"; + rst = mySql.ExecuteNonQuery(sql); + mySql.Close(); + if (!rst || !string.IsNullOrEmpty(mySql.Message)) + { + return "{\"code\":500,\"msg\":\"" + mySql.Message + "\"}"; + } + else + { + var seconds = (DateTime.Now - timeCalc).TotalSeconds.ToString("0.000"); + return "{\"code\":200,\"msg\":\"success\",\"seconds\":" + seconds + "}"; + } + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + /// + /// 查询回采微信小店属性等商品数据 + /// + /// + /// + public string GetProdWXComplateList(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + var timeCalc = DateTime.Now; + 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("'", "\\'"); + var password = RegexUtils.GetStringQuery(ref inputData, "password")?.Replace("'", "\\'"); + if (user_name.IsNullOrEmpty()) + { + return "{\"code\":500,\"msg\":\"用户信息不能为空\"}"; + } + + var spu_id = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "spu_id")).ParseToString().Replace("'", "\\'"); + var coid = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "coid")).ParseToString().Replace("'", "\\'"); + var search_secret_spu_ids = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "search_secret_spu_ids")).ParseToString().Replace("'", "\\'"); + if (search_secret_spu_ids.IsNullOrEmpty()) + { + return "{\"code\":500,\"msg\":\"商品回采数据编号不能为空\"}"; + } + + int page = RegexUtils.GetStringQuery(ref inputData, "page").ParseToInt(); + int page_size = RegexUtils.GetStringQuery(ref inputData, "page_size").ParseToInt(1000); + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + + string sql = "select id,spu_id,coid,secret_spu_id,wx_edit_prod_json,add_time" + + " from bxx.product_wx_complate p where 1=1"; + if (search_secret_spu_ids != null) + { + sql += " and p.secret_spu_id in ('" + string.Join("','", search_secret_spu_ids.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries)) + "')"; + } + sql += " limit " + Math.Max(page - 1, 0) * page_size + "," + page_size; + var dt = mySql.ExecuteDataTable(sql); + + mySql.Close(); + if (dt != null) + { + try + { + JArray wxProdComplateArr = new JArray(); + foreach (DataRow row in dt.Rows) + { + JObject wxProdComplateObj = new JObject(); + wxProdComplateObj["id"] = Convert.ToInt32(row["id"]); + wxProdComplateObj["spu_id"] = row["spu_id"].ToString(); + wxProdComplateObj["coid"] = row["coid"].ToString(); + wxProdComplateObj["secret_spu_id"] = row["secret_spu_id"].ToString(); + wxProdComplateObj["wx_edit_prod_json"] = row["wx_edit_prod_json"].ToString(); + wxProdComplateObj["add_time"] = Convert.ToDateTime(row["add_time"]); + wxProdComplateArr.Add(wxProdComplateObj); + } + JsonSerializerSettings jsonSetting = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }; + var data = JsonUtils.SerializeObjectToString(wxProdComplateArr, jsonSetting); + var seconds = (DateTime.Now - timeCalc).TotalSeconds.ToString("0.000"); + return "{\"code\":200,\"msg\":\"success\",\"data\":" + data + ",\"count\":" + wxProdComplateArr.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\":\"输入为空\"}"; + } + + /// + /// 新增下架sku + /// + /// + /// + public string AddProdDownSku(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("'", "\\'"); + var password = RegexUtils.GetStringQuery(ref inputData, "password")?.Replace("'", "\\'"); + + var itemMainImage = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "itemMainImage")).ParseToString().Replace("'", "\\'"); + var itemName = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "itemName")).ParseToString().Replace("'", "\\'"); + var styleCode = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "styleCode")).ParseToString().Replace("'", "\\'"); + var itemCode = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "itemCode")).ParseToString().Replace("'", "\\'"); + var colourSpec = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "colourSpec")).ParseToString().Replace("'", "\\'"); + var supplyPrice = RegexUtils.GetStringQuery(ref inputData, "supplyPrice").ParseToString().Replace("'", "\\'"); + var supplierName = RegexUtils.GetStringQuery(ref inputData, "supplierName").ParseToString().Replace("'", "\\'"); + var shelvesTime = RegexUtils.GetStringQuery(ref inputData, "shelvesTime").ParseToString().Replace("'", "\\'"); + var supplierCoId = RegexUtils.GetStringQuery(ref inputData, "supplierCoId").ParseToString().Replace("'", "\\'"); + var coId = RegexUtils.GetStringQuery(ref inputData, "coId").ParseToString().Replace("'", "\\'"); + var spuId = RegexUtils.GetStringQuery(ref inputData, "spuId").ParseToString().Replace("'", "\\'"); + var partnerSkuId = RegexUtils.GetStringQuery(ref inputData, "partnerSkuId").ParseToString().Replace("'", "\\'"); + var partnerSpuId = RegexUtils.GetStringQuery(ref inputData, "partnerSpuId").ParseToString().Replace("'", "\\'"); + var supplierId = RegexUtils.GetStringQuery(ref inputData, "supplierId").ParseToString().Replace("'", "\\'"); + var drpItemStatus = RegexUtils.GetStringQuery(ref inputData, "drpItemStatus").ParseToString().Replace("'", "\\'"); + var lastOperator = RegexUtils.GetStringQuery(ref inputData, "lastOperator").ParseToString().Replace("'", "\\'"); + var itemSpuIdMd5 = RegexUtils.GetStringQuery(ref inputData, "itemSpuIdMd5").ParseToString().Replace("'", "\\'"); + var secret_spu_id = RegexUtils.GetStringQuery(ref inputData, "secret_spu_id").ParseToString().Replace("'", "\\'"); + var secret_sku_id = RegexUtils.GetStringQuery(ref inputData, "secret_sku_id").ParseToString().Replace("'", "\\'"); + var is_in_product_db = RegexUtils.GetStringQuery(ref inputData, "is_in_product_db").ParseToInt(); + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + + string sql = ""; + sql = "select styleCode,itemCode,colourSpec from bxx.product_jst_update where styleCode='" + styleCode + + "' and itemCode='" + itemCode + "' and colourSpec='" + colourSpec + "'"; + var dt = mySql.ExecuteDataTable(sql); + if (!string.IsNullOrEmpty(mySql.Message)) + { + mySql.Close(); + return "{\"code\":500,\"msg\":\"" + mySql.Message + "\"}"; + } + if (dt.Rows.Count > 0) + { + mySql.Close(); + return "{\"code\":500,\"msg\":\"数据已存在\"}"; + } + + sql = "insert into bxx.product_jst_update " + + " (itemMainImage,itemName,styleCode,itemCode,colourSpec,supplyPrice,supplierName,shelvesTime,supplierCoId,coId,spuId," + + " partnerSkuId,partnerSpuId,supplierId,drpItemStatus,lastOperator,itemSpuIdMd5,secret_spu_id,secret_sku_id,is_in_product_db)" + + " values('" + itemMainImage + "','" + itemName + "','" + styleCode + "','" + itemCode + "','" + colourSpec + "','" + supplyPrice + "','" + + supplierName + "','" + shelvesTime + "','" + supplierCoId + "','" + coId + "','" + spuId + "','" + partnerSkuId + "','" + + partnerSpuId + "','" + supplierId + "','" + drpItemStatus + "','" + lastOperator + "','" + itemSpuIdMd5 + "','" + secret_spu_id + "','" + + secret_sku_id + "'," + is_in_product_db + ")"; + + //var rst = mySql.ExecuteNonQuery(sql, paramLst.ToArray()); + 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\":\"输入为空\"}"; + } + + /// + /// 查询下架sku + /// + /// + /// + public string GetProdDownSkuLstBySkuCodes(string inputData) + { + var timeCalc = DateTime.Now; + 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 version = RegexUtils.GetStringQuery(ref inputData, "version").ParseToInt(); + //if (version < (System.Configuration.ConfigurationManager.ConnectionStrings["LimitVersion"]?.ConnectionString).ParseToInt()) + // return "{\"code\":1,\"msg\":\"当前版本过于陈旧,请立即升级新版\"}"; + + var user_name = RegexUtils.GetStringQuery(ref inputData, "user_name")?.Replace("'", "\\'"); + var password = RegexUtils.GetStringQuery(ref inputData, "password")?.Replace("'", "\\'"); + var search_spu_ids = RegexUtils.GetStringQuery(ref inputData, "search_spu_ids")?.Replace("'", "\\'"); + var search_sku_codes = RegexUtils.GetStringQuery(ref inputData, "search_sku_codes")?.Replace("'", "\\'"); + var search_secret_spu_ids = RegexUtils.GetStringQuery(ref inputData, "search_secret_spu_ids")?.Replace("'", "\\'"); + if (search_spu_ids.IsNullOrEmpty() && search_sku_codes.IsNullOrEmpty() && search_secret_spu_ids.IsNullOrEmpty()) + return "{\"code\":500,\"msg\":\"查询条件不能全部为空\",\"data\":[],\"count\":" + 0 + "}"; + + int page = RegexUtils.GetStringQuery(ref inputData, "page").ParseToInt(); + int page_size = RegexUtils.GetStringQuery(ref inputData, "page_size").ParseToInt(1000); + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + + string sql = "select id,spuId,itemName,styleCode,itemCode,colourSpec,supplierCoId,supplierName,is_in_product_db,secret_spu_id,secret_sku_id,add_time" + + " from bxx.product_jst_update p where 1=1"; + if (search_secret_spu_ids != null) + { + sql += " and p.secret_spu_id in ('" + string.Join("','", search_secret_spu_ids.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries)) + "')"; + } + if (search_spu_ids != null) + { + sql += " and p.spuId in ('" + string.Join("','", search_spu_ids.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries)) + "')"; + } + if (search_sku_codes != null) + { + sql += " and p.itemCode in ('" + string.Join("','", search_sku_codes.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries)) + "')"; + } + sql += " limit " + Math.Max(page - 1, 0) * page_size + "," + page_size; + var dt = mySql.ExecuteDataTable(sql); + + mySql.Close(); + if (dt != null) + { + try + { + List productLst = new List(); + foreach (DataRow row in dt.Rows) + { + JSTDownProdSkuInfo prod = new JSTDownProdSkuInfo + { + id = Convert.ToInt32(row["id"]), + spuId = row["spuId"].ToString(), + itemName = row["itemName"].ToString(), + styleCode = row["styleCode"].ToString(), + itemCode = row["itemCode"].ToString(), + colourSpec = row["colourSpec"].ToString(), + supplierCoId = row["supplierCoId"].ToString(), + supplierName = row["supplierName"].ToString(), + add_time = Convert.ToDateTime(row["add_time"]), + is_in_product_db = row["is_in_product_db"].ParseToInt(), + secret_spu_id = row["secret_spu_id"].ParseToString(), + secret_sku_id = row["secret_sku_id"].ParseToString(), + }; + productLst.Add(prod); + } + JsonSerializerSettings jsonSetting = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }; + var data = JsonUtils.SerializeObjectToString(productLst, jsonSetting); + var seconds = (DateTime.Now - timeCalc).TotalSeconds.ToString("0.000"); + return "{\"code\":200,\"msg\":\"success\",\"data\":" + data + ",\"count\":" + productLst.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 GetProductGroups(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\":\"没有用户名\"}"; + } + + int page = RegexUtils.GetStringQuery(ref inputData, "page").ParseToInt(); + int page_size = RegexUtils.GetStringQuery(ref inputData, "page_size").ParseToInt(200); + var add_user_name = RegexUtils.GetStringQuery(ref inputData, "add_user_name")?.Replace("'", "\\'"); + var is_get_detail = RegexUtils.GetStringQuery(ref inputData, "is_get_detail") == "true"; + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + + string sql = "SELECT p.* FROM `bxx`.`product_group` p where 1=1 "; + string where = ""; + if (!string.IsNullOrEmpty(add_user_name)) + { + add_user_name = "'" + string.Join("','", add_user_name.Split(new string[] { ",", ",", " " }, StringSplitOptions.RemoveEmptyEntries)) + "'"; + where += " and p.add_user_name in (" + add_user_name + ")"; + } + else + { + where += " and p.add_user_name='admin'"; + } + sql += where; + sql += " ORDER BY id DESC"; + + var dt = mySql.ExecuteDataTable(sql); + mySql.Close(); + + if (dt != null) + { + try + { + JArray groupArr = new JArray(); + string group_data = ""; + foreach (DataRow row in dt.Rows) + { + group_data += row["group_name"].ToString() + ","; + + if (is_get_detail) + { + JObject groupObj = new JObject(); + groupObj["id"] = row["id"].ParseToLong(); + groupObj["group_name"] = row["group_name"].ParseToString(); + groupObj["add_user_name"] = row["add_user_name"].ParseToString(); + groupArr.Add(groupObj); + } + } + var data = group_data.Trim(','); + return "{\"code\":200,\"msg\":\"success\",\"data\":\"" + data + "\",\"groups\":" + JsonUtils.SerializeObject(groupArr) + "}"; + } + catch (Exception ex) + { + return "{\"code\":50002,\"msg\":\"" + ex.Message + "\",\"data\":\"\"}"; + } + } + else + { + return "{\"code\":50003,\"msg\":\"" + mySql.Message + "\",\"data\":\"\"}"; + } + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + public string AddProductGroup(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 add_user_name = RegexUtils.GetStringQuery(ref inputData, "add_user_name")?.Replace("'", "\\'"); + if (string.IsNullOrEmpty(add_user_name)) + { + add_user_name = "admin"; + } + var group_name = RegexUtils.GetStringQuery(ref inputData, "group_name")?.Replace("'", "\\'"); + if (string.IsNullOrEmpty(group_name)) + { + return "{\"code\":500,\"msg\":\"未指定要新增的组\"}"; + } + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + + string sql = "INSERT IGNORE INTO `bxx`.`product_group` (group_name,add_user_name) VALUES ('" + group_name + "','" + add_user_name + "')"; + + var add_rows = mySql.ExecuteAffectedRows(sql); + mySql.Close(); + + if (string.IsNullOrEmpty(mySql.Message)) + { + return "{\"code\":200,\"msg\":\"success\", \"add_rows\":" + add_rows + "}"; + } + else + { + return "{\"code\":50003,\"msg\":\"" + mySql.Message + "\",\"data\":\"\"}"; + } + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + public string DelProductGroup(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 add_user_name = RegexUtils.GetStringQuery(ref inputData, "add_user_name")?.Replace("'", "\\'"); + if (string.IsNullOrEmpty(add_user_name)) + { + add_user_name = "admin"; + } + var id = RegexUtils.GetStringQuery(ref inputData, "group_id")?.Replace("'", "\\'"); + var group_name = RegexUtils.GetStringQuery(ref inputData, "group_name")?.Replace("'", "\\'"); + if (string.IsNullOrEmpty(id) && string.IsNullOrEmpty(group_name)) + { + return "{\"code\":500,\"msg\":\"未指定要删除的组\"}"; + } + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + + string sql = "DELETE FROM `bxx`.`product_group` p where 1=1"; + + string where = ""; + if (!string.IsNullOrEmpty(id)) + { + id = "" + string.Join(",", id.Split(new string[] { ",", ",", " " }, StringSplitOptions.RemoveEmptyEntries)) + ""; + where += " and p.id in (" + id + ")"; + } + if (!string.IsNullOrEmpty(group_name)) + { + group_name = "'" + string.Join("','", group_name.Split(new string[] { ",", ",", " " }, StringSplitOptions.RemoveEmptyEntries)) + "'"; + where += " and p.group_name in (" + group_name + ")"; + } + if (!string.IsNullOrEmpty(add_user_name)) + { + add_user_name = "'" + string.Join("','", add_user_name.Split(new string[] { ",", ",", " " }, StringSplitOptions.RemoveEmptyEntries)) + "'"; + where += " and p.add_user_name in (" + add_user_name + ")"; + } + sql += where; + + var del_rows = mySql.ExecuteAffectedRows(sql); + mySql.Close(); + + if (string.IsNullOrEmpty(mySql.Message)) + { + return "{\"code\":200,\"msg\":\"success\", \"del_rows\":" + del_rows + "}"; + } + else + { + return "{\"code\":50003,\"msg\":\"" + mySql.Message + "\",\"data\":\"\"}"; + } + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + public string GetProductNotes(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\":\"没有用户名\"}"; + } + + int page = RegexUtils.GetStringQuery(ref inputData, "page").ParseToInt(); + int page_size = RegexUtils.GetStringQuery(ref inputData, "page_size").ParseToInt(200); + var add_user_name = RegexUtils.GetStringQuery(ref inputData, "add_user_name")?.Replace("'", "\\'"); + var is_get_detail = RegexUtils.GetStringQuery(ref inputData, "is_get_detail") == "true"; + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + + string sql = "SELECT p.* FROM `bxx`.`product_notes` p where 1=1 "; + string where = ""; + if (!string.IsNullOrEmpty(add_user_name)) + { + add_user_name = "'" + string.Join("','", add_user_name.Split(new string[] { ",", ",", " " }, StringSplitOptions.RemoveEmptyEntries)) + "'"; + where += " and p.add_user_name in (" + add_user_name + ")"; + } + else + { + where += " and p.add_user_name='admin'"; + } + sql += where; + sql += " ORDER BY id DESC"; + + var dt = mySql.ExecuteDataTable(sql); + mySql.Close(); + + if (dt != null) + { + try + { + JArray notesArr = new JArray(); + string notes_data = ""; + foreach (DataRow row in dt.Rows) + { + notes_data += row["notes"].ToString() + ","; + + if (is_get_detail) + { + JObject notesObj = new JObject(); + notesObj["id"] = row["id"].ParseToLong(); + notesObj["notes"] = row["notes"].ParseToString(); + notesObj["add_user_name"] = row["add_user_name"].ParseToString(); + notesArr.Add(notesObj); + } + } + var data = notes_data.Trim(','); + return "{\"code\":200,\"msg\":\"success\",\"data\":\"" + data + "\",\"notes\":" + JsonUtils.SerializeObject(notesArr) + "}"; + } + catch (Exception ex) + { + return "{\"code\":50002,\"msg\":\"" + ex.Message + "\",\"data\":\"\"}"; + } + } + else + { + return "{\"code\":50003,\"msg\":\"" + mySql.Message + "\",\"data\":\"\"}"; + } + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + public string AddProductNotes(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 add_user_name = RegexUtils.GetStringQuery(ref inputData, "add_user_name")?.Replace("'", "\\'"); + if (string.IsNullOrEmpty(add_user_name)) + { + add_user_name = "admin"; + } + var notes = RegexUtils.GetStringQuery(ref inputData, "notes")?.Replace("'", "\\'"); + if (string.IsNullOrEmpty(notes)) + { + return "{\"code\":500,\"msg\":\"未指定要新增的组\"}"; + } + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + + string sql = "INSERT IGNORE INTO `bxx`.`product_notes` (notes,add_user_name) VALUES ('" + notes + "','" + add_user_name + "')"; + + var add_rows = mySql.ExecuteAffectedRows(sql); + mySql.Close(); + + if (string.IsNullOrEmpty(mySql.Message)) + { + return "{\"code\":200,\"msg\":\"success\", \"add_rows\":" + add_rows + "}"; + } + else + { + return "{\"code\":50003,\"msg\":\"" + mySql.Message + "\",\"data\":\"\"}"; + } + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + public string DelProductNotes(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 add_user_name = RegexUtils.GetStringQuery(ref inputData, "add_user_name")?.Replace("'", "\\'"); + if (string.IsNullOrEmpty(add_user_name)) + { + add_user_name = "admin"; + } + var id = RegexUtils.GetStringQuery(ref inputData, "notes_id")?.Replace("'", "\\'"); + var notes = RegexUtils.GetStringQuery(ref inputData, "notes")?.Replace("'", "\\'"); + if (string.IsNullOrEmpty(id) && string.IsNullOrEmpty(notes)) + { + return "{\"code\":500,\"msg\":\"未指定要删除的组\"}"; + } + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + + string sql = "DELETE FROM `bxx`.`product_notes` p where 1=1"; + + string where = ""; + if (!string.IsNullOrEmpty(id)) + { + id = "" + string.Join(",", id.Split(new string[] { ",", ",", " " }, StringSplitOptions.RemoveEmptyEntries)) + ""; + where += " and p.id in (" + id + ")"; + } + if (!string.IsNullOrEmpty(notes)) + { + notes = "'" + string.Join("','", notes.Split(new string[] { ",", ",", " " }, StringSplitOptions.RemoveEmptyEntries)) + "'"; + where += " and p.notes in (" + notes + ")"; + } + if (!string.IsNullOrEmpty(add_user_name)) + { + add_user_name = "'" + string.Join("','", add_user_name.Split(new string[] { ",", ",", " " }, StringSplitOptions.RemoveEmptyEntries)) + "'"; + where += " and p.add_user_name in (" + add_user_name + ")"; + } + sql += where; + + var del_rows = mySql.ExecuteAffectedRows(sql); + mySql.Close(); + + if (string.IsNullOrEmpty(mySql.Message)) + { + return "{\"code\":200,\"msg\":\"success\", \"del_rows\":" + del_rows + "}"; + } + else + { + return "{\"code\":50003,\"msg\":\"" + mySql.Message + "\",\"data\":\"\"}"; + } + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + + public string GetProductCates(string inputData) + { + return "{\"code\":19999,\"msg\":\"接口废弃\"}"; + } + + public string GetProductMainCates(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\":\"没有用户名\"}"; + } + + int page = RegexUtils.GetStringQuery(ref inputData, "page").ParseToInt(); + int page_size = RegexUtils.GetStringQuery(ref inputData, "page_size").ParseToInt(50); + + // 直接返回全部拼多多一级类目名称及ID + var pddCats1Str = "男装,办公设备/耗材/相关服务,文具电教/文化用品/商务用品,3C数码配件,古董文玩/邮币/字画/收藏,影音电器,手机,二手数码,笔记本电脑,数码相机/单反相机/摄像机,智能设备,厨房电器,大家电,生活电器,个人护理保健,网络设备,零食/坚果/特产,咖啡/麦片/冲饮,茶,粮油米面/南北干货/调味品,酒类,保健食品/膳食营养补充食品,传统滋补品,电子元器件市场,摩托车/装备/配件,汽车/用品/配件/改装,水产肉类/新鲜蔬果/熟食,女装/女士精品,新车/二手车,流行男鞋,女鞋,箱包皮具/女包/男包,内衣裤袜,腕表眼镜,服饰配件,本地化生活服务,电影/演出/体育赛事,个性定制/设计服务,购物卡/礼品卡/代金券,婚庆/摄影/摄像服务,教育培训,景点门票/周边游,旅游路线/商品/服务,生活缴费,数字生活娱乐,特价酒店/客栈/公寓旅馆,网络服务/软件,网上营业厅,休闲娱乐,游戏服务/直播,床上用品,电子/电工,基础建材,家居饰品,灯饰光源照明,家装主材,居家布艺,全屋定制,商业/办公家具,特色手工艺,五金工具,住宅家具,电动车/配件/交通工具,户外/登山/旅行野营用品,运动/瑜伽/健身/球类,运动包/户外包/配件,运动服/休闲服,运动鞋,自行车/骑行装备/零配件,OTC药品,精制中药材,隐形眼镜/护理液,奶粉/辅食/营养品/零食,婴童用品,童鞋/婴儿鞋/亲子鞋,童装/婴儿装/亲子装,玩具/童车/益智/积木/模型,孕产妇用品/孕妇装/营养,书籍/杂志/报纸,农机/农具/农膜,畜牧/养殖物资,农用物资,成人用品,宠物/宠物食品及用品,餐饮具,厨房/烹饪用具,收纳整理,家庭/个人清洁工具,居家日用,节庆用品/礼品,烟品/打火机/瑞士军刀,洗护清洁剂/卫生巾/纸/香薰,饰品/流行首饰/摆件/保养鉴定,珠宝/钻石/翡翠/黄金,鲜花园艺/绿植仿真/园林设备,乐器/吉他/钢琴/配件,装修设计/施工/监理,医疗健康服务,处方药,彩妆/香水/美妆工具,美容美体仪器,美发护发/假发,美容护肤/美体/精油,医疗器械,婴童尿裤,汽车服务,交通出行,房地产,模玩/动漫/周边/cos/桌游,音乐/影视/明星/音像,搬运/仓储/物流设备,标准件/零部件/工业耗材,机械设备,清洗/食品/商业设备,橡塑材料及制品,平板电脑/MID,品牌台机/品牌一体机/服务器,DIY电脑,闪存卡/U盘/存储/移动硬盘,电脑硬件/显示器/电脑周边,电玩/配件/游戏/攻略,包装用品,保健用品,特色农产品(非食用),239,2603,2629,2933,5217,5752,5834,5839,5851,5906,5921,5955,6076,6128,6209,6290,6398,6536,6586,6630,6758,6785,6883,7323,7629,7639,8172,8439,8502,8508,8509,8538,8583,8634,8669,8721,8722,8723,8724,8725,8726,8727,8728,8729,8730,8731,8732,8733,8734,8736,9313,9314,9315,9316,9317,9318,9319,9320,9321,9322,9323,9324,11683,11684,11685,11686,11687,11688,11689,13176,13177,13178,14697,14740,14933,14966,15083,15356,15543,16155,16192,16209,16237,16288,16548,16676,16794,16901,16989,17134,17249,17285,17412,17455,17671,17803,18088,18270,18349,18482,18574,18601,18637,18814,19298,20078,20118,20340,20645,21417,22856,22881,22931,22964,22986,24383,24386,24402,24407,24426,24520,24636,24699,27063"; + var data = pddCats1Str; + return "{\"code\":200,\"msg\":\"success\",\"data\":\"" + data + "\"}"; + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + /// + /// 查询商品替换sku + /// + /// + /// + /// + public string GetSkuImgReplaceList(string inputData, bool isDetail = false) + { + 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("'", "\\'"); + var password = RegexUtils.GetStringQuery(ref inputData, "password")?.Replace("'", "\\'"); + var sku_img_replace_ids = RegexUtils.GetStringQuery(ref inputData, "sku_img_replace_ids")?.Replace("'", "\\'"); + + int page = RegexUtils.GetStringQuery(ref inputData, "page").ParseToInt(); + int page_size = RegexUtils.GetStringQuery(ref inputData, "page_size").ParseToInt(50); + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + + string sql = "select count(*) from bxx.sku_img_replace s where 1=1"; + + string where = ""; + if (!string.IsNullOrWhiteSpace(sku_img_replace_ids)) + where += " and s.id in (" + sku_img_replace_ids + ")"; + sql += where; + + var count = mySql.ExecuteRowCount(sql); + + DataTable dt; + if (count == 0) + { + dt = new DataTable(); + } + else + { + sql = "select * from bxx.sku_img_replace s where 1=1"; + + //where子句 + sql += where; + + sql += " order by s.img_type asc, s.id desc"; + sql += " limit " + Math.Max(page - 1, 0) * page_size + "," + page_size; + dt = mySql.ExecuteDataTable(sql); + } + + mySql.Close(); + if (dt != null) + { + try + { + List skuImgReplaceLst = new List(); + foreach (DataRow row in dt.Rows) + { + sku_img_replace skuImgReplace = new sku_img_replace + { + id = Convert.ToInt32(row["id"]), + //img_base64 = row["img_base64"].ToString(), + img_md5 = row["img_md5"].ToString(), + img_url = row["img_url"].ToString(), + add_time = Convert.ToDateTime(row["add_time"]), + mdy_time = Convert.ToDateTime(row["mdy_time"]), + img_type = row["img_type"].ToString(), + img_group = row["img_group"].ToString(), + }; + if (isDetail) + { + skuImgReplace.img_base64 = row["img_base64"].ToString(); + } + skuImgReplaceLst.Add(skuImgReplace); + } + var data = JsonUtils.SerializeObjectToString(skuImgReplaceLst); + return "{\"code\":200,\"msg\":\"success\",\"data\":" + data + ",\"count\":" + count + "}"; + } + 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 GetProductListRandom(string inputData) + { + var timeCalc = DateTime.Now; + 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("'", "\\'"); + var password = RegexUtils.GetStringQuery(ref inputData, "password")?.Replace("'", "\\'"); + var in_ext_codes = RegexUtils.GetStringQuery(ref inputData, "in_ext_codes")?.Replace("'", "\\'"); + var in_spu_ids = RegexUtils.GetStringQuery(ref inputData, "in_spu_ids")?.Replace("'", "\\'"); + var in_skc_ids = RegexUtils.GetStringQuery(ref inputData, "in_skc_ids")?.Replace("'", "\\'"); + var in_groups = RegexUtils.GetStringQuery(ref inputData, "in_groups")?.Replace("'", "\\'"); + var in_notes = RegexUtils.GetStringQuery(ref inputData, "in_notes")?.Replace("'", "\\'"); + var product_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "product_name"))?.Replace("'", "\\'"); + var in_cates = RegexUtils.GetStringQuery(ref inputData, "in_cates")?.Replace("'", "\\'"); + var wx_cat_1 = RegexUtils.GetStringQuery(ref inputData, "wx_cat_1")?.Replace("'", "\\'"); + var wx_cat_2 = RegexUtils.GetStringQuery(ref inputData, "wx_cat_2")?.Replace("'", "\\'"); + var wx_cat_3 = RegexUtils.GetStringQuery(ref inputData, "wx_cat_3")?.Replace("'", "\\'"); + var wx_safe_status = RegexUtils.GetStringQuery(ref inputData, "wx_safe_status")?.Replace("'", "\\'"); + var special_prod_type = RegexUtils.GetStringQuery(ref inputData, "special_prod_type")?.Replace("'", "\\'"); + if (special_prod_type.IsNullOrEmpty()) + special_prod_type = "普通商品"; + var product_get_type = RegexUtils.GetStringQuery(ref inputData, "product_get_type")?.Replace("'", "\\'"); + var is学员数据 = false; + if (product_get_type == "学员数据") + { + is学员数据 = true; + product_get_type = "多多外部数据,微信小店,微信店采"; + special_prod_type = "普通商品,爆款数据"; + } + var is_supplier_prod_ok = RegexUtils.GetStringQuery(ref inputData, "is_supplier_prod_ok")?.Replace("'", "\\'"); + var is_not_count = RegexUtils.GetStringQuery(ref inputData, "is_not_count") == "true"; // 不计数 + var prod_count = RegexUtils.GetStringQuery(ref inputData, "prod_count").ParseToInt(); + var add_days_less = RegexUtils.GetStringQuery(ref inputData, "add_days_less").ParseToNullableInt(); + var has_wx_format = RegexUtils.GetStringQuery(ref inputData, "has_wx_format")?.Replace("'", "\\'"); + var is_relation = RegexUtils.GetStringQuery(ref inputData, "is_relation").ParseToNullableInt(); + var ban_wx = RegexUtils.GetStringQuery(ref inputData, "ban_wx")?.Replace("'", "\\'"); + var ban_pdd = RegexUtils.GetStringQuery(ref inputData, "ban_pdd")?.Replace("'", "\\'"); + var add_user_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "add_user_name"))?.Replace("'", "\\'"); + if (is学员数据) + add_user_name = "admin"; + var no_fission_words = RegexUtils.GetStringQuery(ref inputData, "no_fission_words").ParseToBool(); // 未裂变标题 + var fission_words = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "fission_words"))?.Replace("'", "\\'"); + var min_view_uv = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "min_view_uv"))?.ParseToNullableInt(); + if (min_view_uv > 0 && min_view_uv < 100) + min_view_uv = 100; + if (is学员数据) + min_view_uv = null; + + int page = RegexUtils.GetStringQuery(ref inputData, "page").ParseToInt(); + int page_size = RegexUtils.GetStringQuery(ref inputData, "page_size").ParseToInt(50); + + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + + string tableName = GetProductTableName(inputData); + string sql = ""; + + sql = " SELECT count(*)" + " FROM " + tableName + " p"; + //if (!string.IsNullOrEmpty(wx_safe_status)) + // sql += " FORCE INDEX (index_wx_safe_status)"; + //sql += " LEFT JOIN bxx.jst_supplier_ban_platform b ON (p.skc_id=b.coid or p.real_coid=b.coid)" + sql += " WHERE p.is_del=0"; + + string where = ""; + //where += " AND (b.ban_wx IS NULL OR b.ban_wx=0)"; + if (!string.IsNullOrEmpty(in_ext_codes)) + { + in_ext_codes = "'" + string.Join("','", in_ext_codes.Split(new string[] { ",", ",", " " }, StringSplitOptions.RemoveEmptyEntries)) + "'"; + where += " and p.ext_code in (" + in_ext_codes + ")"; + } + if (!string.IsNullOrEmpty(in_skc_ids)) + { + in_skc_ids = "'" + string.Join("','", in_skc_ids.Split(new string[] { ",", ",", " " }, StringSplitOptions.RemoveEmptyEntries)) + "'"; + where += " and p.skc_id in (" + in_skc_ids + ")"; + } + if (!string.IsNullOrEmpty(in_spu_ids)) + { + in_spu_ids = "'" + string.Join("','", in_spu_ids.Split(new string[] { ",", ",", " " }, StringSplitOptions.RemoveEmptyEntries)) + "'"; + where += " and p.spu_id in (" + in_spu_ids + ")"; + } + if (!string.IsNullOrEmpty(in_groups)) + { + in_groups = "'" + string.Join("','", in_groups.Split(new string[] { ",", ",", " " }, StringSplitOptions.RemoveEmptyEntries)) + "'"; + where += " and p.group in (" + in_groups + ")"; + } + if (!string.IsNullOrEmpty(in_notes)) + { + in_notes = "'" + string.Join("','", in_notes.Split(new string[] { ",", ",", " " }, StringSplitOptions.RemoveEmptyEntries)) + "'"; + where += " and p.notes in (" + in_notes + ")"; + } + if (!string.IsNullOrEmpty(in_cates)) + { + in_cates = "'" + string.Join("','", in_cates.Split(new string[] { ",", ",", " " }, StringSplitOptions.RemoveEmptyEntries)) + "'"; + where += " and (p.cat_name in (" + in_cates + ") or p.main_cat_name in (" + in_cates + "))"; + } + if (!string.IsNullOrEmpty(product_name)) + { + where += " and p.product_name='" + product_name + "'"; + } + if (!string.IsNullOrEmpty(wx_cat_1)) + { + where += " and p.wx_cat_1 in (" + wx_cat_1 + ")"; + } + if (!string.IsNullOrEmpty(wx_cat_2)) + { + where += " and p.wx_cat_2 in (" + wx_cat_2 + ")"; + } + if (!string.IsNullOrEmpty(wx_cat_3)) + { + where += " and p.wx_cat_3 in (" + wx_cat_3 + ")"; + } + string where1 = ""; + string where2 = ""; + if (!string.IsNullOrEmpty(product_get_type)) + { + where1 = " and p.product_get_type in ('" + product_get_type.Replace(",", "','") + "')"; + //where1 = " and ((product_get_type = '多多外部数据') OR (product_get_type = '微信小店') OR (product_get_type = '微信店采' AND wx_safe_status = '安全商品')) "; + if (is学员数据) + { + // 多多外部数据20% 微信小店数据30% 微信店采50% + //where2 = " and (RAND() < 0.066 AND product_get_type = '多多外部数据' OR RAND() < 0.3 AND product_get_type = '微信小店' OR RAND() <= 1 AND product_get_type = '微信店采') "; + where2 = " and ((RAND() < 0.055 AND product_get_type = '多多外部数据') OR (RAND() < 0.39 AND product_get_type = '微信小店') OR (RAND() <= 1 AND product_get_type = '微信店采' AND wx_safe_status = '安全商品')) "; + } + where += where1; + } + if (!string.IsNullOrEmpty(wx_safe_status)) + where += " and p.wx_safe_status in ('" + wx_safe_status.Replace(",", "','") + "')"; + //if (!string.IsNullOrEmpty(special_prod_type)) // 普通商品 爆款数据 + // where += " and p.special_prod_type ='" + special_prod_type + "'"; + if (!string.IsNullOrEmpty(special_prod_type)/* && special_prod_type != "普通商品,爆款数据"*/) + where += " and p.special_prod_type in ('" + special_prod_type.Replace(",", "','") + "')"; + // 供应商货源是否已完成初始设置 + if (!string.IsNullOrEmpty(is_supplier_prod_ok)) + { + if (is_supplier_prod_ok == "1" || is_supplier_prod_ok == "是" || is_supplier_prod_ok == "已设置") + where += " AND wx_cat_leaf > 0 AND send_to_out_server IN (1,127) and distribution_set IN (1,127)"; + else + where += " AND (wx_cat_leaf IS NULL OR send_to_out_server NOT IN (1,127) OR distribution_set NOT IN (1,127))"; + } + else + { + where += " AND send_to_out_server IN (0,1,127) and distribution_set IN (0,1,2,127)"; + } + if (!add_days_less.IsNullOrZero()) + { + where += " and add_time > '" + DateTime.Now.AddDays(-add_days_less.ParseToInt()).ToString("yyyy-MM-dd") + "'"; + } + if (!has_wx_format.IsNullOrEmpty()) + { + where += " and has_wx_format = '" + has_wx_format + "'"; + } + if (is_relation != null) + { + where += " and is_relation = " + is_relation; + } + if (ban_wx != null) + { + where += " and p.ban_wx=" + ban_wx; + } + else + { + where += " and p.ban_wx in (0,1) "; + } + if (ban_pdd != null) + { + where += " and p.ban_pdd=" + ban_pdd; + } + else + { + where += " and p.ban_pdd in (0,1) "; + } + if (!string.IsNullOrEmpty(add_user_name)) + { + add_user_name = "'" + string.Join("','", add_user_name.Split(new string[] { ",", ",", " " }, StringSplitOptions.RemoveEmptyEntries)) + "'"; + where += " and p.add_user_name in (" + add_user_name + ")"; + } + if (no_fission_words) + { + where += " and (fission_words='' or fission_words IS NULL)"; + } + if (!string.IsNullOrEmpty(fission_words)) + { + where += " and fission_words LIKE '" + fission_words + "%'"; + } + if (min_view_uv > 0) + { + where += " and view_uv >= " + min_view_uv + ""; + } + sql += where; + + int count = prod_count; + if (product_get_type == "厂商直采" && count > 1000) + count = (count / 2.0).ParseToInt(); + if (is学员数据 && count >= 450) + count = (count / 3.0).ParseToInt(); + if (!is_not_count) + { + count = mySql.ExecuteRowCount(sql); + Thread.Sleep(1500); + } + + DataTable dt; + if (count == 0 && !is_not_count) + { + dt = new DataTable(); + } + else + { + if (is学员数据) + { + where = where.Replace(where1, where2); + } + + sql = " SELECT p.id" + + " FROM " + tableName + " p" + + //" LEFT JOIN bxx.jst_supplier_ban_platform b ON (p.skc_id=b.coid OR p.real_coid=b.coid)" + + " WHERE p.is_del=0"; + //where子句 + sql += where; + + sql += " ORDER BY RAND()"; + sql += " limit " + Math.Max(page - 1, 0) * page_size + "," + page_size; + + //var limit = RandomUtils.GetId(Math.Max(0, count - page_size)); + //sql += " limit " + limit + "," + 5000; + + dt = mySql.ExecuteDataTable(sql); + Thread.Sleep(100); + if (!string.IsNullOrEmpty(mySql.Message) || dt == null) + { + mySql.Close(); + return "{\"code\":500,\"msg\":\"" + mySql.Message + "\",\"data\":[],\"count\":" + 0 + "}"; + } + + var db_ids = string.Join(",", dt.Rows.Cast().Select(r => r["id"].ParseToInt()).OrderBy(x => RandomUtils.GetId(10000000)).Take(page_size)); + sql = "SELECT p.id,p.from_shop_id,p.spu_id,p.skc_id,p.main_cat_id,p.main_cat_name,p.cat_id,p.cat_name,p.price_text,p.ext_code," + + " p.product_name,p.main_img,p.group,p.notes,p.add_time,p.mdy_time,p.product_get_type,fission_words," + + " p.wx_safe_status,p.special_prod_type,p.wx_cat_1,p.wx_cat_2,p.wx_cat_3,p.send_to_out_server," + + " p.wx_cat_leaf,p.is_relation" + + " from " + tableName + " p where p.is_del=0"; + //where子句 + //sql += where; + sql += " and id in (" + db_ids + ")"; + + //sql += " ORDER BY RAND()"; + //sql += " limit " + Math.Max(page - 1, 0) * page_size + "," + page_size; + dt = mySql.ExecuteDataTable(sql); + } + + mySql.Close(); + Thread.Sleep(500); + if (dt != null) + { + try + { + List productLst = new List(); + foreach (DataRow row in dt.Rows) + { + DBProductResultParam prod = new DBProductResultParam + { + id = Convert.ToInt32(row["id"]), + from_shop_id = row["from_shop_id"].ToString(), + spu_id = row["spu_id"].ToString(), + skc_id = row["skc_id"].ToString(), + main_cat_id = row["main_cat_id"].ToString(), + main_cat_name = row["main_cat_name"].ToString(), + cat_id = row["cat_id"].ToString(), + cat_name = row["cat_name"].ToString(), + wx_cat_1 = row["wx_cat_1"].ToString(), + wx_cat_2 = row["wx_cat_2"].ToString(), + wx_cat_3 = row["wx_cat_3"].ToString(), + wx_cat_leaf = row["wx_cat_leaf"].ToString(), + price_text = row["price_text"].ToString(), + product_name = row["product_name"].ToString(), + main_img = row["main_img"].ToString(), + ext_code = row["ext_code"].ToString(), + add_time = Convert.ToDateTime(row["add_time"]), + mdy_time = Convert.ToDateTime(row["mdy_time"]), + group = row["group"].ToString(), + notes = row["notes"].ToString(), + product_get_type_text = row["product_get_type"].ParseToString(), + //sale_count = row["sale_count"].ParseToInt(), + //sale_count_text = row["sale_count_text"].ToString(), + wx_safe_status = row["wx_safe_status"].ToString(), + special_prod_type = row["special_prod_type"].ParseToString(), + send_to_out_server = row["send_to_out_server"].ParseToInt(), + is_relation = row["is_relation"].ParseToInt(), + fission_words = row["fission_words"].ParseToString(), + }; + productLst.Add(prod); + } + JsonSerializerSettings jsonSetting = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }; + var data = JsonUtils.SerializeObjectToString(productLst, jsonSetting); + var seconds = (DateTime.Now - timeCalc).TotalSeconds.ToString("0.000"); + if (product_get_type == "厂商直采" && count > 500) + count = (count * 2.0).ParseToInt(); + if (is学员数据 && count >= 150) + count = (count * 3.0).ParseToInt(); + 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\":\"输入为空\"}"; + } + + /// + /// 获取拼多多商品随机sku替换图 + /// + /// + /// + public string GetSkuReplaceImgListRandom(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("'", "\\'"); + var password = RegexUtils.GetStringQuery(ref inputData, "password")?.Replace("'", "\\'"); + var in_img_type = RegexUtils.GetStringQuery(ref inputData, "in_img_type")?.Replace("'", "\\'"); + var in_img_group = RegexUtils.GetStringQuery(ref inputData, "in_img_group")?.Replace("'", "\\'"); + + int page = RegexUtils.GetStringQuery(ref inputData, "page").ParseToInt(); + int page_size = RegexUtils.GetStringQuery(ref inputData, "page_size").ParseToInt(50); + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + + string sql = "select count(*) from bxx.sku_img_replace s where 1=1"; + + string where = ""; + if (!string.IsNullOrWhiteSpace(in_img_type) && !string.IsNullOrWhiteSpace(in_img_group)) + { + in_img_type = "'" + string.Join("','", in_img_type.Split(new string[] { ",", ",", " " }, StringSplitOptions.RemoveEmptyEntries)) + "'"; + in_img_group = "'" + string.Join("','", in_img_group.Split(new string[] { ",", ",", " " }, StringSplitOptions.RemoveEmptyEntries)) + "'"; + where += " and (s.img_type in (" + in_img_type + ") or s.img_group in (" + in_img_group + ")"; + } + else if (!string.IsNullOrWhiteSpace(in_img_type)) + { + in_img_type = "'" + string.Join("','", in_img_type.Split(new string[] { ",", ",", " " }, StringSplitOptions.RemoveEmptyEntries)) + "'"; + where += " and s.img_type in (" + in_img_type + ")"; + } + else if (!string.IsNullOrWhiteSpace(in_img_group)) + { + in_img_group = "'" + string.Join("','", in_img_group.Split(new string[] { ",", ",", " " }, StringSplitOptions.RemoveEmptyEntries)) + "'"; + where += " and s.img_group in (" + in_img_group + ")"; + } + + sql += where; + + var count = mySql.ExecuteRowCount(sql); + + DataTable dt; + if (count == 0) + { + dt = new DataTable(); + } + else + { + sql = "select s.img_url from bxx.sku_img_replace s where 1=1"; + + //where子句 + sql += where; + + sql += " ORDER BY RAND()"; + sql += " limit " + Math.Max(page - 1, 0) * page_size + "," + page_size; + dt = mySql.ExecuteDataTable(sql); + } + + mySql.Close(); + if (dt != null) + { + try + { + List imgs = new List(); + foreach (DataRow row in dt.Rows) + { + imgs.Add(row["img_url"].ToString()); + } + var data = JsonUtils.SerializeObjectToString(imgs); + return "{\"code\":200,\"msg\":\"success\",\"data\":" + data + ",\"count\":" + count + "}"; + } + 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 DelDbProd(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\":500,\"msg\":\"没有用户名\"}"; + } + + var id = RegexUtils.GetStringQuery(ref inputData, "db_id")?.Replace("'", "\\'"); + if (string.IsNullOrEmpty(id)) + { + return "{\"code\":500,\"msg\":\"删除失败:请指定要删除的数据!\"}"; + } + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + + string tableName = GetProductTableName(inputData); + string sql = ""; + + if (tableName != "bxx.product") + sql = "delete from " + tableName + " where id='" + id + "'"; + else + sql = "update " + tableName + " set is_del=1 where id='" + id + "'"; + + var rst = mySql.ExecuteNonQuery(sql); + mySql.Close(); + if (rst) + { + return "{\"code\":200,\"msg\":\"success\"}"; + } + else + return "{\"code\":500,\"msg\":\"删除失败:" + mySql.Message + "\"}"; + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + /// + /// 编辑商品备注信息、货号、头尾词和分词 + /// + /// + /// + /// + public string MdyDBProduct(string inputData, bool isAdmin = false) + { + 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\":\"校验失败\"}"; + + string user_name = RegexUtils.GetStringQuery(ref inputData, "user_name")?.Replace("'", "\\'"); + string id = RegexUtils.GetStringQuery(ref inputData, "db_id")?.Replace("'", "\\'"); + string in_db_ids = RegexUtils.GetStringQuery(ref inputData, "in_db_ids")?.Replace("'", "\\'"); + string product_name = RegexUtils.GetStringQuery(ref inputData, "product_name")?.Replace("'", "\\'"); + string group = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "group"))?.Replace("'", "\\'"); + string notes = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "notes"))?.Replace("'", "\\'"); + string ext_code = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "ext_code"))?.Replace("'", "\\'"); + string fission_imgs = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "fission_imgs"))?.Replace("'", "\\'"); + string fission_words = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "fission_words"))?.Replace("'", "\\'"); + string head_words = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "head_words"))?.Replace("'", "\\'"); + string end_words = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "end_words"))?.Replace("'", "\\'"); + string sku_edit_json = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "sku_edit_json"))?.Replace("'", "\\'"); + string wx_safe_status = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "wx_safe_status"))?.Replace("'", "\\'"); + string special_prod_type = RegexUtils.GetStringQuery(ref inputData, "special_prod_type")?.Replace("'", "\\'"); + string wx_cat_1 = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "wx_cat_1"))?.Replace("'", "\\'"); + string wx_cat_2 = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "wx_cat_2"))?.Replace("'", "\\'"); + string wx_cat_3 = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "wx_cat_3"))?.Replace("'", "\\'"); + string wx_cat_leaf = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "wx_cat_leaf"))?.Replace("'", "\\'"); + string main_cat_id = RegexUtils.GetStringQuery(ref inputData, "main_cat_id")?.Replace("'", "\\'"); + string main_cat_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "main_cat_name"))?.Replace("'", "\\'"); + string cat_id = RegexUtils.GetStringQuery(ref inputData, "cat_id")?.Replace("'", "\\'"); + string cat_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "cat_name"))?.Replace("'", "\\'"); + if (!string.IsNullOrEmpty(special_prod_type) && special_prod_type != "爆款数据") + special_prod_type = "普通商品"; + + if (string.IsNullOrEmpty(user_name)) + { + return "{\"code\":500,\"msg\":\"没有用户名\"}"; + } + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + + string tableName = GetProductTableName(inputData); + string sql = ""; + + sql = "update " + tableName + " p set"; + if (product_name != null) + sql += " p.product_name='" + product_name + "',"; + if (group != null) + sql += " p.group='" + group + "',"; + if (notes != null) + sql += " p.notes='" + notes + "',"; + if (ext_code != null) + sql += " p.ext_code='" + ext_code + "',"; + if (fission_imgs != null) + sql += " p.fission_imgs='" + fission_imgs + "',"; + if (fission_words != null) + sql += " p.fission_words='" + fission_words + "',"; + if (head_words != null) + sql += " p.head_words='" + head_words + "',"; + if (end_words != null) + sql += " p.end_words='" + end_words + "',"; + if (sku_edit_json != null) + sql += " p.sku_edit_json='" + sku_edit_json + "',"; + if (wx_safe_status != null) + sql += " p.wx_safe_status='" + wx_safe_status + "',"; + if (special_prod_type != null && special_prod_type != "") + sql += " p.special_prod_type='" + special_prod_type + "',"; + if (!wx_cat_1.IsNullOrEmpty()) + sql += " p.wx_cat_1=" + wx_cat_1 + ","; + if (!wx_cat_2.IsNullOrEmpty()) + sql += " p.wx_cat_2=" + wx_cat_2 + ","; + if (!wx_cat_3.IsNullOrEmpty()) + sql += " p.wx_cat_3=" + wx_cat_3 + ","; + if (!wx_cat_leaf.IsNullOrEmpty()) + sql += " p.wx_cat_leaf=" + wx_cat_leaf + ","; + if (main_cat_id != null) + sql += " p.main_cat_id='" + main_cat_id + "',"; + if (cat_id != null) + sql += " p.cat_id='" + cat_id + "',"; + if (main_cat_name != null) + sql += " p.main_cat_name='" + main_cat_name + "',"; + if (cat_name != null) + sql += " p.cat_name='" + cat_name + "',"; + sql = sql.TrimEnd(','); + if (in_db_ids != null) + { + sql += " where id in (" + in_db_ids + ");"; + } + else + { + sql += " where id=" + id + ";"; + } + + var rst = mySql.ExecuteNonQuery(sql); + mySql.Close(); + if (rst) + { + return "{\"code\":200,\"msg\":\"success\"}"; + } + else + { + return "{\"code\":500,\"msg\":\"更新失败:" + mySql.Message + "\"}"; + } + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + public string AddSkuImgReplace(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + var time = 0; + int.TryParse(RegexUtils.GetStringQuery(ref inputData, "time"), out time); + string time1 = RegexUtils.GetStringQuery(ref inputData, "code"); + if (time1 != EncrypUtil.Encryption(time)) + return "{\"code\":50000,\"msg\":\"校验失败\"}"; + + string user_name = RegexUtils.GetStringQuery(ref inputData, "user_name"); + string img_md5 = RegexUtils.GetStringQuery(ref inputData, "img_md5"); + string img_base64 = RegexUtils.GetStringQuery(ref inputData, "img_base64"); + string img_url = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "img_url")); + string img_type = RegexUtils.GetStringQuery(ref inputData, "img_type")?.Replace("'", "\\'"); + string img_group = RegexUtils.GetStringQuery(ref inputData, "img_group")?.Replace("'", "\\'"); + + if (string.IsNullOrEmpty(user_name)) + { + return "{\"code\":500,\"msg\":\"没有用户名\"}"; + } + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = ""; + + sql = "select id from bxx.sku_img_replace where img_md5='" + img_md5 + "';"; + var bRst = false; + var rst = mySql.ExecuteFirstInt(sql).ParseToLong(); + if (rst <= 0) + { + sql = "insert into bxx.sku_img_replace (img_md5,img_base64,img_url,img_type,img_group) " + + "values ('" + img_md5 + "','" + img_base64 + "','" + img_url + "','" + img_type + "','" + img_group + "');"; + rst = mySql.ExecuteInsertId(sql); + } + if (rst > 0) + { + bRst = true; + } + mySql.Close(); + if (rst > 0 && bRst) + { + return "{\"code\":200,\"msg\":\"success\",\"sku_img_replace_id\":" + rst + "}"; + } + + return "{\"code\":500,\"msg\":\"" + mySql.Message + "\"}"; + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + public string MdySkuImgReplace(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("'", "\\'"); + var id = RegexUtils.GetStringQuery(ref inputData, "db_id")?.Replace("'", "\\'"); + string img_md5 = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "img_md5")); + string img_base64 = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "img_base64")); + string img_url = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "img_url")); + string img_type = RegexUtils.GetStringQuery(ref inputData, "img_type")?.Replace("'", "\\'"); + string img_group = RegexUtils.GetStringQuery(ref inputData, "img_group")?.Replace("'", "\\'"); + + if (string.IsNullOrEmpty(user_name)) + { + return "{\"code\":500,\"msg\":\"没有用户名\"}"; + } + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = "update bxx.sku_img_replace set"; + if (img_md5 != null) + sql += " img_md5='" + img_md5 + "',"; + if (img_base64 != null) + sql += " img_base64='" + img_base64 + "',"; + if (img_url != null) + sql += " img_url='" + img_url + "',"; + if (img_type != null) + sql += " img_type='" + img_type + "',"; + if (img_group != null) + sql += " img_group='" + img_group + "',"; + sql = sql.TrimEnd(','); + sql += " where id=" + id + ";"; + + var rst = mySql.ExecuteNonQuery(sql); + mySql.Close(); + if (rst) + { + return "{\"code\":200,\"msg\":\"success\"}"; + } + else + { + return "{\"code\":500,\"msg\":\"更新失败:" + mySql.Message + "\"}"; + } + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + public string AddSkuImg(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + var time = 0; + int.TryParse(RegexUtils.GetStringQuery(ref inputData, "time"), out time); + string time1 = RegexUtils.GetStringQuery(ref inputData, "code"); + if (time1 != EncrypUtil.Encryption(time)) + return "{\"code\":50000,\"msg\":\"校验失败\"}"; + + string user_name = RegexUtils.GetStringQuery(ref inputData, "user_name").Replace("'", "\\'"); + string img_md5 = RegexUtils.GetStringQuery(ref inputData, "img_md5").Replace("'", "\\'"); + string img_base64 = RegexUtils.GetStringQuery(ref inputData, "img_base64").Replace("'", "\\'"); + string img_url = RegexUtils.GetStringQuery(ref inputData, "img_url").Replace("'", "\\'"); + + if (string.IsNullOrEmpty(user_name)) + { + return "{\"code\":500,\"msg\":\"没有用户名\"}"; + } + + int sku_img_replace_id = 0; + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = ""; + + sql = "select id from bxx.sku_img where img_md5='" + img_md5 + "';"; + var bRst = false; + var rst = mySql.ExecuteFirstInt(sql).ParseToLong(); + if (rst <= 0) + { + sql = "insert into bxx.sku_img (img_md5,img_base64,img_url) " + + "values ('" + img_md5 + "','" + img_base64 + "','" + img_url + "');"; + rst = mySql.ExecuteInsertId(sql); + if (rst > 0) + { + mySql.Close(); + return "{\"code\":200,\"msg\":\"success\",\"insert_id\":" + rst + "}"; + } + } + else + { + sku_img_replace_id = (int)rst; + sql = "update bxx.sku_img set img_url='" + img_url + "' where img_md5='" + img_md5 + "';"; + + bRst = mySql.ExecuteNonQuery(sql); + if (bRst) + { + mySql.Close(); + return "{\"code\":200,\"msg\":\"success\",\"update_id\":" + rst + "}"; + } + } + mySql.Close(); + + return "{\"code\":500,\"msg\":\"" + mySql.Message + "\"}"; + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + public string WxApiGetWxAllCate(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + if (!WXUserService.GetSign(inputData)) + return "{\"code\":999,\"msg\":\"校验失败\"}"; + + //var time = RegexUtils.GetStringQuery(ref inputData, "time").ParseToInt(); + //string time1 = RegexUtils.GetStringQuery(ref inputData, "code"); + //if (time1 != EncrypUtil.Encryption(time)) + // return "{\"code\":50000,\"msg\":\"校验失败\"}"; + string token = RegexUtils.GetStringQuery(ref inputData, "token", true); + return HttpUtils.WxApiGetResponse("https://api.weixin.qq.com/shop/ec/category/all?access_token=" + token, ""); + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + public string WxApiDropshipSearch(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + if (!WXUserService.GetSign(inputData)) + return "{\"code\":999,\"msg\":\"校验失败\"}"; + + string token = RegexUtils.GetStringQuery(ref inputData, "token", true)?.Replace("'", "\\'"); + string order_id = RegexUtils.GetStringQuery(ref inputData, "order_id", true)?.Replace("'", "\\'"); + string status = RegexUtils.GetStringQuery(ref inputData, "status", true)?.Replace("'", "\\'"); + //string data = "{\"search_condition\":{\"order_id\":\"37000204335323251\" },\"page_info\":{\"offset\": 0,\"limit\":10}}"; + string data = "{\"search_condition\":{\"order_id\":\"" + order_id + "\",\"status\":" + status + "}}"; + return HttpUtils.WxApiPostResponse("https://api.weixin.qq.com/channels/ec/order/dropship/search?access_token=" + token, data, ""); + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + /// + /// 微信小店分配订单代发 + /// + /// + /// + public string WxApiDropshipAssign(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + if (!WXUserService.GetSign(inputData)) + return "{\"code\":999,\"msg\":\"校验失败\"}"; + var token = RegexUtils.GetStringQuery(ref inputData, "token")?.Replace("'", "\\'"); + var order_id = RegexUtils.GetStringQuery(ref inputData, "order_id")?.Replace("'", "\\'"); + //var supplier_appid = RegexUtils.GetStringQuery(ref inputData, "supplier_appid")?.Replace("'", "\\'"); + var dropship_product_list = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "dropship_product_list"))?.Replace("'", "\\'"); + //{ + // "order_id": "37012940902395351", + // "supplier_appid": "wxabc", + // "dropship_product_list": [ + // { + // "spu_id": "1253129080", + // "sku_id": "2983950535", + // "product_cnt": 3 + // } + // ] + //} + + //{ "code":0,"data":{ "list":[{ "name":"29供货商","appid":"wxfc630d60a1af6c6f","status":1,"bindAuditStatus":1,"unbindAuditStatus":0,"bindTime":1782903213,"unbindTime":0,"updateTime":1782903213,"actionSource":0,"remark":"","headImg":""}],"totalCount":1} } + + try + { + + JObject obj = new JObject(); + obj["order_id"] = order_id; + obj["supplier_appid"] = "wxfc630d60a1af6c6f"; + JArray array = JArray.Parse(dropship_product_list); + obj["dropship_product_list"] = array; + + return HttpUtils.WxApiPostResponse("https://api.weixin.qq.com/channels/ec/order/dropship/assign?access_token=" + token, JsonUtils.SerializeObject(obj), ""); + } + catch + { + + } + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + public string WxApiDropshipCancel(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + if (!WXUserService.GetSign(inputData)) + return "{\"code\":999,\"msg\":\"校验失败\"}"; + var token = RegexUtils.GetStringQuery(ref inputData, "token")?.Replace("'", "\\'"); + var order_id = RegexUtils.GetStringQuery(ref inputData, "order_id")?.Replace("'", "\\'"); + var ds_order_id = RegexUtils.GetStringQuery(ref inputData, "ds_order_id")?.Replace("'", "\\'"); + var dropship_product_list = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "dropship_product_list"))?.Replace("'", "\\'"); + + try + { + JObject obj = new JObject(); + obj["order_id"] = order_id; + obj["ds_order_id"] = ds_order_id; + JArray array = JArray.Parse(dropship_product_list); + obj["dropship_product_list"] = array; + + return HttpUtils.WxApiPostResponse("https://api.weixin.qq.com/channels/ec/order/dropship/cancel?access_token=" + token, JsonUtils.SerializeObject(obj), ""); + } + catch + { + + } + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + + public string WxApiCategoryClassify(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\":\"校验失败\"}"; + + string post_data = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "post_data")); + string token = RegexUtils.GetStringQuery(ref inputData, "token"); + + return HttpUtils.WxApiPostResponse("https://api.weixin.qq.com/channels/ec/product/category/classify?access_token=" + token, post_data, ""); + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + public string WxApiUploadImage(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\":\"校验失败\"}"; + + string img_base64 = RegexUtils.GetStringQuery(ref inputData, "img_base64")?.Replace("'", "\\'"); + if (!string.IsNullOrEmpty(img_base64)) + { + return WxApiUploadImageBase64(inputData, img_base64); + } + bool is_file = RegexUtils.GetStringQuery(ref inputData, "is_file")?.Replace("'", "\\'").ToLower() == "true"; + if (is_file) + { + return WxApiUploadImageFile(inputData); + } + + + string post_data = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "post_data")); + string token = RegexUtils.GetStringQuery(ref inputData, "token"); + + //https://api.weixin.qq.com/shop/ec/basics/img/upload?access_token=ACCESS_TOKEN&upload_type=1&resp_type=1 + return HttpUtils.WxApiPostResponse("https://api.weixin.qq.com/shop/ec/basics/img/upload?access_token=" + token + + "&upload_type=1&resp_type=1", post_data, ""); + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + public string WxApiUploadImageFile(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\":\"校验失败\"}"; + + string token = RegexUtils.GetStringQuery(ref inputData, "token")?.Replace("'", "\\'"); + string img_url = RegexUtils.GetStringQuery(ref inputData, "img_url")?.Replace("'", "\\'"); + string random_code = RegexUtils.GetStringQuery(ref inputData, "random_code")?.Replace("'", "\\'"); + int img_width = RegexUtils.GetStringQuery(ref inputData, "width").ParseToInt(); + int img_height = RegexUtils.GetStringQuery(ref inputData, "height").ParseToInt(); + bool is_keep_file = RegexUtils.GetStringQuery(ref inputData, "is_keep_file").ParseToBool(); + + string getImgError; + var image = HttpUtils.GetUrlImg(img_url.Replace("https://", "http://"), out getImgError); + if (!string.IsNullOrEmpty(getImgError) || image == null) + { + return "{\"code\":50001,\"msg\":\"获取图片失败:" + getImgError + "\"}"; + } + try + { + if (img_width.IsNullOrZero() || img_height.IsNullOrZero()) + { + img_width = image.Width; + img_height = image.Height; + } + var imageBg = new Bitmap(img_width, img_height); + using (Graphics g = Graphics.FromImage(imageBg)) + { + g.DrawImage(image, new Rectangle(0, 0, imageBg.Width, imageBg.Height), 0, 0, image.Width, image.Height, GraphicsUnit.Pixel); + if (!string.IsNullOrEmpty(random_code) && random_code.ToLower() == "true") + { + g.FillRectangle(new SolidBrush(Color.FromArgb(RandomUtils.GetId(256), RandomUtils.GetId(256), RandomUtils.GetId(256))), + new Rectangle(RandomUtils.GetId(imageBg.Width - 30), RandomUtils.GetId(imageBg.Height - 30), 30, 30)); + } + } + + //string tempImgPath = Path.GetTempPath() + "\\" + RandomUtils.GetWordNumber(8).ToLower(); + string tempImgPath = "C:\\tempImg\\" + RandomUtils.GetWordNumber(8).ToLower(); + if (!Directory.Exists(tempImgPath)) + Directory.CreateDirectory(tempImgPath); + string imgFullPath = tempImgPath + "\\" + EncrypUtil.GetMd5(img_url) + ".jpg"; + imageBg.Save(imgFullPath, System.Drawing.Imaging.ImageFormat.Jpeg); + + var apiUpImgFileRst = HttpUtils.WxApiUploadImgFile(imgFullPath, imageBg.Width, imageBg.Height, token); + if (string.IsNullOrEmpty(apiUpImgFileRst)) + apiUpImgFileRst = "{\"code\":50002,\"msg\":\"图片传输超时\"}"; + + if (!is_keep_file) + { + try + { + // 删除文件夹及其所有内容 + Directory.Delete(tempImgPath, true); // 第二个参数为true表示递归删除所有子文件夹和文件 + } + catch (Exception ex) + { + } + } + return apiUpImgFileRst; + } + catch (Exception ex) + { + return "{\"code\":50001,\"msg\":\"上传图片失败:" + ex.Message + "\"}"; + } + + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + public string WxApiUploadImageBase64(string inputData, string imgBase64) + { + 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\":\"校验失败\"}"; + + string token = RegexUtils.GetStringQuery(ref inputData, "token")?.Replace("'", "\\'"); + string img_url = RegexUtils.GetStringQuery(ref inputData, "img_url")?.Replace("'", "\\'"); + bool is_keep_file = RegexUtils.GetStringQuery(ref inputData, "is_keep_file").ParseToBool(); + + is_keep_file = System.Configuration.ConfigurationManager.ConnectionStrings["IsKeepBase64UploadImgFile"]?.ConnectionString == "1"; + + try + { + byte[] imageBytes = Convert.FromBase64String(imgBase64); + using (MemoryStream ms = new MemoryStream(imageBytes, 0, imageBytes.Length)) + { + // 创建Image对象 + Image imageBg = Image.FromStream(ms, true); + + string tempImgPath = "C:\\tempImg\\" + RandomUtils.GetWordNumber(16).ToLower(); + if (!Directory.Exists(tempImgPath)) + Directory.CreateDirectory(tempImgPath); + string imgFullPath = tempImgPath + "\\" + EncrypUtil.GetMd5(img_url) + ".jpg"; + imageBg.Save(imgFullPath, System.Drawing.Imaging.ImageFormat.Jpeg); + + var apiUpImgFileRst = HttpUtils.WxApiUploadImgFile(imgFullPath, imageBg.Width, imageBg.Height, token); + if (string.IsNullOrEmpty(apiUpImgFileRst)) + apiUpImgFileRst = "{\"code\":50002,\"msg\":\"图片传输超时\"}"; + + if (!is_keep_file) + { + try + { + // 删除文件夹及其所有内容 + Directory.Delete(tempImgPath, true); // 第二个参数为true表示递归删除所有子文件夹和文件 + } + catch (Exception ex) + { + } + } + return apiUpImgFileRst; + } + } + catch (Exception ex) + { + return "{\"code\":50001,\"msg\":\"上传图片失败:" + ex.Message + "\"}"; + } + + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + + + public string AddJSTSku(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + var time = 0; + int.TryParse(RegexUtils.GetStringQuery(ref inputData, "time"), out time); + string time1 = RegexUtils.GetStringQuery(ref inputData, "code"); + if (time1 != EncrypUtil.Encryption(time)) + return "{\"code\":50000,\"msg\":\"校验失败\"}"; + + string user_name = RegexUtils.GetStringQuery(ref inputData, "user_name")?.Replace("'", "\\'"); + if (string.IsNullOrEmpty(user_name)) + return "{\"code\":50000,\"msg\":\"用户不存在\"}"; + + string coid = RegexUtils.GetStringQuery(ref inputData, "coid")?.Replace("'", "\\'"); + string supplierId = RegexUtils.GetStringQuery(ref inputData, "supplierId")?.Replace("'", "\\'"); + string supplierName = RegexUtils.GetStringQuery(ref inputData, "supplierName"); + string skuId = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "skuId"))?.Replace("'", "\\'"); + string itemSpuId = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "itemSpuId"))?.Replace("'", "\\'"); + string pic = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "pic"))?.Replace("'", "\\'"); + string itemName = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "itemName")); + string styleCode = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "styleCode")); + string itemCode = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "itemCode"))?.Replace("'", "\\'"); + string color = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "color"))?.Replace("'", "\\'"); + string spec = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "spec"))?.Replace("'", "\\'"); + string salePrice = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "salePrice"))?.Replace("'", "\\'"); + string supplyPrice = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "supplyPrice"))?.Replace("'", "\\'"); + string stock = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "stock"))?.Replace("'", "\\'"); + string stockTime = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "stockTime"))?.Replace("'", "\\'"); + string weight = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "weight"))?.Replace("'", "\\'"); + string status = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "status"))?.Replace("'", "\\'"); + if (string.IsNullOrEmpty(user_name)) + { + return "{\"code\":500,\"msg\":\"没有用户名\"}"; + } + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = ""; + sql = "insert into "; + sql += "bxx.product_sku_restore "; + sql += "(coid,supplierId,supplierName,skuId,itemSpuId,pic,itemName,styleCode,itemCode,color,spec,stockTime," + + "salePrice,supplyPrice,stock,weight) " + + "values ('" + coid + "','" + supplierId + "','" + supplierName + "','" + skuId + "','" + itemSpuId + "','" + + pic + "','" + itemName + "','" + styleCode + "','" + itemCode + "','" + color + "','" + spec + "','" + stockTime + "'," + + (salePrice.IsNullOrEmpty() ? "null" : salePrice) + "," + supplyPrice + "," + stock + "," + weight + ");"; + + List paramLst = new List(); + //paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "product_json", Value = product_json, }); + //paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "size_json", Value = size_json, }); + var rst = mySql.ExecuteNonQuery(sql, paramLst.ToArray()); + mySql.Close(); + if (rst) + { + return "{\"code\":200,\"msg\":\"success\"}"; + } + else + { + return "{\"code\":500,\"msg\":\"" + mySql.Message + "\"}"; + } + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + public string MdyJSTSku(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + var time = 0; + int.TryParse(RegexUtils.GetStringQuery(ref inputData, "time"), out time); + string time1 = RegexUtils.GetStringQuery(ref inputData, "code"); + if (time1 != EncrypUtil.Encryption(time)) + return "{\"code\":50000,\"msg\":\"校验失败\"}"; + + string user_name = RegexUtils.GetStringQuery(ref inputData, "user_name")?.Replace("'", "\\'"); + if (string.IsNullOrEmpty(user_name)) + return "{\"code\":50000,\"msg\":\"用户不存在\"}"; + + string coid = RegexUtils.GetStringQuery(ref inputData, "coid")?.Replace("'", "\\'"); + string supplierId = RegexUtils.GetStringQuery(ref inputData, "supplierId")?.Replace("'", "\\'"); + string supplierName = RegexUtils.GetStringQuery(ref inputData, "supplierName"); + string skuId = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "skuId"))?.Replace("'", "\\'"); + string itemSpuId = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "itemSpuId"))?.Replace("'", "\\'"); + string pic = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "pic"))?.Replace("'", "\\'"); + string itemName = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "itemName")); + string styleCode = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "styleCode")); + string itemCode = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "itemCode"))?.Replace("'", "\\'"); + string color = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "color"))?.Replace("'", "\\'"); + string spec = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "spec"))?.Replace("'", "\\'"); + string salePrice = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "salePrice"))?.Replace("'", "\\'"); + string supplyPrice = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "supplyPrice"))?.Replace("'", "\\'"); + string stock = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "stock"))?.Replace("'", "\\'"); + string stockTime = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "stockTime"))?.Replace("'", "\\'"); + string weight = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "weight"))?.Replace("'", "\\'"); + string status = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "status"))?.Replace("'", "\\'"); + if (string.IsNullOrEmpty(user_name)) + { + return "{\"code\":500,\"msg\":\"没有用户名\"}"; + } + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = ""; + sql = "update "; + sql += "bxx.product_sku_restore p set "; + if (coid != null) + sql += " p.coid='" + coid + "',"; + if (supplierId != null) + sql += " p.supplierId='" + supplierId + "',"; + if (supplierName != null) + sql += " p.supplierName='" + supplierName + "',"; + if (pic != null) + sql += " p.pic='" + pic + "',"; + if (itemName != null) + sql += " p.itemName='" + itemName + "',"; + if (styleCode != null) + sql += " p.styleCode='" + styleCode + "',"; + if (itemCode != null) + sql += " p.itemCode='" + itemCode + "',"; + if (color != null) + sql += " p.color='" + color + "',"; + if (spec != null) + sql += " p.spec='" + spec + "',"; + if (salePrice != null) + sql += " p.salePrice=" + salePrice + ","; + if (supplyPrice != null) + sql += " p.supplyPrice=" + supplyPrice + ","; + if (stock != null) + sql += " p.stock=" + stock + ","; + if (stockTime != null) + sql += " p.stockTime='" + stockTime + "',"; + if (salePrice != null) + sql += " p.salePrice=" + salePrice + ","; + if (weight != null) + sql += " p.weight='" + weight + "',"; + sql = sql.TrimEnd(','); + sql += " where skuId='" + skuId + "' and itemSpuId='" + itemSpuId + "';"; + + List paramLst = new List(); + //paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "product_json", Value = product_json, }); + //paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "size_json", Value = size_json, }); + var rst = mySql.ExecuteNonQuery(sql, paramLst.ToArray()); + mySql.Close(); + if (rst) + { + return "{\"code\":200,\"msg\":\"success\"}"; + } + else + { + return "{\"code\":500,\"msg\":\"" + mySql.Message + "\"}"; + } + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + public string GetJSTSkuList(string inputData) + { + var timeCalc = DateTime.Now; + 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 version = RegexUtils.GetStringQuery(ref inputData, "version").ParseToInt(); + if (version < (System.Configuration.ConfigurationManager.ConnectionStrings["LimitVersion"]?.ConnectionString).ParseToInt()) + return "{\"code\":1,\"msg\":\"当前版本过于陈旧,请立即升级新版\"}"; + + var user_name = RegexUtils.GetStringQuery(ref inputData, "user_name")?.Replace("'", "\\'"); + if (string.IsNullOrEmpty(user_name)) + return "{\"code\":50000,\"msg\":\"用户不存在\"}"; + + var search_coid = RegexUtils.GetStringQuery(ref inputData, "search_coid")?.Replace("'", "\\'"); + var search_supplierId = RegexUtils.GetStringQuery(ref inputData, "search_supplierId")?.Replace("'", "\\'"); + var search_supplierName = RegexUtils.GetStringQuery(ref inputData, "search_supplierName")?.Replace("'", "\\'"); + var search_skuId = RegexUtils.GetStringQuery(ref inputData, "search_skuId")?.Replace("'", "\\'"); + var search_itemSpuId = RegexUtils.GetStringQuery(ref inputData, "search_itemSpuId")?.Replace("'", "\\'"); + var search_itemName = RegexUtils.GetStringQuery(ref inputData, "search_itemName")?.Replace("'", "\\'"); + var search_styleCode = RegexUtils.GetStringQuery(ref inputData, "search_styleCode")?.Replace("'", "\\'"); + var search_itemCode = RegexUtils.GetStringQuery(ref inputData, "search_itemCode")?.Replace("'", "\\'"); + var search_color = RegexUtils.GetStringQuery(ref inputData, "search_color")?.Replace("'", "\\'"); + var search_spec = RegexUtils.GetStringQuery(ref inputData, "search_spec")?.Replace("'", "\\'"); + var search_status = RegexUtils.GetStringQuery(ref inputData, "search_status")?.Replace("'", "\\'"); + + int page = RegexUtils.GetStringQuery(ref inputData, "page").ParseToInt(); + int page_size = RegexUtils.GetStringQuery(ref inputData, "page_size").ParseToInt(50); + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + + string sql = "select count(*) from bxx.product_sku_restore p where 1=1"; + + string where = ""; + if (!string.IsNullOrEmpty(search_coid)) + where += " and p.coid ='" + search_coid + "'"; + if (!string.IsNullOrEmpty(search_supplierId)) + where += " and p.supplierId ='" + search_supplierId + "'"; + if (!string.IsNullOrEmpty(search_supplierName)) + where += " and p.supplierName ='" + search_supplierName + "'"; + if (!string.IsNullOrEmpty(search_skuId)) + where += " and p.skuId ='" + search_skuId + "'"; + if (!string.IsNullOrEmpty(search_itemSpuId)) + where += " and p.itemSpuId ='" + search_itemSpuId + "'"; + if (!string.IsNullOrEmpty(search_itemName)) + where += " and p.itemName like '%" + search_itemName + "%'"; + if (!string.IsNullOrEmpty(search_styleCode)) + where += " and p.styleCode ='" + search_styleCode + "'"; + if (!string.IsNullOrEmpty(search_itemCode)) + where += " and p.itemCode ='" + search_itemCode + "'"; + if (!string.IsNullOrEmpty(search_color)) + where += " and p.color ='" + search_color + "'"; + if (!string.IsNullOrEmpty(search_spec)) + where += " and p.spec ='" + search_spec + "'"; + if (!string.IsNullOrEmpty(search_status)) + where += " and p.status ='" + search_status + "'"; + + sql += where; + + var count = 0; + count = mySql.ExecuteRowCount(sql); + + DataTable dt; + if (count == 0) + { + dt = new DataTable(); + } + else + { + sql = "select p.* from bxx.product_sku_restore p" + + " where 1=1"; + + //where子句 + sql += where; + sql += " order by p.id desc"; + sql += " limit " + Math.Max(page - 1, 0) * page_size + "," + page_size; + dt = mySql.ExecuteDataTable(sql); + } + + mySql.Close(); + if (dt != null) + { + try + { + List productLst = new List(); + foreach (DataRow row in dt.Rows) + { + JSTListProductSkuInfo prod = new JSTListProductSkuInfo + { + id = Convert.ToInt32(row["id"]), + coid = row["coid"].ToString(), + color = row["color"].ToString(), + itemCode = row["itemCode"].ToString(), + itemName = row["itemName"].ToString(), + itemSpuId = row["itemSpuId"].ToString(), + pic = row["pic"].ToString(), + salePrice = row["salePrice"].ParseToDecimal(), + skuId = row["skuId"].ToString(), + spec = row["spec"].ToString(), + status = row["status"].ToString(), + stock = row["stock"].ParseToInt(), + styleCode = row["styleCode"].ParseToString(), + supplierId = row["supplierId"].ToString(), + supplierName = row["supplierName"].ToString(), + supplyPrice = row["supplyPrice"].ParseToDecimal(), + add_time = Convert.ToDateTime(row["add_time"]), + mdy_time = Convert.ToDateTime(row["mdy_time"]), + stockTime = row["stockTime"].ParseToString().ParseToDateTime(), + weight = row["weight"].ParseToDecimal(), + }; + productLst.Add(prod); + } + JsonSerializerSettings jsonSetting = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }; + var data = JsonUtils.SerializeObjectToString(productLst, jsonSetting); + var seconds = (DateTime.Now - timeCalc).TotalSeconds.ToString("0.000"); + return "{\"code\":200,\"msg\":\"success\",\"data\":" + data + ",\"count\":" + 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 SetRandomCompanyProductConfig(string inputData) + { + var timeCalc = DateTime.Now; + 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\":50000,\"msg\":\"用户不存在\"}"; + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + + string product_group = RegexUtils.GetStringQuery(ref inputData, "product_group")?.Replace("'", "\\'"); + string product_interval = RegexUtils.GetStringQuery(ref inputData, "product_interval")?.Replace("'", "\\'"); + string is_on = RegexUtils.GetStringQuery(ref inputData, "is_on")?.Replace("'", "\\'"); + + string sql = "update bxx.product_com_random set "; + if (product_group != null) + sql += "product_group='" + product_group + "',"; + if (product_interval != null) + sql += "product_interval=" + product_interval + ","; + if (is_on != null) + sql += "is_on=" + is_on + ","; + sql = sql.TrimEnd(','); + sql += " where 1=1;"; + var rst = mySql.ExecuteNonQuery(sql); + mySql.Close(); + if (string.IsNullOrEmpty(mySql.Message)) + { + return "{\"code\":200,\"msg\":\"success\"}"; + } + else + { + return "{\"code\":500,\"msg\":\"" + mySql.Message + "\"}"; + } + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + /// + /// 随机工厂商品 + /// + /// + /// + public string GetRandomCompanyProductConfig(string inputData) + { + var timeCalc = DateTime.Now; + 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\":50000,\"msg\":\"用户不存在\"}"; + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + + string sql = "select p.* from bxx.product_com_random p" + + " where 1=1;"; + var dt = mySql.ExecuteDataTable(sql); + mySql.Close(); + if (dt != null) + { + try + { + string product_group = dt.Rows[0]["product_group"].ParseToString(); + string product_interval = dt.Rows[0]["product_interval"].ParseToString(); + string is_on = dt.Rows[0]["is_on"].ParseToString(); + var seconds = (DateTime.Now - timeCalc).TotalSeconds.ToString("0.000"); + return "{\"code\":200,\"msg\":\"success\"" + + ",\"product_group\":\"" + product_group + "\"" + + ",\"product_interval\":" + product_interval + + ",\"is_on\":" + is_on + + ",\"seconds\":" + seconds + "}"; + } + catch (Exception ex) + { + return "{\"code\":500,\"msg\":\"" + ex.Message + "\"}"; + } + } + else + { + return "{\"code\":500,\"msg\":\"" + mySql.Message + "\"}"; + } + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + public string AddRelation(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 up_spu_id = RegexUtils.GetStringQuery(ref inputData, "up_spu_id")?.Replace("'", "\\'"); + if (string.IsNullOrEmpty(up_spu_id)) + { + return "{\"code\":500,\"msg\":\"缺少上家编号\"}"; + } + var index = RegexUtils.GetStringQuery(ref inputData, "index").ParseToNullableLong(); + if (index == null) + index = Math.Abs(up_spu_id.GetHashCode()) % 128; + var up_goods_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "up_goods_name")); + if (string.IsNullOrEmpty(up_goods_name)) + { + return "{\"code\":500,\"msg\":\"缺少上家商品名称\"}"; + } + var from_site = RegexUtils.GetStringQuery(ref inputData, "from_site")?.Replace("'", "\\'"); + if (string.IsNullOrEmpty(from_site)) + { + return "{\"code\":500,\"msg\":\"缺少关联商品平台\"}"; + } + var goods_id = RegexUtils.GetStringQuery(ref inputData, "goods_id")?.Replace("'", "\\'"); + if (string.IsNullOrEmpty(goods_id)) + { + return "{\"code\":500,\"msg\":\"缺少关联商品编号\"}"; + } + var shop_id = RegexUtils.GetStringQuery(ref inputData, "shop_id")?.Replace("'", "\\'"); + if (string.IsNullOrEmpty(shop_id)) + { + return "{\"code\":500,\"msg\":\"缺少关联店铺编号\"}"; + } + var price_max = RegexUtils.GetStringQuery(ref inputData, "price_max")?.Replace("'", "\\'"); + if (string.IsNullOrEmpty(price_max)) + { + return "{\"code\":500,\"msg\":\"缺少关联最高价格\"}"; + } + var price_min = RegexUtils.GetStringQuery(ref inputData, "price_min")?.Replace("'", "\\'"); + if (string.IsNullOrEmpty(price_min)) + { + return "{\"code\":500,\"msg\":\"缺少关联最低价格\"}"; + } + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + + string sql = "insert into bxx_relation.out_prod_relation_" + index.ParseToString().PadLeft(4, '0') + + " (up_spu_id,up_goods_name,from_site,goods_id,shop_id,price_min,price_max) " + + " values ('" + up_spu_id + "',@up_goods_name,'" + from_site + "','" + + goods_id + "'," + shop_id + "," + price_min + "," + price_max + ");"; + List paramLst = new List(); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "@up_goods_name", Value = up_goods_name, }); + mySql.ExecuteNonQuery(sql, paramLst.ToArray()); + mySql.Close(); + if (mySql.Message.IsNullOrEmpty()) + { + return "{\"code\":200,\"msg\":\"成功\"}"; + } + else + { + return "{\"code\":500,\"msg\":\"失败:" + mySql.Message + "\"}"; + } + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + public string GetRelation(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 up_spu_id = RegexUtils.GetStringQuery(ref inputData, "up_spu_id")?.Replace("'", "\\'"); + if (string.IsNullOrEmpty(up_spu_id)) + { + return "{\"code\":500,\"msg\":\"缺少来源商品编号\"}"; + } + var index = RegexUtils.GetStringQuery(ref inputData, "index").ParseToNullableLong(); + if (index == null) + index = Math.Abs(up_spu_id.GetHashCode()) % 128; + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + + string sql = "select * from bxx_relation.out_prod_relation_" + index.ParseToString().PadLeft(4, '0') + + " where up_spu_id='" + up_spu_id + "' limit 20;"; + var dt = mySql.ExecuteDataTable(sql); + mySql.Close(); + if (mySql.Message.IsNullOrEmpty()) + { + JArray jArr = new JArray(); + foreach (DataRow row in dt.Rows) + { + JObject jObj = new JObject(); + jObj["id"] = row["id"].ParseToInt(); + jObj["up_spu_id"] = row["up_spu_id"].ToString(); + jObj["up_goods_name"] = row["up_goods_name"].ToString(); + jObj["from_site"] = row["from_site"].ToString(); + jObj["goods_id"] = row["goods_id"].ToString(); + jObj["shop_id"] = row["shop_id"].ToString(); + jObj["price_min"] = row["price_min"].ParseToInt(); + jObj["price_max"] = row["price_max"].ParseToInt(); + jObj["add_time"] = row["add_time"].ParseToString().ParseToDateTime(); + jArr.Add(jObj); + } + JsonSerializerSettings jsonSetting = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }; + var data = JsonUtils.SerializeObjectToString(jArr, jsonSetting); + return "{\"code\":200,\"msg\":\"success\",\"data\":" + data + ",\"count\":" + jArr.Count + "}"; + } + else + { + return "{\"code\":500,\"msg\":\"失败:" + mySql.Message + "\"}"; + } + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + public string AddMdyJstProductBan(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + if (!WXUserService.GetSign(inputData)) + return "{\"code\":999,\"msg\":\"校验失败\"}"; + + // 软件用户名 + string coid = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "coid"))?.Replace("'", "\\'"); + int? ban_wx = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "ban_wx"))?.ParseToNullableInt(); + int? ban_pdd = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "ban_pdd"))?.ParseToNullableInt(); + // 收件人 + string user_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "receiver"))?.Replace("'", "\\'"); + if (string.IsNullOrEmpty(coid)) + return "{\"code\":500,\"msg\":\"缺少供应商编号\"}"; + if (ban_wx == null) + return "{\"code\":500,\"msg\":\"缺少设置值\"}"; + if (ban_pdd == null) + return "{\"code\":500,\"msg\":\"缺少设置值\"}"; + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn, true); + + string sql = "SELECT 1 FROM `bxx`.`jst_supplier_ban_platform` where coid='" + coid + "'"; + string where = ""; + sql += where; + var exist = mySql.ExecuteFirstInt(sql); + if (!mySql.Message.IsNullOrEmpty()) + { + mySql.RollBack(); + mySql.Close(); + return "{\"code\":501,\"msg\":\"" + mySql.Message + "\"}"; + } + + if (exist == 0) + { + sql = " INSERT INTO `bxx`.`jst_supplier_ban_platform` (coid,ban_wx,ban_pdd)" + + " VALUES (@coid,@ban_wx,@ban_pdd);"; + } + else + { + sql = "UPDATE `bxx`.`jst_supplier_ban_platform` SET "; + if (ban_wx != null) + sql += " ban_wx=@ban_wx,"; + if (ban_pdd != null) + sql += " ban_pdd=@ban_pdd,"; + sql = sql.TrimEnd(','); + sql += " WHERE coid=@coid;"; + } + + List paramLst = new List(); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "coid", Value = coid, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.Int16, ParameterName = "ban_wx", Value = ban_wx, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.Int16, ParameterName = "ban_pdd", Value = ban_pdd, }); + var rowCnt = mySql.ExecuteAffectedRows(sql, paramLst.ToArray()); + if (!string.IsNullOrEmpty(mySql.Message)) + { + mySql.RollBack(); + mySql.Close(); + return "{\"code\":50003,\"msg\":\"" + mySql.Message + "\",\"data\":\"\"}"; + } + + sql = "UPDATE `bxx`.`product` SET "; + if (ban_wx != null) + sql += " ban_wx=@ban_wx,"; + if (ban_pdd != null) + sql += " ban_pdd=@ban_pdd,"; + sql = sql.TrimEnd(','); + sql += " WHERE (real_coid=@coid or skc_id=@coid) AND product_get_type='厂商直采';"; + rowCnt = mySql.ExecuteAffectedRows(sql, paramLst.ToArray()); + if (!string.IsNullOrEmpty(mySql.Message)) + { + mySql.RollBack(); + mySql.Close(); + return "{\"code\":50003,\"msg\":\"" + mySql.Message + "\",\"data\":\"\"}"; + } + + mySql.Commit(); + mySql.Close(); + return "{\"code\":200,\"msg\":\"success\",\"data\":\"\"}"; + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + public string GetJstProductCoidList(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + var timeCalc = DateTime.Now; + if (!WXUserService.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 coids = RegexUtils.GetStringQuery(ref inputData, "coids")?.Replace("'", "\\'"); + string not_count = RegexUtils.GetStringQuery(ref inputData, "not_count")?.Replace("'", "\\'"); + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + + string tableName = GetProductTableName(inputData); + string sql = ""; + var count = -1; + + //sql = " SELECT COUNT(*) FROM" + + // " (SELECT skc_id as coid FROM " + tableName + " WHERE product_get_type='厂商直采' UNION SELECT real_coid as coid FROM " + tableName + " WHERE product_get_type='厂商直采') as coids" + + // " WHERE 1=1 AND coids.coid != ''"; + sql = "select count(*) FROM (SELECT DISTINCT coids.*,a.after_sale_json,p.from_shop_name,b.ban_wx,b.ban_pdd" + + " FROM (SELECT skc_id as coid FROM " + tableName + " WHERE product_get_type='厂商直采' UNION SELECT real_coid as coid FROM " + tableName + " WHERE product_get_type='厂商直采') as coids" + + " LEFT JOIN wxxd.after_sale as a ON coids.coid=a.coid AND a.is_del = 0" + + " LEFT JOIN " + tableName + " p ON coids.coid=p.skc_id AND p.product_get_type='厂商直采'" + + " LEFT JOIN bxx.jst_supplier_ban_platform b ON coids.coid=b.coid" + + " WHERE 1=1 AND coids.coid != ''"; + string where = ""; + if (coids != null) + where += " AND coids.coid IN ('" + coids.Replace(",", "','") + "')"; + sql += where; + sql += ") as cnt"; + sql += ";"; + + if (not_count != "true") + count = mySql.ExecuteRowCount(sql); + + DataTable dt; + if (count == 0) + { + dt = new DataTable(); + } + else + { + sql = " SELECT DISTINCT coids.*,a.after_sale_json,p.from_shop_name,b.ban_wx,b.ban_pdd" + + " FROM (SELECT skc_id as coid FROM " + tableName + " WHERE product_get_type='厂商直采' UNION SELECT real_coid as coid FROM " + tableName + " WHERE product_get_type='厂商直采') as coids" + + " LEFT JOIN wxxd.after_sale as a ON coids.coid=a.coid AND a.is_del = 0" + + " LEFT JOIN " + tableName + " p ON coids.coid=p.skc_id AND p.product_get_type='厂商直采'" + + " LEFT JOIN bxx.jst_supplier_ban_platform b ON coids.coid=b.coid" + + " WHERE 1=1 AND coids.coid != ''"; + sql += where; + //sql += " ORDER BY coid DESC"; + //sql += " ORDER BY coid ASC"; + sql += " LIMIT " + Math.Max(0, page - 1) * page_size + "," + page_size + ";"; + dt = mySql.ExecuteDataTable(sql); + if (!string.IsNullOrEmpty(mySql.Message)) + { + mySql.Close(); + return "{\"code\":500,\"msg\":\"" + mySql.Message + "\",\"data\":[],\"count\":" + 0 + "}"; + } + } + mySql.Close(); + + if (dt != null) + { + try + { + List coidLst = new List(); + foreach (DataRow row in dt.Rows) + { + var jObj = new JObject(); + var afterSaleJson = row["after_sale_json"].ParseToString(); + var supplier_name = row["from_shop_name"].ParseToString(); + if (string.IsNullOrEmpty(supplier_name)) + supplier_name = RegexUtils.GetStringJson(ref afterSaleJson, "name"); + coidLst.Add(jObj); + jObj["coid"] = row["coid"].ParseToString(); + jObj["supplier_name"] = supplier_name; + jObj["ban_wx"] = row["ban_wx"].ParseToInt(); + jObj["ban_pdd"] = row["ban_pdd"].ParseToInt(); + } + JsonSerializerSettings jsonSetting = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }; + var data = JsonUtils.SerializeObjectToString(coidLst, 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 GetJstProductBanPlatformList(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + var timeCalc = DateTime.Now; + if (!WXUserService.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 coids = RegexUtils.GetStringQuery(ref inputData, "coid")?.Replace("'", "\\'"); + string not_count = RegexUtils.GetStringQuery(ref inputData, "not_count")?.Replace("'", "\\'"); + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + + string sql = ""; + var count = -1; + + sql = "SELECT count(*) FROM `bxx`.`jst_supplier_ban_platform` where 1=1"; + string where = ""; + if (coids != null) + where += " AND coid IN ('" + coids.Replace(",", "','") + "')"; + sql += where; + sql += ";"; + + if (not_count != "true") + count = mySql.ExecuteRowCount(sql); + + DataTable dt; + if (count == 0) + { + dt = new DataTable(); + } + else + { + sql = "SELECT * FROM `bxx`.`jst_supplier_ban_platform` 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 supplierBanPlatformLst = new List(); + foreach (DataRow row in dt.Rows) + { + var jObj = new JObject(); + supplierBanPlatformLst.Add(jObj); + jObj["id"] = row["id"].ParseToInt(); + jObj["coid"] = row["coid"].ParseToString(); + jObj["ban_wx"] = row["ban_wx"].ParseToInt(); + jObj["ban_pdd"] = row["ban_pdd"].ParseToInt(); + } + JsonSerializerSettings jsonSetting = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }; + var data = JsonUtils.SerializeObjectToString(supplierBanPlatformLst, 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 XJGetAiImage(string inputData) + //{ + // if (string.IsNullOrEmpty(inputData)) + // return "{\"code\":19999,\"msg\":\"输入为空\"}"; + + // if (!WXUserService.GetSign(inputData)) + // return "{\"code\":999,\"msg\":\"校验失败\"}"; + + // string image_url = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "image_url"))?.ParseToString(); + // string word = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "word"))?.ParseToString(); + // if (image_url == null) + // return "{\"code\":500,\"msg\":\"缺少图片地址\"}"; + // if (word == null) + // return "{\"code\":500,\"msg\":\"缺少图片文字\"}"; + + // string secret = "sadhjufhe15c4fbvFBvcvds+5sdfds@#%$xsc"; + // string time = TimeUtils.DateTimeToTimestampSeconds(DateTime.Now).ToString(); + // string code = EncrypUtil.GetMd5(secret + time); + + // try + // { + // string url = "http://ai-bs.jiaotian.vip:" + RandomUtils.GetId(20010, 20021) + "/index.php?obj=public/image"; + // string data = "time=" + time + "&code=" + code + "&image_url=" + image_url + "&word=" + word; + // string html = HttpUtils.e57GetResponse(url, ""); + // return html; + // } + // catch (Exception ex) + // { + // return "{\"code\":50001,\"msg\":\"" + ex.Message + "\"}"; + // } + //} + + public string IsGetWXRecommendHotProd(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + if (!WXUserService.GetSign(inputData)) + return "{\"code\":999,\"msg\":\"校验失败\"}"; + + var isGetReturn = System.Configuration.ConfigurationManager.ConnectionStrings["GetWXRecommendHotProd"]?.ConnectionString; + var isGetOnce = System.Configuration.ConfigurationManager.ConnectionStrings["GetWXRecommendHotProd"]?.ConnectionString; + var minViewUv = (System.Configuration.ConfigurationManager.ConnectionStrings["GetWXRecommendHotProdMinViewUv"]?.ConnectionString).ParseToInt(500); + var getInterval = (System.Configuration.ConfigurationManager.ConnectionStrings["GetWXRecommendHotProdInterval"]?.ConnectionString).ParseToInt(3); + return "{\"code\":200,\"is_get\":\"" + isGetReturn + "\",\"isGetOnce\":\"" + isGetOnce + "\"," + + "\"minViewUv\":" + minViewUv + ",\"getViewUvInterval\":" + getInterval + "}"; + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + } +} + + +/* + List paramLst = new List(); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "spu_id", Value = spu_id, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "skc_id", Value = skc_id, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "cat_id", Value = cat_id, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "cat_name", Value = cat_name, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "product_name", Value = product_name, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "ext_code", Value = ext_code, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "main_img", Value = main_img, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "product_json", Value = product_json, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "size_json", Value = size_json, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "notes", Value = notes.ParseToString(), }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "product_md5", Value = product_md5, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "add_time", Value = add_time, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "mdy_time", Value = mdy_time, }); + rst = mySql.ExecuteInsertId(sql, paramLst.ToArray());*/ + + + + + diff --git a/StoreHub.KJDWebService/Services/BXXProductThirdService.cs b/StoreHub.KJDWebService/Services/BXXProductThirdService.cs new file mode 100644 index 0000000..5e851ee --- /dev/null +++ b/StoreHub.KJDWebService/Services/BXXProductThirdService.cs @@ -0,0 +1,751 @@ +using StoreHub.KJDWebService.Models; +using StoreHub.Framework.Repositorys; +using Microsoft.Extensions.Configuration; +using StoreHub.KJDWebService.Commons; +using MySql.Data.MySqlClient; +using NaiBa.Util.Extension; +using System; +using System.Collections.Generic; +using System.Data; +using System.Linq; +using System.Text.RegularExpressions; + +namespace StoreHub.KJDWebService.Services +{ + public class BXXProductThirdService : ServiceBase + { + public BXXProductThirdService(SqlRepository sqlRepository, IConfiguration configuration) : base(sqlRepository, configuration) + { + } + public string AddProduct(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + var time = 0; + int.TryParse(RegexUtils.GetStringQuery(ref inputData, "time"), out time); + string time1 = RegexUtils.GetStringQuery(ref inputData, "code"); + if (time1 != EncrypUtil.Encryption(time)) + return "{\"code\":50000,\"msg\":\"校验失败\"}"; + + string user_name = RegexUtils.GetStringQuery(ref inputData, "user_name"); + string from_shop_id = RegexUtils.GetStringQuery(ref inputData, "from_shop_id"); + string spu_id = RegexUtils.GetStringQuery(ref inputData, "spu_id"); + string skc_id = RegexUtils.GetStringQuery(ref inputData, "skc_id"); + string cat_id = RegexUtils.GetStringQuery(ref inputData, "cat_id"); + string cat_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "cat_name")); + string ext_code = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "ext_code")); + string product_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "product_name")); + string product_json = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "product_json")); + string size_json = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "size_json")); + string main_img = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "main_img")); + string notes = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "notes")); + + if (string.IsNullOrEmpty(user_name)) + { + return "{\"code\":500,\"msg\":\"没有用户名\"}"; + } + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = ""; + var json_ids = RegexUtils.GetMatchRegex(ref product_json, "(\"id\":\\d{8,14})"); // 取商品json数据里不同签名的部分 + var product_json_replace = product_json; + foreach (Match json_id in json_ids) + { + product_json_replace = product_json_replace.Replace(json_id.Value, "\"id\":0"); + } + var product_md5 = EncrypUtil.GetMd5(product_json_replace + size_json); + sql = "select id from bxx.third_product where product_md5='" + product_md5 + "';"; + var rst = mySql.ExecuteFirstInt(sql).ParseToLong(); + if (rst <= 0) + { + //sql = "insert into bxx.third_product (from_shop_id,spu_id,skc_id,cat_id,cat_name,product_name,ext_code,main_img,product_json,size_json,notes,product_md5,add_time,mdy_time) " + + // "values ('" + from_shop_id + "','" + spu_id + "','" + skc_id + "','" + cat_id + "','" + cat_name + "','" + product_name + "','" + + // ext_code + "','" + main_img + "','" + product_json + "','" + size_json + "','" + notes + "','" + product_md5 + "','" + + // DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "','" + + // DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "');"; + //rst = mySql.ExecuteInsertId(sql); + + sql = "insert into bxx.third_product (from_shop_id,spu_id,skc_id,cat_id,cat_name,product_name," + + "ext_code,main_img,product_json,size_json,notes,product_md5,add_time,mdy_time) " + + "values (@from_shop_id,@spu_id,@skc_id,@cat_id,@cat_name,@product_name," + + "@ext_code,@main_img,@product_json,@size_json,@notes,@product_md5," + + "@add_time,@mdy_time);"; + string add_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); + string mdy_time = add_time; + List paramLst = new List(); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "@from_shop_id", Value = from_shop_id, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "@spu_id", Value = spu_id, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "@skc_id", Value = skc_id, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "@cat_id", Value = cat_id, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "@cat_name", Value = cat_name, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "@product_name", Value = product_name, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "@ext_code", Value = ext_code, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "@main_img", Value = main_img, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "@product_json", Value = product_json, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "@size_json", Value = size_json, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "@notes", Value = notes.ParseToString(), }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "@product_md5", Value = product_md5, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "@add_time", Value = add_time, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "@mdy_time", Value = mdy_time, }); + rst = mySql.ExecuteInsertId(sql, paramLst.ToArray()); + mySql.Close(); + } + if (rst > 0) + { + return "{\"code\":200,\"msg\":\"success\",\"id\":" + rst + "}"; + } + else + { + return "{\"code\":500,\"msg\":\"" + mySql.Message + "\"}"; + } + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + public string GetProductList(string inputData, bool isDetail = false) + { + 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("'","\\'"); + var password = RegexUtils.GetStringQuery(ref inputData, "password")?.Replace("'", "\\'"); + var from_shop_id = RegexUtils.GetStringQuery(ref inputData, "from_shop_id")?.Replace("'", "\\'"); + var search_spu = RegexUtils.GetStringQuery(ref inputData, "search_spu")?.Replace("'", "\\'"); + var search_skc = RegexUtils.GetStringQuery(ref inputData, "search_skc")?.Replace("'", "\\'"); + var search_cat = RegexUtils.GetStringQuery(ref inputData, "search_cat")?.Replace("'", "\\'"); + var search_ext_code = RegexUtils.GetStringQuery(ref inputData, "search_ext_code")?.Replace("'", "\\'"); + var search_prod_name = RegexUtils.GetStringQuery(ref inputData, "search_prod_name")?.Replace("'", "\\'"); + var search_notes = RegexUtils.GetStringQuery(ref inputData, "search_notes")?.Replace("'", "\\'"); + var search_db_ids = RegexUtils.GetStringQuery(ref inputData, "search_db_ids")?.Replace("'", "\\'"); + + int page = RegexUtils.GetStringQuery(ref inputData, "page").ParseToInt(); + int page_size= RegexUtils.GetStringQuery(ref inputData, "page_size").ParseToInt(50); + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + + string sql = "select count(id) from bxx.third_product where 1=1"; + + string where = ""; + if (!string.IsNullOrWhiteSpace(search_spu)) + where += " and spu_id like '%" + search_spu + "%'"; + if (!string.IsNullOrWhiteSpace(search_skc)) + where += " and skc_id like '%" + search_skc + "%'"; + if (!string.IsNullOrWhiteSpace(search_cat)) + where += " and cat_name like '%" + search_cat + "%'"; + if (!string.IsNullOrWhiteSpace(search_ext_code)) + where += " and ext_code like '%" + search_ext_code + "%'"; + if (!string.IsNullOrWhiteSpace(search_prod_name)) + where += " and product_name like '%" + search_prod_name + "%'"; + if (!string.IsNullOrWhiteSpace(search_notes)) + where += " and notes like '%" + search_notes + "%'"; + if (!string.IsNullOrEmpty(search_db_ids)) + where += " and id in (" + search_db_ids + ")"; + sql += where; + + var count = mySql.ExecuteRowCount(sql); + + DataTable dt; + if (count == 0) + { + dt = new DataTable(); + } + else + { + if (isDetail) + sql = "select * from bxx.third_product where 1=1"; + else + sql = "select id,from_shop_id,spu_id,skc_id,cat_id,cat_name,change_cat_id,change_cat_name,ext_code,product_name,main_img,notes," + + "add_time,mdy_time from bxx.third_product where 1=1"; + + sql += where; + + sql += " order by id desc"; + sql += " limit " + Math.Max(page - 1, 0) * page_size + "," + page_size; + dt = mySql.ExecuteDataTable(sql); + } + + mySql.Close(); + if (dt != null) + { + try + { + List productLst = new List(); + foreach (DataRow row in dt.Rows) + { + DBProductResultParam prod = new DBProductResultParam + { + id = Convert.ToInt32(row["id"]), + from_shop_id = row["from_shop_id"].ToString(), + skc_id = row["skc_id"].ToString(), + spu_id = row["spu_id"].ToString(), + cat_id = row["cat_id"].ToString(), + cat_name = row["cat_name"].ToString(), + change_cat_id = row["change_cat_id"].ToString(), + change_cat_name = row["change_cat_name"].ToString(), + product_name = row["product_name"].ToString(), + main_img = row["main_img"].ToString(), + ext_code = row["ext_code"].ToString(), + //product_json = row["product_json"].ToString(), + //size_json = row["size_json"].ToString(), + add_time = Convert.ToDateTime(row["add_time"]), + mdy_time = Convert.ToDateTime(row["mdy_time"]), + notes = row["notes"].ToString(), + }; + if (isDetail) + { + prod.product_json = row["product_json"].ToString(); + prod.size_json = row["size_json"].ToString(); + } + productLst.Add(prod); + } + var data = JsonUtils.SerializeObjectToString(productLst); + return "{\"code\":200,\"msg\":\"success\",\"data\":" + data + ",\"count\":" + count + "}"; + } + 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 DelDbProd(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("'", "\\'"); + var id = RegexUtils.GetStringQuery(ref inputData, "db_id")?.Replace("'", "\\'"); + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = "delete from bxx.third_product where id='" + + id + "'"; + + var rst = mySql.ExecuteNonQuery(sql); + mySql.Close(); + if (rst) + { + return "{\"code\":200,\"msg\":\"success\"}"; + } + else + return "{\"code\":500,\"msg\":\"删除失败:" + mySql.Message + "\"}"; + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + public string MdyProductCategory(string inputData, bool isAdmin = false) + { + 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("'", "\\'"); + var id = RegexUtils.GetStringQuery(ref inputData, "db_id")?.Replace("'", "\\'"); + string change_cat_id = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "change_cat_id"))?.Replace("'", "\\'"); + string change_cat_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "change_cat_name"))?.Replace("'", "\\'"); + + if (string.IsNullOrEmpty(user_name)) + { + return "{\"code\":500,\"msg\":\"没有用户名\"}"; + } + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = "update bxx.third_product set"; + if (change_cat_id != null) + sql += " change_cat_id='" + change_cat_id + "',"; + if (change_cat_name != null) + sql += " change_cat_name='" + change_cat_name + "',"; + sql = sql.TrimEnd(','); + sql += " where id=" + id + ";"; + + var rst = mySql.ExecuteNonQuery(sql); + mySql.Close(); + if (rst) + { + return "{\"code\":200,\"msg\":\"success\"}"; + } + else + { + return "{\"code\":500,\"msg\":\"更新失败:" + mySql.Message + "\"}"; + } + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + + public string AddUserSelectProduct(string inputData, bool isAdmin = false) + { + 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 out_product_Id = RegexUtils.GetStringQuery(ref inputData, "out_product_id")?.Replace("'", "\\'"); + var shop_id = RegexUtils.GetStringQuery(ref inputData, "shop_id")?.Replace("'", "\\'"); + var shop_account = RegexUtils.GetStringQuery(ref inputData, "shop_account")?.Replace("'", "\\'"); + var user_name = RegexUtils.GetStringQuery(ref inputData, "main_user_name")?.Replace("'", "\\'"); + var sub_user_name = RegexUtils.GetStringQuery(ref inputData, "sub_user_name")?.Replace("'", "\\'"); + var notes = RegexUtils.GetStringQuery(ref inputData, "notes")?.Replace("'", "\\'"); + var status = RegexUtils.GetStringQuery(ref inputData, "status")?.Replace("'", "\\'"); + var add_product_remaining = RegexUtils.GetStringQuery(ref inputData, "add_product_remaining").ParseToInt(); + + if (string.IsNullOrEmpty(user_name)) + { + return "{\"code\":500,\"msg\":\"没有用户名\"}"; + } + if (string.IsNullOrEmpty(shop_id)) + { + return "{\"code\":500,\"msg\":\"没有店铺信息\"}"; + } + + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = "insert into bxx.third_product_select (out_product_Id,shop_id,shop_account,user_name,sub_user_name,notes,status,add_time,mdy_time) " + + "values ('" + out_product_Id + "','" + shop_id + "','" + shop_account + "','" + user_name + "','" + sub_user_name + "','" + + notes + "','" + status + "','" + + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "','" + + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "');"; + if (add_product_remaining > 0) + { + add_product_remaining = add_product_remaining - 1; + sql += "\r\n"; + sql += "update bxx.shop set add_product_remaining=" + add_product_remaining + " where shop_id='" + shop_id + "';"; + //sql += "update bxx.shop_add_prod_count set add_product_remaining=" + add_product_remaining + " where shop_id=" + shop_id + ";"; + sql += "INSERT INTO bxx.shop_add_prod_count(shop_id, add_product_remaining) VALUES('" + shop_id + "'," + add_product_remaining + ")" + + "ON DUPLICATE KEY UPDATE add_product_remaining=VALUES(add_product_remaining)"; + } + 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 MdyUserSelectProductStatus(string inputData, bool isAdmin = false) + { + 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("'", "\\'"); + var draft_id = RegexUtils.GetStringQuery(ref inputData, "draft_id")?.Replace("'", "\\'"); + var up_spu_id = RegexUtils.GetStringQuery(ref inputData, "up_spu_id")?.Replace("'", "\\'"); + var shop_id = RegexUtils.GetStringQuery(ref inputData, "shop_id")?.Replace("'", "\\'"); + var status = RegexUtils.GetStringQuery(ref inputData, "status")?.Replace("'", "\\'"); + var add_times = RegexUtils.GetStringQuery(ref inputData, "add_times")?.Replace("'", "\\'"); + + long l_draft_id = draft_id.ParseToLong(); + long l_spu_map_table_id = l_draft_id % 128; + long l_select_map_table_id = id.ParseToLong() % 64; + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = ""; + // 使用事务一次提交多个sql操作 + //sql += "set @@autocommit=0;\r\n"; + sql += "START TRANSACTION;\r\n"; + if (!string.IsNullOrEmpty(up_spu_id) && !string.IsNullOrEmpty(draft_id)) + { + sql += "insert into kjd_map.spu_map_" + l_spu_map_table_id + + " (draft_id,from_spu_id,shop_id) values(" + draft_id + "," + up_spu_id + ",'" + shop_id + "');\r\n"; + sql += "insert into kjd_map.product_third_select_map_" + l_select_map_table_id + + " (product_id,product_select_db_id,shop_id) values(" + draft_id + "," + id + ",'" + shop_id + "');\r\n"; + } + sql += "update bxx.third_product_select set"; + if (draft_id != null) + sql += " draft_id='" + draft_id + "',"; + if (status != null) + sql += " status='" + status + "',"; + if (status == "已上传") + sql += " add_times=add_times+1,"; + sql += " mdy_time='" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "',"; + sql = sql.TrimEnd(','); + sql += " where id=" + id + ";\r\n"; + var rst = mySql.ExecuteNonQuery(sql); + string errMsg = mySql.Message; + if (string.IsNullOrEmpty(errMsg)) + sql = "COMMIT;"; + else + sql = "ROLLBACK;"; + mySql.ExecuteNonQuery(sql); + mySql.Close(); + if (rst) + { + return "{\"code\":200,\"msg\":\"success\"}"; + } + else + { + return "{\"code\":500,\"msg\":\"" + errMsg + "\"}"; + } + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + public string GetUserSelectProductList(string inputData, bool isAdmin = false) + { + 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\":500,\"msg\":\"没有用户名\"}"; + } + + var shop_ids = RegexUtils.GetStringQuery(ref inputData, "shop_ids")?.Replace("'", "\\'"); + var search_shop_id = RegexUtils.GetStringQuery(ref inputData, "search_shop_id")?.Replace("'", "\\'"); + var search_shop_account = RegexUtils.GetStringQuery(ref inputData, "search_shop_account"); + var search_spu = RegexUtils.GetStringQuery(ref inputData, "search_spu")?.Replace("'", "\\'"); + var search_skc = RegexUtils.GetStringQuery(ref inputData, "search_skc")?.Replace("'", "\\'"); + var search_cat = RegexUtils.GetStringQuery(ref inputData, "search_cat")?.Replace("'", "\\'"); + var search_ext_code = RegexUtils.GetStringQuery(ref inputData, "search_ext_code")?.Replace("'", "\\'"); + var search_prod_name = RegexUtils.GetStringQuery(ref inputData, "search_prod_name"); + var search_notes = RegexUtils.GetStringQuery(ref inputData, "search_notes")?.Replace("'", "\\'"); + var search_user_notes = RegexUtils.GetStringQuery(ref inputData, "search_user_notes")?.Replace("'", "\\'"); + var search_db_ids = RegexUtils.GetStringQuery(ref inputData, "search_db_ids")?.Replace("'", "\\'"); + var search_sub_sa_name = RegexUtils.GetStringQuery(ref inputData, "search_sub_sa_name")?.Replace("'", "\\'"); + var status = RegexUtils.GetStringQuery(ref inputData, "status")?.Replace("'", "\\'"); + var operate_sub_sa_name = RegexUtils.GetStringQuery(ref inputData, "operate_sub_sa_name")?.Replace("'", "\\'"); + + var no_sub_sa = RegexUtils.GetStringQuery(ref inputData, "no_sub_sa")?.Replace("'", "\\'"); + + int page = RegexUtils.GetStringQuery(ref inputData, "page").ParseToInt(); + int page_size = RegexUtils.GetStringQuery(ref inputData, "page_size").ParseToInt(50); + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + + string sql = "select count(s.id) from bxx.third_product_select s " + + "left join bxx.third_product p on s.out_product_id=p.id " + + "left join bxx.user u on s.operate_sub_sa_name=u.user_name " + + "where 1=1"; + + string where = ""; + if (!isAdmin) + where += " and (s.user_name='" + user_name + "' or s.sub_user_name like'%" + user_name + "%')"; + if (!string.IsNullOrEmpty(operate_sub_sa_name)) + { + where += " and s.operate_sub_sa_name = '" + operate_sub_sa_name + "'"; + } + if (no_sub_sa == "true") + where += " and s.operate_sub_sa_name is null"; + if (!string.IsNullOrEmpty(search_db_ids)) + where += " and s.id in (" + search_db_ids + ")"; + if (!string.IsNullOrEmpty(shop_ids)) + where += " and s.shop_id in (" + shop_ids + ")"; + if (!string.IsNullOrWhiteSpace(status)) + where += " and s.status = '" + status + "'"; + if (!string.IsNullOrWhiteSpace(search_shop_id)) + where += " and s.shop_id like '%" + search_shop_id + "%'"; + if (!string.IsNullOrWhiteSpace(search_shop_account)) + where += " and s.shop_account like @search_shop_account"; + if (!string.IsNullOrWhiteSpace(search_notes)) + { + //核价成功 重复 核价成功(重复) + if (search_notes == "无备注") + where += " and s.notes = ''"; + else if (search_notes == "重复") + where += " and s.notes like '%重复%' and s.notes not like '%核价成功%' and s.notes not like '%核价通过%'"; + else if (search_notes == "核价成功") + where += " and (s.notes like '%核价成功%' or s.notes like '%核价通过%') and s.notes not like '%重复%'"; + else if (search_notes == "核价成功(重复)") + where += " and (s.notes like '%核价成功%' or s.notes like '%核价通过%') and s.notes like '%重复%'"; + else + where += " and s.notes like '%" + search_notes + "%'"; + } + if (!string.IsNullOrWhiteSpace(search_user_notes)) + where += " and s.user_notes like '%" + search_user_notes + "%'"; + if (!string.IsNullOrWhiteSpace(search_spu)) + where += " and p.spu_id like '%" + search_spu + "%'"; + if (!string.IsNullOrWhiteSpace(search_skc)) + where += " and p.skc_id like '%" + search_skc + "%'"; + if (!string.IsNullOrWhiteSpace(search_cat)) + where += " and p.cat_name like '%" + search_cat + "%'"; + if (!string.IsNullOrWhiteSpace(search_ext_code)) + where += " and p.ext_code like '%" + search_ext_code + "%'"; + if (!string.IsNullOrWhiteSpace(search_prod_name)) + where += " and p.product_name like @search_prod_name"; + if (!string.IsNullOrEmpty(search_sub_sa_name)) + { + where += " and (s.operate_sub_sa_name like '%" + search_sub_sa_name + "%'"; + where += " or u.nick_name like '%" + operate_sub_sa_name + "%')"; + } + + sql += where; + + List paramLst = new List(); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "@search_shop_account", Value = "%" + search_shop_account + "%", }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "@search_prod_name", Value = "%" + search_prod_name + "%", }); + + var count = mySql.ExecuteRowCount(sql, paramLst.ToArray()); + + DataTable dt; + if (count == 0) + { + dt = new DataTable(); + } + else + { + //if (isDetail) + //sql = "select * from bxx.third_product_select where 1=1"; + //else + sql = "select s.id,s.out_product_id,s.shop_id,s.shop_account,s.user_name," + + "s.sub_user_name,s.notes,s.user_notes,s.status,s.draft_id,s.add_times,s.add_time,s.mdy_time," + + "s.fission_product_name,s.operate_sub_sa_name,s.add_sub_sa_time," + + "p.from_shop_id,p.spu_id,p.skc_id,p.cat_id,p.cat_name,p.change_cat_id,p.change_cat_name,p.ext_code,p.product_name,p.main_img," + + "u.nick_name as operate_sub_sa_nick " + + "from bxx.third_product_select s left join bxx.third_product p on s.out_product_id=p.id " + + "left join bxx.user u on u.user_name=s.operate_sub_sa_name " + + "where 1=1"; + + sql += where; // where子句 + + sql += " order by id desc"; + sql += " limit " + Math.Max(page - 1, 0) * page_size + "," + page_size; + dt = mySql.ExecuteDataTable(sql, paramLst.ToArray()); + } + + mySql.Close(); + if (dt != null) + { + try + { + List productLst = new List(); + foreach (DataRow row in dt.Rows) + { + ProductSelectResultParam prodSelect = new ProductSelectResultParam() + { + id = row["id"].ParseToInt(), + out_product_Id = row["out_product_Id"].ParseToString(), + shop_account = row["shop_account"].ParseToString(), + shop_id = row["shop_id"].ParseToString(), + status = row["status"].ParseToString(), + sub_user_name = row["sub_user_name"].ParseToString(), + user_name = row["user_name"].ParseToString(), + cat_id = row["cat_id"].ParseToString(), + cat_name = row["cat_name"].ParseToString(), + change_cat_id = row["change_cat_id"].ParseToString(), + change_cat_name = row["change_cat_name"].ParseToString(), + product_name = row["product_name"].ParseToString(), + main_img = row["main_img"].ParseToString(), + ext_code = row["ext_code"].ParseToString(), + add_time = Convert.ToDateTime(row["add_time"]), + mdy_time = Convert.ToDateTime(row["mdy_time"]), + notes = row["notes"].ParseToString(), + draft_id = row["draft_id"].ParseToString(), + add_times = row["add_times"].ParseToInt(), + skc_id = row["skc_id"].ToString(), + spu_id = row["spu_id"].ToString(), + operate_sub_sa_name = row["operate_sub_sa_name"].ToString(), + operate_sub_sa_nick = row["operate_sub_sa_nick"].ToString(), + fission_product_name = row["fission_product_name"].ToString(), + user_notes = row["user_notes"].ToString(), + from_shop_id = row["from_shop_id"].ToString(), + //product_json = row["product_json"].ToString(), + //size_json = row["size_json"].ToString(), + }; + prodSelect.add_sub_sa_time = row["add_sub_sa_time"] as DateTime?; + productLst.Add(prodSelect); + } + var data = JsonUtils.SerializeObjectToString(productLst); + return "{\"code\":200,\"msg\":\"success\",\"data\":" + data + ",\"count\":" + count + "}"; + } + 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 DelSelectProd(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("'", "\\'"); + var id = RegexUtils.GetStringQuery(ref inputData, "db_id")?.Replace("'", "\\'"); + + if (string.IsNullOrEmpty(user_name)) + { + return "{\"code\":500,\"msg\":\"没有用户名\"}"; + } + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = "delete from bxx.third_product_select where id='" + + id + "'"; + + var rst = mySql.ExecuteNonQuery(sql); + mySql.Close(); + if (rst) + { + return "{\"code\":200,\"msg\":\"success\"}"; + } + else + return "{\"code\":500,\"msg\":\"删除失败:" + mySql.Message + "\"}"; + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + /// + /// 设置上传商品的二级超管 + /// + /// + public string SetSelectProductSubSa(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 shop_id = RegexUtils.GetStringQuery(ref inputData, "shop_id")?.Replace("'", "\\'"); + var operate_sub_sa_name = RegexUtils.GetStringQuery(ref inputData, "operate_sub_sa_name")?.Replace("'", "\\'"); + var status = RegexUtils.GetStringQuery(ref inputData, "status")?.Replace("'", "\\'"); + + if (string.IsNullOrEmpty(id) && string.IsNullOrEmpty(shop_id)) + { + return "{\"code\":50002,\"msg\":\"未选择任何待上传\"}"; + } + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = "update bxx.third_product_select 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(shop_id)) + sql += " where shop_id in ('" + shop_id.Replace(",","','") + "')"; + else + sql += " where 1=2"; + if(!string.IsNullOrEmpty(status)) + sql += " and status='" + status + "';"; + 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 MdyProductSelectNotes(string inputData, bool isAdmin = false) + { + 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 id = RegexUtils.GetStringQuery(ref inputData, "db_id"); + string notes = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "notes")); + string user_notes = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "user_notes")); + string fission_product_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "fission_product_name")); + + if (string.IsNullOrEmpty(user_name)) + { + return "{\"code\":500,\"msg\":\"没有用户名\"}"; + } + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = "update bxx.third_product_select set"; + if (notes != null) + sql += " notes=@notes,"; + if (user_notes != null) + sql += " user_notes=@user_notes,"; + if (fission_product_name != null) + sql += " fission_product_name=@fission_product_name,"; + sql = sql.TrimEnd(','); + sql += " where id=@id;"; + + List paramLst = new List(); + paramLst.Add(new MySqlParameter() { DbType = DbType.Int32, ParameterName = "@id", Value = id, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "@fission_product_name", Value = fission_product_name, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "@user_notes", Value = user_notes, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "@notes", Value = notes, }); + + var rst = mySql.ExecuteNonQuery(sql, paramLst.ToArray()); + mySql.Close(); + if (rst) + { + return "{\"code\":200,\"msg\":\"success\"}"; + } + else + { + return "{\"code\":500,\"msg\":\"更新失败:" + mySql.Message + "\"}"; + } + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + } +} + + + + diff --git a/StoreHub.KJDWebService/Services/BXXShopService.cs b/StoreHub.KJDWebService/Services/BXXShopService.cs new file mode 100644 index 0000000..d2aabef --- /dev/null +++ b/StoreHub.KJDWebService/Services/BXXShopService.cs @@ -0,0 +1,1451 @@ +using StoreHub.KJDWebService.Models; +using StoreHub.Framework.Repositorys; +using Microsoft.Extensions.Configuration; +using StoreHub.KJDWebService.Models.ShopModel; +using StoreHub.KJDWebService.Commons; +using MySql.Data.MySqlClient; +using NaiBa.Util.Extension; +using Newtonsoft.Json.Linq; +using System; +using System.Collections.Generic; +using System.Data; +using System.Drawing; +using System.Linq; + +namespace StoreHub.KJDWebService.Services +{ + public class BXXShopService : ServiceBase + { + public BXXShopService(SqlRepository sqlRepository, IConfiguration configuration) : base(sqlRepository, configuration) + { + } + public string GetPddClientInfo(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + var time = 0; + int.TryParse(RegexUtils.GetStringQuery(ref inputData, "time"), out time); + string time1 = RegexUtils.GetStringQuery(ref inputData, "code"); + if (time1 != EncrypUtil.Encryption(time)) + return "{\"code\":50000,\"msg\":\"校验失败\"}"; + + var mobile = RegexUtils.GetStringQuery(ref inputData, "mobile")?.Replace("'", "\\'"); + var password = RegexUtils.GetStringQuery(ref inputData, "password")?.Replace("'", "\\'"); + int r2 = 0; + int.TryParse(RegexUtils.GetStringQuery(ref inputData, "r2"), out r2); + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = "select * from bxx.user where user_name='" + + mobile + "' and password='" + password + "'"; + + var dt = mySql.ExecuteDataTable(sql); + mySql.Close(); + if (dt == null) + { + return "{\"code\":500,\"msg\":\"用户不存在\"}"; + } + + JArray jArr = new JArray(); + + JObject obj1 = new JObject(); + obj1["describe"] = "貔貅管家"; + obj1["client_id"] = "ad502ec19e0c49ab9df14f83494e153c"; + obj1["client_secret"] = "bd52aba51737d03fc073711d386b3b0779d010ad"; + obj1["market_id"] = 84862; + //https://fuwu.pinduoduo.com/service-market/auth?response_type=code&client_id=ad502ec19e0c49ab9df14f83494e153c&redirect_uri=http%3A%2F%2Fpo.e57.cn%2Flogin%3Fsource%3Dpdd_code_pixiu + //obj1["redirect_uri"] = "http%3A%2F%2Fpo.e57.cn%2Flogin%3Fsource%3Dpdd_code"; + obj1["redirect_uri"] = "http%3A%2F%2Fpo.e57.cn%2Flogin%3Fsource%3Dpdd_code_pixiu"; + obj1["is_current"] = false; + //jArr.Add(obj1); + + JObject obj2 = new JObject(); + obj2["describe"] = "小红椒商品管理"; + obj2["client_id"] = "48e76c60853d47d8a4e2e631b6db26b5"; + obj2["client_secret"] = "b2a5f9eeb36d192ed035f023eaf9ce5280aac397"; + obj2["market_id"] = 84690; + obj2["redirect_uri"] = "http%3A%2F%2Fxtjpd.jiaotian.vip%2Fpdd_token.html"; + obj2["is_current"] = true; + jArr.Add(obj2); + + return "{\"code\":200,\"msg\":\"success\",\"data\":" + JsonUtils.SerializeObject(jArr) + "}"; + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + public string GetShopClientInfo(string inputData, bool isAdmin = false) + { + if (!string.IsNullOrEmpty(inputData)) + { + var time = 0; + int.TryParse(RegexUtils.GetStringQuery(ref inputData, "time"), out time); + 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"); + if (string.IsNullOrEmpty(user_name)) + { + return "{\"code\":50001,\"msg\":\"没有用户名\"}"; + } + + 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 page = RegexUtils.GetStringQuery(ref inputData, "page").ParseToInt(); + var page_size = RegexUtils.GetStringQuery(ref inputData, "page_size").ParseToInt(); + + if (page_size == 0) + page_size = 500; + + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + + string sql = "SELECT COUNT(s.id) FROM bxx.shop_api_auth s WHERE 1=1"; + + //where子句 + string where = ""; + if (!string.IsNullOrWhiteSpace(shop_ids)) + where += " and s.ShopId in (" + shop_ids + ")"; + sql += where; + + var count = mySql.ExecuteRowCount(sql); + + DataTable dt; + if (count == 0) + { + dt = new DataTable(); + } + else + { + sql = "SELECT * FROM bxx.shop_api_auth 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 (!string.IsNullOrEmpty(mySql.Message)) + { + return "{\"code\":50001,\"msg\":\"查询失败:" + mySql.Message + "\"}"; + } + + if (dt != null) + { + List shopAuthList = new List(); + foreach (DataRow row in dt.Rows) + { + AuthInfo auth = new AuthInfo + { + id = Convert.ToInt32(row["id"]), + AccessToken = row["AccessToken"].ToString(), + ApiAuthStatus = row["ApiAuthStatus"].ToString(), + AppKey = row["AppKey"].ToString(), + AppSecret = row["AppSecret"].ToString(), + ExpiresTime = row["ExpiresTime"].ParseToString().ParseToDateTime(), + RefreshToken = row["RefreshToken"].ToString(), + ShopId = row["ShopId"].ToString(), + UpdateTime = row["UpdateTime"].ParseToString().ParseToDateTime(), + }; + shopAuthList.Add(auth); + } + var data = JsonUtils.SerializeObjectToString(shopAuthList); + return "{\"code\":200,\"msg\":\"success\",\"data\":" + data + ",\"count\":" + count + "}"; + } + } + return "{\"code\":19999,\"msg\":\"未知错误\"}"; + } + + public string AddMdyShopClientInfo(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\":\"没有用户名\"}"; + } + + string ShopId = RegexUtils.GetStringQuery(ref inputData, "ShopId")?.Replace("'", "\\'"); + string AppKey = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "AppKey"))?.Replace("'", "\\'"); + string AccessToken = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "AccessToken"))?.Replace("'", "\\'"); + string RefreshToken = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "RefreshToken"))?.Replace("'", "\\'"); + string AppSecret = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "AppSecret"))?.Replace("'", "\\'"); + string ExpiresTime = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "ExpiresTime"))?.Replace("'", "\\'"); + string ApiAuthStatus = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "ApiAuthStatus"))?.Replace("'", "\\'"); + if (string.IsNullOrEmpty("ShopId")) + return "{\"code\":50001,\"msg\":\"没有店铺编号\"}"; + if (string.IsNullOrEmpty("AppKey")) + return "{\"code\":50001,\"msg\":\"没有Api编号\"}"; + if (string.IsNullOrEmpty("AccessToken")) + return "{\"code\":50001,\"msg\":\"没有令牌信息\"}"; + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + + string sql = "SELECT ShopId,AppKey FROM `bxx`.`shop_api_auth` where ShopId='" + ShopId + "' and AppKey='" + AppKey + "'"; + + string where = ""; + sql += where; + + var dt = mySql.ExecuteDataTable(sql); + mySql.Close(); + + if (dt != null) + { + conn = Config("ConnKJD"); + mySql = new MysqlUtils(conn); + if (dt.Rows.Count == 0) + { + sql = "INSERT INTO `bxx`.`shop_api_auth` (ShopId,AppKey,AccessToken,RefreshToken,AppSecret,ExpiresTime,ApiAuthStatus)" + + " VALUES (@ShopId,@AppKey,@AccessToken,@RefreshToken,@AppSecret,@ExpiresTime,@ApiAuthStatus);"; + } + else + { + sql = "UPDATE `bxx`.`shop_api_auth` SET AccessToken=@AccessToken"; + if (RefreshToken != null) + sql += ", RefreshToken=@RefreshToken "; + if (AppSecret != null) + sql += ", AppSecret=@AppSecret "; + if (ExpiresTime != null) + sql += ", ExpiresTime=@ExpiresTime "; + if (ApiAuthStatus != null) + sql += ", ApiAuthStatus=@ApiAuthStatus "; + sql += " WHERE ShopId=@ShopId and AppKey=@AppKey;"; + } + + List paramLst = new List(); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "ShopId", Value = ShopId, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "AppKey", Value = AppKey, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "AccessToken", Value = AccessToken.ParseToString(), }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "RefreshToken", Value = RefreshToken.ParseToString(), }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "AppSecret", Value = AppSecret.ParseToString(), }); + paramLst.Add(new MySqlParameter() { DbType = DbType.DateTime, ParameterName = "ExpiresTime", Value = ExpiresTime.ParseToDateTime(), }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "ApiAuthStatus", Value = ApiAuthStatus, }); + + 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\":\"\"}"; + } + } + else + { + return "{\"code\":50003,\"msg\":\"" + mySql.Message + "\",\"data\":\"\"}"; + } + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + public string GetShop(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 = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + + string sql = "SELECT COUNT(s.id) FROM bxx.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,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 bxx.shop s WHERE 1=1"; + sql += " FROM bxx.shop s LEFT JOIN bxx.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(), + pddid = row["pddid"].ParseToString(), + mall_id = row["mall_id"].ParseToString(), + }; + shopList.Add(shop); + } + + //sql = "\r\nINSERT INTO bxx.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 bxx.shop set add_product_remaining=" + remainCount + ", add_product_month=" + month + + " where 1=1 and id in (" + ids + ");"; + + sql += "\r\nINSERT INTO bxx.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 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 = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + + string sql = "SELECT COUNT(s.id) FROM bxx.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 bxx.product_select WHERE operate_sub_sa_name='" + operate_sub_sa_name + "') or " + + "s.shop_id in (SELECT DISTINCT shop_id From bxx.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.shop_account,s.sub_user_name,s.user_name," + + "s.company_name,s.notes,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 bxx.shop s LEFT JOIN bxx.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(), + + }; + shopList.Add(shop); + } + + //sql = "\r\nINSERT INTO bxx.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 bxx.shop set add_product_remaining=" + remainCount + ", add_product_month=" + month + + " where 1=1 and id in (" + ids + ");"; + + sql += "\r\nINSERT INTO bxx.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 = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = ""; + sql += "update bxx.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 = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = "select id,login_name,login_pass,cookie,cookie2,anti_contents,shop_id,shop_account,sub_user_name,user_name from bxx.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(), + }; + 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 = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = "select id,login_name,login_pass,cookie,cookie2,anti_contents,shop_id,shop_account,sub_user_name,user_name from bxx.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(), + }; + shopList.Add(shop); + } + var data = JsonUtils.SerializeObjectToString(shopList); + return "{\"code\":200,\"msg\":\"success\",\"data\":" + data + ",\"c\":\"" + EncrypUtil.Encryption(r2) + "\"}"; + } + } + 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 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 = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = ""; + if (string.IsNullOrEmpty(shop_id)) + sql = "select exists (select 1 from bxx.shop where login_name='" + login_name + "' and user_name='" + user_name + "')"; + else + sql = "select exists (select 1 from bxx.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 bxx.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 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 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 = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = "update bxx.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 MdyAntiContent(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + string login_name = RegexUtils.GetStringQuery(ref inputData, "login_name"); + string shop_id = RegexUtils.GetStringQuery(ref inputData, "shop_id"); + string anti_contents = RegexUtils.GetStringQuery(ref inputData, "anti_contents"); + + int r2 = 0; + int.TryParse(RegexUtils.GetStringQuery(ref inputData, "r2"), out r2); + + if (string.IsNullOrEmpty(login_name)) + { + return "{\"code\":500,\"msg\":\"店铺没有登录名\"}"; + } + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = "update bxx.shop set"; + if (anti_contents != null) + sql += " anti_contents='" + anti_contents + "',"; + sql = sql.TrimEnd(','); + sql += " where login_name='" + login_name + "' 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 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 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 = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = "update bxx.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 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 = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = "delete from bxx.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 = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = "update bxx.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 E57GetPddShopToken(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 mall_id = RegexUtils.GetStringQuery(ref inputData, "mall_id")?.Replace("'", "\\'"); + var url = "https://po.e57.cn/prod-api/api/sys-api/system/open/api/shop/info/forPdd?mallId=" + mall_id; + + var tokenRst = HttpUtils.e57GetResponse(url, ""); + if (!tokenRst.Contains("\"code\":0")) + tokenRst = HttpUtils.e57GetResponse(url, ""); + return tokenRst; + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + + public string GetWeiDianShop(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("'", "\\'"); + 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 = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + + string sql = "SELECT COUNT(s.id) FROM weidian.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.wd_token,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 weidian.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 (!string.IsNullOrEmpty(mySql.Message)) + { + return "{\"code\":500,\"msg\":\"" + mySql.Message + "\"}"; + } + 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(), + wd_token = row["wd_token"].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(), + mall_id = row["mall_id"].ParseToString(), + }; + shopList.Add(shop); + } + + var data = JsonUtils.SerializeObjectToString(shopList); + return "{\"code\":200,\"msg\":\"success\",\"data\":" + data + ",\"count\":" + count + "}"; + } + } + return "{\"code\":19999,\"msg\":\"未知错误\"}"; + } + + public string AddWeiDianShop(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 wd_token = RegexUtils.GetStringQuery(ref inputData, "wd_token"); + 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 = 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 = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = ""; + if (string.IsNullOrEmpty(shop_id)) + sql = "select exists (select 1 from weidian.shop where login_name='" + login_name + "' and user_name='" + user_name + "')"; + else + sql = "select exists (select 1 from weidian.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 MdyWeiDianShop(inputData, isAdmin); + } + + sql = "insert into weidian.shop (login_name,login_pass,cookie,cookie2,wd_token,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 + "','" + wd_token + "','" + 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\"}"; + } + else + return "{\"code\":500,\"msg\":\"" + mySql.Message + "\"}"; + } + return "{\"code\":19999,\"msg\":\"未知错误\"}"; + } + + public string MdyWeiDianShop(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 wd_token = RegexUtils.GetStringQuery(ref inputData, "wd_token"); + 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 = 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 = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = "update weidian.shop set"; + if (login_pass != null) + sql += " login_pass='" + login_pass + "',"; + if (cookie != null) + sql += " cookie='" + cookie + "',"; + if (cookie2 != null) + sql += " cookie2='" + cookie2 + "',"; + if (wd_token != null) + sql += " wd_token='" + wd_token + "',"; + 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\"}"; + } + else + { + return "{\"code\":500,\"msg\":\"" + mySql.Message + "\"}"; + } + } + return "{\"code\":19999,\"msg\":\"未知错误\"}"; + } + + public string MdyWeiDianShopCookie(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 shop_id = RegexUtils.GetStringQuery(ref inputData, "shop_id"); + string wd_token = RegexUtils.GetStringQuery(ref inputData, "wd_token"); + string cookie = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "cookie")); + 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(shop_id)) + { + return "{\"code\":501,\"msg\":\"没有店铺信息\"}"; + } + if (string.IsNullOrEmpty(cookie) && string.IsNullOrEmpty(login_status)) + { + return "{\"code\":501,\"msg\":\"cookie和登录状态不能全为空\"}"; + } + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = "update weidian.shop set"; + if (cookie != null) + sql += " cookie='" + cookie + "',"; + if (wd_token != null) + sql += " wd_token='" + wd_token + "',"; + if (login_status != null) + sql += " login_status='" + login_status + "',"; + sql = sql.TrimEnd(','); + sql += " where shop_id='" + shop_id + "'"; + + var rst = mySql.ExecuteNonQuery(sql); + mySql.Close(); + if (rst) + { + return "{\"code\":200,\"msg\":\"success\"}"; + } + } + return "{\"code\":19999,\"msg\":\"未知错误\"}"; + } + + public string DelWeiDianShop(string inputData, bool isAdmin = false) + { + if (!string.IsNullOrEmpty(inputData)) + { + string user_name = RegexUtils.GetStringQuery(ref inputData, "user_name")?.Replace("'", "\\'"); + if (isAdmin) + user_name = RegexUtils.GetStringQuery(ref inputData, "shop_user_name")?.Replace("'", "\\'"); + string shop_id = RegexUtils.GetStringQuery(ref inputData, "shop_id")?.Replace("'", "\\'"); + + int r2 = 0; + int.TryParse(RegexUtils.GetStringQuery(ref inputData, "r2"), out r2); + + if (string.IsNullOrEmpty(user_name)) + { + return "{\"code\":500,\"msg\":\"没有用户名\"}"; + } + if (string.IsNullOrEmpty(shop_id)) + { + return "{\"code\":501,\"msg\":\"没有指定要删除的店铺\"}"; + } + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = "delete from weidian.shop where user_name='" + user_name + "' and shop_id='" + shop_id + "'"; + + var rst = mySql.ExecuteNonQuery(sql); + mySql.Close(); + if (rst) + { + return "{\"code\":200,\"msg\":\"success\"}"; + } + } + return "{\"code\":19999,\"msg\":\"未知错误\"}"; + } + } +} + + + + diff --git a/StoreHub.KJDWebService/Services/BXXUserService.cs b/StoreHub.KJDWebService/Services/BXXUserService.cs new file mode 100644 index 0000000..2c589b7 --- /dev/null +++ b/StoreHub.KJDWebService/Services/BXXUserService.cs @@ -0,0 +1,894 @@ +using StoreHub.KJDWebService.Services; +using StoreHub.Framework.Repositorys; +using Microsoft.Extensions.Configuration; +using StoreHub.KJDWebService.Models; +using StoreHub.KJDWebService.Models.PddModel; +using StoreHub.KJDWebService.Models.ShopModel; +using StoreHub.KJDWebService.Commons; +using NaiBa.Util.Extension; +using NaiBa.Util.Helper; +using System; +using System.Collections.Generic; +using System.Data; +using System.Linq; +using System.Net; +using System.Reflection; + +namespace StoreHub.KJDWebService.Services +{ + public class BXXUserService : ServiceBase + { + public BXXUserService(SqlRepository sqlRepository, IConfiguration configuration) : base(sqlRepository, configuration) + { + } + public string CheckUserLogin(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + if (!WXUserService.GetSign(inputData, true)) + return "{\"code\":999,\"msg\":\"校验失败\"}"; + + var mobile = RegexUtils.GetStringQuery(ref inputData, "mobile")?.Replace("'", "\\'"); + var password = RegexUtils.GetStringQuery(ref inputData, "password")?.Replace("'", "\\'"); + var r2 = RegexUtils.GetStringQuery(ref inputData, "r2").ParseToInt(); + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = "select * from bxx.user where user_name='" + + mobile + "' and password='" + password + "'"; + + var dt = mySql.ExecuteDataTable(sql); + if (!string.IsNullOrEmpty(mySql.Message)) + { + mySql.Close(); + return "{\"code\":500,\"msg\":\"" + mySql.Message + "\"}"; + } + + if (dt == null) + dt = new DataTable(); + + foreach (DataRow row in dt.Rows) + { + UserLoginResultParam user = new UserLoginResultParam + { + id = Convert.ToInt32(row["id"]), + user_name = row["user_name"].ToString(), + nick_name = row["nick_name"].ToString(), + mobile = row["user_name"].ToString(), + password = row["password"].ToString(), + group_id = row["group_id"].ToString(), + card_id = row["card_id"].ToString(), + company_name = row["company_name"].ToString(), + is_sa = row.Table.Columns.Contains("is_sa") ? row["is_sa"].ParseToInt() : 0, + sa_level = row.Table.Columns.Contains("sa_level") ? row["sa_level"].ParseToInt() : 0, + authority = row["authority"].ToString(), + forbidden_page = row["forbidden_page"].ToString(), + parent_user_name = row["parent_user_name"].ToString(), + }; + + if (string.IsNullOrEmpty(user.company_name)) + { + user.company_name = "-"; + } + if (user.group_id != "3" && !string.IsNullOrEmpty(user.parent_user_name)) + { + sql = "select authority from bxx.user where user_name='" + user.parent_user_name + "'"; + var rst = mySql.ExecuteFirst(sql); + if (mySql.Message.IsNullOrEmpty()) + { + user.parent_authority = rst; + } + } + + var data = JsonUtils.SerializeObjectToString(user); + + mySql.Close(); + return "{\"code\":200,\"msg\":\"success\",\"data\":" + data + ",\"c\":\"" + EncrypUtil.Encryption(r2) + "\"}"; + } + mySql.Close(); + return "{\"code\":1,\"msg\":\"用户名或密码错误\"}"; + + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + public string AddSubUser(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + if (!WXUserService.GetSign(inputData)) + return "{\"code\":999,\"msg\":\"校验失败\"}"; + + var parent_user_name = RegexUtils.GetStringQuery(ref inputData, "user_name")?.Replace("'", "\\'"); + var nick_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "sub_nick_name"))?.Replace("'", "\\'"); + var user_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "sub_name"))?.Replace("'", "\\'"); + var mobile = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "sub_mobile"))?.Replace("'", "\\'"); + var password = RegexUtils.GetStringQuery(ref inputData, "sub_password")?.Replace("'", "\\'"); + var group_id = RegexUtils.GetStringQuery(ref inputData, "group_id")?.Replace("'", "\\'"); + var card_id = RegexUtils.GetStringQuery(ref inputData, "card_id")?.Replace("'", "\\'"); + var company_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "company"))?.Replace("'", "\\'"); + var notes = RegexUtils.GetStringQuery(ref inputData, "notes")?.Replace("'", "\\'"); + var authority = RegexUtils.GetStringQuery(ref inputData, "authority")?.Replace("'", "\\'"); + var forbidden_page = RegexUtils.GetStringQuery(ref inputData, "forbidden_page")?.Replace("'", "\\'"); + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = ""; + sql = "select exists (select 1 from bxx.user where user_name='" + user_name + "')"; + var exist = mySql.ExecuteFirstInt(sql); + if (exist > 0) + { + mySql.Close(); + return "{\"code\":500,\"msg\":\"用户名已存在\"}"; + } + + sql = "insert into bxx.user (nick_name,user_name,mobile,password,card_id,group_id,company_name,notes,parent_user_name,authority,forbidden_page,add_time,mdy_time) " + + "values ('" + nick_name + "','" + user_name + "','" + mobile + "','" + password + "','" + card_id + "','" + + group_id + "','" + company_name + "','" + notes + "','" + parent_user_name + "','" + authority + "','" + forbidden_page + "','" + + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "','" + + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "');"; + var rst = mySql.ExecuteNonQuery(sql); + mySql.Close(); + if (!rst) + return "{\"code\":501,\"msg\":\""+ mySql.Message + "\"}"; + else + return "{\"code\":200,\"msg\":\"子账户创建成功!\"}"; + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + public string GetSubUser(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + if (!WXUserService.GetSign(inputData)) + return "{\"code\":999,\"msg\":\"校验失败\"}"; + + var r2 = RegexUtils.GetStringQuery(ref inputData, "r2").ParseToInt(); + var user_name = RegexUtils.GetStringQuery(ref inputData, "user_name"); + var password = RegexUtils.GetStringQuery(ref inputData, "password"); + var group = RegexUtils.GetStringQuery(ref inputData, "group"); + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = "select * from bxx.user where parent_user_name='" + + user_name + "'"; + + var dt = mySql.ExecuteDataTable(sql); + mySql.Close(); + if (dt != null) + { + List userList = new List(); + foreach (DataRow row in dt.Rows) + { + + UserLoginResultParam user = new UserLoginResultParam + { + id = Convert.ToInt32(row["id"]), + user_name = row["user_name"].ToString(), + nick_name = row["nick_name"].ToString(), + mobile = row["mobile"].ToString(), + password = row["password"].ToString(), + group_id = row["group_id"].ToString(), + card_id = row["card_id"].ToString(), + parent_user_name = row["parent_user_name"].ToString(), + company_name = row["company_name"].ToString(), + notes = row["notes"].ToString(), + authority = row.Table.Columns.Contains("authority") ? row["authority"].ParseToString() : "", + forbidden_page = row.Table.Columns.Contains("forbidden_page") ? row["forbidden_page"].ParseToString() : "", + }; + if (string.IsNullOrEmpty(user.mobile)) + { + user.mobile = row["user_name"].ToString(); + } + userList.Add(user); + } + var data = JsonUtils.SerializeObjectToString(userList); + return "{\"code\":200,\"msg\":\"success\",\"data\":" + data + ",\"c\":\"" + EncrypUtil.Encryption(r2) + "\"}"; + } + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + public string UpdateSubUser(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + if (!WXUserService.GetSign(inputData)) + return "{\"code\":999,\"msg\":\"校验失败\"}"; + + var id = RegexUtils.GetStringQuery(ref inputData, "id")?.Replace("'", "\\'"); + var parent_user_name = RegexUtils.GetStringQuery(ref inputData, "user_name")?.Replace("'", "\\'"); + var nick_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "sub_nick_name"))?.Replace("'", "\\'"); + var user_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "sub_name"))?.Replace("'", "\\'"); + var mobile = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "sub_mobile"))?.Replace("'", "\\'"); + var password = RegexUtils.GetStringQuery(ref inputData, "sub_password")?.Replace("'", "\\'"); + var group_id = RegexUtils.GetStringQuery(ref inputData, "group_id")?.Replace("'", "\\'"); + var card_id = RegexUtils.GetStringQuery(ref inputData, "card_id")?.Replace("'", "\\'"); + var notes = RegexUtils.GetStringQuery(ref inputData, "notes")?.Replace("'", "\\'"); + var authority = RegexUtils.GetStringQuery(ref inputData, "authority")?.Replace("'", "\\'"); + var forbidden_page = RegexUtils.GetStringQuery(ref inputData, "forbidden_page")?.Replace("'", "\\'"); + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = ""; + //sql = "select * from bxx.user where parent_user_name='" + // + user_name + "'"; + sql = "update bxx.user set"; + if (!string.IsNullOrEmpty(nick_name)) + sql += " nick_name='" + nick_name + "',"; + if (!string.IsNullOrEmpty(user_name)) + sql += " user_name='" + user_name + "',"; + if (!string.IsNullOrEmpty(mobile)) + sql += " mobile='" + mobile + "',"; + if (!string.IsNullOrEmpty(password)) + sql += " password='" + password + "',"; + if (!string.IsNullOrEmpty(group_id)) + sql += " group_id=" + group_id + ","; + if (!string.IsNullOrEmpty(card_id)) + sql += " card_id='" + card_id + "',"; + if (!string.IsNullOrEmpty(notes)) + sql += " notes='" + notes + "',"; + if (authority != null) + sql += " authority='" + authority + "',"; + if (forbidden_page != null) + sql += " forbidden_page='" + forbidden_page + "',"; + sql = sql.TrimEnd(','); + sql += " where id=" + id + ""; + + var rst = mySql.ExecuteNonQuery(sql); + mySql.Close(); + if (rst) + { + return "{\"code\":200,\"msg\":\"success\"}"; + } + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + public string DelUser(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + if (!WXUserService.GetSign(inputData)) + return "{\"code\":999,\"msg\":\"校验失败\"}"; + + var user_name = RegexUtils.GetStringQuery(ref inputData, "user_name"); + var id = RegexUtils.GetStringQuery(ref inputData, "id"); + if (string.IsNullOrWhiteSpace(id)) + return "{\"code\":500,\"msg\":\"id不能为空\"}"; + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = "delete from bxx.user where id='" + + id + "'"; + + var rst = mySql.ExecuteNonQuery(sql); + mySql.Close(); + if (rst) + { + return "{\"code\":200,\"msg\":\"success\"}"; + } + else + return "{\"code\":500,\"msg\":\"删除失败,请稍后重试\"}"; + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + public string GetAllUser(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + if (!WXUserService.GetSign(inputData)) + return "{\"code\":999,\"msg\":\"校验失败\"}"; + + var user_name = RegexUtils.GetStringQuery(ref inputData, "user_name")?.Replace("'", "\\'"); + var password = RegexUtils.GetStringQuery(ref inputData, "password")?.Replace("'", "\\'"); + var group_id = RegexUtils.GetStringQuery(ref inputData, "group_id")?.Replace("'", "\\'"); + var search = RegexUtils.GetStringQuery(ref inputData, "search")?.Replace("'", "\\'"); + var sa_level = RegexUtils.GetStringQuery(ref inputData, "sa_level")?.Replace("'", "\\'"); + var r2 = RegexUtils.GetStringQuery(ref inputData, "r2").ParseToInt(); + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + //string sql = "select * from bxx.user where group_id=3"; + string sql = "select * from bxx.user where 1=1"; + if (!string.IsNullOrEmpty(group_id)) + sql += " and group_id=" + group_id; + if (!string.IsNullOrEmpty(sa_level)) + sql += " and sa_level=" + sa_level; + if (!string.IsNullOrEmpty(search)) + sql += " and (user_name like '%" + search + + "%' or nick_name like '%" + search + + "%' or company_name like '%" + search + "%')"; + sql += " order by id desc"; + + var dt = mySql.ExecuteDataTable(sql); + mySql.Close(); + if (dt != null) + { + List userList = new List(); + foreach (DataRow row in dt.Rows) + { + + UserLoginResultParam user = new UserLoginResultParam + { + id = Convert.ToInt32(row["id"]), + user_name = row["user_name"].ToString(), + nick_name = row["nick_name"].ToString(), + mobile = row["mobile"].ToString(), + password = row["password"].ToString(), + group_id = row["group_id"].ToString(), + card_id = row["card_id"].ToString(), + parent_user_name = row["parent_user_name"].ToString(), + company_name = row["company_name"].ToString(), + notes = row["notes"].ToString(), + is_sa = row.Table.Columns.Contains("is_sa") ? row["is_sa"].ParseToInt() : 0, + sa_level = row.Table.Columns.Contains("sa_level") ? row["sa_level"].ParseToInt() : 0, + authority = row.Table.Columns.Contains("authority") ? row["authority"].ParseToString() : "", + forbidden_page = row.Table.Columns.Contains("forbidden_page") ? row["forbidden_page"].ParseToString() : "", + }; + if (string.IsNullOrEmpty(user.mobile)) + { + user.mobile = row["user_name"].ToString(); + } + userList.Add(user); + } + var data = JsonUtils.SerializeObjectToString(userList); + return "{\"code\":200,\"msg\":\"success\",\"data\":" + data + ",\"c\":\"" + EncrypUtil.Encryption(r2) + "\"}"; + } + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + public string AddUser(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + if (!WXUserService.GetSign(inputData)) + return "{\"code\":999,\"msg\":\"校验失败\"}"; + + var nick_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "add_nick_name"))?.Replace("'", "\\'"); + var user_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "add_user_name"))?.Replace("'", "\\'"); + var mobile = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "add_mobile"))?.Replace("'", "\\'"); + var password = RegexUtils.GetStringQuery(ref inputData, "add_password")?.Replace("'", "\\'"); + var company_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "add_company"))?.Replace("'", "\\'"); + var group_id = RegexUtils.GetStringQuery(ref inputData, "group_id")?.Replace("'", "\\'"); ; + var card_id = RegexUtils.GetStringQuery(ref inputData, "card_id")?.Replace("'", "\\'"); + var notes = RegexUtils.GetStringQuery(ref inputData, "notes")?.Replace("'", "\\'"); + var sa_level = RegexUtils.GetStringQuery(ref inputData, "sa_level")?.Replace("'", "\\'"); + var authority = RegexUtils.GetStringQuery(ref inputData, "authority")?.Replace("'", "\\'"); + var forbidden_page = RegexUtils.GetStringQuery(ref inputData, "forbidden_page")?.Replace("'", "\\'"); + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = ""; + sql = "select exists (select 1 from bxx.user where user_name='" + user_name + "')"; + var exist = mySql.ExecuteFirstInt(sql); + if (exist > 0) + { + mySql.Close(); + return "{\"code\":500,\"msg\":\"用户名已存在\"}"; + } + + sql = "insert into bxx.user (nick_name,user_name,mobile,password,card_id,group_id,company_name,notes,sa_level,authority,add_time,mdy_time,forbidden_page) " + + "values ('" + nick_name + "','" + user_name + "','" + mobile + "','" + password + "','" + card_id + "','" + + group_id + "','" + company_name + "','" + notes + "'," + sa_level + ",'" + authority + "','" + forbidden_page + "','" + + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "','" + + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "');"; + var rst = mySql.ExecuteNonQuery(sql); + mySql.Close(); + if (!rst) + return "{\"code\":501,\"msg\":\"" + mySql.Message + "\"}"; + else + return "{\"code\":200,\"msg\":\"success\"}"; + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + public string UpdateUser(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + if (!WXUserService.GetSign(inputData)) + return "{\"code\":999,\"msg\":\"校验失败\"}"; + + var id = RegexUtils.GetStringQuery(ref inputData, "id")?.Replace("'", "\\'"); + var nick_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "add_nick_name"))?.Replace("'", "\\'"); + var user_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "add_user_name"))?.Replace("'", "\\'"); + var mobile = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "add_mobile"))?.Replace("'", "\\'"); + var company_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "add_company"))?.Replace("'", "\\'"); + var password = RegexUtils.GetStringQuery(ref inputData, "add_password")?.Replace("'", "\\'"); + var group_id = RegexUtils.GetStringQuery(ref inputData, "group_id")?.Replace("'", "\\'"); + var card_id = RegexUtils.GetStringQuery(ref inputData, "card_id")?.Replace("'", "\\'"); + var notes = RegexUtils.GetStringQuery(ref inputData, "notes")?.Replace("'", "\\'"); + var sa_level = RegexUtils.GetStringQuery(ref inputData, "sa_level")?.Replace("'", "\\'"); + var authority = RegexUtils.GetStringQuery(ref inputData, "authority")?.Replace("'", "\\'"); + var forbidden_page = RegexUtils.GetStringQuery(ref inputData, "forbidden_page")?.Replace("'", "\\'"); + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = ""; + //sql = "select * from bxx.user where parent_user_name='" + // + user_name + "'"; + sql = "update bxx.user set"; + if (!string.IsNullOrEmpty(nick_name)) + sql += " nick_name='" + nick_name + "',"; + if (!string.IsNullOrEmpty(user_name)) + sql += " user_name='" + user_name + "',"; + if (!string.IsNullOrEmpty(mobile)) + sql += " mobile='" + mobile + "',"; + if (!string.IsNullOrEmpty(company_name)) + sql += " company_name='" + company_name + "',"; + if (!string.IsNullOrEmpty(password)) + sql += " password='" + password + "',"; + if (!string.IsNullOrEmpty(group_id)) + sql += " group_id=" + group_id + ","; + if (!string.IsNullOrEmpty(card_id)) + sql += " card_id='" + card_id + "',"; + if (!string.IsNullOrEmpty(notes)) + sql += " notes='" + notes + "',"; + if (!string.IsNullOrEmpty(sa_level)) + sql += " sa_level=" + sa_level + ","; + if (authority != null) + sql += " authority='" + authority + "',"; + if (forbidden_page != null) + sql += " forbidden_page='" + forbidden_page + "',"; + sql = sql.TrimEnd(','); + sql += " where id=" + id + ""; + + var rst = mySql.ExecuteNonQuery(sql); + mySql.Close(); + if (rst) + { + return "{\"code\":200,\"msg\":\"success\"}"; + } + else + { + return "{\"code\":500,\"msg\":\"" + mySql.Message + "\"}"; + } + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + public string ChangePassword(string inputData) + { + var userName = RegexUtils.GetStringJson(ref inputData, "user_name")?.Replace("'", "\\'"); + var password = RegexUtils.GetStringJson(ref inputData, "password")?.Replace("'", "\\'"); + var newPassword = RegexUtils.GetStringJson(ref inputData, "new_password")?.Replace("'", "\\'"); + + string conn = "Conn"; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = "select user_id,password from pepdtp.user where user_id='" + + userName + "' and password='" + password + "'"; + + var dw = mySql.ExecuteDataTableRow(sql); + if (dw != null) + { + UserLoginResultParam user = new UserLoginResultParam + { + user_name = dw["user_id"].ToString(), + password = dw["password"].ToString(), + }; + sql = "update pepdtp.user set password = '" + newPassword + "' where user_id='" + userName + "'"; + var result = mySql.ExecuteNonQuery(sql); + mySql.Close(); + + if (result) + { + return "{\"code\":0,\"msg\":\"密码修改成功!\"}"; + } + else + return "{\"code\":19999,\"msg\":\"密码修改失败!请稍后再试。\"}"; + } + else + { + mySql.Close(); + return "{\"code\":1,\"msg\":\"原密码错误。\"}"; + } + } + + public string return_package_secret_key { get; set; } = "aaMETt2bPe6YHzZ1ojbC+6wOvgtwehqc6A+/Rz+pCUU="; + + public string GetPackageSign(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + var mobile = RegexUtils.GetStringQuery(ref inputData, "mobile")?.Replace("'", "\\'"); + var password = RegexUtils.GetStringQuery(ref inputData, "password")?.Replace("'", "\\'"); + var timestamp = RegexUtils.GetStringQuery(ref inputData, "timestamp")?.Replace("'", "\\'"); + var mallId = RegexUtils.GetStringQuery(ref inputData, "mallId")?.Replace("'", "\\'"); + var returnPackageNo = RegexUtils.GetStringQuery(ref inputData, "returnPackageNo")?.Replace("'", "\\'"); + int r2 = RegexUtils.GetStringQuery(ref inputData, "r2").ParseToInt(); + string c2 = RegexUtils.GetStringQuery(ref inputData, "c2"); + + if (EncrypUtil.Encryption(r2) != c2) + return "{\"code\":2,\"msg\":\"不合法的输入内容\"}"; + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = "select * from bxx.user where user_name='" + + mobile + "' and password='" + password + "'"; + + sql = "select * from bxx.user where user_name='" + mobile + "'"; + + var dt = mySql.ExecuteDataTable(sql); + mySql.Close(); + if (dt == null || dt.Rows.Count <=0) + { + return "{\"code\":1,\"msg\":\"用户不存在\"}"; + } + + string sign = EncrypUtil.GetMd5(timestamp + return_package_secret_key + mallId + returnPackageNo).ToLower(); + + return "{\"code\":200, \"sign\":\"" + sign + "\", \"msg\":\"\"}"; + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + public string UpdateScm121Cookie(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + var id = (RegexUtils.GetStringQuery(ref inputData, "db_id")?.Replace("'", "\\'")).ParseToInt(); + if (id == 0) + id = 1; + var cookie = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "cookie"))?.Replace("'", "\\'"); + var time = RegexUtils.GetStringQuery(ref inputData, "time").ParseToInt(); + string time1 = RegexUtils.GetStringQuery(ref inputData, "code"); + if (time1 != EncrypUtil.Encryption(time)) + return "{\"code\":50000,\"msg\":\"校验失败\"}"; + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = "update bxx.scm121_user set cookie='" + cookie + "' WHERE id=" + id + ";"; + + var rst = mySql.ExecuteNonQuery(sql); + mySql.Close(); + if (rst && string.IsNullOrEmpty(mySql.Message)) + { + return "{\"code\":200,\"msg\":\"success\"}"; + } + if (!string.IsNullOrEmpty(mySql.Message)) + { + return "{\"code\":500,\"msg\":\"" + mySql.Message + "\"}"; + } + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + public string GetScm121Cookie(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + var id = (RegexUtils.GetStringQuery(ref inputData, "db_id")?.Replace("'", "\\'")).ParseToInt(); + if (id == 0) + id = 1; + var time = RegexUtils.GetStringQuery(ref inputData, "time").ParseToInt(); + string time1 = RegexUtils.GetStringQuery(ref inputData, "code"); + if (time1 != EncrypUtil.Encryption(time)) + return "{\"code\":50000,\"msg\":\"校验失败\"}"; + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = "select cookie from bxx.scm121_user WHERE id=" + id + ";"; + + var rst = mySql.ExecuteDataTableRow(sql); + mySql.Close(); + if (string.IsNullOrEmpty(mySql.Message)) + { + return "{\"code\":200,\"cookie\":" + rst["cookie"] + "}"; + } + if (!string.IsNullOrEmpty(mySql.Message)) + { + return "{\"code\":500,\"msg\":\"" + mySql.Message + "\"}"; + } + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + public string AddBuyer(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + string user_name = RegexUtils.GetStringQuery(ref inputData, "user_name")?.Replace("'", "\\'"); + string buyer_id = RegexUtils.GetStringQuery(ref inputData, "buyer_id")?.Replace("'", "\\'"); + string buyer_name = RegexUtils.GetStringQuery(ref inputData, "buyer_name")?.Replace("'", "\\'"); + string buyer_nick = RegexUtils.GetStringQuery(ref inputData, "buyer_nick")?.Replace("'", "\\'"); + string cookie = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "cookie"))?.Replace("'", "\\'"); + string notes = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "notes"))?.Replace("'", "\\'"); + + int r2 = 0; + int.TryParse(RegexUtils.GetStringQuery(ref inputData, "r2"), out r2); + + if (string.IsNullOrEmpty(user_name)) + { + return "{\"code\":500,\"msg\":\"没有用户名\"}"; + } + if (string.IsNullOrEmpty(buyer_name)) + { + return "{\"code\":501,\"msg\":\"没有买手登录名\"}"; + } + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = "select exists (select 1 from bxx.shop where buyer_id='" + buyer_id + "' and user_name='" + user_name + "')"; + var exist = mySql.ExecuteFirstInt(sql); + if (exist > 0) + { + mySql.Close(); + return "{\"code\":500,\"msg\":\"买手" + buyer_name + " " + buyer_nick + "已存在\"}"; + } + + sql = "insert into bxx.buyer (user_name,buyer_id,buyer_name,buyer_nick,cookie,notes) " + + "values ('" + user_name + "','" + buyer_id + "','" + buyer_name + "','" + buyer_nick + "','" + cookie + "','" + notes + "');"; + 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 MdyBuyer(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + string user_name = RegexUtils.GetStringQuery(ref inputData, "user_name")?.Replace("'", "\\'"); + string buyer_id = RegexUtils.GetStringQuery(ref inputData, "buyer_id")?.Replace("'", "\\'"); + string buyer_name = RegexUtils.GetStringQuery(ref inputData, "buyer_name")?.Replace("'", "\\'"); ; + string buyer_nick = RegexUtils.GetStringQuery(ref inputData, "buyer_nick")?.Replace("'", "\\'"); ; + string cookie = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "cookie"))?.Replace("'", "\\'"); ; + string notes = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "notes"))?.Replace("'", "\\'"); + string status = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "status"))?.Replace("'", "\\'"); + + int r2 = 0; + int.TryParse(RegexUtils.GetStringQuery(ref inputData, "r2"), out r2); + + if (string.IsNullOrEmpty(user_name)) + { + return "{\"code\":500,\"msg\":\"没有用户名\"}"; + } + if (string.IsNullOrEmpty(buyer_id)) + { + return "{\"code\":501,\"msg\":\"没有买手号\"}"; + } + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = "update bxx.buyer set"; + if (buyer_name != null) + sql += " buyer_name='" + buyer_name + "',"; + if (buyer_nick != null) + sql += " buyer_nick='" + buyer_nick + "',"; + if (cookie != null) + sql += " cookie='" + cookie + "',"; + if (notes != null) + sql += " notes='" + notes + "',"; + if (status != null) + sql += " status='" + status + "',"; + sql = sql.TrimEnd(','); + + sql += " where buyer_id='" + buyer_id + "' and user_name='" + user_name + "'"; + + 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 MdyBuyerCookie(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + string user_name = RegexUtils.GetStringQuery(ref inputData, "buyer_user_name")?.Replace("'", "\\'"); + string buyer_id = RegexUtils.GetStringQuery(ref inputData, "buyer_id")?.Replace("'", "\\'"); + string cookie = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "cookie"))?.Replace("'", "\\'"); + string status = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "status"))?.Replace("'", "\\'"); + + int r2 = 0; + int.TryParse(RegexUtils.GetStringQuery(ref inputData, "r2"), out r2); + + if (string.IsNullOrEmpty(buyer_id)) + { + return "{\"code\":501,\"msg\":\"没有买手号\"}"; + } + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = "update bxx.buyer set"; + if (cookie != null) + sql += " cookie='" + cookie + "',"; + if (status != null) + sql += " status='" + status + "',"; + sql = sql.TrimEnd(','); + + sql += " where buyer_id='" + buyer_id + "';"; + + var rst = mySql.ExecuteNonQuery(sql); + mySql.Close(); + if (rst) + { + return "{\"code\":200,\"msg\":\"success\"}"; + } + else + { + return "{\"code\":500,\"msg\":\"" + mySql.Message + "\"}"; + } + } + return "{\"code\":19999,\"msg\":\"未知错误\"}"; + } + + public string GetBuyer(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + var user_name = RegexUtils.GetStringQuery(ref inputData, "user_name"); + var password = RegexUtils.GetStringQuery(ref inputData, "password"); + if (string.IsNullOrEmpty(user_name)) + { + return "{\"code\":500,\"msg\":\"没有用户名\"}"; + } + + var search_notes = RegexUtils.GetStringQuery(ref inputData, "search_notes"); + var search_buyer_id = RegexUtils.GetStringQuery(ref inputData, "search_buyer_id"); + var search_buyer_name = RegexUtils.GetStringQuery(ref inputData, "search_buyer_name"); + var search_buyer_nick = RegexUtils.GetStringQuery(ref inputData, "search_buyer_nick"); + + var buyer_ids = RegexUtils.GetStringQuery(ref inputData, "buyer_ids")?.Replace("'", ""); + if (!string.IsNullOrWhiteSpace(buyer_ids)) + { + List shopIdLst = buyer_ids.Split(',').ToList(); + buyer_ids = "'" + string.Join("','", shopIdLst) + "'"; + } + var buyer_names = RegexUtils.GetStringQuery(ref inputData, "buyer_names"); + if (!string.IsNullOrWhiteSpace(buyer_names)) + { + List shopNameLst = buyer_names.Split(',').ToList(); + buyer_names = "'" + string.Join("','", shopNameLst) + "'"; + } + var buyer_nicks = RegexUtils.GetStringQuery(ref inputData, "buyer_nicks"); + if (!string.IsNullOrWhiteSpace(buyer_nicks)) + { + List shopNotesLst = buyer_nicks.Split(',').ToList(); + buyer_nicks = "'" + 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 = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + + string sql = "SELECT COUNT(s.id) FROM bxx.buyer s WHERE 1=1"; + + //where子句 + string where = ""; + if (!string.IsNullOrWhiteSpace(search_notes)) + where += " and s.notes like '%" + search_notes + "%'"; + if (!string.IsNullOrWhiteSpace(search_buyer_id)) + where += " and s.buyer_id like '%" + search_buyer_id + "%'"; + if (!string.IsNullOrWhiteSpace(search_buyer_name)) + where += " and s.buyer_name like '%" + search_buyer_name + "%'"; + if (!string.IsNullOrWhiteSpace(search_buyer_nick)) + where += " and s.buyer_nick like '%" + search_buyer_nick + "%'"; + + if (!string.IsNullOrWhiteSpace(buyer_ids)) + where += " and s.buyer_id in (" + buyer_ids + ")"; + if (!string.IsNullOrWhiteSpace(buyer_names)) + where += " and s.buyer_name in (" + buyer_names + ")"; + if (!string.IsNullOrWhiteSpace(buyer_nicks)) + where += " and s.buyer_nick in (" + buyer_nicks + ")"; + + if (!string.IsNullOrWhiteSpace(user_name)) + where += " and s.user_name='" + user_name + "'"; + sql += where; + + var count = mySql.ExecuteRowCount(sql); + + DataTable dt; + if (count == 0) + { + dt = new DataTable(); + } + else + { + sql = "SELECT s.*"; + sql += " FROM bxx.buyer 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 buyerList = new List(); + foreach (DataRow row in dt.Rows) + { + BuyerLoginInfo shop = new BuyerLoginInfo + { + id = Convert.ToInt32(row["id"]), + cookie = row["cookie"].ToString(), + user_name = row["user_name"].ToString(), + notes = row["notes"].ToString(), + add_time = row["add_time"].ParseToString().ParseToDateTime(), + mdy_time = row["mdy_time"].ParseToString().ParseToDateTime(), + buyer_id = row["buyer_id"].ToString(), + buyer_name = row["buyer_name"].ToString(), + buyer_nick = row["buyer_nick"].ToString(), + status = row["status"].ToString(), + }; + buyerList.Add(shop); + } + var data = JsonUtils.SerializeObjectToString(buyerList); + return "{\"code\":200,\"msg\":\"success\",\"data\":" + data + ",\"count\":" + count + "}"; + } + } + return "{\"code\":19999,\"msg\":\"未知错误\"}"; + } + + public string DelBuyer(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + var user_name = RegexUtils.GetStringQuery(ref inputData, "user_name"); + var password = RegexUtils.GetStringQuery(ref inputData, "password"); + if (string.IsNullOrEmpty(user_name)) + { + return "{\"code\":500,\"msg\":\"没有用户名\"}"; + } + + var buyer_id = RegexUtils.GetStringQuery(ref inputData, "buyer_id"); + if (string.IsNullOrEmpty(buyer_id)) + { + return "{\"code\":500,\"msg\":\"没有买手号\"}"; + } + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + + string sql = "DELETE FROM bxx.buyer WHERE user_name='" + user_name + "' and buyer_id='" + buyer_id + "'"; + + + var rst = mySql.ExecuteNonQuery(sql); + mySql.Close(); + + if (rst) + { + return "{\"code\":200,\"msg\":\"success\"}"; + } + else + { + return "{\"code\":501,\"msg\":" + mySql.Message + "}"; + } + } + return "{\"code\":19999,\"msg\":\"未知错误\"}"; + } + } +} + + + + diff --git a/StoreHub.KJDWebService/Services/DYShopService.cs b/StoreHub.KJDWebService/Services/DYShopService.cs new file mode 100644 index 0000000..0255fa4 --- /dev/null +++ b/StoreHub.KJDWebService/Services/DYShopService.cs @@ -0,0 +1,788 @@ +using StoreHub.KJDWebService.Models; +using StoreHub.Framework.Repositorys; +using Microsoft.Extensions.Configuration; +using StoreHub.KJDWebService.Models.ShopModel; +using StoreHub.KJDWebService.Commons; +using NaiBa.Util.Extension; +using System; +using System.Collections.Generic; +using System.Data; +using System.Drawing; +using System.Linq; + +namespace StoreHub.KJDWebService.Services +{ + public class DYShopService : ServiceBase + { + public DYShopService(SqlRepository sqlRepository, IConfiguration configuration) : base(sqlRepository, configuration) + { + } + public string GetShop(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("'", "\\'"); + 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 = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + + string sql = "SELECT COUNT(s.id) FROM dyxd.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.shop_id,s.shop_account,s.sub_user_name," + + "s.user_name,s.company_name,s.notes,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 dyxd.shop s WHERE 1=1"; + sql += " FROM dyxd.shop s LEFT JOIN dyxd.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(), + pddid = row["pddid"].ParseToString(), + }; + shopList.Add(shop); + } + + //sql = "\r\nINSERT INTO dyxd.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 dyxd.shop set add_product_remaining=" + remainCount + ", add_product_month=" + month + + " where 1=1 and id in (" + ids + ");"; + + sql += "\r\nINSERT INTO dyxd.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 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 = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + + string sql = "SELECT COUNT(s.id) FROM dyxd.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 dyxd.product_select WHERE operate_sub_sa_name='" + operate_sub_sa_name + "') or " + + "s.shop_id in (SELECT DISTINCT shop_id From dyxd.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.shop_account,s.sub_user_name,s.user_name," + + "s.company_name,s.notes,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 dyxd.shop s LEFT JOIN dyxd.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(), + + }; + shopList.Add(shop); + } + + //sql = "\r\nINSERT INTO dyxd.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 dyxd.shop set add_product_remaining=" + remainCount + ", add_product_month=" + month + + " where 1=1 and id in (" + ids + ");"; + + sql += "\r\nINSERT INTO dyxd.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 = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = ""; + sql += "update dyxd.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 = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = "select id,login_name,login_pass,cookie,cookie2,anti_contents,shop_id,shop_account,sub_user_name,user_name from dyxd.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(), + }; + 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 = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = "select id,login_name,login_pass,cookie,cookie2,anti_contents,shop_id,shop_account,sub_user_name,user_name from dyxd.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(), + }; + shopList.Add(shop); + } + var data = JsonUtils.SerializeObjectToString(shopList); + return "{\"code\":200,\"msg\":\"success\",\"data\":" + data + ",\"c\":\"" + EncrypUtil.Encryption(r2) + "\"}"; + } + } + 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 = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = ""; + if (string.IsNullOrEmpty(shop_id)) + sql = "select exists (select 1 from dyxd.shop where login_name='" + login_name + "' and user_name='" + user_name + "')"; + else + sql = "select exists (select 1 from dyxd.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 dyxd.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 = 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 = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = "update dyxd.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 pddid = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "pddid")); + + int r2 = 0; + int.TryParse(RegexUtils.GetStringQuery(ref inputData, "r2"), out r2); + + if (string.IsNullOrEmpty(login_name)) + { + return "{\"code\":500,\"msg\":\"店铺没有登录名\"}"; + } + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = "update dyxd.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 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 = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = "delete from dyxd.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 = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = "update dyxd.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\":\"输入为空\"}"; + } + } +} + + + + diff --git a/StoreHub.KJDWebService/Services/DYUserService.cs b/StoreHub.KJDWebService/Services/DYUserService.cs new file mode 100644 index 0000000..5dec731 --- /dev/null +++ b/StoreHub.KJDWebService/Services/DYUserService.cs @@ -0,0 +1,481 @@ +using StoreHub.KJDWebService.Models; +using StoreHub.Framework.Repositorys; +using Microsoft.Extensions.Configuration; +using StoreHub.KJDWebService.Commons; +using NaiBa.Util.Extension; +using System; +using System.Collections.Generic; +using System.Data; +using System.Linq; +using System.Net; +using System.Reflection; + +namespace StoreHub.KJDWebService.Services +{ + public class DYUserService : ServiceBase + { + public DYUserService(SqlRepository sqlRepository, IConfiguration configuration) : base(sqlRepository, configuration) + { + } + public string CheckUserLogin(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + var mobile = RegexUtils.GetStringQuery(ref inputData, "mobile")?.Replace("'", "\\'"); + var password = RegexUtils.GetStringQuery(ref inputData, "password")?.Replace("'", "\\'"); + + var version = RegexUtils.GetStringQuery(ref inputData, "version").ParseToInt(); + if (version < (System.Configuration.ConfigurationManager.ConnectionStrings["LimitVersion"]?.ConnectionString).ParseToInt()) + return "{\"code\":1,\"msg\":\"当前版本过于陈旧,请立即升级新版\"}"; + + int r2 = 0; + int.TryParse(RegexUtils.GetStringQuery(ref inputData, "r2"), out r2); + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = "select * from dyxd.user where user_name='" + + mobile + "' and password='" + password + "'"; + + var dt = mySql.ExecuteDataTable(sql); + mySql.Close(); + if (dt != null) + { + foreach (DataRow row in dt.Rows) + { + UserLoginResultParam user = new UserLoginResultParam + { + id = Convert.ToInt32(row["id"]), + user_name = row["user_name"].ToString(), + nick_name = row["nick_name"].ToString(), + mobile = row["user_name"].ToString(), + password = row["password"].ToString(), + group_id = row["group_id"].ToString(), + card_id = row["card_id"].ToString(), + company_name = row["company_name"].ToString(), + is_sa = row.Table.Columns.Contains("is_sa") ? row["is_sa"].ParseToInt() : 0, + sa_level = row.Table.Columns.Contains("sa_level") ? row["sa_level"].ParseToInt() : 0, + }; + + if (string.IsNullOrEmpty(user.company_name)) + { + user.company_name = "-"; + } + var data = JsonUtils.SerializeObjectToString(user); + return "{\"code\":200,\"msg\":\"success\",\"data\":" + data + ",\"c\":\"" + EncrypUtil.Encryption(r2) + "\"}"; + } + return "{\"code\":1,\"msg\":\"用户名或密码错误\"}"; + } + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + public string AddSubUser(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + var parent_user_name = RegexUtils.GetStringQuery(ref inputData, "user_name")?.Replace("'", "\\'"); + var nick_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "sub_nick_name"))?.Replace("'", "\\'"); + var user_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "sub_name"))?.Replace("'", "\\'"); + var mobile = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "sub_mobile"))?.Replace("'", "\\'"); + var password = RegexUtils.GetStringQuery(ref inputData, "sub_password")?.Replace("'", "\\'"); + var group_id = RegexUtils.GetStringQuery(ref inputData, "group_id")?.Replace("'", "\\'"); + var card_id = RegexUtils.GetStringQuery(ref inputData, "card_id")?.Replace("'", "\\'"); + var company_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "company"))?.Replace("'", "\\'"); + var notes = RegexUtils.GetStringQuery(ref inputData, "notes")?.Replace("'", "\\'"); + int r2 = 0; + int.TryParse(RegexUtils.GetStringQuery(ref inputData, "r2"), out r2); + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = ""; + sql = "select exists (select 1 from dyxd.user where user_name='" + user_name + "')"; + var exist = mySql.ExecuteFirstInt(sql); + if (exist > 0) + { + mySql.Close(); + return "{\"code\":500,\"msg\":\"用户名已存在\"}"; + } + + sql = "insert into dyxd.user (nick_name,user_name,mobile,password,card_id,group_id,company_name,notes,parent_user_name,add_time,mdy_time) " + + "values ('" + nick_name + "','" + user_name + "','" + mobile + "','" + password + "','" + card_id + "','" + + group_id + "','" + company_name + "','" + notes + "','" + parent_user_name + "','" + + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "','" + + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "');"; + var rst = mySql.ExecuteNonQuery(sql); + mySql.Close(); + if (!rst) + return "{\"code\":501,\"msg\":\""+ mySql.Message + "\"}"; + else + return "{\"code\":200,\"msg\":\"子账户创建成功!\"}"; + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + public string GetSubUser(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + var user_name = RegexUtils.GetStringQuery(ref inputData, "user_name"); + var password = RegexUtils.GetStringQuery(ref inputData, "password"); + var group = RegexUtils.GetStringQuery(ref inputData, "group"); + int r2 = 0; + int.TryParse(RegexUtils.GetStringQuery(ref inputData, "r2"), out r2); + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = "select * from dyxd.user where parent_user_name='" + + user_name + "'"; + + var dt = mySql.ExecuteDataTable(sql); + mySql.Close(); + if (dt != null) + { + List userList = new List(); + foreach (DataRow row in dt.Rows) + { + + UserLoginResultParam user = new UserLoginResultParam + { + id = Convert.ToInt32(row["id"]), + user_name = row["user_name"].ToString(), + nick_name = row["nick_name"].ToString(), + mobile = row["mobile"].ToString(), + password = row["password"].ToString(), + group_id = row["group_id"].ToString(), + card_id = row["card_id"].ToString(), + parent_user_name = row["parent_user_name"].ToString(), + company_name = row["company_name"].ToString(), + notes = row["notes"].ToString(), + }; + if (string.IsNullOrEmpty(user.mobile)) + { + user.mobile = row["user_name"].ToString(); + } + userList.Add(user); + } + var data = JsonUtils.SerializeObjectToString(userList); + return "{\"code\":200,\"msg\":\"success\",\"data\":" + data + ",\"c\":\"" + EncrypUtil.Encryption(r2) + "\"}"; + } + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + public string UpdateSubUser(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + var id = RegexUtils.GetStringQuery(ref inputData, "id")?.Replace("'", "\\'"); + var parent_user_name = RegexUtils.GetStringQuery(ref inputData, "user_name")?.Replace("'", "\\'"); + var nick_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "sub_nick_name"))?.Replace("'", "\\'"); + var user_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "sub_name"))?.Replace("'", "\\'"); + var mobile = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "sub_mobile"))?.Replace("'", "\\'"); + var password = RegexUtils.GetStringQuery(ref inputData, "sub_password")?.Replace("'", "\\'"); + var group_id = RegexUtils.GetStringQuery(ref inputData, "group_id")?.Replace("'", "\\'"); + var card_id = RegexUtils.GetStringQuery(ref inputData, "card_id")?.Replace("'", "\\'"); + var notes = RegexUtils.GetStringQuery(ref inputData, "notes")?.Replace("'", "\\'"); + int r2 = 0; + int.TryParse(RegexUtils.GetStringQuery(ref inputData, "r2"), out r2); + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = ""; + //sql = "select * from dyxd.user where parent_user_name='" + // + user_name + "'"; + sql = "update dyxd.user set"; + if (!string.IsNullOrEmpty(nick_name)) + sql += " nick_name='" + nick_name + "',"; + if (!string.IsNullOrEmpty(user_name)) + sql += " user_name='" + user_name + "',"; + if (!string.IsNullOrEmpty(mobile)) + sql += " mobile='" + mobile + "',"; + if (!string.IsNullOrEmpty(password)) + sql += " password='" + password + "',"; + if (!string.IsNullOrEmpty(group_id)) + sql += " group_id=" + group_id + ","; + if (!string.IsNullOrEmpty(card_id)) + sql += " card_id='" + card_id + "',"; + if (!string.IsNullOrEmpty(notes)) + sql += " notes='" + notes + "',"; + sql = sql.TrimEnd(','); + sql += " where id=" + id + ""; + + var rst = mySql.ExecuteNonQuery(sql); + mySql.Close(); + if (rst) + { + return "{\"code\":200,\"msg\":\"success\"}"; + } + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + + public string DelUser(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + var user_name = RegexUtils.GetStringQuery(ref inputData, "user_name"); + var id = RegexUtils.GetStringQuery(ref inputData, "id"); + int r2 = 0; + int.TryParse(RegexUtils.GetStringQuery(ref inputData, "r2"), out r2); + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = "delete from dyxd.user where id='" + + id + "'"; + + var rst = mySql.ExecuteNonQuery(sql); + mySql.Close(); + if (rst) + { + return "{\"code\":200,\"msg\":\"success\"}"; + } + else + return "{\"code\":500,\"msg\":\"删除失败,请稍后重试\"}"; + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + public string GetAllUser(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + var user_name = RegexUtils.GetStringQuery(ref inputData, "user_name")?.Replace("'", "\\'"); + var password = RegexUtils.GetStringQuery(ref inputData, "password")?.Replace("'", "\\'"); + var group_id = RegexUtils.GetStringQuery(ref inputData, "group_id")?.Replace("'", "\\'"); + var search = RegexUtils.GetStringQuery(ref inputData, "search")?.Replace("'", "\\'"); + var sa_level = RegexUtils.GetStringQuery(ref inputData, "sa_level")?.Replace("'", "\\'"); + int r2 = 0; + int.TryParse(RegexUtils.GetStringQuery(ref inputData, "r2"), out r2); + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + //string sql = "select * from dyxd.user where group_id=3"; + string sql = "select * from dyxd.user where 1=1"; + if (!string.IsNullOrEmpty(group_id)) + sql += " and group_id=" + group_id; + if (!string.IsNullOrEmpty(sa_level)) + sql += " and sa_level=" + sa_level; + if (!string.IsNullOrEmpty(search)) + sql += " and (user_name like '%" + search + + "%' or nick_name like '%" + search + + "%' or company_name like '%" + search + "%')"; + sql += " order by id desc"; + + var dt = mySql.ExecuteDataTable(sql); + mySql.Close(); + if (dt != null) + { + List userList = new List(); + foreach (DataRow row in dt.Rows) + { + + UserLoginResultParam user = new UserLoginResultParam + { + id = Convert.ToInt32(row["id"]), + user_name = row["user_name"].ToString(), + nick_name = row["nick_name"].ToString(), + mobile = row["mobile"].ToString(), + password = row["password"].ToString(), + group_id = row["group_id"].ToString(), + card_id = row["card_id"].ToString(), + parent_user_name = row["parent_user_name"].ToString(), + company_name = row["company_name"].ToString(), + notes = row["notes"].ToString(), + is_sa = row.Table.Columns.Contains("is_sa") ? row["is_sa"].ParseToInt() : 0, + sa_level = row.Table.Columns.Contains("sa_level") ? row["sa_level"].ParseToInt() : 0, + }; + if (string.IsNullOrEmpty(user.mobile)) + { + user.mobile = row["user_name"].ToString(); + } + userList.Add(user); + } + var data = JsonUtils.SerializeObjectToString(userList); + return "{\"code\":200,\"msg\":\"success\",\"data\":" + data + ",\"c\":\"" + EncrypUtil.Encryption(r2) + "\"}"; + } + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + public string AddUser(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + var nick_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "add_nick_name"))?.Replace("'", "\\'"); + var user_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "add_user_name"))?.Replace("'", "\\'"); + var mobile = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "add_mobile"))?.Replace("'", "\\'"); + var password = RegexUtils.GetStringQuery(ref inputData, "add_password")?.Replace("'", "\\'"); + var company_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "add_company"))?.Replace("'", "\\'"); + var group_id = RegexUtils.GetStringQuery(ref inputData, "group_id")?.Replace("'", "\\'"); ; + var card_id = RegexUtils.GetStringQuery(ref inputData, "card_id")?.Replace("'", "\\'"); + var notes = RegexUtils.GetStringQuery(ref inputData, "notes")?.Replace("'", "\\'"); + var sa_level = RegexUtils.GetStringQuery(ref inputData, "sa_level")?.Replace("'", "\\'"); + int r2 = 0; + int.TryParse(RegexUtils.GetStringQuery(ref inputData, "r2"), out r2); + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = ""; + sql = "select exists (select 1 from dyxd.user where user_name='" + user_name + "')"; + var exist = mySql.ExecuteFirstInt(sql); + if (exist > 0) + { + mySql.Close(); + return "{\"code\":500,\"msg\":\"用户名已存在\"}"; + } + + sql = "insert into dyxd.user (nick_name,user_name,mobile,password,card_id,group_id,company_name,notes,sa_level,add_time,mdy_time) " + + "values ('" + nick_name + "','" + user_name + "','" + mobile + "','" + password + "','" + card_id + "','" + + group_id + "','" + company_name + "','" + notes + "'," + sa_level + ",'" + + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "','" + + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "');"; + var rst = mySql.ExecuteNonQuery(sql); + mySql.Close(); + if (!rst) + return "{\"code\":501,\"msg\":\"" + mySql.Message + "\"}"; + else + return "{\"code\":200,\"msg\":\"success\"}"; + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + public string UpdateUser(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + var id = RegexUtils.GetStringQuery(ref inputData, "id")?.Replace("'", "\\'"); + var nick_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "add_nick_name"))?.Replace("'", "\\'"); + var user_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "add_user_name"))?.Replace("'", "\\'"); + var mobile = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "add_mobile"))?.Replace("'", "\\'"); + var company_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "add_company"))?.Replace("'", "\\'"); + var password = RegexUtils.GetStringQuery(ref inputData, "add_password")?.Replace("'", "\\'"); + var group_id = RegexUtils.GetStringQuery(ref inputData, "group_id")?.Replace("'", "\\'"); + var card_id = RegexUtils.GetStringQuery(ref inputData, "card_id")?.Replace("'", "\\'"); + var notes = RegexUtils.GetStringQuery(ref inputData, "notes")?.Replace("'", "\\'"); + var sa_level = RegexUtils.GetStringQuery(ref inputData, "sa_level")?.Replace("'", "\\'"); + int r2 = 0; + int.TryParse(RegexUtils.GetStringQuery(ref inputData, "r2"), out r2); + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = ""; + //sql = "select * from dyxd.user where parent_user_name='" + // + user_name + "'"; + sql = "update dyxd.user set"; + if (!string.IsNullOrEmpty(nick_name)) + sql += " nick_name='" + nick_name + "',"; + if (!string.IsNullOrEmpty(user_name)) + sql += " user_name='" + user_name + "',"; + if (!string.IsNullOrEmpty(mobile)) + sql += " mobile='" + mobile + "',"; + if (!string.IsNullOrEmpty(company_name)) + sql += " company_name='" + company_name + "',"; + if (!string.IsNullOrEmpty(password)) + sql += " password='" + password + "',"; + if (!string.IsNullOrEmpty(group_id)) + sql += " group_id=" + group_id + ","; + if (!string.IsNullOrEmpty(card_id)) + sql += " card_id='" + card_id + "',"; + if (!string.IsNullOrEmpty(notes)) + sql += " notes='" + notes + "',"; + if (!string.IsNullOrEmpty(sa_level)) + sql += " sa_level=" + sa_level + ","; + sql = sql.TrimEnd(','); + sql += " where id=" + id + ""; + + var rst = mySql.ExecuteNonQuery(sql); + mySql.Close(); + if (rst) + { + return "{\"code\":200,\"msg\":\"success\"}"; + } + else + { + return "{\"code\":500,\"msg\":\"" + mySql.Message + "\"}"; + } + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + + + public string ChangePassword(string inputData) + { + var userName = RegexUtils.GetStringJson(ref inputData, "user_name")?.Replace("'", "\\'"); + var password = RegexUtils.GetStringJson(ref inputData, "password")?.Replace("'", "\\'"); + var newPassword = RegexUtils.GetStringJson(ref inputData, "new_password")?.Replace("'", "\\'"); + + string conn = "Conn"; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = "select user_id,password from pepdtp.user where user_id='" + + userName + "' and password='" + password + "'"; + + var dw = mySql.ExecuteDataTableRow(sql); + if (dw != null) + { + UserLoginResultParam user = new UserLoginResultParam + { + user_name = dw["user_id"].ToString(), + password = dw["password"].ToString(), + }; + sql = "update pepdtp.user set password = '" + newPassword + "' where user_id='" + userName + "'"; + var result = mySql.ExecuteNonQuery(sql); + mySql.Close(); + + if (result) + { + return "{\"code\":0,\"msg\":\"密码修改成功!\"}"; + } + else + return "{\"code\":19999,\"msg\":\"密码修改失败!请稍后再试。\"}"; + } + else + { + mySql.Close(); + return "{\"code\":1,\"msg\":\"原密码错误。\"}"; + } + } + + public string return_package_secret_key { get; set; } = "aaMETt2bPe6YHzZ1ojbC+6wOvgtwehqc6A+/Rz+pCUU="; + + public string GetPackageSign(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + var mobile = RegexUtils.GetStringQuery(ref inputData, "mobile")?.Replace("'", "\\'"); + var password = RegexUtils.GetStringQuery(ref inputData, "password")?.Replace("'", "\\'"); + var timestamp = RegexUtils.GetStringQuery(ref inputData, "timestamp")?.Replace("'", "\\'"); + var mallId = RegexUtils.GetStringQuery(ref inputData, "mallId")?.Replace("'", "\\'"); + var returnPackageNo = RegexUtils.GetStringQuery(ref inputData, "returnPackageNo")?.Replace("'", "\\'"); + int r2 = RegexUtils.GetStringQuery(ref inputData, "r2").ParseToInt(); + string c2 = RegexUtils.GetStringQuery(ref inputData, "c2"); + + if (EncrypUtil.Encryption(r2) != c2) + return "{\"code\":2,\"msg\":\"不合法的输入内容\"}"; + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = "select * from dyxd.user where user_name='" + + mobile + "' and password='" + password + "'"; + + sql = "select * from dyxd.user where user_name='" + mobile + "'"; + + var dt = mySql.ExecuteDataTable(sql); + mySql.Close(); + if (dt == null || dt.Rows.Count <=0) + { + return "{\"code\":1,\"msg\":\"用户不存在\"}"; + } + + string sign = EncrypUtil.GetMd5(timestamp + return_package_secret_key + mallId + returnPackageNo).ToLower(); + + return "{\"code\":200, \"sign\":\"" + sign + "\", \"msg\":\"\"}"; + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + } +} + + + diff --git a/StoreHub.KJDWebService/Services/OrderService.cs b/StoreHub.KJDWebService/Services/OrderService.cs new file mode 100644 index 0000000..b67e0a2 --- /dev/null +++ b/StoreHub.KJDWebService/Services/OrderService.cs @@ -0,0 +1,675 @@ +using StoreHub.KJDWebService.Models; +using StoreHub.Framework.Repositorys; +using Microsoft.Extensions.Configuration; +using StoreHub.KJDWebService.Commons; +using NaiBa.Util.Extension; +using NaiBa.Util.Helper; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; +using System; +using System.Collections.Generic; +using System.Data; +using System.Diagnostics; +using System.Linq; + +namespace StoreHub.KJDWebService.Services +{ + public class OrderService : ServiceBase + { + public OrderService(SqlRepository sqlRepository, IConfiguration configuration) : base(sqlRepository, configuration) + { + } + public List year_mounth_lst = new List() { "202510", "202511", "202512", + "202601", "202602", "202603", "202604", "202605", "202606", "202607", "202608", "202609", "202610", "202611", "202612", + "202701", "202702", "202703", "202704", "202705", "202706", "202707", "202708", "202709", "202710", "202711", "202712", + "202801", "202802", "202803", "202804", "202805", "202806", "202807", "202808", "202809", "202810", "202811", "202812", + "202901", "202902", "202903", "202904", "202905", "202906", "202907", "202908", "202909", "202910", "202911", "202912", + "203001", "203002", "203003", "203004", "203005", "203006", "203007", "203008", "203009", "203010", "203011", "203012", + "203101", "203102", "203103", "203104", "203105", "203106", "203107", "203108", "203109", "203110", "203111", "203112", + "203201", "203202", "203203", "203204", "203205", "203206", "203207", "203208", "203209", "203210", "203211", "203212", + "203301", "203302", "203303", "203304", "203305", "203306", "203307", "203308", "203309", "203310", "203311", "203312" }; + public string AddOrder(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + var time = 0; + int.TryParse(RegexUtils.GetStringQuery(ref inputData, "time"), out time); + string time1 = RegexUtils.GetStringQuery(ref inputData, "code"); + if (time1 != EncrypUtil.Encryption(time)) + return "{\"code\":50000,\"msg\":\"校验失败\"}"; + + string user_name = RegexUtils.GetStringQuery(ref inputData, "user_name"); + if (string.IsNullOrEmpty(user_name)) + { + return "{\"code\":500,\"msg\":\"没有用户名\"}"; + } + var shop_id = RegexUtils.GetStringQuery(ref inputData, "shop_id")?.Replace("'", "\\'"); + if (string.IsNullOrEmpty(shop_id)) + return "{\"code\":500,\"msg\":\"请输入店铺\"}"; + + string order_data = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "order_data"))?.Replace("'", "\\'"); + if (string.IsNullOrEmpty(order_data)) + return "{\"code\":500,\"msg\":\"请输入订单参数\"}"; + + //string orderPurchaseTime = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "order_data"))?.Replace("'", "\\'"); + //if (string.IsNullOrEmpty(order_data)) + // return "{\"code\":500,\"msg\":\"请输入订单创建时间\"}"; + + JObject jObj = null; + try + { + jObj = JObject.Parse(order_data); + } + catch + { + return "{\"code\":500,\"msg\":\"数据格式错误\"}"; + } + + //long table_id = shop_id.ParseToLong() % 128; + string table_id = "999999"; + try + { + table_id = TimeUtils.StampMillisecondsToDateTime(long.Parse(jObj["purchaseTime"].ToString())).ToString("yyyyMM"); + } + catch (Exception ex) + { + return "{\"code\":500,\"msg\":\"" + ex.Message + "\"}"; + } + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = ""; + + sql = "insert into kjd_order.order_" + table_id + " ("; + foreach (var item in jObj) + { + if (item.Key.ParseToString() != "id" && JsonConvert.SerializeObject(item.Value) != "null" && + item.Key.ParseToString() != "add_time" && item.Key.ParseToString() != "mdy_time") + sql += item.Key + ","; + } + sql = sql.Trim(','); + sql += ")"; + sql += "values ("; + foreach (var item in jObj) + { + if (item.Key.ParseToString() != "id" && JsonConvert.SerializeObject(item.Value) != "null" && + item.Key.ParseToString() != "add_time" && item.Key.ParseToString() != "mdy_time") + sql += "'" + item.Value.ParseToString().Replace("\\'", "'").Replace("'", "\\'") + "',"; + } + sql = sql.Trim(','); + sql += ");"; + var rst = mySql.ExecuteInsertId(sql); + mySql.Close(); + if (rst > 0) + { + return "{\"code\":200,\"msg\":\"success\"}"; + } + else + { + return "{\"code\":500,\"msg\":\"" + mySql.Message + "\"}"; + } + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + public string GetOrderList(string inputData, bool isDetail = false) + { + 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("'", "\\'"); + var password = RegexUtils.GetStringQuery(ref inputData, "password")?.Replace("'", "\\'"); + + var shop_id = RegexUtils.GetStringQuery(ref inputData, "shop_id")?.Replace("'", "\\'"); + //if (string.IsNullOrEmpty(shop_id)) + // return "{\"code\":500,\"msg\":\"请输入查询店铺\",\"data\":[],\"count\":" + 0 + "}"; + + var upload_order_status = RegexUtils.GetStringQuery(ref inputData, "upload_order_status")?.Replace("'", "\\'"); + //var start_time = RegexUtils.GetStringQuery(ref inputData, "start_time")?.Replace("'", "\\'"); + var start_time = TimeUtils.DateTimeToTimestampMilliseconds(DateTime.Now.Date.AddDays(-30)); + + int page = RegexUtils.GetStringQuery(ref inputData, "page").ParseToInt(); + int page_size = RegexUtils.GetStringQuery(ref inputData, "page_size").ParseToInt(50); + + string startTimeStr = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "startTime"))?.Replace("'", "\\'"); + string endTimeStr = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "endTime"))?.Replace("'", "\\'"); + if (string.IsNullOrEmpty(endTimeStr)) + { + var datetime = DateTime.Now; + startTimeStr = datetime.AddMonths(-1).ToString("yyyyMM"); + endTimeStr = datetime.ToString("yyyyMM"); + } + var startIndex = year_mounth_lst.IndexOf(startTimeStr); + var endIndex = year_mounth_lst.IndexOf(endTimeStr); + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + + //long table_id = shop_id.ParseToLong() % 128; + //sql = "select count(id) from kjd_order.order_" + table_id + " o where 1=1"; + string sql = ""; + sql += " SELECT count(*) FROM ( "; + for (int i = startIndex; i<=endIndex; i++) + { + if (i > startIndex) + sql += " UNION ALL "; + sql += " SELECT id,purchaseTime,supplierId,upLoadStatus FROM kjd_order.order_" + year_mounth_lst[i]; + } + sql += " ) AS o WHERE 1=1"; + + string where = ""; + if (start_time > 0) + where += " and o.purchaseTime > " + start_time; + if (!string.IsNullOrWhiteSpace(shop_id)) + where += " and o.supplierId = '" + shop_id + "'"; + if (!string.IsNullOrEmpty(upload_order_status)) + where += " and upLoadStatus >= " + upload_order_status; + sql += where; + + var count = mySql.ExecuteRowCount(sql); + + DataTable dt; + if (count == 0) + { + dt = new DataTable(); + } + else + { + //sql = "SELECT * FROM kjd_order.order_" + table_id + " o where 1=1"; // p.is_del=0 + sql = " SELECT * FROM ( "; + for (int i = startIndex; i <= endIndex; i++) + { + if (i > startIndex) + sql += " UNION ALL "; + sql += " SELECT * FROM kjd_order.order_" + year_mounth_lst[i]; + } + sql += " ) AS o WHERE 1=1"; + + //where子句 + sql += where; + + sql += " ORDER BY o.purchaseTime desc"; + //sql += " ORDER BY o.select_total_count desc, p.id desc"; + sql += " LIMIT " + Math.Max(page - 1, 0) * page_size + "," + page_size; + dt = mySql.ExecuteDataTable(sql); + } + + mySql.Close(); + if (dt != null) + { + try + { + List orderLst = new List(); + foreach (DataRow row in dt.Rows) + { + TemuDBOrderInfo prod = new TemuDBOrderInfo + { + id = Convert.ToInt32(row["id"]), + add_time = Convert.ToDateTime(row["add_time"]), + mdy_time = Convert.ToDateTime(row["mdy_time"]), + notes = row["notes"].ParseToString(), + availableSaleDays = row["availableSaleDays"].ParseToNullableDecimal(), + barCodeMd5 = row["barCodeMd5"].ParseToString(), + category = row["category"].ParseToString(), + className = row["className"].ParseToString(), + costPrice = row["costPrice"].ParseToNullableInt(), + currencyType = row["currencyType"].ParseToString(), + deliverQuantity = row["deliverQuantity"].ParseToInt(), + deliverTime = row["deliverTime"].ParseToNullableLong(), + deliveryFee = row["deliveryFee"].ParseToNullableInt(), + deliveryOrderSn = row["deliveryOrderSn"].ParseToString(), + expectLatestArrivalTimeOrDefault = row["expectLatestArrivalTimeOrDefault"].ParseToLong(), + expectLatestDeliverTimeOrDefault = row["expectLatestDeliverTimeOrDefault"].ParseToLong(), + extCode = row["extCode"].ParseToString(), + jiaTongCode = row["jiaTongCode"].ParseToString(), + markFee = row["markFee"].ParseToNullableInt(), + originalPurchaseOrderSn = row["originalPurchaseOrderSn"].ParseToString(), + productId = row["productId"].ParseToString(), + productName = row["productName"].ParseToString(), + productSkcPicture = row["productSkcPicture"].ParseToString(), + productSkcId = row["productSkcId"].ParseToString(), + productSkuId = row["productSkuId"].ParseToString(), + productSn = row["productSn"].ParseToString(), + purchaseQuantity = row["purchaseQuantity"].ParseToInt(), + purchaseTime = row["purchaseTime"].ParseToLong(), + qcResult = row["qcResult"].ParseToNullableInt(), + realReceiveAuthenticQuantity = row["realReceiveAuthenticQuantity"].ParseToInt(), + receiveTime = row["receiveTime"].ParseToNullableLong(), + receiveWarehouseId = row["receiveWarehouseId"].ParseToString(), + receiveWarehouseName = row["receiveWarehouseName"].ParseToString(), + shippingMarkMd5 = row["shippingMarkMd5"].ParseToString(), + status = row["status"].ParseToInt(), + subPurchaseOrderSn = row["subPurchaseOrderSn"].ParseToString(), + supplierId = row["supplierId"].ParseToString(), + supplierName = row["supplierName"].ParseToString(), + supplierPrice = row["supplierPrice"].ParseToInt(), + thumbUrlList = row["thumbUrlList"].ParseToString(), + upLoadStatus = row["upLoadStatus"].ParseToInt(), + upProductId = row["upProductId"].ParseToString(), + warehouseGroupId = row["warehouseGroupId"].ParseToString(), + }; + orderLst.Add(prod); + } + var data = JsonUtils.SerializeObjectToString(orderLst); + return "{\"code\":200,\"msg\":\"success\",\"data\":" + data + ",\"count\":" + count + "}"; + } + 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 UpdateOrderStatus1(string inputData, bool isDetail = false) + { + //作废 + //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("'", "\\'"); + // var password = RegexUtils.GetStringQuery(ref inputData, "password")?.Replace("'", "\\'"); + + // var shop_id = RegexUtils.GetStringQuery(ref inputData, "shop_id")?.Replace("'", "\\'"); + // if (string.IsNullOrEmpty(shop_id)) + // return "{\"code\":500,\"msg\":\"请输入查询店铺\"}"; + // var product_id = RegexUtils.GetStringQuery(ref inputData, "product_id")?.Replace("'", "\\'"); + // if (string.IsNullOrEmpty(product_id)) + // return "{\"code\":500,\"msg\":\"请输入商品编号\"}"; + + // int page = RegexUtils.GetStringQuery(ref inputData, "page").ParseToInt(); + // int page_size = RegexUtils.GetStringQuery(ref inputData, "page_size").ParseToInt(50); + + // string conn = "ConnKJD"; + // MysqlUtils mySql = new MysqlUtils(conn); + + // long table_id = shop_id.ParseToLong() % 128; + // string sql = "update kjd_order.order_" + table_id + " o set o.upLoadStatus=1"; + + // string where = ""; + // where += " and o.supplierId = '" + shop_id + "'"; + // where += " and o.productId = '" + product_id + "'"; + // where += " and o.upLoadStatus < 1"; + // sql += where; + + // 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 AddOrderCodeFile(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + var time = 0; + int.TryParse(RegexUtils.GetStringQuery(ref inputData, "time"), out time); + string time1 = RegexUtils.GetStringQuery(ref inputData, "code"); + if (time1 != EncrypUtil.Encryption(time)) + return "{\"code\":50000,\"msg\":\"校验失败\"}"; + + string user_name = RegexUtils.GetStringQuery(ref inputData, "user_name"); + if (string.IsNullOrEmpty(user_name)) + { + return "{\"code\":500,\"msg\":\"没有用户名\"}"; + } + var shop_id = RegexUtils.GetStringQuery(ref inputData, "shop_id")?.Replace("'", "\\'"); + if (string.IsNullOrEmpty(shop_id)) + return "{\"code\":500,\"msg\":\"请输入店铺\"}"; + + string file_md5 = RegexUtils.GetStringQuery(ref inputData, "file_md5")?.Replace("'", "\\'"); + string file_base64 = RegexUtils.GetStringQuery(ref inputData, "file_base64")?.Replace("'", "\\'"); + if (string.IsNullOrEmpty(file_md5) || string.IsNullOrEmpty(file_base64)) + return "{\"code\":500,\"msg\":\"请输入文件信息\"}"; + + //long table_id = shop_id.ParseToLong() % 128; + string purchaseTime = RegexUtils.GetStringQuery(ref inputData, "purchaseTime")?.Replace("'", "\\'"); + string table_id = "999999"; + try + { + table_id = TimeUtils.StampMillisecondsToDateTime(long.Parse(purchaseTime)).ToString("yyyyMM"); + } + catch (Exception ex) + { + return "{\"code\":500,\"msg\":\"请输入正确的时间:" + ex.Message + "\"}"; + } + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = ""; + + sql = "select count(fileCodeMd5) from kjd_order.order_code_" + table_id + " where fileCodeMd5='" + file_md5 + "';"; + var rowCount = mySql.ExecuteRowCount(sql); + if (!string.IsNullOrEmpty(mySql.Message)) + { + mySql.Close(); + return "{\"code\":500,\"msg\":\"" + mySql.Message + "\"}"; + } + else if (rowCount > 0) + { + mySql.Close(); + return "{\"code\":200,\"msg\":\"success\"}"; + } + + sql = "insert into kjd_order.order_code_" + table_id + " (supplierId,fileCodeMd5,fileCodeBase64)"; + sql += " values ('" + shop_id + "','" + file_md5 + "','" + file_base64 + "')"; + + var rst = mySql.ExecuteNonQuery(sql); + mySql.Close(); + if (!rst) + { + return "{\"code\":500,\"msg\":\"" + mySql.Message + "\"}"; + } + + return "{\"code\":200,\"msg\":\"success\"}"; + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + public string SaveOrderCodeFileLink(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + var time = 0; + int.TryParse(RegexUtils.GetStringQuery(ref inputData, "time"), out time); + string time1 = RegexUtils.GetStringQuery(ref inputData, "code"); + if (time1 != EncrypUtil.Encryption(time)) + return "{\"code\":50000,\"msg\":\"校验失败\"}"; + + string user_name = RegexUtils.GetStringQuery(ref inputData, "user_name"); + if (string.IsNullOrEmpty(user_name)) + { + return "{\"code\":500,\"msg\":\"没有用户名\"}"; + } + var shop_id = RegexUtils.GetStringQuery(ref inputData, "shop_id")?.Replace("'", "\\'"); + if (string.IsNullOrEmpty(shop_id)) + return "{\"code\":500,\"msg\":\"请输入店铺\"}"; + var sub_order_sn = RegexUtils.GetStringQuery(ref inputData, "sub_order_sn")?.Replace("'", "\\'"); + if (string.IsNullOrEmpty(sub_order_sn)) + return "{\"code\":500,\"msg\":\"请输入子单号\"}"; + + string jia_tong_code = RegexUtils.GetStringQuery(ref inputData, "jia_tong_code")?.Replace("'", "\\'"); // 佳同码 + string bar_code_md5 = RegexUtils.GetStringQuery(ref inputData, "bar_code_md5")?.Replace("'", "\\'"); // 商品条码md5 + string shipping_mark_md5 = RegexUtils.GetStringQuery(ref inputData, "shipping_mark_md5")?.Replace("'", "\\'"); // 箱唛md5 + if (string.IsNullOrEmpty(jia_tong_code) && string.IsNullOrEmpty(bar_code_md5) && string.IsNullOrEmpty(shipping_mark_md5)) + return "{\"code\":500,\"msg\":\"请输入文件信息\"}"; + + //long table_id = shop_id.ParseToLong() % 128; + string purchaseTime = RegexUtils.GetStringQuery(ref inputData, "purchaseTime")?.Replace("'", "\\'"); // 佳同码 + string table_id = "999999"; + try + { + table_id = TimeUtils.StampMillisecondsToDateTime(long.Parse(purchaseTime)).ToString("yyyyMM"); + } + catch (Exception ex) + { + return "{\"code\":500,\"msg\":\"请输入正确的时间:" + ex.Message + "\"}"; + } + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = ""; + + sql = "update kjd_order.order_" + table_id; + sql += " set"; + if (jia_tong_code != null) + sql += " jiaTongCode='" + jia_tong_code + "',"; + if (bar_code_md5 != null) + sql += " barCodeMd5='" + bar_code_md5 + "',"; + if (shipping_mark_md5 != null) + sql += " shippingMarkMd5='" + shipping_mark_md5 + "',"; + sql = sql.TrimEnd(','); + sql += " where subPurchaseOrderSn='" + sub_order_sn + "';"; + var rst = mySql.ExecuteNonQuery(sql); + mySql.Close(); + if (rst) + { + return "{\"code\":200,\"msg\":\"success\"}"; + } + return "{\"code\":500,\"msg\":\"" + mySql.Message + "\"}"; + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + public string getOrderCodeFile(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + var time = 0; + int.TryParse(RegexUtils.GetStringQuery(ref inputData, "time"), out time); + string time1 = RegexUtils.GetStringQuery(ref inputData, "code"); + if (time1 != EncrypUtil.Encryption(time)) + return "{\"code\":50000,\"msg\":\"校验失败\"}"; + + string user_name = RegexUtils.GetStringQuery(ref inputData, "user_name"); + if (string.IsNullOrEmpty(user_name)) + { + return "{\"code\":500,\"msg\":\"没有用户名\"}"; + } + var shop_id = RegexUtils.GetStringQuery(ref inputData, "shop_id")?.Replace("'", "\\'"); + if (string.IsNullOrEmpty(shop_id)) + return "{\"code\":500,\"msg\":\"请输入店铺\"}"; + + string file_md5 = RegexUtils.GetStringQuery(ref inputData, "file_md5")?.Replace("'", "\\'"); + if (string.IsNullOrEmpty(file_md5)) + return "{\"code\":500,\"msg\":\"请输入文件信息\"}"; + + //long table_id = shop_id.ParseToLong() % 128; + string purchaseTime = RegexUtils.GetStringQuery(ref inputData, "purchaseTime")?.Replace("'", "\\'"); + string table_id = "999999"; + try + { + table_id = TimeUtils.StampMillisecondsToDateTime(long.Parse(purchaseTime)).ToString("yyyyMM"); + } + catch (Exception ex) + { + return "{\"code\":500,\"msg\":\"请输入正确的时间:" + ex.Message + "\"}"; + } + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = ""; + + sql = "select fileCodeMd5,fileCodeBase64 from kjd_order.order_code_" + table_id + " where fileCodeMd5='" + file_md5 + "';"; + + var dt = mySql.ExecuteDataTable(sql); + mySql.Close(); + if (!string.IsNullOrEmpty(mySql.Message)) + { + return "{\"code\":500,\"msg\":\"" + mySql.Message + "\"}"; + } + else + { + string file_md5_rst = ""; + string file_base64_rst = ""; + if (dt.Rows.Count > 0) + { + file_md5_rst = dt.Rows[0]["fileCodeMd5"].ParseToString(); + file_base64_rst = dt.Rows[0]["fileCodeBase64"].ParseToString(); + } + return "{\"code\":200,\"msg\":\"success\",\"data\":\"{\"file_md5\":\"" + file_md5_rst + "\",\"file_base64\":\"" + file_base64_rst + "\"}\"}"; + } + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + public string UploadOrder(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + var time = 0; + int.TryParse(RegexUtils.GetStringQuery(ref inputData, "time"), out time); + string time1 = RegexUtils.GetStringQuery(ref inputData, "code"); + if (time1 != EncrypUtil.Encryption(time)) + return "{\"code\":50000,\"msg\":\"校验失败\"}"; + + string user_name = RegexUtils.GetStringQuery(ref inputData, "user_name")?.Replace("'", "\\'"); + if (string.IsNullOrEmpty(user_name)) + { + return "{\"code\":500,\"msg\":\"没有用户名\"}"; + } + var shop_id = RegexUtils.GetStringQuery(ref inputData, "shop_id")?.Replace("'", "\\'"); + if (string.IsNullOrEmpty(shop_id)) + return "{\"code\":500,\"msg\":\"请输入店铺\"}"; + + string subPurchaseOrderSn = RegexUtils.GetStringQuery(ref inputData, "subPurchaseOrderSn")?.Replace("'", "\\'"); + if (string.IsNullOrEmpty(subPurchaseOrderSn)) + return "{\"code\":500,\"msg\":\"请输入订单编号\"}"; + + string feeStr = RegexUtils.GetStringQuery(ref inputData, "fee")?.Replace("'", "\\'"); + if (string.IsNullOrEmpty(feeStr)) + return "{\"code\":500,\"msg\":\"请输入费用\"}"; + decimal fee = feeStr.ParseToDecimal(); + + //long table_id = shop_id.ParseToLong() % 128; + string purchaseTime = RegexUtils.GetStringQuery(ref inputData, "purchaseTime")?.Replace("'", "\\'"); + string table_id = "999999"; + try + { + table_id = TimeUtils.StampMillisecondsToDateTime(long.Parse(purchaseTime)).ToString("yyyyMM"); + } + catch (Exception ex) + { + return "{\"code\":500,\"msg\":\"请输入正确的时间:" + ex.Message + "\"}"; + } + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = ""; + + sql = "select authorized_amount from kjd.user where user_name='" + user_name + "'"; + var value = mySql.ExecuteFirst(sql); + if (!string.IsNullOrEmpty(mySql.Message)) + { + mySql.Close(); + return "{\"code\":500,\"msg\":\"" + mySql.Message + "\"}"; + } + if (value.IsNullOrEmpty()) + { + mySql.Close(); + return "{\"code\":500,\"msg\":\"用户不存\"}"; + } + if (value.ParseToDecimal() < fee) + { + mySql.Close(); + return "{\"code\":500,\"msg\":\"授权金不足\"}"; + } + + sql = "update kjd_order.order_" + table_id + " set upLoadStatus=2 where upLoadStatus < 2 and subPurchaseOrderSn in('" + subPurchaseOrderSn + "');"; + var rst = mySql.ExecuteAffectedRows(sql); + if (!string.IsNullOrEmpty(mySql.Message)) + { + mySql.Close(); + return "{\"code\":500,\"msg\":\"" + mySql.Message + "\"}"; + } + if (rst == 0) + { + mySql.Close(); + return "{\"code\":500,\"msg\":\"订单不存在或已上传\"}"; + } + + sql = "update kjd.user set authorized_amount=authorized_amount-" + fee + " where user_name='" + user_name + "';"; + rst = mySql.ExecuteAffectedRows(sql); + mySql.Close(); + if (!string.IsNullOrEmpty(mySql.Message)) + { + return "{\"code\":500,\"msg\":\"" + mySql.Message + "\"}"; + } + if(rst == 0) + { + return "{\"code\":500,\"msg\":\"订单已提交但扣费失败\"}"; + } + return "{\"code\":200,\"msg\":\"success\"}"; + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + public string UpdateOrderStatus(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + var time = 0; + int.TryParse(RegexUtils.GetStringQuery(ref inputData, "time"), out time); + string time1 = RegexUtils.GetStringQuery(ref inputData, "code"); + if (time1 != EncrypUtil.Encryption(time)) + return "{\"code\":50000,\"msg\":\"校验失败\"}"; + + string user_name = RegexUtils.GetStringQuery(ref inputData, "user_name"); + if (string.IsNullOrEmpty(user_name)) + { + return "{\"code\":500,\"msg\":\"没有用户名\"}"; + } + var shop_id = RegexUtils.GetStringQuery(ref inputData, "shop_id")?.Replace("'", "\\'"); + if (string.IsNullOrEmpty(shop_id)) + return "{\"code\":500,\"msg\":\"请输入店铺\"}"; + + string subPurchaseOrderSn = RegexUtils.GetStringQuery(ref inputData, "subPurchaseOrderSn")?.Replace("'", "\\'"); + if (string.IsNullOrEmpty(subPurchaseOrderSn)) + return "{\"code\":500,\"msg\":\"请输入订单编号\"}"; + + string new_status = RegexUtils.GetStringQuery(ref inputData, "new_status")?.Replace("'", "\\'"); + string old_status = RegexUtils.GetStringQuery(ref inputData, "old_status")?.Replace("'", "\\'"); + if (string.IsNullOrEmpty(new_status)) + return "{\"code\":500,\"msg\":\"请输入订单状态\"}"; + + //long table_id = shop_id.ParseToLong() % 128; + string purchaseTime = RegexUtils.GetStringQuery(ref inputData, "purchaseTime")?.Replace("'", "\\'"); + string table_id = "999999"; + try + { + table_id = TimeUtils.StampMillisecondsToDateTime(long.Parse(purchaseTime)).ToString("yyyyMM"); + } + catch (Exception ex) + { + return "{\"code\":500,\"msg\":\"请输入正确的时间:" + ex.Message + "\"}"; + } + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = ""; + + sql = "update kjd_order.order_" + table_id + " set upLoadStatus=" + new_status + " where 1=1"; + if (!string.IsNullOrEmpty(old_status)) + sql += " and upLoadStatus=" + old_status; + sql += " and subPurchaseOrderSn in('" + subPurchaseOrderSn + "');"; + var rst = mySql.ExecuteAffectedRows(sql); + mySql.Close(); + if (!string.IsNullOrEmpty(mySql.Message)) + { + return "{\"code\":500,\"msg\":\"" + mySql.Message + "\"}"; + } + else + { + return "{\"code\":200,\"msg\":\"success\"}"; + } + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + } +} + + + + diff --git a/StoreHub.KJDWebService/Services/PriceService.cs b/StoreHub.KJDWebService/Services/PriceService.cs new file mode 100644 index 0000000..c7928c8 --- /dev/null +++ b/StoreHub.KJDWebService/Services/PriceService.cs @@ -0,0 +1,607 @@ +using StoreHub.KJDWebService.Models; +using StoreHub.Framework.Repositorys; +using Microsoft.Extensions.Configuration; +using StoreHub.KJDWebService.Commons; +using MySql.Data.MySqlClient; +using NaiBa.Util.Extension; +using System; +using System.Collections.Generic; +using System.Data; +using System.Linq; + +namespace StoreHub.KJDWebService.Services +{ + public class PriceService : ServiceBase + { + public PriceService(SqlRepository sqlRepository, IConfiguration configuration) : base(sqlRepository, configuration) + { + } + public string AddPrice(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\":\"校验失败\"}"; + + string user_name = RegexUtils.GetStringQuery(ref inputData, "user_name"); + string ext_code = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "ext_code")).ParseToString(); + int original_price = RegexUtils.GetStringQuery(ref inputData, "original_price").ParseToInt(); + int markup_times = RegexUtils.GetStringQuery(ref inputData, "markup_times").ParseToInt(); + int extra_price = RegexUtils.GetStringQuery(ref inputData, "extra_price").ParseToInt(); + string notes = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "notes")).ParseToString(); + + if (string.IsNullOrEmpty(user_name)) + { + return "{\"code\":500,\"msg\":\"没有用户名\"}"; + } + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + string sqlExist = "select count(ext_code) from kjd.price_markup where ext_code=@ext_code"; + string sql = "insert into kjd.price_markup " + + "(ext_code,original_price,markup_times,extra_price,notes) " + + "values (@ext_code,@original_price,@markup_times,@extra_price,@notes);"; + List paramLst = new List(); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "@ext_code", Value = ext_code, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.Int32, ParameterName = "@original_price", Value = original_price, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.Int32, ParameterName = "@markup_times", Value = markup_times, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.Int32, ParameterName = "@extra_price", Value = extra_price, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "@notes", Value = notes, }); + + var has = mySql.ExecuteFirst(sqlExist, paramLst.ToArray()); + if (has != "0") + { + mySql.Close(); + return "{\"code\":501,\"msg\":\"货号 " + ext_code + " 价格数据已存在\"}"; + } + + var rst = mySql.ExecuteNonQuery(sql, paramLst.ToArray()); + mySql.Close(); + if (rst) + { + return "{\"code\":200,\"msg\":\"success\"}"; + } + else + { + return "{\"code\":502,\"msg\":\"" + mySql.Message + "\"}"; + } + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + public string GetPriceList(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"); + + string start_original_price = RegexUtils.GetStringQuery(ref inputData, "start_original_price"); + string end_original_price = RegexUtils.GetStringQuery(ref inputData, "end_original_price"); + string start_markup_times = RegexUtils.GetStringQuery(ref inputData, "start_markup_times"); + string end_markup_times = RegexUtils.GetStringQuery(ref inputData, "end_markup_times"); + string start_extra_price = RegexUtils.GetStringQuery(ref inputData, "start_extra_price"); + string end_extra_price = RegexUtils.GetStringQuery(ref inputData, "end_extra_price"); + var search_ext_code = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "search_ext_code")); + var search_notes = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "search_notes")); + var in_ext_code = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "in_ext_code")); + int page = RegexUtils.GetStringQuery(ref inputData, "page").ParseToInt(); + int page_size = RegexUtils.GetStringQuery(ref inputData, "page_size").ParseToInt(50); + if (string.IsNullOrEmpty(user_name)) + { + return "{\"code\":500,\"msg\":\"没有用户名\"}"; + } + + + List paramLst = new List(); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "@search_ext_code", Value = "%" + search_ext_code + "%", }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "@search_notes", Value = "%" + search_notes + "%", }); + paramLst.Add(new MySqlParameter() { DbType = DbType.Int32, ParameterName = "@start_original_price", Value = start_original_price.ParseToInt(), }); + paramLst.Add(new MySqlParameter() { DbType = DbType.Int32, ParameterName = "@end_original_price", Value = end_original_price.ParseToInt(), }); + paramLst.Add(new MySqlParameter() { DbType = DbType.Int32, ParameterName = "@start_markup_times", Value = start_markup_times.ParseToInt(), }); + paramLst.Add(new MySqlParameter() { DbType = DbType.Int32, ParameterName = "@end_markup_times", Value = end_markup_times.ParseToInt(), }); + paramLst.Add(new MySqlParameter() { DbType = DbType.Int32, ParameterName = "@start_extra_price", Value = start_extra_price.ParseToInt(), }); + paramLst.Add(new MySqlParameter() { DbType = DbType.Int32, ParameterName = "@end_extra_price", Value = end_extra_price.ParseToInt(), }); + //paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "@in_ext_code", Value = "'" + in_ext_code?.Replace(",", "','") + "'", }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "@in_ext_code", Value = in_ext_code.ParseToString() }); + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + + string sql = "select count(id) from kjd.price_markup p where 1=1"; + + string where = ""; + if (!string.IsNullOrWhiteSpace(search_ext_code)) + where += " and p.ext_code like @search_ext_code"; + if (!string.IsNullOrWhiteSpace(search_notes)) + where += " and p.notes like @search_notes"; + if (!string.IsNullOrWhiteSpace(start_original_price)) + where += " and p.original_price >= @start_original_price"; + if (!string.IsNullOrWhiteSpace(end_original_price)) + where += " and p.original_price <= @end_original_price"; + if (!string.IsNullOrWhiteSpace(start_markup_times)) + where += " and p.markup_times >= @start_markup_times"; + if (!string.IsNullOrWhiteSpace(end_markup_times)) + where += " and p.markup_times <= @end_markup_times"; + if (!string.IsNullOrWhiteSpace(start_extra_price)) + where += " and p.extra_price >= @start_extra_price"; + if (!string.IsNullOrWhiteSpace(end_extra_price)) + where += " and p.extra_price <= @end_extra_price"; + if (!string.IsNullOrEmpty(in_ext_code)) + where += " and p.ext_code in ('" + in_ext_code?.Replace(",", "','") + "')"; + sql += where; + + var count = mySql.ExecuteRowCount(sql, paramLst.ToArray()); + + DataTable dt; + if (count == 0) + { + dt = new DataTable(); + } + else + { + sql = "select * from kjd.price_markup p where 1=1"; + + //where子句 + sql += where; + + sql += " order by p.id desc"; + sql += " limit " + Math.Max(page - 1, 0) * page_size + "," + page_size; + dt = mySql.ExecuteDataTable(sql, paramLst.ToArray()); + } + + mySql.Close(); + if (dt != null) + { + try + { + List priceList = new List(); + foreach (DataRow row in dt.Rows) + { + DBPriceResultParam price = new DBPriceResultParam + { + id = row["id"].ParseToInt(), + extra_price = row["extra_price"].ParseToInt(), + markup_times = row["markup_times"].ParseToInt(), + original_price = row["original_price"].ParseToInt(), + notes = row["notes"].ParseToString(), + ext_code = row["ext_code"].ParseToString(), + add_time = Convert.ToDateTime(row["add_time"]), + mdy_time = Convert.ToDateTime(row["mdy_time"]), + }; + priceList.Add(price); + } + var data = JsonUtils.SerializeObjectToString(priceList); + return "{\"code\":200,\"msg\":\"success\",\"data\":" + data + ",\"count\":" + count + "}"; + } + 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 DelDbPrice(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("'", "\\'"); + var id = RegexUtils.GetStringQuery(ref inputData, "db_id")?.Replace("'", "\\'"); + + if (string.IsNullOrEmpty(user_name)) + { + return "{\"code\":500,\"msg\":\"没有用户名\"}"; + } + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = "delete from kjd.price_markup where id='" + id + "'"; + + var rst = mySql.ExecuteNonQuery(sql); + mySql.Close(); + if (rst) + { + return "{\"code\":200,\"msg\":\"success\"}"; + } + else + return "{\"code\":500,\"msg\":\"删除失败:" + mySql.Message + "\"}"; + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + public string MdyDBPrice(string inputData, bool isAdmin = false) + { + 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 db_id = RegexUtils.GetStringQuery(ref inputData, "db_id"); + string notes = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "notes")); + string ext_code = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "ext_code")); + string original_price = RegexUtils.GetStringQuery(ref inputData, "original_price"); + string markup_times = RegexUtils.GetStringQuery(ref inputData, "markup_times"); + string extra_price = RegexUtils.GetStringQuery(ref inputData, "extra_price"); + + if (string.IsNullOrEmpty(user_name)) + { + return "{\"code\":500,\"msg\":\"没有用户名\"}"; + } + + List paramLst = new List(); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "@ext_code", Value = ext_code, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.Int32, ParameterName = "@original_price", Value = original_price.ParseToInt(), }); + paramLst.Add(new MySqlParameter() { DbType = DbType.Int32, ParameterName = "@markup_times", Value = markup_times.ParseToInt(), }); + paramLst.Add(new MySqlParameter() { DbType = DbType.Int32, ParameterName = "@extra_price", Value = extra_price.ParseToInt(), }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "@notes", Value = notes, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.Int32, ParameterName = "@db_id", Value = db_id, }); + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + + string sqlExist = "select count(ext_code) from kjd.price_markup where ext_code=@ext_code and id!=@db_id"; + var has = mySql.ExecuteFirst(sqlExist, paramLst.ToArray()); + if (has != "0") + { + mySql.Close(); + return "{\"code\":501,\"msg\":\"货号 " + ext_code + " 价格数据已存在\"}"; + } + + string sql = "update kjd.price_markup set"; + if (notes != null) + sql += " notes=@notes,"; + if (ext_code != null) + sql += " ext_code=@ext_code,"; + if (original_price != null) + sql += " original_price=@original_price,"; + if (markup_times != null) + sql += " markup_times=@markup_times,"; + if (extra_price != null) + sql += " extra_price=@extra_price,"; + sql = sql.TrimEnd(','); + sql += " where id=@db_id;"; + + var rst = mySql.ExecuteNonQuery(sql, paramLst.ToArray()); + mySql.Close(); + if (rst) + { + return "{\"code\":200,\"msg\":\"success\"}"; + } + else + { + return "{\"code\":500,\"msg\":\"更新失败:" + mySql.Message + "\"}"; + } + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + public string AddPurchasePrice(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\":\"校验失败\"}"; + + string user_name = RegexUtils.GetStringQuery(ref inputData, "user_name"); + if (string.IsNullOrEmpty(user_name)) + { + return "{\"code\":500,\"msg\":\"没有用户名\"}"; + } + + string shop_id = RegexUtils.GetStringQuery(ref inputData, "shop_id"); + string shop_name = RegexUtils.GetStringQuery(ref inputData, "shop_name"); + string spu_id = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "spu_id")).ParseToString(); + string skc_id = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "skc_id")).ParseToString(); + string cat_id = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "cat_id")).ParseToString(); + string cat_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "cat_name")).ParseToString(); + string ext_code = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "ext_code")).ParseToString(); + string product_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "product_name")).ParseToString(); + string main_img = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "main_img")).ParseToString(); + string discount = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "discount")).ParseToString(); + string price_text = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "price_text")).ParseToString(); + string sku_purchase_price_json = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "sku_purchase_price_json")).ParseToString(); + string notes = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "notes")).ParseToString(); + + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + string sqlExist = "select count(spu_id) from kjd.product_purchase_price where spu_id=@spu_id"; + string sql = "insert into kjd.product_purchase_price " + + "(shop_id,shop_name,spu_id,skc_id,cat_id,cat_name,ext_code,product_name,main_img,discount,price_text,sku_purchase_price_json,notes) " + + "values (@shop_id,@shop_name,@spu_id,@skc_id,@cat_id,@cat_name,@ext_code,@product_name,@main_img,@discount,@price_text,@sku_purchase_price_json,@notes);"; + List paramLst = new List(); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "@shop_id", Value = shop_id, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "@shop_name", Value = shop_name, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "@spu_id", Value = spu_id, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "@skc_id", Value = skc_id, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "@cat_id", Value = cat_id, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "@cat_name", Value = cat_name, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "@ext_code", Value = ext_code, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "@product_name", Value = product_name, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "@main_img", Value = main_img, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.Int32, ParameterName = "@discount", Value = discount.ParseToInt(), }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "@price_text", Value = price_text, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "@sku_purchase_price_json", Value = sku_purchase_price_json, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "@notes", Value = notes, }); + + var has = mySql.ExecuteFirst(sqlExist, paramLst.ToArray()); + if (has != "0") + { + mySql.Close(); + return "{\"code\":501,\"msg\":\"货号 " + ext_code + " 价格数据已存在\"}"; + } + + var rst = mySql.ExecuteNonQuery(sql, paramLst.ToArray()); + mySql.Close(); + if (rst) + { + return "{\"code\":200,\"msg\":\"success\"}"; + } + else + { + return "{\"code\":502,\"msg\":\"" + mySql.Message + "\"}"; + } + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + public string MdyPurchasePrice(string inputData, bool isAdmin = false) + { + 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"); + if (string.IsNullOrEmpty(user_name)) + { + return "{\"code\":500,\"msg\":\"没有用户名\"}"; + } + + var db_id = RegexUtils.GetStringQuery(ref inputData, "db_id"); + string shop_id = RegexUtils.GetStringQuery(ref inputData, "shop_id"); + string shop_name = RegexUtils.GetStringQuery(ref inputData, "shop_name"); + string cat_id = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "cat_id")).ParseToString(); + string cat_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "cat_name")).ParseToString(); + string ext_code = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "ext_code")).ParseToString(); + string product_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "product_name")).ParseToString(); + string main_img = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "main_img")).ParseToString(); + string discount = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "discount")).ParseToString(); + string price_text = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "price_text")).ParseToString(); + string sku_purchase_price_json = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "sku_purchase_price_json")).ParseToString(); + string notes = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "notes")).ParseToString(); + + List paramLst = new List(); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "@db_id", Value = db_id, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "@shop_id", Value = shop_id, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "@shop_name", Value = shop_name, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "@cat_id", Value = cat_id, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "@cat_name", Value = cat_name, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "@ext_code", Value = ext_code, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "@product_name", Value = product_name, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "@main_img", Value = main_img, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.Int32, ParameterName = "@discount", Value = discount.ParseToInt(), }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "@price_text", Value = price_text, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "@sku_purchase_price_json", Value = sku_purchase_price_json, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "@notes", Value = notes, }); + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + + string sql = "update kjd.product_purchase_price set"; + if (shop_id != null) + sql += " shop_id=@shop_id,"; + if (shop_name != null) + sql += " shop_name=@shop_name,"; + if (cat_id != null) + sql += " cat_id=@cat_id,"; + if (cat_name != null) + sql += " cat_name=@cat_name,"; + if (ext_code != null) + sql += " ext_code=@ext_code,"; + if (product_name != null) + sql += " product_name=@product_name,"; + if (main_img != null) + sql += " main_img=@main_img,"; + if (discount != null) + sql += " discount=@discount,"; + if (price_text != null) + sql += " price_text=@price_text,"; + if (sku_purchase_price_json != null) + sql += " sku_purchase_price_json=@sku_purchase_price_json,"; + if (notes != null) + sql += " notes=@notes,"; + sql = sql.TrimEnd(','); + sql += " where id=@db_id;"; + + var rst = mySql.ExecuteNonQuery(sql, paramLst.ToArray()); + mySql.Close(); + if (rst) + { + return "{\"code\":200,\"msg\":\"success\"}"; + } + else + { + return "{\"code\":500,\"msg\":\"更新失败:" + mySql.Message + "\"}"; + } + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + public string GetPurchasePriceList(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 search_spu_id = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "search_spu_id")); + var search_skc_id = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "search_skc_id")); + var search_ext_code = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "search_ext_code")); + var search_notes = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "search_notes")); + var in_spu_id = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "in_spu_id")); + int page = RegexUtils.GetStringQuery(ref inputData, "page").ParseToInt(); + int page_size = RegexUtils.GetStringQuery(ref inputData, "page_size").ParseToInt(50); + if (string.IsNullOrEmpty(user_name)) + { + return "{\"code\":500,\"msg\":\"没有用户名\"}"; + } + + + List paramLst = new List(); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "@search_spu_id", Value = "%" + search_spu_id + "%", }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "@search_skc_id", Value = "%" + search_skc_id + "%", }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "@search_ext_code", Value = "%" + search_ext_code + "%", }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "@search_notes", Value = "%" + search_notes + "%", }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "@in_spu_id", Value = in_spu_id.ParseToString() }); + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + + string sql = "select count(id) from kjd.product_purchase_price p where 1=1"; + + string where = ""; + if (!string.IsNullOrWhiteSpace(search_spu_id)) + where += " and p.spu_id like @search_spu_id"; + if (!string.IsNullOrWhiteSpace(search_skc_id)) + where += " and p.skc_id like @search_skc_id"; + if (!string.IsNullOrWhiteSpace(search_ext_code)) + where += " and p.ext_code like @search_ext_code"; + if (!string.IsNullOrWhiteSpace(search_notes)) + where += " and p.notes like @search_notes"; + if (!string.IsNullOrEmpty(in_spu_id)) + where += " and p.spu_id in ('" + in_spu_id?.Replace(",", "','") + "')"; + sql += where; + + var count = mySql.ExecuteRowCount(sql, paramLst.ToArray()); + + DataTable dt; + if (count == 0) + { + dt = new DataTable(); + } + else + { + sql = "select * from kjd.product_purchase_price p where 1=1"; + + //where子句 + sql += where; + + sql += " order by p.id desc"; + sql += " limit " + Math.Max(page - 1, 0) * page_size + "," + page_size; + dt = mySql.ExecuteDataTable(sql, paramLst.ToArray()); + } + + mySql.Close(); + if (dt != null) + { + try + { + List purchasePriceList = new List(); + foreach (DataRow row in dt.Rows) + { + ProductPurchasePriceResultParam price = new ProductPurchasePriceResultParam + { + id = row["id"].ParseToInt(), + shop_id = row["shop_id"].ParseToString(), + shop_name = row["shop_name"].ParseToString(), + cat_id = row["cat_id"].ParseToString(), + cat_name = row["cat_name"].ParseToString(), + main_img = row["main_img"].ParseToString(), + discount = row["discount"].ParseToInt(), + price_text = row["price_text"].ParseToString(), + product_name = row["product_name"].ParseToString(), + skc_id = row["skc_id"].ParseToString(), + sku_purchase_price_json = row["sku_purchase_price_json"].ParseToString(), + spu_id = row["spu_id"].ParseToString(), + notes = row["notes"].ParseToString(), + ext_code = row["ext_code"].ParseToString(), + add_time = Convert.ToDateTime(row["add_time"]), + mdy_time = Convert.ToDateTime(row["mdy_time"]), + }; + purchasePriceList.Add(price); + } + var data = JsonUtils.SerializeObjectToString(purchasePriceList); + return "{\"code\":200,\"msg\":\"success\",\"data\":" + data + ",\"count\":" + count + "}"; + } + 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 DelPurchasePrice(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("'", "\\'"); + var id = RegexUtils.GetStringQuery(ref inputData, "db_id")?.Replace("'", "\\'"); + + if (string.IsNullOrEmpty(user_name)) + { + return "{\"code\":500,\"msg\":\"没有用户名\"}"; + } + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = "delete from kjd.product_purchase_price where id='" + id + "'"; + + var rst = mySql.ExecuteNonQuery(sql); + mySql.Close(); + if (rst) + { + return "{\"code\":200,\"msg\":\"success\"}"; + } + else + return "{\"code\":500,\"msg\":\"删除失败:" + mySql.Message + "\"}"; + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + } +} + + + + diff --git a/StoreHub.KJDWebService/Services/ProductService.cs b/StoreHub.KJDWebService/Services/ProductService.cs new file mode 100644 index 0000000..3cd6ead --- /dev/null +++ b/StoreHub.KJDWebService/Services/ProductService.cs @@ -0,0 +1,1811 @@ +using StoreHub.KJDWebService.Models; +using StoreHub.Framework.Repositorys; +using Microsoft.Extensions.Configuration; +using StoreHub.KJDWebService.Commons; +using MySql.Data.MySqlClient; +using NaiBa.Util.Extension; +using Newtonsoft.Json.Linq; +using System; +using System.Collections.Generic; +using System.Data; +using System.Diagnostics; +using System.Linq; + +namespace StoreHub.KJDWebService.Services +{ + public class ProductService : ServiceBase + { + public ProductService(SqlRepository sqlRepository, IConfiguration configuration) : base(sqlRepository, configuration) + { + } + public string AddProduct(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + var time = 0; + int.TryParse(RegexUtils.GetStringQuery(ref inputData, "time"), out time); + string time1 = RegexUtils.GetStringQuery(ref inputData, "code"); + if (time1 != EncrypUtil.Encryption(time)) + return "{\"code\":50000,\"msg\":\"校验失败\"}"; + + string user_name = RegexUtils.GetStringQuery(ref inputData, "user_name"); + string spu_id = RegexUtils.GetStringQuery(ref inputData, "spu_id"); + string skc_id = RegexUtils.GetStringQuery(ref inputData, "skc_id"); + string cat_id = RegexUtils.GetStringQuery(ref inputData, "cat_id"); + string cat_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "cat_name"))?.Replace("'", "\\'"); + string ext_code = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "ext_code"))?.Replace("'", "\\'"); + string product_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "product_name"))?.Replace("'", "\\'"); + string product_json = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "product_json"))?.Replace("'", "\\'"); + string size_json = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "size_json"))?.Replace("'", "\\'"); + string original_json = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "original_json"))?.Replace("'", "\\'"); + string main_img = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "main_img"))?.Replace("'", "\\'"); + string notes = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "notes"))?.Replace("'", "\\'"); + string product_get_type = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "product_get_type"))?.Replace("'", "\\'"); + if (string.IsNullOrEmpty(product_get_type)) + product_get_type = "0"; + + if (string.IsNullOrEmpty(user_name)) + { + return "{\"code\":500,\"msg\":\"没有用户名\"}"; + } + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = ""; + + sql = "insert into kjd.product (spu_id,skc_id,cat_id,cat_name,product_name,ext_code,main_img,product_json,size_json,original_json,notes,product_get_type,add_time,mdy_time) " + + "values ('" + spu_id + "','" + skc_id + "','" + cat_id + "','" + cat_name + "','" + product_name + "','" + + ext_code + "','" + main_img + "','" + product_json + "','" + size_json + "','" + original_json + "','" + notes + "','" + + product_get_type + "','" + + 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\"}"; + } + else + { + return "{\"code\":500,\"msg\":\"" + mySql.Message + "\"}"; + } + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + public string GetProductGroupList(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("'", "\\'"); + var password = RegexUtils.GetStringQuery(ref inputData, "password")?.Replace("'", "\\'"); + int page = RegexUtils.GetStringQuery(ref inputData, "page").ParseToInt(); + int page_size = RegexUtils.GetStringQuery(ref inputData, "page_size").ParseToInt(100); + if (string.IsNullOrEmpty(user_name)) + { + return "{\"code\":500,\"msg\":\"没有用户名\"}"; + } + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + + string sql = "select count(distinct p.group) from kjd.product p where p.is_del=0"; + + var count = mySql.ExecuteRowCount(sql); + + DataTable dt; + if (count == 0) + { + dt = new DataTable(); + } + else + { + sql = "select distinct p.group from kjd.product p where p.is_del=0"; + sql += " limit " + Math.Max(page - 1, 0) * page_size + "," + page_size; + dt = mySql.ExecuteDataTable(sql); + } + + mySql.Close(); + if (dt != null) + { + try + { + List groupNameLst = new List(); + foreach (DataRow row in dt.Rows) + { + var group = row["group"].ToString(); + groupNameLst.Add(group); + } + var data = JsonUtils.SerializeObjectToString(groupNameLst); + return "{\"code\":200,\"msg\":\"success\",\"data\":" + data + ",\"count\":" + count + "}"; + } + 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 GetProductList(string inputData, bool isDetail = false) + { + DateTime timeCalc = DateTime.Now; + 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("'", "\\'"); + var password = RegexUtils.GetStringQuery(ref inputData, "password")?.Replace("'", "\\'"); + var search_spu = RegexUtils.GetStringQuery(ref inputData, "search_spu")?.Replace("'", "\\'"); + var search_skc = RegexUtils.GetStringQuery(ref inputData, "search_skc")?.Replace("'", "\\'"); + var search_cat = RegexUtils.GetStringQuery(ref inputData, "search_cat")?.Replace("'", "\\'"); + var search_ext_code = RegexUtils.GetStringQuery(ref inputData, "search_ext_code")?.Replace("'", "\\'"); + var search_prod_name = RegexUtils.GetStringQuery(ref inputData, "search_prod_name")?.Replace("'", "\\'"); + var search_notes = RegexUtils.GetStringQuery(ref inputData, "search_notes")?.Replace("'", "\\'"); + var search_group = RegexUtils.GetStringQuery(ref inputData, "search_group")?.Replace("'", "\\'"); + var search_db_ids = RegexUtils.GetStringQuery(ref inputData, "search_db_ids")?.Replace("'", "\\'"); + var get_select_count = RegexUtils.GetStringQuery(ref inputData, "get_select_count")?.Replace("'", "\\'"); + var select_shop_id = RegexUtils.GetStringQuery(ref inputData, "select_shop_id")?.Replace("'", "\\'"); + var sort_field = RegexUtils.GetStringQuery(ref inputData, "sort_field")?.Replace("'", "\\'"); + var product_get_type = RegexUtils.GetStringQuery(ref inputData, "product_get_type")?.Replace("'", "\\'"); + var sa_level = RegexUtils.GetStringQuery(ref inputData, "sa_level").ParseToInt(); + if (string.IsNullOrEmpty(product_get_type)) // 母店采集0或前端直采1 + product_get_type = "0"; + if (sa_level != 1 && product_get_type.ToLower() == "all") + product_get_type = "0,1"; + + int page = RegexUtils.GetStringQuery(ref inputData, "page").ParseToInt(); + int page_size = RegexUtils.GetStringQuery(ref inputData, "page_size").ParseToInt(50); + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + + string sql = "SELECT COUNT(id) FROM kjd.product p WHERE p.is_del=0"; + + string where = ""; + if (!isDetail && product_get_type != "all") // 详情必须从列表页面进入,不用限制 + where += " AND p.product_get_type in (" + product_get_type + ")"; + if (!string.IsNullOrEmpty(search_db_ids)) + where += " AND p.id in (" + search_db_ids + ")"; + if (!string.IsNullOrWhiteSpace(search_group)) + where += " AND p.group = '" + search_group + "'"; + if (!string.IsNullOrWhiteSpace(search_spu)) + where += " AND p.spu_id like '%" + search_spu + "%'"; + if (!string.IsNullOrWhiteSpace(search_skc)) + where += " AND p.skc_id like '%" + search_skc + "%'"; + if (!string.IsNullOrWhiteSpace(search_cat)) + where += " AND p.cat_name like '%" + search_cat + "%'"; + if (!string.IsNullOrWhiteSpace(search_ext_code)) + { + if (search_ext_code.Contains(",")) + where += " AND p.ext_code in ('" + search_ext_code.Replace(",", "','") + "')"; + else + where += " AND p.ext_code like '%" + search_ext_code + "%'"; + } + if (!string.IsNullOrWhiteSpace(search_prod_name)) + where += " AND p.product_name like '%" + search_prod_name + "%'"; + if (!string.IsNullOrWhiteSpace(search_notes)) + where += " AND p.notes like '%" + search_notes + "%'"; + sql += where; + + var count = mySql.ExecuteRowCount(sql); + + DataTable dt; + if (count == 0) + { + dt = new DataTable(); + } + else + { + if (isDetail) + sql = "SELECT * from kjd.product p where p.is_del=0"; + else if (string.IsNullOrEmpty(get_select_count)) + sql = "SELECT p.id,p.spu_id,p.skc_id,p.cat_id,p.cat_name,p.ext_code,p.product_name,p.main_img,p.notes,p.group," + + "p.add_time,p.mdy_time,p.select_total_count,p.fission_words,p.head_words,p.end_words,p.product_get_type," + + "p.cost_price,p.delivery_fee,p.mark_fee" + + " FROM kjd.product p" + + " WHERE p.is_del=0"; + else // 统计单店认领次数 + { + sql = "SELECT p.id,p.spu_id,p.skc_id,p.cat_id,p.cat_name,p.ext_code,p.product_name,p.main_img,p.notes,p.group," + + "p.add_time,p.mdy_time,p.select_total_count,p.fission_words,p.head_words,p.end_words,p.product_get_type," + + "p.cost_price,delivery_fee,p.mark_fee" + + ",COUNT(s.id) AS select_count" + + " FROM kjd.product p" + + " LEFT JOIN (" + + " SELECT id,out_product_id,shop_id FROM kjd.product_select WHERE shop_id='" + select_shop_id + "'"; + for (int year = Math.Max(2026, DateTime.Now.AddYears(-3).Year); year <= DateTime.Now.Year; year++) + { + sql += "UNION ALL SELECT id,out_product_id,shop_id FROM kjd_yearly.product_select_" + year + " WHERE shop_id='" + select_shop_id + "'"; + } + sql += ") s" + + " ON s.out_product_id=p.id AND s.shop_id='" + select_shop_id + "'" + + " WHERE p.is_del=0"; + } + + //sql += "SELECT * FROM " + tableName + l_spu_map_table_id + " where draft_id=" + in_draft_id_list[i]; + + //where子句 + sql += where; + + if (!isDetail && !string.IsNullOrEmpty(get_select_count)) + sql += " GROUP BY p.id"; + if (sort_field == "select_total_count") + sql += " ORDER BY p.select_total_count desc, p.id desc"; + else + sql += " ORDER BY p.add_time desc"; + sql += " LIMIT " + Math.Max(page - 1, 0) * page_size + "," + page_size; + dt = mySql.ExecuteDataTable(sql); + } + + mySql.Close(); + if (dt != null) + { + try + { + List productLst = new List(); + foreach (DataRow row in dt.Rows) + { + DBProductResultParam prod = new DBProductResultParam + { + id = Convert.ToInt32(row["id"]), + skc_id = row["skc_id"].ToString(), + spu_id = row["spu_id"].ToString(), + cat_id = row["cat_id"].ToString(), + cat_name = row["cat_name"].ToString(), + product_name = row["product_name"].ToString(), + main_img = row["main_img"].ToString(), + ext_code = row["ext_code"].ToString(), + //product_json = row["product_json"].ToString(), + //size_json = row["size_json"].ToString(), + add_time = Convert.ToDateTime(row["add_time"]), + mdy_time = Convert.ToDateTime(row["mdy_time"]), + notes = row["notes"].ToString(), + group = row["group"].ToString(), + select_total_count = row["select_total_count"].ParseToInt(), + fission_words = row["fission_words"].ParseToString(), + head_words = row["head_words"].ParseToString(), + end_words = row["end_words"].ParseToString(), + cost_price = row["cost_price"].ParseToString(), + delivery_fee = row["delivery_fee"].ParseToString(), + mark_fee = row["mark_fee"].ParseToString(), + product_get_type = row["product_get_type"].ParseToInt(), //0母店采集 1前端直采 + }; + if (isDetail) + { + prod.product_json = row["product_json"].ToString(); + prod.size_json = row["size_json"].ToString(); + } + if (!string.IsNullOrEmpty(get_select_count)) + { + prod.select_count = row["select_count"].ParseToInt(); + } + productLst.Add(prod); + } + var data = JsonUtils.SerializeObjectToString(productLst); + 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 DelDbProd(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("'", "\\'"); + var id = RegexUtils.GetStringQuery(ref inputData, "db_id")?.Replace("'", "\\'"); + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + //string sql = "delete from kjd.product where id='" + id + "'"; + string sql = "update kjd.product set is_del=1 where id='" + id + "'"; + + var rst = mySql.ExecuteNonQuery(sql); + mySql.Close(); + if (rst) + { + return "{\"code\":200,\"msg\":\"success\"}"; + } + else + return "{\"code\":500,\"msg\":\"删除失败:" + mySql.Message + "\"}"; + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + public string MdyProductNotes(string inputData, bool isAdmin = false) + { + 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("'", "\\'"); + var id = RegexUtils.GetStringQuery(ref inputData, "db_id")?.Replace("'", "\\'"); + string notes = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "notes"))?.Replace("'", "\\'"); + + if (string.IsNullOrEmpty(user_name)) + { + return "{\"code\":500,\"msg\":\"没有用户名\"}"; + } + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = "update kjd.product set"; + if (notes != null) + sql += " notes='" + notes + "',"; + sql = sql.TrimEnd(','); + sql += " where id=" + id + ";"; + + var rst = mySql.ExecuteNonQuery(sql); + mySql.Close(); + if (rst) + { + return "{\"code\":200,\"msg\":\"success\"}"; + } + else + { + return "{\"code\":500,\"msg\":\"更新失败:" + mySql.Message + "\"}"; + } + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + public string MdyDBProduct(string inputData, bool isAdmin = false) + { + 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("'", "\\'"); + var id = RegexUtils.GetStringQuery(ref inputData, "db_id")?.Replace("'", "\\'"); + var product_name = RegexUtils.GetStringQuery(ref inputData, "product_name")?.Replace("'", "\\'"); + string notes = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "notes"))?.Replace("'", "\\'"); + string ext_code = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "ext_code"))?.Replace("'", "\\'"); + + string group = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "group"))?.Replace("'", "\\'"); + string fission_words = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "fission_words"))?.Replace("'", "\\'"); + string head_words = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "head_words"))?.Replace("'", "\\'"); + string end_words = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "end_words"))?.Replace("'", "\\'"); + string cost_price = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "cost_price"))?.Replace("'", "\\'"); + string delivery_fee = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "delivery_fee"))?.Replace("'", "\\'"); + string mark_fee = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "mark_fee"))?.Replace("'", "\\'"); + + string product_json = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "product_json"))?.Replace("'", "\\'"); + string size_json = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "size_json"))?.Replace("'", "\\'"); + + string original_json = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "original_json"))?.Replace("'", "\\'"); + + if (string.IsNullOrEmpty(id)) + { + return "{\"code\":500,\"msg\":\"没有指定商品\"}"; + } + if (string.IsNullOrEmpty(user_name)) + { + return "{\"code\":500,\"msg\":\"没有用户名\"}"; + } + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = "update kjd.product set"; + if (product_name != null) + sql += " product_name='" + product_name + "',"; + if (notes != null) + sql += " notes='" + notes + "',"; + if (group != null) + sql += " kjd.product.group='" + group + "',"; + if (ext_code != null) + sql += " ext_code='" + ext_code + "',"; + if (fission_words != null) + sql += " fission_words='" + fission_words + "',"; + if (head_words != null) + sql += " head_words='" + head_words + "',"; + if (end_words != null) + sql += " end_words='" + end_words + "',"; + if (cost_price != null) + sql += " cost_price='" + cost_price + "',"; + if (delivery_fee != null) + sql += " delivery_fee='" + delivery_fee + "',"; + if (mark_fee != null) + sql += " mark_fee='" + mark_fee + "',"; + if (product_json != null) + sql += " product_json='" + product_json + "',"; + if (size_json != null) + sql += " size_json='" + size_json + "',"; + if (original_json != null) + sql += " original_json='" + original_json + "',"; + sql = sql.TrimEnd(','); + sql += " where id=" + id + ";"; + + var rst = mySql.ExecuteNonQuery(sql); + mySql.Close(); + if (rst) + { + return "{\"code\":200,\"msg\":\"success\"}"; + } + else + { + return "{\"code\":500,\"msg\":\"更新失败:" + mySql.Message + "\"}"; + } + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + + public string AddUserSelectProduct(string inputData, bool isAdmin = false) + { + 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 out_product_Id = RegexUtils.GetStringQuery(ref inputData, "out_product_id")?.Replace("'", "\\'"); + var shop_id = RegexUtils.GetStringQuery(ref inputData, "shop_id")?.Replace("'", "\\'"); + var shop_account = RegexUtils.GetStringQuery(ref inputData, "shop_account")?.Replace("'", "\\'"); + var user_name = RegexUtils.GetStringQuery(ref inputData, "main_user_name")?.Replace("'", "\\'"); + var sub_user_name = RegexUtils.GetStringQuery(ref inputData, "sub_user_name")?.Replace("'", "\\'"); + var notes = RegexUtils.GetStringQuery(ref inputData, "notes")?.Replace("'", "\\'"); + var status = RegexUtils.GetStringQuery(ref inputData, "status")?.Replace("'", "\\'"); + var add_product_remaining = RegexUtils.GetStringQuery(ref inputData, "add_product_remaining").ParseToInt(); + var add_fission_product_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "add_fission_product_name").ParseToString())?.Replace("'", "\\'"); + + if (string.IsNullOrEmpty(user_name)) + { + return "{\"code\":500,\"msg\":\"没有用户名\"}"; + } + if (string.IsNullOrEmpty(shop_id)) + { + return "{\"code\":500,\"msg\":\"没有店铺信息\"}"; + } + + DateTime addTime = DateTime.Now; + string addTimeStr = addTime.ToString("yyyy-MM-dd HH:mm:ss"); + string dbName = "kjd"; + if (addTime.Year >= 2026) + dbName = "kjd_yearly"; + + bool is_client_jit = RegexUtils.GetStringQuery(ref inputData, "is_client_jit")?.ParseToBool() == true; + string tableName; + if (!is_client_jit) + tableName = dbName + ".product_select"; + else + tableName = dbName + ".jit_product_select"; + + if (addTime.Year >= 2026) + tableName += "_" + addTime.Year; + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + + string sql = ""; + if (add_product_remaining > 0) // add_product_remaining 为空或为0表示商品直传,不消耗次数 + { + sql = "select * from kjd.shop_add_prod_count where shop_id='" + shop_id + "';"; + var dt = mySql.ExecuteDataTable(sql); + if (!string.IsNullOrEmpty(mySql.Message)) + { + mySql.Close(); + return "{\"code\":500,\"msg\":\"" + mySql.Message + "\"}"; + } + if (dt != null && dt.Rows.Count > 0) + { + add_product_remaining = dt.Rows[0]["add_product_remaining"].ParseToInt(); + if (add_product_remaining <= 0) + { + mySql.Close(); + return "{\"code\":501,\"msg\":\"本月商品认领限额已用完,请下个月再操作!\"}"; + } + } + } + + sql = "INSERT INTO " + tableName + + " (out_product_Id,shop_id,shop_account,user_name,sub_user_name,notes,status,fission_product_name,add_time,mdy_time) VALUES" + + " ('" + out_product_Id + "','" + shop_id + "','" + shop_account + "','" + user_name + "','" + sub_user_name + "','" + + notes + "','" + status + "','" + add_fission_product_name + "','" + + addTimeStr + "','" + + addTimeStr + "');"; + if (add_product_remaining > 0) // add_product_remaining 为空或为0表示商品直传,不消耗次数 + { + add_product_remaining = add_product_remaining - 1; + sql += "\r\n"; + //sql += "UPDATE kjd.shop SET add_product_remaining=" + add_product_remaining + " WHERE shop_id='" + shop_id + "';"; + sql += "UPDATE kjd.product SET select_total_count=select_total_count+1 WHERE id=" + out_product_Id + ";"; + sql += "INSERT INTO kjd.shop_add_prod_count(shop_id, add_product_remaining) VALUES('" + shop_id + "'," + add_product_remaining + ")" + + "ON DUPLICATE KEY UPDATE add_product_remaining=add_product_remaining-1"; + } + 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 MdyUserSelectProductStatus(string inputData, bool isAdmin = false) + { + 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 select_db_id = RegexUtils.GetStringQuery(ref inputData, "db_id")?.Replace("'", "\\'"); + var draft_id = RegexUtils.GetStringQuery(ref inputData, "draft_id")?.Replace("'", "\\'"); + var up_spu_id = RegexUtils.GetStringQuery(ref inputData, "up_spu_id")?.Replace("'", "\\'"); + var shop_id = RegexUtils.GetStringQuery(ref inputData, "shop_id")?.Replace("'", "\\'"); + var status = RegexUtils.GetStringQuery(ref inputData, "status")?.Replace("'", "\\'"); + var add_times = RegexUtils.GetStringQuery(ref inputData, "add_times")?.Replace("'", "\\'"); + var is_client_jit = RegexUtils.GetStringQuery(ref inputData, "is_client_jit")?.ParseToBool() == true; + var select_add_time = RegexUtils.GetStringQuery(ref inputData, "select_add_time")?.Replace("'", "\\'").ParseToDateTimeNullable(); + if (select_add_time == null) + { + return "{\"code\":500,\"msg\":\"当前软件版本不支持该操作,请升级软件。\"}"; + } + + long l_draft_id = draft_id.ParseToLong(); + long l_spu_map_table_id = l_draft_id % 128; + long l_select_map_table_id = select_db_id.ParseToLong() % 64; + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = ""; + + // 使用事务一次提交多个sql操作 + //sql += "set @@autocommit=0;\r\n"; + sql += "START TRANSACTION;\r\n"; + if (!string.IsNullOrEmpty(up_spu_id) && !string.IsNullOrEmpty(draft_id)) + { + sql += "INSERT INTO kjd_map.spu_map_" + l_spu_map_table_id + + " (draft_id,from_spu_id,shop_id) VALUES(" + draft_id + "," + up_spu_id + ",'" + shop_id + "');\r\n"; + + if (!select_add_time.HasValue || select_add_time.Value.Year < 2026) + { + if (!is_client_jit) + { + sql += "INSERT INTO kjd_map.product_select_map_" + l_select_map_table_id + + " (product_id,product_select_db_id,shop_id) VALUES(" + draft_id + "," + select_db_id + ",'" + shop_id + "');\r\n"; + } + else + { + sql += "INSERT INTO kjd_map.jit_product_select_map_" + l_select_map_table_id + + " (product_id,product_select_db_id,shop_id) VALUES(" + draft_id + "," + select_db_id + ",'" + shop_id + "');\r\n"; + } + } + else //(select_add_time.HasValue && select_add_time.Value.Year >= 2026) + { + string select_type; + if (!is_client_jit) + select_type = "normal"; + else + select_type = "jit"; + sql += "INSERT INTO kjd_map_yearly.product_select_map_" + select_add_time.Value.Year + + "(product_select_db_id,product_id,shop_id,select_type) VALUES" + + "(" + select_db_id + ",'" + draft_id + "','" + shop_id + "','" + select_type + "');\r\n"; + } + } + + string dbName = "kjd"; + if (select_add_time.HasValue && select_add_time.Value.Year >= 2026) + dbName = "kjd_yearly"; + string tableName; + if (!is_client_jit) + tableName = dbName + ".product_select"; + else + tableName = dbName + ".jit_product_select"; + if (select_add_time.HasValue && select_add_time.Value.Year >= 2026) + tableName += "_" + select_add_time.Value.Year; + + sql += "update " + tableName + " set"; + if (draft_id != null) + sql += " draft_id='" + draft_id + "',"; + if (status != null) + sql += " status='" + status + "',"; + if (status == "已上传") + sql += " add_times=add_times+1,"; + sql += " mdy_time='" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "',"; + sql = sql.TrimEnd(','); + sql += " WHERE id=" + select_db_id + ";\r\n"; + var rst = mySql.ExecuteNonQuery(sql); + string errMsg = mySql.Message; + if (string.IsNullOrEmpty(errMsg)) + sql = "COMMIT;"; + else + sql = "ROLLBACK;"; + mySql.ExecuteNonQuery(sql); + mySql.Close(); + if (rst) + { + return "{\"code\":200,\"msg\":\"success\"}"; + } + else + { + return "{\"code\":500,\"msg\":\"" + errMsg + "\"}"; + } + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + public string GetUserSelectProductList(string inputData, bool isAdmin = false) + { + DateTime timeCalc = DateTime.Now; + 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\":500,\"msg\":\"没有用户名\"}"; + } + + var shop_ids = RegexUtils.GetStringQuery(ref inputData, "shop_ids")?.Replace("'", "\\'"); + var search_shop_id = RegexUtils.GetStringQuery(ref inputData, "search_shop_id")?.Replace("'", "\\'"); + var search_shop_account = RegexUtils.GetStringQuery(ref inputData, "search_shop_account")?.Replace("'", "\\'"); + var search_spu = RegexUtils.GetStringQuery(ref inputData, "search_spu")?.Replace("'", "\\'"); + var search_skc = RegexUtils.GetStringQuery(ref inputData, "search_skc")?.Replace("'", "\\'"); + var search_cat = RegexUtils.GetStringQuery(ref inputData, "search_cat")?.Replace("'", "\\'"); + var search_ext_code = RegexUtils.GetStringQuery(ref inputData, "search_ext_code")?.Replace("'", "\\'"); + var search_prod_name = RegexUtils.GetStringQuery(ref inputData, "search_prod_name")?.Replace("'", "\\'"); + var search_notes = RegexUtils.GetStringQuery(ref inputData, "search_notes")?.Replace("'", "\\'"); + var search_user_notes = RegexUtils.GetStringQuery(ref inputData, "search_user_notes")?.Replace("'", "\\'"); + var search_db_ids = RegexUtils.GetStringQuery(ref inputData, "search_db_ids")?.Replace("'", "\\'"); + var search_sub_sa_name = RegexUtils.GetStringQuery(ref inputData, "search_sub_sa_name")?.Replace("'", "\\'"); + var status = RegexUtils.GetStringQuery(ref inputData, "status")?.Replace("'", "\\'"); + var operate_sub_sa_name = RegexUtils.GetStringQuery(ref inputData, "operate_sub_sa_name")?.Replace("'", "\\'"); + + var search_end_time = RegexUtils.GetStringJson(ref inputData, "search_end_time")?.ParseToDateTimeNullable(); + if (search_end_time == null || search_end_time.Value > DateTime.Now.Date.AddDays(1)) search_end_time = DateTime.Now.Date.AddDays(1); + var search_start_time = RegexUtils.GetStringJson(ref inputData, "search_start_time")?.ParseToDateTimeNullable(); + if (search_start_time == null || search_start_time.Value >= search_end_time.Value) search_start_time = search_end_time.Value.AddMonths(-6); + int startTableId = Math.Max(2025, search_start_time.Value.Year); + int endTableId = Math.Max(2025, search_end_time.Value.Year); + + var no_sub_sa = RegexUtils.GetStringQuery(ref inputData, "no_sub_sa")?.Replace("'", "\\'"); + + int page = RegexUtils.GetStringQuery(ref inputData, "page").ParseToInt(); + int page_size = RegexUtils.GetStringQuery(ref inputData, "page_size").ParseToInt(50); + + var is_client_jit = RegexUtils.GetStringQuery(ref inputData, "is_client_jit")?.ParseToBool() == true; + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + + string sql = "SELECT count(s.id) from ("; + for (int year = search_start_time.Value.Year; year <= search_end_time.Value.Year; year++) + { + string dbName = "kjd"; + if (year >= 2026) + dbName = "kjd_yearly"; + string tableName; + if (!is_client_jit) + tableName = dbName + ".product_select"; + else + tableName = dbName + ".jit_product_select"; + + if (year >= 2026) + tableName += "_" + year; + if (year > search_start_time.Value.Year) + sql += " UNION ALL"; + sql += " SELECT * FROM " + tableName; + } + sql += ") s " + + "LEFT JOIN kjd.product p ON s.out_product_id=p.id " + + "LEFT JOIN kjd.user u ON s.operate_sub_sa_name=u.user_name " + + "WHERE s.add_time BETWEEN '" + search_start_time.Value.ToString("yyyy-MM-dd") + "' AND '" + search_end_time.Value.ToString("yyyy-MM-dd") + "' "; + + string where = ""; + if (!isAdmin || is_client_jit) + where += " AND (s.user_name='" + user_name + "' or s.sub_user_name like '%" + user_name + "%')"; + if (!string.IsNullOrEmpty(operate_sub_sa_name)) + { + where += " AND s.operate_sub_sa_name = '" + operate_sub_sa_name + "'"; + } + if (no_sub_sa == "true") + where += " AND s.operate_sub_sa_name IS null"; + if (!string.IsNullOrEmpty(search_db_ids)) + where += " AND s.id IN (" + search_db_ids + ")"; + if (!string.IsNullOrEmpty(shop_ids)) + where += " AND s.shop_id IN ('" + string.Join("','", shop_ids.Split(new char[] { '\"', '\'', ' ', ',' }, StringSplitOptions.RemoveEmptyEntries)) + "')"; + if (!string.IsNullOrWhiteSpace(status)) + where += " AND s.status = '" + status + "'"; + if (!string.IsNullOrWhiteSpace(search_shop_id)) + where += " AND s.shop_id LIKE '%" + search_shop_id + "%'"; + if (!string.IsNullOrWhiteSpace(search_shop_account)) + where += " AND s.shop_account LIKE '%" + search_shop_account + "%'"; + if (!string.IsNullOrWhiteSpace(search_notes)) + { + //核价成功 重复 核价成功(重复) + if (search_notes == "无备注") + where += " AND s.notes = ''"; + else if (search_notes == "重复") + where += " AND s.notes LIKE '重复%' AND s.notes NOT LIKE '核价成功%' AND s.notes not LIKE '核价通过%'"; + else if (search_notes == "核价成功") + where += " AND (s.notes LIKE '核价成功%' OR s.notes LIKE '核价通过%') AND s.notes not LIKE '重复%'"; + else if (search_notes == "核价成功(重复)") + where += " AND (s.notes LIKE '核价成功%' OR s.notes LIKE '核价通过%') AND s.notes LIKE '重复%'"; + else + where += " AND s.notes LIKE '%" + search_notes + "%'"; + } + if (!string.IsNullOrWhiteSpace(search_user_notes)) + where += " AND s.user_notes LIKE '%" + search_user_notes + "%'"; + + where += " AND p.is_del=0"; + if (!string.IsNullOrWhiteSpace(search_spu)) + where += " AND p.spu_id LIKE '%" + search_spu + "%'"; + if (!string.IsNullOrWhiteSpace(search_skc)) + where += " AND p.skc_id LIKE '%" + search_skc + "%'"; + if (!string.IsNullOrWhiteSpace(search_cat)) + where += " AND p.cat_name LIKE '%" + search_cat + "%'"; + if (!string.IsNullOrWhiteSpace(search_ext_code)) + where += " AND p.ext_code LIKE '%" + search_ext_code + "%'"; + if (!string.IsNullOrWhiteSpace(search_prod_name)) + where += " AND p.product_name LIKE '%" + search_prod_name + "%'"; + if (!string.IsNullOrEmpty(search_sub_sa_name)) + { + where += " AND (s.operate_sub_sa_name LIKE '%" + search_sub_sa_name + "%'"; + where += " OR u.nick_name LIKE '%" + operate_sub_sa_name + "%')"; + } + + sql += where; + + var count = mySql.ExecuteRowCount(sql); + + DataTable dt; + if (count == 0) + { + dt = new DataTable(); + } + else + { + //if (isDetail) + //sql = "SELECT * FROM " + tableName + " where 1=1"; + //else + sql = "SELECT s.id,s.out_product_id,s.shop_id,s.shop_account,s.user_name," + + "s.sub_user_name,s.notes,s.user_notes,s.status,s.draft_id,s.add_times,s.add_time,s.mdy_time," + + "s.fission_product_name,s.operate_sub_sa_name,s.add_sub_sa_time," + + "p.spu_id,p.skc_id,p.cat_id,p.cat_name,p.ext_code,p.product_name,p.main_img," + + "p.product_get_type,u.nick_name as operate_sub_sa_nick " + + " FROM ("; + for (int year = search_start_time.Value.Year; year <= search_end_time.Value.Year; year++) + { + string dbName = "kjd"; + if (year >= 2026) + dbName = "kjd_yearly"; + string tableName; + if (!is_client_jit) + tableName = dbName + ".product_select"; + else + tableName = dbName + ".jit_product_select"; + + if (year >= 2026) + tableName += "_" + year; + if (year > search_start_time.Value.Year) + sql += " UNION ALL"; + sql += " SELECT * FROM " + tableName; + } + sql += ") s" + + " LEFT JOIN kjd.product p ON s.out_product_id=p.id" + + " LEFT join kjd.user u ON u.user_name=s.operate_sub_sa_name" + + " WHERE 1=1"; + + sql += where; // where子句 + + sql += " ORDER BY add_time desc"; + sql += " LIMIT " + Math.Max(page - 1, 0) * page_size + "," + page_size; + dt = mySql.ExecuteDataTable(sql); + } + + mySql.Close(); + if (dt != null) + { + try + { + List productLst = new List(); + foreach (DataRow row in dt.Rows) + { + ProductSelectResultParam prodSelect = new ProductSelectResultParam() + { + id = row["id"].ParseToLong(), + out_product_Id = row["out_product_Id"].ParseToString(), + shop_account = row["shop_account"].ParseToString(), + shop_id = row["shop_id"].ParseToString(), + status = row["status"].ParseToString(), + sub_user_name = row["sub_user_name"].ParseToString(), + user_name = row["user_name"].ParseToString(), + cat_id = row["cat_id"].ParseToString(), + cat_name = row["cat_name"].ParseToString(), + product_name = row["product_name"].ParseToString(), + main_img = row["main_img"].ParseToString(), + ext_code = row["ext_code"].ParseToString(), + add_time = Convert.ToDateTime(row["add_time"]), + mdy_time = Convert.ToDateTime(row["mdy_time"]), + notes = row["notes"].ParseToString(), + draft_id = row["draft_id"].ParseToString(), + add_times = row["add_times"].ParseToInt(), + skc_id = row["skc_id"].ToString(), + spu_id = row["spu_id"].ToString(), + operate_sub_sa_name = row["operate_sub_sa_name"].ToString(), + operate_sub_sa_nick = row["operate_sub_sa_nick"].ToString(), + fission_product_name = row["fission_product_name"].ToString(), + user_notes = row["user_notes"].ToString(), + product_get_type = row["product_get_type"].ParseToInt(), + //product_json = row["product_json"].ToString(), + //size_json = row["size_json"].ToString(), + }; + prodSelect.add_sub_sa_time = row["add_sub_sa_time"] as DateTime?; + productLst.Add(prodSelect); + } + var data = JsonUtils.SerializeObjectToString(productLst); + 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 DelSelectProd(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("'", "\\'"); + var id = RegexUtils.GetStringQuery(ref inputData, "db_id")?.Replace("'", "\\'"); + + if (string.IsNullOrEmpty(user_name)) + { + return "{\"code\":500,\"msg\":\"没有用户名\"}"; + } + + var select_add_time = RegexUtils.GetStringQuery(ref inputData, "select_add_time")?.Replace("'", "\\'").ParseToDateTimeNullable(); + if (select_add_time == null) + { + return "{\"code\":500,\"msg\":\"当前软件版本不支持该操作,请升级软件。\"}"; + } + + var is_client_jit = RegexUtils.GetStringQuery(ref inputData, "is_client_jit")?.ParseToBool() == true; + string dbName = "kjd"; + if (select_add_time != null && select_add_time.Value.Year >= 2026) + dbName = "kjd_yearly"; + string tableName; + if (!is_client_jit) + tableName = dbName + ".product_select"; + else + tableName = dbName + ".jit_product_select"; + if (select_add_time != null && select_add_time.Value.Year >= 2026) + tableName += "_" + select_add_time.Value.Year; + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = "delete from " + tableName + " where id='" + + id + "'"; + + var rst = mySql.ExecuteNonQuery(sql); + mySql.Close(); + if (rst) + { + return "{\"code\":200,\"msg\":\"success\"}"; + } + else + return "{\"code\":500,\"msg\":\"删除失败:" + mySql.Message + "\"}"; + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + /// + /// 设置上传商品的二级超管 + /// + /// + public string SetSelectProductSubSa(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 db_ids = RegexUtils.GetStringQuery(ref inputData, "db_id")?.Replace("'", "\\'"); + var shop_ids = RegexUtils.GetStringQuery(ref inputData, "shop_id")?.Replace("'", "\\'"); + var operate_sub_sa_name = RegexUtils.GetStringQuery(ref inputData, "operate_sub_sa_name")?.Replace("'", "\\'"); + var status = RegexUtils.GetStringQuery(ref inputData, "status")?.Replace("'", "\\'"); + var db_id_infos = RegexUtils.GetStringQuery(ref inputData, "db_id_infos")?.Replace("'", "\\'"); + + if (operate_sub_sa_name == null) + { + return "{\"code\":50002,\"msg\":\"未选择任何二级超管\"}"; + } + if (string.IsNullOrEmpty(db_ids) && string.IsNullOrEmpty(shop_ids)) + { + return "{\"code\":50002,\"msg\":\"未选择任何待设置对象\"}"; + } + + var select_add_time = RegexUtils.GetStringQuery(ref inputData, "select_add_time")?.Replace("'", "\\'").ParseToDateTimeNullable(); + if (select_add_time == null && db_id_infos == null && db_ids == null) + { + return "{\"code\":500,\"msg\":\"当前软件版本不支持该操作,请升级软件。\"}"; + } + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = ""; + bool rst = false; + + if (!string.IsNullOrEmpty(db_ids)) + { + sql = "UPDATE kjd.product_select SET"; + sql += " operate_sub_sa_name='" + operate_sub_sa_name + "',"; + sql += " add_sub_sa_time='" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "'"; + sql += " WHERE id IN (" + db_ids + ")"; + if (!string.IsNullOrEmpty(status)) + sql += " AND status='" + status + "';"; + + rst = mySql.ExecuteNonQuery(sql); + if (!string.IsNullOrEmpty(mySql.Message)) + { + mySql.Close(); + return "{\"code\":500,\"msg\":\"" + mySql.Message + "\"}"; + } + } + else if (!string.IsNullOrEmpty(shop_ids)) + { + List yearLst = new List() { 2025 }; + if (select_add_time != null) + { + yearLst.Clear(); + yearLst.Add(select_add_time.Value.Year); + yearLst.Add(select_add_time.Value.AddMonths(-6).Year); + yearLst = yearLst.Distinct().ToList(); + } + foreach (int year in yearLst) + { + string dbName = "kjd"; + if (year >= 2026) + dbName = "kjd_yearly"; + string tableName = dbName + ".product_select"; + if (year >= 2026) + tableName += "_" + year; + + sql = "UPDATE " + tableName + " SET"; + sql += " operate_sub_sa_name='" + operate_sub_sa_name + "',"; + sql += " add_sub_sa_time='" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "'"; + sql += " WHERE shop_id in ('" + shop_ids.Replace(",", "','") + "')"; + if (!string.IsNullOrEmpty(status)) + sql += " AND status='" + status + "';"; + + rst = mySql.ExecuteNonQuery(sql); + if (!string.IsNullOrEmpty(mySql.Message)) + { + mySql.Close(); + return "{\"code\":500,\"msg\":\"" + mySql.Message + "\"}"; + } + } + } + else if (!string.IsNullOrEmpty(db_id_infos)) + { + try + { + JArray jArr = JArray.Parse(db_id_infos); + foreach (JObject jObj in jArr) + { + var year = jObj["year"].ParseToInt(); + var dbIds = jObj["db_ids"].ParseToString(); + + string dbName = "kjd"; + if (year >= 2026) + dbName = "kjd_yearly"; + string tableName = dbName + ".product_select"; + if (year >= 2026) + tableName += "_" + year; + + sql = "UPDATE " + tableName + " SET"; + sql += " operate_sub_sa_name='" + operate_sub_sa_name + "',"; + sql += " add_sub_sa_time='" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "'"; + sql += " WHERE id IN (" + dbIds + ")"; + if (!string.IsNullOrEmpty(status)) + sql += " AND status='" + status + "';"; + + rst = mySql.ExecuteNonQuery(sql); + if (!string.IsNullOrEmpty(mySql.Message)) + { + mySql.Close(); + return "{\"code\":500,\"msg\":\"" + mySql.Message + "\"}"; + } + } + } + catch (Exception ex) + { + mySql.Close(); + return "{\"code\":50004,\"msg\":\"" + ex.Message + "\"}"; + } + } + mySql.Close(); + return "{\"code\":200,\"msg\":\"success\"}"; + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + public string MdyProductSelectNotes(string inputData, bool isAdmin = false) + { + 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 db_id = RegexUtils.GetStringQuery(ref inputData, "db_id"); + string notes = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "notes")); + string user_notes = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "user_notes")); + string fission_product_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "fission_product_name")); + + if (string.IsNullOrEmpty(user_name)) + { + return "{\"code\":500,\"msg\":\"没有用户名\"}"; + } + + var select_add_time = RegexUtils.GetStringQuery(ref inputData, "select_add_time")?.Replace("'", "\\'").ParseToDateTimeNullable(); + if (select_add_time == null) + { + return "{\"code\":500,\"msg\":\"当前软件版本不支持该操作,请升级软件。\"}"; + } + + var is_client_jit = RegexUtils.GetStringQuery(ref inputData, "is_client_jit")?.ParseToBool() == true; + string dbName = "kjd"; + if (select_add_time != null && select_add_time.Value.Year >= 2026) + dbName = "kjd_yearly"; + string tableName; + if (!is_client_jit) + tableName = dbName + ".product_select"; + else + tableName = dbName + ".jit_product_select"; + if (select_add_time != null && select_add_time.Value.Year >= 2026) + tableName += "_" + select_add_time.Value.Year; + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = "update " + tableName + " set"; + if (notes != null) + sql += " notes=@notes,"; + if (user_notes != null) + sql += " user_notes=@user_notes,"; + if (fission_product_name != null) + sql += " fission_product_name=@fission_product_name,"; + sql = sql.TrimEnd(','); + sql += " where id=@db_id;"; + + List paramLst = new List(); + paramLst.Add(new MySqlParameter() { DbType = DbType.Int64, ParameterName = "@db_id", Value = db_id, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "@fission_product_name", Value = fission_product_name, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "@user_notes", Value = user_notes, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "@notes", Value = notes, }); + + var rst = mySql.ExecuteNonQuery(sql, paramLst.ToArray()); + mySql.Close(); + if (rst) + { + return "{\"code\":200,\"msg\":\"success\"}"; + } + else + { + return "{\"code\":500,\"msg\":\"更新失败:" + mySql.Message + "\"}"; + } + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + public string GetSelectProdDbIdMapDraftIdList(string inputData, bool isDetail = false) + { + DateTime timeCalc = DateTime.Now; + 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("'", "\\'"); + var password = RegexUtils.GetStringQuery(ref inputData, "password")?.Replace("'", "\\'"); + if (string.IsNullOrEmpty(user_name)) + { + return "{\"code\":50001,\"msg\":\"用户为空\"}"; + } + + var select_db_id = RegexUtils.GetStringQuery(ref inputData, "select_db_id")?.Replace("'", "\\'"); + if (string.IsNullOrEmpty(select_db_id)) + { + return "{\"code\":50002,\"msg\":\"未选择选品数据\"}"; + } + + var select_add_time = RegexUtils.GetStringQuery(ref inputData, "select_add_time")?.Replace("'", "\\'").ParseToDateTimeNullable(); + if (select_add_time == null) + { + return "{\"code\":500,\"msg\":\"当前软件版本不支持该操作,请升级软件。\"}"; + } + + var is_client_jit = RegexUtils.GetStringQuery(ref inputData, "is_client_jit")?.ParseToBool() == true; + string dbName = "kjd_map"; + if (select_add_time != null && select_add_time.Value.Year >= 2026) + dbName = "kjd_map_yearly"; + string tableName; + if (!is_client_jit || (select_add_time != null && select_add_time.Value.Year >= 2026)) // 2026年以后的数据在新表,不带jit + tableName = dbName + ".product_select_map_"; + else + tableName = dbName + ".jit_product_select_map_"; + + if (select_add_time != null && select_add_time.Value.Year >= 2026) + tableName += select_add_time.Value.Year; + else + { + long l_select_map_table_id = select_db_id.ParseToLong() % 64; + tableName += +l_select_map_table_id; + } + + int page = RegexUtils.GetStringQuery(ref inputData, "page").ParseToInt(); + int page_size = RegexUtils.GetStringQuery(ref inputData, "page_size").ParseToInt(50); + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + + string sql = "SELECT COUNT(id) FROM " + tableName + " where 1=1"; + + string where = " and product_select_db_id=" + select_db_id; + if (select_add_time != null && select_add_time.Value.Year >= 2026) // 2026年以后的数据在新表 + where += " AND select_type='" + (!is_client_jit ? "normal" : "jit") + "'"; + + sql += where; + + var count = mySql.ExecuteRowCount(sql); + + DataTable dt; + if (count == 0) + { + dt = new DataTable(); + } + else + { + sql = "SELECT * FROM " + tableName + " where 1=1"; + //where子句 + sql += where; + sql += " ORDER BY add_time 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\":500,\"msg\":\"" + mySql.Message + "\",\"data\":[],\"count\":" + 0 + "}"; + } + if (dt != null) + { + try + { + List dbIdMapProductIdLst = new List(); + foreach (DataRow row in dt.Rows) + { + DBProdDbIdMapProductIdResultParam dbIdMapProductId = new DBProdDbIdMapProductIdResultParam + { + id = row["id"].ParseToLong(), + product_select_db_id = row["product_select_db_id"].ParseToLong(), + product_id = row["product_id"].ParseToLong(), + shop_id = row["shop_id"].ParseToLong(), + add_time = Convert.ToDateTime(row["add_time"]), + }; + dbIdMapProductIdLst.Add(dbIdMapProductId); + } + var data = JsonUtils.SerializeObjectToString(dbIdMapProductIdLst); + 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 + "}"; + } + } + return "{\"code\":500,\"msg\":\"查询结果为空!\",\"data\":[],\"count\":" + 0 + "}"; + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + + public string GetSelectProdMapUpSpuIdList(string inputData, bool isDetail = false) + { + DateTime timeCalc = DateTime.Now; + 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("'", "\\'"); + var password = RegexUtils.GetStringQuery(ref inputData, "password")?.Replace("'", "\\'"); + if (string.IsNullOrEmpty(user_name)) + { + return "{\"code\":50001,\"msg\":\"用户为空\"}"; + } + + var in_draft_ids = RegexUtils.GetStringQuery(ref inputData, "in_draft_ids")?.Replace("'", "\\'"); + if (string.IsNullOrEmpty(in_draft_ids)) + { + return "{\"code\":50002,\"msg\":\"未选择选品数据\"}"; + } + var in_draft_id_list = in_draft_ids.Split(new string[] { " ", ",", "," }, StringSplitOptions.RemoveEmptyEntries); + if (in_draft_id_list.Count() <= 0) + { + return "{\"code\":50003,\"msg\":\"未选择选品数据\"}"; + } + string tableName = "kjd_map.spu_map_"; // kjd pdd jit 都在一套表 + long l_spu_map_table_id = 0; + + int page = RegexUtils.GetStringQuery(ref inputData, "page").ParseToInt(); + int page_size = RegexUtils.GetStringQuery(ref inputData, "page_size").ParseToInt(50); + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + + string sql = ""; + sql += "SELECT combined_query.*, p.cost_price, p.delivery_fee, p.mark_fee FROM ("; + for (int i = 0; i < in_draft_id_list.Count() && i < 200; i++) + { + if (i > 0) + sql += " UNION ALL "; + l_spu_map_table_id = in_draft_id_list[i].ParseToLong() % 128; + sql += "select * from " + tableName + l_spu_map_table_id + " where draft_id=" + in_draft_id_list[i]; + } + sql += ") AS combined_query left join product p ON combined_query.from_spu_id=p.spu_id"; + sql += " ORDER BY add_time desc"; + sql += " limit " + Math.Max(page - 1, 0) * page_size + "," + page_size; + DataTable dt = mySql.ExecuteDataTable(sql); + + mySql.Close(); + + if (!string.IsNullOrEmpty(mySql.Message)) + { + return "{\"code\":500,\"msg\":\"" + mySql.Message + "\",\"data\":[],\"count\":" + 0 + "}"; + } + if (dt != null) + { + try + { + List draftIdMapUpSpuIdLst = new List(); + foreach (DataRow row in dt.Rows) + { + DBProdDraftIdMapUpSpuIdResultParam draftIdMapUpSpuId = new DBProdDraftIdMapUpSpuIdResultParam + { + id = row["id"].ParseToLong(), + draft_id = row["draft_id"].ParseToLong(), + from_spu_id = row["from_spu_id"].ParseToLong(), + shop_id = row["shop_id"].ParseToLong(), + add_time = Convert.ToDateTime(row["add_time"]), + cost_price = row["cost_price"].IsNullOrEmpty() ? new decimal?() : row["cost_price"].ParseToDecimal(), + delivery_fee = row["delivery_fee"].IsNullOrEmpty() ? new decimal?() : row["delivery_fee"].ParseToDecimal(), + mark_fee = row["mark_fee"].IsNullOrEmpty() ? new decimal?() : row["mark_fee"].ParseToDecimal(), + }; + draftIdMapUpSpuIdLst.Add(draftIdMapUpSpuId); + } + var data = JsonUtils.SerializeObjectToString(draftIdMapUpSpuIdLst); + var seconds = (DateTime.Now - timeCalc).TotalSeconds.ToString("0.000"); + return "{\"code\":200,\"msg\":\"success\",\"data\":" + data + ",\"count\":" + -1 + ",\"seconds\":" + seconds + "}"; + } + catch (Exception ex) + { + return "{\"code\":500,\"msg\":\"" + ex.Message + "\",\"data\":[],\"count\":" + 0 + "}"; + } + } + return "{\"code\":500,\"msg\":\"查询结果为空!\",\"data\":[],\"count\":" + 0 + "}"; + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + public string AddSkuImg(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + var time = 0; + int.TryParse(RegexUtils.GetStringQuery(ref inputData, "time"), out time); + string time1 = RegexUtils.GetStringQuery(ref inputData, "code"); + if (time1 != EncrypUtil.Encryption(time)) + return "{\"code\":50000,\"msg\":\"校验失败\"}"; + + string user_name = RegexUtils.GetStringQuery(ref inputData, "user_name"); + string img_md5 = RegexUtils.GetStringQuery(ref inputData, "img_md5"); + string img_base64 = RegexUtils.GetStringQuery(ref inputData, "img_base64"); + string product_id = RegexUtils.GetStringQuery(ref inputData, "product_id"); + string spec_id = RegexUtils.GetStringQuery(ref inputData, "spec_id"); + string spec_name = RegexUtils.GetStringQuery(ref inputData, "spec_name"); + string original_img_url = RegexUtils.GetStringQuery(ref inputData, "original_img_url"); + + if (string.IsNullOrEmpty(user_name)) + { + return "{\"code\":500,\"msg\":\"没有用户名\"}"; + } + + int img_base64_db_id = 0; + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = ""; + + sql = "select id from kjd.sku_img_base64 where img_md5='" + img_md5 + "';"; + var nRst = 0L; + var rst = mySql.ExecuteFirstInt(sql).ParseToLong(); + if (rst <= 0) + { + sql = "insert into kjd.sku_img_base64 (img_md5,img_base64) " + + "values ('" + img_md5 + "','" + img_base64 + "');"; + rst = mySql.ExecuteInsertId(sql); + } + if (rst > 0) + { + img_base64_db_id = (int)rst; + sql = "insert kjd.sku_img (img_base64_db_id,product_id,spec_id,spec_name,original_img_url) " + + "values (" + img_base64_db_id + ",'" + product_id + "','" + spec_id + "','" + spec_name + "','" + original_img_url + "');"; + nRst = mySql.ExecuteInsertId(sql); + } + mySql.Close(); + if (nRst > 0) + { + return "{\"code\":200,\"msg\":\"success\",\"sku_img_id\":" + nRst + ",\"sku_img_Base64_id\":" + img_base64_db_id + "}"; + } + + return "{\"code\":500,\"msg\":\"" + mySql.Message + "\"}"; + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + public string DelSkuImg(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + var time = 0; + int.TryParse(RegexUtils.GetStringQuery(ref inputData, "time"), out time); + string time1 = RegexUtils.GetStringQuery(ref inputData, "code"); + if (time1 != EncrypUtil.Encryption(time)) + return "{\"code\":50000,\"msg\":\"校验失败\"}"; + + string user_name = RegexUtils.GetStringQuery(ref inputData, "user_name"); + int img_id = RegexUtils.GetStringQuery(ref inputData, "img_id").ParseToInt(); + int img_base64_id = RegexUtils.GetStringQuery(ref inputData, "img_base64_id").ParseToInt(); + + if (string.IsNullOrEmpty(user_name)) + { + return "{\"code\":500,\"msg\":\"没有用户名\"}"; + } + if (img_id == 0 || img_base64_id == 0) + { + return "{\"code\":501,\"msg\":\"图片编号或者图片数据编号为空\"}"; + } + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = ""; + + sql = "delete from kjd.sku_img where id=" + img_id + ";"; + var bRst = mySql.ExecuteNonQuery(sql); + if (!bRst) + { + mySql.Close(); + return "{\"code\":500,\"msg\":\"" + mySql.Message + "\"}"; + } + sql = "select id from kjd.sku_img where img_base64_db_id=" + img_base64_id + " limit 1;"; + var nRst = mySql.ExecuteRowCount(sql); + //如果已无对图片的引用,则删除原图片 + if (nRst == 0) + { + sql = "delete from kjd.sku_img_base64 where id=" + img_base64_id + ";"; + mySql.ExecuteNonQuery(sql); + } + mySql.Close(); + if (!string.IsNullOrEmpty(mySql.Message)) + return "{\"code\":500,\"msg\":\"" + mySql.Message + "\"}"; + return "{\"code\":200,\"msg\":\"success\"}"; + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + public string GetSkuImgList(string inputData, bool isDetail = false) + { + 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("'", "\\'"); + var password = RegexUtils.GetStringQuery(ref inputData, "password")?.Replace("'", "\\'"); + if (string.IsNullOrEmpty(user_name)) + { + return "{\"code\":500,\"msg\":\"没有用户名\"}"; + } + + var search_db_id = RegexUtils.GetStringQuery(ref inputData, "search_db_id")?.Replace("'", "\\'"); + var search_db_ids = RegexUtils.GetStringQuery(ref inputData, "search_db_ids")?.Replace("'", "\\'"); + var search_product_id = RegexUtils.GetStringQuery(ref inputData, "search_product_id")?.Replace("'", "\\'"); + var search_spec_id = RegexUtils.GetStringQuery(ref inputData, "search_spec_id")?.Replace("'", "\\'"); + var search_original_img_url = RegexUtils.GetStringQuery(ref inputData, "search_original_img_url")?.Replace("'", "\\'"); + + int page = RegexUtils.GetStringQuery(ref inputData, "page").ParseToInt(); + int page_size = RegexUtils.GetStringQuery(ref inputData, "page_size").ParseToInt(200); + bool is_random = RegexUtils.GetStringQuery(ref inputData, "is_random").ParseToBool(); + if (is_random) + { + page_size = 3; + } + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + + string sql = "select count(id) from kjd.sku_img s where 1=1"; + + string where = ""; + //if (!string.IsNullOrWhiteSpace(search_db_id)) + // where += " and s.id like '%" + search_db_id + "%'"; + //if (!string.IsNullOrWhiteSpace(search_product_id)) + // where += " and s.product_id like '%" + search_product_id + "%'"; + //if (!string.IsNullOrWhiteSpace(search_spec_id)) + // where += " and s.spec_id like '%" + search_spec_id + "%'"; + //if (!string.IsNullOrWhiteSpace(search_original_img_url)) + // where += " and s.original_img_url like '%" + search_original_img_url + "%'"; + if (!string.IsNullOrWhiteSpace(search_db_id)) + where += " and s.id = '" + search_db_id + "'"; + if (!string.IsNullOrWhiteSpace(search_product_id)) + where += " and s.product_id = '" + search_product_id + "'"; + if (!string.IsNullOrWhiteSpace(search_spec_id)) + where += " and s.spec_id = '" + search_spec_id + "'"; + if (!string.IsNullOrWhiteSpace(search_original_img_url)) + where += " and s.original_img_url = '" + search_original_img_url + "'"; + if (!string.IsNullOrEmpty(search_db_ids)) + where += " and s.id in (" + search_db_ids + ")"; + sql += where; + + var count = mySql.ExecuteRowCount(sql); + + DataTable dt; + if (count == 0) + { + dt = new DataTable(); + } + else + { + sql = "select s.*,b.img_md5,b.use_count,b.img_base64,b.img_url,b.mdy_time base64_mdy_time from kjd.sku_img s left join kjd.sku_img_base64 b on " + + "s.img_base64_db_id = b.id where 1=1"; + + //where子句 + sql += where; + + if (is_random) + sql += " ORDER BY RAND(),s.add_time desc"; + else + sql += " ORDER BY s.add_time 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\":500,\"msg\":\"" + mySql.Message + "\",\"data\":[],\"count\":" + 0 + "}"; + } + + if (dt != null) + { + try + { + List skuImgLst = new List(); + foreach (DataRow row in dt.Rows) + { + SkuImgResult img = new SkuImgResult + { + id = row["id"].ParseToInt(), + img_base64 = row["img_base64"].ParseToString(), + img_base64_db_id = row["img_base64_db_id"].ParseToInt(), + img_md5 = row["img_md5"].ParseToString(), + img_url = row["img_url"].ParseToString(), + original_img_url = row["original_img_url"].ParseToString(), + add_time = Convert.ToDateTime(row["add_time"]), + mdy_time = Convert.ToDateTime(row["mdy_time"]), + base64_mdy_time = Convert.ToDateTime(row["base64_mdy_time"]), + product_id = row["product_id"].ParseToString(), + spec_id = row["spec_id"].ParseToString(), + spec_name = row["spec_name"].ParseToString(), + use_count = row["use_count"].ParseToInt(), + }; + if(img.base64_mdy_time.AddDays(3) < DateTime.Now) + { + // 每过3天返回给客户端空图,让客户端重传base64图片 + img.img_url = ""; + } + else if (is_random && !string.IsNullOrWhiteSpace(img.img_url)) + { + // (仅上货)3天内返回给客户端图片链接同时不传base64图片 + img.img_base64 = ""; + } + //if (isDetail) + //{ + // img.img_base64 = row["img_base64"].ToString(); + //} + skuImgLst.Add(img); + } + var data = JsonUtils.SerializeObjectToString(skuImgLst); + return "{\"code\":200,\"msg\":\"success\",\"data\":" + data + ",\"count\":" + count + "}"; + } + 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 MdyBase64ImgUrl(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("'", "\\'"); + var id = RegexUtils.GetStringQuery(ref inputData, "db_id")?.Replace("'", "\\'"); + var img_url = RegexUtils.GetStringQuery(ref inputData, "img_url")?.Replace("'", "\\'"); + if(string.IsNullOrEmpty(id) || string.IsNullOrEmpty(img_url)) + { + return "{\"code\":500,\"msg\":\"保存失败:缺少图片编号或图片路径\"}"; + } + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = "update kjd.sku_img_base64 set img_url=\'" + img_url + "\' where id='" + id + "';"; + + var rst = mySql.ExecuteNonQuery(sql); + mySql.Close(); + if (rst) + { + return "{\"code\":200,\"msg\":\"success\"}"; + } + else + return "{\"code\":500,\"msg\":\"保存失败:" + mySql.Message + "\"}"; + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + public string MdyBase64ImgUseCount(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("'", "\\'"); + var ids = RegexUtils.GetStringQuery(ref inputData, "db_ids")?.Replace("'", "\\'"); + if (string.IsNullOrEmpty(ids)) + { + return "{\"code\":500,\"msg\":\"保存失败:缺少图片编号\"}"; + } + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = "update kjd.sku_img_base64 set use_count=use_count+1 where id in (" + ids + ");"; + + 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 AddCateSizeWeightConfig(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + var time = 0; + int.TryParse(RegexUtils.GetStringQuery(ref inputData, "time"), out time); + string time1 = RegexUtils.GetStringQuery(ref inputData, "code"); + if (time1 != EncrypUtil.Encryption(time)) + return "{\"code\":50000,\"msg\":\"校验失败\"}"; + + string user_name = RegexUtils.GetStringQuery(ref inputData, "user_name"); + string cat_id = RegexUtils.GetStringQuery(ref inputData, "cat_id"); + string min_len = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "minLen"))?.Replace("'", "\\'"); + string max_len = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "maxLen"))?.Replace("'", "\\'"); + string min_width = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "minWidth"))?.Replace("'", "\\'"); + string max_width = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "maxWidth"))?.Replace("'", "\\'"); + string min_height = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "minHeight"))?.Replace("'", "\\'"); + string max_height = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "maxHeight"))?.Replace("'", "\\'"); + string min_weight = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "minWeight"))?.Replace("'", "\\'"); + string max_weight = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "maxWeight"))?.Replace("'", "\\'"); + + if (string.IsNullOrEmpty(user_name)) + { + return "{\"code\":500,\"msg\":\"没有用户名\"}"; + } + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = ""; + + sql = "insert into kjd.cate_size_weight_config (cat_id,min_len,max_len,min_width,max_width,min_height,max_height,min_weight,max_weight) " + + "values ('" + cat_id + "'," + min_len + "," + max_len + "," + min_width + "," + max_width + "," + + min_height + "," + max_height + "," + min_weight + "," + max_weight + ");"; + 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 GetCateSizeWeightConfig(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + var time = 0; + int.TryParse(RegexUtils.GetStringQuery(ref inputData, "time"), out time); + string time1 = RegexUtils.GetStringQuery(ref inputData, "code"); + if (time1 != EncrypUtil.Encryption(time)) + return "{\"code\":50000,\"msg\":\"校验失败\"}"; + + string user_name = RegexUtils.GetStringQuery(ref inputData, "user_name"); + string cat_id = RegexUtils.GetStringQuery(ref inputData, "cat_id"); + string min_len = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "minLen"))?.Replace("'", "\\'"); + string max_len = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "maxLen"))?.Replace("'", "\\'"); + string min_width = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "minWidth"))?.Replace("'", "\\'"); + string max_width = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "maxWidth"))?.Replace("'", "\\'"); + string min_height = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "minHeight"))?.Replace("'", "\\'"); + string max_height = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "maxHeight"))?.Replace("'", "\\'"); + string min_weight = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "minWeight"))?.Replace("'", "\\'"); + string max_weight = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "maxWeight"))?.Replace("'", "\\'"); + + if (string.IsNullOrEmpty(user_name)) + { + return "{\"code\":500,\"msg\":\"没有用户名\"}"; + } + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = ""; + + sql = "select * from kjd.cate_size_weight_config where cat_id='" + cat_id + "';"; + var dt = mySql.ExecuteDataTable(sql); + mySql.Close(); + if (dt != null) + { + if(dt.Rows.Count > 0) + { + var row = dt.Rows[0]; + int id = row["id"].ParseToInt(); + string catId = row["cat_id"].ParseToString(); + int minLen = row["min_len"].ParseToInt(); + int maxLen = row["max_len"].ParseToInt(); + int minWidth = row["min_width"].ParseToInt(); + int maxWidth = row["max_width"].ParseToInt(); + int minHeight = row["min_height"].ParseToInt(); + int maxHeight = row["max_height"].ParseToInt(); + int minWeight = row["min_weight"].ParseToInt(); + int maxWeight = row["max_weight"].ParseToInt(); + + return "{\"code\":200,\"msg\":\"success\",\"data\":{\"catId\":\"" + catId + "\"," + + "\"minLen\":" + minLen + ",\"maxLen\":" + maxLen + "," + + "\"minWidth\":" + minWidth + ",\"maxWidth\":" + maxWidth + "," + + "\"minHeight\":" + minHeight + ",\"maxHeight\":" + maxHeight + "," + + "\"minWeight\":" + minWeight + ",\"maxWeight\":" + maxWeight + "}}"; + } + else + return "{\"code\":200,\"msg\":\"success\",\"data\":null}"; + } + else + { + return "{\"code\":500,\"msg\":\"" + mySql.Message + "\"}"; + } + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + } +} + + +/* + List paramLst = new List(); +paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "spu_id", Value = spu_id, }); +paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "skc_id", Value = skc_id, }); +paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "cat_id", Value = cat_id, }); +paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "cat_name", Value = cat_name, }); +paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "product_name", Value = product_name, }); +paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "ext_code", Value = ext_code, }); +paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "main_img", Value = main_img, }); +paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "product_json", Value = product_json, }); +paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "size_json", Value = size_json, }); +paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "notes", Value = notes.ParseToString(), }); +paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "product_md5", Value = product_md5, }); +paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "add_time", Value = add_time, }); +paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "mdy_time", Value = mdy_time, }); +rst = mySql.ExecuteInsertId(sql, paramLst.ToArray());*/ + + + + diff --git a/StoreHub.KJDWebService/Services/ProductThirdService.cs b/StoreHub.KJDWebService/Services/ProductThirdService.cs new file mode 100644 index 0000000..674ff68 --- /dev/null +++ b/StoreHub.KJDWebService/Services/ProductThirdService.cs @@ -0,0 +1,1474 @@ +using StoreHub.KJDWebService.Models; +using StoreHub.Framework.Repositorys; +using Microsoft.Extensions.Configuration; +using StoreHub.KJDWebService.Commons; +using MySql.Data.MySqlClient; +using NaiBa.Util.Extension; +using Newtonsoft.Json.Linq; +using System; +using System.Collections.Generic; +using System.Data; +using System.Linq; + +namespace StoreHub.KJDWebService.Services +{ + public class ProductThirdService : ServiceBase + { + public ProductThirdService(SqlRepository sqlRepository, IConfiguration configuration) : base(sqlRepository, configuration) + { + } + public string AddProduct(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + var time = 0; + int.TryParse(RegexUtils.GetStringQuery(ref inputData, "time"), out time); + string time1 = RegexUtils.GetStringQuery(ref inputData, "code"); + if (time1 != EncrypUtil.Encryption(time)) + return "{\"code\":50000,\"msg\":\"校验失败\"}"; + + string user_name = RegexUtils.GetStringQuery(ref inputData, "user_name"); + string spu_id = RegexUtils.GetStringQuery(ref inputData, "spu_id"); + string skc_id = RegexUtils.GetStringQuery(ref inputData, "skc_id"); + string cat_id = RegexUtils.GetStringQuery(ref inputData, "cat_id"); + string cat_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "cat_name")); + string ext_code = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "ext_code")); + string product_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "product_name")); + string product_json = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "product_json")); + string size_json = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "size_json")); + string main_img = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "main_img")); + string notes = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "notes")); + + if (string.IsNullOrEmpty(user_name)) + { + return "{\"code\":500,\"msg\":\"没有用户名\"}"; + } + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = ""; + var json_sign = RegexUtils.GetStringJson(ref product_json, "signedImageUrl"); // 取商品json数据里不同签名的部分 + var product_md5 = EncrypUtil.GetMd5(product_json?.Replace(json_sign, "") + size_json); + var product_md5_2 = EncrypUtil.GetMd5(product_json?.Replace("'", "\\'").Replace(json_sign, "") + size_json); + sql = "select id from kjd.third_product where product_md5='" + product_md5 + "' or product_md5='" + product_md5_2 + "';"; + var rst = mySql.ExecuteFirstInt(sql).ParseToLong(); + if (rst <= 0) + { + //sql = "insert into kjd.third_product (spu_id,skc_id,cat_id,cat_name,product_name,ext_code,main_img,product_json,size_json,notes,product_md5,add_time,mdy_time) " + + // "values ('" + spu_id + "','" + skc_id + "','" + cat_id + "','" + cat_name + "','" + product_name + "','" + + // ext_code + "','" + main_img + "','" + product_json + "','" + size_json + "','" + notes + "','" + product_md5 + "','" + + // DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "','" + + // DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "');"; + //rst = mySql.ExecuteInsertId(sql); + + sql = "insert into kjd.third_product (spu_id,skc_id,cat_id,cat_name,product_name," + + "ext_code,main_img,product_json,size_json,notes,product_md5,add_time,mdy_time) " + + "values (@spu_id,@skc_id,@cat_id,@cat_name,@product_name," + + "@ext_code,@main_img,@product_json,@size_json,@notes,@product_md5," + + "@add_time,@mdy_time);"; + string add_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); + string mdy_time = add_time; + List paramLst = new List(); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "@spu_id", Value = spu_id, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "@skc_id", Value = skc_id, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "@cat_id", Value = cat_id, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "@cat_name", Value = cat_name, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "@product_name", Value = product_name, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "@ext_code", Value = ext_code, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "@main_img", Value = main_img, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "@product_json", Value = product_json, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "@size_json", Value = size_json, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "@notes", Value = notes.ParseToString(), }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "@product_md5", Value = product_md5, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "@add_time", Value = add_time, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "@mdy_time", Value = mdy_time, }); + rst = mySql.ExecuteInsertId(sql, paramLst.ToArray()); + mySql.Close(); + } + if (rst > 0) + { + return "{\"code\":200,\"msg\":\"success\",\"id\":" + rst + "}"; + } + else + { + return "{\"code\":500,\"msg\":\"" + mySql.Message + "\"}"; + } + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + public string GetProductList(string inputData, bool isDetail = false) + { + var timeCalc = DateTime.Now; + 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("'","\\'"); + var password = RegexUtils.GetStringQuery(ref inputData, "password")?.Replace("'", "\\'"); + var search_spu = RegexUtils.GetStringQuery(ref inputData, "search_spu")?.Replace("'", "\\'"); + var search_skc = RegexUtils.GetStringQuery(ref inputData, "search_skc")?.Replace("'", "\\'"); + var search_cat = RegexUtils.GetStringQuery(ref inputData, "search_cat")?.Replace("'", "\\'"); + var search_ext_code = RegexUtils.GetStringQuery(ref inputData, "search_ext_code")?.Replace("'", "\\'"); + var search_prod_name = RegexUtils.GetStringQuery(ref inputData, "search_prod_name")?.Replace("'", "\\'"); + var search_notes = RegexUtils.GetStringQuery(ref inputData, "search_notes")?.Replace("'", "\\'"); + var search_db_ids = RegexUtils.GetStringQuery(ref inputData, "search_db_ids")?.Replace("'", "\\'"); + + int page = RegexUtils.GetStringQuery(ref inputData, "page").ParseToInt(); + int page_size= RegexUtils.GetStringQuery(ref inputData, "page_size").ParseToInt(50); + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + + string sql = "select count(id) from kjd.third_product where 1=1"; + + string where = ""; + if (!string.IsNullOrWhiteSpace(search_spu)) + where += " and spu_id like '%" + search_spu + "%'"; + if (!string.IsNullOrWhiteSpace(search_skc)) + where += " and skc_id like '%" + search_skc + "%'"; + if (!string.IsNullOrWhiteSpace(search_cat)) + where += " and cat_name like '%" + search_cat + "%'"; + if (!string.IsNullOrWhiteSpace(search_ext_code)) + where += " and ext_code like '%" + search_ext_code + "%'"; + if (!string.IsNullOrWhiteSpace(search_prod_name)) + where += " and product_name like '%" + search_prod_name + "%'"; + if (!string.IsNullOrWhiteSpace(search_notes)) + where += " and notes like '%" + search_notes + "%'"; + if (!string.IsNullOrEmpty(search_db_ids)) + where += " and id in (" + search_db_ids + ")"; + sql += where; + + var count = mySql.ExecuteRowCount(sql); + + DataTable dt; + if (count == 0) + { + dt = new DataTable(); + } + else + { + if (isDetail) + sql = "select * from kjd.third_product where 1=1"; + else + sql = "select id,spu_id,skc_id,cat_id,cat_name,change_cat_id,change_cat_name,ext_code,product_name,main_img,notes," + + "add_time,mdy_time from kjd.third_product where 1=1"; + + sql += where; + + sql += " order by id desc"; + sql += " limit " + Math.Max(page - 1, 0) * page_size + "," + page_size; + dt = mySql.ExecuteDataTable(sql); + } + + mySql.Close(); + if (dt != null) + { + try + { + List productLst = new List(); + foreach (DataRow row in dt.Rows) + { + DBProductResultParam prod = new DBProductResultParam + { + id = Convert.ToInt32(row["id"]), + skc_id = row["skc_id"].ToString(), + spu_id = row["spu_id"].ToString(), + cat_id = row["cat_id"].ToString(), + cat_name = row["cat_name"].ToString(), + change_cat_id = row["change_cat_id"].ToString(), + change_cat_name = row["change_cat_name"].ToString(), + product_name = row["product_name"].ToString(), + main_img = row["main_img"].ToString(), + ext_code = row["ext_code"].ToString(), + //product_json = row["product_json"].ToString(), + //size_json = row["size_json"].ToString(), + add_time = Convert.ToDateTime(row["add_time"]), + mdy_time = Convert.ToDateTime(row["mdy_time"]), + notes = row["notes"].ToString(), + }; + if (isDetail) + { + prod.product_json = row["product_json"].ToString(); + prod.size_json = row["size_json"].ToString(); + } + productLst.Add(prod); + } + var data = JsonUtils.SerializeObjectToString(productLst); + 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 GetProductListEmptyProductJsonForBak(string inputData, bool isDetail = false) + { + var timeCalc = DateTime.Now; + 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("'", "\\'"); + var password = RegexUtils.GetStringQuery(ref inputData, "password")?.Replace("'", "\\'"); + var search_spu = RegexUtils.GetStringQuery(ref inputData, "search_spu")?.Replace("'", "\\'"); + var search_skc = RegexUtils.GetStringQuery(ref inputData, "search_skc")?.Replace("'", "\\'"); + var search_cat = RegexUtils.GetStringQuery(ref inputData, "search_cat")?.Replace("'", "\\'"); + var search_ext_code = RegexUtils.GetStringQuery(ref inputData, "search_ext_code")?.Replace("'", "\\'"); + var search_prod_name = RegexUtils.GetStringQuery(ref inputData, "search_prod_name")?.Replace("'", "\\'"); + var search_notes = RegexUtils.GetStringQuery(ref inputData, "search_notes")?.Replace("'", "\\'"); + var search_db_ids = RegexUtils.GetStringQuery(ref inputData, "search_db_ids")?.Replace("'", "\\'"); + + int page = RegexUtils.GetStringQuery(ref inputData, "page").ParseToInt(); + int page_size = RegexUtils.GetStringQuery(ref inputData, "page_size").ParseToInt(50); + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + + string sql = "select count(id) from kjd.third_product where 1=1"; + + string where = ""; + if (!string.IsNullOrWhiteSpace(search_spu)) + where += " and spu_id like '%" + search_spu + "%'"; + if (!string.IsNullOrWhiteSpace(search_skc)) + where += " and skc_id like '%" + search_skc + "%'"; + if (!string.IsNullOrWhiteSpace(search_cat)) + where += " and cat_name like '%" + search_cat + "%'"; + if (!string.IsNullOrWhiteSpace(search_ext_code)) + where += " and ext_code like '%" + search_ext_code + "%'"; + if (!string.IsNullOrWhiteSpace(search_prod_name)) + where += " and product_name like '%" + search_prod_name + "%'"; + if (!string.IsNullOrWhiteSpace(search_notes)) + where += " and notes like '%" + search_notes + "%'"; + if (!string.IsNullOrEmpty(search_db_ids)) + where += " and id in (" + search_db_ids + ")"; + where += " AND add_time BETWEEN '26-1-11 17:33:35' and '26-1-15 9:30:00' and product_json='{}'"; + //where += " and product_json='{}' "; + sql += where; + + var count = mySql.ExecuteRowCount(sql); + + DataTable dt; + if (count == 0) + { + dt = new DataTable(); + } + else + { + if (isDetail) + sql = "select * from kjd.third_product where 1=1"; + else + sql = "select id,spu_id,skc_id,cat_id,cat_name,change_cat_id,change_cat_name,ext_code,product_name,main_img,notes," + + "add_time,mdy_time from kjd.third_product where 1=1"; + + sql += where; + + //sql += " order by id desc"; + sql += " order by id"; + sql += " limit " + Math.Max(page - 1, 0) * page_size + "," + page_size; + dt = mySql.ExecuteDataTable(sql); + } + + mySql.Close(); + if (dt != null) + { + try + { + List productLst = new List(); + foreach (DataRow row in dt.Rows) + { + DBProductResultParam prod = new DBProductResultParam + { + id = Convert.ToInt32(row["id"]), + skc_id = row["skc_id"].ToString(), + spu_id = row["spu_id"].ToString(), + cat_id = row["cat_id"].ToString(), + cat_name = row["cat_name"].ToString(), + change_cat_id = row["change_cat_id"].ToString(), + change_cat_name = row["change_cat_name"].ToString(), + product_name = row["product_name"].ToString(), + main_img = row["main_img"].ToString(), + ext_code = row["ext_code"].ToString(), + //product_json = row["product_json"].ToString(), + //size_json = row["size_json"].ToString(), + add_time = Convert.ToDateTime(row["add_time"]), + mdy_time = Convert.ToDateTime(row["mdy_time"]), + notes = row["notes"].ToString(), + }; + if (isDetail) + { + prod.product_json = row["product_json"].ToString(); + prod.size_json = row["size_json"].ToString(); + } + productLst.Add(prod); + } + var data = JsonUtils.SerializeObjectToString(productLst); + 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 GetProductListBak(string inputData, bool isDetail = false) + { + var timeCalc = DateTime.Now; + 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("'", "\\'"); + var password = RegexUtils.GetStringQuery(ref inputData, "password")?.Replace("'", "\\'"); + var search_spu = RegexUtils.GetStringQuery(ref inputData, "search_spu")?.Replace("'", "\\'"); + var search_skc = RegexUtils.GetStringQuery(ref inputData, "search_skc")?.Replace("'", "\\'"); + var search_cat = RegexUtils.GetStringQuery(ref inputData, "search_cat")?.Replace("'", "\\'"); + var search_ext_code = RegexUtils.GetStringQuery(ref inputData, "search_ext_code")?.Replace("'", "\\'"); + var search_prod_name = RegexUtils.GetStringQuery(ref inputData, "search_prod_name")?.Replace("'", "\\'"); + var search_notes = RegexUtils.GetStringQuery(ref inputData, "search_notes")?.Replace("'", "\\'"); + var search_db_ids = RegexUtils.GetStringQuery(ref inputData, "search_db_ids")?.Replace("'", "\\'"); + + int page = RegexUtils.GetStringQuery(ref inputData, "page").ParseToInt(); + int page_size = RegexUtils.GetStringQuery(ref inputData, "page_size").ParseToInt(50); + + string conn = "ConnKJDBAK"; + MysqlUtils mySql = new MysqlUtils(conn); + + string sql = "select count(id) from kjd.third_product where 1=1"; + + string where = ""; + if (!string.IsNullOrWhiteSpace(search_spu)) + where += " and spu_id = '" + search_spu + "'"; + if (!string.IsNullOrWhiteSpace(search_skc)) + where += " and skc_id = '" + search_skc + "'"; + if (!string.IsNullOrWhiteSpace(search_cat)) + where += " and cat_name like '%" + search_cat + "%'"; + if (!string.IsNullOrWhiteSpace(search_ext_code)) + where += " and ext_code like '%" + search_ext_code + "%'"; + if (!string.IsNullOrWhiteSpace(search_prod_name)) + where += " and product_name like '%" + search_prod_name + "%'"; + if (!string.IsNullOrWhiteSpace(search_notes)) + where += " and notes like '%" + search_notes + "%'"; + if (!string.IsNullOrEmpty(search_db_ids)) + where += " and id in (" + search_db_ids + ")"; + sql += where; + + var count = mySql.ExecuteRowCount(sql); + + DataTable dt; + if (count == 0) + { + dt = new DataTable(); + } + else + { + if (isDetail) + sql = "select * from kjd.third_product where 1=1"; + else + sql = "select id,spu_id,skc_id,cat_id,cat_name,change_cat_id,change_cat_name,ext_code,product_name,main_img,notes," + + "add_time,mdy_time from kjd.third_product where 1=1"; + + sql += where; + + sql += " order by id desc"; + sql += " limit " + Math.Max(page - 1, 0) * page_size + "," + page_size; + dt = mySql.ExecuteDataTable(sql); + } + + mySql.Close(); + if (dt != null) + { + try + { + List productLst = new List(); + foreach (DataRow row in dt.Rows) + { + DBProductResultParam prod = new DBProductResultParam + { + id = Convert.ToInt32(row["id"]), + skc_id = row["skc_id"].ToString(), + spu_id = row["spu_id"].ToString(), + cat_id = row["cat_id"].ToString(), + cat_name = row["cat_name"].ToString(), + change_cat_id = row["change_cat_id"].ToString(), + change_cat_name = row["change_cat_name"].ToString(), + product_name = row["product_name"].ToString(), + main_img = row["main_img"].ToString(), + ext_code = row["ext_code"].ToString(), + //product_json = row["product_json"].ToString(), + //size_json = row["size_json"].ToString(), + add_time = Convert.ToDateTime(row["add_time"]), + mdy_time = Convert.ToDateTime(row["mdy_time"]), + notes = row["notes"].ToString(), + }; + if (isDetail) + { + prod.product_json = row["product_json"].ToString(); + prod.size_json = row["size_json"].ToString(); + } + productLst.Add(prod); + } + var data = JsonUtils.SerializeObjectToString(productLst); + 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 DelDbProd(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("'", "\\'"); + var id = RegexUtils.GetStringQuery(ref inputData, "db_id")?.Replace("'", "\\'"); + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = "delete from kjd.third_product where id='" + + id + "'"; + + var rst = mySql.ExecuteNonQuery(sql); + mySql.Close(); + if (rst) + { + return "{\"code\":200,\"msg\":\"success\"}"; + } + else + return "{\"code\":500,\"msg\":\"删除失败:" + mySql.Message + "\"}"; + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + public string MdyProductNotes(string inputData, bool isAdmin = false) + { + 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("'", "\\'"); + var id = RegexUtils.GetStringQuery(ref inputData, "db_id")?.Replace("'", "\\'"); + string notes = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "notes"))?.Replace("'", "\\'"); + + if (string.IsNullOrEmpty(user_name)) + { + return "{\"code\":500,\"msg\":\"没有用户名\"}"; + } + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = "update kjd.third_product set"; + if (notes != null) + sql += " notes='" + notes + "',"; + sql = sql.TrimEnd(','); + sql += " where id=" + id + ";"; + + var rst = mySql.ExecuteNonQuery(sql); + mySql.Close(); + if (rst) + { + return "{\"code\":200,\"msg\":\"success\"}"; + } + else + { + return "{\"code\":500,\"msg\":\"更新失败:" + mySql.Message + "\"}"; + } + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + public string MdyProductCategory(string inputData, bool isAdmin = false) + { + 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("'", "\\'"); + var id = RegexUtils.GetStringQuery(ref inputData, "db_id")?.Replace("'", "\\'"); + string change_cat_id = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "change_cat_id"))?.Replace("'", "\\'"); + string change_cat_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "change_cat_name"))?.Replace("'", "\\'"); + + if (string.IsNullOrEmpty(user_name)) + { + return "{\"code\":500,\"msg\":\"没有用户名\"}"; + } + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = "update kjd.third_product set"; + if (change_cat_id != null) + sql += " change_cat_id='" + change_cat_id + "',"; + if (change_cat_name != null) + sql += " change_cat_name='" + change_cat_name + "',"; + sql = sql.TrimEnd(','); + sql += " where id=" + id + ";"; + + var rst = mySql.ExecuteNonQuery(sql); + mySql.Close(); + if (rst) + { + return "{\"code\":200,\"msg\":\"success\"}"; + } + else + { + return "{\"code\":500,\"msg\":\"更新失败:" + mySql.Message + "\"}"; + } + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + public string MdyDBProduct(string inputData, bool isAdmin = false) + { + 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("'", "\\'"); + var id = RegexUtils.GetStringQuery(ref inputData, "db_id")?.Replace("'", "\\'"); + string product_name = RegexUtils.GetStringQuery(ref inputData, "product_name"); + string notes = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "notes")); + string ext_code = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "ext_code")); + string product_json = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "product_json")); + string size_json = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "size_json")); + + if (string.IsNullOrEmpty(id)) + { + return "{\"code\":500,\"msg\":\"没有指定商品\"}"; + } + if (string.IsNullOrEmpty(user_name)) + { + return "{\"code\":500,\"msg\":\"没有用户名\"}"; + } + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = "update kjd.third_product set"; + if (product_name != null) + sql += " product_name=@product_name,"; + if (notes != null) + sql += " notes=@notes,"; + if (ext_code != null) + sql += " ext_code=@ext_code,"; + if (product_json != null) + sql += " product_json=@product_json,"; + if (size_json != null) + sql += " size_json=@size_json,"; + sql = sql.TrimEnd(','); + sql += " where id=" + id + ";"; + + + + + + List paramLst = new List(); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "@product_name", Value = product_name, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "@ext_code", Value = ext_code, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "@product_json", Value = product_json, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "@size_json", Value = size_json, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "@notes", Value = notes, }); + + + + var rst = mySql.ExecuteNonQuery(sql, paramLst.ToArray()); + mySql.Close(); + if (rst) + { + return "{\"code\":200,\"msg\":\"success\"}"; + } + else + { + return "{\"code\":500,\"msg\":\"更新失败:" + mySql.Message + "\"}"; + } + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + + public string AddUserSelectProduct(string inputData, bool isAdmin = false) + { + 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 out_product_Id = RegexUtils.GetStringQuery(ref inputData, "out_product_id")?.Replace("'", "\\'"); + var shop_id = RegexUtils.GetStringQuery(ref inputData, "shop_id")?.Replace("'", "\\'"); + var shop_account = RegexUtils.GetStringQuery(ref inputData, "shop_account")?.Replace("'", "\\'"); + var user_name = RegexUtils.GetStringQuery(ref inputData, "main_user_name")?.Replace("'", "\\'"); + var sub_user_name = RegexUtils.GetStringQuery(ref inputData, "sub_user_name")?.Replace("'", "\\'"); + var notes = RegexUtils.GetStringQuery(ref inputData, "notes")?.Replace("'", "\\'"); + var status = RegexUtils.GetStringQuery(ref inputData, "status")?.Replace("'", "\\'"); + var add_product_remaining = RegexUtils.GetStringQuery(ref inputData, "add_product_remaining").ParseToInt(); + + if (string.IsNullOrEmpty(user_name)) + { + return "{\"code\":500,\"msg\":\"没有用户名\"}"; + } + if (string.IsNullOrEmpty(shop_id)) + { + return "{\"code\":500,\"msg\":\"没有店铺信息\"}"; + } + + DateTime addTime = DateTime.Now; + string addTimeStr = addTime.ToString("yyyy-MM-dd HH:mm:ss"); + string dbName = "kjd"; + if (addTime.Year >= 2026) + dbName = "kjd_yearly"; + + string tableName = dbName + ".third_product_select"; + if (addTime.Year >= 2026) + tableName += "_" + addTime.Year; + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + + string sql = ""; + if (add_product_remaining > 0) // add_product_remaining 为空或为0表示商品直传,不消耗次数 + { + sql = "select * from kjd.shop_add_prod_count where shop_id='" + shop_id + "';"; + var dt = mySql.ExecuteDataTable(sql); + if (!string.IsNullOrEmpty(mySql.Message)) + { + mySql.Close(); + return "{\"code\":500,\"msg\":\"" + mySql.Message + "\"}"; + } + if (dt != null && dt.Rows.Count > 0) + { + add_product_remaining = dt.Rows[0]["add_product_remaining"].ParseToInt(); + if (add_product_remaining <= 0) + { + mySql.Close(); + return "{\"code\":501,\"msg\":\"本月商品认领限额已用完,请下个月再操作!\"}"; + } + } + } + + sql = "INSERT INTO " + tableName + + " (out_product_Id,shop_id,shop_account,user_name,sub_user_name,notes,status,add_time,mdy_time) VALUES" + + " ('" + out_product_Id + "','" + shop_id + "','" + shop_account + "','" + user_name + "','" + sub_user_name + "','" + + notes + "','" + status + "','" + + addTimeStr + "','" + + addTimeStr + "');"; + if (add_product_remaining > 0) // add_product_remaining 为空或为0表示商品直传,不消耗次数 + { + add_product_remaining = add_product_remaining - 1; + sql += "\r\n"; + //sql += "UPDATE kjd.shop SET add_product_remaining=" + add_product_remaining + " where shop_id='" + shop_id + "';"; + sql += "INSERT INTO kjd.shop_add_prod_count(shop_id, add_product_remaining) VALUES('" + shop_id + "'," + add_product_remaining + ")" + + "ON DUPLICATE KEY UPDATE add_product_remaining=add_product_remaining-1"; + } + 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 MdyUserSelectProductStatus(string inputData, bool isAdmin = false) + { + 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 select_db_id = RegexUtils.GetStringQuery(ref inputData, "db_id")?.Replace("'", "\\'"); + var draft_id = RegexUtils.GetStringQuery(ref inputData, "draft_id")?.Replace("'", "\\'"); + var up_spu_id = RegexUtils.GetStringQuery(ref inputData, "up_spu_id")?.Replace("'", "\\'"); + var shop_id = RegexUtils.GetStringQuery(ref inputData, "shop_id")?.Replace("'", "\\'"); + var status = RegexUtils.GetStringQuery(ref inputData, "status")?.Replace("'", "\\'"); + var add_times = RegexUtils.GetStringQuery(ref inputData, "add_times")?.Replace("'", "\\'"); + var select_add_time = RegexUtils.GetStringQuery(ref inputData, "select_add_time")?.Replace("'", "\\'").ParseToDateTimeNullable(); + if (select_add_time == null) + { + return "{\"code\":500,\"msg\":\"当前软件版本不支持该操作,请升级软件。\"}"; + } + + long l_draft_id = draft_id.ParseToLong(); + long l_spu_map_table_id = l_draft_id % 128; + long l_select_map_table_id = select_db_id.ParseToLong() % 64; + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = ""; + + // 使用事务一次提交多个sql操作 + //sql += "set @@autocommit=0;\r\n"; + sql += "START TRANSACTION;\r\n"; + if (!string.IsNullOrEmpty(up_spu_id) && !string.IsNullOrEmpty(draft_id)) + { + sql += "INSERT into kjd_map.spu_map_" + l_spu_map_table_id + + " (draft_id,from_spu_id,shop_id) VALUES(" + draft_id + "," + up_spu_id + ",'" + shop_id + "');\r\n"; + if (!select_add_time.HasValue || select_add_time.Value.Year < 2026) + { + sql += "INSERT into kjd_map.product_third_select_map_" + l_select_map_table_id + + " (product_id,product_select_db_id,shop_id) VALUES(" + draft_id + "," + select_db_id + ",'" + shop_id + "');\r\n"; + } + else + { + string select_type = "third-party"; + sql += "INSERT INTO kjd_map_yearly.product_select_map_" + select_add_time.Value.Year + + "(product_select_db_id,product_id,shop_id,select_type) VALUES" + + "(" + select_db_id + ",'" + draft_id + "','" + shop_id + "','" + select_type + "');\r\n"; + } + } + + string dbName = "kjd"; + if (select_add_time.HasValue && select_add_time.Value.Year >= 2026) + dbName = "kjd_yearly"; + string tableName = dbName + ".third_product_select"; + if (select_add_time.HasValue && select_add_time.Value.Year >= 2026) + tableName += "_" + select_add_time.Value.Year; + + sql += "update " + tableName + " set"; + if (draft_id != null) + sql += " draft_id='" + draft_id + "',"; + if (status != null) + sql += " status='" + status + "',"; + if (status == "已上传") + sql += " add_times=add_times+1,"; + sql += " mdy_time='" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "',"; + sql = sql.TrimEnd(','); + sql += " WHERE id=" + select_db_id + ";\r\n"; + var rst = mySql.ExecuteNonQuery(sql); + string errMsg = mySql.Message; + if (string.IsNullOrEmpty(errMsg)) + sql = "COMMIT;"; + else + sql = "ROLLBACK;"; + mySql.ExecuteNonQuery(sql); + mySql.Close(); + if (rst) + { + return "{\"code\":200,\"msg\":\"success\"}"; + } + else + { + return "{\"code\":500,\"msg\":\"" + errMsg + "\"}"; + } + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + public string GetUserSelectProductList(string inputData, bool isAdmin = false) + { + var timeCalc = DateTime.Now; + 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\":500,\"msg\":\"没有用户名\"}"; + } + + var shop_ids = RegexUtils.GetStringQuery(ref inputData, "shop_ids")?.Replace("'", "\\'"); + var search_shop_id = RegexUtils.GetStringQuery(ref inputData, "search_shop_id")?.Replace("'", "\\'"); + var search_shop_account = RegexUtils.GetStringQuery(ref inputData, "search_shop_account"); + var search_spu = RegexUtils.GetStringQuery(ref inputData, "search_spu")?.Replace("'", "\\'"); + var search_skc = RegexUtils.GetStringQuery(ref inputData, "search_skc")?.Replace("'", "\\'"); + var search_cat = RegexUtils.GetStringQuery(ref inputData, "search_cat")?.Replace("'", "\\'"); + var search_ext_code = RegexUtils.GetStringQuery(ref inputData, "search_ext_code")?.Replace("'", "\\'"); + var search_prod_name = RegexUtils.GetStringQuery(ref inputData, "search_prod_name"); + var search_notes = RegexUtils.GetStringQuery(ref inputData, "search_notes")?.Replace("'", "\\'"); + var search_user_notes = RegexUtils.GetStringQuery(ref inputData, "search_user_notes")?.Replace("'", "\\'"); + var search_db_ids = RegexUtils.GetStringQuery(ref inputData, "search_db_ids")?.Replace("'", "\\'"); + var search_sub_sa_name = RegexUtils.GetStringQuery(ref inputData, "search_sub_sa_name")?.Replace("'", "\\'"); + var status = RegexUtils.GetStringQuery(ref inputData, "status")?.Replace("'", "\\'"); + var operate_sub_sa_name = RegexUtils.GetStringQuery(ref inputData, "operate_sub_sa_name")?.Replace("'", "\\'"); + var search_year = RegexUtils.GetStringQuery(ref inputData, "search_year")?.Replace("'", "\\'").ParseToInt(); + + var search_end_time = RegexUtils.GetStringJson(ref inputData, "search_end_time")?.ParseToDateTimeNullable(); + if (search_end_time == null || search_end_time.Value > DateTime.Now.Date.AddDays(1)) search_end_time = DateTime.Now.Date.AddDays(1); + var search_start_time = RegexUtils.GetStringJson(ref inputData, "search_start_time")?.ParseToDateTimeNullable(); + if (search_start_time == null || search_start_time.Value >= search_end_time.Value) search_start_time = search_end_time.Value.AddMonths(-6); + int startTableId = Math.Max(2025, search_start_time.Value.Year); + int endTableId = Math.Max(2025, search_end_time.Value.Year); + + var no_sub_sa = RegexUtils.GetStringQuery(ref inputData, "no_sub_sa")?.Replace("'", "\\'"); + + int page = RegexUtils.GetStringQuery(ref inputData, "page").ParseToInt(); + int page_size = RegexUtils.GetStringQuery(ref inputData, "page_size").ParseToInt(50); + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + + string sql = ""; + if (search_year != null) + { + string dbName = "kjd"; + if (search_year >= 2026) + dbName = "kjd_yearly"; + string tableName = dbName + ".third_product_select"; + if (search_year >= 2026) + tableName += "_" + search_year; + sql += " SELECT count(s.id) FROM " + tableName + " s " + + //"LEFT JOIN kjd.third_product p on s.out_product_id=p.id " + + //"LEFT JOIN kjd.user u on s.operate_sub_sa_name=u.user_name " + + "WHERE 1=1"; + } + else + { + sql = "select count(s.id) from ("; + for (int year = search_start_time.Value.Year; year <= search_end_time.Value.Year; year++) + { + string dbName = "kjd"; + if (year >= 2026) + dbName = "kjd_yearly"; + string tableName = dbName + ".third_product_select"; + + if (year >= 2026) + tableName += "_" + year; + if (year > search_start_time.Value.Year) + sql += " UNION ALL"; + sql += " SELECT * FROM " + tableName; + } + sql += ") s " + + "LEFT JOIN kjd.third_product p on s.out_product_id=p.id " + + "LEFT JOIN kjd.user u on s.operate_sub_sa_name=u.user_name " + + "WHERE s.add_time BETWEEN '" + search_start_time.Value.ToString("yyyy-MM-dd") + "' AND '" + search_end_time.Value.ToString("yyyy-MM-dd") + "' "; + } + + string where = ""; + if (!isAdmin) + //where += " and (s.user_name='" + user_name + "' or s.sub_user_name like '%" + user_name + "%')"; + where += " and s.user_name='" + user_name + "'"; + if (!string.IsNullOrEmpty(operate_sub_sa_name)) + { + where += " and s.operate_sub_sa_name = '" + operate_sub_sa_name + "'"; + } + if (no_sub_sa == "true") + where += " and s.operate_sub_sa_name is null"; + if (!string.IsNullOrEmpty(search_db_ids)) + where += " and s.id in (" + search_db_ids + ")"; + if (!string.IsNullOrEmpty(shop_ids)) + where += " and s.shop_id in (" + shop_ids + ")"; + if (!string.IsNullOrWhiteSpace(status)) + where += " and s.status = '" + status + "'"; + if (!string.IsNullOrWhiteSpace(search_shop_id)) + where += " and s.shop_id like '" + search_shop_id + "%'"; + if (!string.IsNullOrWhiteSpace(search_shop_account)) + where += " and s.shop_account like @search_shop_account"; + if (!string.IsNullOrWhiteSpace(search_notes)) + { + //核价成功 重复 核价成功(重复) + if (search_notes == "无备注") + where += " and s.notes = ''"; + else if (search_notes == "重复") + where += " and s.notes like '重复%' and s.notes not like '核价成功%' and s.notes not like '核价通过%'"; + else if (search_notes == "核价成功") + where += " and (s.notes like '核价成功%' or s.notes like '核价通过%') and s.notes not like '重复%'"; + else if (search_notes == "核价成功(重复)") + where += " and (s.notes like '核价成功%' or s.notes like '核价通过%') and s.notes like '重复%'"; + else + where += " and s.notes like '" + search_notes + "%'"; + } + if (!string.IsNullOrWhiteSpace(search_user_notes)) + where += " and s.user_notes like '" + search_user_notes + "%'"; + if (!string.IsNullOrWhiteSpace(search_spu)) + where += " and p.spu_id like '" + search_spu + "%'"; + if (!string.IsNullOrWhiteSpace(search_skc)) + where += " and p.skc_id like '" + search_skc + "%'"; + if (!string.IsNullOrWhiteSpace(search_cat)) + where += " and p.cat_name like '" + search_cat + "%'"; + if (!string.IsNullOrWhiteSpace(search_ext_code)) + where += " and p.ext_code like '" + search_ext_code + "%'"; + if (!string.IsNullOrWhiteSpace(search_prod_name)) + where += " and p.product_name like @search_prod_name"; + if (!string.IsNullOrEmpty(search_sub_sa_name)) + { + where += " and (s.operate_sub_sa_name like '" + search_sub_sa_name + "%'"; + where += " or u.nick_name like '" + operate_sub_sa_name + "%')"; + } + + sql += where; + + List paramLst = new List(); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "@search_shop_account", Value = "" + search_shop_account + "%", }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "@search_prod_name", Value = "%" + search_prod_name + "%", }); + + var count = mySql.ExecuteRowCount(sql, paramLst.ToArray()); + + DataTable dt; + if (count == 0) + { + dt = new DataTable(); + } + else + { + //if (isDetail) + //sql = "select * from kjd.third_product_select where 1=1"; + //else + + if (search_year != null) + { + string dbName = "kjd"; + if (search_year >= 2026) + dbName = "kjd_yearly"; + string tableName = dbName + ".third_product_select"; + if (search_year >= 2026) + tableName += "_" + search_year; + + //sql = "SELECT s.id,s.out_product_id,s.shop_id,s.shop_account,s.user_name," + + // "s.sub_user_name,s.notes,s.user_notes,s.status,s.draft_id,s.add_times,s.add_time,s.mdy_time," + + // "s.fission_product_name,s.operate_sub_sa_name,s.add_sub_sa_time," + + // "p.spu_id,p.skc_id,p.cat_id,p.cat_name,p.change_cat_id,p.change_cat_name,p.ext_code,p.product_name,p.main_img," + + // "u.nick_name as operate_sub_sa_nick " + + // "FROM " + tableName + " s LEFT JOIN kjd.third_product p ON s.out_product_id=p.id " + + // "LEFT JOIN kjd.user u ON u.user_name=s.operate_sub_sa_name " + + // "WHERE 1=1"; + //sql += where; // where子句 + //sql += " order by s.add_time desc"; + //sql += " limit " + Math.Max(page - 1, 0) * page_size + "," + page_size; + //-------------------------------------------------------------------------------------------------------- + sql = "SELECT s1.id,s1.out_product_id,s1.shop_id,s1.shop_account,s1.user_name," + + "s1.sub_user_name,s1.notes,s1.user_notes,s1.status,s1.draft_id,s1.add_times,s1.add_time,s1.mdy_time," + + "s1.fission_product_name,s1.operate_sub_sa_name,s1.add_sub_sa_time," + + "s2.spu_id,s2.skc_id,s2.cat_id,s2.cat_name,s2.change_cat_id,s2.change_cat_name,s2.ext_code,s2.product_name,s2.main_img "; + if (operate_sub_sa_name != null || 1 == 1) + sql += ",s2.operate_sub_sa_nick"; + sql += " FROM " + tableName + " s1"; + // 子查询 + sql += " JOIN (SELECT s.id," + + "p.spu_id,p.skc_id,p.cat_id,p.cat_name,p.change_cat_id,p.change_cat_name,p.ext_code,p.product_name,p.main_img "; + if (operate_sub_sa_name != null || 1 == 1) + sql += ",u.nick_name as operate_sub_sa_nick "; + sql += " FROM " + tableName + " s LEFT JOIN kjd.third_product p ON s.out_product_id=p.id "; + if (operate_sub_sa_name != null || 1 == 1) + sql += "LEFT JOIN kjd.user u ON u.user_name=s.operate_sub_sa_name "; + sql += "WHERE 1=1"; + sql += where; // where子句 + sql += " order by s.add_time desc"; + sql += " limit " + Math.Max(page - 1, 0) * page_size + "," + page_size; + sql += ") as s2 ON s1.id = s2.id"; + } + else + { + sql = "SELECT s.id,s.out_product_id,s.shop_id,s.shop_account,s.user_name," + + "s.sub_user_name,s.notes,s.user_notes,s.status,s.draft_id,s.add_times,s.add_time,s.mdy_time," + + "s.fission_product_name,s.operate_sub_sa_name,s.add_sub_sa_time," + + "p.spu_id,p.skc_id,p.cat_id,p.cat_name,p.change_cat_id,p.change_cat_name,p.ext_code,p.product_name,p.main_img," + + "u.nick_name as operate_sub_sa_nick " + + "FROM ("; + + for (int year = search_start_time.Value.Year; year <= search_end_time.Value.Year; year++) + { + string dbName = "kjd"; + if (year >= 2026) + dbName = "kjd_yearly"; + string tableName = dbName + ".third_product_select"; + + if (year >= 2026) + tableName += "_" + year; + if (year > search_start_time.Value.Year) + sql += " UNION ALL"; + sql += " SELECT * FROM " + tableName; + } + + sql += ") s LEFT JOIN kjd.third_product p ON s.out_product_id=p.id " + + "LEFT JOIN kjd.user u ON u.user_name=s.operate_sub_sa_name " + + "WHERE s.add_time BETWEEN '" + search_start_time.Value.ToString("yyyy-MM-dd") + "' AND '" + search_end_time.Value.ToString("yyyy-MM-dd") + "' "; + + + sql += where; // where子句 + + sql += " order by s.add_time desc"; + sql += " limit " + Math.Max(page - 1, 0) * page_size + "," + page_size; + } + dt = mySql.ExecuteDataTable(sql, paramLst.ToArray()); + } + + mySql.Close(); + if (dt != null) + { + try + { + List productLst = new List(); + foreach (DataRow row in dt.Rows) + { + ProductSelectResultParam prodSelect = new ProductSelectResultParam() + { + id = row["id"].ParseToLong(), + out_product_Id = row["out_product_Id"].ParseToString(), + shop_account = row["shop_account"].ParseToString(), + shop_id = row["shop_id"].ParseToString(), + status = row["status"].ParseToString(), + sub_user_name = row["sub_user_name"].ParseToString(), + user_name = row["user_name"].ParseToString(), + cat_id = row["cat_id"].ParseToString(), + cat_name = row["cat_name"].ParseToString(), + change_cat_id = row["change_cat_id"].ParseToString(), + change_cat_name = row["change_cat_name"].ParseToString(), + product_name = row["product_name"].ParseToString(), + main_img = row["main_img"].ParseToString(), + ext_code = row["ext_code"].ParseToString(), + add_time = Convert.ToDateTime(row["add_time"]), + mdy_time = Convert.ToDateTime(row["mdy_time"]), + notes = row["notes"].ParseToString(), + draft_id = row["draft_id"].ParseToString(), + add_times = row["add_times"].ParseToInt(), + skc_id = row["skc_id"].ToString(), + spu_id = row["spu_id"].ToString(), + operate_sub_sa_name = row["operate_sub_sa_name"].ToString(), + fission_product_name = row["fission_product_name"].ToString(), + user_notes = row["user_notes"].ToString(), + //product_json = row["product_json"].ToString(), + //size_json = row["size_json"].ToString(), + }; + if (operate_sub_sa_name != null || 1 == 1) + { + prodSelect.operate_sub_sa_nick = row["operate_sub_sa_nick"].ToString(); + } + prodSelect.add_sub_sa_time = row["add_sub_sa_time"] as DateTime?; + productLst.Add(prodSelect); + } + var data = JsonUtils.SerializeObjectToString(productLst); + 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 DelSelectProd(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("'", "\\'"); + var id = RegexUtils.GetStringQuery(ref inputData, "db_id")?.Replace("'", "\\'"); + + if (string.IsNullOrEmpty(user_name)) + { + return "{\"code\":500,\"msg\":\"没有用户名\"}"; + } + + var select_add_time = RegexUtils.GetStringQuery(ref inputData, "select_add_time")?.Replace("'", "\\'").ParseToDateTimeNullable(); + if (select_add_time == null) + { + return "{\"code\":500,\"msg\":\"当前软件版本不支持该操作,请升级软件。\"}"; + } + + string dbName = "kjd"; + if (select_add_time != null && select_add_time.Value.Year >= 2026) + dbName = "kjd_yearly"; + string tableName = dbName + ".third_product_select"; + if (select_add_time != null && select_add_time.Value.Year >= 2026) + tableName += "_" + select_add_time.Value.Year; + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = "delete from " + tableName + " where id='" + + id + "'"; + + var rst = mySql.ExecuteNonQuery(sql); + mySql.Close(); + if (rst) + { + return "{\"code\":200,\"msg\":\"success\"}"; + } + else + return "{\"code\":500,\"msg\":\"删除失败:" + mySql.Message + "\"}"; + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + /// + /// 设置上传商品的二级超管 + /// + /// + public string SetSelectProductSubSa(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 db_ids = RegexUtils.GetStringQuery(ref inputData, "db_id")?.Replace("'", "\\'"); + var shop_ids = RegexUtils.GetStringQuery(ref inputData, "shop_id")?.Replace("'", "\\'"); + var operate_sub_sa_name = RegexUtils.GetStringQuery(ref inputData, "operate_sub_sa_name")?.Replace("'", "\\'"); + var status = RegexUtils.GetStringQuery(ref inputData, "status")?.Replace("'", "\\'"); + var db_id_infos = RegexUtils.GetStringQuery(ref inputData, "db_id_infos")?.Replace("'", "\\'"); + + if (operate_sub_sa_name == null) + { + return "{\"code\":50002,\"msg\":\"未选择任何二级超管\"}"; + } + if (string.IsNullOrEmpty(db_ids) && string.IsNullOrEmpty(shop_ids) && string.IsNullOrEmpty(db_id_infos)) + { + return "{\"code\":50003,\"msg\":\"未选择任何待设置对象\"}"; + } + + var select_add_time = RegexUtils.GetStringQuery(ref inputData, "select_add_time")?.Replace("'", "\\'").ParseToDateTimeNullable(); + if (select_add_time == null && db_id_infos == null && db_ids == null) + { + return "{\"code\":500,\"msg\":\"当前软件版本不支持该操作,请升级软件。\"}"; + } + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + + string sql = ""; + bool rst = false; + + if (!string.IsNullOrEmpty(db_ids)) + { + sql = "UPDATE kjd.third_product_select SET"; + sql += " operate_sub_sa_name='" + operate_sub_sa_name + "',"; + sql += " add_sub_sa_time='" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "'"; + sql += " WHERE id IN (" + db_ids + ")"; + if (!string.IsNullOrEmpty(status)) + sql += " AND status='" + status + "';"; + + rst = mySql.ExecuteNonQuery(sql); + if (!string.IsNullOrEmpty(mySql.Message)) + { + mySql.Close(); + return "{\"code\":500,\"msg\":\"" + mySql.Message + "\"}"; + } + } + else if (!string.IsNullOrEmpty(shop_ids)) + { + List yearLst = new List() { 2025 }; + if (select_add_time != null) + { + yearLst.Clear(); + yearLst.Add(select_add_time.Value.Year); + yearLst.Add(select_add_time.Value.AddMonths(-6).Year); + yearLst = yearLst.Distinct().ToList(); + } + foreach (int year in yearLst) + { + string dbName = "kjd"; + if (year >= 2026) + dbName = "kjd_yearly"; + string tableName = dbName + ".third_product_select"; + if (year >= 2026) + tableName += "_" + year; + + sql = "UPDATE " + tableName + " SET"; + sql += " operate_sub_sa_name='" + operate_sub_sa_name + "',"; + sql += " add_sub_sa_time='" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "'"; + sql += " WHERE shop_id in ('" + shop_ids.Replace(",", "','") + "')"; + if (!string.IsNullOrEmpty(status)) + sql += " AND status='" + status + "';"; + + rst = mySql.ExecuteNonQuery(sql); + if (!string.IsNullOrEmpty(mySql.Message)) + { + mySql.Close(); + return "{\"code\":500,\"msg\":\"" + mySql.Message + "\"}"; + } + } + } + else if (!string.IsNullOrEmpty(db_id_infos)) + { + try + { + JArray jArr = JArray.Parse(db_id_infos); + foreach (JObject jObj in jArr) + { + var year = jObj["year"].ParseToInt(); + var dbIds = jObj["db_ids"].ParseToString(); + + string dbName = "kjd"; + if (year >= 2026) + dbName = "kjd_yearly"; + string tableName = dbName + ".third_product_select"; + if (year >= 2026) + tableName += "_" + year; + + sql = "UPDATE " + tableName + " SET"; + sql += " operate_sub_sa_name='" + operate_sub_sa_name + "',"; + sql += " add_sub_sa_time='" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "'"; + sql += " WHERE id IN (" + dbIds + ")"; + if (!string.IsNullOrEmpty(status)) + sql += " AND status='" + status + "';"; + + rst = mySql.ExecuteNonQuery(sql); + if (!string.IsNullOrEmpty(mySql.Message)) + { + mySql.Close(); + return "{\"code\":500,\"msg\":\"" + mySql.Message + "\"}"; + } + } + } + catch (Exception ex) + { + mySql.Close(); + return "{\"code\":50004,\"msg\":\"" + ex.Message + "\"}"; + } + } + mySql.Close(); + return "{\"code\":200,\"msg\":\"success\"}"; + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + public string MdyProductSelectNotes(string inputData, bool isAdmin = false) + { + 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 db_id = RegexUtils.GetStringQuery(ref inputData, "db_id"); + string notes = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "notes")); + string user_notes = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "user_notes")); + string fission_product_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "fission_product_name")); + + if (string.IsNullOrEmpty(user_name)) + { + return "{\"code\":500,\"msg\":\"没有用户名\"}"; + } + + var select_add_time = RegexUtils.GetStringQuery(ref inputData, "select_add_time")?.Replace("'", "\\'").ParseToDateTimeNullable(); + if (select_add_time == null) + { + return "{\"code\":500,\"msg\":\"当前软件版本不支持该操作,请升级软件。\"}"; + } + + string dbName = "kjd"; + if (select_add_time != null && select_add_time.Value.Year >= 2026) + dbName = "kjd_yearly"; + string tableName = dbName + ".third_product_select"; + if (select_add_time != null && select_add_time.Value.Year >= 2026) + tableName += "_" + select_add_time.Value.Year; + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = "update " + tableName + " set"; + if (notes != null) + sql += " notes=@notes,"; + if (user_notes != null) + sql += " user_notes=@user_notes,"; + if (fission_product_name != null) + sql += " fission_product_name=@fission_product_name,"; + sql = sql.TrimEnd(','); + sql += " where id=@id;"; + + List paramLst = new List(); + paramLst.Add(new MySqlParameter() { DbType = DbType.Int64, ParameterName = "@id", Value = db_id, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "@fission_product_name", Value = fission_product_name, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "@user_notes", Value = user_notes, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "@notes", Value = notes, }); + + var rst = mySql.ExecuteNonQuery(sql, paramLst.ToArray()); + mySql.Close(); + if (rst) + { + return "{\"code\":200,\"msg\":\"success\"}"; + } + else + { + return "{\"code\":500,\"msg\":\"更新失败:" + mySql.Message + "\"}"; + } + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + public string GetSelectProdDbIdMapDraftIdList(string inputData, bool isDetail = false) + { + var timeCalc = DateTime.Now; + 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("'", "\\'"); + var password = RegexUtils.GetStringQuery(ref inputData, "password")?.Replace("'", "\\'"); + if (string.IsNullOrEmpty(user_name)) + { + return "{\"code\":50001,\"msg\":\"用户为空\"}"; + } + + var select_db_id = RegexUtils.GetStringQuery(ref inputData, "select_db_id")?.Replace("'", "\\'"); + if (string.IsNullOrEmpty(select_db_id)) + { + return "{\"code\":50002,\"msg\":\"未选择选品数据\"}"; + } + + var select_add_time = RegexUtils.GetStringQuery(ref inputData, "select_add_time")?.Replace("'", "\\'").ParseToDateTimeNullable(); + if (select_add_time == null) + { + return "{\"code\":500,\"msg\":\"当前软件版本不支持该操作,请升级软件。\"}"; + } + + string dbName = "kjd_map"; + if (select_add_time != null && select_add_time.Value.Year >= 2026) + dbName = "kjd_map_yearly"; + string tableName; + if (select_add_time != null && select_add_time.Value.Year >= 2026) // 2026年以后的数据在新表 + tableName = dbName + ".product_select_map_"; + else + tableName = dbName + ".product_third_select_map_"; + + if (select_add_time != null && select_add_time.Value.Year >= 2026) + tableName += select_add_time.Value.Year; + else + { + long l_select_map_table_id = select_db_id.ParseToLong() % 64; + tableName += +l_select_map_table_id; + } + + int page = RegexUtils.GetStringQuery(ref inputData, "page").ParseToInt(); + int page_size = RegexUtils.GetStringQuery(ref inputData, "page_size").ParseToInt(50); + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + + string sql = "SELECT COUNT(id) FROM " + tableName + " WHERE 1=1"; + string where = " AND product_select_db_id=" + select_db_id; + if (select_add_time != null && select_add_time.Value.Year >= 2026) // 2026年以后的数据在新表 + where += " AND select_type='third-party'"; + sql += where; + + var count = mySql.ExecuteRowCount(sql); + + DataTable dt; + if (count == 0) + { + dt = new DataTable(); + } + else + { + sql = "SELECT * FROM " + tableName + " WHERE 1=1"; + //where子句 + sql += where; + sql += " ORDER BY add_time 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\":500,\"msg\":\"" + mySql.Message + "\",\"data\":[],\"count\":" + 0 + "}"; + } + if (dt != null) + { + try + { + List dbIdMapProductIdLst = new List(); + foreach (DataRow row in dt.Rows) + { + DBProdDbIdMapProductIdResultParam dbIdMapProductId = new DBProdDbIdMapProductIdResultParam + { + id = row["id"].ParseToLong(), + product_select_db_id = row["product_select_db_id"].ParseToLong(), + product_id = row["product_id"].ParseToLong(), + shop_id = row["shop_id"].ParseToLong(), + add_time = Convert.ToDateTime(row["add_time"]), + }; + dbIdMapProductIdLst.Add(dbIdMapProductId); + } + var data = JsonUtils.SerializeObjectToString(dbIdMapProductIdLst); + 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 + "}"; + } + } + return "{\"code\":500,\"msg\":\"查询结果为空!\",\"data\":[],\"count\":" + 0 + "}"; + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + } +} + + + + diff --git a/StoreHub.KJDWebService/Services/ServiceBase.cs b/StoreHub.KJDWebService/Services/ServiceBase.cs new file mode 100644 index 0000000..45c4978 --- /dev/null +++ b/StoreHub.KJDWebService/Services/ServiceBase.cs @@ -0,0 +1,40 @@ +using FreeSql; +using MAX.Core.DependencyInjection; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using StoreHub.Framework.Repositorys; +using StoreHub.KJDWebService.Commons; + +namespace StoreHub.KJDWebService.Services +{ + /// + /// 迁移服务基类:注入 SqlRepository(提供 KJDDB IAdo)与 IConfiguration。 + /// 提供 MySql(connKey[, isUseTrans]) 创建与旧 MysqlUtils 兼容的执行器(内部参数化执行)。 + /// + public abstract class ServiceBase : ITransientDependency + { + protected readonly SqlRepository _sqlRepository; + protected readonly IConfiguration _configuration; + + protected ServiceBase(SqlRepository sqlRepository, IConfiguration configuration) + { + _sqlRepository = sqlRepository; + _configuration = configuration; + } + + /// KJDDB 的 IAdo(等效旧 ConnKJD) + protected IAdo Ado => _sqlRepository.Ado; + + /// 创建 MysqlUtils(等效旧 new MysqlUtils(conn[, isUseTrans])) + protected MysqlUtils MySql(string connKey, bool isUseTrans = false) + { + return new MysqlUtils(AdoProvider.Get(connKey), isUseTrans); + } + + /// 读取配置(旧 ConfigurationManager.ConnectionStrings["key"].ConnectionString) + protected string Config(string key) + { + return KJDConfig.Get(key); + } + } +} diff --git a/StoreHub.KJDWebService/Services/ShopService.cs b/StoreHub.KJDWebService/Services/ShopService.cs new file mode 100644 index 0000000..5479bf0 --- /dev/null +++ b/StoreHub.KJDWebService/Services/ShopService.cs @@ -0,0 +1,1129 @@ +using StoreHub.KJDWebService.Models; +using StoreHub.Framework.Repositorys; +using Microsoft.Extensions.Configuration; +using StoreHub.KJDWebService.Models.ShopModel; +using StoreHub.KJDWebService.Commons; +using NaiBa.Util.Extension; +using System; +using System.Collections.Generic; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; + +namespace StoreHub.KJDWebService.Services +{ + public class ShopService : ServiceBase + { + public ShopService(SqlRepository sqlRepository, IConfiguration configuration) : base(sqlRepository, configuration) + { + } + public string GetShop(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("'", "\\'"); + 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 = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + + string sql = "SELECT COUNT(s.id) FROM kjd.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.*, c.add_product_remaining add_remaining, c.add_product_month add_month, cc.jit_expire_time FROM kjd.shop s" + + /*, u.sub_nick_name*/ + //" LEFT JOIN (SELECT parent_user_name, GROUP_CONCAT(nick_name) as sub_nick_name FROM kjd.user WHERE user_name in(s.sub_user_name) GROUP BY parent_user_name) u ON s.shop_id=u.parent_user_name" + + " LEFT JOIN kjd.shop_add_prod_count c ON s.shop_id=c.shop_id" + + " LEFT JOIN (SELECT shop_id, MAX(expire_time) as jit_expire_time FROM kjd.jit_card_code GROUP BY shop_id) cc ON s.shop_id=cc.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(), + shop_id = row["shop_id"].ToString(), + shop_account = row["shop_account"].ToString(), + sub_user_name = row["sub_user_name"].ToString(), + //sub_nick_name = row["sub_nick_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 = Math.Max(0, row["add_remaining"].ParseToInt()), + add_product_month = row["add_month"].ParseToInt(), + operate_sub_sa_name = row["operate_sub_sa_name"].ParseToString(), + ad_cookie = row["ad_cookie"].ParseToString(), + ad_login_status = row["ad_login_status"].ParseToString(), + ad_seller_unique_id = row["ad_seller_unique_id"].ParseToString(), + ad_url = row["ad_url"].ParseToString(), + jit_expire_time = row["jit_expire_time"].IsNullOrEmpty() ? new DateTime?() : Convert.ToDateTime(row["jit_expire_time"]), + }; + shopList.Add(shop); + } + + //sql = "\r\nINSERT INTO kjd.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 kjd.shop set add_product_remaining=" + remainCount + ", add_product_month=" + month + + " where 1=1 and id in (" + ids + ");"; + + sql += "\r\nINSERT INTO kjd.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 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 = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + + string sql = "SELECT COUNT(s.id) FROM kjd.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 kjd.product_select WHERE operate_sub_sa_name='" + operate_sub_sa_name + "') or " + + "s.shop_id in (SELECT DISTINCT shop_id From kjd.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.*,c.add_product_remaining add_remaining,c.add_product_month add_month FROM kjd.shop s LEFT JOIN kjd.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(), + 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 = Math.Max(0, row["add_remaining"].ParseToInt()), + add_product_month = row["add_month"].ParseToInt(), + operate_sub_sa_name = row["operate_sub_sa_name"].ParseToString(), + ad_cookie = row["ad_cookie"].ParseToString(), + ad_login_status = row["ad_login_status"].ParseToString(), + ad_seller_unique_id = row["ad_seller_unique_id"].ParseToString(), + ad_url = row["ad_url"].ParseToString(), + }; + shopList.Add(shop); + } + + //sql = "\r\nINSERT INTO kjd.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 kjd.shop set add_product_remaining=" + remainCount + ", add_product_month=" + month + + " where 1=1 and id in (" + ids + ");"; + + sql += "\r\nINSERT INTO kjd.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 = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = ""; + sql += "update kjd.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 = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = "select id,login_name,login_pass,cookie,cookie2,shop_id,shop_account,sub_user_name,user_name from kjd.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(), + 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(), + }; + 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 = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = "select id,login_name,login_pass,cookie,cookie2,shop_id,shop_account,sub_user_name,user_name from kjd.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(), + 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(), + }; + shopList.Add(shop); + } + var data = JsonUtils.SerializeObjectToString(shopList); + return "{\"code\":200,\"msg\":\"success\",\"data\":" + data + ",\"c\":\"" + EncrypUtil.Encryption(r2) + "\"}"; + } + } + 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 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 = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = ""; + if (string.IsNullOrEmpty(shop_id)) + sql = "select exists (select 1 from kjd.shop where login_name='" + login_name + "' and user_name='" + user_name + "')"; + else + sql = "select exists (select 1 from kjd.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 kjd.shop (login_name,login_pass,cookie,cookie2,shop_account,shop_id,sub_user_name,user_name,group_name,notes,add_time,mdy_time) " + + "values ('" + login_name + "','" + login_pass + "','" + cookie + "','" + cookie2 + "','" + 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 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 = 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 = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = "update kjd.shop set"; + if (login_pass != null) + sql += " login_pass='" + login_pass + "',"; + if (cookie != null) + sql += " cookie='" + cookie + "',"; + if (cookie2 != null) + sql += " cookie2='" + cookie2 + "',"; + 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")); + + int r2 = 0; + int.TryParse(RegexUtils.GetStringQuery(ref inputData, "r2"), out r2); + + if (string.IsNullOrEmpty(login_name)) + { + return "{\"code\":500,\"msg\":\"店铺没有登录名\"}"; + } + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = "update kjd.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 + "',"; + 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 MdyAdsCookieAndLoginStatus(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + string shop_id = RegexUtils.GetStringQuery(ref inputData, "shop_id"); + string ad_url = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "ad_url")); + string ad_seller_unique_id = RegexUtils.GetStringQuery(ref inputData, "ad_seller_unique_id"); + string ad_login_status = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "ad_login_status")); + string ad_cookie = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "ad_cookie")); + + int r2 = 0; + int.TryParse(RegexUtils.GetStringQuery(ref inputData, "r2"), out r2); + + if (string.IsNullOrEmpty(shop_id)) + { + return "{\"code\":500,\"msg\":\"店铺没有登录名\"}"; + } + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = "update kjd.shop set"; + if (ad_url != null) + sql += " ad_url='" + ad_url + "',"; + if (ad_seller_unique_id != null) + sql += " ad_seller_unique_id='" + ad_seller_unique_id + "',"; + if (ad_login_status != null) + sql += " ad_login_status='" + ad_login_status + "',"; + if (ad_cookie != null) + sql += " ad_cookie='" + ad_cookie + "',"; + sql = sql.TrimEnd(','); + sql += " where shop_id='" + shop_id + "'"; + + 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 = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = "delete from kjd.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 = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = "update kjd.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 GetShopCardCodeList(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + var user_name = RegexUtils.GetStringQuery(ref inputData, "user_name"); + var password = RegexUtils.GetStringQuery(ref inputData, "password"); + var search_card_code_id = RegexUtils.GetStringQuery(ref inputData, "search_card_code_id"); + var search_shop_id = RegexUtils.GetStringQuery(ref inputData, "search_shop_id"); + var search_shop_name = RegexUtils.GetStringQuery(ref inputData, "search_shop_name"); + var search_notes = RegexUtils.GetStringQuery(ref inputData, "search_notes"); + var card_code_ids = RegexUtils.GetStringQuery(ref inputData, "card_code_ids")?.Replace("'", ""); + var sort_field = RegexUtils.GetStringQuery(ref inputData, "sort_field")?.Replace("'", ""); + if (!string.IsNullOrWhiteSpace(card_code_ids)) + { + List shopIdLst = card_code_ids.Split(',').ToList(); + card_code_ids = "'" + string.Join("','", shopIdLst) + "'"; + } + 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 list_notes = RegexUtils.GetStringQuery(ref inputData, "list_notes"); + if (!string.IsNullOrWhiteSpace(list_notes)) + { + List notesLst = list_notes.Split(',').ToList(); + list_notes = "'" + string.Join("','", notesLst) + "'"; + } + + 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 = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + + string sql = "SELECT COUNT(s.id) FROM kjd.jit_card_code s WHERE 1=1"; + + //where子句 + string where = ""; + if (!string.IsNullOrWhiteSpace(search_card_code_id)) + where += " and s.card_code_id like '%" + search_card_code_id + "%'"; + if (!string.IsNullOrWhiteSpace(search_shop_id)) + where += " and s.shop_id like '%" + search_shop_id + "%'"; + if (!string.IsNullOrWhiteSpace(search_shop_name)) + where += " and s.shop_account like '%" + search_shop_name + "%'"; + if (!string.IsNullOrWhiteSpace(search_notes)) + where += " and s.notes like '%" + search_notes + "%'"; + if (!string.IsNullOrWhiteSpace(card_code_ids)) + where += " and s.card_code_id in (" + card_code_ids + ")"; + 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(list_notes)) + where += " and s.notes in (" + list_notes + ")"; + sql += where; + + var count = mySql.ExecuteRowCount(sql); + + DataTable dt; + if (count == 0) + { + dt = new DataTable(); + } + else + { + sql = "SELECT s.* FROM kjd.jit_card_code s WHERE 1=1"; + + sql += where; // where 子句 + + // 排序 + if (sort_field == "expire_time") + sql += " ORDER BY s.expire_time DESC"; + else + 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 cardCodeList = new List(); + foreach (DataRow row in dt.Rows) + { + JitCardCodeParam cardCode = new JitCardCodeParam + { + id = Convert.ToInt32(row["id"]), + shop_id = row["shop_id"].ToString(), + shop_account = row["shop_account"].ToString(), + add_time = (DateTime)row["add_time"], + active_time = row["active_time"].IsNullOrEmpty() ? new DateTime?() : Convert.ToDateTime(row["active_time"]), + expire_time = row["expire_time"].IsNullOrEmpty() ? new DateTime?() : Convert.ToDateTime(row["expire_time"]), + card_code_id = row["card_code_id"].ToString(), + notes = row["notes"].ToString(), + }; + cardCodeList.Add(cardCode); + } + var data = JsonUtils.SerializeObjectToString(cardCodeList); + + + return "{\"code\":200,\"msg\":\"success\",\"data\":" + data + ",\"count\":" + count + "}"; + } + } + return "{\"code\":19999,\"msg\":\"未知错误\"}"; + } + + public string CreateShopCardCode(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 create_count = RegexUtils.GetStringQuery(ref inputData, "create_count")?.Replace("'", "\\'"); + + if (string.IsNullOrEmpty(create_count)) + { + return "{\"code\":50002,\"msg\":\"未选择生成数量\"}"; + } + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = "insert into kjd.jit_card_code (card_code_id) values "; + Random random = new Random(Guid.NewGuid().GetHashCode()); + for (int i = 0; i < create_count.ParseToInt(); i++) + { + sql += "('" + GenerateCardCode(random, 16) + "'),"; + } + sql = sql.TrimEnd(',') + ";"; + 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 DelShopCardCode(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 del_ids = RegexUtils.GetStringQuery(ref inputData, "del_ids")?.Replace("'", "\\'"); + + if (string.IsNullOrEmpty(del_ids)) + { + return "{\"code\":50002,\"msg\":\"未选择删除数据\"}"; + } + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = "delete from kjd.jit_card_code where id in (" + del_ids + ");"; + 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 ActiveJitCardCode(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 shop_id = RegexUtils.GetStringQuery(ref inputData, "shop_id")?.Replace("'", "\\'"); + var card_code_id = RegexUtils.GetStringQuery(ref inputData, "card_code_id")?.Replace("'", "\\'"); + var shop_account = RegexUtils.GetStringQuery(ref inputData, "shop_account")?.Replace("'", "\\'"); + if (string.IsNullOrEmpty(shop_id)) + { + return "{\"code\":50002,\"msg\":\"未输入店铺\"}"; + } + if (string.IsNullOrEmpty(card_code_id)) + { + return "{\"code\":50002,\"msg\":\"未输入卡密\"}"; + } + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = "select card_code_id from kjd.jit_card_code where card_code_id = \'" + card_code_id + "\' and active_time is null;"; + var rst = mySql.ExecuteExists(sql); + if (!rst) + { + mySql.Close(); + if (string.IsNullOrEmpty(mySql.Message)) + { + return "{\"code\":500,\"msg\":\"JIT卡密不存在或已激活\"}"; + } + else + { + return "{\"code\":500,\"msg\":\"" + mySql.Message + "\"}"; + } + } + sql = "select s.shop_id,cc.jit_expire_time from kjd.shop s" + + " LEFT JOIN (SELECT shop_id, MAX(expire_time) as jit_expire_time FROM kjd.jit_card_code GROUP BY shop_id) cc ON s.shop_id=cc.shop_id" + + " where s.shop_id = '" + shop_id + "';"; + var dt = mySql.ExecuteDataTable(sql); + if (dt == null || !mySql.Message.IsNullOrEmpty()) + { + mySql.Close(); + return "{\"code\":500,\"msg\":\"" + mySql.Message + "\"}"; + } + else if (dt.Rows.Count == 0) + { + mySql.Close(); + return "{\"code\":500,\"msg\":\"店铺不存在\"}"; + } + + var row = dt.Rows[0]; + ShopParam shop = new ShopParam + { + shop_id = row["shop_id"].ToString(), + jit_expire_time = row["jit_expire_time"].IsNullOrEmpty() ? new DateTime?() : Convert.ToDateTime(row["jit_expire_time"]), + }; + DateTime activeTime = DateTime.Now; + DateTime expireTime = DateTime.Now.Date.AddMonths(1); + if (shop.jit_expire_time != null && shop.jit_expire_time.Value.Date > DateTime.Now.Date) + expireTime = shop.jit_expire_time.Value.Date.AddMonths(1); + shop.jit_expire_time = expireTime; + + sql = "update kjd.jit_card_code set active_time='" + activeTime.ToString("yyyy/MM/dd HH:mm:ss") + "'," + + "expire_time='" + expireTime.ToString("yyyy/MM/dd HH:mm:ss") + "'," + + "shop_id='" + shop_id + "',shop_account='" + shop_account + "'" + + " where card_code_id='" + card_code_id + "';"; + rst = mySql.ExecuteNonQuery(sql); + + mySql.Close(); + if (rst) + { + return "{\"code\":200,\"expire_time\":\"" + expireTime + "\",\"msg\":\"success\"}"; + } + else + { + return "{\"code\":500,\"msg\":\"" + mySql.Message + "\"}"; + } + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + private static readonly char[] chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789".ToCharArray(); // 增加特殊字符 + + public static string GenerateCardCode(Random random, int length) + { + StringBuilder result = new StringBuilder(length); + for (int i = 0; i < length; i++) + { + result.Append(chars[random.Next(chars.Length)]); + } + return result.ToString(); + } + } +} + + + + diff --git a/StoreHub.KJDWebService/Services/ToolService.cs b/StoreHub.KJDWebService/Services/ToolService.cs new file mode 100644 index 0000000..2b9d153 --- /dev/null +++ b/StoreHub.KJDWebService/Services/ToolService.cs @@ -0,0 +1,232 @@ +using StoreHub.KJDWebService.Commons; +using StoreHub.Framework.Repositorys; +using Microsoft.Extensions.Configuration; +using NaiBa.Util.Extension; +using System; +using System.Collections.Generic; +using System.Linq; + +namespace StoreHub.KJDWebService.Services +{ + public class ToolService : ServiceBase + { + public ToolService(SqlRepository sqlRepository, IConfiguration configuration) : base(sqlRepository, configuration) + { + } + //mysql workbench 存储过程,可以使用分隔符重定义 + // string 存储过程1 = @" + //DELIMITER $ + //DROP PROCEDURE IF EXISTS add_spu_map; + //CREATE PROCEDURE add_spu_map() + //BEGIN + //insert into kjd_map.spu_map_0 (draft_id,from_spu_id,shop_id) values(9122600878,727585921,'3049342434562'); + //update kjd.third_product_select set draft_id='9122600878', status='已上传', add_times=add_times+1, mdy_time='2025-08-06 11:54:50' where id=6532; + //END $ + //DELIMITER ; + //CALL add_spu_map();"; + + //腾讯云服务器存储过程,不能使用分隔符重定义 + // string 存储过程2 = @" + //DROP PROCEDURE IF EXISTS add_spu_map; + //CREATE PROCEDURE add_spu_map() + //BEGIN + //insert into kjd_map.spu_map_1 (draft_id,from_spu_id,shop_id) values(9122600878,727585921,'3049342434562'); + //update kjd.third_product_select set draft_id='9122600878', status='已上传', add_times=add_times+1, mdy_time='2025-08-06 11:54:50' where id=6532; + //END ; + //CALL add_spu_map();"; + + public void CreateTable() + { + //string conn = "ConnKJD"; + //MysqlUtils mySql = new MysqlUtils(conn); + //string sql = ""; + //for (int i = 0; i < 128; i++) + //{ + // sql = @"drop table if exists bxx_relation.out_prod_relation_" + i.ParseToString().PadLeft(4, '0') + ";\r\n"; + // sql += @"CREATE TABLE bxx_relation.out_prod_relation_" + i.ParseToString().PadLeft(4, '0') + @" ( + // `id` int NOT NULL AUTO_INCREMENT, + // `up_spu_id` varchar(50) NOT NULL COMMENT '源商品id信息,此字段为分表依据', + // `up_goods_name` varchar(255) NOT NULL COMMENT '源商品标题', + // `from_site` varchar(10) NOT NULL COMMENT '商品来源平台如pdd,tb,1688,vd(微店)等', + // `goods_id` varchar(50) NOT NULL COMMENT '映射商品id信息', + // `shop_id` varchar(50) NOT NULL COMMENT '上传到的店铺id', + // `price_min` int NOT NULL COMMENT '最低价,单位分', + // `price_max` int NOT NULL COMMENT '最高价,单位分', + // `add_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, + // PRIMARY KEY(`id`), + // KEY `index_add_time` (`add_time`) USING BTREE, + // KEY `index_up_spu_id` (`up_spu_id`) USING BTREE, + // KEY `index_shop_id` (`shop_id`) USING BTREE, + // KEY `index_price_min` (`price_min`) USING BTREE, + // KEY `index_price_max` (`price_max`) USING BTREE + // ) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '记录拼多多关联数据信息'"; + // var rst = mySql.ExecuteNonQuery(sql); + //} + //mySql.Close(); + + + //string conn = "ConnKJD"; + //MysqlUtils mySql = new MysqlUtils(conn); + //string sql = ""; + //for (int i = 0; i < 1024; i++) + //{ + // sql = @"drop table if exists wxxd_product_up_map.product_up_map_" + i.ParseToString().PadLeft(4, '0') + ";\r\n"; + // sql += @" + //CREATE TABLE wxxd_product_up_map.product_up_map_" + i.ParseToString().PadLeft(4, '0') + @" ( + // `id` int NOT NULL AUTO_INCREMENT, + // `up_secret_spu_id` varchar(50) NOT NULL COMMENT '加密源商品id信息,此字段为分表依据,对应商品货号字段', + // `up_spu_id` varchar(50) NOT NULL COMMENT '源商品id信息', + // `shop_id` varchar(50) NOT NULL COMMENT '上传到的店铺id', + // `price_min` int NOT NULL COMMENT '最低价', + // `price_max` int NOT NULL COMMENT '最高价', + // `add_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, + // PRIMARY KEY(`id`), + // KEY `index_add_time` (`add_time`) USING BTREE, + // KEY `index_up_secret_spu_id_shop_id` (`up_secret_spu_id`, `shop_id`) USING BTREE + //) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '记录微信商品上传到哪些店铺的信息'"; + // var rst = mySql.ExecuteNonQuery(sql); + //} + //mySql.Close(); + + + // string conn = "ConnKJD"; + // MysqlUtils mySql = new MysqlUtils(conn); + // string sql = ""; + // string sql1 = ""; + // for (int i = 0; i < 64; i++) + // { + // //sql = @"drop table if exists kjd_map.spu_map_" + i + ";\r\n"; + // sql = @"CREATE TABLE IF NOT EXISTS kjd_map.jit_product_select_map_" + i + @" ( + // `id` int NOT NULL AUTO_INCREMENT, + // `product_id` bigint NOT NULL COMMENT '草稿箱/商品Id', + // `product_select_db_id` bigint NOT NULL COMMENT '选品上传数据库Id', + // `shop_id` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '上传的店铺', + // PRIMARY KEY (`id`) + //) ENGINE = InnoDB AUTO_INCREMENT = 1 DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '上传商品kjd库Id与商品DraftId映射关系';"; + + // sql += @" + //ALTER TABLE + // kjd_map.jit_product_select_map_" + i + @" + //ADD + // COLUMN `add_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP"; + // var rst = mySql.ExecuteNonQuery(sql); + // } + // mySql.Close(); + + + + // string conn = "ConnKJD"; + // MysqlUtils mySql = new MysqlUtils(conn); + // string sql = ""; + // for (int i = 0; i < 128; i++) + // { + // //sql = @"drop table if exists kjd_map.spu_map_" + i + ";\r\n"; + // sql = @"CREATE TABLE IF NOT EXISTS kjd_order.order_code_" + i + @" ( + // `id` int unsigned NOT NULL AUTO_INCREMENT, + // `supplierId` varchar(25) COLLATE utf8mb4_general_ci NOT NULL, + // `subPurchaseOrderSn` varchar(25) COLLATE utf8mb4_general_ci DEFAULT NULL, + // `jiaTongCode` varchar(50) COLLATE utf8mb4_general_ci DEFAULT NULL, + // `barCodeMd5` varchar(32) COLLATE utf8mb4_general_ci DEFAULT NULL, + // `barCodeBase64` longtext COLLATE utf8mb4_general_ci, + // `shippingMark​Md5` varchar(32) COLLATE utf8mb4_general_ci DEFAULT NULL, + // `shippingMarkBase64` longtext COLLATE utf8mb4_general_ci, + // `add_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, + // `mdy_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + // PRIMARY KEY (`id`), + // UNIQUE KEY `index_subPurchaseOrderSn` (`subPurchaseOrderSn`) USING BTREE + //) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_general_ci"; + // sql = "ALTER TABLE\r\n kjd_order.order_code_" + i + "\r\nMODIFY\r\n COLUMN `jiaTongCode` varchar (50) NULL COMMENT '佳同码'\r\nAFTER\r\n `subPurchaseOrderSn`"; + // var rst = mySql.ExecuteNonQuery(sql); + // } + // mySql.Close(); + + + + //string conn = "ConnKJD"; + //MysqlUtils mySql = new MysqlUtils(conn); + //string sql = ""; + // for (int i = 1; i <= 12; i++) + // { + + // //sql = @"drop table if exists kjd_order.order_code_" + i + ";\r\n"; + // sql = @"CREATE TABLE IF NOT EXISTS kjd_order.order_2026" + i.ToString("D2") + @" ( + // `id` int NOT NULL AUTO_INCREMENT, + // `supplierId` varchar(25) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '店铺Id', + // `supplierName` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '店铺名称', + // `originalPurchaseOrderSn` varchar(25) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '备母货单号', + // `subPurchaseOrderSn` varchar(25) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '备货单号', + // `productName` varchar(1000) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL, + // `category` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL, + // `productId` varchar(25) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '商品编号', + // `upProductId` varchar(25) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '上家编号', + // `productSkcId` varchar(25) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL, + // `productSkcPicture` varchar(250) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '主图', + // `productSn` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '货号', + // `status` int NOT NULL COMMENT '状态 1待发货 2已送货 7已入库 8已作废', + // `productSkuId` varchar(25) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL, + // `extCode` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT 'sku货号', + // `className` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT 'sku规格', + // `currencyType` varchar(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL, + // `supplierPrice` int NOT NULL COMMENT '申报价格', + // `costPrice` int DEFAULT NULL COMMENT '成本价', + // `deliveryFee` int DEFAULT NULL COMMENT '车队费', + // `markFee` int DEFAULT NULL COMMENT '贴标费', + // `purchaseQuantity` int NOT NULL COMMENT '备货件数', + // `deliverQuantity` int NOT NULL COMMENT '送货件数', + // `realReceiveAuthenticQuantity` int NOT NULL COMMENT '入库件数', + // `availableSaleDays` decimal(10, 0) DEFAULT NULL COMMENT '可售天数', + // `qcResult` int DEFAULT NULL COMMENT '抽检结果 1合格 2不合格', + // `thumbUrlList` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT 'sku图片', + // `purchaseTime` bigint NOT NULL COMMENT '备货单创建时间', + // `deliverTime` bigint DEFAULT NULL COMMENT '发货时间', + // `receiveTime` bigint DEFAULT NULL COMMENT '收货时间', + // `expectLatestDeliverTimeOrDefault` bigint NOT NULL COMMENT '最迟发货时间', + // `expectLatestArrivalTimeOrDefault` bigint NOT NULL COMMENT '最迟到货时间', + // `deliveryOrderSn` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '发货单号', + // `receiveWarehouseId` varchar(25) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '实际收货仓库Id', + // `receiveWarehouseName` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '实际收货仓库', + // `warehouseGroupId` varchar(25) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '仓组Id', + // `jiaTongCode` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '佳同码', + // `barCodeMd5` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '商品条码MD5', + // `shippingMarkMd5` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '箱唛文件MD5', + // `notes` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '备注', + // `upLoadStatus` int NOT NULL DEFAULT '0' COMMENT '是否上传订单(上传后扣除用户授权金额,产生扣费记录)', + // `add_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, + // `mdy_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + // PRIMARY KEY (`id`), + // UNIQUE KEY `index_subPurchaseOrderSn` (`subPurchaseOrderSn`) USING BTREE + //) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '订单推送表'"; + + // //sql = @"drop table if exists kjd_order.order_code_" + i + ";\r\n"; + // sql = @"CREATE TABLE IF NOT EXISTS kjd_order.order_code_2026" + i.ToString("D2") + @" ( + // `id` int unsigned NOT NULL AUTO_INCREMENT, + // `supplierId` varchar(25) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL, + // `fileCodeMd5` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL, + // `fileCodeBase64` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL, + // `add_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, + // `mdy_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + // PRIMARY KEY (`id`), + // UNIQUE KEY `index_fileCodeMd5` (`fileCodeMd5`) USING BTREE + //) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_general_ci"; + + // // sql = "ALTER TABLE\r\n kjd_order.order_" + i + "\r\nADD\r\n COLUMN `upLoadStatus` int NOT NULL DEFAULT 0 COMMENT '是否上传订单(上传后扣除用户授权金额,产生扣费记录)',\r\nMODIFY\r\n COLUMN `add_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP\r\nAFTER\r\n `upLoadStatus`,\r\nMODIFY\r\n COLUMN `mdy_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP\r\nAFTER\r\n `add_time`"; + // // sql = "ALTER TABLE\r\n kjd_order.order_" + i + "\r\nADD\r\n COLUMN `extCode` varchar (50) NOT NULL COMMENT 'sku货号',\r\nMODIFY\r\n COLUMN `className` varchar (100) NOT NULL COMMENT 'sku规格'\r\nAFTER\r\n `extCode`,\r\nMODIFY\r\n COLUMN `currencyType` varchar (10) NOT NULL\r\nAFTER\r\n `className`,\r\nMODIFY\r\n COLUMN `supplierPrice` int NOT NULL COMMENT '申报价格'\r\nAFTER\r\n `currencyType`,\r\nMODIFY\r\n COLUMN `purchaseQuantity` int NOT NULL COMMENT '备货件数'\r\nAFTER\r\n `supplierPrice`,\r\nMODIFY\r\n COLUMN `deliverQuantity` int NOT NULL COMMENT '送货件数'\r\nAFTER\r\n `purchaseQuantity`,\r\nMODIFY\r\n COLUMN `realReceiveAuthenticQuantity` int NOT NULL COMMENT '入库件数'\r\nAFTER\r\n `deliverQuantity`,\r\nMODIFY\r\n COLUMN `availableSaleDays` decimal (10, 0) NOT NULL COMMENT '可售天数'\r\nAFTER\r\n `realReceiveAuthenticQuantity`,\r\nMODIFY\r\n COLUMN `qcResult` int NULL COMMENT '抽检结果 1合格 2不合格'\r\nAFTER\r\n `availableSaleDays`,\r\nMODIFY\r\n COLUMN `thumbUrlList` varchar (500) NULL COMMENT 'sku图片'\r\nAFTER\r\n `qcResult`,\r\nMODIFY\r\n COLUMN `purchaseTime` bigint NOT NULL COMMENT '备货单创建时间'\r\nAFTER\r\n `thumbUrlList`,\r\nMODIFY\r\n COLUMN `deliverTime` bigint NULL COMMENT '发货时间'\r\nAFTER\r\n `purchaseTime`,\r\nMODIFY\r\n COLUMN `receiveTime` bigint NULL COMMENT '收货时间'\r\nAFTER\r\n `deliverTime`,\r\nMODIFY\r\n COLUMN `expectLatestDeliverTimeOrDefault` bigint NOT NULL COMMENT '最迟发货时间'\r\nAFTER\r\n `receiveTime`,\r\nMODIFY\r\n COLUMN `expectLatestArrivalTimeOrDefault` bigint NOT NULL COMMENT '最迟到货时间'\r\nAFTER\r\n `expectLatestDeliverTimeOrDefault`,\r\nMODIFY\r\n COLUMN `deliveryOrderSn` varchar (50) NULL COMMENT '发货单号'\r\nAFTER\r\n `expectLatestArrivalTimeOrDefault`,\r\nMODIFY\r\n COLUMN `receiveWarehouseId` varchar (25) NULL COMMENT '实际收货仓库Id'\r\nAFTER\r\n `deliveryOrderSn`,\r\nMODIFY\r\n COLUMN `receiveWarehouseName` varchar (50) NULL COMMENT '实际收货仓库'\r\nAFTER\r\n `receiveWarehouseId`,\r\nMODIFY\r\n COLUMN `warehouseGroupId` varchar (25) NULL COMMENT '仓组Id'\r\nAFTER\r\n `receiveWarehouseName`,\r\nMODIFY\r\n COLUMN `jiaTongCode` varchar (50) NULL COMMENT '佳同码'\r\nAFTER\r\n `warehouseGroupId`,\r\nMODIFY\r\n COLUMN `barCodeMd5` varchar (32) NULL COMMENT '商品条码MD5'\r\nAFTER\r\n `jiaTongCode`,\r\nMODIFY\r\n COLUMN `shippingMark​Md5` varchar (32) NULL COMMENT '箱唛文件MD5'\r\nAFTER\r\n `barCodeMd5`,\r\nMODIFY\r\n COLUMN `notes` varchar (50) NULL COMMENT '备注'\r\nAFTER\r\n `shippingMark​Md5`,\r\nMODIFY\r\n COLUMN `add_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP\r\nAFTER\r\n `notes`,\r\nMODIFY\r\n COLUMN `mdy_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP\r\nAFTER\r\n `add_time`"; + // // sql = "ALTER TABLE\r\n kjd_order.order_" + i + "\r\nMODIFY\r\n COLUMN `extCode` varchar (50) NOT NULL COMMENT 'sku货号'\r\nAFTER\r\n `productSkuId`,\r\nMODIFY\r\n COLUMN `className` varchar (100) NOT NULL COMMENT 'sku规格'\r\nAFTER\r\n `extCode`,\r\nMODIFY\r\n COLUMN `currencyType` varchar (10) NOT NULL\r\nAFTER\r\n `className`,\r\nMODIFY\r\n COLUMN `supplierPrice` int NOT NULL COMMENT '申报价格'\r\nAFTER\r\n `currencyType`,\r\nMODIFY\r\n COLUMN `purchaseQuantity` int NOT NULL COMMENT '备货件数'\r\nAFTER\r\n `supplierPrice`,\r\nMODIFY\r\n COLUMN `deliverQuantity` int NOT NULL COMMENT '送货件数'\r\nAFTER\r\n `purchaseQuantity`,\r\nMODIFY\r\n COLUMN `realReceiveAuthenticQuantity` int NOT NULL COMMENT '入库件数'\r\nAFTER\r\n `deliverQuantity`,\r\nMODIFY\r\n COLUMN `availableSaleDays` decimal (10, 0) NOT NULL COMMENT '可售天数'\r\nAFTER\r\n `realReceiveAuthenticQuantity`,\r\nMODIFY\r\n COLUMN `qcResult` int NULL COMMENT '抽检结果 1合格 2不合格'\r\nAFTER\r\n `availableSaleDays`,\r\nMODIFY\r\n COLUMN `thumbUrlList` varchar (500) NULL COMMENT 'sku图片'\r\nAFTER\r\n `qcResult`,\r\nMODIFY\r\n COLUMN `purchaseTime` bigint NOT NULL COMMENT '备货单创建时间'\r\nAFTER\r\n `thumbUrlList`,\r\nMODIFY\r\n COLUMN `deliverTime` bigint NULL COMMENT '发货时间'\r\nAFTER\r\n `purchaseTime`,\r\nMODIFY\r\n COLUMN `receiveTime` bigint NULL COMMENT '收货时间'\r\nAFTER\r\n `deliverTime`,\r\nMODIFY\r\n COLUMN `expectLatestDeliverTimeOrDefault` bigint NOT NULL COMMENT '最迟发货时间'\r\nAFTER\r\n `receiveTime`,\r\nMODIFY\r\n COLUMN `expectLatestArrivalTimeOrDefault` bigint NOT NULL COMMENT '最迟到货时间'\r\nAFTER\r\n `expectLatestDeliverTimeOrDefault`,\r\nMODIFY\r\n COLUMN `deliveryOrderSn` varchar (50) NULL COMMENT '发货单号'\r\nAFTER\r\n `expectLatestArrivalTimeOrDefault`,\r\nMODIFY\r\n COLUMN `receiveWarehouseId` varchar (25) NULL COMMENT '实际收货仓库Id'\r\nAFTER\r\n `deliveryOrderSn`,\r\nMODIFY\r\n COLUMN `receiveWarehouseName` varchar (50) NULL COMMENT '实际收货仓库'\r\nAFTER\r\n `receiveWarehouseId`,\r\nMODIFY\r\n COLUMN `warehouseGroupId` varchar (25) NULL COMMENT '仓组Id'\r\nAFTER\r\n `receiveWarehouseName`,\r\nMODIFY\r\n COLUMN `jiaTongCode` varchar (50) NULL COMMENT '佳同码'\r\nAFTER\r\n `warehouseGroupId`,\r\nMODIFY\r\n COLUMN `barCodeMd5` varchar (32) NULL COMMENT '商品条码MD5'\r\nAFTER\r\n `jiaTongCode`,\r\nMODIFY\r\n COLUMN `shippingMark​Md5` varchar (32) NULL COMMENT '箱唛文件MD5'\r\nAFTER\r\n `barCodeMd5`,\r\nMODIFY\r\n COLUMN `notes` varchar (50) NULL COMMENT '备注'\r\nAFTER\r\n `shippingMark​Md5`,\r\nMODIFY\r\n COLUMN `upLoadStatus` int NOT NULL DEFAULT '0' COMMENT '是否上传订单(上传后扣除用户授权金额,产生扣费记录)'\r\nAFTER\r\n `notes`"; + // // sql = "ALTER TABLE\r\n kjd_order.order_" + i + "\r\nADD\r\n COLUMN `costPrice` int NULL COMMENT '成本价',\r\nADD\r\n COLUMN `deliveryFee` int NULL COMMENT '车队费',\r\nADD\r\n COLUMN `markFee` int NULL COMMENT '贴标费',\r\nMODIFY\r\n COLUMN `purchaseQuantity` int NOT NULL COMMENT '备货件数'\r\nAFTER\r\n `markFee`,\r\nMODIFY\r\n COLUMN `deliverQuantity` int NOT NULL COMMENT '送货件数'\r\nAFTER\r\n `purchaseQuantity`,\r\nMODIFY\r\n COLUMN `realReceiveAuthenticQuantity` int NOT NULL COMMENT '入库件数'\r\nAFTER\r\n `deliverQuantity`,\r\nMODIFY\r\n COLUMN `availableSaleDays` decimal (10, 0) NOT NULL COMMENT '可售天数'\r\nAFTER\r\n `realReceiveAuthenticQuantity`,\r\nMODIFY\r\n COLUMN `qcResult` int NULL COMMENT '抽检结果 1合格 2不合格'\r\nAFTER\r\n `availableSaleDays`,\r\nMODIFY\r\n COLUMN `thumbUrlList` varchar (500) NULL COMMENT 'sku图片'\r\nAFTER\r\n `qcResult`,\r\nMODIFY\r\n COLUMN `purchaseTime` bigint NOT NULL COMMENT '备货单创建时间'\r\nAFTER\r\n `thumbUrlList`,\r\nMODIFY\r\n COLUMN `deliverTime` bigint NULL COMMENT '发货时间'\r\nAFTER\r\n `purchaseTime`,\r\nMODIFY\r\n COLUMN `receiveTime` bigint NULL COMMENT '收货时间'\r\nAFTER\r\n `deliverTime`,\r\nMODIFY\r\n COLUMN `expectLatestDeliverTimeOrDefault` bigint NOT NULL COMMENT '最迟发货时间'\r\nAFTER\r\n `receiveTime`,\r\nMODIFY\r\n COLUMN `expectLatestArrivalTimeOrDefault` bigint NOT NULL COMMENT '最迟到货时间'\r\nAFTER\r\n `expectLatestDeliverTimeOrDefault`,\r\nMODIFY\r\n COLUMN `deliveryOrderSn` varchar (50) NULL COMMENT '发货单号'\r\nAFTER\r\n `expectLatestArrivalTimeOrDefault`,\r\nMODIFY\r\n COLUMN `receiveWarehouseId` varchar (25) NULL COMMENT '实际收货仓库Id'\r\nAFTER\r\n `deliveryOrderSn`,\r\nMODIFY\r\n COLUMN `receiveWarehouseName` varchar (50) NULL COMMENT '实际收货仓库'\r\nAFTER\r\n `receiveWarehouseId`,\r\nMODIFY\r\n COLUMN `warehouseGroupId` varchar (25) NULL COMMENT '仓组Id'\r\nAFTER\r\n `receiveWarehouseName`,\r\nMODIFY\r\n COLUMN `jiaTongCode` varchar (50) NULL COMMENT '佳同码'\r\nAFTER\r\n `warehouseGroupId`,\r\nMODIFY\r\n COLUMN `barCodeMd5` varchar (32) NULL COMMENT '商品条码MD5'\r\nAFTER\r\n `jiaTongCode`,\r\nMODIFY\r\n COLUMN `shippingMark​Md5` varchar (32) NULL COMMENT '箱唛文件MD5'\r\nAFTER\r\n `barCodeMd5`,\r\nMODIFY\r\n COLUMN `notes` varchar (50) NULL COMMENT '备注'\r\nAFTER\r\n `shippingMark​Md5`,\r\nMODIFY\r\n COLUMN `upLoadStatus` int NOT NULL DEFAULT '0' COMMENT '是否上传订单(上传后扣除用户授权金额,产生扣费记录)'\r\nAFTER\r\n `notes`,\r\nMODIFY\r\n COLUMN `add_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP\r\nAFTER\r\n `upLoadStatus`,\r\nMODIFY\r\n COLUMN `mdy_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP\r\nAFTER\r\n `add_time`"; + // // sql = "ALTER TABLE\r\n kjd_order.order_" + i + "\r\nMODIFY\r\n COLUMN `originalPurchaseOrderSn` varchar (25) NOT NULL COMMENT '备母货单号'\r\nAFTER\r\n `supplierId`,\r\nMODIFY\r\n COLUMN `subPurchaseOrderSn` varchar (25) NOT NULL COMMENT '备货单号'\r\nAFTER\r\n `originalPurchaseOrderSn`"; + // // sql = "ALTER TABLE\r\n kjd_order.order_" + i + "\r\nMODIFY\r\n COLUMN `availableSaleDays` decimal (10, 0) NULL COMMENT '可售天数'\r\nAFTER\r\n `realReceiveAuthenticQuantity`"; + // // sql = "ALTER TABLE\r\n kjd_order.order_" + i + "\r\nADD\r\n COLUMN `upProductId` varchar (25) NOT NULL COMMENT '上家编号',\r\nMODIFY\r\n COLUMN `productSkcId` varchar (25) NOT NULL\r\nAFTER\r\n `upProductId`,\r\nMODIFY\r\n COLUMN `productSkcPicture` varchar (250) NOT NULL COMMENT '主图'\r\nAFTER\r\n `productSkcId`,\r\nMODIFY\r\n COLUMN `productSn` varchar (50) NULL COMMENT '货号'\r\nAFTER\r\n `productSkcPicture`,\r\nMODIFY\r\n COLUMN `status` int NOT NULL COMMENT '状态 1待发货 2已送货 7已入库 8已作废'\r\nAFTER\r\n `productSn`,\r\nMODIFY\r\n COLUMN `productSkuId` varchar (25) NOT NULL\r\nAFTER\r\n `status`,\r\nMODIFY\r\n COLUMN `extCode` varchar (50) NOT NULL COMMENT 'sku货号'\r\nAFTER\r\n `productSkuId`,\r\nMODIFY\r\n COLUMN `className` varchar (100) NOT NULL COMMENT 'sku规格'\r\nAFTER\r\n `extCode`,\r\nMODIFY\r\n COLUMN `currencyType` varchar (10) NOT NULL\r\nAFTER\r\n `className`,\r\nMODIFY\r\n COLUMN `supplierPrice` int NOT NULL COMMENT '申报价格'\r\nAFTER\r\n `currencyType`,\r\nMODIFY\r\n COLUMN `costPrice` int NULL COMMENT '成本价'\r\nAFTER\r\n `supplierPrice`,\r\nMODIFY\r\n COLUMN `deliveryFee` int NULL COMMENT '车队费'\r\nAFTER\r\n `costPrice`,\r\nMODIFY\r\n COLUMN `markFee` int NULL COMMENT '贴标费'\r\nAFTER\r\n `deliveryFee`,\r\nMODIFY\r\n COLUMN `purchaseQuantity` int NOT NULL COMMENT '备货件数'\r\nAFTER\r\n `markFee`,\r\nMODIFY\r\n COLUMN `deliverQuantity` int NOT NULL COMMENT '送货件数'\r\nAFTER\r\n `purchaseQuantity`,\r\nMODIFY\r\n COLUMN `realReceiveAuthenticQuantity` int NOT NULL COMMENT '入库件数'\r\nAFTER\r\n `deliverQuantity`,\r\nMODIFY\r\n COLUMN `availableSaleDays` decimal (10, 0) NULL COMMENT '可售天数'\r\nAFTER\r\n `realReceiveAuthenticQuantity`,\r\nMODIFY\r\n COLUMN `qcResult` int NULL COMMENT '抽检结果 1合格 2不合格'\r\nAFTER\r\n `availableSaleDays`,\r\nMODIFY\r\n COLUMN `thumbUrlList` varchar (500) NULL COMMENT 'sku图片'\r\nAFTER\r\n `qcResult`,\r\nMODIFY\r\n COLUMN `purchaseTime` bigint NOT NULL COMMENT '备货单创建时间'\r\nAFTER\r\n `thumbUrlList`,\r\nMODIFY\r\n COLUMN `deliverTime` bigint NULL COMMENT '发货时间'\r\nAFTER\r\n `purchaseTime`,\r\nMODIFY\r\n COLUMN `receiveTime` bigint NULL COMMENT '收货时间'\r\nAFTER\r\n `deliverTime`,\r\nMODIFY\r\n COLUMN `expectLatestDeliverTimeOrDefault` bigint NOT NULL COMMENT '最迟发货时间'\r\nAFTER\r\n `receiveTime`,\r\nMODIFY\r\n COLUMN `expectLatestArrivalTimeOrDefault` bigint NOT NULL COMMENT '最迟到货时间'\r\nAFTER\r\n `expectLatestDeliverTimeOrDefault`,\r\nMODIFY\r\n COLUMN `deliveryOrderSn` varchar (50) NULL COMMENT '发货单号'\r\nAFTER\r\n `expectLatestArrivalTimeOrDefault`,\r\nMODIFY\r\n COLUMN `receiveWarehouseId` varchar (25) NULL COMMENT '实际收货仓库Id'\r\nAFTER\r\n `deliveryOrderSn`,\r\nMODIFY\r\n COLUMN `receiveWarehouseName` varchar (50) NULL COMMENT '实际收货仓库'\r\nAFTER\r\n `receiveWarehouseId`,\r\nMODIFY\r\n COLUMN `warehouseGroupId` varchar (25) NULL COMMENT '仓组Id'\r\nAFTER\r\n `receiveWarehouseName`,\r\nMODIFY\r\n COLUMN `jiaTongCode` varchar (50) NULL COMMENT '佳同码'\r\nAFTER\r\n `warehouseGroupId`,\r\nMODIFY\r\n COLUMN `barCodeMd5` varchar (32) NULL COMMENT '商品条码MD5'\r\nAFTER\r\n `jiaTongCode`,\r\nMODIFY\r\n COLUMN `shippingMark​Md5` varchar (32) NULL COMMENT '箱唛文件MD5'\r\nAFTER\r\n `barCodeMd5`,\r\nMODIFY\r\n COLUMN `notes` varchar (50) NULL COMMENT '备注'\r\nAFTER\r\n `shippingMark​Md5`,\r\nMODIFY\r\n COLUMN `upLoadStatus` int NOT NULL DEFAULT '0' COMMENT '是否上传订单(上传后扣除用户授权金额,产生扣费记录)'\r\nAFTER\r\n `notes`,\r\nMODIFY\r\n COLUMN `add_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP\r\nAFTER\r\n `upLoadStatus`,\r\nMODIFY\r\n COLUMN `mdy_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP\r\nAFTER\r\n `add_time`"; + // // sql = "ALTER TABLE\r\n kjd_order.order_" + i + "\r\nMODIFY\r\n COLUMN `upProductId` varchar (25) NULL COMMENT '上家编号'\r\nAFTER\r\n `productId`"; + // // sql = "ALTER TABLE\r\n kjd_order.order_" + i + "\r\nADD\r\n COLUMN `supplierName` varchar (50) NOT NULL COMMENT '店铺名称',\r\nMODIFY\r\n COLUMN `originalPurchaseOrderSn` varchar (25) NOT NULL COMMENT '备母货单号'\r\nAFTER\r\n `supplierName`,\r\nMODIFY\r\n COLUMN `subPurchaseOrderSn` varchar (25) NOT NULL COMMENT '备货单号'\r\nAFTER\r\n `originalPurchaseOrderSn`,\r\nMODIFY\r\n COLUMN `productName` varchar (1000) NOT NULL\r\nAFTER\r\n `subPurchaseOrderSn`,\r\nMODIFY\r\n COLUMN `category` varchar (50) NOT NULL\r\nAFTER\r\n `productName`,\r\nMODIFY\r\n COLUMN `productId` varchar (25) NOT NULL COMMENT '商品编号'\r\nAFTER\r\n `category`,\r\nMODIFY\r\n COLUMN `upProductId` varchar (25) NULL COMMENT '上家编号'\r\nAFTER\r\n `productId`,\r\nMODIFY\r\n COLUMN `productSkcId` varchar (25) NOT NULL\r\nAFTER\r\n `upProductId`,\r\nMODIFY\r\n COLUMN `productSkcPicture` varchar (250) NOT NULL COMMENT '主图'\r\nAFTER\r\n `productSkcId`,\r\nMODIFY\r\n COLUMN `productSn` varchar (50) NULL COMMENT '货号'\r\nAFTER\r\n `productSkcPicture`,\r\nMODIFY\r\n COLUMN `status` int NOT NULL COMMENT '状态 1待发货 2已送货 7已入库 8已作废'\r\nAFTER\r\n `productSn`,\r\nMODIFY\r\n COLUMN `productSkuId` varchar (25) NOT NULL\r\nAFTER\r\n `status`,\r\nMODIFY\r\n COLUMN `extCode` varchar (50) NOT NULL COMMENT 'sku货号'\r\nAFTER\r\n `productSkuId`,\r\nMODIFY\r\n COLUMN `className` varchar (100) NOT NULL COMMENT 'sku规格'\r\nAFTER\r\n `extCode`,\r\nMODIFY\r\n COLUMN `currencyType` varchar (10) NOT NULL\r\nAFTER\r\n `className`,\r\nMODIFY\r\n COLUMN `supplierPrice` int NOT NULL COMMENT '申报价格'\r\nAFTER\r\n `currencyType`,\r\nMODIFY\r\n COLUMN `costPrice` int NULL COMMENT '成本价'\r\nAFTER\r\n `supplierPrice`,\r\nMODIFY\r\n COLUMN `deliveryFee` int NULL COMMENT '车队费'\r\nAFTER\r\n `costPrice`,\r\nMODIFY\r\n COLUMN `markFee` int NULL COMMENT '贴标费'\r\nAFTER\r\n `deliveryFee`,\r\nMODIFY\r\n COLUMN `purchaseQuantity` int NOT NULL COMMENT '备货件数'\r\nAFTER\r\n `markFee`,\r\nMODIFY\r\n COLUMN `deliverQuantity` int NOT NULL COMMENT '送货件数'\r\nAFTER\r\n `purchaseQuantity`,\r\nMODIFY\r\n COLUMN `realReceiveAuthenticQuantity` int NOT NULL COMMENT '入库件数'\r\nAFTER\r\n `deliverQuantity`,\r\nMODIFY\r\n COLUMN `availableSaleDays` decimal (10, 0) NULL COMMENT '可售天数'\r\nAFTER\r\n `realReceiveAuthenticQuantity`,\r\nMODIFY\r\n COLUMN `qcResult` int NULL COMMENT '抽检结果 1合格 2不合格'\r\nAFTER\r\n `availableSaleDays`,\r\nMODIFY\r\n COLUMN `thumbUrlList` varchar (500) NULL COMMENT 'sku图片'\r\nAFTER\r\n `qcResult`,\r\nMODIFY\r\n COLUMN `purchaseTime` bigint NOT NULL COMMENT '备货单创建时间'\r\nAFTER\r\n `thumbUrlList`,\r\nMODIFY\r\n COLUMN `deliverTime` bigint NULL COMMENT '发货时间'\r\nAFTER\r\n `purchaseTime`,\r\nMODIFY\r\n COLUMN `receiveTime` bigint NULL COMMENT '收货时间'\r\nAFTER\r\n `deliverTime`,\r\nMODIFY\r\n COLUMN `expectLatestDeliverTimeOrDefault` bigint NOT NULL COMMENT '最迟发货时间'\r\nAFTER\r\n `receiveTime`,\r\nMODIFY\r\n COLUMN `expectLatestArrivalTimeOrDefault` bigint NOT NULL COMMENT '最迟到货时间'\r\nAFTER\r\n `expectLatestDeliverTimeOrDefault`,\r\nMODIFY\r\n COLUMN `deliveryOrderSn` varchar (50) NULL COMMENT '发货单号'\r\nAFTER\r\n `expectLatestArrivalTimeOrDefault`,\r\nMODIFY\r\n COLUMN `receiveWarehouseId` varchar (25) NULL COMMENT '实际收货仓库Id'\r\nAFTER\r\n `deliveryOrderSn`,\r\nMODIFY\r\n COLUMN `receiveWarehouseName` varchar (50) NULL COMMENT '实际收货仓库'\r\nAFTER\r\n `receiveWarehouseId`,\r\nMODIFY\r\n COLUMN `warehouseGroupId` varchar (25) NULL COMMENT '仓组Id'\r\nAFTER\r\n `receiveWarehouseName`,\r\nMODIFY\r\n COLUMN `jiaTongCode` varchar (50) NULL COMMENT '佳同码'\r\nAFTER\r\n `warehouseGroupId`,\r\nMODIFY\r\n COLUMN `barCodeMd5` varchar (32) NULL COMMENT '商品条码MD5'\r\nAFTER\r\n `jiaTongCode`,\r\nMODIFY\r\n COLUMN `shippingMark​Md5` varchar (32) NULL COMMENT '箱唛文件MD5'\r\nAFTER\r\n `barCodeMd5`,\r\nMODIFY\r\n COLUMN `notes` varchar (50) NULL COMMENT '备注'\r\nAFTER\r\n `shippingMark​Md5`,\r\nMODIFY\r\n COLUMN `upLoadStatus` int NOT NULL DEFAULT '0' COMMENT '是否上传订单(上传后扣除用户授权金额,产生扣费记录)'\r\nAFTER\r\n `notes`,\r\nMODIFY\r\n COLUMN `add_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP\r\nAFTER\r\n `upLoadStatus`,\r\nMODIFY\r\n COLUMN `mdy_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP\r\nAFTER\r\n `add_time`"; + + // // sql = "ALTER TABLE\r\n kjd_order.order_" + i + " CHANGE COLUMN `shippingMark​Md5` `shippingMarkMd5` varchar (32) NULL COMMENT '箱唛文件MD5'"; + // // sql = "ALTER TABLE\r\n kjd_order.order_code_" + i + " DROP COLUMN `subPurchaseOrderSn`,\r\n DROP COLUMN `jiaTongCode`,\r\n DROP COLUMN `shippingMark​Md5`,\r\n DROP COLUMN `shippingMarkBase64`,\r\n CHANGE COLUMN `barCodeMd5` `fileCodeMd5` varchar (32) NOT NULL,\r\n CHANGE COLUMN `barCodeBase64` `fileCodeBase64` longtext NOT NULL,\r\nMODIFY\r\n COLUMN `add_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP\r\nAFTER\r\n `fileCodeBase64`,\r\nMODIFY\r\n COLUMN `mdy_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP\r\nAFTER\r\n `add_time`,\r\n DROP INDEX `index_subPurchaseOrderSn`,\r\nADD\r\n UNIQUE `index_fileCodeMd5` USING btree (`fileCodeMd5`)"; + // var rst = mySql.ExecuteNonQuery(sql); + //} + //mySql.Close(); + } + } +} + + + diff --git a/StoreHub.KJDWebService/Services/UpdateService.cs b/StoreHub.KJDWebService/Services/UpdateService.cs new file mode 100644 index 0000000..e4ef88e --- /dev/null +++ b/StoreHub.KJDWebService/Services/UpdateService.cs @@ -0,0 +1,230 @@ +using StoreHub.KJDWebService.Commons; +using StoreHub.Framework.Repositorys; +using Microsoft.Extensions.Configuration; +using NaiBa.Util.Extension; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; + +namespace StoreHub.KJDWebService.Services +{ + public class UpdateService : ServiceBase + { + public UpdateService(SqlRepository sqlRepository, IConfiguration configuration) : base(sqlRepository, configuration) + { + } + public string GetUpdate(string inputData) + { + //string time1 = Encryption(time); + //return "time=" + time + "&code=" + time1 + "&NbCodeVersion=1" + "&version=" + BaseClass.VersionCount + + if (!string.IsNullOrEmpty(inputData)) + { + var time = 0; + int.TryParse(RegexUtils.GetStringQuery(ref inputData, "time"), out time); + string time1 = RegexUtils.GetStringQuery(ref inputData, "code"); + if (time1 != EncrypUtil.Encryption(time)) + return "{\"code\":50000,\"msg\":\"校验失败\"}"; + + var version = RegexUtils.GetStringQuery(ref inputData, "version").ParseToInt(); + var serverVersion = Config("UpdateVersion"); + var UpdateFiles = ""; //Config("UpdateFiles"); + var UpdateExe = Config("UpdateExe"); + var UpdateExeChk = Config("UpdateExeChk"); + var LowVersion = Config("LowVersion"); + + serverVersion = "1115"; + UpdateFiles = "http://weidian.e57.cn/kjd_update/Update1115.zip"; + + if (version > LowVersion.ParseToInt()) + { + return "{\"code\":200,\"msg\":\"success\",\"next_version\":" + serverVersion + ",\"exe_check\":\"" + UpdateExeChk + + "\",\"exe_address\":\"" + UpdateExe + "\",\"file_address\":\"" + UpdateFiles + "\"}"; + } + else if (version > 0) + { + return "{\"code\":501,\"msg\":\"版本过低已无法直接升级,请联系管理员获取最新安装包\"}"; + } + else + { + return "{\"code\":502,\"msg\":\"get update version failed\"}"; + } + } + return "{\"code\":19999,\"msg\":\"未知错误\"}"; + } + + public string GetUpdateNew(string inputData) + { + //string time1 = Encryption(time); + //return "time=" + time + "&code=" + time1 + "&NbCodeVersion=1" + "&version=" + BaseClass.VersionCount + + if (!string.IsNullOrEmpty(inputData)) + { + var time = 0; + int.TryParse(RegexUtils.GetStringQuery(ref inputData, "time"), out time); + string time1 = RegexUtils.GetStringQuery(ref inputData, "code"); + if (time1 != EncrypUtil.Encryption(time)) + return "{\"code\":50000,\"msg\":\"校验失败\"}"; + + var path = RegexUtils.GetStringQuery(ref inputData, "path"); + + var version = RegexUtils.GetStringQuery(ref inputData, "version").ParseToInt(); + var serverVersion = Config("UpdateVersion"); + var UpdateNewUrl = Config("UpdateNewUrl"); + var UpdateExe = Config("UpdateExe"); + var UpdateExeChk = Config("UpdateExeChk"); + var LowVersion = Config("LowVersion"); + + int MaxVersion = 999999; + if (version <= 1200) + MaxVersion = 1200; + if (version <= 1159) + MaxVersion = 1159; + + if (version > LowVersion.ParseToInt()) + { + if (path != null) + { + try + { + var fileDir = Config("UpdateFileDir"); + if (path == "29wx") + { + var file = Directory.GetFiles(fileDir); + var versionTmp = 0; + foreach (var f in file) + { + var v = Path.GetFileName(f).Replace("Update29wx", "").Replace(".zip", "").ParseToInt(); + if (v > versionTmp && v <= serverVersion.ParseToInt() && v <= MaxVersion) + { + versionTmp = v; + } + } + if (versionTmp > 0) + { + serverVersion = versionTmp.ToString(); + return "{\"code\":200,\"msg\":\"success\",\"next_version\":" + serverVersion + ",\"exe_check\":\"" + UpdateExeChk + + "\",\"exe_address\":\"" + UpdateExe + "\",\"file_address\":\"" + UpdateNewUrl + "Update" + serverVersion + ".zip\"}"; + } + } + if (path == "29pdd") + { + var file = Directory.GetFiles(fileDir); + var versionTmp = 0; + foreach (var f in file) + { + var v = Path.GetFileName(f).Replace("Update29pdd", "").Replace(".zip", "").ParseToInt(); + if (v > versionTmp && v <= serverVersion.ParseToInt() && v <= MaxVersion) + { + versionTmp = v; + } + } + if (versionTmp > 0) + { + serverVersion = versionTmp.ToString(); + return "{\"code\":200,\"msg\":\"success\",\"next_version\":" + serverVersion + ",\"exe_check\":\"" + UpdateExeChk + + "\",\"exe_address\":\"" + UpdateExe + "\",\"file_address\":\"" + UpdateNewUrl + "Update" + serverVersion + ".zip\"}"; + } + } + } + catch (Exception ex) + { + //return "{\"code\":500,\"msg\":\"升级文件查询失败\"}"; + } + } + + if (serverVersion.ParseToInt() > MaxVersion) + serverVersion = MaxVersion.ParseToString(); + return "{\"code\":200,\"msg\":\"success\",\"next_version\":" + serverVersion + ",\"exe_check\":\"" + UpdateExeChk + + "\",\"exe_address\":\"" + UpdateExe + "\",\"file_address\":\"" + UpdateNewUrl + "Update" + serverVersion + ".zip\"}"; + } + else if (version > 0) + { + return "{\"code\":501,\"msg\":\"版本过低已无法直接升级,请联系管理员获取最新安装包\"}"; + } + else + { + return "{\"code\":502,\"msg\":\"get update version failed\"}"; + } + } + return "{\"code\":19999,\"msg\":\"未知错误\"}"; + } + + + public string GetWxFindOrderUpdate(string inputData) + { + //string time1 = Encryption(time); + //return "time=" + time + "&code=" + time1 + "&NbCodeVersion=1" + "&version=" + BaseClass.VersionCount + + if (!string.IsNullOrEmpty(inputData)) + { + var time = 0; + int.TryParse(RegexUtils.GetStringQuery(ref inputData, "time"), out time); + string time1 = RegexUtils.GetStringQuery(ref inputData, "code"); + if (time1 != EncrypUtil.Encryption(time)) + return "{\"code\":50000,\"msg\":\"校验失败\"}"; + + var path = RegexUtils.GetStringQuery(ref inputData, "path"); + + var version = RegexUtils.GetStringQuery(ref inputData, "version").ParseToInt(); + var serverVersion = Config("UpdateVersion"); + var UpdateFileNewUrl = Config("UpdateWxFindOrderUrl"); + var UpdateExe = Config("UpdateExe"); + var UpdateExeChk = Config("UpdateExeChk"); + var LowVersion = Config("WxFindOrderLowVersion"); + + if (version > LowVersion.ParseToInt()) + { + //if (path != null) + { + try + { + var fileDir = Config("UpdateWxFindOrderFileDir"); + //if (path == "29wx") + { + var file = Directory.GetFiles(fileDir); + var versionTmp = 0; + foreach (var f in file) + { + var v = Path.GetFileName(f).Replace("WxFindOrderUpdate", "").Replace(".zip", "").ParseToInt(); + if (v > versionTmp && v <= serverVersion.ParseToInt()) + { + versionTmp = v; + } + } + if (versionTmp > 0) + { + serverVersion = versionTmp.ToString(); + return "{\"code\":200,\"msg\":\"success\",\"next_version\":" + serverVersion + ",\"exe_check\":\"" + UpdateExeChk + + "\",\"exe_address\":\"" + UpdateExe + "\",\"file_address\":\"" + UpdateFileNewUrl + "WxFindOrderUpdate" + serverVersion + ".zip\"}"; + } + } + } + catch (Exception ex) + { + //return "{\"code\":500,\"msg\":\"升级文件查询失败\"}"; + } + } + + if (serverVersion.ParseToInt() > 1159) + serverVersion = 1159.ToString(); + return "{\"code\":200,\"msg\":\"success\",\"next_version\":" + serverVersion + ",\"exe_check\":\"" + UpdateExeChk + + "\",\"exe_address\":\"" + UpdateExe + "\",\"file_address\":\"" + UpdateFileNewUrl + "WxFindOrderUpdate" + serverVersion + ".zip\"}"; + } + else if (version > 0) + { + return "{\"code\":501,\"msg\":\"版本过低已无法直接升级,请联系管理员获取最新安装包\"}"; + } + else + { + return "{\"code\":502,\"msg\":\"get update version failed\"}"; + } + } + return "{\"code\":19999,\"msg\":\"未知错误\"}"; + } + } +} + + + diff --git a/StoreHub.KJDWebService/Services/UserService.cs b/StoreHub.KJDWebService/Services/UserService.cs new file mode 100644 index 0000000..f897296 --- /dev/null +++ b/StoreHub.KJDWebService/Services/UserService.cs @@ -0,0 +1,555 @@ +using StoreHub.KJDWebService.Models; +using StoreHub.Framework.Repositorys; +using Microsoft.Extensions.Configuration; +using StoreHub.KJDWebService.Commons; +using NaiBa.Util.Extension; +using System; +using System.Collections.Generic; +using System.Data; +using System.Linq; +using System.Net; +using System.Reflection; + +namespace StoreHub.KJDWebService.Services +{ + public class UserService : ServiceBase + { + public UserService(SqlRepository sqlRepository, IConfiguration configuration) : base(sqlRepository, configuration) + { + } + public string CheckUserLogin(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + var mobile = RegexUtils.GetStringQuery(ref inputData, "mobile")?.Replace("'", "\\'"); + var password = RegexUtils.GetStringQuery(ref inputData, "password")?.Replace("'", "\\'"); + int r2 = 0; + int.TryParse(RegexUtils.GetStringQuery(ref inputData, "r2"), out r2); + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = "select * from kjd.user where user_name='" + + mobile + "' and password='" + password + "'"; + + var dt = mySql.ExecuteDataTable(sql); + mySql.Close(); + if (dt != null) + { + foreach (DataRow row in dt.Rows) + { + UserLoginResultParam user = new UserLoginResultParam + { + id = Convert.ToInt32(row["id"]), + user_name = row["user_name"].ToString(), + nick_name = row["nick_name"].ToString(), + mobile = row["user_name"].ToString(), + password = row["password"].ToString(), + group_id = row["group_id"].ToString(), + card_id = row["card_id"].ToString(), + company_name = row["company_name"].ToString(), + is_sa = row.Table.Columns.Contains("is_sa") ? row["is_sa"].ParseToInt() : 0, + sa_level = row.Table.Columns.Contains("sa_level") ? row["sa_level"].ParseToInt() : 0, + authorized_amount = row.Table.Columns.Contains("authorized_amount") ? row["authorized_amount"].ParseToInt() : 0, + authority = row.Table.Columns.Contains("authority") ? row["authority"].ParseToString() : "", + forbidden_page = row.Table.Columns.Contains("forbidden_page") ? row["forbidden_page"].ParseToString() : "", + + }; + + if (string.IsNullOrEmpty(user.company_name)) + { + user.company_name = "-"; + } + var data = JsonUtils.SerializeObjectToString(user); + return "{\"code\":200,\"msg\":\"success\",\"data\":" + data + ",\"c\":\"" + EncrypUtil.Encryption(r2) + "\"}"; + } + return "{\"code\":1,\"msg\":\"用户名或密码错误\"}"; + } + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + public string AddSubUser(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + var parent_user_name = RegexUtils.GetStringQuery(ref inputData, "user_name")?.Replace("'", "\\'"); + var nick_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "sub_nick_name"))?.Replace("'", "\\'"); + var user_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "sub_name"))?.Replace("'", "\\'"); + var mobile = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "sub_mobile"))?.Replace("'", "\\'"); + var password = RegexUtils.GetStringQuery(ref inputData, "sub_password")?.Replace("'", "\\'"); + var group_id = RegexUtils.GetStringQuery(ref inputData, "group_id")?.Replace("'", "\\'"); + var card_id = RegexUtils.GetStringQuery(ref inputData, "card_id")?.Replace("'", "\\'"); + var company_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "company"))?.Replace("'", "\\'"); + var notes = RegexUtils.GetStringQuery(ref inputData, "notes")?.Replace("'", "\\'"); + var authority = RegexUtils.GetStringQuery(ref inputData, "authority")?.Replace("'", "\\'"); + var forbidden_page = RegexUtils.GetStringQuery(ref inputData, "forbidden_page")?.Replace("'", "\\'"); + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = ""; + sql = "select exists (select 1 from kjd.user where user_name='" + user_name + "')"; + var exist = mySql.ExecuteFirstInt(sql); + if (exist > 0) + { + mySql.Close(); + return "{\"code\":500,\"msg\":\"用户名已存在\"}"; + } + + sql = "insert into kjd.user (nick_name,user_name,mobile,password,card_id,group_id,company_name,notes,parent_user_name,authority,forbidden_page,add_time,mdy_time) " + + "values ('" + nick_name + "','" + user_name + "','" + mobile + "','" + password + "','" + card_id + "','" + + group_id + "','" + company_name + "','" + notes + "','" + parent_user_name + "','" + authority + "','" + forbidden_page + "','" + + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "','" + + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "');"; + var rst = mySql.ExecuteNonQuery(sql); + mySql.Close(); + if (!rst) + return "{\"code\":501,\"msg\":\""+ mySql.Message + "\"}"; + else + return "{\"code\":200,\"msg\":\"子账户创建成功!\"}"; + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + public string GetSubUser(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + var user_name = RegexUtils.GetStringQuery(ref inputData, "user_name"); + var password = RegexUtils.GetStringQuery(ref inputData, "password"); + var group = RegexUtils.GetStringQuery(ref inputData, "group"); + int r2 = 0; + int.TryParse(RegexUtils.GetStringQuery(ref inputData, "r2"), out r2); + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = "select * from kjd.user where parent_user_name='" + + user_name + "'"; + + var dt = mySql.ExecuteDataTable(sql); + mySql.Close(); + if (dt != null) + { + List userList = new List(); + foreach (DataRow row in dt.Rows) + { + + UserLoginResultParam user = new UserLoginResultParam + { + id = Convert.ToInt32(row["id"]), + user_name = row["user_name"].ToString(), + nick_name = row["nick_name"].ToString(), + mobile = row["mobile"].ToString(), + password = row["password"].ToString(), + group_id = row["group_id"].ToString(), + card_id = row["card_id"].ToString(), + parent_user_name = row["parent_user_name"].ToString(), + company_name = row["company_name"].ToString(), + notes = row["notes"].ToString(), + authority = row.Table.Columns.Contains("authority") ? row["authority"].ParseToString() : "", + forbidden_page = row.Table.Columns.Contains("forbidden_page") ? row["forbidden_page"].ParseToString() : "", + }; + if (string.IsNullOrEmpty(user.mobile)) + { + user.mobile = row["user_name"].ToString(); + } + userList.Add(user); + } + var data = JsonUtils.SerializeObjectToString(userList); + return "{\"code\":200,\"msg\":\"success\",\"data\":" + data + ",\"c\":\"" + EncrypUtil.Encryption(r2) + "\"}"; + } + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + public string UpdateSubUser(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + var id = RegexUtils.GetStringQuery(ref inputData, "id")?.Replace("'", "\\'"); + var parent_user_name = RegexUtils.GetStringQuery(ref inputData, "user_name")?.Replace("'", "\\'"); + var nick_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "sub_nick_name"))?.Replace("'", "\\'"); + var user_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "sub_name"))?.Replace("'", "\\'"); + var mobile = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "sub_mobile"))?.Replace("'", "\\'"); + var password = RegexUtils.GetStringQuery(ref inputData, "sub_password")?.Replace("'", "\\'"); + var group_id = RegexUtils.GetStringQuery(ref inputData, "group_id")?.Replace("'", "\\'"); + var card_id = RegexUtils.GetStringQuery(ref inputData, "card_id")?.Replace("'", "\\'"); + var notes = RegexUtils.GetStringQuery(ref inputData, "notes")?.Replace("'", "\\'"); + var authority = RegexUtils.GetStringQuery(ref inputData, "authority")?.Replace("'", "\\'"); + var forbidden_page = RegexUtils.GetStringQuery(ref inputData, "forbidden_page")?.Replace("'", "\\'"); + int r2 = 0; + int.TryParse(RegexUtils.GetStringQuery(ref inputData, "r2"), out r2); + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = ""; + //sql = "select * from kjd.user where parent_user_name='" + // + user_name + "'"; + sql = "update kjd.user set"; + if (!string.IsNullOrEmpty(nick_name)) + sql += " nick_name='" + nick_name + "',"; + if (!string.IsNullOrEmpty(user_name)) + sql += " user_name='" + user_name + "',"; + if (!string.IsNullOrEmpty(mobile)) + sql += " mobile='" + mobile + "',"; + if (!string.IsNullOrEmpty(password)) + sql += " password='" + password + "',"; + if (!string.IsNullOrEmpty(group_id)) + sql += " group_id=" + group_id + ","; + if (!string.IsNullOrEmpty(card_id)) + sql += " card_id='" + card_id + "',"; + if (!string.IsNullOrEmpty(notes)) + sql += " notes='" + notes + "',"; + if (!string.IsNullOrEmpty(authority)) + sql += " authority='" + authority + "',"; + if (!string.IsNullOrEmpty(forbidden_page)) + sql += " forbidden_page='" + forbidden_page + "',"; + sql = sql.TrimEnd(','); + sql += " where id=" + id + ""; + + var rst = mySql.ExecuteNonQuery(sql); + mySql.Close(); + if (rst) + { + return "{\"code\":200,\"msg\":\"success\"}"; + } + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + + public string DelUser(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + var user_name = RegexUtils.GetStringQuery(ref inputData, "user_name"); + var id = RegexUtils.GetStringQuery(ref inputData, "id"); + int r2 = 0; + int.TryParse(RegexUtils.GetStringQuery(ref inputData, "r2"), out r2); + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = "delete from kjd.user where id='" + + id + "'"; + + var rst = mySql.ExecuteNonQuery(sql); + mySql.Close(); + if (rst) + { + return "{\"code\":200,\"msg\":\"success\"}"; + } + else + return "{\"code\":500,\"msg\":\"删除失败,请稍后重试\"}"; + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + public string GetAllUser(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + var user_name = RegexUtils.GetStringQuery(ref inputData, "user_name")?.Replace("'", "\\'"); + var password = RegexUtils.GetStringQuery(ref inputData, "password")?.Replace("'", "\\'"); + var group_id = RegexUtils.GetStringQuery(ref inputData, "group_id")?.Replace("'", "\\'"); + var search = RegexUtils.GetStringQuery(ref inputData, "search")?.Replace("'", "\\'"); + var sa_level = RegexUtils.GetStringQuery(ref inputData, "sa_level")?.Replace("'", "\\'"); + var user_name_in = RegexUtils.GetStringQuery(ref inputData, "user_name_in")?.Replace("'", "\\'"); + int r2 = 0; + int.TryParse(RegexUtils.GetStringQuery(ref inputData, "r2"), out r2); + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + //string sql = "select * from kjd.user where group_id=3"; + string sql = "select * from kjd.user where 1=1"; + if (!string.IsNullOrEmpty(group_id)) + sql += " and group_id=" + group_id; + if (!string.IsNullOrEmpty(sa_level)) + sql += " and sa_level=" + sa_level; + if (!string.IsNullOrEmpty(user_name_in)) + sql += " AND user_name IN(" + user_name_in + ")"; + if (!string.IsNullOrEmpty(search)) + sql += " and (user_name like '%" + search + + "%' or nick_name like '%" + search + + "%' or company_name like '%" + search + "%')"; + sql += " order by id desc"; + + var dt = mySql.ExecuteDataTable(sql); + mySql.Close(); + if (dt != null) + { + List userList = new List(); + foreach (DataRow row in dt.Rows) + { + + UserLoginResultParam user = new UserLoginResultParam + { + id = Convert.ToInt32(row["id"]), + user_name = row["user_name"].ToString(), + nick_name = row["nick_name"].ToString(), + mobile = row["mobile"].ToString(), + password = row["password"].ToString(), + group_id = row["group_id"].ToString(), + card_id = row["card_id"].ToString(), + parent_user_name = row["parent_user_name"].ToString(), + company_name = row["company_name"].ToString(), + notes = row["notes"].ToString(), + is_sa = row.Table.Columns.Contains("is_sa") ? row["is_sa"].ParseToInt() : 0, + sa_level = row.Table.Columns.Contains("sa_level") ? row["sa_level"].ParseToInt() : 0, + authorized_amount = row.Table.Columns.Contains("authorized_amount") ? row["authorized_amount"].ParseToInt() : 0, + authority = row.Table.Columns.Contains("authority") ? row["authority"].ParseToString() : "", + forbidden_page = row.Table.Columns.Contains("forbidden_page") ? row["forbidden_page"].ParseToString() : "", + }; + if (string.IsNullOrEmpty(user.mobile)) + { + user.mobile = row["user_name"].ToString(); + } + userList.Add(user); + } + var data = JsonUtils.SerializeObjectToString(userList); + return "{\"code\":200,\"msg\":\"success\",\"data\":" + data + ",\"c\":\"" + EncrypUtil.Encryption(r2) + "\"}"; + } + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + public string AddUser(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + var nick_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "add_nick_name"))?.Replace("'", "\\'"); + var user_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "add_user_name"))?.Replace("'", "\\'"); + var mobile = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "add_mobile"))?.Replace("'", "\\'"); + var password = RegexUtils.GetStringQuery(ref inputData, "add_password")?.Replace("'", "\\'"); + var company_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "add_company"))?.Replace("'", "\\'"); + var group_id = RegexUtils.GetStringQuery(ref inputData, "group_id")?.Replace("'", "\\'"); ; + var card_id = RegexUtils.GetStringQuery(ref inputData, "card_id")?.Replace("'", "\\'"); + var notes = RegexUtils.GetStringQuery(ref inputData, "notes")?.Replace("'", "\\'"); + var sa_level = RegexUtils.GetStringQuery(ref inputData, "sa_level")?.Replace("'", "\\'"); + var authorized_amount = RegexUtils.GetStringQuery(ref inputData, "authorized_amount")?.Replace("'", "\\'"); + var authority = RegexUtils.GetStringQuery(ref inputData, "authority")?.Replace("'", "\\'"); + var forbidden_page = RegexUtils.GetStringQuery(ref inputData, "forbidden_page")?.Replace("'", "\\'"); + int r2 = 0; + int.TryParse(RegexUtils.GetStringQuery(ref inputData, "r2"), out r2); + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = ""; + sql = "select exists (select 1 from kjd.user where user_name='" + user_name + "')"; + var exist = mySql.ExecuteFirstInt(sql); + if (exist > 0) + { + mySql.Close(); + return "{\"code\":500,\"msg\":\"用户名已存在\"}"; + } + + sql = "insert into kjd.user (nick_name,user_name,mobile,password,card_id,group_id,company_name,notes,sa_level," + + "authorized_amount,authority,forbidden_page,add_time,mdy_time) " + + "values ('" + nick_name + "','" + user_name + "','" + mobile + "','" + password + "','" + card_id + "','" + + group_id + "','" + company_name + "','" + notes + "'," + sa_level + "," + authorized_amount + ",'" + authority + "','" + forbidden_page + "','" + + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "','" + + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "');"; + var rst = mySql.ExecuteNonQuery(sql); + mySql.Close(); + if (!rst) + return "{\"code\":501,\"msg\":\"" + mySql.Message + "\"}"; + else + return "{\"code\":200,\"msg\":\"success\"}"; + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + public string UpdateUser(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + var id = RegexUtils.GetStringQuery(ref inputData, "id")?.Replace("'", "\\'"); + var nick_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "add_nick_name"))?.Replace("'", "\\'"); + var user_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "add_user_name"))?.Replace("'", "\\'"); + var mobile = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "add_mobile"))?.Replace("'", "\\'"); + var company_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "add_company"))?.Replace("'", "\\'"); + var password = RegexUtils.GetStringQuery(ref inputData, "add_password")?.Replace("'", "\\'"); + var group_id = RegexUtils.GetStringQuery(ref inputData, "group_id")?.Replace("'", "\\'"); + var card_id = RegexUtils.GetStringQuery(ref inputData, "card_id")?.Replace("'", "\\'"); + var notes = RegexUtils.GetStringQuery(ref inputData, "notes")?.Replace("'", "\\'"); + var sa_level = RegexUtils.GetStringQuery(ref inputData, "sa_level")?.Replace("'", "\\'"); + var authorized_amount = RegexUtils.GetStringQuery(ref inputData, "authorized_amount")?.Replace("'", "\\'"); + var authority = RegexUtils.GetStringQuery(ref inputData, "authority")?.Replace("'", "\\'"); + var forbidden_page = RegexUtils.GetStringQuery(ref inputData, "forbidden_page")?.Replace("'", "\\'"); + int r2 = 0; + int.TryParse(RegexUtils.GetStringQuery(ref inputData, "r2"), out r2); + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = ""; + //sql = "select * from kjd.user where parent_user_name='" + // + user_name + "'"; + sql = "update kjd.user set"; + if (!string.IsNullOrEmpty(nick_name)) + sql += " nick_name='" + nick_name + "',"; + if (!string.IsNullOrEmpty(user_name)) + sql += " user_name='" + user_name + "',"; + if (!string.IsNullOrEmpty(mobile)) + sql += " mobile='" + mobile + "',"; + if (!string.IsNullOrEmpty(company_name)) + sql += " company_name='" + company_name + "',"; + if (!string.IsNullOrEmpty(password)) + sql += " password='" + password + "',"; + if (!string.IsNullOrEmpty(group_id)) + sql += " group_id=" + group_id + ","; + if (!string.IsNullOrEmpty(card_id)) + sql += " card_id='" + card_id + "',"; + if (!string.IsNullOrEmpty(notes)) + sql += " notes='" + notes + "',"; + if (!string.IsNullOrEmpty(sa_level)) + sql += " sa_level=" + sa_level + ","; + if (!string.IsNullOrEmpty(authorized_amount)) + sql += " authorized_amount=" + authorized_amount + ","; + if (authority != null) + sql += " authority='" + authority + "',"; + if (forbidden_page != null) + sql += " forbidden_page='" + forbidden_page + "',"; + sql = sql.TrimEnd(','); + sql += " where id=" + id + ""; + + var rst = mySql.ExecuteNonQuery(sql); + mySql.Close(); + if (rst) + { + return "{\"code\":200,\"msg\":\"success\"}"; + } + else + { + return "{\"code\":500,\"msg\":\"" + mySql.Message + "\"}"; + } + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + public string ChangePassword(string inputData) + { + var userName = RegexUtils.GetStringJson(ref inputData, "user_name")?.Replace("'", "\\'"); + var password = RegexUtils.GetStringJson(ref inputData, "password")?.Replace("'", "\\'"); + var newPassword = RegexUtils.GetStringJson(ref inputData, "new_password")?.Replace("'", "\\'"); + + string conn = "Conn"; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = "select user_id,password from pepdtp.user where user_id='" + + userName + "' and password='" + password + "'"; + + var dw = mySql.ExecuteDataTableRow(sql); + if (dw != null) + { + UserLoginResultParam user = new UserLoginResultParam + { + user_name = dw["user_id"].ToString(), + password = dw["password"].ToString(), + }; + sql = "update pepdtp.user set password = '" + newPassword + "' where user_id='" + userName + "'"; + var result = mySql.ExecuteNonQuery(sql); + mySql.Close(); + + if (result) + { + return "{\"code\":0,\"msg\":\"密码修改成功!\"}"; + } + else + return "{\"code\":19999,\"msg\":\"密码修改失败!请稍后再试。\"}"; + } + else + { + mySql.Close(); + return "{\"code\":1,\"msg\":\"原密码错误。\"}"; + } + } + + public string GetUserAmount(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + var time = 0; + int.TryParse(RegexUtils.GetStringQuery(ref inputData, "time"), out time); + 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\":500,\"msg\":\"请输入用户\"}"; + } + var password = RegexUtils.GetStringQuery(ref inputData, "password")?.Replace("'", "\\'"); + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = "select authorized_amount from kjd.user where user_name=" + user_name; + + var rst = mySql.ExecuteFirst(sql); + mySql.Close(); + if (!string.IsNullOrEmpty(rst)) + { + return "{\"code\":200,\"msg\":\"success\",\"data\":" + rst + "}"; + } + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + public string return_package_secret_key { get; set; } = "aaMETt2bPe6YHzZ1ojbC+6wOvgtwehqc6A+/Rz+pCUU="; + + public string GetPackageSign(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + var mobile = RegexUtils.GetStringQuery(ref inputData, "mobile")?.Replace("'", "\\'"); + var password = RegexUtils.GetStringQuery(ref inputData, "password")?.Replace("'", "\\'"); + var timestamp = RegexUtils.GetStringQuery(ref inputData, "timestamp")?.Replace("'", "\\'"); + var mallId = RegexUtils.GetStringQuery(ref inputData, "mallId")?.Replace("'", "\\'"); + var returnPackageNo = RegexUtils.GetStringQuery(ref inputData, "returnPackageNo")?.Replace("'", "\\'"); + int r2 = RegexUtils.GetStringQuery(ref inputData, "r2").ParseToInt(); + string c2 = RegexUtils.GetStringQuery(ref inputData, "c2"); + + if (EncrypUtil.Encryption(r2) != c2) + return "{\"code\":2,\"msg\":\"不合法的输入内容\"}"; + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = "select * from kjd.user where user_name='" + + mobile + "' and password='" + password + "'"; + + sql = "select * from kjd.user where user_name='" + mobile + "'"; + + var dt = mySql.ExecuteDataTable(sql); + mySql.Close(); + if (dt == null || dt.Rows.Count <=0) + { + return "{\"code\":1,\"msg\":\"用户不存在\"}"; + } + + string sign = EncrypUtil.GetMd5(timestamp + return_package_secret_key + mallId + returnPackageNo).ToLower(); + + return "{\"code\":200, \"sign\":\"" + sign + "\", \"msg\":\"\"}"; + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + public string IsGetReturnPackage(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + var user_name = RegexUtils.GetStringQuery(ref inputData, "user_name")?.Replace("'", "\\'"); + var password = RegexUtils.GetStringQuery(ref inputData, "password")?.Replace("'", "\\'"); + + int r2 = RegexUtils.GetStringQuery(ref inputData, "r2").ParseToInt(); + string c2 = RegexUtils.GetStringQuery(ref inputData, "c2"); + + if (EncrypUtil.Encryption(r2) != c2) + return "{\"code\":2,\"msg\":\"不合法的输入内容\"}"; + + var isGetReturn = System.Configuration.ConfigurationManager.ConnectionStrings["GetReturnPackage"]?.ConnectionString; + return "{\"code\":200, \"is_get\":\"" + isGetReturn + "\"}"; + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + } +} + + + diff --git a/StoreHub.KJDWebService/Services/WXExpressOptimizeService.cs b/StoreHub.KJDWebService/Services/WXExpressOptimizeService.cs new file mode 100644 index 0000000..e088069 --- /dev/null +++ b/StoreHub.KJDWebService/Services/WXExpressOptimizeService.cs @@ -0,0 +1,883 @@ +using StoreHub.KJDWebService.Models.WxModel; +using StoreHub.KJDWebService.Commons; +using StoreHub.KJDWebService.Models; +using StoreHub.Framework.Repositorys; +using Microsoft.Extensions.Configuration; +using MySql.Data.MySqlClient; +using NaiBa.Util.Extension; +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Data; +using System.Linq; + +namespace StoreHub.KJDWebService.Services +{ + public class WXExpressOptimizeService : ServiceBase + { + public WXExpressOptimizeService(SqlRepository sqlRepository, IConfiguration configuration) : base(sqlRepository, configuration) + { + } + public string GetWayBill(string inputData, bool isNoUserName = false) + { + if (!string.IsNullOrEmpty(inputData)) + { + var timeCalc = DateTime.Now; + + if (!WXUserService.GetSign(inputData)) + return "{\"code\":999,\"msg\":\"校验失败\"}"; + + //var delivery_id = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "delivery_id"))?.Replace("'", "\\'"); + //var delivery_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "delivery_name"))?.Replace("'", "\\'"); + //var waybill_id = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "waybill_id"))?.Replace("'", "\\'"); + //if (string.IsNullOrEmpty(delivery_id) || string.IsNullOrEmpty(delivery_name) || string.IsNullOrEmpty(waybill_id)) + //{ + // return "{\"code\":500,\"msg\":\"运单号信息不完整\"}"; + //} + var status = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "status"))?.Replace("'", "\'"); + var order_ids = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "order_ids"))?.Replace("'", "\'"); + var user_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "user_name"))?.Replace("'", "\'"); + if (!isNoUserName && user_name.IsNullOrEmpty()) + { + return "{\"code\":500,\"msg\":\"用户名不能为空\"}"; + } + if (isNoUserName && order_ids.IsNullOrEmpty()) + { + return "{\"code\":500,\"msg\":\"订单号不能为空\"}"; + } + + + int page = RegexUtils.GetStringQuery(ref inputData, "page").ParseToInt(); + int page_size = RegexUtils.GetStringQuery(ref inputData, "page_size").ParseToInt(50); + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = ""; + + //string tableName = "wxxd.express_optimize"; + //sql = "select exists (SELECT table_name FROM information_schema.tables WHERE table_schema = 'wxxd' AND table_name = 'express_optimize')"; + //var existTable = mySql.ExecuteFirstInt(sql); + //if (existTable == 0) + // sql = "select count(*) from wxxd.express_optimize where 1=1"; + //else + sql = "select count(*) from wxxd.express_optimize where 1=1"; + + string where = ""; + if (!isNoUserName) + where += " AND user_name='" + user_name + "'"; + if (status != null) + where += " AND status in (" + status + ")"; + if (order_ids != null) + where += " AND order_id in ('" + order_ids.Replace(",", "','") + "')"; + + sql += where; + + var count = 0; + count = mySql.ExecuteRowCount(sql); + + DataTable dt; + if (count == 0) + { + dt = new DataTable(); + } + else + { + sql = "select * from wxxd.express_optimize 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 (!string.IsNullOrEmpty(mySql.Message)) + return "{\"code\":501,\"msg\":\"" + mySql.Message + "\"}"; + + if (dt != null) + { + try + { + List WxOptimizeExpressInfoLst = new List(); + foreach (DataRow row in dt.Rows) + { + WxOptimizeExpressInfoLst.Add(new WxOptimizeExpressInfo() + { + id = row["id"].ParseToInt(), + delivery_id = row["delivery_id"].ParseToString(), + delivery_name = row["delivery_name"].ParseToString(), + order_id = row["order_id"].ParseToString(), + bind_order_id = row["bind_order_id"].ParseToString(), + shop_id = row["shop_id"].ParseToString(), + status = row["status"].ParseToInt(), + waybill_id = row["waybill_id"].ParseToString(), + add_time = Convert.ToDateTime(row["add_time"]), + use_time = row["use_time"].ParseToString().ParseToDateTimeNullable(), + waybill_pickup_time = row["waybill_pickup_time"].ParseToString().ParseToDateTimeNullable(), + }); + } + JsonSerializerSettings jsonSetting = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }; + var data = JsonUtils.SerializeObjectToString(WxOptimizeExpressInfoLst, 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 AddWaybill(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + if (!WXUserService.GetSign(inputData)) + return "{\"code\":999,\"msg\":\"校验失败\"}"; + + var delivery_id = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "delivery_id"))?.Replace("'", "\\'"); + var delivery_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "delivery_name"))?.Replace("'", "\\'"); + var waybill_id = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "waybill_id"))?.Replace("'", "\\'"); + var bind_order_id = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "bind_order_id"))?.Replace("'", "\\'"); + var waybill_pickup_time = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "waybill_pickup_time")).ParseToDateTimeNullable(); + if (string.IsNullOrEmpty(delivery_id) || string.IsNullOrEmpty(delivery_name) || string.IsNullOrEmpty(waybill_id)) + { + return "{\"code\":500,\"msg\":\"运单号信息不完整\"}"; + } + if (waybill_pickup_time == null && bind_order_id.IsNullOrEmpty()) + { + return "{\"code\":500,\"msg\":\"揽收时间和绑定订单编号不能同时为空\"}"; + } + var user_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "user_name"))?.ParseToString(); + if (user_name.IsNullOrEmpty()) + { + return "{\"code\":500,\"msg\":\"请输入用户名\"}"; + } + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = ""; + sql = "SELECT EXISTS (SELECT 1 FROM wxxd.express_optimize WHERE waybill_id='" + waybill_id + "')"; + var exist = mySql.ExecuteFirstInt(sql); + if (!mySql.Message.IsNullOrEmpty()) + { + mySql.Close(); + return "{\"code\":501,\"msg\":\"" + mySql.Message + "\"}"; + } + if (exist > 0) + { + mySql.Close(); + return "{\"code\":500,\"msg\":\"运单号已存在\"}"; + } + + sql = "INSERT INTO wxxd.express_optimize (user_name,delivery_id,delivery_name,waybill_id,"; + if (!bind_order_id.IsNullOrEmpty()) + sql += "bind_order_id,"; + if (waybill_pickup_time != null) + sql += "waybill_pickup_time,"; + sql = sql.Trim(','); + sql += ") VALUES ('" + user_name + "','" + delivery_id + "','" + delivery_name + "','" + waybill_id + "',"; + if (!bind_order_id.IsNullOrEmpty()) + sql += "'" + bind_order_id + "',"; + if (waybill_pickup_time != null) + sql += "'" + waybill_pickup_time.Value.ToString("yyyy-MM-dd HH:mm:ss") + "',"; + sql = sql.Trim(','); + sql += ");"; + var rst = mySql.ExecuteNonQuery(sql); + mySql.Close(); + if (!rst) + return "{\"code\":501,\"msg\":\"" + mySql.Message + "\"}"; + else + return "{\"code\":200,\"msg\":\"success\"}"; + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + public string DelWaybill(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + if (!WXUserService.GetSign(inputData)) + return "{\"code\":999,\"msg\":\"校验失败\"}"; + + var waybill_ids = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "waybill_ids"))?.Replace("'", "\\'"); + if (string.IsNullOrEmpty(waybill_ids)) + { + return "{\"code\":500,\"msg\":\"运单号信息不完整\"}"; + } + var user_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "user_name"))?.ParseToString(); + if (user_name.IsNullOrEmpty()) + { + return "{\"code\":500,\"msg\":\"请输入用户名\"}"; + } + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = ""; + sql = "DELETE FROM wxxd.express_optimize WHERE waybill_id in ('" + waybill_ids.Replace(",", "','") + "') and status=0"; + var rst = mySql.ExecuteNonQuery(sql); + mySql.Close(); + if (!rst || !mySql.Message.IsNullOrEmpty()) + return "{\"code\":501,\"msg\":\"删除失败 " + mySql.Message + "\"}"; + else + return "{\"code\":200,\"msg\":\"success\"}"; + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + /// + /// 选择并使用运单 + /// + /// + /// + public string SelectAndSetWaybill(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + if (!WXUserService.GetSign(inputData)) + return "{\"code\":999,\"msg\":\"校验失败\"}"; + + var user_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "user_name"))?.ParseToString(); + if (user_name.IsNullOrEmpty()) + { + return "{\"code\":500,\"msg\":\"请输入用户名\"}"; + } + var shop_id = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "shop_id"))?.Replace("'", "\\'"); + var order_id = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "order_id"))?.Replace("'", "\\'"); + if (string.IsNullOrEmpty(order_id) || string.IsNullOrEmpty(shop_id)) + { + return "{\"code\":500,\"msg\":\"缺少订单信息\"}"; + } + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn, true); + + string sql = ""; + sql = "select * from wxxd.express_optimize where order_id='" + order_id + "' and status = 1"; + var dt = mySql.ExecuteDataTable(sql); + if (!mySql.Message.IsNullOrEmpty()) + { + mySql.RollBack(); + mySql.Close(); + return "{\"code\":501,\"msg\":\"物流信息查询失败 " + mySql.Message + "\"}"; + } + if (dt?.Rows?.Count == 0) + { + sql = "UPDATE wxxd.express_optimize SET order_id='" + order_id + "',status=1 WHERE user_name='" + user_name + + "' AND status=0 AND (order_id IS NULL OR order_id='') LIMIT 1"; + var cnt = mySql.ExecuteAffectedRows(sql); + if (cnt == 0 || !mySql.Message.IsNullOrEmpty()) + { + mySql.RollBack(); + mySql.Close(); + return "{\"code\":501,\"msg\":\"物流信息提取失败 " + mySql.Message + "\"}"; + } + + sql = "SELECT * FROM wxxd.express_optimize WHERE user_name='" + user_name + "' AND order_id='" + order_id + "' AND status = 1"; + dt = mySql.ExecuteDataTable(sql); + if (!mySql.Message.IsNullOrEmpty()) + { + mySql.RollBack(); + mySql.Close(); + return "{\"code\":501,\"msg\":\"物流信息提取失败 " + mySql.Message + "\"}"; + } + if (dt?.Rows?.Count == 0) + { + mySql.RollBack(); + mySql.Close(); + return "{\"code\":501,\"msg\":\"物流信息提取失败 " + mySql.Message + "\"}"; + } + } + var waybill_id = dt.Rows[0]["waybill_id"].ToString(); + + // todo E57调用接口处理 + + mySql.Close(); + mySql = new MysqlUtils(conn, true); + sql = " UPDATE wxxd.express_optimize SET shop_id='" + shop_id + "',status=2,use_time='" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "' " + + " WHERE user_name='" + user_name + "' AND status=1 AND order_id='" + order_id + "' AND waybill_id='" + waybill_id + "'"; + var rst = mySql.ExecuteAffectedRows(sql); + if (rst == 0 || !mySql.Message.IsNullOrEmpty()) + { + mySql.RollBack(); + mySql.Close(); + return "{\"code\":501,\"msg\":\"修改物流信息失败 " + mySql.Message + "\"}"; + } + else + { + mySql.Commit(); + mySql.Close(); + return "{\"code\":200,\"msg\":\"success\"}"; + } + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + public string SelectWaybill(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + if (!WXUserService.GetSign(inputData)) + return "{\"code\":999,\"msg\":\"校验失败\"}"; + + var user_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "user_name"))?.ParseToString(); + if (user_name.IsNullOrEmpty()) + { + return "{\"code\":500,\"msg\":\"请输入用户名\"}"; + } + var shop_id = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "shop_id"))?.Replace("'", "\\'"); + var order_id = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "order_id"))?.Replace("'", "\\'"); + var order_time = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "order_time")).ParseToDateTimeNullable(); + + if (string.IsNullOrEmpty(order_id) || string.IsNullOrEmpty(shop_id)) + { + return "{\"code\":500,\"msg\":\"缺少订单信息\"}"; + } + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn, true); + + try + { + string sql = ""; + sql = "select * from wxxd.express_optimize WHERE user_name='" + user_name + "' AND order_id='" + order_id + "' and status = 1 LIMIT 1"; + var dt = mySql.ExecuteDataTable(sql); + if (!mySql.Message.IsNullOrEmpty()) + { + mySql.RollBack(); + mySql.Close(); + return "{\"code\":501,\"msg\":\"物流查询失败 " + mySql.Message + "\"}"; + } + if (dt?.Rows?.Count == 0) + { + // 获取事先绑定的订单运单 + sql = " UPDATE wxxd.express_optimize SET order_id='" + order_id + "',status=1" + + " WHERE user_name='" + user_name + "' AND status=0 AND bind_order_id='" + order_id + "'" + + " ORDER BY RAND() LIMIT 1"; + var cnt = mySql.ExecuteAffectedRows(sql); + if (!mySql.Message.IsNullOrEmpty()) + { + mySql.RollBack(); + mySql.Close(); + return "{\"code\":501,\"msg\":\"物流提取失败 " + mySql.Message + "\"}"; + } + // 根据订单时间提取指定时间段内的运单号 + if (cnt == 0 && order_time != null) + { + // 第一天的订单用第二天的物流发货 + var start_time = order_time.Value.Date.AddHours(24).ToString("yyyy-MM-dd HH:mm:ss"); + var end_time = order_time.Value.Date.AddHours(48).AddSeconds(-1).ToString("yyyy-MM-dd HH:mm:ss"); + sql = " UPDATE wxxd.express_optimize SET order_id='" + order_id + "',status=1" + + " WHERE user_name='" + user_name + "' AND status=0 AND (order_id IS NULL OR order_id='') AND (bind_order_id IS NULL OR bind_order_id='')" + + " AND waybill_pickup_time between '" + start_time + "' and '" + end_time + "'" + + " ORDER BY RAND() LIMIT 1"; + cnt = mySql.ExecuteAffectedRows(sql); + if (!mySql.Message.IsNullOrEmpty()) + { + mySql.RollBack(); + mySql.Close(); + return "{\"code\":501,\"msg\":\"物流提取失败 " + mySql.Message + "\"}"; + } + } + // 挑选最早入库的运单号 + //if (cnt == 0 && order_time == null) + //{ + // sql = " UPDATE wxxd.express_optimize SET order_id='" + order_id + "',status=1" + + // " WHERE user_name='" + user_name + "' AND status=0 AND (order_id IS NULL OR order_id='') AND (bind_order_id IS NULL OR bind_order_id='')" + + // " LIMIT 1"; + // cnt = mySql.ExecuteAffectedRows(sql); + // if (!mySql.Message.IsNullOrEmpty()) + // { + // mySql.RollBack(); + // mySql.Close(); + // return "{\"code\":501,\"msg\":\"物流提取失败 " + mySql.Message + "\"}"; + // } + //} + if (cnt == 0) + { + mySql.RollBack(); + mySql.Close(); + return "{\"code\":501,\"msg\":\"没有可用的运单号\"}"; + } + + sql = "SELECT * FROM wxxd.express_optimize WHERE user_name='" + user_name + "' AND order_id='" + order_id + "' AND status = 1"; + dt = mySql.ExecuteDataTable(sql); + if (!mySql.Message.IsNullOrEmpty()) + { + mySql.RollBack(); + mySql.Close(); + return "{\"code\":501,\"msg\":\"物流提取失败 " + mySql.Message + "\"}"; + } + if (dt?.Rows?.Count == 0) + { + mySql.RollBack(); + mySql.Close(); + return "{\"code\":501,\"msg\":\"物流提取失败 " + mySql.Message + "\"}"; + } + } + var waybill_id = dt.Rows[0]["waybill_id"].ToString(); + var delivery_id = dt.Rows[0]["delivery_id"].ParseToString(); + var delivery_name = dt.Rows[0]["delivery_name"].ParseToString(); + + mySql.Commit(); + mySql.Close(); + + return "{\"code\":200,\"msg\":\"success\",\"data\":{\"waybill_id\":\"" + waybill_id + + "\",\"delivery_id\":\"" + delivery_id + "\",\"delivery_name\":\"" + delivery_name + "\"}}"; + } + catch (Exception ex) + { + mySql.RollBack(); + mySql.Close(); + return "{\"code\":501,\"msg\":\"物流提取失败 " + ex.Message + "\"}"; + } + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + public string UpdateUsedWaybill(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + if (!WXUserService.GetSign(inputData)) + return "{\"code\":999,\"msg\":\"校验失败\"}"; + + var user_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "user_name"))?.ParseToString(); + if (user_name.IsNullOrEmpty()) + { + return "{\"code\":500,\"msg\":\"请输入用户名\"}"; + } + var shop_id = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "shop_id"))?.Replace("'", "\\'"); + var order_id = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "order_id"))?.Replace("'", "\\'"); + var waybill_id = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "waybill_id"))?.Replace("'", "\\'"); + var is_rollback = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "is_rollback"))?.Replace("'", "\\'"); + if (string.IsNullOrEmpty(order_id) || string.IsNullOrEmpty(shop_id) || string.IsNullOrEmpty(waybill_id)) + { + return "{\"code\":500,\"msg\":\"缺少订单信息\"}"; + } + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn, true); + + var sql = " UPDATE wxxd.express_optimize SET shop_id='" + shop_id + "',status=2,use_time='" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "' " + + " WHERE user_name='" + user_name + "' AND status=1 AND order_id='" + order_id + "' AND waybill_id='" + waybill_id + "'"; + if (is_rollback == "true") + sql = " UPDATE wxxd.express_optimize SET shop_id='',order_id='',status=0,use_time=NULL" + + " WHERE user_name='" + user_name + "' AND status=1 AND order_id='" + order_id + "' AND waybill_id='" + waybill_id + "'"; + + var rst = mySql.ExecuteAffectedRows(sql); + if (rst == 0 || !mySql.Message.IsNullOrEmpty()) + { + mySql.RollBack(); + mySql.Close(); + return "{\"code\":501,\"msg\":\"修改物流信息失败 " + mySql.Message + "\"}"; + } + + // 记录修改结果,暂时注释 + if (is_rollback != "true") + { + //var relation_id = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "relation_id"))?.Replace("'", "\\'"); + //var optimize_rst = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "optimize_rst"))?.Replace("'", "\\'"); + //var delivery_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "delivery_name"))?.Replace("'", "\\'"); + //if (optimize_rst != null) + //{ + // sql = "select exists (select 1 from wxxd.express_optimize where order_id='" + order_id + "')"; + // var exist = mySql.ExecuteFirstInt(sql); + // if (exist > 0) + // { + // sql = " UPDATE wxxd.express_optimize_rst SET "; + // if (shop_id != null) + // sql += " shop_id=@shop_id,"; + // if (relation_id != null) + // sql += " relation_id=@relation_id,"; + // if (optimize_rst != null) + // sql += " optimize_rst=@optimize_rst,"; + // if (waybill_id != null) + // sql += " waybill_id=@waybill_id,"; + // if (delivery_name != null) + // sql += " delivery_name=@delivery_name,"; + // sql = sql.TrimEnd(','); + // sql += " WHERE order_id=@order_id"; + // } + // else + // { + // sql = " insert into wxxd.express_optimize_rst (shop_id,order_id,"; + // if (relation_id != null) + // sql += "relation_id,"; + // if (optimize_rst != null) + // sql += "optimize_rst,"; + // if (waybill_id != null) + // sql += "waybill_id,"; + // if (delivery_name != null) + // sql += "delivery_name,"; + // sql = sql.TrimEnd(','); + // sql += ") "; + // sql += " values (@shop_id,@order_id,"; + // if (relation_id != null) + // sql += "@relation_id,"; + // if (optimize_rst != null) + // sql += "@optimize_rst,"; + // if (waybill_id != null) + // sql += "@waybill_id,"; + // if (delivery_name != null) + // sql += "@delivery_name,"; + // sql = sql.TrimEnd(','); + // sql += ");"; + // } + + // List paramLst = new List(); + // paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "@shop_id", Value = shop_id, }); + // paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "@relation_id", Value = relation_id, }); + // paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "@optimize_rst", Value = optimize_rst, }); + // paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "@waybill_id", Value = waybill_id, }); + // paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "@delivery_name", Value = delivery_name, }); + // paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "@order_id", Value = order_id, }); + // var rows = mySql.ExecuteAffectedRows(sql, paramLst.ToArray()); + //} + } + + mySql.Commit(); + mySql.Close(); + return "{\"code\":200,\"msg\":\"success\"}"; + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + public string AddMdyExpressOptimizeRst(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + if (!WXUserService.GetSign(inputData)) + return "{\"code\":999,\"msg\":\"校验失败\"}"; + + var shop_id = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "shop_id"))?.Replace("'", "\\'"); + var order_id = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "order_id"))?.Replace("'", "\\'"); + var optimize_rst = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "optimize_rst"))?.Replace("'", "\\'"); + var waybill_id = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "waybill_id"))?.Replace("'", "\\'"); + var delivery_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "delivery_name"))?.Replace("'", "\\'"); + if (string.IsNullOrEmpty(order_id)) + { + return "{\"code\":500,\"msg\":\"请输入订单编号\"}"; + } + if (string.IsNullOrEmpty(optimize_rst)) + { + return "{\"code\":500,\"msg\":\"请输入补发结果\"}"; + } + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = ""; + sql = "select exists (select 1 from wxxd.express_optimize_rst where order_id='" + order_id + "')"; + var exist = mySql.ExecuteFirstInt(sql); + if (!mySql.Message.IsNullOrEmpty()) + { + mySql.Close(); + return "{\"code\":501,\"msg\":\"" + mySql.Message + "\"}"; + } + if (exist > 0) + { + sql = " UPDATE wxxd.express_optimize_rst SET "; + if (shop_id != null) + sql += " shop_id=@shop_id,"; + if (optimize_rst != null) + sql += " optimize_rst=@optimize_rst,"; + if (waybill_id != null) + sql += " waybill_id=@waybill_id,"; + if (delivery_name != null) + sql += " delivery_name=@delivery_name,"; + sql = sql.TrimEnd(','); + sql += " WHERE order_id=@order_id"; + } + else + { + sql = " insert into wxxd.express_optimize_rst (shop_id,order_id,"; + if (optimize_rst != null) + sql += "optimize_rst,"; + if (waybill_id != null) + sql += "waybill_id,"; + if (delivery_name != null) + sql += "delivery_name,"; + sql = sql.TrimEnd(','); + sql += ") "; + sql += " values (@shop_id,@order_id,"; + if (optimize_rst != null) + sql += "@optimize_rst,"; + if (waybill_id != null) + sql += "@waybill_id,"; + if (delivery_name != null) + sql += "@delivery_name,"; + sql = sql.TrimEnd(','); + sql += ");"; + } + + List paramLst = new List(); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "@shop_id", Value = shop_id, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "@optimize_rst", Value = optimize_rst, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "@waybill_id", Value = waybill_id, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "@delivery_name", Value = delivery_name, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "@order_id", Value = order_id, }); + var rows = mySql.ExecuteAffectedRows(sql, paramLst.ToArray()); + mySql.Close(); + if (!mySql.Message.IsNullOrEmpty()) + return "{\"code\":501,\"msg\":\"" + mySql.Message + "\"}"; + else + return "{\"code\":200,\"msg\":\"success\",\"affected_rows\":" + rows + "}"; + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + + public string GetExpressOptimizeRst(string inputData, bool isNoUserName = false) + { + if (!string.IsNullOrEmpty(inputData)) + { + var timeCalc = DateTime.Now; + + if (!WXUserService.GetSign(inputData)) + return "{\"code\":999,\"msg\":\"校验失败\"}"; + + var order_ids = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "order_ids"))?.Replace("'", "\'"); + if (isNoUserName && order_ids.IsNullOrEmpty()) + { + return "{\"code\":500,\"msg\":\"订单号不能为空\"}"; + } + + int page = RegexUtils.GetStringQuery(ref inputData, "page").ParseToInt(); + int page_size = RegexUtils.GetStringQuery(ref inputData, "page_size").ParseToInt(200); + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = ""; + sql = "select count(*) from wxxd.express_optimize_rst where 1=1"; + + string where = ""; + if (order_ids != null) + where += " AND order_id in ('" + order_ids.Replace(",", "','") + "')"; + + sql += where; + + var count = 0; + count = mySql.ExecuteRowCount(sql); + + DataTable dt; + if (count == 0) + { + dt = new DataTable(); + } + else + { + sql = "select * from wxxd.express_optimize_rst 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 (!string.IsNullOrEmpty(mySql.Message)) + return "{\"code\":501,\"msg\":\"" + mySql.Message + "\"}"; + + if (dt != null) + { + try + { + List WxOptimizeRstInfoLst = new List(); + foreach (DataRow row in dt.Rows) + { + WxOptimizeRstInfoLst.Add(new WxOptimizeRstInfo() + { + id = row["id"].ParseToInt(), + waybill_id = row["waybill_id"].ParseToString(), + delivery_name = row["delivery_name"].ParseToString(), + order_id = row["order_id"].ParseToString(), + optimize_rst = row["optimize_rst"].ParseToString(), + shop_id = row["shop_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(WxOptimizeRstInfoLst, 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 AddMdyExpressOptimizeRemark(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + if (!WXUserService.GetSign(inputData)) + return "{\"code\":999,\"msg\":\"校验失败\"}"; + + var shop_id = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "shop_id"))?.Replace("'", "\\'"); + var order_id = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "order_id"))?.Replace("'", "\\'"); + var remark = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "remark"))?.Replace("'", "\\'"); + if (string.IsNullOrEmpty(order_id)) + { + return "{\"code\":500,\"msg\":\"请输入订单编号\"}"; + } + if (remark == null) + { + return "{\"code\":500,\"msg\":\"请输入备注内容\"}"; + } + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = ""; + sql = "select exists (select 1 from wxxd.express_optimize_remark where order_id='" + order_id + "')"; + var exist = mySql.ExecuteFirstInt(sql); + if (!mySql.Message.IsNullOrEmpty()) + { + mySql.Close(); + return "{\"code\":501,\"msg\":\"" + mySql.Message + "\"}"; + } + if (exist > 0) + { + sql = " UPDATE wxxd.express_optimize_remark SET "; + if (shop_id != null) + sql += " shop_id=@shop_id,"; + if (remark != null) + sql += " remark=@remark,"; + sql = sql.TrimEnd(','); + sql += " WHERE order_id=@order_id"; + } + else + { + sql = " insert into wxxd.express_optimize_remark (shop_id,order_id,"; + if (remark != null) + sql += "remark,"; + sql = sql.TrimEnd(','); + sql += ") "; + sql += " values (@shop_id,@order_id,"; + if (remark != null) + sql += "@remark,"; + sql = sql.TrimEnd(','); + sql += ");"; + } + + List paramLst = new List(); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "@shop_id", Value = shop_id, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "@remark", Value = remark, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "@order_id", Value = order_id, }); + var rows = mySql.ExecuteAffectedRows(sql, paramLst.ToArray()); + mySql.Close(); + if (!mySql.Message.IsNullOrEmpty()) + return "{\"code\":501,\"msg\":\"" + mySql.Message + "\"}"; + else + return "{\"code\":200,\"msg\":\"success\",\"affected_rows\":" + rows + "}"; + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + + public string GetExpressOptimizeRemark(string inputData, bool isNoUserName = false) + { + if (!string.IsNullOrEmpty(inputData)) + { + var timeCalc = DateTime.Now; + + if (!WXUserService.GetSign(inputData)) + return "{\"code\":999,\"msg\":\"校验失败\"}"; + + var order_ids = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "order_ids"))?.Replace("'", "\'"); + if (isNoUserName && order_ids.IsNullOrEmpty()) + { + return "{\"code\":500,\"msg\":\"订单号不能为空\"}"; + } + + int page = RegexUtils.GetStringQuery(ref inputData, "page").ParseToInt(); + int page_size = RegexUtils.GetStringQuery(ref inputData, "page_size").ParseToInt(200); + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = ""; + sql = "select count(*) from wxxd.express_optimize_remark where 1=1"; + + string where = ""; + if (order_ids != null) + where += " AND order_id in ('" + order_ids.Replace(",", "','") + "')"; + + sql += where; + + var count = 0; + count = mySql.ExecuteRowCount(sql); + + DataTable dt; + if (count == 0) + { + dt = new DataTable(); + } + else + { + sql = "select * from wxxd.express_optimize_remark 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 (!string.IsNullOrEmpty(mySql.Message)) + return "{\"code\":501,\"msg\":\"" + mySql.Message + "\"}"; + + if (dt != null) + { + try + { + List WxOptimizeRemarkInfoLst = new List(); + foreach (DataRow row in dt.Rows) + { + WxOptimizeRemarkInfoLst.Add(new WxOptimizeRemarkInfo() + { + id = row["id"].ParseToInt(), + order_id = row["order_id"].ParseToString(), + remark = row["remark"].ParseToString(), + shop_id = row["shop_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(WxOptimizeRemarkInfoLst, 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\":\"输入为空\"}"; + } + } +} + + + + + diff --git a/StoreHub.KJDWebService/Services/WXOemService.cs b/StoreHub.KJDWebService/Services/WXOemService.cs new file mode 100644 index 0000000..4d63fc4 --- /dev/null +++ b/StoreHub.KJDWebService/Services/WXOemService.cs @@ -0,0 +1,147 @@ +using StoreHub.KJDWebService.Models.WxModel; +using StoreHub.KJDWebService.Commons; +using StoreHub.Framework.Repositorys; +using Microsoft.Extensions.Configuration; +using NaiBa.Util.Extension; +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Data; +using System.Linq; + +namespace StoreHub.KJDWebService.Services +{ + public class WXOemService : ServiceBase + { + public WXOemService(SqlRepository sqlRepository, IConfiguration configuration) : base(sqlRepository, configuration) + { + } + public string AddMdyOem(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + if (!WXUserService.GetSign(inputData)) + return "{\"code\":999,\"msg\":\"校验失败\"}"; + + var oem_id = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "oem_id")?.Replace("'", "\\'")); + var oem_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "oem_name")?.Replace("'", "\\'")); + var oem_owner = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "oem_owner")?.Replace("'", "\\'")); + if (oem_id.IsNullOrEmpty() || oem_name.IsNullOrEmpty()) + return "{\"code\":500,\"msg\":\"oem信息不能为空\"}"; + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = "INSERT INTO wxxd.oem (oem_id,oem_name,oem_owner) VALUES('" + oem_id + "','" + oem_name + "','" + oem_owner + "')" + + "ON DUPLICATE KEY UPDATE oem_name=VALUES(oem_name),oem_owner=VALUES(oem_owner);"; + + var rst = mySql.ExecuteAffectedRows(sql); + mySql.Close(); + + if (!string.IsNullOrEmpty(mySql.Message)) + { + return "{\"code\":500,\"msg\":\"" + mySql.Message + "\"}"; + } + return "{\"code\":200,\"msg\":\"success\",\"affected_rows\":" + rst + "}"; + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + public string DelOem(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + if (!WXUserService.GetSign(inputData)) + return "{\"code\":999,\"msg\":\"校验失败\"}"; + + var id = (RegexUtils.GetStringQuery(ref inputData, "db_id")?.Replace("'", "\\'")); + var oem_id = (RegexUtils.GetStringQuery(ref inputData, "oem_id")?.Replace("'", "\\'")); + if (oem_id.IsNullOrEmpty() && id.IsNullOrEmpty()) + return "{\"code\":500,\"msg\":\"oem信息不能为空\"}"; + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = "UPDATE wxxd.oem SET is_del=1 WHERE id=" + id + " or oem_id='" + oem_id + "'"; + + var rst = mySql.ExecuteAffectedRows(sql); + mySql.Close(); + + if (!string.IsNullOrEmpty(mySql.Message)) + { + return "{\"code\":500,\"msg\":\"" + mySql.Message + "\"}"; + } + return "{\"code\":200,\"msg\":\"success\"}"; + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + public string GetOem(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + if (!WXUserService.GetSign(inputData)) + return "{\"code\":999,\"msg\":\"校验失败\"}"; + + var timeCalc = DateTime.Now; + var oem_id = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "oem_id")?.Replace("'", "\\'")); + var oem_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "oem_name")?.Replace("'", "\\'")); + var oem_owner = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "oem_owner")?.Replace("'", "\\'")); + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = "SELECT * FROM wxxd.oem WHERE is_del=0"; + + string where = ""; + if (!string.IsNullOrEmpty(oem_id)) + where += " and oem_id in ('" + oem_id.Replace(",", "','") + "')"; + if (!string.IsNullOrEmpty(oem_name)) + where += " and oem_name in ('" + oem_name.Replace(",", "','") + "')"; + if (!string.IsNullOrEmpty(oem_owner)) + where += " and oem_owner in ('" + oem_owner.Replace(",", "','") + "')"; + + sql += where; + sql += " ORDER BY add_time DESC;"; + + var dt = mySql.ExecuteDataTable(sql); + mySql.Close(); + + if (!string.IsNullOrEmpty(mySql.Message) || dt == null) + { + return "{\"code\":500,\"msg\":\"" + mySql.Message + "\"}"; + } + + try + { + List productLst = new List(); + foreach (DataRow row in dt.Rows) + { + oem prod = new oem + { + id = row["id"].ParseToInt(), + oem_icon = null, + oem_id = row["oem_id"].ParseToString(), + add_time = row["add_time"].ParseToString().ParseToDateTime(), + mdy_time = row["mdy_time"].ParseToString().ParseToDateTime(), + oem_img = null, + oem_name = row["oem_name"].ParseToString(), + oem_owner = row["oem_owner"].ParseToString(), + }; + productLst.Add(prod); + } + JsonSerializerSettings jsonSetting = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }; + var data = JsonUtils.SerializeObjectToString(productLst, jsonSetting); + var seconds = (DateTime.Now - timeCalc).TotalSeconds.ToString("0.000"); + return "{\"code\":200,\"msg\":\"success\",\"data\":" + data + ",\"count\":" + -1 + ",\"seconds\":" + seconds + "}"; + } + catch (Exception ex) + { + return "{\"code\":500,\"msg\":\"" + ex.Message + "\",\"data\":[],\"count\":" + 0 + "}"; + } + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + } +} + + + + diff --git a/StoreHub.KJDWebService/Services/WXOrderService.cs b/StoreHub.KJDWebService/Services/WXOrderService.cs new file mode 100644 index 0000000..1e08ab8 --- /dev/null +++ b/StoreHub.KJDWebService/Services/WXOrderService.cs @@ -0,0 +1,2048 @@ +using StoreHub.KJDWebService.Models.WxModel; +using StoreHub.KJDWebService.Commons; +using StoreHub.Framework.Repositorys; +using Microsoft.Extensions.Configuration; +using MySql.Data.MySqlClient; +using NaiBa.Util.Extension; +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Data; +using System.Linq; + +namespace StoreHub.KJDWebService.Services +{ + public class WXOrderService : ServiceBase + { + public WXOrderService(SqlRepository sqlRepository, IConfiguration configuration) : base(sqlRepository, configuration) + { + } + public string WXGetErpOrderList(string inputData, bool isDetail = false) + { + if (!string.IsNullOrEmpty(inputData)) + { + if (!WXUserService.GetSign(inputData)) + return "{\"code\":999,\"msg\":\"校验失败\"}"; + var timeCalc = DateTime.Now; + + var erp_shop_id_in = RegexUtils.GetStringQuery(ref inputData, "erp_shop_id_in")?.Replace("'", "\\'"); + var erp_order_id_in = RegexUtils.GetStringQuery(ref inputData, "erp_order_id_in")?.Replace("'", "\\'"); + if (erp_shop_id_in.IsNullOrEmpty() && erp_order_id_in.IsNullOrEmpty()) + { + return "{\"code\":500,\"msg\":\"未指定店铺和订单\"}"; + } + var query_status = RegexUtils.GetStringQuery(ref inputData, "query_status")?.Replace("'", "\\'"); + var purchase_status = RegexUtils.GetStringQuery(ref inputData, "purchase_status")?.Replace("'", "\\'"); + var sort_type = RegexUtils.GetStringQuery(ref inputData, "sort_type")?.Replace("'", "\\'"); + var start_time = RegexUtils.GetStringQuery(ref inputData, "start_time").ParseToInt(); + var end_time = RegexUtils.GetStringQuery(ref inputData, "end_time").ParseToInt(); + var is_not_count = RegexUtils.GetStringQuery(ref inputData, "is_not_count") == "true"; + + int page = RegexUtils.GetStringQuery(ref inputData, "page").ParseToInt(); + int page_size = RegexUtils.GetStringQuery(ref inputData, "page_size").ParseToInt(50); + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + + string sql = "SELECT COUNT(id) FROM erp.oms_wei_order o WHERE 1=1 "; + + string where = ""; + if (!string.IsNullOrWhiteSpace(erp_shop_id_in)) + where += " and o.shop_id in (" + erp_shop_id_in + ")"; + if (!string.IsNullOrWhiteSpace(erp_order_id_in)) + where += " and o.order_id in ('" + erp_order_id_in.Replace(",", "','") + "')"; + if (!string.IsNullOrWhiteSpace(query_status)) + where += " and o.status = " + query_status; + if (!string.IsNullOrWhiteSpace(purchase_status)) + where += " and o.purchase_status = " + purchase_status; + if (start_time > 0) + where += " and o.update_time >= " + start_time; + if (end_time > 0) + where += " and o.update_time <= " + end_time; + sql += where; + + var count = 0; + if (!is_not_count) + count = mySql.ExecuteRowCount(sql); + + DataTable dt; + if (count == 0 && !is_not_count) + { + dt = new DataTable(); + } + else + { + //tinyint(1)中存超过两个值,只返回true或false,无法直接取值解决办法 + //解决方法: + //1.强制修改mapResult中的映射,将po属性的类型由Boolean改为Byte + //2.查询 tinyint(1) 的sql 字段时,转为(status + 0) as status + //3.避免使用 tinyint(1) 作为字段的数据类型 + + sql = "SELECT o.*,(out_shipped+0) as out_shipped_int FROM erp.oms_wei_order o WHERE 1=1"; + + //where子句 + sql += where; + + if (sort_type == "asc") + //sql += " ORDER BY o.create_time ASC, o.id desc"; + sql += " ORDER BY o.create_time ASC"; + else + sql += " ORDER BY o.create_time DESC"; + sql += " LIMIT " + Math.Max(page - 1, 0) * page_size + "," + page_size; + dt = mySql.ExecuteDataTable(sql); + } + + mySql.Close(); + if (dt != null) + { + try + { + List orderList = new List(); + foreach (DataRow row in dt.Rows) + { + oms_wei_order order = new oms_wei_order + { + id = row["id"].ParseToLong(), + aftersale_detail = row["aftersale_detail"].ParseToNullableString(), + audit_status = row["audit_status"].ParseToNullableInt(), + //audit_time = row["audit_time"].ParseToNullableString().ParseToDateTime(), + city_name = row["city_name"].ParseToNullableString(), + colour_flag = row["colour_flag"].ParseToNullableInt(), + colour_flag_update_time = row["colour_flag_update_time"].ParseToNullableString().ParseToDateTime(), + commission_amount = row["commission_amount"].ParseToNullableInt(), + county_name = row["county_name"].ParseToNullableString(), + create_time = row["create_time"].ParseToInt(), + delivery_deadline = row["delivery_deadline"].ParseToNullableInt(), + //delivery_product_info = row["delivery_product_info"].ParseToNullableString(), + delivery_time = row["delivery_time"].ParseToNullableInt(), + detail_info = row["detail_info"].ParseToNullableString(), + discounted_price = row["discounted_price"].ParseToNullableInt(), + erp_send_code = row["erp_send_code"].ParseToNullableString(), + erp_send_company = row["erp_send_company"].ParseToNullableString(), + erp_send_status = row["erp_send_status"].ParseToNullableInt(), + erp_send_time = row["erp_send_time"].ParseToNullableString().ParseToDateTime(), + //ewaybill_order_code = row["ewaybill_order_code"].ParseToNullableString(), + external_gift = row["external_gift"].ParseToNullableInt(), + //ext_info = row["ext_info"].ParseToNullableString(), + freight = row["freight"].ParseToNullableInt(), + freight_insurance_amount = row["freight_insurance_amount"].ParseToNullableInt(), + gift_order_status = row["gift_order_status"].ParseToNullableInt(), + hash_code = row["hash_code"].ParseToNullableString(), + has_freight_insurance = row["has_freight_insurance"].ParseToNullableInt(), + house_number = row["house_number"].ParseToNullableString(), + is_express_no_used = row["is_express_no_used"].ParseToNullableInt(), + is_shipment_optimized = row["is_shipment_optimized"].ParseToNullableInt(), + merchant_id = row["merchant_id"].ParseToLong(), + openid = row["openid"].ParseToNullableString(), + order_id = row["order_id"].ParseToNullableString(), + order_price = row["order_price"].ParseToNullableInt(), + out_account = row["out_account"].ParseToNullableString(), + out_after_sale_status = row["out_after_sale_status"].ParseToNullableString(), + out_amount = row["out_amount"].ParseToNullableInt(), + out_express_company = row["out_express_company"].ParseToNullableString(), + out_express_no = row["out_express_no"].ParseToNullableString(), + out_order_no = row["out_order_no"].ParseToNullableString(), + out_shipped = row["out_shipped_int"].ParseToNullableInt(), + //pay_info = row["pay_info"].ParseToNullableString(), + postal_code = row["postal_code"].ParseToNullableString(), + predict_commission_fee = row["predict_commission_fee"].ParseToNullableInt(), + product_price = row["product_price"].ParseToNullableInt(), + profit = row["profit"].ParseToNullableInt(), + province_name = row["province_name"].ParseToNullableString(), + purchase_price = row["purchase_price"].ParseToNullableInt(), + purchase_status = row["purchase_status"].ParseToNullableInt(), + purchase_time = row["purchase_time"].ParseToNullableInt(), + settle_info = row["settle_info"].ParseToNullableString(), + ship_done_time = row["ship_done_time"].ParseToNullableInt(), + shop_id = row["shop_id"].ParseToLong(), + shop_name = row["shop_name"].ParseToNullableString(), + shop_remark = row["shop_remark"].ParseToNullableString(), + soft_remark = row["soft_remark"].ParseToNullableString(), + status = row["status"].ParseToNullableInt(), + supplier_remark_exception = row["supplier_remark_exception"].ParseToNullableString(), + tel_number = row["tel_number"].ParseToNullableString(), + tel_number_ext_info = row["tel_number_ext_info"].ParseToNullableString(), + transfer_warehouse_status = row["transfer_warehouse_status"].ParseToNullableInt(), + unionid = row["unionid"].ParseToNullableString(), + update_time = row["update_time"].ParseToInt(), + user_name = row["user_name"].ParseToNullableString(), + use_tel_number = row["use_tel_number"].ParseToNullableInt(), + virtual_order_tel_number = row["virtual_order_tel_number"].ParseToNullableString(), + }; + if (order.order_id == "3737914129536416512") + { + + } + orderList.Add(order); + } + JsonSerializerSettings jsonSetting = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }; + var data = JsonUtils.SerializeObjectToString(orderList, 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 WXGetErpOrderItemList(string inputData, bool isDetail = false) + { + if (!string.IsNullOrEmpty(inputData)) + { + var timeCalc = DateTime.Now; + + 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 erp_order_id_in = RegexUtils.GetStringQuery(ref inputData, "erp_order_id_in")?.Replace("'", "\\'"); + if (erp_order_id_in.IsNullOrEmpty()) + { + return "{\"code\":500,\"msg\":\"未指定订单\"}"; + } + var sort_type = RegexUtils.GetStringQuery(ref inputData, "sort_type")?.Replace("'", "\\'"); + var is_not_count = RegexUtils.GetStringQuery(ref inputData, "is_not_count") != "false"; + + int page = RegexUtils.GetStringQuery(ref inputData, "page").ParseToInt(); + int page_size = RegexUtils.GetStringQuery(ref inputData, "page_size").ParseToInt(500); + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + + string sql = "SELECT COUNT(id) FROM erp.oms_wei_order_item o WHERE 1=1 "; + + string where = ""; + if (!string.IsNullOrWhiteSpace(erp_order_id_in)) + where += " and o.order_id in ('" + erp_order_id_in.Replace(",", "','") + "')"; + sql += where; + + var count = 0; + if (!is_not_count) + count = mySql.ExecuteRowCount(sql); + + DataTable dt; + if (count == 0 && !is_not_count) + { + dt = new DataTable(); + } + else + { + sql = "SELECT o.* FROM erp.oms_wei_order_item o WHERE 1=1"; + + //where子句 + sql += where; + + if (sort_type == "asc") + sql += " ORDER BY o.id ASC"; + else + sql += " ORDER BY o.id DESC"; + sql += " LIMIT " + Math.Max(page - 1, 0) * page_size + "," + page_size; + dt = mySql.ExecuteDataTable(sql); + } + + mySql.Close(); + if (dt != null) + { + try + { + List orderItemList = new List(); + foreach (DataRow row in dt.Rows) + { + oms_wei_order_item order = new oms_wei_order_item + { + id = row["id"].ParseToLong(), + commission_amount = row["commission_amount"].ParseToNullableInt(), + freight = row["freight"].ParseToNullableInt(), + merchant_id = row["merchant_id"].ParseToLong(), + order_id = row["order_id"].ParseToNullableString(), + predict_commission_fee = row["predict_commission_fee"].ParseToNullableInt(), + purchase_price = row["purchase_price"].ParseToNullableInt(), + shop_id = row["shop_id"].ParseToLong(), + cash_coupon_discounted_price = row["cash_coupon_discounted_price"].ParseToNullableInt(), + change_price = row["change_price"].ParseToNullableInt(), + deduction_price = row["deduction_price"].ParseToNullableInt(), + erp_goods_id = row["erp_goods_id"].ParseToNullableLong(), + erp_goods_sku_id = row["erp_goods_sku_id"].ParseToNullableLong(), + estimate_price = row["estimate_price"].ParseToNullableInt(), + extra_service = row["extra_service"].ParseToNullableString(), + finish_aftersale_sku_cnt = row["finish_aftersale_sku_cnt"].ParseToNullableInt(), + is_change_price = row["is_change_price"].ParseToNullableString(), + is_discounted = row["is_discounted"].ParseToNullableString(), + market_price = row["market_price"].ParseToNullableInt(), + on_aftersale_sku_cnt = row["on_aftersale_sku_cnt"].ParseToNullableInt(), + order_product_coupon_info_list = row["order_product_coupon_info_list"].ParseToNullableString(), + out_product_id = row["out_product_id"].ParseToNullableString(), + out_sku_id = row["out_sku_id"].ParseToNullableString(), + out_warehouse_id = row["out_warehouse_id"].ParseToNullableString(), + product_id = row["product_id"].ParseToNullableString(), + real_price = row["real_price"].ParseToNullableInt(), + refund_status = row["refund_status"].ParseToNullableInt(), + return_address = row["return_address"].ParseToNullableString(), + sale_price = row["sale_price"].ParseToNullableInt(), + sku_attrs = row["sku_attrs"].ParseToNullableString(), + sku_cnt = row["sku_cnt"].ParseToNullableInt(), + sku_code = row["sku_code"].ParseToNullableString(), + sku_deliver_info = row["sku_deliver_info"].ParseToNullableString(), + sku_id = row["sku_id"].ParseToNullableString(), + thumb_img = row["thumb_img"].ParseToNullableString(), + title = row["title"].ParseToNullableString(), + use_deduction = row["use_deduction"].ParseToNullableString(), + }; + orderItemList.Add(order); + } + JsonSerializerSettings jsonSetting = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }; + var data = JsonUtils.SerializeObjectToString(orderItemList, 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 WXGetErpRefundList(string inputData, bool isDetail = false) + { + if (!string.IsNullOrEmpty(inputData)) + { + var timeCalc = DateTime.Now; + + 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 erp_order_id_in = RegexUtils.GetStringQuery(ref inputData, "erp_order_id_in")?.Replace("'", "\\'"); + if (erp_order_id_in.IsNullOrEmpty()) + { + return "{\"code\":500,\"msg\":\"未指定订单\"}"; + } + var sort_type = RegexUtils.GetStringQuery(ref inputData, "sort_type")?.Replace("'", "\\'"); + var is_not_count = RegexUtils.GetStringQuery(ref inputData, "is_not_count") != "false"; + + int page = RegexUtils.GetStringQuery(ref inputData, "page").ParseToInt(); + int page_size = RegexUtils.GetStringQuery(ref inputData, "page_size").ParseToInt(500); + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + + string sql = "SELECT COUNT(id) FROM erp.oms_wei_refund o WHERE 1=1 "; + + string where = ""; + if (!string.IsNullOrWhiteSpace(erp_order_id_in)) + where += " and o.order_id in ('" + erp_order_id_in.Replace(",", "','") + "')"; + sql += where; + + var count = 0; + if (!is_not_count) + count = mySql.ExecuteRowCount(sql); + + DataTable dt; + if (count == 0 && !is_not_count) + { + dt = new DataTable(); + } + else + { + sql = "SELECT o.* FROM" + + " erp.oms_wei_refund o " + + " WHERE 1=1"; + + //where子句 + sql += where; + + if (sort_type == "asc") + sql += " ORDER BY o.id ASC"; + else + sql += " ORDER BY o.id DESC"; + sql += " LIMIT " + Math.Max(page - 1, 0) * page_size + "," + page_size; + dt = mySql.ExecuteDataTable(sql); + } + + mySql.Close(); + if (dt != null) + { + try + { + List refundItemList = new List(); + foreach (DataRow row in dt.Rows) + { + oms_wei_refund order = new oms_wei_refund + { + id = row["id"].ParseToLong(), + merchant_id = row["merchant_id"].ParseToLong(), + order_id = row["order_id"].ParseToNullableString(), + shop_id = row["shop_id"].ParseToLong(), + erp_goods_id = row["erp_goods_id"].ParseToNullableLong(), + erp_goods_sku_id = row["erp_goods_sku_id"].ParseToNullableLong(), + product_id = row["product_id"].ParseToNullableString(), + sku_id = row["sku_id"].ParseToNullableString(), + after_sale_order_id = row["after_sale_order_id"].ParseToNullableString(), + complaint_id = row["complaint_id"].ParseToNullableString(), + count = row["count"].ParseToNullableInt(), + create_time = row["create_time"].ParseToNullableInt(), + details = row["details"].ParseToNullableString(), + fast_refund = row["fast_refund"].ParseToNullableString(), + merchant_upload_info = row["merchant_upload_info"].ParseToNullableString(), + openid = row["openid"].ParseToNullableString(), + pull_status = row["pull_status"].ParseToNullableInt(), + pull_time = row["pull_time"].ParseToNullableString().ParseToDateTime(), + reason = row["reason"].ParseToNullableString(), + reason_text = row["reason_text"].ParseToNullableString(), + refund_amount = row["refund_amount"].ParseToNullableInt(), + refund_reason = row["refund_reason"].ParseToNullableInt(), + refund_resp = row["refund_resp"].ParseToNullableString(), + return_delivery_id = row["return_delivery_id"].ParseToNullableString(), + return_delivery_name = row["return_delivery_name"].ParseToNullableString(), + return_waybill_id = row["return_waybill_id"].ParseToNullableString(), + status = row["status"].ParseToNullableString(), + type = row["type"].ParseToNullableString(), + unionid = row["unionid"].ParseToNullableString(), + update_time = row["update_time"].ParseToNullableInt(), + warehouse_status = row["warehouse_status"].ParseToNullableInt(), + return_city = row["return_city"].ParseToNullableString(), + return_county = row["return_county"].ParseToNullableString(), + return_detail = row["return_detail"].ParseToNullableString(), + return_province = row["return_province"].ParseToNullableString(), + return_tel = row["return_tel"].ParseToNullableString(), + return_user_name = row["return_user_name"].ParseToNullableString(), + }; + refundItemList.Add(order); + } + JsonSerializerSettings jsonSetting = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }; + var data = JsonUtils.SerializeObjectToString(refundItemList, 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\":\"输入为空\"}"; + } + + + + + /// + /// 微信添加修改采购映射商品(含sku映射和) + /// + /// + /// + public string WXAddMdyBuyProdMap(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + if (!WXUserService.GetSign(inputData)) + return "{\"code\":999,\"msg\":\"校验失败\"}"; + + // 软件用户名 + string spu_code = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "spu_code"))?.Replace("'", "\\'"); + string sku_code = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "sku_code"))?.Replace("'", "\\'"); + string user_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "main_user_name"))?.Replace("'", "\\'"); + string map_url = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "map_url"))?.Replace("'", "\\'"); + string map_goods_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "map_goods_name"))?.Replace("'", "\\'"); + string map_spec_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "map_spec_name"))?.Replace("'", "\\'"); + string map_goods_id = RegexUtils.GetStringQuery(ref inputData, "map_goods_id")?.Replace("'", "\\'"); + string map_sku_id = RegexUtils.GetStringQuery(ref inputData, "map_sku_id")?.Replace("'", "\\'"); + string map_send_address = RegexUtils.GetStringQuery(ref inputData, "map_send_address")?.Replace("'", "\\'"); + string transit_warehouse_id = RegexUtils.GetStringQuery(ref inputData, "transit_warehouse_id")?.Replace("'", "\\'"); + + if (string.IsNullOrEmpty(spu_code) || string.IsNullOrEmpty(sku_code)) + return "{\"code\":500,\"msg\":\"缺少系统商品或SKU编号\"}"; + if (string.IsNullOrEmpty(user_name)) + return "{\"code\":500,\"msg\":\"缺少用户名\"}"; + if (string.IsNullOrEmpty(map_url) && (string.IsNullOrEmpty(map_goods_id) || string.IsNullOrEmpty(map_sku_id))) + return "{\"code\":500,\"msg\":\"缺少采购商品信息\"}"; + if (string.IsNullOrEmpty(transit_warehouse_id)) + return "{\"code\":500,\"msg\":\"缺少中转仓信息\"}"; + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + + string sql = "SELECT 1 FROM `bxx`.`product_buy_map` where user_name='" + user_name + "' AND spu_code='" + spu_code + "' AND sku_code='" + sku_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_map` (user_name,spu_code,sku_code,map_url,map_goods_name,map_spec_name,map_goods_id,map_sku_id,map_send_address,transit_warehouse_id)" + + " VALUES (@user_name,@spu_code,@sku_code,@map_url,@map_goods_name,@map_spec_name,@map_goods_id,@map_sku_id,@map_send_address,@transit_warehouse_id);"; + } + else + { + sql = "UPDATE `bxx`.`product_buy_map` SET "; + if (map_url != null) + sql += " map_url=@map_url,"; + if (map_goods_name != null) + sql += " map_goods_name=@map_goods_name,"; + if (map_spec_name != null) + sql += " map_spec_name=@map_spec_name,"; + if (map_goods_id != null) + sql += " map_goods_id=@map_goods_id,"; + if (map_sku_id != null) + sql += " map_sku_id=@map_sku_id,"; + if (map_send_address != null) + sql += " map_send_address=@map_send_address,"; + if (transit_warehouse_id != null) + sql += " transit_warehouse_id=@transit_warehouse_id,"; + sql = sql.TrimEnd(','); + sql += " WHERE user_name=@user_name and spu_code=@spu_code and sku_code=@sku_code;"; + } + + List paramLst = new List(); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "user_name", Value = user_name, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "spu_code", Value = spu_code, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "sku_code", Value = sku_code, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "map_url", Value = map_url, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "map_goods_name", Value = map_goods_name, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "map_spec_name", Value = map_spec_name, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "map_goods_id", Value = map_goods_id, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "map_sku_id", Value = map_sku_id, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "map_send_address", Value = map_send_address, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "transit_warehouse_id", Value = transit_warehouse_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 WXGetBuyPordMap(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + if (!WXUserService.GetSign(inputData)) + return "{\"code\":999,\"msg\":\"校验失败\"}"; + var timeCalc = DateTime.Now; + + 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 sku_codes = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "sku_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 = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + + string sql = ""; + var count = -1; + + sql = "SELECT COUNT(*) FROM `bxx`.`product_buy_map` WHERE 1=1"; + string where = ""; + if (spu_codes != null) + where += " and spu_code IN ('" + spu_codes.Replace(",", "','") + "')"; + if (sku_codes != null) + where += " and sku_code IN ('" + sku_codes.Replace(",", "','") + "')"; + if (user_name != null) + where += " and user_name='" + user_name + "'"; + sql += where; + sql += ";"; + + if (not_count == "false") + count = mySql.ExecuteRowCount(sql); + + DataTable dt; + if (count == 0) + { + dt = new DataTable(); + } + else + { + sql = "SELECT * FROM `bxx`.`product_buy_map` 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 WXBuyMapInfoLst = new List(); + foreach (DataRow row in dt.Rows) + { + WXBuyMapInfoLst.Add(new WXBuyMapInfo() + { + id = row["id"].ParseToInt(), + user_name = row["user_name"].ParseToNullableString(), + spu_code = row["spu_code"].ParseToNullableString(), + sku_code = row["sku_code"].ParseToNullableString(), + map_url = row["map_url"].ParseToNullableString(), + map_goods_name = row["map_goods_name"].ParseToNullableString(), + map_spec_name = row["map_spec_name"].ParseToNullableString(), + map_goods_id = row["map_goods_id"].ParseToNullableString(), + map_sku_id = row["map_sku_id"].ParseToNullableString(), + map_send_address = row["map_send_address"].ParseToNullableString(), + transit_warehouse_id = row["transit_warehouse_id"].ParseToNullableString(), + 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(WXBuyMapInfoLst, 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 WXGetTransitOrder(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + if (!WXUserService.GetSign(inputData)) + return "{\"code\":999,\"msg\":\"校验失败\"}"; + var timeCalc = DateTime.Now; + var count = -1; + int page = RegexUtils.GetStringQuery(ref inputData, "page").ParseToInt(); + int page_size = RegexUtils.GetStringQuery(ref inputData, "page_size").ParseToInt(200); + string order_no = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "order_no"))?.Replace("'", "\\'"); + string order_sku_id = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "order_sku_id"))?.Replace("'", "\\'"); + string out_order_no = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "out_order_no"))?.Replace("'", "\\'"); + string pre_allocated_order_no = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "pre_allocated_order_no"))?.Replace("'", "\\'"); + string transfer_warehouse_status = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "transfer_warehouse_status"))?.Replace("'", "\\'"); + string not_count = RegexUtils.GetStringQuery(ref inputData, "not_count")?.Replace("'", "\\'"); + string is_admin = RegexUtils.GetStringQuery(ref inputData, "is_admin")?.Replace("'", "\\'"); + if (string.IsNullOrEmpty(order_no) && string.IsNullOrEmpty(out_order_no) && string.IsNullOrEmpty(order_sku_id) && is_admin != "true") + return "{\"code\":500,\"msg\":\"中转订单查询信息不能为空\"}"; + + try + { + var oms_wei_external_procurement_log_list = GetTransitOrderTable(page, page_size, order_no, order_sku_id, out_order_no, pre_allocated_order_no, transfer_warehouse_status, not_count, out count); + if (oms_wei_external_procurement_log_list != null) + { + + + JsonSerializerSettings jsonSetting = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }; + var data = JsonUtils.SerializeObjectToString(oms_wei_external_procurement_log_list, 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 + "}"; + } + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + + /// + /// 查询中转仓订单 + /// + public List GetTransitOrderTable( + int page, + int pageSize, + string orderNo, + string orderSkuId, + string outOrderNo, + string preAllocatedOrderNo, + string transferWarehouseStatus, + string not_count, out int count) + { + var timeCalc = DateTime.Now; + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + + + string sql = ""; + count = -1; + + sql = "SELECT COUNT(*) FROM `erp`.`oms_wei_external_procurement_log` WHERE 1=1"; + string where = ""; + if (!string.IsNullOrEmpty(orderNo)) + where += $" and order_no IN ('{orderNo.Replace(",", "','")}')"; + + if (!string.IsNullOrEmpty(orderSkuId)) + where += $" and order_sku_id IN ('{orderSkuId.Replace(",", "','")}')"; + + if (!string.IsNullOrEmpty(outOrderNo)) + where += $" and out_order_no IN ('{outOrderNo.Replace(",", "','")}')"; + + if (!string.IsNullOrEmpty(preAllocatedOrderNo)) + where += $" and pre_allocated_order_no IN ({preAllocatedOrderNo})"; + + if (!string.IsNullOrEmpty(transferWarehouseStatus)) + where += $" and transfer_warehouse_status IN ({transferWarehouseStatus})"; + sql += where; + sql += ";"; + + if (not_count == "false") + count = mySql.ExecuteRowCount(sql); + + DataTable dt; + if (count == 0) + { + dt = new DataTable(); + } + else + { + sql = "SELECT * FROM `erp`.`oms_wei_external_procurement_log` WHERE 1=1"; + sql += where; + sql += " order by id desc limit " + Math.Max(0, page - 1) * pageSize + "," + pageSize + ";"; + dt = mySql.ExecuteDataTable(sql); + } + mySql.Close(); + + if (dt != null) + { + List oms_wei_external_procurement_log_list = new List(); + + foreach (DataRow row in dt.Rows) + { + oms_wei_external_procurement_log_list.Add(new oms_wei_external_procurement_log() + { + id = row["id"].ParseToInt(), + buyer_account = row["buyer_account"].ParseToNullableString(), + order_no = row["order_no"].ParseToNullableString(), + order_sku_id = row["order_sku_id"].ParseToNullableString(), + out_amount = row["out_amount"].ParseToNullableInt(), + out_order_no = row["out_order_no"].ParseToNullableString(), + purchaser_note = row["purchaser_note"].ParseToNullableString(), + created_time = row["created_time"].ParseToNullableString().ParseToDateTime(), + express_1_company = row["express_1_company"].ParseToNullableString(), + express_1_waybill = row["express_1_waybill"].ParseToNullableString(), + express_2_company = row["express_2_company"].ParseToNullableString(), + express_2_waybill = row["express_2_waybill"].ParseToNullableString(), + order_code = row["order_code"].ParseToNullableString(), + order_platform_code = row["order_platform_code"].ParseToNullableString(), + pickup_time = row["pickup_time"].ParseToNullableString().ParseToDateTime(), + platform = row["platform"].ParseToNullableString(), + pre_allocated_order_no = row["pre_allocated_order_no"].ParseToNullableInt(), + raw_message = row["raw_message"].ParseToNullableString(), + refund_status = row["refund_status"].ParseToNullableString(), + transfer_warehouse_status = row["transfer_warehouse_status"].ParseToNullableInt(), + updated_time = row["updated_time"].ParseToNullableString().ParseToDateTime(), + is_transfer_ship = row["is_transfer_ship"].ParseToNullableInt(), + random_code = row["random_code"].ParseToNullableString(), + transfer_refund_status = row["transfer_refund_status"].ParseToNullableInt(), + order_void_status = row["order_void_status"].ParseToNullableInt(), + warehouse_status = row["warehouse_status"].ParseToNullableInt(), + inbound_time = row["inbound_time"].ParseToNullableString().ParseToDateTimeNullable(), + outbound_time = row["outbound_time"].ParseToNullableString().ParseToDateTimeNullable(), + has_reject = row["has_reject"].ParseToInt(), + + }); + } + return oms_wei_external_procurement_log_list; + + } + else + { + throw new Exception(mySql.Message); + } + return null; + } + + + /// + /// 修改中转仓订单信息(真实物流),临时补救 + /// + /// + /// + public string WXUpdateErpOrderExpress(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + if (!WXUserService.GetSign(inputData)) + return "{\"code\":999,\"msg\":\"校验失败\"}"; + var timeCalc = DateTime.Now; + + int page = RegexUtils.GetStringQuery(ref inputData, "page").ParseToInt(); + int page_size = RegexUtils.GetStringQuery(ref inputData, "page_size").ParseToInt(200); + string out_order_no = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "out_order_no"))?.Replace("'", "\\'"); + string express_1_company = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "express_1_company"))?.Replace("'", "\\'"); + string express_1_waybill = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "express_1_waybil"))?.Replace("'", "\\'"); + string refund_status = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "refund_status"))?.Replace("'", "\\'"); + if (string.IsNullOrEmpty(out_order_no)) + return "{\"code\":500,\"msg\":\"订单外部ID信息不能为空\"}"; + //if (string.IsNullOrEmpty(express_1_company)) + // return "{\"code\":500,\"msg\":\"物流公司不能为空\"}"; + //if (string.IsNullOrEmpty(express_1_waybill)) + // return "{\"code\":500,\"msg\":\"物流单号不能为空\"}"; + + if (string.IsNullOrEmpty(express_1_company) && string.IsNullOrEmpty(express_1_waybill) && string.IsNullOrEmpty(refund_status)) + return "{\"code\":500,\"msg\":\"修改信息不能为空\"}"; + + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + + string sql = ""; + var count = -1; + + sql = " update `erp`.`oms_wei_external_procurement_log` set "; + if (!string.IsNullOrEmpty(express_1_company)) + sql += " express_1_company='" + express_1_company + "',"; + if (!string.IsNullOrEmpty(express_1_waybill)) + sql += " express_1_waybill='" + express_1_waybill + "',"; + if (!string.IsNullOrEmpty(refund_status)) + sql += " refund_status='" + refund_status + "',"; + sql = sql.TrimEnd(','); + sql += " where out_order_no = '" + out_order_no + "';"; + + count = mySql.ExecuteAffectedRows(sql); + mySql.Close(); + + if (!string.IsNullOrEmpty(mySql.Message)) + { + return "{\"code\":500,\"msg\":\"" + mySql.Message + "\",\"affected_rows\":" + count + "}"; + } + return "{\"code\":200,\"msg\":\"success\",\"affected_rows\":" + count + "}"; + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + /// + /// 修改中转仓订单信息(取号状态),临时补救 + /// + /// + /// + public string WXUpdateErpAllocatedOrderNo(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + if (!WXUserService.GetSign(inputData)) + return "{\"code\":999,\"msg\":\"校验失败\"}"; + var timeCalc = DateTime.Now; + + int page = RegexUtils.GetStringQuery(ref inputData, "page").ParseToInt(); + int page_size = RegexUtils.GetStringQuery(ref inputData, "page_size").ParseToInt(200); + string out_order_no = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "out_order_no"))?.Replace("'", "\\'"); + string pre_allocated_order_no = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "pre_allocated_order_no"))?.Replace("'", "\\'"); + if (string.IsNullOrEmpty(out_order_no)) + return "{\"code\":500,\"msg\":\"订单外部ID信息不能为空\"}"; + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + + string sql = ""; + var count = -1; + + sql = " update `erp`.`oms_wei_external_procurement_log` set "; + if (!string.IsNullOrEmpty(pre_allocated_order_no)) + sql += " pre_allocated_order_no=" + pre_allocated_order_no + ","; + sql = sql.TrimEnd(','); + sql += " where out_order_no = '" + out_order_no + "';"; + + count = mySql.ExecuteAffectedRows(sql); + mySql.Close(); + + if (!string.IsNullOrEmpty(mySql.Message)) + { + return "{\"code\":500,\"msg\":\"" + mySql.Message + "\",\"affected_rows\":" + count + "}"; + } + return "{\"code\":200,\"msg\":\"success\",\"affected_rows\":" + count + "}"; + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + /// + /// 删除中转仓订单 临时补救,慎用 + /// + /// + /// + public string WXDelErpTransitWarehouseOrder(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + if (!WXUserService.GetSign(inputData)) + return "{\"code\":999,\"msg\":\"校验失败\"}"; + var timeCalc = DateTime.Now; + + string out_order_no = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "out_order_no"))?.Replace("'", "\\'"); + if (string.IsNullOrEmpty(out_order_no)) + return "{\"code\":500,\"msg\":\"订单外部ID信息不能为空\"}"; + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + + string sql = ""; + var count = -1; + + sql = " DELETE FROM `erp`.`oms_wei_external_procurement_log` WHERE out_order_no in ('" + out_order_no.Replace(",", "','") + "')"; + + count = mySql.ExecuteAffectedRows(sql); + mySql.Close(); + + if (!string.IsNullOrEmpty(mySql.Message)) + { + return "{\"code\":500,\"msg\":\"" + mySql.Message + "\",\"affected_rows\":" + count + "}"; + } + if (count == 0) + { + return "{\"code\":500,\"msg\":\"删除失败,订单不存在\",\"affected_rows\":" + count + "}"; + } + return "{\"code\":200,\"msg\":\"success\",\"affected_rows\":" + count + "}"; + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + /// + /// 修改订单软件备注 + /// + /// + /// + public string WXUpdateErpSoftRemark(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + if (!WXUserService.GetSign(inputData)) + return "{\"code\":999,\"msg\":\"校验失败\"}"; + var timeCalc = DateTime.Now; + + string order_id = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "order_id"))?.Replace("'", "\\'"); + string soft_remark = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "soft_remark"))?.Replace("'", "\\'"); + if (string.IsNullOrEmpty(order_id)) + return "{\"code\":500,\"msg\":\"订单ID不能为空\"}"; + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + + string sql = ""; + var count = -1; + + sql = " update erp.oms_wei_order set "; + if (soft_remark != null) + sql += " soft_remark='" + soft_remark + "',"; + sql = sql.TrimEnd(','); + sql += " where order_id = '" + order_id + "';"; + + count = mySql.ExecuteAffectedRows(sql); + mySql.Close(); + + if (!string.IsNullOrEmpty(mySql.Message)) + { + return "{\"code\":500,\"msg\":\"" + mySql.Message + "\",\"affected_rows\":" + count + "}"; + } + return "{\"code\":200,\"msg\":\"success\",\"affected_rows\":" + count + "}"; + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + public string WXUpdateErpColorFlag(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + if (!WXUserService.GetSign(inputData)) + return "{\"code\":999,\"msg\":\"校验失败\"}"; + var timeCalc = DateTime.Now; + + string order_id = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "order_id"))?.Replace("'", "\\'"); + string colour_flag = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "colour_flag"))?.Replace("'", "\\'"); + if (string.IsNullOrEmpty(order_id)) + return "{\"code\":500,\"msg\":\"订单ID不能为空\"}"; + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + + string sql = ""; + var count = -1; + + sql = " update erp.oms_wei_order set "; + if (colour_flag != null) + { + sql += " colour_flag=" + colour_flag + ","; + sql += " colour_flag_update_time='" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "',"; + } + sql = sql.TrimEnd(','); + sql += " where order_id = '" + order_id + "';"; + + count = mySql.ExecuteAffectedRows(sql); + mySql.Close(); + + if (!string.IsNullOrEmpty(mySql.Message)) + { + return "{\"code\":500,\"msg\":\"" + mySql.Message + "\",\"affected_rows\":" + count + "}"; + } + return "{\"code\":200,\"msg\":\"success\",\"affected_rows\":" + count + "}"; + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + public string WXUpdateErpOutAfterSaleStatus(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + if (!WXUserService.GetSign(inputData)) + return "{\"code\":999,\"msg\":\"校验失败\"}"; + var timeCalc = DateTime.Now; + + string order_id = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "order_id"))?.Replace("'", "\\'"); + if (string.IsNullOrEmpty(order_id)) + return "{\"code\":500,\"msg\":\"订单ID不能为空\"}"; + string out_after_sale_status = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "out_after_sale_status"))?.Replace("'", "\\'"); + if (out_after_sale_status == null) + return "{\"code\":500,\"msg\":\"售后状态不能为NULL\"}"; + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + + string sql = ""; + var count = -1; + + sql = " update erp.oms_wei_order set "; + if (out_after_sale_status != null) + { + if (out_after_sale_status == "" || out_after_sale_status == "NULL") + sql += " out_after_sale_status=NULL,"; + else + sql += " out_after_sale_status='" + out_after_sale_status + "',"; + } + sql = sql.TrimEnd(','); + sql += " where order_id = '" + order_id + "';"; + + count = mySql.ExecuteAffectedRows(sql); + mySql.Close(); + + if (!string.IsNullOrEmpty(mySql.Message)) + { + return "{\"code\":500,\"msg\":\"" + mySql.Message + "\",\"affected_rows\":" + count + "}"; + } + return "{\"code\":200,\"msg\":\"success\",\"affected_rows\":" + count + "}"; + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + public string WXAddMdyBuyerOrder(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + if (!WXUserService.GetSign(inputData)) + return "{\"code\":999,\"msg\":\"校验失败\"}"; + var timeCalc = DateTime.Now; + + string wx_order_id = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "wx_order_id"))?.Replace("'", "\\'"); + string wx_sku_id = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "wx_sku_id"))?.Replace("'", "\\'"); + string wx_send_type = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "wx_send_type"))?.Replace("'", "\\'"); + if (wx_send_type.IsNullOrEmpty()) + wx_send_type = "0"; + string TransitCreateTime = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "TransitCreateTime"))?.Replace("'", "\\'"); + string pre_allocated_order_no = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "pre_allocated_order_no"))?.Replace("'", "\\'"); + string buyerId = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "buyerId"))?.Replace("'", "\\'"); + string buyerName = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "buyerName"))?.Replace("'", "\\'"); + string pdd_order_sn = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "pdd_order_sn"))?.Replace("'", "\\'"); + string order_amount = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "order_amount"))?.Replace("'", "\\'"); + string order_time = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "order_time"))?.Replace("'", "\\'"); + string outExpressCompanyCode = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "outExpressCompanyCode"))?.Replace("'", "\\'"); + string tracking_number = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "tracking_number"))?.Replace("'", "\\'"); + string order_status_prompt = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "order_status_prompt"))?.Replace("'", "\\'"); + string after_sales_status = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "after_sales_status"))?.Replace("'", "\\'"); + string order_detail = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "order_detail"))?.Replace("'", "\\'"); + string wx_order_send_type = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "wx_order_send_type"))?.Replace("'", "\\'"); + if (string.IsNullOrEmpty(wx_order_send_type)) + wx_order_send_type = "1"; + if (string.IsNullOrEmpty(wx_order_id) || string.IsNullOrEmpty(pdd_order_sn)) + return "{\"code\":500,\"msg\":\"订单ID不能为空\"}"; + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + + string sql = ""; + var count = -1; + + sql = "select id from wxxd.order_pdd_buyer_order where order_sn='" + pdd_order_sn + "'"; + var id = mySql.ExecuteFirstInt(sql); + if (!string.IsNullOrEmpty(mySql.Message)) + { + mySql.Close(); + return "{\"code\":500,\"msg\":\"" + mySql.Message + "\"}"; + } + + //sql = "INSERT INTO wxxd.order_pdd_buyer_order (wx_order_id,wx_sku_id,TransitCreateTime,pre_allocated_order_no,buyerId,buyerName,order_sn,order_amount,order_time," + + // "outExpressCompanyCode,tracking_number,order_status_prompt,after_sales_status,order_detail)"; + //sql += "VALUES(@wx_order_id,@wx_sku_id,@TransitCreateTime,@pre_allocated_order_no,@buyerId,@buyerName,@pdd_order_sn,@order_amount,@order_time," + + // "@outExpressCompanyCode,@tracking_number,@order_status_prompt,@after_sales_status,@order_detail)"; + //sql += " ON DUPLICATE KEY UPDATE wx_order_id=VALUES(@wx_order_id),wx_sku_id=VALUES(@wx_sku_id),TransitCreateTime=VALUES(@TransitCreateTime)," + + // "pre_allocated_order_no=VALUES(@pre_allocated_order_no),buyerId=VALUES(@buyerId),buyerName=VALUES(@buyerName),order_amount=VALUES(@order_amount)," + + // "order_time=VALUES(@order_time),outExpressCompanyCode=VALUES(@outExpressCompanyCode),tracking_number=VALUES(@tracking_number),order_status_prompt=VALUES(@order_status_prompt)," + + // "after_sales_status=VALUES(@after_sales_status),order_detail=VALUES(@order_detail)"; + + if (id == 0) + { + sql = "INSERT INTO wxxd.order_pdd_buyer_order (wx_order_id,wx_sku_id,wx_send_type,TransitCreateTime,pre_allocated_order_no,buyerId,buyerName,order_sn,order_amount,order_time," + + "outExpressCompanyCode,tracking_number,order_status_prompt,after_sales_status,order_detail)"; + sql += "VALUES(@wx_order_id,@wx_sku_id,@wx_send_type,@TransitCreateTime,@pre_allocated_order_no,@buyerId,@buyerName,@pdd_order_sn,@order_amount,@order_time," + + "@outExpressCompanyCode,@tracking_number,@order_status_prompt,@after_sales_status,@order_detail);"; + } + else + { + sql = "UPDATE wxxd.order_pdd_buyer_order SET "; + if (!string.IsNullOrEmpty(wx_order_id)) + sql += " wx_order_id=@wx_order_id,"; + if (!string.IsNullOrEmpty(wx_sku_id)) + sql += " wx_sku_id=@wx_sku_id,"; + if (!string.IsNullOrEmpty(wx_send_type)) + sql += " wx_send_type=@wx_send_type,"; + if (!string.IsNullOrEmpty(TransitCreateTime)) + sql += " TransitCreateTime=@TransitCreateTime,"; + if (!string.IsNullOrEmpty(pre_allocated_order_no)) + sql += " pre_allocated_order_no=@pre_allocated_order_no,"; + if (!string.IsNullOrEmpty(buyerId)) + sql += " buyerId=@buyerId,"; + if (!string.IsNullOrEmpty(buyerName)) + sql += " buyerName=@buyerName,"; + if (!string.IsNullOrEmpty(order_amount)) + sql += " order_amount=@order_amount,"; + if (!string.IsNullOrEmpty(order_time)) + sql += " order_time=@order_time,"; + if (!string.IsNullOrEmpty(outExpressCompanyCode)) + sql += " outExpressCompanyCode=@outExpressCompanyCode,"; + if (!string.IsNullOrEmpty(tracking_number)) + sql += " tracking_number=@tracking_number,"; + if (!string.IsNullOrEmpty(order_status_prompt)) + sql += " order_status_prompt=@order_status_prompt,"; + if (!string.IsNullOrEmpty(after_sales_status)) + sql += " after_sales_status=@after_sales_status,"; + if (!string.IsNullOrEmpty(order_detail)) + sql += " order_detail=@order_detail,"; + sql = sql.TrimEnd(','); + sql += " where order_sn=@pdd_order_sn"; + } + //260705-105706954352823 + + + List paramLst = new List(); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "wx_order_id", Value = wx_order_id, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "wx_sku_id", Value = wx_sku_id, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.Int32, ParameterName = "wx_send_type", Value = wx_send_type.ParseToInt(), }); + paramLst.Add(new MySqlParameter() { DbType = DbType.DateTime, ParameterName = "TransitCreateTime", Value = TransitCreateTime.ParseToDateTime(), }); + paramLst.Add(new MySqlParameter() { DbType = DbType.Int32, ParameterName = "pre_allocated_order_no", Value = pre_allocated_order_no.ParseToInt(), }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "buyerId", Value = buyerId, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "buyerName", Value = buyerName, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "pdd_order_sn", Value = pdd_order_sn, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.Int32, ParameterName = "order_amount", Value = order_amount.ParseToNullableInt(), }); + paramLst.Add(new MySqlParameter() { DbType = DbType.Int64, ParameterName = "order_time", Value = order_time.ParseToLong(), }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "outExpressCompanyCode", Value = outExpressCompanyCode, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "tracking_number", Value = tracking_number, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "order_status_prompt", Value = order_status_prompt, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.Int32, ParameterName = "after_sales_status", Value = after_sales_status.ParseToInt(), }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "order_detail", Value = order_detail, }); + //sql = " update `wxxd`.`order_pdd_buyer_order` set "; + //if (!string.IsNullOrEmpty(soft_remark)) + // sql += " soft_remark=" + soft_remark + ","; + //sql = sql.TrimEnd(','); + //sql += " where order_id = '" + wx_order_id + "';"; + + count = mySql.ExecuteAffectedRows(sql, paramLst.ToArray()); + mySql.Close(); + + if (!string.IsNullOrEmpty(mySql.Message)) + { + return "{\"code\":500,\"msg\":\"" + mySql.Message + "\",\"affected_rows\":" + count + "}"; + } + return "{\"code\":200,\"msg\":\"success\",\"affected_rows\":" + count + "}"; + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + public string WXGetBuyerOrderList(string inputData, bool isDetail = false) + { + if (!string.IsNullOrEmpty(inputData)) + { + if (!WXUserService.GetSign(inputData)) + return "{\"code\":999,\"msg\":\"校验失败\"}"; + var timeCalc = DateTime.Now; + + var wx_order_id_in = RegexUtils.GetStringQuery(ref inputData, "wx_order_id_in")?.Replace("'", "\\'"); + var buyer_order_sn_in = RegexUtils.GetStringQuery(ref inputData, "buyer_order_sn_in")?.Replace("'", "\\'"); + if (wx_order_id_in.IsNullOrEmpty() && string.IsNullOrEmpty(buyer_order_sn_in)) + { + return "{\"code\":500,\"msg\":\"未指定订单\"}"; + } + var sort_type = RegexUtils.GetStringQuery(ref inputData, "sort_type")?.Replace("'", "\\'"); + var is_not_count = RegexUtils.GetStringQuery(ref inputData, "is_not_count") != "false"; + + int page = RegexUtils.GetStringQuery(ref inputData, "page").ParseToInt(); + int page_size = RegexUtils.GetStringQuery(ref inputData, "page_size").ParseToInt(500); + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + + string sql = "SELECT COUNT(id) FROM wxxd.order_pdd_buyer_order o WHERE 1=1 "; + + string where = ""; + if (!string.IsNullOrWhiteSpace(wx_order_id_in)) + where += " and o.wx_order_id in ('" + wx_order_id_in.Replace(",", "','") + "')"; + if (!string.IsNullOrWhiteSpace(buyer_order_sn_in)) + where += " and o.order_sn in ('" + buyer_order_sn_in.Replace(",", "','") + "')"; + sql += where; + + var count = 0; + if (!is_not_count) + count = mySql.ExecuteRowCount(sql); + + DataTable dt; + if (count == 0 && !is_not_count) + { + dt = new DataTable(); + } + else + { + sql = "SELECT o.* FROM" + + " wxxd.order_pdd_buyer_order o " + + " WHERE 1=1"; + + //where子句 + sql += where; + + if (sort_type == "asc") + sql += " ORDER BY o.id ASC"; + else + sql += " ORDER BY o.id DESC"; + sql += " LIMIT " + Math.Max(page - 1, 0) * page_size + "," + page_size; + dt = mySql.ExecuteDataTable(sql); + } + + mySql.Close(); + if (dt != null) + { + try + { + List buyerOrderList = new List(); + foreach (DataRow row in dt.Rows) + { + order_pdd_buyer_order order = new order_pdd_buyer_order + { + id = row["id"].ParseToLong(), + add_time = row["add_time"].ParseToString().ParseToDateTime(), + after_sales_status = row["after_sales_status"].ParseToNullableInt(), + buyerId = row["buyerId"].ParseToString(), + buyerName = row["buyerName"].ParseToString(), + mdy_time = row["mdy_time"].ParseToString().ParseToDateTime(), + order_amount = row["order_amount"].ParseToNullableInt(), + order_detail = row["order_detail"].ParseToString(), + order_sn = row["order_sn"].ParseToString(), + order_status_prompt = row["order_status_prompt"].ParseToString(), + order_time = row["order_time"].ParseToNullableLong(), + outExpressCompanyCode = row["outExpressCompanyCode"].ParseToString(), + pre_allocated_order_no = row["pre_allocated_order_no"].ParseToNullableInt(), + tracking_number = row["tracking_number"].ParseToString(), + TransitCreateTime = row["TransitCreateTime"].ParseToString().ParseToDateTime(), + wx_order_id = row["wx_order_id"].ParseToString(), + wx_sku_id = row["wx_sku_id"].ParseToString(), + wx_send_type = row["wx_send_type"].ParseToInt(), + }; + buyerOrderList.Add(order); + } + JsonSerializerSettings jsonSetting = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }; + var data = JsonUtils.SerializeObjectToString(buyerOrderList, 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 WXAddMdyBuyerAfterSale(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + if (!WXUserService.GetSign(inputData)) + return "{\"code\":999,\"msg\":\"校验失败\"}"; + var timeCalc = DateTime.Now; + + string wx_order_id = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "wx_order_id"))?.Replace("'", "\\'"); + string wx_sku_id = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "wx_sku_id"))?.Replace("'", "\\'"); + string wx_send_type = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "wx_send_type"))?.Replace("'", "\\'"); + if (wx_send_type.IsNullOrEmpty()) + wx_send_type = "0"; + string TransitCreateTime = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "TransitCreateTime"))?.Replace("'", "\\'"); + string pre_allocated_order_no = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "pre_allocated_order_no"))?.Replace("'", "\\'"); + string buyerId = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "buyerId"))?.Replace("'", "\\'"); + string buyerName = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "buyerName"))?.Replace("'", "\\'"); + string orderSn = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "orderSn"))?.Replace("'", "\\'"); + string afterSalesId = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "afterSalesId"))?.Replace("'", "\\'"); + string orderAmount = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "orderAmount"))?.Replace("'", "\\'"); + string orderDate = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "orderDate"))?.Replace("'", "\\'"); + string order_detail = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "order_detail"))?.Replace("'", "\\'"); + string refundAmount = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "refundAmount"))?.Replace("'", "\\'"); + string statusText = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "statusText"))?.Replace("'", "\\'"); + string afterSaleAddress = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "afterSaleAddress"))?.Replace("'", "\\'"); + string is_mdy = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "is_mdy"))?.Replace("'", "\\'"); + if (string.IsNullOrEmpty(wx_order_id) || string.IsNullOrEmpty(orderSn) || string.IsNullOrEmpty(afterSalesId)) + return "{\"code\":500,\"msg\":\"订单ID不能为空\"}"; + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + + string sql = ""; + var count = -1; + + sql = "select id from wxxd.order_pdd_buyer_after_sale where afterSalesId='" + afterSalesId + "'"; + var id = mySql.ExecuteFirstInt(sql); + if (!string.IsNullOrEmpty(mySql.Message)) + { + mySql.Close(); + return "{\"code\":500,\"msg\":\"" + mySql.Message + "\"}"; + } + + if (id == 0 && is_mdy != "true") + { + sql = "INSERT INTO wxxd.order_pdd_buyer_after_sale (wx_order_id,wx_sku_id,wx_send_type,TransitCreateTime,pre_allocated_order_no,buyerId,buyerName,orderSn,afterSalesId,orderAmount,orderDate," + + "refundAmount,statusText,afterSaleAddress,order_detail)"; + sql += "VALUES(@wx_order_id,@wx_sku_id,@wx_send_type,@TransitCreateTime,@pre_allocated_order_no,@buyerId,@buyerName,@orderSn,@afterSalesId,@orderAmount,@orderDate," + + "@refundAmount,@statusText,@afterSaleAddress,@order_detail);"; + } + else + { + sql = "UPDATE wxxd.order_pdd_buyer_after_sale SET "; + if (!string.IsNullOrEmpty(wx_order_id)) + sql += " wx_order_id=@wx_order_id,"; + if (!string.IsNullOrEmpty(wx_sku_id)) + sql += " wx_sku_id=@wx_sku_id,"; + if (!string.IsNullOrEmpty(wx_send_type)) + sql += " wx_send_type=@wx_send_type,"; + if (!string.IsNullOrEmpty(TransitCreateTime)) + sql += " TransitCreateTime=@TransitCreateTime,"; + if (!string.IsNullOrEmpty(pre_allocated_order_no)) + sql += " pre_allocated_order_no=@pre_allocated_order_no,"; + if (!string.IsNullOrEmpty(buyerId)) + sql += " buyerId=@buyerId,"; + if (!string.IsNullOrEmpty(buyerName)) + sql += " buyerName=@buyerName,"; + if (!string.IsNullOrEmpty(orderSn)) + sql += " orderSn=@orderSn,"; + if (!string.IsNullOrEmpty(orderAmount)) + sql += " orderAmount=@orderAmount,"; + if (!string.IsNullOrEmpty(refundAmount)) + sql += " refundAmount=@refundAmount,"; + if (!string.IsNullOrEmpty(statusText)) + sql += " statusText=@statusText,"; + if (!string.IsNullOrEmpty(orderDate)) + sql += " orderDate=@orderDate,"; + if (!string.IsNullOrEmpty(afterSaleAddress)) + sql += " afterSaleAddress=@afterSaleAddress,"; + + if (!string.IsNullOrEmpty(order_detail)) + sql += " order_detail=@order_detail,"; + sql = sql.TrimEnd(','); + sql += " where afterSalesId=@afterSalesId"; + } + + List paramLst = new List(); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "wx_order_id", Value = wx_order_id, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "wx_sku_id", Value = wx_sku_id, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.Int32, ParameterName = "wx_send_type", Value = wx_send_type.ParseToInt(), }); + paramLst.Add(new MySqlParameter() { DbType = DbType.DateTime, ParameterName = "TransitCreateTime", Value = TransitCreateTime.ParseToDateTime(), }); + paramLst.Add(new MySqlParameter() { DbType = DbType.Int32, ParameterName = "pre_allocated_order_no", Value = pre_allocated_order_no.ParseToInt(), }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "buyerId", Value = buyerId, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "buyerName", Value = buyerName, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "statusText", Value = statusText, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "orderSn", Value = orderSn, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "afterSalesId", Value = afterSalesId, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.Int32, ParameterName = "refundAmount", Value = refundAmount.ParseToNullableInt(), }); + paramLst.Add(new MySqlParameter() { DbType = DbType.Int32, ParameterName = "orderAmount", Value = orderAmount.ParseToNullableInt(), }); + paramLst.Add(new MySqlParameter() { DbType = DbType.Int64, ParameterName = "orderDate", Value = orderDate.ParseToLong(), }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "afterSaleAddress", Value = afterSaleAddress, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "order_detail", Value = order_detail, }); + + count = mySql.ExecuteAffectedRows(sql, paramLst.ToArray()); + mySql.Close(); + + if (!string.IsNullOrEmpty(mySql.Message)) + { + return "{\"code\":500,\"msg\":\"" + mySql.Message + "\",\"affected_rows\":" + count + "}"; + } + return "{\"code\":200,\"msg\":\"success\",\"affected_rows\":" + count + "}"; + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + public string WXGetBuyerAfterSaleList(string inputData, bool isDetail = false) + { + if (!string.IsNullOrEmpty(inputData)) + { + if (!WXUserService.GetSign(inputData)) + return "{\"code\":999,\"msg\":\"校验失败\"}"; + var timeCalc = DateTime.Now; + + var wx_order_id_in = RegexUtils.GetStringQuery(ref inputData, "wx_order_id_in")?.Replace("'", "\\'"); + var buyer_order_sn_in = RegexUtils.GetStringQuery(ref inputData, "buyer_order_sn_in")?.Replace("'", "\\'"); + if (wx_order_id_in.IsNullOrEmpty() && string.IsNullOrEmpty(buyer_order_sn_in)) + { + return "{\"code\":500,\"msg\":\"未指定订单\"}"; + } + var sort_type = RegexUtils.GetStringQuery(ref inputData, "sort_type")?.Replace("'", "\\'"); + var is_not_count = RegexUtils.GetStringQuery(ref inputData, "is_not_count") != "false"; + + int page = RegexUtils.GetStringQuery(ref inputData, "page").ParseToInt(); + int page_size = RegexUtils.GetStringQuery(ref inputData, "page_size").ParseToInt(500); + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + + string sql = "SELECT COUNT(id) FROM wxxd.order_pdd_buyer_after_sale o WHERE 1=1 "; + + string where = ""; + if (!string.IsNullOrWhiteSpace(wx_order_id_in)) + where += " and o.wx_order_id in ('" + wx_order_id_in.Replace(",", "','") + "')"; + if (!string.IsNullOrWhiteSpace(buyer_order_sn_in)) + where += " and o.order_sn in ('" + buyer_order_sn_in.Replace(",", "','") + "')"; + sql += where; + + var count = 0; + if (!is_not_count) + count = mySql.ExecuteRowCount(sql); + + DataTable dt; + if (count == 0 && !is_not_count) + { + dt = new DataTable(); + } + else + { + sql = "SELECT o.* FROM" + + " wxxd.order_pdd_buyer_after_sale o " + + " WHERE 1=1"; + + //where子句 + sql += where; + + if (sort_type == "asc") + sql += " ORDER BY o.id ASC"; + else + sql += " ORDER BY o.id DESC"; + sql += " LIMIT " + Math.Max(page - 1, 0) * page_size + "," + page_size; + dt = mySql.ExecuteDataTable(sql); + } + + mySql.Close(); + if (dt != null) + { + try + { + List buyerAfterSaleLst = new List(); + foreach (DataRow row in dt.Rows) + { + order_pdd_buyer_after_sale afterSale = new order_pdd_buyer_after_sale + { + id = row["id"].ParseToLong(), + add_time = row["add_time"].ParseToString().ParseToDateTime(), + afterSalesId = row["afterSalesId"].ParseToString(), + buyerId = row["buyerId"].ParseToString(), + buyerName = row["buyerName"].ParseToString(), + mdy_time = row["mdy_time"].ParseToString().ParseToDateTime(), + orderAmount = row["orderAmount"].ParseToNullableInt(), + order_detail = row["order_detail"].ParseToString(), + orderSn = row["orderSn"].ParseToString(), + orderDate = row["orderDate"].ParseToNullableInt(), + refundAmount = row["refundAmount"].ParseToNullableInt(), + statusText = row["statusText"].ParseToString(), + afterSaleAddress = row["afterSaleAddress"].ParseToString(), + pre_allocated_order_no = row["pre_allocated_order_no"].ParseToNullableInt(), + TransitCreateTime = row["TransitCreateTime"].ParseToString().ParseToDateTime(), + wx_order_id = row["wx_order_id"].ParseToString(), + wx_sku_id = row["wx_sku_id"].ParseToString(), + wx_send_type = row["wx_send_type"].ParseToInt(), + }; + buyerAfterSaleLst.Add(afterSale); + } + JsonSerializerSettings jsonSetting = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }; + var data = JsonUtils.SerializeObjectToString(buyerAfterSaleLst, 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 WXGetTransitWarehouseAfterSaleList(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + if (!WXUserService.GetSign(inputData)) + return "{\"code\":999,\"msg\":\"校验失败\"}"; + var timeCalc = DateTime.Now; + + var wx_order_id_in = RegexUtils.GetStringQuery(ref inputData, "wx_order_id_in")?.Replace("'", "\\'"); + var buyer_order_sn_in = RegexUtils.GetStringQuery(ref inputData, "buyer_order_sn_in")?.Replace("'", "\\'"); + if (wx_order_id_in.IsNullOrEmpty() && string.IsNullOrEmpty(buyer_order_sn_in)) + { + return "{\"code\":500,\"msg\":\"未指定订单\"}"; + } + var sort_type = RegexUtils.GetStringQuery(ref inputData, "sort_type")?.Replace("'", "\\'"); + var is_not_count = RegexUtils.GetStringQuery(ref inputData, "is_not_count") != "false"; + + int page = RegexUtils.GetStringQuery(ref inputData, "page").ParseToInt(); + int page_size = RegexUtils.GetStringQuery(ref inputData, "page_size").ParseToInt(1000); + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + + string sql = "SELECT COUNT(id) FROM erp.oms_wei_external_procurement_after_sale o WHERE 1=1 "; + + string where = ""; + if (!string.IsNullOrWhiteSpace(wx_order_id_in)) + where += " and o.order_no in ('" + wx_order_id_in.Replace(",", "','") + "')"; + if (!string.IsNullOrWhiteSpace(buyer_order_sn_in)) + where += " and o.order_code in ('" + buyer_order_sn_in.Replace(",", "','") + "')"; + sql += where; + + var count = 0; + if (!is_not_count) + count = mySql.ExecuteRowCount(sql); + + DataTable dt; + if (count == 0 && !is_not_count) + { + dt = new DataTable(); + } + else + { + sql = "SELECT o.* FROM" + + " erp.oms_wei_external_procurement_after_sale o " + + " WHERE 1=1"; + + //where子句 + sql += where; + + if (sort_type == "asc") + sql += " ORDER BY o.id ASC"; + else + sql += " ORDER BY o.id DESC"; + sql += " LIMIT " + Math.Max(page - 1, 0) * page_size + "," + page_size; + dt = mySql.ExecuteDataTable(sql); + } + + mySql.Close(); + if (dt != null) + { + try + { + List refundItemList = new List(); + foreach (DataRow row in dt.Rows) + { + oms_wei_external_procurement_after_sale_info order = new oms_wei_external_procurement_after_sale_info + { + id = row["id"].ParseToLong(), + order_no = row["order_no"].ParseToString(), + order_code = row["order_code"].ParseToString(), + inbound_time = row["inbound_time"].ParseToString().ParseToDateTimeNullable(), + outbound_time = row["outbound_time"].ParseToString().ParseToDateTimeNullable(), + account_user = row["account_user"].ParseToString(), + after_sale_no = row["after_sale_no"].ParseToString(), + created_time = row["created_time"].ParseToString().ParseToDateTimeNullable(), + create_user = row["create_user"].ParseToString(), + downstream_express_code = row["downstream_express_code"].ParseToString(), + downstream_waybill = row["downstream_waybill"].ParseToString(), + external_order_no = row["external_order_no"].ParseToString(), + raw_message = row["raw_message"].ParseToString(), + recipient_name = row["recipient_name"].ParseToString(), + recipient_phone = row["recipient_phone"].ParseToString(), + refund_city = row["refund_city"].ParseToString(), + refund_county = row["refund_county"].ParseToString(), + refund_detail_address = row["refund_detail_address"].ParseToString(), + refund_province = row["refund_province"].ParseToString(), + refund_waybill = row["refund_waybill"].ParseToString(), + return_express_company = row["return_express_company"].ParseToString(), + return_or_exchange = row["return_or_exchange"].ParseToNullableInt(), + status = row["status"].ParseToNullableInt(), + updated_time = row["updated_time"].ParseToString().ParseToDateTimeNullable(), + update_user = row["update_user"].ParseToString(), + warehouse_status = row["warehouse_status"].ParseToNullableInt(), + }; + refundItemList.Add(order); + } + JsonSerializerSettings jsonSetting = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }; + var data = JsonUtils.SerializeObjectToString(refundItemList, 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 WXUpdateAbnormalTransitOrder(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + if (!WXUserService.GetSign(inputData)) + return "{\"code\":999,\"msg\":\"校验失败\"}"; + + var out_order_no = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "out_order_no"))?.Replace("'", "\\'"); + var order_no = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "order_no"))?.Replace("'", "\\'"); + var order_sku_id = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "order_sku_id"))?.Replace("'", "\\'"); + var buyer_account = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "buyer_account"))?.Replace("'", "\\'"); + var out_amount = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "out_amount"))?.Replace("'", "\\'"); + var purchaser_note = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "purchaser_note"))?.Replace("'", "\\'"); + var refund_status = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "refund_status"))?.Replace("'", "\\'"); + var old_out_order_no = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "old_out_order_no"))?.Replace("'", "\\'"); + var old_order_no = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "old_order_no"))?.Replace("'", "\\'"); + var old_order_sku_id = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "old_order_sku_id"))?.Replace("'", "\\'"); + var old_buyer_account = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "old_buyer_account"))?.Replace("'", "\\'"); + var old_out_amount = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "old_out_amount"))?.Replace("'", "\\'"); + var old_purchaser_note = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "old_purchaser_note"))?.Replace("'", "\\'"); + var old_refund_status = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "old_refund_status"))?.Replace("'", "\\'"); + var order_code = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "order_code"))?.Replace("'", "\\'"); + if (order_code.IsNullOrEmpty() || old_purchaser_note.IsNullOrEmpty() || old_out_amount.ParseToInt().IsNullOrZero() || old_buyer_account.IsNullOrEmpty() || old_order_no.IsNullOrEmpty() || old_out_order_no.IsNullOrEmpty() || + purchaser_note.IsNullOrEmpty() || out_amount.ParseToInt().IsNullOrZero() || buyer_account.IsNullOrEmpty() || order_no.IsNullOrEmpty() || out_order_no.IsNullOrEmpty()) + { + return "{\"code\":500,\"msg\":\"异常单记录信息不完整\",\"affected_rows\":" + 0 + "}"; + } + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn, true); + + string sql; + + sql = "INSERT INTO wxxd.order_abnormal_transit_order_rebuy_record (out_order_no,order_no,order_sku_id,buyer_account,out_amount,purchaser_note,refund_status,order_code) "; + sql += " VALUES('" + old_out_order_no + "','" + old_order_no + "','" + old_order_sku_id + "','" + old_buyer_account + "'," + old_out_amount + ",'" + + old_purchaser_note + "','" + old_refund_status + "','" + order_code + "')"; + var rows = mySql.ExecuteAffectedRows(sql); + if (!mySql.Message.IsNullOrEmpty()) + { + mySql.RollBack(); + mySql.Close(); + return "{\"code\":500,\"msg\":\"" + mySql.Message + "\",\"affected_rows\":" + rows + "}"; + } + if (rows == 0) + { + mySql.RollBack(); + mySql.Close(); + return "{\"code\":500,\"msg\":\"创建异常单重拍记录失败\",\"affected_rows\":" + rows + "}"; + } + + sql = "UPDATE erp.oms_wei_external_procurement_log SET "; + sql += " out_order_no='" + out_order_no + "',"; + sql += " order_no='" + order_no + "',"; + sql += " order_sku_id='" + order_sku_id + "',"; + sql += " buyer_account='" + buyer_account + "',"; + sql += " out_amount=" + out_amount + ","; + sql += " purchaser_note='" + purchaser_note + "',"; + sql += " refund_status='" + refund_status + "',"; + sql = sql.TrimEnd(','); + sql += " WHERE order_code='" + order_code + "' AND order_no='" + old_order_no + "';"; + rows = mySql.ExecuteAffectedRows(sql); + if (!mySql.Message.IsNullOrEmpty()) + { + mySql.RollBack(); + mySql.Close(); + return "{\"code\":500,\"msg\":\"" + mySql.Message + "\",\"affected_rows\":" + rows + "}"; + } + if (rows == 0) + { + mySql.RollBack(); + mySql.Close(); + return "{\"code\":500,\"msg\":\"更新异常单拍单失败\",\"affected_rows\":" + rows + "}"; + } + mySql.Commit(); + mySql.Close(); + return "{\"code\":200,\"msg\":\"success\",\"affected_rows\":" + rows + "}"; + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + + /// + /// 订单拒收状态维护 + /// + /// + /// + public string WXUpdateTransitOrderRejectStatus(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + if (!WXUserService.GetSign(inputData)) + return "{\"code\":999,\"msg\":\"校验失败\"}"; + + var order_no = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "order_no"))?.Replace("'", "\\'"); + var order_sku_id = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "order_sku_id"))?.Replace("'", "\\'"); + var order_code = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "order_code"))?.Replace("'", "\\'"); + var has_reject = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "has_reject"))?.Replace("'", "\\'"); + if (order_code.IsNullOrEmpty() && (order_no.IsNullOrEmpty() || order_sku_id.IsNullOrEmpty())) + { + return "{\"code\":500,\"msg\":\"拒收信息不完整\",\"affected_rows\":" + 0 + "}"; + } + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn, true); + + string sql; + + sql = "UPDATE erp.oms_wei_external_procurement_log SET "; + sql += " has_reject=" + has_reject + ","; + sql = sql.TrimEnd(','); + if (!order_code.IsNullOrEmpty()) + sql += " WHERE order_code='" + order_code + "' AND order_no='" + order_code + "';"; + else + sql += " WHERE order_no='" + order_no + "' AND order_sku_id='" + order_sku_id + "';"; + var rows = mySql.ExecuteAffectedRows(sql); + if (!mySql.Message.IsNullOrEmpty()) + { + mySql.RollBack(); + mySql.Close(); + return "{\"code\":500,\"msg\":\"" + mySql.Message + "\",\"affected_rows\":" + rows + "}"; + } + if (rows == 0) + { + mySql.RollBack(); + mySql.Close(); + return "{\"code\":500,\"msg\":\"更新拒收状态失败,未找到记录\",\"affected_rows\":" + rows + "}"; + } + mySql.Commit(); + mySql.Close(); + return "{\"code\":200,\"msg\":\"success\",\"affected_rows\":" + rows + "}"; + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + + public string WXAddOrderItemExtInfo(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + if (!WXUserService.GetSign(inputData)) + return "{\"code\":999,\"msg\":\"校验失败\"}"; + var timeCalc = DateTime.Now; + + string order_id = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "wx_order_id"))?.Replace("'", "\\'"); + string sku_id = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "wx_sku_id"))?.Replace("'", "\\'"); + string out_order_id = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "out_order_id"))?.Replace("'", "\\'"); + string shop_app_id = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "shop_app_id"))?.Replace("'", "\\'"); + string shop_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "shop_name"))?.Replace("'", "\\'"); + string buy_type = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "buy_type"))?.Replace("'", "\\'"); + string abnormal_text = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "abnormal_text"))?.Replace("'", "\\'"); + string flag = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "flag"))?.Replace("'", "\\'"); + string label = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "label"))?.Replace("'", "\\'"); + string remark = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "remark"))?.Replace("'", "\\'"); + string after_sale_user_delivery_address = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "after_sale_user_delivery_address"))?.Replace("'", "\\'"); + + if (string.IsNullOrEmpty(order_id) || string.IsNullOrEmpty(sku_id)) + return "{\"code\":500,\"msg\":\"订单ID不能为空\"}"; + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + + string sql = ""; + var count = -1; + + sql = "select id from wxxd.order_item_ext where order_id='" + order_id + "' and sku_id='" + sku_id + "'"; + var id = mySql.ExecuteFirstInt(sql); + if (!string.IsNullOrEmpty(mySql.Message)) + { + mySql.Close(); + return "{\"code\":500,\"msg\":\"" + mySql.Message + "\"}"; + } + if (id > 0) + { + mySql.Close(); + return "{\"code\":500,\"msg\":\"订单已存在\"}"; + } + + sql = "INSERT INTO wxxd.order_item_ext (order_id,sku_id,out_order_id,shop_app_id,shop_name,buy_type,abnormal_text,flag,label,remark,after_sale_user_delivery_address)"; + sql += "VALUES(@order_id,@sku_id,@out_order_id,@shop_app_id,@shop_name,@buy_type,@abnormal_text,@flag,@label,@remark,@after_sale_user_delivery_address);"; + + List paramLst = new List(); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "order_id", Value = order_id, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "sku_id", Value = sku_id, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "out_order_id", Value = out_order_id, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "shop_app_id", Value = shop_app_id, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "shop_name", Value = shop_name, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "buy_type", Value = buy_type, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "abnormal_text", Value = abnormal_text, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.Int32, ParameterName = "flag", Value = flag, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "label", Value = label, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "remark", Value = remark, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "after_sale_user_delivery_address", Value = after_sale_user_delivery_address, }); + + count = mySql.ExecuteAffectedRows(sql, paramLst.ToArray()); + mySql.Close(); + + if (!string.IsNullOrEmpty(mySql.Message)) + { + return "{\"code\":500,\"msg\":\"" + mySql.Message + "\",\"affected_rows\":" + count + "}"; + } + return "{\"code\":200,\"msg\":\"success\",\"affected_rows\":" + count + "}"; + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + public string WXMdyOrderItemExtInfo(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + if (!WXUserService.GetSign(inputData)) + return "{\"code\":999,\"msg\":\"校验失败\"}"; + var timeCalc = DateTime.Now; + + string order_id = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "wx_order_id"))?.Replace("'", "\\'"); + string sku_id = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "wx_sku_id"))?.Replace("'", "\\'"); + string out_order_id = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "out_order_id"))?.Replace("'", "\\'"); + string shop_app_id = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "shop_app_id"))?.Replace("'", "\\'"); + string shop_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "shop_name"))?.Replace("'", "\\'"); + string buy_type = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "buy_type"))?.Replace("'", "\\'"); + string abnormal_text = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "abnormal_text"))?.Replace("'", "\\'"); + string flag = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "flag"))?.Replace("'", "\\'"); + string label = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "label"))?.Replace("'", "\\'"); + string remark = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "remark"))?.Replace("'", "\\'"); + string after_sale_user_delivery_address = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "after_sale_user_delivery_address"))?.Replace("'", "\\'"); + + if (string.IsNullOrEmpty(order_id)) + return "{\"code\":500,\"msg\":\"订单ID不能为空\"}"; + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + + string sql = "UPDATE wxxd.order_item_ext SET "; + if (!string.IsNullOrEmpty(shop_app_id)) + sql += " shop_app_id=@shop_app_id,"; + if (!string.IsNullOrEmpty(out_order_id)) + sql += " out_order_id=@out_order_id,"; + if (!string.IsNullOrEmpty(shop_name)) + sql += " shop_name=@shop_name,"; + if (buy_type != null) + sql += " buy_type=@buy_type,"; + if (abnormal_text != null) + sql += " abnormal_text=@abnormal_text,"; + if (!string.IsNullOrEmpty(flag)) + sql += " flag=@flag,"; + if (label != null) + sql += " label=@label,"; + if (remark != null) + sql += " remark=@remark,"; + if (!string.IsNullOrEmpty(after_sale_user_delivery_address)) + sql += " after_sale_user_delivery_address=@after_sale_user_delivery_address,"; + sql = sql.TrimEnd(','); + sql += " where 1=1"; + if (!string.IsNullOrEmpty(order_id)) + sql += " and order_id=@order_id"; + if (!string.IsNullOrEmpty(sku_id)) + sql += " and sku_id=@sku_id"; + + List paramLst = new List(); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "order_id", Value = order_id, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "sku_id", Value = sku_id, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "out_order_id", Value = out_order_id, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "shop_app_id", Value = shop_app_id, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "shop_name", Value = shop_name, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "buy_type", Value = buy_type, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "abnormal_text", Value = abnormal_text, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.Int32, ParameterName = "flag", Value = flag, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "label", Value = label, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "remark", Value = remark, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "after_sale_user_delivery_address", Value = after_sale_user_delivery_address, }); + + var count = mySql.ExecuteAffectedRows(sql, paramLst.ToArray()); + mySql.Close(); + + if (!string.IsNullOrEmpty(mySql.Message)) + { + return "{\"code\":500,\"msg\":\"" + mySql.Message + "\",\"affected_rows\":" + count + "}"; + } + return "{\"code\":200,\"msg\":\"success\",\"affected_rows\":" + count + "}"; + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + public string WXGetOrderItemExtInfoList(string inputData, bool isDetail = false) + { + if (!string.IsNullOrEmpty(inputData)) + { + if (!WXUserService.GetSign(inputData)) + return "{\"code\":999,\"msg\":\"校验失败\"}"; + var timeCalc = DateTime.Now; + + var wx_order_id_in = RegexUtils.GetStringQuery(ref inputData, "wx_order_id_in")?.Replace("'", "\\'"); + var wx_sku_id = RegexUtils.GetStringQuery(ref inputData, "wx_sku_id_in")?.Replace("'", "\\'"); + var out_order_id_in = RegexUtils.GetStringQuery(ref inputData, "out_order_id_in")?.Replace("'", "\\'"); + if (wx_order_id_in.IsNullOrEmpty() && out_order_id_in.IsNullOrEmpty()) + { + return "{\"code\":500,\"msg\":\"未指定订单\"}"; + } + var sort_type = RegexUtils.GetStringQuery(ref inputData, "sort_type")?.Replace("'", "\\'"); + var is_not_count = RegexUtils.GetStringQuery(ref inputData, "is_not_count") != "false"; + + int page = RegexUtils.GetStringQuery(ref inputData, "page").ParseToInt(); + int page_size = RegexUtils.GetStringQuery(ref inputData, "page_size").ParseToInt(500); + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + + string sql = "SELECT COUNT(id) FROM wxxd.order_item_ext o WHERE 1=1 "; + + string where = ""; + if (!string.IsNullOrWhiteSpace(wx_order_id_in)) + where += " and o.order_id in ('" + wx_order_id_in.Replace(",", "','") + "')"; + if (!string.IsNullOrWhiteSpace(wx_sku_id)) + where += " and o.sku_id in ('" + wx_sku_id.Replace(",", "','") + "')"; + if (!string.IsNullOrWhiteSpace(out_order_id_in)) + where += " and o.out_order_id in ('" + out_order_id_in.Replace(",", "','") + "')"; + sql += where; + + var count = 0; + if (!is_not_count) + count = mySql.ExecuteRowCount(sql); + + DataTable dt; + if (count == 0 && !is_not_count) + { + dt = new DataTable(); + } + else + { + sql = "SELECT o.* FROM" + + " wxxd.order_item_ext o " + + " WHERE 1=1"; + + //where子句 + sql += where; + + if (sort_type == "asc") + sql += " ORDER BY o.id ASC"; + else + sql += " ORDER BY o.id DESC"; + sql += " LIMIT " + Math.Max(page - 1, 0) * page_size + "," + page_size; + dt = mySql.ExecuteDataTable(sql); + } + + mySql.Close(); + if (dt != null) + { + try + { + List buyerOrderList = new List(); + foreach (DataRow row in dt.Rows) + { + order_item_ext order = new order_item_ext + { + id = row["id"].ParseToLong(), + add_time = row["add_time"].ParseToString().ParseToDateTime(), + buy_type = row["buy_type"].ParseToString(), + abnormal_text = row["abnormal_text"].ParseToString(), + after_sale_user_delivery_address = row["after_sale_user_delivery_address"].ParseToString(), + flag = row["flag"].ParseToNullableInt(), + mdy_time = row["mdy_time"].ParseToString().ParseToDateTime(), + label = row["label"].ParseToString(), + order_id = row["order_id"].ParseToString(), + remark = row["remark"].ParseToString(), + shop_app_id = row["shop_app_id"].ParseToString(), + shop_name = row["shop_name"].ParseToString(), + sku_id = row["sku_id"].ParseToString(), + out_order_id = row["out_order_id"].ParseToString(), + }; + buyerOrderList.Add(order); + } + JsonSerializerSettings jsonSetting = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }; + var data = JsonUtils.SerializeObjectToString(buyerOrderList, 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\":\"输入为空\"}"; + } + } +} + + + + diff --git a/StoreHub.KJDWebService/Services/WXProductService.cs b/StoreHub.KJDWebService/Services/WXProductService.cs new file mode 100644 index 0000000..f83625f --- /dev/null +++ b/StoreHub.KJDWebService/Services/WXProductService.cs @@ -0,0 +1,1375 @@ +using StoreHub.KJDWebService.Models; +using StoreHub.KJDWebService.Services; +using StoreHub.Framework.Repositorys; +using Microsoft.Extensions.Configuration; +using StoreHub.KJDWebService.Models.ShopModel; +using StoreHub.KJDWebService.Models.WxModel; +using StoreHub.KJDWebService.Commons; +using MySql.Data.MySqlClient; +using NaiBa.Util.Extension; +using NaiBa.Util.Helper; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; +using System; +using System.Collections.Generic; +using System.Data; +using System.Linq; +using System.Threading; + +namespace StoreHub.KJDWebService.Services +{ + public class WXProductService : ServiceBase + { + private readonly BXXProductService _bXXProductService; + public WXProductService(SqlRepository sqlRepository, IConfiguration configuration, BXXProductService bXXProductService) : base(sqlRepository, configuration) + { + _bXXProductService = bXXProductService; + } + public string WXGetPDDProductList(string inputData, bool isDetail = false) + { + return _bXXProductService.GetProductList(inputData, isDetail); + } + + public string WXGetPDDProductGroups(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\":\"没有用户名\"}"; + } + + int page = RegexUtils.GetStringQuery(ref inputData, "page").ParseToInt(); + int page_size = RegexUtils.GetStringQuery(ref inputData, "page_size").ParseToInt(50); + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + + string sql = "SELECT DISTINCT p.group FROM `bxx`.`product` p where p.is_del=0"; + + string where = ""; + sql += where; + + var dt = mySql.ExecuteDataTable(sql); + mySql.Close(); + + if (dt != null) + { + try + { + string group_data = ""; + foreach (DataRow row in dt.Rows) + { + group_data += row["group"].ToString() + ","; + } + var data = group_data.Trim(','); + return "{\"code\":200,\"msg\":\"success\",\"data\":\"" + data + "\"}"; + } + catch (Exception ex) + { + return "{\"code\":50002,\"msg\":\"" + ex.Message + "\",\"data\":\"\"}"; + } + } + else + { + return "{\"code\":50003,\"msg\":\"" + mySql.Message + "\",\"data\":\"\"}"; + } + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + public string WXGetPDDProductCates(string inputData) + { + return _bXXProductService.GetProductMainCates(inputData); + } + + /// + /// 随机获取商品(无详情) 随机添加到上传列表所以不需要获取详情 + /// + /// + /// + public string WXGetPDDProductListRandom(string inputData) + { + return _bXXProductService.GetProductListRandom(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("'", "\\'"); + var password = RegexUtils.GetStringQuery(ref inputData, "password")?.Replace("'", "\\'"); + var in_ext_codes = RegexUtils.GetStringQuery(ref inputData, "in_ext_codes")?.Replace("'", "\\'"); + var in_skc_ids = RegexUtils.GetStringQuery(ref inputData, "in_skc_ids")?.Replace("'", "\\'"); + var in_groups = RegexUtils.GetStringQuery(ref inputData, "in_groups")?.Replace("'", "\\'"); + var in_cates = RegexUtils.GetStringQuery(ref inputData, "in_cates")?.Replace("'", "\\'"); + + int page = RegexUtils.GetStringQuery(ref inputData, "page").ParseToInt(); + int page_size = RegexUtils.GetStringQuery(ref inputData, "page_size").ParseToInt(50); + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + + string sql = "select count(id) from bxx.product p where p.is_del=0"; + + string where = ""; + if (!string.IsNullOrEmpty(in_ext_codes)) + { + in_ext_codes = "'" + string.Join("','", in_ext_codes.Split(new string[] { ",", ",", " " }, StringSplitOptions.RemoveEmptyEntries)) + "'"; + where += " and p.ext_code in (" + in_ext_codes + ")"; + } + if (!string.IsNullOrEmpty(in_skc_ids)) + { + in_skc_ids = "'" + string.Join("','", in_skc_ids.Split(new string[] { ",", ",", " " }, StringSplitOptions.RemoveEmptyEntries)) + "'"; + where += " and p.skc_id in (" + in_skc_ids + ")"; + } + if (!string.IsNullOrEmpty(in_groups)) + { + in_groups = "'" + string.Join("','", in_groups.Split(new string[] { ",", ",", " " }, StringSplitOptions.RemoveEmptyEntries)) + "'"; + where += " and p.group in (" + in_groups + ")"; + } + if (!string.IsNullOrEmpty(in_cates)) + { + in_cates = "'" + string.Join("','", in_cates.Split(new string[] { ",", ",", " " }, StringSplitOptions.RemoveEmptyEntries)) + "'"; + where += " and (p.cat_name in (" + in_cates + ") or p.main_cat_name in (" + in_cates + "))"; + } + + sql += where; + + var count = mySql.ExecuteRowCount(sql); + + DataTable dt; + if (count == 0) + { + dt = new DataTable(); + } + else + { + sql = "select p.id,p.from_shop_id,p.spu_id,p.skc_id,p.main_cat_id,p.main_cat_name,p.cat_id,p.cat_name,p.price_text,p.ext_code," + + "p.product_name,p.main_img,p.group,p.notes,p.add_time,p.mdy_time,p.select_total_count," + + "p.fission_words,p.head_words,p.end_words from bxx.product p where p.is_del=0"; + + //where子句 + sql += where; + + sql += " ORDER BY RAND()"; + sql += " limit " + Math.Max(page - 1, 0) * page_size + "," + page_size; + dt = mySql.ExecuteDataTable(sql); + } + + mySql.Close(); + if (dt != null) + { + try + { + List productLst = new List(); + foreach (DataRow row in dt.Rows) + { + DBProductResultParam prod = new DBProductResultParam + { + id = Convert.ToInt32(row["id"]), + from_shop_id = row["from_shop_id"].ToString(), + skc_id = row["skc_id"].ToString(), + spu_id = row["spu_id"].ToString(), + cat_id = row["cat_id"].ToString(), + cat_name = row["cat_name"].ToString(), + main_cat_id = row["main_cat_id"].ToString(), + main_cat_name = row["main_cat_name"].ToString(), + price_text = row["price_text"].ToString(), + product_name = row["product_name"].ToString(), + main_img = row["main_img"].ToString(), + ext_code = row["ext_code"].ToString(), + //product_json = row["product_json"].ToString(), + //size_json = row["size_json"].ToString(), + add_time = Convert.ToDateTime(row["add_time"]), + mdy_time = Convert.ToDateTime(row["mdy_time"]), + group = row["group"].ToString(), + notes = row["notes"].ToString(), + select_total_count = row["select_total_count"].ParseToInt(), + end_words = row["end_words"].ParseToString(), + fission_words = row["fission_words"].ParseToString(), + head_words = row["head_words"].ParseToString(), + }; + productLst.Add(prod); + } + var data = JsonUtils.SerializerObjectToString(productLst); + return "{\"code\":200,\"msg\":\"success\",\"data\":" + data + ",\"count\":" + count + "}"; + } + 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 WXMdyPDDProduct(string inputData) + { + return _bXXProductService.MdyProduct(inputData); + } + + public string MdyBestSaleProd(string inputData) + { + return _bXXProductService.MdyBestSaleProd(inputData); + } + + public string WXAddSecretSpuIdShopIdMap(string inputData) + { + return "{\"code\":500,\"msg\":\"接口已作废\"}"; + 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 up_secret_spu_id = RegexUtils.GetStringQuery(ref inputData, "up_secret_spu_id")?.Replace("'", "\\'"); + if (string.IsNullOrEmpty(up_secret_spu_id)) + { + return "{\"code\":500,\"msg\":\"缺少商品编号1\"}"; + } + var index = RegexUtils.GetStringQuery(ref inputData, "index").ParseToNullableLong(); + if (index == null) + index = up_secret_spu_id.ParseToLong() % 1024; + var up_spu_id = RegexUtils.GetStringQuery(ref inputData, "up_spu_id")?.Replace("'", "\\'"); + if (string.IsNullOrEmpty(up_spu_id)) + { + return "{\"code\":500,\"msg\":\"缺少商品编号2\"}"; + } + var shop_id = RegexUtils.GetStringQuery(ref inputData, "shop_id")?.Replace("'", "\\'"); + if (string.IsNullOrEmpty(shop_id)) + { + return "{\"code\":500,\"msg\":\"缺少店铺编号\"}"; + } + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = "select id from wxxd_product_shop_map.product_shop_map_" + index.ParseToString().PadLeft(4, '0') + + " where up_secret_spu_id='" + up_secret_spu_id + "' and shop_id='" + shop_id + "';"; + + DataTable dt = mySql.ExecuteDataTable(sql); + if (!string.IsNullOrEmpty(mySql.Message) || dt == null || dt.Rows == null) + { + mySql.Close(); + return "{\"code\":500,\"msg\":\"失败:" + mySql.Message + "\"}"; + } + if (dt.Rows.Count > 0) + { + mySql.Close(); + return "{\"code\":200,\"msg\":\"数据已存在\"}"; + } + + sql = "insert into wxxd_product_shop_map.product_shop_map_" + index.ParseToString().PadLeft(4, '0') + + " (up_secret_spu_id,up_spu_id,shop_id) " + + " values ('" + up_secret_spu_id + "','" + up_spu_id + "','" + shop_id + "');"; + mySql.ExecuteNonQuery(sql); + mySql.Close(); + if (mySql.Message.IsNullOrEmpty()) + { + return "{\"code\":200,\"msg\":\"成功\"}"; + } + else + { + return "{\"code\":500,\"msg\":\"失败:" + mySql.Message + "\"}"; + } + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + public string WXAddSecretIdUpMap(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 up_secret_spu_id = RegexUtils.GetStringQuery(ref inputData, "up_secret_spu_id")?.Replace("'", "\\'"); + if (string.IsNullOrEmpty(up_secret_spu_id)) + { + return "{\"code\":500,\"msg\":\"缺少商品编号1\"}"; + } + var index = RegexUtils.GetStringQuery(ref inputData, "index").ParseToNullableLong(); + if (index == null) + index = Math.Abs(up_secret_spu_id.GetHashCode()) % 1024; + var up_spu_id = RegexUtils.GetStringQuery(ref inputData, "up_spu_id")?.Replace("'", "\\'"); + if (string.IsNullOrEmpty(up_spu_id)) + { + return "{\"code\":500,\"msg\":\"缺少商品编号2\"}"; + } + var shop_id = RegexUtils.GetStringQuery(ref inputData, "shop_id")?.Replace("'", "\\'"); + if (string.IsNullOrEmpty(shop_id)) + { + return "{\"code\":500,\"msg\":\"缺少店铺编号\"}"; + } + var price_max = RegexUtils.GetStringQuery(ref inputData, "price_max")?.Replace("'", "\\'"); + if (string.IsNullOrEmpty(price_max)) + { + return "{\"code\":500,\"msg\":\"缺少最高价格\"}"; + } + var price_min = RegexUtils.GetStringQuery(ref inputData, "price_min")?.Replace("'", "\\'"); + if (string.IsNullOrEmpty(price_min)) + { + return "{\"code\":500,\"msg\":\"缺少最低价格\"}"; + } + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + + string sql = "insert into wxxd_product_up_map.product_up_map_" + index.ParseToString().PadLeft(4, '0') + + " (up_secret_spu_id,up_spu_id,shop_id,price_min,price_max) " + + " values ('" + up_secret_spu_id + "','" + up_spu_id + "','" + shop_id + "'," + price_min + "," + price_max + ");"; + mySql.ExecuteNonQuery(sql); + mySql.Close(); + if (mySql.Message.IsNullOrEmpty()) + { + return "{\"code\":200,\"msg\":\"成功\"}"; + } + else + { + return "{\"code\":500,\"msg\":\"失败:" + mySql.Message + "\"}"; + } + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + public string WXGetSecretSpuIdShopIdMapList(string inputData) + { + var timeCalc = DateTime.Now; + 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 up_secret_spu_id = RegexUtils.GetStringQuery(ref inputData, "up_secret_spu_id")?.Replace("'", "\\'"); + if (string.IsNullOrEmpty(up_secret_spu_id)) + { + return "{\"code\":500,\"msg\":\"缺少商品编号1\"}"; + } + var index = RegexUtils.GetStringQuery(ref inputData, "index").ParseToNullableLong(); + if (index == null) + index = up_secret_spu_id.ParseToLong() % 1024; + int page = RegexUtils.GetStringQuery(ref inputData, "page").ParseToInt(); + int page_size = RegexUtils.GetStringQuery(ref inputData, "page_size").ParseToInt(50); + var shop_id = RegexUtils.GetStringQuery(ref inputData, "shop_id")?.Replace("'", "\\'"); + var is_not_count = RegexUtils.GetStringQuery(ref inputData, "is_not_count") == "true"; + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + + int count = 0; + string sql = ""; + if (!is_not_count) + { + sql = "select count(*) from wxxd_product_shop_map.product_shop_map_" + index.ParseToString().PadLeft(4, '0') + + " where up_secret_spu_id='" + up_secret_spu_id; + if (!shop_id.IsNullOrEmpty()) + sql += "' and shop_id='" + shop_id + "'"; + sql += ";"; + + count = mySql.ExecuteRowCount(sql); + Thread.Sleep(100); + } + + DataTable dt; + if (count == 0 && !is_not_count) + { + dt = new DataTable(); + } + else + { + sql = "select * from wxxd_product_shop_map.product_shop_map_" + index.ParseToString().PadLeft(4, '0') + + " where up_secret_spu_id='" + up_secret_spu_id; + if (!shop_id.IsNullOrEmpty()) + sql += "' and shop_id='" + shop_id + "'"; + sql += " order by add_time desc"; + sql += " limit " + Math.Max(page - 1, 0) * page_size + "," + page_size; + + dt = mySql.ExecuteDataTable(sql); + mySql.Close(); + if (!string.IsNullOrEmpty(mySql.Message) || dt == null) + { + Thread.Sleep(1000); + return "{\"code\":500,\"msg\":\"" + mySql.Message + "\",\"data\":[],\"count\":" + 0 + "}"; + } + } + + if (dt != null) + { + try + { + List prodSecretIdMapLst = new List(); + foreach (DataRow row in dt.Rows) + { + WxProdSecretSpuIdShopIdMapParam idMap = new WxProdSecretSpuIdShopIdMapParam + { + id = Convert.ToInt32(row["id"]), + up_secret_spu_id = row["up_secret_spu_id"].ToString(), + up_spu_id = row["up_spu_id"].ToString(), + shop_id = row["shop_id"].ToString(), + add_time = Convert.ToDateTime(row["add_time"]), + //mdy_time = Convert.ToDateTime(row["mdy_time"]), + }; + prodSecretIdMapLst.Add(idMap); + } + var data = JsonUtils.SerializeObjectToString(prodSecretIdMapLst); + 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 SetRandomCompanyProductConfig(string inputData) + { + var timeCalc = DateTime.Now; + 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\":50000,\"msg\":\"用户不存在\"}"; + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + + string product_group = RegexUtils.GetStringQuery(ref inputData, "product_group")?.Replace("'", "\\'"); + string product_interval = RegexUtils.GetStringQuery(ref inputData, "product_interval")?.Replace("'", "\\'"); + string is_on = RegexUtils.GetStringQuery(ref inputData, "is_on")?.Replace("'", "\\'"); + + string sql = "update wxxd.product_com_random set "; + if (product_group != null) + sql += "product_group='" + product_group + "',"; + if (product_interval != null) + sql += "product_interval=" + product_interval + ","; + if (is_on != null) + sql += "is_on=" + is_on + ","; + sql = sql.TrimEnd(','); + sql += " where 1=1;"; + var rst = mySql.ExecuteNonQuery(sql); + mySql.Close(); + if (string.IsNullOrEmpty(mySql.Message)) + { + return "{\"code\":200,\"msg\":\"success\"}"; + } + else + { + return "{\"code\":500,\"msg\":\"" + mySql.Message + "\"}"; + } + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + public string GetRandomCompanyProductConfig(string inputData) + { + var timeCalc = DateTime.Now; + 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\":50000,\"msg\":\"用户不存在\"}"; + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + + string sql = "select p.* from wxxd.product_com_random p" + + " where 1=1;"; + var dt = mySql.ExecuteDataTable(sql); + mySql.Close(); + if (dt != null) + { + try + { + string product_group = dt.Rows[0]["product_group"].ParseToString(); + string product_interval = dt.Rows[0]["product_interval"].ParseToString(); + string is_on = dt.Rows[0]["is_on"].ParseToString(); + var seconds = (DateTime.Now - timeCalc).TotalSeconds.ToString("0.000"); + return "{\"code\":200,\"msg\":\"success\"" + + ",\"product_group\":\"" + product_group + "\"" + + ",\"product_interval\":" + product_interval + + ",\"is_on\":" + is_on + + ",\"seconds\":" + seconds + "}"; + } + catch (Exception ex) + { + return "{\"code\":500,\"msg\":\"" + ex.Message + "\"}"; + } + } + else + { + return "{\"code\":500,\"msg\":\"" + mySql.Message + "\"}"; + } + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + + public string WXAddMdyAfterSale(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\":\"没有用户名\"}"; + } + + //int page = RegexUtils.GetStringQuery(ref inputData, "page").ParseToInt(); + //int page_size = RegexUtils.GetStringQuery(ref inputData, "page_size").ParseToInt(50); + string coid = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "coid"))?.Replace("'", "\\'"); + string after_sale_json = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "after_sale_json"))?.Replace("'", "\\'"); + if (string.IsNullOrEmpty(coid)) + return "{\"code\":50001,\"msg\":\"没有售后编号\"}"; + if (string.IsNullOrEmpty(after_sale_json)) + return "{\"code\":50001,\"msg\":\"没有售后信息\"}"; + string supplier_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "supplier_name"))?.Replace("'", "\\'"); + string type = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "type"))?.Replace("'", "\\'"); + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + + string sql = "SELECT coid FROM `wxxd`.`after_sale` where coid='" + coid + "' and is_del=0"; + + string where = ""; + sql += where; + + var dt = mySql.ExecuteDataTable(sql); + mySql.Close(); + + if (dt != null) + { + conn = Config("ConnKJD"); + mySql = new MysqlUtils(conn); + if (dt.Rows.Count == 0) + { + sql = "INSERT INTO `wxxd`.`after_sale` (coid,after_sale_json,supplier_name,type) VALUES (@coid,@after_sale_json,@supplier_name,@type);"; + } + else + { + sql = "UPDATE `wxxd`.`after_sale` SET after_sale_json=@after_sale_json"; + if (supplier_name != null) + sql += ", supplier_name=@supplier_name "; + if (type != null) + sql += ", type=@type "; + sql += " WHERE coid=@coid and is_del=0;"; + } + + List paramLst = new List(); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "coid", Value = coid, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "after_sale_json", Value = after_sale_json, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "supplier_name", Value = supplier_name.ParseToString(), }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "type", Value = type.IsNullOrEmpty() ? "jst" : type, }); + 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\":\"\"}"; + } + } + else + { + return "{\"code\":50003,\"msg\":\"" + mySql.Message + "\",\"data\":\"\"}"; + } + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + /// + /// 上货实时获取聚水潭等外部平台售后地址 + /// + /// + /// + public string WXGetAfterSale(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\":\"没有用户名\"}"; + } + + //int page = RegexUtils.GetStringQuery(ref inputData, "page").ParseToInt(); + //int page_size = RegexUtils.GetStringQuery(ref inputData, "page_size").ParseToInt(50); + string coid = RegexUtils.GetStringQuery(ref inputData, "coid")?.Replace("'", "\\'"); + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + + string sql = "SELECT * FROM `wxxd`.`after_sale` where coid='" + coid + "' and is_del=0"; + + string where = ""; + sql += where; + + var dt = mySql.ExecuteDataTable(sql); + mySql.Close(); + + if (dt != null) + { + try + { + string group_data = ""; + foreach (DataRow row in dt.Rows) + { + group_data += row["after_sale_json"].ToString(); + break; + } + var data = group_data.Trim(','); + if (data.IsNullOrEmpty()) + data = "\"\""; + return "{\"code\":200,\"msg\":\"success\",\"data\":" + data + "}"; + } + catch (Exception ex) + { + return "{\"code\":50002,\"msg\":\"" + ex.Message + "\",\"data\":\"\"}"; + } + } + else + { + return "{\"code\":50003,\"msg\":\"" + mySql.Message + "\",\"data\":\"\"}"; + } + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + public string WXGetRandomAfterSaleList(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + var timeCalc = DateTime.Now; + 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\":\"没有用户名\"}"; + } + + int page = RegexUtils.GetStringQuery(ref inputData, "page").ParseToInt(); + int page_size = RegexUtils.GetStringQuery(ref inputData, "page_size").ParseToInt(50); + string type = RegexUtils.GetStringQuery(ref inputData, "type")?.Replace("'", "\\'"); + string isDel = RegexUtils.GetStringQuery(ref inputData, "isDel")?.Replace("'", "\\'"); + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + + string sql = "SELECT count(*) FROM `wxxd`.`after_sale` where 1=1"; + + string where = ""; + if (type != null) + where += " and type='" + type + "'"; + + if (isDel == "true") + where += " and is_del>0"; + else + where += " and is_del=0"; + + sql += where; + sql += ";"; + + var count = 0; + count = mySql.ExecuteRowCount(sql); + + DataTable dt; + if (count == 0) + { + dt = new DataTable(); + } + else + { + sql = "SELECT * FROM `wxxd`.`after_sale` where 1=1"; + sql += where; + sql += " order by RAND() limit " + Math.Max(0, page - 1) * page_size + "," + page_size + ";"; + dt = mySql.ExecuteDataTable(sql); + } + mySql.Close(); + + if (dt != null) + { + try + { + List WXAddressInfoLst = new List(); + foreach (DataRow row in dt.Rows) + { + WXAddressInfoLst.Add(new StoreHub.KJDWebService.Models.WXAddressInfo() + { + id = row["id"].ParseToInt(), + after_sale_json = row["after_sale_json"].ParseToString(), + coid = row["coid"].ParseToString(), + supplier_name = row["supplier_name"].ParseToString(), + type = row["type"].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(WXAddressInfoLst, 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 WXGetAfterSaleList(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + var timeCalc = DateTime.Now; + 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\":\"没有用户名\"}"; + } + + int page = RegexUtils.GetStringQuery(ref inputData, "page").ParseToInt(); + int page_size = RegexUtils.GetStringQuery(ref inputData, "page_size").ParseToInt(50); + string coid = RegexUtils.GetStringQuery(ref inputData, "coid")?.Replace("'", "\\'"); + string type = RegexUtils.GetStringQuery(ref inputData, "type")?.Replace("'", "\\'"); + string supplier_name = RegexUtils.GetStringQuery(ref inputData, "supplier_name")?.Replace("'", "\\'"); + string detail = RegexUtils.GetStringQuery(ref inputData, "detail")?.Replace("'", "\\'"); + string isDel = RegexUtils.GetStringQuery(ref inputData, "isDel")?.Replace("'", "\\'"); + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + + string sql = "SELECT count(*) FROM `wxxd`.`after_sale` where 1=1"; + + string where = ""; + if (coid != null) + where += " and coid='" + coid + "'"; + if (type != null) + where += " and type='" + type + "'"; + if (supplier_name != null) + where += " and supplier_name='" + supplier_name + "'"; + if (detail != null) + where += " and after_sale_json like '%" + detail + "%'"; + + if (isDel == "true") + where += " and is_del>0"; + else + where += " and is_del=0"; + + sql += where; + sql += ";"; + + var count = 0; + count = mySql.ExecuteRowCount(sql); + + DataTable dt; + if (count == 0) + { + dt = new DataTable(); + } + else + { + sql = "SELECT * FROM `wxxd`.`after_sale` 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 WXAddressInfoLst = new List(); + foreach (DataRow row in dt.Rows) + { + WXAddressInfoLst.Add(new StoreHub.KJDWebService.Models.WXAddressInfo() + { + id = row["id"].ParseToInt(), + after_sale_json = row["after_sale_json"].ParseToString(), + coid = row["coid"].ParseToString(), + supplier_name = row["supplier_name"].ParseToString(), + type = row["type"].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(WXAddressInfoLst, 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 WXDelAddress(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + var timeCalc = DateTime.Now; + 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 coid = RegexUtils.GetStringQuery(ref inputData, "coid"); + if (string.IsNullOrEmpty(coid)) + { + return "{\"code\":50002,\"msg\":\"没有售后地址编号\"}"; + } + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + //string sql = "delete from wxxd.after_sale where coid='" + coid + "' and is_del=false"; + string sql = "update wxxd.after_sale set is_del=" + RandomUtils.GetId(1, Int32.MaxValue) + " where coid='" + coid + "' and is_del=false"; + + 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 WXAddMdyShippingTemplate(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\":\"没有用户名\"}"; + } + + //int page = RegexUtils.GetStringQuery(ref inputData, "page").ParseToInt(); + //int page_size = RegexUtils.GetStringQuery(ref inputData, "page_size").ParseToInt(50); + string coid = RegexUtils.GetStringQuery(ref inputData, "coid")?.Replace("'", "\\'"); + string shipping_template_json = RegexUtils.GetStringQuery(ref inputData, "shipping_template_json")?.Replace("'", "\\'"); + if (string.IsNullOrEmpty("coid")) + return "{\"code\":50001,\"msg\":\"没有运费编号\"}"; + if (string.IsNullOrEmpty("shipping_template_json")) + return "{\"code\":50001,\"msg\":\"没有运费信息\"}"; + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + + string sql = "SELECT * FROM `wxxd`.`shipping_template` where coid='" + coid + "'"; + + string where = ""; + sql += where; + + var dt = mySql.ExecuteDataTable(sql); + mySql.Close(); + + if (dt != null) + { + conn = Config("ConnKJD"); + mySql = new MysqlUtils(conn); + if (dt.Rows.Count == 0) + { + sql = "INSERT INTO `wxxd`.`shipping_template` (coid,shipping_template_json) VALUES (@coid,@shipping_template_json);"; + } + else + { + sql = "UPDATE `wxxd`.`shipping_template` SET shipping_template_json=@shipping_template_json WHERE coid=@coid;"; + } + + List paramLst = new List(); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "coid", Value = coid, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "shipping_template_json", Value = shipping_template_json, }); + 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\":\"\"}"; + } + } + else + { + return "{\"code\":50003,\"msg\":\"" + mySql.Message + "\",\"data\":\"\"}"; + } + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + public string WXGetShippingTemplate(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\":\"没有用户名\"}"; + } + + //int page = RegexUtils.GetStringQuery(ref inputData, "page").ParseToInt(); + //int page_size = RegexUtils.GetStringQuery(ref inputData, "page_size").ParseToInt(50); + string coid = RegexUtils.GetStringQuery(ref inputData, "coid")?.Replace("'", "\\'"); + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + + string sql = "SELECT * FROM `wxxd`.`shipping_template` where coid='" + coid + "'"; + + string where = ""; + sql += where; + + var dt = mySql.ExecuteDataTable(sql); + mySql.Close(); + + if (dt != null) + { + try + { + string group_data = ""; + foreach (DataRow row in dt.Rows) + { + group_data += row["shipping_template_json"].ToString(); + break; + } + var data = group_data.Trim(','); + if (data.IsNullOrEmpty()) + data = "\"\""; + return "{\"code\":200,\"msg\":\"success\",\"data\":" + data + "}"; + } + catch (Exception ex) + { + return "{\"code\":50002,\"msg\":\"" + ex.Message + "\",\"data\":\"\"}"; + } + } + else + { + return "{\"code\":50003,\"msg\":\"" + mySql.Message + "\",\"data\":\"\"}"; + } + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + public string WXAddMdyCommissionRate(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + if (!WXUserService.GetSign(inputData)) + return "{\"code\":999,\"msg\":\"校验失败\"}"; + + //int page = RegexUtils.GetStringQuery(ref inputData, "page").ParseToInt(); + //int page_size = RegexUtils.GetStringQuery(ref inputData, "page_size").ParseToInt(50); + string spu_id = RegexUtils.GetStringQuery(ref inputData, "spu_id")?.Replace("'", "\\'"); + string product_name = RegexUtils.GetStringQuery(ref inputData, "product_name")?.Replace("'", "\\'"); + int? commission_rate = RegexUtils.GetStringQuery(ref inputData, "commission_rate").ParseToNullableInt(); + if (string.IsNullOrEmpty(spu_id)) + return "{\"code\":50001,\"msg\":\"没有商品Id\"}"; + if (string.IsNullOrEmpty(product_name)) + return "{\"code\":50001,\"msg\":\"没有商品名称\"}"; + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + + string sql = "SELECT * FROM `bxx`.`product_wx_commission_rate` where spu_id='" + spu_id + "'"; + + string where = ""; + sql += where; + + var dt = mySql.ExecuteDataTable(sql); + mySql.Close(); + + if (dt != null) + { + conn = Config("ConnKJD"); + mySql = new MysqlUtils(conn); + if (dt.Rows.Count == 0) + { + sql = "INSERT INTO `bxx`.`product_wx_commission_rate` (spu_id,product_name,commission_rate) VALUES (@spu_id,@product_name,@commission_rate);"; + } + else + { + sql = "UPDATE `bxx`.`product_wx_commission_rate` SET product_name=@product_name,commission_rate=@commission_rate WHERE spu_id=@spu_id;"; + } + + List paramLst = new List(); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "spu_id", Value = spu_id, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "product_name", Value = product_name, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.Int32, ParameterName = "commission_rate", Value = commission_rate, }); + 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\":\"\"}"; + } + } + else + { + return "{\"code\":50003,\"msg\":\"" + mySql.Message + "\",\"data\":\"\"}"; + } + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + public string WXGetCommissionRate(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + if (!WXUserService.GetSign(inputData)) + return "{\"code\":999,\"msg\":\"校验失败\"}"; + + //int page = RegexUtils.GetStringQuery(ref inputData, "page").ParseToInt(); + //int page_size = RegexUtils.GetStringQuery(ref inputData, "page_size").ParseToInt(50); + string spu_ids = RegexUtils.GetStringQuery(ref inputData, "spu_ids")?.Replace("'", "\\'"); + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + + string sql = "SELECT * FROM `bxx`.`product_wx_commission_rate` where spu_id in ('" + spu_ids.Replace(",", "','") + "')"; + + string where = ""; + sql += where; + + var dt = mySql.ExecuteDataTable(sql); + mySql.Close(); + + if (dt != null) + { + JArray jArr = new JArray(); + try + { + foreach (DataRow row in dt.Rows) + { + JObject jObj = new JObject(); + jObj["id"] = row["id"].ToString(); + jObj["product_name"] = row["product_name"].ToString(); + jObj["commission_rate"] = row["commission_rate"].ParseToNullableInt(); + jObj["add_time"] = Convert.ToDateTime(row["add_time"]); + jObj["mdy_time"] = Convert.ToDateTime(row["mdy_time"]); + jArr.Add(jObj); + } + return "{\"code\":200,\"msg\":\"success\",\"data\":" + JsonUtils.SerializeObject(jArr) + "}"; + } + catch (Exception ex) + { + return "{\"code\":50002,\"msg\":\"" + ex.Message + "\",\"data\":[]}"; + } + } + else + { + return "{\"code\":50003,\"msg\":\"" + mySql.Message + "\",\"data\":[]}"; + } + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + + public string WXAddMdyQualificationImage(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + if (!WXUserService.GetSign(inputData)) + return "{\"code\":999,\"msg\":\"校验失败\"}"; + + //int page = RegexUtils.GetStringQuery(ref inputData, "page").ParseToInt(); + //int page_size = RegexUtils.GetStringQuery(ref inputData, "page_size").ParseToInt(50); + string img_md5 = RegexUtils.GetStringQuery(ref inputData, "img_md5")?.Replace("'", "\\'"); + string img_base64 = RegexUtils.GetStringQuery(ref inputData, "img_base64")?.Replace("'", "\\'"); + string img_thumb_base64 = RegexUtils.GetStringQuery(ref inputData, "img_thumb_base64")?.Replace("'", "\\'"); + string txt_margin = RegexUtils.GetStringQuery(ref inputData, "txt_margin")?.Replace("'", "\\'"); + if (string.IsNullOrEmpty(img_md5)) + return "{\"code\":50001,\"msg\":\"没有图片码\"}"; + if (string.IsNullOrEmpty("product_name")) + return "{\"code\":50001,\"msg\":\"没有图片\"}"; + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + + string sql = "INSERT INTO wxxd.wx_qualification_image (img_md5,img_base64,img_thumb_base64,txt_margin) VALUES " + + " ('" + img_md5 + "','" + img_base64 + "','" + img_thumb_base64 + "','" + txt_margin + "')" + + " ON DUPLICATE KEY UPDATE img_base64=VALUES(img_base64),img_thumb_base64=VALUES(img_thumb_base64),txt_margin=VALUES(txt_margin);"; + + var rst = mySql.ExecuteAffectedRows(sql); + mySql.Close(); + + if (!mySql.Message.IsNullOrEmpty()) + { + return "{\"code\":500,\"msg\":\"" + mySql.Message + "\"}"; + } + else if (rst < 1) + { + return "{\"code\":500,\"msg\":\"未新增或更新\"}"; + } + return "{\"code\":200,\"msg\":\"success\"}"; + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + public string WXGetQualificationImage(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + if (!WXUserService.GetSign(inputData)) + return "{\"code\":999,\"msg\":\"校验失败\"}"; + + int page = RegexUtils.GetStringQuery(ref inputData, "page").ParseToInt(1); + int page_size = RegexUtils.GetStringQuery(ref inputData, "page_size").ParseToInt(200); + string img_md5 = RegexUtils.GetStringQuery(ref inputData, "img_md5")?.Replace("'", "\\'"); + string cat_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "cat_name"))?.Replace("'", "\\'"); + string is_detail = RegexUtils.GetStringQuery(ref inputData, "is_detail")?.Replace("'", "\\'"); + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + + string sql = "SELECT * FROM wxxd.wx_qualification_image where 1=1"; + + string where = ""; + if (!string.IsNullOrEmpty(img_md5)) + where += " and img_md5 in ('" + img_md5.Replace(",", "','") + "')"; + if (!string.IsNullOrEmpty(cat_name)) + where += " and cat_name in ('" + cat_name.Replace(",", "','") + "')"; + sql += where; + sql += " ORDER BY id DESC"; + sql += " LIMIT " + (page - 1) * page_size + "," + page_size + ";"; + + var dt = mySql.ExecuteDataTable(sql); + mySql.Close(); + + if (dt != null) + { + JArray jArr = new JArray(); + List wxQualificationImageInfos = new List(); + try + { + foreach (DataRow row in dt.Rows) + { + var img = new wx_qualification_image_info() + { + id = row["id"].ParseToInt(), + cat_name = row["cat_name"].ParseToString(), + img_md5 = row["img_md5"].ParseToString(), + img_thumb_base64 = row["img_thumb_base64"].ParseToNullableString(), + txt_margin = row["txt_margin"].ParseToNullableString(), + add_time = row["add_time"].ParseToString().ParseToDateTime(), + mdy_time = row["mdy_time"].ParseToString().ParseToDateTime(), + }; + if (is_detail == "true") + img.img_base64 = row["img_base64"].ParseToNullableString(); + wxQualificationImageInfos.Add(img); + } + return "{\"code\":200,\"msg\":\"success\",\"data\":" + JsonUtils.SerializeObject(wxQualificationImageInfos) + "}"; + } + catch (Exception ex) + { + return "{\"code\":50002,\"msg\":\"" + ex.Message + "\",\"data\":[]}"; + } + } + else + { + return "{\"code\":50003,\"msg\":\"" + mySql.Message + "\",\"data\":[]}"; + } + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + public string WXDelQualificationImage(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + if (!WXUserService.GetSign(inputData)) + return "{\"code\":999,\"msg\":\"校验失败\"}"; + + string img_md5 = RegexUtils.GetStringQuery(ref inputData, "img_md5")?.Replace("'", "\\'"); + string id = RegexUtils.GetStringQuery(ref inputData, "id")?.Replace("'", "\\'"); + if (id.IsNullOrZero() && img_md5.IsNullOrEmpty()) + { + return "{\"code\":50001,\"msg\":\"图片id不能为空\"}"; + } + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + + string sql = "delete FROM wxxd.wx_qualification_image where 1=1"; + + string where = ""; + if (!string.IsNullOrEmpty(img_md5)) + where += " and img_md5 in ('" + img_md5.Replace(",", "','") + "')"; + if (!id.IsNullOrZero()) + where += " and id in (" + id + ")"; + sql += where + ";"; + + var rows = mySql.ExecuteAffectedRows(sql); + mySql.Close(); + + if(!string.IsNullOrEmpty(mySql.Message)) + { + return "{\"code\":50002,\"msg\":\"" + mySql.Message + "\"}"; + } + return "{\"code\":200,\"msg\":\"success\",\"affected_rows\":" + rows + "}"; + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + + public string E57GetFreightTemplate(string inputData) + { + if (string.IsNullOrEmpty(inputData)) + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + + var time = RegexUtils.GetStringQuery(ref inputData, "time").ParseToInt(); + string time1 = RegexUtils.GetStringQuery(ref inputData, "code"); + if (time1 != EncrypUtil.Encryption(time)) + return "{\"code\":50000,\"msg\":\"校验失败\"}"; + + // 供应商id + string coid = RegexUtils.GetStringQuery(ref inputData, "coid")?.Replace("'", "\\'"); + + try + { + // 获取运费模板 + //"https://po.e57.cn/prod-api/api/sys-api/system/open/api/freightTemplate/list?warehouseNum=10361546"; + var urlShip = "https://po.e57.cn/prod-api/api/sys-api/system/open/api/freightTemplate/list?warehouseNum=" + coid; + var shipRst = HttpUtils.e57GetResponse(urlShip, ""); + return shipRst; + } + catch (Exception ex) + { + return "{\"code\":50001,\"msg\":\"" + ex.Message + "\"}"; + } + } + + public string E57AfterSale(string inputData) + { + if (string.IsNullOrEmpty(inputData)) + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + + var time = RegexUtils.GetStringQuery(ref inputData, "time").ParseToInt(); + string time1 = RegexUtils.GetStringQuery(ref inputData, "code"); + if (time1 != EncrypUtil.Encryption(time)) + return "{\"code\":50000,\"msg\":\"校验失败\"}"; + + // 供应商id + string coid = RegexUtils.GetStringQuery(ref inputData, "coid")?.Replace("'", "\\'"); + + try + { + // 获取推单售后地址 + //https://po.e57.cn/prod-api/api/sys-api/system/open/api/afterSale/info?warehouseNum=10361546&shopId=46568955 + var urlAfter = "https://po.e57.cn/prod-api/api/sys-api/system/open/api/afterSale/info?warehouseNum=" + coid; + var shipRst = HttpUtils.e57GetResponse(urlAfter, ""); + return shipRst; + } + catch (Exception ex) + { + return "{\"code\":50001,\"msg\":\"" + ex.Message + "\"}"; + } + } + } +} + + + + + + + + + + + diff --git a/StoreHub.KJDWebService/Services/WXShopRevenueStatisticsService.cs b/StoreHub.KJDWebService/Services/WXShopRevenueStatisticsService.cs new file mode 100644 index 0000000..4e4975c --- /dev/null +++ b/StoreHub.KJDWebService/Services/WXShopRevenueStatisticsService.cs @@ -0,0 +1,306 @@ +using StoreHub.KJDWebService.Models; +using StoreHub.Framework.Repositorys; +using Microsoft.Extensions.Configuration; +using StoreHub.KJDWebService.Models.WxModel; +using StoreHub.KJDWebService.Commons; +using StoreHub.KJDWebService.Commons; +using MySql.Data.MySqlClient; +using NaiBa.Util.Extension; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; +using Newtonsoft.Json.Serialization; +using System; +using System.Collections.Generic; +using System.Data; +using System.Linq; +using System.Net; +using System.Reflection; +using System.Text; +using System.Threading; + +namespace StoreHub.KJDWebService.Services +{ + public class WXShopRevenueStatisticsService : ServiceBase + { + private readonly WXOrderService _wxOrderService; + public WXShopRevenueStatisticsService(SqlRepository sqlRepository, IConfiguration configuration, WXOrderService wxOrderService) : base(sqlRepository, configuration) + { + _wxOrderService = wxOrderService; + } + public string GetShopOrderAmountRange(string inputData) + { + Result ret = Result.ArgumentNull(); + if (!string.IsNullOrEmpty(inputData)) + { + try + { + // todo 获取当前用户微信店铺,或指定某一个店铺,某一段时间 + // 获取店铺下时间范围内的所有订单涉及到的金额 + // 直接返回 + if (!WXUserService.GetSign(inputData)) + throw new ArgumentException("校验失败"); + var timeCalc = DateTime.Now; + + string shop_ids = RegexUtils.GetStringQuery(ref inputData, "shop_ids")?.Replace("'", "");//所有店铺信息 + if (string.IsNullOrEmpty(shop_ids)) + throw new ArgumentException("请选择店铺"); + List shopIdLst = shop_ids.Split(',').ToList(); + if (shopIdLst.Count > 0) + shop_ids = "'" + string.Join("','", shopIdLst) + "'"; + + + + string start_Time = RegexUtils.GetStringQuery(ref inputData, "start_time")?.Replace("'", ""); + string end_Time = RegexUtils.GetStringQuery(ref inputData, "end_time")?.Replace("'", ""); + DateTime startTime = DateTime.Now.AddDays(-7); + DateTime endTime = DateTime.Now; + if (!string.IsNullOrEmpty(start_Time)) + startTime = TimeUtils.StampMillisecondsToDateTime(start_Time.ParseToLong()); + if (!string.IsNullOrEmpty(end_Time)) + endTime = TimeUtils.StampMillisecondsToDateTime(end_Time.ParseToLong()); + if (endTime <= startTime) + throw new ArgumentException("结束时间必须大于开始时间"); + if (endTime > startTime.AddMonths(3)) + throw new ArgumentException("时间范围不能超过3个月"); + + int startTimestamp = TimeUtils.DateTimeToTimestampSeconds(startTime); + int endTimestamp = TimeUtils.DateTimeToTimestampSeconds(endTime); + + StringBuilder sb = new StringBuilder(); + sb.Append("SELECT "); + sb.Append("A.shop_name, "); + sb.Append("A.create_time, "); + sb.Append("A.order_id, "); + sb.Append("A.`status`, "); + sb.Append("A.product_price, "); + sb.Append("A.order_price, "); + sb.Append("A.purchase_price, "); + sb.Append("A.freight, "); + sb.Append("A.predict_commission_fee, "); + sb.Append("A.commission_amount, "); + sb.Append("A.discounted_price, "); + sb.Append("A.profit, "); + sb.Append("A.purchase_status, "); + sb.Append("A.out_amount, "); + sb.Append("B.refund_status, "); + sb.Append("c.`status` as refund_status_string, "); + sb.Append("IFNULL(C.refund_amount, 0) AS refund_amount "); + sb.Append("FROM erp.oms_wei_order AS A "); + sb.Append("INNER JOIN erp.`oms_wei_order_item` AS B ON A.`order_id` = B.`order_id` "); + sb.Append("LEFT JOIN ( SELECT order_id,`status`,refund_amount,id FROM erp.`oms_wei_refund` WHERE id IN ( SELECT MAX(id) FROM erp.`oms_wei_refund` GROUP BY order_id)) AS C ON A.order_id = C.order_id "); + sb.Append("WHERE A.create_time BETWEEN " + startTimestamp + " AND " + endTimestamp + " "); + sb.Append("AND A.`status` > 10 "); + sb.Append("AND A.shop_id IN (" + shop_ids + ") "); + sb.Append("ORDER BY A.create_time asc"); + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + DataTable dt = mySql.ExecuteDataTable(sb.ToString()); + mySql.Close(); + if (!string.IsNullOrEmpty(mySql.Message)) + throw new Exception(mySql.Message); + + // out_amount 为空或为0的订单,从中转仓订单表(GetTransitOrderTable)补全外采金额 + // external_procurement:0=未查到,1=从 GetTransitOrderTable 查询到 + Dictionary transitOutAmountMap = new Dictionary(); + if (dt != null && dt.Rows.Count > 0) + { + HashSet needLookupOrderIds = new HashSet(); + foreach (DataRow row in dt.Rows) + { + int? rowOutAmount = row["out_amount"].ParseToInt(); + if (rowOutAmount == null || rowOutAmount.Value == 0) + { + string orderId = row["order_id"].ParseToString(); + if (!string.IsNullOrEmpty(orderId)) + needLookupOrderIds.Add(orderId); + } + } + + if (needLookupOrderIds.Count > 0) + { + + const int chunkSize = 100; + const int transitPageSize = 500; + List needLookupList = needLookupOrderIds.ToList(); + for (int i = 0; i < needLookupList.Count; i += chunkSize) + { + int takeCount = Math.Min(chunkSize, needLookupList.Count - i); + string chunkOrderIds = string.Join(",", needLookupList.GetRange(i, takeCount)); + int pageIndex = 1; + while (true) + { + int count = -1; + var transitList = _wxOrderService.GetTransitOrderTable(pageIndex, transitPageSize, chunkOrderIds, null, null, null, null, "true", out count); + if (transitList == null || transitList.Count == 0) + break; + foreach (var transit in transitList) + { + if (transit != null && !string.IsNullOrEmpty(transit.order_no) && needLookupOrderIds.Contains(transit.order_no)) + { + if (!transitOutAmountMap.ContainsKey(transit.order_no)) + transitOutAmountMap[transit.order_no] = transit.out_amount ?? 0; + } + } + if (transitList.Count < transitPageSize) + break; + pageIndex++; + } + } + } + } + + List orderList = new List(); + if (dt != null) + { + foreach (DataRow row in dt.Rows) + orderList.Add(BuildOrderAmountInfo(row, transitOutAmountMap)); + } + + // 买手号退款金额:退款订单(refund_status>1)且非外采时,从买手售后表补全退款金额 + FillBuyerRefundAmount(orderList, conn); + + ret.Code = 200; + ret.Msg = "success"; + ret.Data = orderList; + } + catch (Exception ex) + { + ret.Code = 500; + ret.Msg = ex.Message; + } + } + return JsonUtils.SerializeObjectToString(ret, new JsonSerializerSettings + { + ContractResolver = new CamelCasePropertyNamesContractResolver(), + NullValueHandling = NullValueHandling.Ignore + }); + } + + /// + /// 将订单行转换为金额详情:out_amount 为空或0时从中转仓订单表补全,并计算利润 + /// + private WXOrderAmountInfo BuildOrderAmountInfo(DataRow row, Dictionary transitOutAmountMap) + { + string orderId = row["order_id"].ParseToString(); + + int outAmount = row["out_amount"].ParseToInt(); + int externalProcurement = 0; + if (outAmount == 0) + { + int transitAmount; + if (transitOutAmountMap.TryGetValue(orderId, out transitAmount)) + { + externalProcurement = 1; + outAmount = transitAmount; + } + } + + int orderPrice = row["order_price"].ParseToInt(); + int predictCommissionFee = row["predict_commission_fee"].ParseToInt(); + int commissionAmount = row["commission_amount"].ParseToInt(); + int refund_amount = row["refund_amount"].ParseToInt(); + // 利润 = 订单金额 - 外采金额 - 平台服务费 - 达人佣金(为空按0处理) + int profit = orderPrice - outAmount - predictCommissionFee - commissionAmount; + if (refund_amount > 0) //退款利润计算 + { + profit = orderPrice - refund_amount; + } + + return new WXOrderAmountInfo + { + shop_name = row["shop_name"].ParseToString(), + create_time = row["create_time"].ParseToInt(), + order_id = orderId, + status = row["status"].ParseToInt(), + product_price = row["product_price"].ParseToInt(), + order_price = orderPrice, + purchase_price = row["purchase_price"].ParseToInt(), + freight = row["freight"].ParseToInt(), + predict_commission_fee = predictCommissionFee, + commission_amount = commissionAmount, + discounted_price = row["discounted_price"].ParseToInt(), + profit = profit, + purchase_status = row["purchase_status"].ParseToInt(), + out_amount = outAmount, + refund_status = row["refund_status"].ParseToInt(), + refund_status_string = row["refund_status_string"].ParseToString(), + refund_amount = row["refund_amount"].ParseToInt(), + external_procurement = externalProcurement + }; + } + + /// + /// 买手号退款金额:退款订单(refund_status>1)且非外采时,从买手售后表(wxxd.order_pdd_buyer_after_sale)查询退款金额(refundAmount)填入 + /// + private void FillBuyerRefundAmount(List orderList, string conn) + { + if (orderList == null || orderList.Count == 0) + return; + + // 退款订单(refund_status>1)且非外采(out_amount、external_procurement都为0)的订单才查询买手号退款金额 + HashSet needLookupOrderIds = new HashSet(); + foreach (WXOrderAmountInfo order in orderList) + { + if (order.refund_status > 1 && order.external_procurement == 1 && order.out_amount > 0) + { + if (!string.IsNullOrEmpty(order.order_id)) + needLookupOrderIds.Add(order.order_id); + } + } + if (needLookupOrderIds.Count == 0) + return; + + Dictionary> buyerRefundAmountMap = new Dictionary>(); + MysqlUtils mySql = new MysqlUtils(conn); + try + { + const int chunkSize = 100; + List needLookupList = needLookupOrderIds.ToList(); + for (int i = 0; i < needLookupList.Count; i += chunkSize) + { + int takeCount = Math.Min(chunkSize, needLookupList.Count - i); + string chunkOrderIds = string.Join("','", needLookupList.GetRange(i, takeCount)); + string sql = "SELECT WX_ORDER_ID,refundAmount,statusText FROM wxxd.order_pdd_buyer_after_sale a " + + "WHERE a.WX_ORDER_ID IN ('" + chunkOrderIds + "') AND a.id = ( SELECT MAX(b.id) FROM wxxd.order_pdd_buyer_after_sale b WHERE b.WX_ORDER_ID = a.WX_ORDER_ID) ORDER BY a.WX_ORDER_ID;"; + DataTable buyerDt = mySql.ExecuteDataTable(sql); + if (buyerDt != null) + { + foreach (DataRow row in buyerDt.Rows) + { + string wxOrderId = row["WX_ORDER_ID"].ParseToString(); + int refundAmount = row["refundAmount"].ParseToInt(); + string statusText = row["statusText"].ParseToString(); + if (!string.IsNullOrEmpty(wxOrderId) && !buyerRefundAmountMap.ContainsKey(wxOrderId)) + buyerRefundAmountMap[wxOrderId] = new Tuple(refundAmount, statusText); + } + } + } + } + finally + { + mySql.Close(); + } + if (!string.IsNullOrEmpty(mySql.Message)) + throw new Exception(mySql.Message); + + foreach (WXOrderAmountInfo order in orderList) + { + Tuple buyerRefundAmount; + if (buyerRefundAmountMap.TryGetValue(order.order_id, out buyerRefundAmount)) + { + order.buyer_refund_amount = buyerRefundAmount.Item1; + order.buyer_refund_status = buyerRefundAmount.Item2; + } + } + } + } +} + + + + + + + + diff --git a/StoreHub.KJDWebService/Services/WXShopService.cs b/StoreHub.KJDWebService/Services/WXShopService.cs new file mode 100644 index 0000000..70d658f --- /dev/null +++ b/StoreHub.KJDWebService/Services/WXShopService.cs @@ -0,0 +1,1872 @@ +using StoreHub.KJDWebService.Models; +using StoreHub.Framework.Repositorys; +using Microsoft.Extensions.Configuration; +using StoreHub.KJDWebService.Models.ErpModel; +using StoreHub.KJDWebService.Models.ShopModel; +using StoreHub.KJDWebService.Models.WxModel; +using StoreHub.KJDWebService.Commons; +using MySql.Data.MySqlClient; +using NaiBa.Util.Extension; +using NaiBa.Util.Helper; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; +using System; +using System.Collections.Generic; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Reflection; +using System.Security.Cryptography; + +namespace StoreHub.KJDWebService.Services +{ + public class WXShopService : ServiceBase + { + public WXShopService(SqlRepository sqlRepository, IConfiguration configuration) : base(sqlRepository, configuration) + { + } + 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 = "ConnKJD"; + 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 = Config("ConnKJD"); + 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 (!WXUserService.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 = "ConnKJD"; + 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 = "ConnKJD"; + 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 = "ConnKJD"; + 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 = "ConnKJD"; + 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 = "ConnKJD"; + 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\":\"未知错误\"}"; + } + + 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 = "ConnKJD"; + 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 = "ConnKJD"; + 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 = "ConnKJD"; + 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 = "ConnKJD"; + 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 = "ConnKJD"; + 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 (!WXUserService.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 = "ConnKJD"; + 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 (!WXUserService.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 = "ConnKJD"; + 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 (!WXUserService.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 = "ConnKJD"; + 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 (!WXUserService.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 = "ConnKJD"; + 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 (!WXUserService.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 = "ConnKJD"; + 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 (!WXUserService.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 = "ConnKJD"; + 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 (!WXUserService.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 = "ConnKJD"; + 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 = "ConnKJD"; + 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 = "ConnKJD"; + 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 = "ConnKJD"; + 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 = "ConnKJD"; + 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 = "ConnKJD"; + 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 = "ConnKJD"; + 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 = Config("ConnKJD"); + 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\":\"输入为空\"}"; + } + } +} + + + + + diff --git a/StoreHub.KJDWebService/Services/WXUserService.cs b/StoreHub.KJDWebService/Services/WXUserService.cs new file mode 100644 index 0000000..3d6733e --- /dev/null +++ b/StoreHub.KJDWebService/Services/WXUserService.cs @@ -0,0 +1,1734 @@ +using StoreHub.KJDWebService.Models; +using StoreHub.Framework.Repositorys; +using Microsoft.Extensions.Configuration; +using StoreHub.KJDWebService.Models.WxModel; +using StoreHub.KJDWebService.Commons; +using MySql.Data.MySqlClient; +using NaiBa.Util.Extension; +using System; +using System.Collections.Generic; +using System.Data; +using System.Linq; +using System.Net; +using System.Reflection; +using System.Threading; + +namespace StoreHub.KJDWebService.Services +{ + public class WXUserService : ServiceBase + { + public WXUserService(SqlRepository sqlRepository, IConfiguration configuration) : base(sqlRepository, configuration) + { + } + public static bool GetSign(string signData, bool isUserLogin = false) + { + if (string.IsNullOrEmpty(signData)) { return false; } + + var time = RegexUtils.GetStringQuery(ref signData, "time").ParseToInt(); + var time1 = RegexUtils.GetStringQuery(ref signData, "code"); + if (time1 != EncrypUtil.Encryption(time)) + return false; + + if (!isUserLogin) + { + var user_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref signData, "user_name"))?.ParseToString(); + if (user_name.IsNullOrEmpty()) + { + //return "{\"code\":500,\"msg\":\"请输入用户名\"}"; + return false; + } + } + + return true; + } + + public static DateTime dtAuthorizationExpireTime = DateTime.Now; + public static string e57Authorization = ""; + public string GetE57Authorization(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + if (!GetSign(inputData)) + return "{\"code\":999,\"msg\":\"校验失败\"}"; + + if (dtAuthorizationExpireTime <= DateTime.Now || string.IsNullOrEmpty(e57Authorization)) + { + //{"msg":"username required","code":500} + //{"msg":"操作成功","code":200,"token":"eyJhbGciOiJIUzUxMiJ9.eyJsb2dpbl91c2VyX2tleSI6ImIxYTU3OWI2LTM0NWUtNDQwOC05ZjFiLTk0ZTUyOTIxMzlmZCJ9.3qvRXiWeCo_cIOHs6gbCHqDrmfCrH6XDOrMY0BjuUOIu3yVsCwFGVO0hT0A5Wssh_VFPJLouyb1moTcODt0vow"} + var url = "https://po.e57.cn/prod-api/api/sys-api/internal/createTokenForUser"; + var data = "{\"username\":\"admin\"}"; + var html = HttpUtils.e57PostResponse(url, data, ""); + e57Authorization = RegexUtils.GetStringJson(ref html, "token").ParseToString(); + dtAuthorizationExpireTime = DateTime.Now.AddHours(2); + //dtAuthorizationExpireTime = DateTime.Now.AddMinutes(10); + return html.Replace("token", "authorization"); + } + return "{\"code\":200,\"authorization\":\"" + e57Authorization + "\"}"; + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + public string CheckUserLogin(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + if (!GetSign(inputData, true)) + return "{\"code\":999,\"msg\":\"校验失败\"}"; + + var mobile = RegexUtils.GetStringQuery(ref inputData, "mobile")?.Replace("'", "\\'"); + var password = RegexUtils.GetStringQuery(ref inputData, "password")?.Replace("'", "\\'"); + var sub_soft_type = RegexUtils.GetStringQuery(ref inputData, "sub_soft_type")?.Replace("'", "\\'"); + + + var version = RegexUtils.GetStringQuery(ref inputData, "version").ParseToInt(); + if (sub_soft_type == "order") + { + if (version < (System.Configuration.ConfigurationManager.ConnectionStrings["WxFindOrderLimitVersion"]?.ConnectionString).ParseToInt()) + return "{\"code\":1,\"msg\":\"当前版本过于陈旧,请立即升级新版\"}"; + } + else + { + if (version < (System.Configuration.ConfigurationManager.ConnectionStrings["LimitVersion"]?.ConnectionString).ParseToInt()) + return "{\"code\":1,\"msg\":\"当前版本过于陈旧,请立即升级新版\"}"; + } + + int r2 = 0; + int.TryParse(RegexUtils.GetStringQuery(ref inputData, "r2"), out r2); + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = "select u.*,uu.authority as main_authority,uu.oem_id as main_oem_id,uu.postage_per_order as main_postage_per_order," + + "uu.refund_postage_per_order as main_refund_postage_per_order,uu.gift_oem_amount_per_order as main_gift_oem_amount_per_order " + + "FROM wxxd.user u LEFT JOIN wxxd.user uu ON uu.user_name=u.parent_user_name where u.user_name='" + + mobile + "' and u.password='" + password + "'"; + + var dt = mySql.ExecuteDataTable(sql); + if (!string.IsNullOrEmpty(mySql.Message)) + { + mySql.Close(); + return "{\"code\":500,\"msg\":\"" + mySql.Message + "\"}"; + } + + if (dt == null) + dt = new DataTable(); + + foreach (DataRow row in dt.Rows) + { + UserLoginResultParam user = new UserLoginResultParam + { + id = Convert.ToInt32(row["id"]), + user_name = row["user_name"].ToString(), + nick_name = row["nick_name"].ToString(), + mobile = row["user_name"].ToString(), + password = row["password"].ToString(), + group_id = row["group_id"].ToString(), + card_id = row["card_id"].ToString(), + company_name = row["company_name"].ToString(), + is_sa = row.Table.Columns.Contains("is_sa") ? row["is_sa"].ParseToInt() : 0, + sa_level = row.Table.Columns.Contains("sa_level") ? row["sa_level"].ParseToInt() : 0, + authority = row.Table.Columns.Contains("authority") ? row["authority"].ParseToString() : "", + forbidden_page = row.Table.Columns.Contains("forbidden_page") ? row["forbidden_page"].ParseToString() : "", + parent_user_name = row["parent_user_name"].ToString(), + oem_id = row["oem_id"].ToString(), + points = row.Table.Columns.Contains("points") ? row["points"].ParseToInt() : 0, + shop_points_per_month = row.Table.Columns.Contains("shop_points_per_month") ? row["shop_points_per_month"].ParseToInt() : 30, + balance = row.Table.Columns.Contains("balance") ? row["balance"].ParseToDecimal() : 0, + recharge_amount_total = row.Table.Columns.Contains("recharge_amount_total") ? row["recharge_amount_total"].ParseToDecimal() : 0, + postage_per_order = row.Table.Columns.Contains("postage_per_order") ? row["postage_per_order"].ParseToNullableDecimal() : null, + refund_postage_per_order = row.Table.Columns.Contains("refund_postage_per_order") ? row["refund_postage_per_order"].ParseToNullableDecimal() : null, + gift_oem_amount_per_order = row.Table.Columns.Contains("gift_oem_amount_per_order") ? row["gift_oem_amount_per_order"].ParseToNullableDecimal() : null, + }; + var main_authority = row.Table.Columns.Contains("main_authority") ? row["main_authority"].ParseToString() : ""; + var main_oem_id = row.Table.Columns.Contains("main_oem_id") ? row["main_oem_id"].ParseToString() : ""; + var main_postage_per_order = row.Table.Columns.Contains("main_postage_per_order") ? row["main_postage_per_order"].ParseToDecimal() : 0m; + var main_refund_postage_per_order = row.Table.Columns.Contains("main_refund_postage_per_order") ? row["main_refund_postage_per_order"].ParseToDecimal() : 0m; + var main_gift_oem_amount_per_order = row.Table.Columns.Contains("main_gift_oem_amount_per_order") ? row["main_gift_oem_amount_per_order"].ParseToDecimal() : 0m; + + // 填写子账号的父账号权限 + if (user.group_id != "3") + { + user.parent_authority = main_authority; + + // 子账号积分用户权限跟随主账号 + var userAuthLst = user.authority.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries).ToList(); + if (!main_authority.Contains("积分用户")) + { + userAuthLst.Remove("积分用户"); + user.authority = string.Join(",", userAuthLst); + } + else if (!user.authority.Contains("积分用户")) + { + user.authority = (user.authority + "," + "积分用户").Trim(','); + } + + // 子账号贴牌编号跟随主账号 + user.oem_id = main_oem_id; + + // 子账号每单扣费金额跟随主账号 + user.postage_per_order = Math.Max(2.2m, main_postage_per_order); + user.refund_postage_per_order = Math.Max(2.5m, main_refund_postage_per_order); + user.gift_oem_amount_per_order = Math.Max(0m, main_gift_oem_amount_per_order); + } + if (string.IsNullOrEmpty(user.company_name)) + { + user.company_name = "-"; + } + + if (!user.oem_id.IsNullOrEmpty()) + { + sql = "select * from wxxd.oem where oem_id='" + user.oem_id + "'"; + var dtr = mySql.ExecuteDataTableRow(sql); + if (!string.IsNullOrEmpty(mySql.Message) || dtr == null) + { + mySql.Close(); + return "{\"code\":500,\"msg\":\"获取用户信息失败,请重试\"}"; + } + user.oem_name = dtr["oem_name"].ParseToString(); + user.is_oem_owner = dtr["oem_owner"].ParseToString() == user.user_name; + } + + var data = JsonUtils.SerializeObjectToString(user); + + mySql.Close(); + return "{\"code\":200,\"msg\":\"success\",\"data\":" + data + ",\"c\":\"" + EncrypUtil.Encryption(r2) + "\"}"; + } + mySql.Close(); + return "{\"code\":1,\"msg\":\"用户名或密码错误\"}"; + + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + /// + /// 添加子账号 + /// + /// + /// + public string AddSubUser(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + if (!GetSign(inputData)) + return "{\"code\":999,\"msg\":\"校验失败\"}"; + + var parent_user_name = RegexUtils.GetStringQuery(ref inputData, "user_name")?.Replace("'", "\\'"); + var nick_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "sub_nick_name"))?.Replace("'", "\\'"); + var user_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "sub_name"))?.Replace("'", "\\'"); + var mobile = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "sub_mobile"))?.Replace("'", "\\'"); + var password = RegexUtils.GetStringQuery(ref inputData, "sub_password")?.Replace("'", "\\'"); + var group_id = RegexUtils.GetStringQuery(ref inputData, "group_id")?.Replace("'", "\\'"); + var card_id = RegexUtils.GetStringQuery(ref inputData, "card_id")?.Replace("'", "\\'"); + var company_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "company"))?.Replace("'", "\\'"); + var notes = RegexUtils.GetStringQuery(ref inputData, "notes")?.Replace("'", "\\'"); + var authority = RegexUtils.GetStringQuery(ref inputData, "authority")?.Replace("'", "\\'"); + var forbidden_page = RegexUtils.GetStringQuery(ref inputData, "forbidden_page")?.Replace("'", "\\'"); + int r2 = 0; + int.TryParse(RegexUtils.GetStringQuery(ref inputData, "r2"), out r2); + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = ""; + sql = "select exists (select 1 from wxxd.user where user_name='" + user_name + "')"; + var exist = mySql.ExecuteFirstInt(sql); + if (exist > 0) + { + mySql.Close(); + return "{\"code\":500,\"msg\":\"用户名已存在\"}"; + } + + sql = "INSERT into wxxd.user (nick_name,user_name,mobile,password,card_id,group_id,company_name,notes,parent_user_name," + + "authority,forbidden_page,add_time,mdy_time) " + + "VALUES ('" + nick_name + "','" + user_name + "','" + mobile + "','" + password + "','" + card_id + "','" + + group_id + "','" + company_name + "','" + notes + "','" + parent_user_name + "','" + authority + "','" + forbidden_page + "','" + + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "','" + + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "');"; + var rst = mySql.ExecuteNonQuery(sql); + mySql.Close(); + if (!rst) + return "{\"code\":501,\"msg\":\""+ mySql.Message + "\"}"; + else + return "{\"code\":200,\"msg\":\"子账户创建成功!\"}"; + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + public string GetSubUser(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + if (!GetSign(inputData)) + return "{\"code\":999,\"msg\":\"校验失败\"}"; + + var user_name = RegexUtils.GetStringQuery(ref inputData, "user_name"); + var password = RegexUtils.GetStringQuery(ref inputData, "password"); + var group = RegexUtils.GetStringQuery(ref inputData, "group"); + int r2 = 0; + int.TryParse(RegexUtils.GetStringQuery(ref inputData, "r2"), out r2); + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = "select * from wxxd.user where parent_user_name='" + + user_name + "'"; + + var dt = mySql.ExecuteDataTable(sql); + mySql.Close(); + if (dt != null) + { + List userList = new List(); + foreach (DataRow row in dt.Rows) + { + + UserLoginResultParam user = new UserLoginResultParam + { + id = Convert.ToInt32(row["id"]), + user_name = row["user_name"].ToString(), + nick_name = row["nick_name"].ToString(), + mobile = row["mobile"].ToString(), + password = row["password"].ToString(), + group_id = row["group_id"].ToString(), + card_id = row["card_id"].ToString(), + parent_user_name = row["parent_user_name"].ToString(), + company_name = row["company_name"].ToString(), + notes = row["notes"].ToString(), + authority = row.Table.Columns.Contains("authority") ? row["authority"].ParseToString() : "", + forbidden_page = row.Table.Columns.Contains("forbidden_page") ? row["forbidden_page"].ParseToString() : "", + }; + if (string.IsNullOrEmpty(user.mobile)) + { + user.mobile = row["user_name"].ToString(); + } + userList.Add(user); + } + var data = JsonUtils.SerializeObjectToString(userList); + return "{\"code\":200,\"msg\":\"success\",\"data\":" + data + ",\"c\":\"" + EncrypUtil.Encryption(r2) + "\"}"; + } + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + public string UpdateSubUser(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + if (!GetSign(inputData)) + return "{\"code\":999,\"msg\":\"校验失败\"}"; + + var id = RegexUtils.GetStringQuery(ref inputData, "id")?.Replace("'", "\\'"); + var parent_user_name = RegexUtils.GetStringQuery(ref inputData, "user_name")?.Replace("'", "\\'"); + var nick_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "sub_nick_name"))?.Replace("'", "\\'"); + var user_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "sub_name"))?.Replace("'", "\\'"); + var mobile = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "sub_mobile"))?.Replace("'", "\\'"); + var password = RegexUtils.GetStringQuery(ref inputData, "sub_password")?.Replace("'", "\\'"); + var group_id = RegexUtils.GetStringQuery(ref inputData, "group_id")?.Replace("'", "\\'"); + var card_id = RegexUtils.GetStringQuery(ref inputData, "card_id")?.Replace("'", "\\'"); + var notes = RegexUtils.GetStringQuery(ref inputData, "notes")?.Replace("'", "\\'"); + var authority = RegexUtils.GetStringQuery(ref inputData, "authority")?.Replace("'", "\\'"); + var forbidden_page = RegexUtils.GetStringQuery(ref inputData, "forbidden_page")?.Replace("'", "\\'"); + int r2 = 0; + int.TryParse(RegexUtils.GetStringQuery(ref inputData, "r2"), out r2); + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = ""; + //sql = "select * from wxxd.user where parent_user_name='" + // + user_name + "'"; + sql = "update wxxd.user set"; + if (!string.IsNullOrEmpty(nick_name)) + sql += " nick_name='" + nick_name + "',"; + if (!string.IsNullOrEmpty(user_name)) + sql += " user_name='" + user_name + "',"; + if (!string.IsNullOrEmpty(mobile)) + sql += " mobile='" + mobile + "',"; + if (!string.IsNullOrEmpty(password)) + sql += " password='" + password + "',"; + if (!string.IsNullOrEmpty(group_id)) + sql += " group_id=" + group_id + ","; + if (!string.IsNullOrEmpty(card_id)) + sql += " card_id='" + card_id + "',"; + if (!string.IsNullOrEmpty(notes)) + sql += " notes='" + notes + "',"; + if (authority != null) + sql += " authority='" + authority + "',"; + if (forbidden_page != null) + sql += " forbidden_page='" + forbidden_page + "',"; + sql = sql.TrimEnd(','); + sql += " where id=" + id + ""; + + var rst = mySql.ExecuteNonQuery(sql); + mySql.Close(); + if (rst) + { + return "{\"code\":200,\"msg\":\"success\"}"; + } + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + public string DelUser(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + if (!GetSign(inputData)) + return "{\"code\":999,\"msg\":\"校验失败\"}"; + + var user_name = RegexUtils.GetStringQuery(ref inputData, "user_name"); + var id = RegexUtils.GetStringQuery(ref inputData, "id"); + int r2 = 0; + int.TryParse(RegexUtils.GetStringQuery(ref inputData, "r2"), out r2); + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = "delete from wxxd.user where id='" + + id + "'"; + + var rst = mySql.ExecuteNonQuery(sql); + mySql.Close(); + if (rst) + { + return "{\"code\":200,\"msg\":\"success\"}"; + } + else + return "{\"code\":500,\"msg\":\"删除失败,请稍后重试\"}"; + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + public string GetAllUser(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + if (!GetSign(inputData)) + return "{\"code\":999,\"msg\":\"校验失败\"}"; + + var user_name = RegexUtils.GetStringQuery(ref inputData, "user_name")?.Replace("'", "\\'"); + var password = RegexUtils.GetStringQuery(ref inputData, "password")?.Replace("'", "\\'"); + var group_id = RegexUtils.GetStringQuery(ref inputData, "group_id")?.Replace("'", "\\'"); + var search = RegexUtils.GetStringQuery(ref inputData, "search")?.Replace("'", "\\'"); + var sa_level = RegexUtils.GetStringQuery(ref inputData, "sa_level")?.Replace("'", "\\'"); + var user_name_in = RegexUtils.GetStringQuery(ref inputData, "user_name_in")?.Replace("'", "\\'"); + var search_user_name = RegexUtils.GetStringQuery(ref inputData, "search_user_name")?.Replace("'", "\\'"); + var search_nick_name = RegexUtils.GetStringQuery(ref inputData, "search_nick_name")?.Replace("'", "\\'"); + var search_company_name = RegexUtils.GetStringQuery(ref inputData, "search_company_name")?.Replace("'", "\\'"); + var search_authoritys_and = RegexUtils.GetStringQuery(ref inputData, "search_authoritys_and")?.Replace("'", "\\'"); + var search_authoritys_or = RegexUtils.GetStringQuery(ref inputData, "search_authoritys_or")?.Replace("'", "\\'"); + var oem_id = RegexUtils.GetStringQuery(ref inputData, "oem_id")?.Replace("'", "\\'"); + var is_not_count = RegexUtils.GetStringQuery(ref inputData, "is_not_count")?.Replace("'", "\\'"); + + + int page = RegexUtils.GetStringQuery(ref inputData, "page").ParseToInt(); + int page_size = RegexUtils.GetStringQuery(ref inputData, "page_size").ParseToInt(5000); + + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + + //string sql = "select * from wxxd.user where group_id=3"; + string sql = "select COUNT(*) " + + " FROM wxxd.user u " + + " LEFT JOIN wxxd.user uu ON uu.user_name=u.parent_user_name " + + " LEFT JOIN wxxd.oem o ON uu.oem_id=o.oem_id or u.oem_id=o.oem_id " + + " WHERE 1=1"; + + + string where = ""; + if (!string.IsNullOrEmpty(group_id)) + where += " AND u.group_id=" + group_id; + if (!string.IsNullOrEmpty(sa_level)) + where += " AND u.sa_level=" + sa_level; + if (!string.IsNullOrEmpty(user_name_in)) + where += " AND u.user_name in ('" + user_name_in.Replace(",", "','") + "')"; + if (!string.IsNullOrEmpty(search_user_name)) + where += " AND u.user_name like '%" + search_user_name + "%'"; + if (!string.IsNullOrEmpty(search_nick_name)) + where += " AND u.nick_name like '%" + search_nick_name + "%'"; + if (!string.IsNullOrEmpty(search_company_name)) + where += " AND u.company_name like '%" + search_company_name + "%'"; + if (!string.IsNullOrEmpty(search_authoritys_and)) + { + var search_authority_list = search_authoritys_and.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries).Distinct().ToList(); + foreach (var auth in search_authority_list) + { + where += " AND u.authority like '%" + auth + "%'"; + } + } + if (!string.IsNullOrEmpty(search_authoritys_or)) + { + where += " AND ("; + var search_authority_list = search_authoritys_or.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries).Distinct().ToList(); + int index = 0; + foreach (var auth in search_authority_list) + { + if (index == 0) + where += " u.authority like '%" + auth + "%'"; + else + where += " or u.authority like '%" + auth + "%'"; + index++; + } + where += " )"; + } + + if (!string.IsNullOrEmpty(search)) + where += " AND (u.user_name like '%" + search + + "%' or u.nick_name like '%" + search + + "%' or u.company_name like '%" + search + "%')"; + + if (!string.IsNullOrEmpty(oem_id)) + where += " AND (u.oem_id='" + oem_id + "' or uu.oem_id='" + oem_id + "')"; + + sql += where; + + int count = -1; + if (is_not_count != "true") + { + count = mySql.ExecuteFirstInt(sql); + if (!mySql.Message.IsNullOrEmpty()) + { + mySql.Close(); + return "{\"code\":500,\"msg\":\"" + mySql.Message + "\"}"; + } + if (count == 0) + { + return "{\"code\":200,\"msg\":\"success\",\"data\":[]}"; + } + } + + sql = "select u.*,uu.authority as main_authority,uu.oem_id as main_oem_id," + + " uu.postage_per_order as main_postage_per_order," + + " uu.refund_postage_per_order as main_refund_postage_per_order," + + " uu.gift_oem_amount_per_order as main_gift_oem_amount_per_order,o.oem_name " + + " FROM wxxd.user u " + + " LEFT JOIN wxxd.user uu ON uu.user_name=u.parent_user_name " + + " LEFT JOIN wxxd.oem o ON uu.oem_id=o.oem_id or u.oem_id=o.oem_id " + + " WHERE 1=1"; + sql += where; + + sql += " ORDER BY u.id desc"; + sql += " limit " + Math.Max(page - 1, 0) * page_size + "," + page_size; + + var dt = mySql.ExecuteDataTable(sql); + mySql.Close(); + if (!mySql.Message.IsNullOrEmpty()) + { + mySql.Close(); + return "{\"code\":500,\"msg\":\"" + mySql.Message + "\"}"; + } + if (dt != null) + { + List userList = new List(); + foreach (DataRow row in dt.Rows) + { + UserLoginResultParam user = new UserLoginResultParam + { + id = Convert.ToInt32(row["id"]), + user_name = row["user_name"].ToString(), + nick_name = row["nick_name"].ToString(), + mobile = row["mobile"].ToString(), + password = row["password"].ToString(), + group_id = row["group_id"].ToString(), + card_id = row["card_id"].ToString(), + parent_user_name = row["parent_user_name"].ToString(), + oem_id = row["oem_id"].ToString(), + oem_name = row["oem_name"].ToString(), + company_name = row["company_name"].ToString(), + notes = row["notes"].ToString(), + is_sa = row.Table.Columns.Contains("is_sa") ? row["is_sa"].ParseToInt() : 0, + sa_level = row.Table.Columns.Contains("sa_level") ? row["sa_level"].ParseToInt() : 0, + authority = row.Table.Columns.Contains("authority") ? row["authority"].ParseToString() : "", + forbidden_page = row.Table.Columns.Contains("forbidden_page") ? row["forbidden_page"].ParseToString() : "", + points = row.Table.Columns.Contains("points") ? row["points"].ParseToInt() : 0, + shop_points_per_month = row.Table.Columns.Contains("shop_points_per_month") ? row["shop_points_per_month"].ParseToInt() : 30, + balance = row.Table.Columns.Contains("balance") ? row["balance"].ParseToDecimal() : 0, + recharge_amount_total = row.Table.Columns.Contains("recharge_amount_total") ? row["recharge_amount_total"].ParseToDecimal() : 0, + postage_per_order = row.Table.Columns.Contains("postage_per_order") ? row["postage_per_order"].ParseToNullableDecimal() : null, + refund_postage_per_order = row.Table.Columns.Contains("refund_postage_per_order") ? row["refund_postage_per_order"].ParseToNullableDecimal() : null, + gift_oem_amount_per_order = row.Table.Columns.Contains("gift_oem_amount_per_order") ? row["gift_oem_amount_per_order"].ParseToNullableDecimal() : null, + }; + var main_authority = row.Table.Columns.Contains("main_authority") ? row["main_authority"].ParseToString() : ""; + var main_oem_id = row.Table.Columns.Contains("main_oem_id") ? row["main_oem_id"].ParseToString() : ""; + var main_postage_per_order = row.Table.Columns.Contains("main_postage_per_order") ? row["main_postage_per_order"].ParseToDecimal() : 0m; + var main_refund_postage_per_order = row.Table.Columns.Contains("main_refund_postage_per_order") ? row["main_refund_postage_per_order"].ParseToDecimal() : 0m; + var main_gift_oem_amount_per_order = row.Table.Columns.Contains("main_gift_oem_amount_per_order") ? row["main_gift_oem_amount_per_order"].ParseToDecimal() : 0m; + + if (user.group_id != "3") + { + // 子账号积分用户权限跟随主账号 + var userAuthLst = user.authority.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries).ToList(); + if (!main_authority.Contains("积分用户")) + { + userAuthLst.Remove("积分用户"); + user.authority = string.Join(",", userAuthLst); + } + else if (!user.authority.Contains("积分用户")) + { + user.authority = (user.authority + "," + "积分用户").Trim(','); + } + + // 子账号贴牌编号跟随主账号 + user.oem_id = main_oem_id; + + // 子账号每单扣费金额跟随主账号 + user.postage_per_order = Math.Max(2.2m, main_postage_per_order); + user.refund_postage_per_order = Math.Max(2.5m, main_refund_postage_per_order); + user.gift_oem_amount_per_order = Math.Max(0m, main_gift_oem_amount_per_order); + } + if (string.IsNullOrEmpty(user.mobile)) + { + user.mobile = row["user_name"].ToString(); + } + userList.Add(user); + } + var data = JsonUtils.SerializeObjectToString(userList); + return "{\"code\":200,\"msg\":\"success\",\"data\":" + data + ",\"count\":" + count + "}"; + } + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + public string AddUser(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + if (!GetSign(inputData)) + return "{\"code\":999,\"msg\":\"校验失败\"}"; + + var nick_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "add_nick_name"))?.Replace("'", "\\'"); + var user_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "add_user_name"))?.Replace("'", "\\'"); + var mobile = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "add_mobile"))?.Replace("'", "\\'"); + var password = RegexUtils.GetStringQuery(ref inputData, "add_password")?.Replace("'", "\\'"); + var company_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "add_company"))?.Replace("'", "\\'"); + var group_id = RegexUtils.GetStringQuery(ref inputData, "group_id")?.Replace("'", "\\'"); ; + var card_id = RegexUtils.GetStringQuery(ref inputData, "card_id")?.Replace("'", "\\'"); + var notes = RegexUtils.GetStringQuery(ref inputData, "notes")?.Replace("'", "\\'"); + var sa_level = RegexUtils.GetStringQuery(ref inputData, "sa_level")?.Replace("'", "\\'"); + var authority = RegexUtils.GetStringQuery(ref inputData, "authority")?.Replace("'", "\\'"); + var forbidden_page = RegexUtils.GetStringQuery(ref inputData, "forbidden_page")?.Replace("'", "\\'"); + var oem_id = RegexUtils.GetStringQuery(ref inputData, "oem_id")?.Replace("'", "\\'"); + + var shop_points_per_month = RegexUtils.GetStringQuery(ref inputData, "shop_points_per_month")?.Replace("'", "\\'"); + if (shop_points_per_month.ParseToInt() <= 30) // 充值用户月积分消耗点数,最小30 + shop_points_per_month = "30"; + var postage_per_order = RegexUtils.GetStringQuery(ref inputData, "postage_per_order")?.Replace("'", "\\'"); + if (postage_per_order.ParseToDecimal() <= 2.2m) // 每单费用 + postage_per_order = "2.2"; + var refund_postage_per_order = RegexUtils.GetStringQuery(ref inputData, "refund_postage_per_order")?.Replace("'", "\\'"); + if (refund_postage_per_order.ParseToDecimal() <= 2.5m) // 每单费用 + refund_postage_per_order = "2.5"; + var gift_oem_amount_per_order = RegexUtils.GetStringQuery(ref inputData, "gift_oem_amount_per_order")?.Replace("'", "\\'"); + if (gift_oem_amount_per_order.ParseToDecimal() < 0m) // 每单费用 + gift_oem_amount_per_order = "0"; + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = ""; + sql = "select exists (select 1 from wxxd.user where user_name='" + user_name + "')"; + var exist = mySql.ExecuteFirstInt(sql); + if (exist > 0) + { + mySql.Close(); + return "{\"code\":500,\"msg\":\"用户名已存在\"}"; + } + + sql = "insert into wxxd.user (nick_name,user_name,mobile,password,card_id,group_id,company_name,notes,sa_level,authority," + + "forbidden_page,shop_points_per_month,postage_per_order,refund_postage_per_order,gift_oem_amount_per_order,oem_id,add_time,mdy_time) " + + "values ('" + nick_name + "','" + user_name + "','" + mobile + "','" + password + "','" + card_id + "','" + + group_id + "','" + company_name + "','" + notes + "'," + sa_level + ",'" + authority + "','" + forbidden_page + "'," + + shop_points_per_month + "," + postage_per_order + "," + refund_postage_per_order + "," + gift_oem_amount_per_order + ",@oem_id,'" + + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "','" + + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "');"; + + List paramLst = new List(); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "oem_id", Value = oem_id, }); + + var rst = mySql.ExecuteNonQuery(sql, paramLst.ToArray()); + mySql.Close(); + if (!rst) + return "{\"code\":501,\"msg\":\"" + mySql.Message + "\"}"; + else + return "{\"code\":200,\"msg\":\"success\"}"; + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + public string UpdateUser(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + if (!GetSign(inputData)) + return "{\"code\":999,\"msg\":\"校验失败\"}"; + + var id = RegexUtils.GetStringQuery(ref inputData, "id")?.Replace("'", "\\'"); + var nick_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "add_nick_name"))?.Replace("'", "\\'"); + var user_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "add_user_name"))?.Replace("'", "\\'"); + var mobile = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "add_mobile"))?.Replace("'", "\\'"); + var company_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "add_company"))?.Replace("'", "\\'"); + var password = RegexUtils.GetStringQuery(ref inputData, "add_password")?.Replace("'", "\\'"); + var group_id = RegexUtils.GetStringQuery(ref inputData, "group_id")?.Replace("'", "\\'"); + var card_id = RegexUtils.GetStringQuery(ref inputData, "card_id")?.Replace("'", "\\'"); + var notes = RegexUtils.GetStringQuery(ref inputData, "notes")?.Replace("'", "\\'"); + var sa_level = RegexUtils.GetStringQuery(ref inputData, "sa_level")?.Replace("'", "\\'"); + var authority = RegexUtils.GetStringQuery(ref inputData, "authority")?.Replace("'", "\\'"); + var forbidden_page = RegexUtils.GetStringQuery(ref inputData, "forbidden_page")?.Replace("'", "\\'"); + var shop_points_per_month = RegexUtils.GetStringQuery(ref inputData, "shop_points_per_month")?.Replace("'", "\\'"); + var postage_per_order = RegexUtils.GetStringQuery(ref inputData, "postage_per_order")?.Replace("'", "\\'"); + var refund_postage_per_order = RegexUtils.GetStringQuery(ref inputData, "refund_postage_per_order")?.Replace("'", "\\'"); + var gift_oem_amount_per_order = RegexUtils.GetStringQuery(ref inputData, "gift_oem_amount_per_order")?.Replace("'", "\\'"); + var oem_id = RegexUtils.GetStringQuery(ref inputData, "oem_id")?.Replace("'", "\\'"); + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = ""; + //sql = "select * from wxxd.user where parent_user_name='" + // + user_name + "'"; + sql = "update wxxd.user set"; + if (!string.IsNullOrEmpty(nick_name)) + sql += " nick_name='" + nick_name + "',"; + if (!string.IsNullOrEmpty(user_name)) + sql += " user_name='" + user_name + "',"; + if (!string.IsNullOrEmpty(mobile)) + sql += " mobile='" + mobile + "',"; + if (!string.IsNullOrEmpty(company_name)) + sql += " company_name='" + company_name + "',"; + if (!string.IsNullOrEmpty(password)) + sql += " password='" + password + "',"; + if (!string.IsNullOrEmpty(group_id)) + sql += " group_id=" + group_id + ","; + if (!string.IsNullOrEmpty(card_id)) + sql += " card_id='" + card_id + "',"; + if (!string.IsNullOrEmpty(notes)) + sql += " notes='" + notes + "',"; + if (!string.IsNullOrEmpty(sa_level)) + sql += " sa_level=" + sa_level + ","; + if (authority != null) + sql += " authority='" + authority + "',"; + if (forbidden_page != null) + sql += " forbidden_page='" + forbidden_page + "',"; + if (shop_points_per_month != null) + sql += " shop_points_per_month=" + shop_points_per_month + ","; + if (postage_per_order != null) + sql += " postage_per_order=" + postage_per_order + ","; + if (refund_postage_per_order != null) + sql += " refund_postage_per_order=" + refund_postage_per_order + ","; + if (gift_oem_amount_per_order != null) + sql += " gift_oem_amount_per_order=" + gift_oem_amount_per_order + ","; + if (oem_id != null) + sql += " oem_id='" + oem_id + "',"; + sql = sql.TrimEnd(','); + sql += " where id=" + id + ""; + + var rst = mySql.ExecuteAffectedRows(sql); + mySql.Close(); + if (!mySql.Message.IsNullOrEmpty()) + { + return "{\"code\":500,\"msg\":\"" + mySql.Message + "\"}"; + } + return "{\"code\":200,\"msg\":\"success\",\"affected_rows\":" + rst + "}"; + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + public string AddUserTopUpMsg(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + if (!GetSign(inputData)) + return "{\"code\":999,\"msg\":\"校验失败\"}"; + + var nick_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "add_nick_name"))?.Replace("'", "\\'"); + var user_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "add_user_name"))?.Replace("'", "\\'"); + var msg = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "msg"))?.Replace("'", "\\'"); + if (string.IsNullOrEmpty(user_name)) + return "{\"code\":501,\"msg\":\"请输入用户名\"}"; + if (string.IsNullOrEmpty(msg)) + return "{\"code\":501,\"msg\":\"请输入充值备注信息\"}"; + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + string sql; + sql = "INSERT INTO wxxd.user_points_top_up_msg (nick_name,user_name,msg) " + + "VALUES ('" + nick_name + "','" + user_name + "','" + msg + "');"; + var rst = mySql.ExecuteNonQuery(sql); + mySql.Close(); + if (!rst) + return "{\"code\":501,\"msg\":\"" + mySql.Message + "\"}"; + else + return "{\"code\":200,\"msg\":\"success\"}"; + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + public string UpdateUserTopUpMsg(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + if (!GetSign(inputData)) + return "{\"code\":999,\"msg\":\"校验失败\"}"; + + var id = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "id"))?.Replace("'", "\\'"); + var op_rst = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "op_rst"))?.Replace("'", "\\'"); + if (string.IsNullOrEmpty(id)) + return "{\"code\":501,\"msg\":\"请输入要修改的记录\"}"; + if (string.IsNullOrEmpty(op_rst)) + return "{\"code\":501,\"msg\":\"请输入操作结果\"}"; + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + string sql; + sql = "UPDATE wxxd.user_points_top_up_msg SET op_rst='" + op_rst + "' WHERE id='" + id + "';"; + var rst = mySql.ExecuteNonQuery(sql); + mySql.Close(); + if (!rst) + return "{\"code\":501,\"msg\":\"" + mySql.Message + "\"}"; + else + return "{\"code\":200,\"msg\":\"success\"}"; + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + /// + /// 增加或减少用户积分 + /// + /// + /// + public string UpdateUserPoints(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + if (!GetSign(inputData)) + return "{\"code\":999,\"msg\":\"校验失败\"}"; + + var user_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "update_user_name"))?.Replace("'", "\\'"); + var user_nick = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "update_user_nick"))?.Replace("'", "\\'"); + var delta_points = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "delta_points")).ParseToInt(); + var option_type = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "option_type"))?.Replace("'", "\\'"); + var operator_type = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "operator_type"))?.Replace("'", "\\'"); + var operator_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "operator_name"))?.Replace("'", "\\'"); + var operator_nick = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "operator_nick"))?.Replace("'", "\\'"); + var shop_id = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "shop_id"))?.Replace("'", "\\'"); + var shop_account = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "shop_account"))?.Replace("'", "\\'"); + + if (string.IsNullOrEmpty(user_name) || string.IsNullOrEmpty(user_nick)) + { + return "{\"code\":500,\"msg\":\"操作对象不能为空\"}"; + } + if (delta_points <= 0 && option_type == "续费") + { + return "{\"code\":500,\"msg\":\"续费金额错误,需大于0\"}"; + } + if (delta_points == 0) + { + return "{\"code\":500,\"msg\":\"操作金额错误,不能等于0\"}"; + } + if (string.IsNullOrEmpty(option_type) || string.IsNullOrEmpty(operator_type) || string.IsNullOrEmpty(operator_name)) + { + return "{\"code\":500,\"msg\":\"操作或操作者信息错误\"}"; + } + if (option_type != "充值" && option_type != "续费" && option_type != "转移") + { + return "{\"code\":500,\"msg\":\"操作类型错误\"}"; + } + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn, true); + string sql; + decimal userPoints; + decimal userPointsNew; + decimal userTotalPoints; + decimal userTotalPointsNew; + decimal operatorPoints; + decimal operatorPointsNew; + decimal shopPointsPerMonth = 30; + + // 账户之间的转移单独写 + if (option_type == "转移") + { + // 转移查找自己账户及对方账户确定余额足够 + sql = "SELECT points FROM `wxxd`.`user` WHERE user_name='" + operator_name + "'"; + operatorPoints = mySql.ExecuteFirstDecimal(sql); + if (!mySql.Message.IsNullOrEmpty()) + { + mySql.RollBack(); + mySql.Close(); + return "{\"code\":500,\"msg\":\"查询错误:" + mySql.Message + "\"}"; + } + if (operatorPoints < delta_points) + { + mySql.RollBack(); + mySql.Close(); + return "{\"code\":500,\"msg\":\"余额不足\"}"; + } + sql = "SELECT points FROM `wxxd`.`user` WHERE user_name='" + user_name + "'"; + userPoints = mySql.ExecuteFirstDecimal(sql); + if (!mySql.Message.IsNullOrEmpty()) + { + mySql.RollBack(); + mySql.Close(); + return "{\"code\":500,\"msg\":\"查询错误:" + mySql.Message + "\"}"; + } + if (userPoints < -delta_points) + { + mySql.RollBack(); + mySql.Close(); + return "{\"code\":500,\"msg\":\"对方账户余额不足\"}"; + } + sql = "SELECT recharge_points_total FROM `wxxd`.`user` WHERE user_name='" + user_name + "'"; + userTotalPoints = mySql.ExecuteFirstDecimal(sql); + if (!mySql.Message.IsNullOrEmpty()) + { + mySql.RollBack(); + mySql.Close(); + return "{\"code\":500,\"msg\":\"查询错误:" + mySql.Message + "\"}"; + } + + userPointsNew = userPoints + delta_points; + userTotalPointsNew = userTotalPoints + delta_points; + sql = " UPDATE `wxxd`.`user` SET points=" + userPointsNew + ",recharge_points_total=" + userTotalPointsNew; + sql += " WHERE user_name='" + user_name + "' AND points=" + userPoints + ";"; + var toPointsRst = mySql.ExecuteAffectedRows(sql); + if (!string.IsNullOrEmpty(mySql.Message)) + { + mySql.RollBack(); + mySql.Close(); + return "{\"code\":501,\"msg\":\"" + mySql.Message + "\"}"; + } + else if (toPointsRst <= 0) + { + mySql.RollBack(); + mySql.Close(); + return "{\"code\":500,\"msg\":\"收款账户已发生改变,请刷新账户后重新操作\"}"; + } + + operatorPointsNew = operatorPoints - delta_points; + sql = " UPDATE `wxxd`.`user` SET points=" + operatorPointsNew; + sql += " WHERE user_name='" + operator_name + "' AND points=" + operatorPoints + ";"; + var fromPointsRst = mySql.ExecuteAffectedRows(sql); + if (!string.IsNullOrEmpty(mySql.Message)) + { + mySql.RollBack(); + mySql.Close(); + return "{\"code\":501,\"msg\":\"" + mySql.Message + "\"}"; + } + else if (fromPointsRst <= 0) + { + mySql.RollBack(); + mySql.Close(); + return "{\"code\":500,\"msg\":\"付款账户已发生改变,请刷新账户后重新操作\"}"; + } + + // 转入 + sql = " INSERT INTO wxxd.user_points_record" + + " (user_name,user_nick,delta_points,new_points,option_type,operator_type,operator_name,shop_id,shop_account,counterparty_account_name)"; + sql += " VALUES" + + " (@user_name,@user_nick,@delta_points,@new_points,@option_type,@operator_type,@operator_name,@shop_id,@shop_account,@counterparty_account_name);"; + List paramLst = new List(); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "user_name", Value = user_name, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "user_nick", Value = user_nick, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.Decimal, ParameterName = "delta_points", Value = delta_points, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.Decimal, ParameterName = "new_points", Value = userPointsNew, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "option_type", Value = "转入" }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "operator_type", Value = operator_type, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "operator_name", Value = operator_name, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "shop_id", Value = shop_id, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "shop_account", Value = shop_account, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "counterparty_account_name", Value = operator_name, }); + var addOptionRst = mySql.ExecuteAffectedRows(sql, paramLst.ToArray()); + if (!string.IsNullOrEmpty(mySql.Message)) + { + mySql.RollBack(); + mySql.Close(); + return "{\"code\":501,\"msg\":\"" + mySql.Message + "\"}"; + } + else if (addOptionRst <= 0) + { + mySql.RollBack(); + mySql.Close(); + return "{\"code\":500,\"msg\":\"新增操作记录失败,请稍候重试\"}"; + } + + // 转出 + sql = " INSERT INTO wxxd.user_points_record" + + "(user_name,user_nick,delta_points,new_points,option_type,operator_type,operator_name,shop_id,shop_account,counterparty_account_name)"; + sql += " VALUES" + + "(@user_name,@user_nick,@delta_points,@new_points,@option_type,@operator_type,@operator_name,@shop_id,@shop_account,@counterparty_account_name);"; + paramLst = new List(); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "user_name", Value = operator_name, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "user_nick", Value = operator_nick, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.Decimal, ParameterName = "delta_points", Value = delta_points, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.Decimal, ParameterName = "new_points", Value = operatorPointsNew, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "option_type", Value = "转出" }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "operator_type", Value = operator_type, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "operator_name", Value = operator_name, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "shop_id", Value = shop_id, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "shop_account", Value = shop_account, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "counterparty_account_name", Value = user_name, }); + addOptionRst = mySql.ExecuteAffectedRows(sql, paramLst.ToArray()); + if (!string.IsNullOrEmpty(mySql.Message)) + { + mySql.RollBack(); + mySql.Close(); + return "{\"code\":501,\"msg\":\"" + mySql.Message + "\"}"; + } + else if (addOptionRst <= 0) + { + mySql.RollBack(); + mySql.Close(); + return "{\"code\":500,\"msg\":\"新增操作记录失败,请稍候重试\"}"; + } + + mySql.Commit(); + mySql.Close(); + return "{\"code\":200,\"msg\":\"success\",\"newOperatorPoints\":" + operatorPointsNew + ",\"newUserPoints\":" + userPointsNew + "}"; + } + else + { + #region 计算是否余额不足 + sql = "SELECT points FROM `wxxd`.`user` WHERE user_name='" + user_name + "'"; + userPoints = mySql.ExecuteFirstDecimal(sql); + if (!string.IsNullOrEmpty(mySql.Message)) + { + mySql.RollBack(); + mySql.Close(); + return "{\"code\":501,\"msg\":\"" + mySql.Message + "\"}"; + } + sql = "SELECT recharge_points_total FROM `wxxd`.`user` WHERE user_name='" + user_name + "'"; + userTotalPoints = mySql.ExecuteFirstDecimal(sql); + if (!mySql.Message.IsNullOrEmpty()) + { + mySql.RollBack(); + mySql.Close(); + return "{\"code\":500,\"msg\":\"查询错误:" + mySql.Message + "\"}"; + } + + if (option_type == "续费") + { + sql = "SELECT shop_points_per_month FROM `wxxd`.`user` WHERE user_name='" + user_name + "'"; + shopPointsPerMonth = mySql.ExecuteFirstDecimal(sql); // 店铺续费一个月的点数,默认30,可以设置为其他值 + if (!string.IsNullOrEmpty(mySql.Message)) + { + mySql.RollBack(); + mySql.Close(); + return "{\"code\":501,\"msg\":\"" + mySql.Message + "\"}"; + } + shopPointsPerMonth = Math.Max(30, shopPointsPerMonth); + + if (delta_points <= 0 || delta_points.ParseToInt().ParseToDecimal() != delta_points || delta_points.ParseToInt() % shopPointsPerMonth.ParseToInt() > 0) + { + mySql.RollBack(); + mySql.Close(); + return "{\"code\":501,\"msg\":\"续费点数必须是" + shopPointsPerMonth.ParseToInt() + "的整倍数\"}"; + } + else if (userPoints < delta_points) + { + mySql.RollBack(); + mySql.Close(); + return "{\"code\":500,\"msg\":\"余额不足\"}"; + } + } + #endregion + + sql = "UPDATE `wxxd`.`user` SET"; + if (option_type == "充值") + { + userPointsNew = userPoints + delta_points; + sql += " points=" + userPointsNew + ","; + userTotalPointsNew = userTotalPoints + delta_points; + sql += " recharge_points_total=" + userTotalPointsNew + ","; + } + else + { + userPointsNew = userPoints - delta_points; + sql += " points=" + userPointsNew + ","; + } + sql = sql.TrimEnd(','); + sql += " WHERE user_name='" + user_name + "' AND points=" + userPoints + ";"; + var changePointsRst = mySql.ExecuteAffectedRows(sql); + if (!string.IsNullOrEmpty(mySql.Message)) + { + mySql.RollBack(); + mySql.Close(); + return "{\"code\":501,\"msg\":\"" + mySql.Message + "\"}"; + } + else if (changePointsRst <= 0) + { + mySql.RollBack(); + mySql.Close(); + return "{\"code\":500,\"msg\":\"账户已发生改变,请刷新账户后重新操作\"}"; + } + + sql = " INSERT INTO wxxd.user_points_record(user_name,user_nick,delta_points,new_points,option_type,operator_type,operator_name,shop_id,shop_account)"; + sql += " VALUES(@user_name,@user_nick,@delta_points,@new_points,@option_type,@operator_type,@operator_name,@shop_id,@shop_account);"; + List paramLst = new List(); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "user_name", Value = user_name, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "user_nick", Value = user_nick, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.Decimal, ParameterName = "delta_points", Value = delta_points, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.Decimal, ParameterName = "new_points", Value = userPointsNew, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "option_type", Value = option_type, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "operator_type", Value = operator_type, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "operator_name", Value = operator_name, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "shop_id", Value = shop_id, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "shop_account", Value = shop_account, }); + var addOptionRst = mySql.ExecuteAffectedRows(sql, paramLst.ToArray()); + if (!string.IsNullOrEmpty(mySql.Message)) + { + mySql.RollBack(); + mySql.Close(); + return "{\"code\":501,\"msg\":\"" + mySql.Message + "\"}"; + } + else if (addOptionRst <= 0) + { + mySql.RollBack(); + mySql.Close(); + return "{\"code\":500,\"msg\":\"新增操作记录失败,请稍候重试\"}"; + } + + int expireTime = 0; + int newExpireTime = 0; + if (option_type == "续费") + { + sql = "SELECT expire_time‌ FROM `wxxd`.`user_points_shop_expire` WHERE shop_id='" + shop_id + "';"; + expireTime = mySql.ExecuteFirstInt(sql); + if (!string.IsNullOrEmpty(mySql.Message)) + { + mySql.RollBack(); + mySql.Close(); + return "{\"code\":501,\"msg\":\"" + mySql.Message + "\"}"; + } + + if (expireTime == 0) + { + newExpireTime = TimeUtils.DateTimeToTimestampSeconds(DateTime.Now.AddMonths(delta_points.ParseToInt() / shopPointsPerMonth.ParseToInt())); + sql = " INSERT INTO `wxxd`.`user_points_shop_expire` (shop_id,expire_time‌)" + + " VALUES ('" + shop_id + "'," + newExpireTime + ");"; + } + else + { + DateTime expireDateTime = TimeUtils.StampToDateTime(expireTime); + if (expireDateTime < DateTime.Now) + expireDateTime = DateTime.Now.AddMonths(delta_points.ParseToInt() / shopPointsPerMonth.ParseToInt()); + else + expireDateTime = expireDateTime.AddMonths(delta_points.ParseToInt() / shopPointsPerMonth.ParseToInt()); + newExpireTime = TimeUtils.DateTimeToTimestampSeconds(expireDateTime); + + sql = "UPDATE `wxxd`.`user_points_shop_expire` set expire_time‌=" + newExpireTime + " WHERE shop_id='" + shop_id + "' AND expire_time‌=" + expireTime; + } + var renewalRst = mySql.ExecuteAffectedRows(sql); + if (!string.IsNullOrEmpty(mySql.Message)) + { + mySql.RollBack(); + mySql.Close(); + return "{\"code\":501,\"msg\":\"" + mySql.Message + "\"}"; + } + else if (renewalRst <= 0) + { + mySql.RollBack(); + mySql.Close(); + return "{\"code\":500,\"msg\":\"店铺已发生改变,请刷新店铺后重新操作\"}"; + } + } + + mySql.Commit(); + mySql.Close(); + return "{\"code\":200,\"msg\":\"success\",\"newExpireTime\":" + newExpireTime + ",\"newUserPoints\":" + userPointsNew + "}"; + } + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + + public string GetUserPoints(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + if (!GetSign(inputData)) + return "{\"code\":999,\"msg\":\"校验失败\"}"; + + var option_type_in = RegexUtils.GetStringQuery(ref inputData, "option_type_in")?.Replace("'", "\\'"); + var user_name_in = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "user_name_in"))?.Replace("'", "\\'"); + var shop_id_in = RegexUtils.GetStringQuery(ref inputData, "shop_id_in")?.Replace("'", "\\'"); + var shop_account_in = RegexUtils.GetStringQuery(ref inputData, "shop_account_in")?.Replace("'", "\\'"); + var create_time_begin = RegexUtils.GetStringQuery(ref inputData, "create_time_begin")?.Replace("'", "\\'"); + var create_time_end = RegexUtils.GetStringQuery(ref inputData, "create_time_end")?.Replace("'", "\\'"); + var is_not_count = RegexUtils.GetStringQuery(ref inputData, "is_not_count")?.Replace("'", "\\'"); + + int page = RegexUtils.GetStringQuery(ref inputData, "page").ParseToInt(); + int page_size = RegexUtils.GetStringQuery(ref inputData, "page_size").ParseToInt(200); + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + + string sql = "SELECT count(*) " + + " FROM wxxd.user_points_record up " + + " WHERE 1=1"; + string where = ""; + if (!string.IsNullOrEmpty(option_type_in)) + where += " AND up.option_type in ('" + option_type_in + "')"; + if (!string.IsNullOrEmpty(user_name_in)) + where += " AND up.user_name in ('" + user_name_in.Replace(",", "','") + "')"; + if (!string.IsNullOrEmpty(shop_id_in)) + where += " AND up.shop_id in ('" + shop_id_in.Replace(",", "','") + "')"; + if (!string.IsNullOrEmpty(shop_account_in)) + where += " AND up.shop_account in ('" + shop_account_in.Replace(",", "','") + "')"; + if (!string.IsNullOrEmpty(create_time_begin)) + where += " AND up.add_time >= '" + create_time_begin + "'"; + if (!string.IsNullOrEmpty(create_time_end)) + where += " AND up.add_time <= '" + create_time_end + "'"; + + sql += where; + + int count = -1; + if (is_not_count != "true") + { + count = mySql.ExecuteFirstInt(sql); + if (!mySql.Message.IsNullOrEmpty()) + { + mySql.Close(); + return "{\"code\":500,\"msg\":\"" + mySql.Message + "\"}"; + } + } + + sql = "SELECT * " + + " FROM wxxd.user_points_record up " + + " WHERE 1=1"; + sql += where; + sql += " ORDER BY up.add_time desc "; + sql += " limit " + Math.Max(page - 1, 0) * page_size + "," + page_size; + + var dt = mySql.ExecuteDataTable(sql); + mySql.Close(); + if (!string.IsNullOrEmpty(mySql.Message)) + { + return "{\"code\":500,\"msg\":\"" + mySql.Message + "\"}"; + } + if (dt != null) + { + List userPaymentList = new List(); + foreach (DataRow row in dt.Rows) + { + user_points_record_info userPayment = new user_points_record_info + { + id = Convert.ToInt32(row["id"]), + user_name = row["user_name"].ParseToString(), + delta_points = row["delta_points"].ParseToInt(), + new_points = row["new_points"].ParseToNullableInt(), + operator_name = row["operator_name"].ParseToString(), + operator_type = row["operator_type"].ParseToString(), + option_type = row["option_type"].ParseToString(), + shop_account = row["shop_account"].ParseToString(), + shop_id = row["shop_id"].ParseToString(), + user_nick = row["user_nick"].ParseToString(), + remark = row["remark"].ParseToString(), + add_time = row["add_time"].ParseToString().ParseToDateTime(), + counterparty_account_name = row["counterparty_account_name"].ParseToString(), + }; + userPaymentList.Add(userPayment); + } + var data = JsonUtils.SerializeObjectToString(userPaymentList); + return "{\"code\":200,\"msg\":\"success\",\"data\":" + data + ",\"count\":\"" + count + "\"}"; + } + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + + /// + /// 增加或减少用户积分 + /// + /// + /// + public string UpdateUserBalance(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + if (!GetSign(inputData)) + return "{\"code\":999,\"msg\":\"校验失败\"}"; + + var user_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "update_user_name"))?.Replace("'", "\\'"); + var user_nick = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "update_user_nick"))?.Replace("'", "\\'"); + var delta_balance = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "delta_balance")).ParseToDecimal(); + var option_type = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "option_type"))?.Replace("'", "\\'"); + var operator_name = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "operator_name"))?.Replace("'", "\\'"); + + if (string.IsNullOrEmpty(user_name) || string.IsNullOrEmpty(user_nick)) + { + return "{\"code\":500,\"msg\":\"操作对象不能为空\"}"; + } + if (delta_balance <= 0 && option_type == "消费") + { + return "{\"code\":500,\"msg\":\"消费金额错误,需大于0\"}"; + } + if (delta_balance == 0) + { + return "{\"code\":500,\"msg\":\"操作金额错误,不能等于0\"}"; + } + if (string.IsNullOrEmpty(option_type) || string.IsNullOrEmpty(operator_name)) + { + return "{\"code\":500,\"msg\":\"操作或操作者信息错误\"}"; + } + if (option_type != "充值" && option_type != "消费") + { + return "{\"code\":500,\"msg\":\"操作类型错误\"}"; + } + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn, true); + string sql; + decimal balance = 0; + decimal recharge_amount_total = 0; + decimal newBalance = 0; + decimal newRechargeAmountTotal = 0; + + #region 计算是否余额不足 + sql = "SELECT balance,recharge_amount_total FROM `wxxd`.`user` WHERE user_name='" + user_name + "'"; + var dataRow = mySql.ExecuteDataTableRow(sql); + if (!string.IsNullOrEmpty(mySql.Message)) + { + mySql.RollBack(); + mySql.Close(); + return "{\"code\":501,\"msg\":\"" + mySql.Message + "\"}"; + } + if (dataRow == null) + { + mySql.RollBack(); + mySql.Close(); + return "{\"code\":501,\"msg\":\"用户不存在\"}"; + } + try + { + balance = dataRow["balance"].ParseToDecimal(); + newBalance = balance; + recharge_amount_total = dataRow["recharge_amount_total"].ParseToDecimal(); + newRechargeAmountTotal = recharge_amount_total; + } + catch + { + } + //if (option_type == "消费") + //{ + // sql = "SELECT shop_points_per_month FROM `wxxd`.`user` WHERE user_name='" + user_name + "'"; + // shopPointsPerMonth = mySql.ExecuteFirstInt(sql); // 店铺消费一个月的点数,默认30,可以设置为其他值 + // if (!string.IsNullOrEmpty(mySql.Message)) + // { + // mySql.RollBack(); + // mySql.Close(); + // return "{\"code\":501,\"msg\":\"" + mySql.Message + "\"}"; + // } + // shopPointsPerMonth = Math.Max(30, shopPointsPerMonth); + + // if (delta_balance <= 0 || delta_balance % shopPointsPerMonth > 0) + // { + // mySql.RollBack(); + // mySql.Close(); + // return "{\"code\":501,\"msg\":\"消费点数必须是" + shopPointsPerMonth + "的整倍数\"}"; + // } + // else if (balance < delta_balance) + // { + // mySql.RollBack(); + // mySql.Close(); + // return "{\"code\":500,\"msg\":\"余额不足\"}"; + // } + //} + #endregion + + sql = "UPDATE `wxxd`.`user` SET"; + if (option_type == "充值") + { + newBalance = balance + delta_balance; + sql += " balance=" + newBalance + ","; + newRechargeAmountTotal = recharge_amount_total + delta_balance; + sql += " recharge_amount_total=" + newRechargeAmountTotal + ","; + } + else + { + newBalance = balance - delta_balance.ParseToInt(); + sql += " balance=" + newBalance + ","; + } + sql = sql.TrimEnd(','); + sql += " WHERE user_name='" + user_name + "' AND balance=" + balance + " AND recharge_amount_total=" + recharge_amount_total + ";"; + var changePointsRst = mySql.ExecuteAffectedRows(sql); + if (!string.IsNullOrEmpty(mySql.Message)) + { + mySql.RollBack(); + mySql.Close(); + return "{\"code\":501,\"msg\":\"" + mySql.Message + "\"}"; + } + else if (changePointsRst <= 0) + { + mySql.RollBack(); + mySql.Close(); + return "{\"code\":500,\"msg\":\"" + option_type + "失败,账户余额已发生改变,请刷新账户后重新操作\"}"; + } + + sql = " INSERT INTO wxxd.user_payment_record(type,amount,balance,user_name,create_by,create_time,update_by,update_time,counterparty_account_name)"; + sql += " VALUES(@type,@amount,@balance,@user_name,@create_by,@create_time,@update_by,@update_time,@counterparty_account_name);"; + List paramLst = new List(); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "user_name", Value = user_name, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.Decimal, ParameterName = "amount", Value = delta_balance, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.Decimal, ParameterName = "balance", Value = newBalance, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.Int32, ParameterName = "type", Value = option_type == "充值" ? 1 : 0, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "create_by", Value = operator_name, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.DateTime, ParameterName = "create_time", Value = DateTime.Now, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "update_by", Value = operator_name, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.DateTime, ParameterName = "update_time", Value = DateTime.Now, }); + paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "counterparty_account_name", Value = operator_name, }); + var addOptionRst = mySql.ExecuteAffectedRows(sql, paramLst.ToArray()); + if (!string.IsNullOrEmpty(mySql.Message)) + { + mySql.RollBack(); + mySql.Close(); + return "{\"code\":501,\"msg\":\"" + mySql.Message + "\"}"; + } + else if (addOptionRst <= 0) + { + mySql.RollBack(); + mySql.Close(); + return "{\"code\":500,\"msg\":\"新增操作记录失败,请稍候重试\"}"; + } + + //int expireTime = 0; + //int newExpireTime = 0; + //if (option_type == "消费") + //{ + // sql = "SELECT expire_time‌ FROM `wxxd`.`user_points_shop_expire` WHERE shop_id='" + shop_id + "';"; + // expireTime = mySql.ExecuteFirstInt(sql); + // if (!string.IsNullOrEmpty(mySql.Message)) + // { + // mySql.RollBack(); + // mySql.Close(); + // return "{\"code\":501,\"msg\":\"" + mySql.Message + "\"}"; + // } + + // if (expireTime == 0) + // { + // newExpireTime = TimeUtils.DateTimeToTimestampSeconds(DateTime.Now.AddMonths(delta_balance.ParseToInt() / shopPointsPerMonth)); + // sql = " INSERT INTO `wxxd`.`user_points_shop_expire` (shop_id,expire_time‌)" + + // " VALUES ('" + shop_id + "'," + newExpireTime + ");"; + // } + // else + // { + // DateTime expireDateTime = TimeUtils.StampToDateTime(expireTime); + // if (expireDateTime < DateTime.Now) + // expireDateTime = DateTime.Now.AddMonths(delta_balance.ParseToInt() / shopPointsPerMonth); + // else + // expireDateTime = expireDateTime.AddMonths(delta_balance.ParseToInt() / shopPointsPerMonth); + // newExpireTime = TimeUtils.DateTimeToTimestampSeconds(expireDateTime); + + // sql = "UPDATE `wxxd`.`user_points_shop_expire` set expire_time‌=" + newExpireTime + " WHERE shop_id='" + shop_id + "' AND expire_time‌=" + expireTime; + // } + // var renewalRst = mySql.ExecuteAffectedRows(sql); + // if (!string.IsNullOrEmpty(mySql.Message)) + // { + // mySql.RollBack(); + // mySql.Close(); + // return "{\"code\":501,\"msg\":\"" + mySql.Message + "\"}"; + // } + // else if (renewalRst <= 0) + // { + // mySql.RollBack(); + // mySql.Close(); + // return "{\"code\":500,\"msg\":\"店铺已发生改变,请刷新店铺后重新操作\"}"; + // } + //} + + mySql.Commit(); + mySql.Close(); + return "{\"code\":200,\"msg\":\"success\",\"newRechargeAmountTotal\":" + newRechargeAmountTotal + ",\"newBalance\":" + newBalance + "}"; + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + public string GetUserBalance(string inputData) + { + // ALTER TABLE books ALTER INDEX idx_name INVISIBLE; --隐藏 + // ALTER TABLE books ALTER INDEX idx_name VISIBLE; --恢复 + // 双字匹配的全文索引 ALTER TABLE `user_payment_record` ADD FULLTEXT INDEX `remark_fulltext` (`remark`) WITH parser ngram + if (!string.IsNullOrEmpty(inputData)) + { + if (!GetSign(inputData)) + return "{\"code\":999,\"msg\":\"校验失败\"}"; + + var timeCalc = DateTime.Now; + + var type_in = RegexUtils.GetStringQuery(ref inputData, "type_in")?.Replace("'", "\\'"); + var user_name_in = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "user_name_in"))?.Replace("'", "\\'"); + var order_id_in = RegexUtils.GetStringQuery(ref inputData, "order_id_in")?.Replace("'", "\\'"); + var after_sale_id_in = RegexUtils.GetStringQuery(ref inputData, "after_sale_id_in")?.Replace("'", "\\'"); + var create_time_begin = RegexUtils.GetStringQuery(ref inputData, "create_time_begin")?.Replace("'", "\\'"); + var create_time_end = RegexUtils.GetStringQuery(ref inputData, "create_time_end")?.Replace("'", "\\'"); + var is_not_count = RegexUtils.GetStringQuery(ref inputData, "is_not_count")?.Replace("'", "\\'"); + var remark_fulltext = RegexUtils.GetStringQuery(ref inputData, "remark_fulltext")?.Replace("'", "\\'"); + + int page = RegexUtils.GetStringQuery(ref inputData, "page").ParseToInt(); + int page_size = RegexUtils.GetStringQuery(ref inputData, "page_size").ParseToInt(200); + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + + string sql = "SELECT count(*) " + + " FROM wxxd.user_payment_record up " + + " WHERE 1=1"; + string where = ""; + if (!string.IsNullOrEmpty(type_in)) + where += " AND up.type in (" + type_in + ")"; + if (!string.IsNullOrEmpty(user_name_in)) + where += " AND up.user_name in ('" + user_name_in.Replace(",", "','") + "')"; + if (!string.IsNullOrEmpty(order_id_in)) + where += " AND up.order_id in ('" + order_id_in.Replace(",", "','") + "')"; + if (!string.IsNullOrEmpty(after_sale_id_in)) + where += " AND up.after_sale_id in ('" + after_sale_id_in.Replace(",", "','") + "')"; + if (!string.IsNullOrEmpty(create_time_begin)) + where += " AND up.create_time >= '" + create_time_begin + "'"; + if (!string.IsNullOrEmpty(create_time_end)) + where += " AND up.create_time <= '" + create_time_end + "'"; + //if (!string.IsNullOrEmpty(remark_fulltext)) + //{ + // List fullTextSearchStr = new List(); + // var remark_fulltextLst = remark_fulltext.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries); + // foreach (var t in remark_fulltextLst) + // { + // var t1 = t; + // while (t1.Length >= 12) + // { + // fullTextSearchStr.Add(t1.Substring(0, 10)); + // t1 = t1.Substring(10); + // } + // fullTextSearchStr.Add(t1); + // } + // where += " AND MATCH(remark) AGAINST('" + string.Join(" +", fullTextSearchStr) + "' IN BOOLEAN MODE) "; + // //where += " AND MATCH(remark) AGAINST('" + string.Join(" +", fullTextSearchStr) + "' IN NATURAL LANGUAGE MODE) "; + // //where += " AND MATCH(remark) AGAINST('" + remark_fulltext.Replace(",", " ") + "' IN NATURAL LANGUAGE MODE) "; + //} + if (!string.IsNullOrEmpty(remark_fulltext)) + { + where += " AND MATCH(remark) AGAINST('" + remark_fulltext + "' IN BOOLEAN MODE)"; + } + + sql += where; + + int count = -1; + if (is_not_count != "true") + { + count = mySql.ExecuteFirstInt(sql); + if (!mySql.Message.IsNullOrEmpty()) + { + mySql.Close(); + return "{\"code\":500,\"msg\":\"" + mySql.Message + "\"}"; + } + } + + sql = "SELECT * " + + " FROM wxxd.user_payment_record up " + + " WHERE 1=1"; + sql += where; + sql += " ORDER BY up.create_time desc "; + sql += " limit " + Math.Max(page - 1, 0) * page_size + "," + page_size; + + var dt = mySql.ExecuteDataTable(sql); + mySql.Close(); + if (dt != null) + { + List userPaymentList = new List(); + foreach (DataRow row in dt.Rows) + { + user_payment_record_info userPayment = new user_payment_record_info + { + id = Convert.ToInt32(row["id"]), + user_name = row["user_name"].ParseToString(), + after_sale_id = row["after_sale_id"].ParseToLong(), + amount = row["amount"].ParseToDecimal(), + counterparty_account_name = row["counterparty_account_name"].ParseToString(), + create_by = row["create_by"].ParseToString(), + balance = row["balance"].ParseToDecimal(), + create_time = row["create_time"].ParseToString().ParseToDateTime(), + is_deleted = row["is_deleted"].ParseToInt(), + order_id = row["order_id"].ParseToString(), + platform_code = row["platform_code"].ParseToString(), + remark = row["remark"].ParseToString(), + type = row["type"].ParseToInt(), + update_by = row["update_by"].ParseToString(), + update_time = row["update_time"].ParseToString().ParseToDateTime(), + }; + userPaymentList.Add(userPayment); + } + var data = JsonUtils.SerializeObjectToString(userPaymentList); + var seconds = (DateTime.Now - timeCalc).TotalSeconds.ToString("0.000"); + return "{\"code\":200,\"msg\":\"success\",\"data\":" + data + ",\"count\":\"" + count + "\",\"seconds\":\"" + seconds + "\"}"; + } + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + public string ChangePassword(string inputData) + { + if (!GetSign(inputData)) + return "{\"code\":999,\"msg\":\"校验失败\"}"; + + var userName = RegexUtils.GetStringJson(ref inputData, "user_name")?.Replace("'", "\\'"); + var password = RegexUtils.GetStringJson(ref inputData, "password")?.Replace("'", "\\'"); + var newPassword = RegexUtils.GetStringJson(ref inputData, "new_password")?.Replace("'", "\\'"); + + if (string.IsNullOrWhiteSpace(userName) || string.IsNullOrWhiteSpace(password) || string.IsNullOrWhiteSpace(newPassword)) + { + return "{\"code\":500,\"msg\":\"输入不能为空\"}"; + } + + string conn = "Conn"; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = "select user_id,password from pepdtp.user where user_id='" + + userName + "' and password='" + password + "'"; + + var dw = mySql.ExecuteDataTableRow(sql); + if (dw != null) + { + UserLoginResultParam user = new UserLoginResultParam + { + user_name = dw["user_id"].ToString(), + password = dw["password"].ToString(), + }; + sql = "update pepdtp.user set password = '" + newPassword + "' where user_id='" + userName + "'"; + var result = mySql.ExecuteNonQuery(sql); + mySql.Close(); + + if (result) + { + return "{\"code\":0,\"msg\":\"密码修改成功!\"}"; + } + else + return "{\"code\":19999,\"msg\":\"密码修改失败!请稍后再试。\"}"; + } + else + { + mySql.Close(); + return "{\"code\":1,\"msg\":\"原密码错误。\"}"; + } + } + + public string UpdateWxSaleAssistantCookie(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + var id = (RegexUtils.GetStringQuery(ref inputData, "db_id")?.Replace("'", "\\'")).ParseToInt(); + if (id == 0) + id = 1; + var cookie = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "cookie"))?.Replace("'", "\\'"); + var time = RegexUtils.GetStringQuery(ref inputData, "time").ParseToInt(); + string time1 = RegexUtils.GetStringQuery(ref inputData, "code"); + if (time1 != EncrypUtil.Encryption(time)) + return "{\"code\":50000,\"msg\":\"校验失败\"}"; + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = "update wxxd.wx_sale_assistant_user set cookie='" + cookie + "' WHERE id=" + id + ";"; + + var rst = mySql.ExecuteNonQuery(sql); + mySql.Close(); + if (rst && string.IsNullOrEmpty(mySql.Message)) + { + return "{\"code\":200,\"msg\":\"success\"}"; + } + if (!string.IsNullOrEmpty(mySql.Message)) + { + return "{\"code\":500,\"msg\":\"" + mySql.Message + "\"}"; + } + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + public string GetWxSaleAssistantCookie(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + var id = (RegexUtils.GetStringQuery(ref inputData, "db_id")?.Replace("'", "\\'")).ParseToInt(); + if (id == 0) + id = 1; + var time = RegexUtils.GetStringQuery(ref inputData, "time").ParseToInt(); + string time1 = RegexUtils.GetStringQuery(ref inputData, "code"); + if (time1 != EncrypUtil.Encryption(time)) + return "{\"code\":50000,\"msg\":\"校验失败\"}"; + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = "select cookie from wxxd.wx_sale_assistant_user WHERE id=" + id + ";"; + + var rst = mySql.ExecuteDataTableRow(sql); + mySql.Close(); + if (string.IsNullOrEmpty(mySql.Message)) + { + return "{\"code\":200,\"cookie\":" + rst["cookie"] + "}"; + } + if (!string.IsNullOrEmpty(mySql.Message)) + { + return "{\"code\":500,\"msg\":\"" + mySql.Message + "\"}"; + } + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + /// + /// 添加充值二维码 + /// + /// + /// + public string UpdateTopUpQrcode(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + if (!GetSign(inputData)) + return "{\"code\":999,\"msg\":\"校验失败\"}"; + + var qrcode_base64 = (RegexUtils.GetStringQuery(ref inputData, "qrcode_base64")?.Replace("'", "\\'")); + var agent_code = (RegexUtils.GetStringQuery(ref inputData, "agent_code")?.Replace("'", "\\'")).ParseToString(); + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + //string sql = "UPDATE wxxd.user_top_up_qrcode SET qrcode_base64='" + qrcode_base64 + "' WHERE agent_code=" + agent_code + ";"; + string sql = "INSERT INTO wxxd.user_top_up_qrcode (agent_code,qrcode_base64) VALUES('" + agent_code + "','" + qrcode_base64 + "')" + + "ON DUPLICATE KEY UPDATE agent_code=VALUES(agent_code),qrcode_base64=VALUES(qrcode_base64);"; + + var rst = mySql.ExecuteAffectedRows(sql); + mySql.Close(); + + if (!string.IsNullOrEmpty(mySql.Message)) + { + return "{\"code\":500,\"msg\":\"" + mySql.Message + "\"}"; + } + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + + /// + /// 获取充值二维码 + /// + /// + /// + public string GetTopUpQrcode(string inputData) + { + if (!string.IsNullOrEmpty(inputData)) + { + if (!GetSign(inputData)) + return "{\"code\":999,\"msg\":\"校验失败\"}"; + + var agent_code = (RegexUtils.GetStringQuery(ref inputData, "agent_code")?.Replace("'", "\\'")).ParseToString(); + + string conn = "ConnKJD"; + MysqlUtils mySql = new MysqlUtils(conn); + string sql = "SELECT qrcode_base64 from wxxd.user_top_up_qrcode WHERE agent_code = '" + agent_code + "';"; + + var qrcode_base64 = mySql.ExecuteFirst(sql); + mySql.Close(); + + if (string.IsNullOrEmpty(mySql.Message)) + { + return "{\"code\":200, \"qrcode_base64\":\"" + qrcode_base64 + "\"}"; + } + if (!string.IsNullOrEmpty(mySql.Message)) + { + return "{\"code\":500,\"msg\":\"" + mySql.Message + "\"}"; + } + } + return "{\"code\":19999,\"msg\":\"输入为空\"}"; + } + } +} + + + + diff --git a/StoreHub.KJDWebService/Startup.cs b/StoreHub.KJDWebService/Startup.cs index 7883e2d..6ecec08 100644 --- a/StoreHub.KJDWebService/Startup.cs +++ b/StoreHub.KJDWebService/Startup.cs @@ -1,8 +1,5 @@ using MAX.Core.DependencyInjection; using MAX.Core.Infrastructure; -using System; -using System.Collections.Generic; -using System.Text; namespace StoreHub.KJDWebService { @@ -12,12 +9,10 @@ namespace StoreHub.KJDWebService public void Initialize() { - } public void Register(IServiceRegistrar registrar) { - } } } diff --git a/StoreHub.KJDWebService/StoreHub.KJDWebService.csproj b/StoreHub.KJDWebService/StoreHub.KJDWebService.csproj index 850cf91..1183b05 100644 --- a/StoreHub.KJDWebService/StoreHub.KJDWebService.csproj +++ b/StoreHub.KJDWebService/StoreHub.KJDWebService.csproj @@ -1,7 +1,9 @@  enable - enable + disable + 12.0 + CS0618;CS0649;CS0169;CS0414;CS0114 @@ -10,9 +12,13 @@ - - - + + + + + + + - + diff --git a/StoreHub/Program.cs b/StoreHub/Program.cs index 45167a5..ee2c58c 100644 --- a/StoreHub/Program.cs +++ b/StoreHub/Program.cs @@ -15,6 +15,11 @@ public partial class Program builder.Services.AddStoreHubJwt(builder.Configuration); // Add services to the container. + builder.Services.Configure(options => + { + // 兼容迁移的同步控制器:允许同步读写请求/响应 IO(旧 asmx 行为) + options.AllowSynchronousIO = true; + }); builder.Services.AddControllers(); // Learn more about configuring OpenAPI at https://aka.ms/aspnet/openapi builder.Services.AddApiVersioning(options => @@ -37,6 +42,10 @@ public partial class Program var app = builder.Build(); + // 初始化 KJD 迁移的静态提供者(MysqlUtils 连接提供 / 业务配置读取) + StoreHub.KJDWebService.Commons.AdoProvider.SetServiceProvider(app.Services); + StoreHub.KJDWebService.Commons.KJDConfig.SetConfiguration(app.Configuration); + // Configure the HTTP request pipeline. if (app.Environment.IsDevelopment()) { @@ -59,4 +68,7 @@ public partial class Program app.Run(); } -} \ No newline at end of file +} + + + diff --git a/StoreHub/appsettings.json b/StoreHub/appsettings.json index d9215b9..064798a 100644 --- a/StoreHub/appsettings.json +++ b/StoreHub/appsettings.json @@ -1,4 +1,4 @@ -{ +{ "Logging": { "LogLevel": { "Default": "Information", @@ -8,13 +8,35 @@ "ConnectionStrings": { "DefaultConnection": "Server=localhost;Port=3306;Database=erp;Uid=root;Pwd=123456;", "UserConnection": "Server=localhost;Port=3306;Database=wxxd;Uid=root;Pwd=123456;", - "KJDConnection": "Server=localhost;Port=3306;Database=mysql;Uid=root;Pwd=123456;" + "KJDConnection": "Max Pool Size=512;Database='kjd';Data Source='nj-cynosdbmysql-grp-hl51pkfr.sql.tencentcdb.com';Port=27660;User Id='kjd';Password='Temukjd0625';Charset=utf8mb4;", + "KJDBAKConnection": "Max Pool Size=512;Database='kjd';Data Source='nj-cynosdbmysql-grp-9s7x16mt.sql.tencentcdb.com';Port=24049;User Id='kjdbak';Password='Temukjd0126';Charset=utf8mb4;", + "ConnKJD": "Max Pool Size=512;Database='kjd';Data Source='nj-cynosdbmysql-grp-hl51pkfr.sql.tencentcdb.com';Port=27660;User Id='kjd';Password='Temukjd0625';Charset=utf8mb4;", + "ConnKJDBAK": "Max Pool Size=512;Database='kjd';Data Source='nj-cynosdbmysql-grp-9s7x16mt.sql.tencentcdb.com';Port=24049;User Id='kjdbak';Password='Temukjd0126';Charset=utf8mb4;" + }, + "KJDConfig": { + "UpdateVersion": "525", + "UpdateFileDir": "C:\\inetpub\\wwwroot\\kjd_update", + "UpdateNewUrl": "http://weidian.e57.cn/kjd_update/", + "UpdateExe": "http://1.13.195.131:9000/Download/Update.exe", + "UpdateExeChk": "CE4A009B7AA330314F03EEA0C3AB23F9", + "LowVersion": "523", + "LimitVersion": "823", + "GetReturnPackage": "true", + "GetWXRecommendHotProd": "true", + "GetWXRecommendHotProdOncePerDay": "false", + "GetWXRecommendHotProdMinViewUv": "200", + "GetWXRecommendHotProdInterval": "3", + "IsKeepBase64UploadImgFile": "0", + "UpdateWxFindOrderFileDir": "C:\\inetpub\\wwwroot\\find_order_update", + "UpdateWxFindOrderUrl": "http://weidian.e57.cn/find_order_update/", + "WxFindOrderLimitVersion": "172", + "WxFindOrderLowVersion": "99" }, "Jwt": { "Issuer": "StoreHub", "Audience": "StoreHub.Client", "SigningKey": "StoreHub--Smxf8DtV8a5dFdaCVCXtFfWbmMRfw53ectEjr8JvhUjGpPP7fuBdRn", - "ExpiresMinutes": 120, + "ExpiresMinutes": 2880, "ClockSkewMinutes": 5, "ValidateIssuer": true, "ValidateAudience": true,