diff --git a/AllBase/AllBase.csproj b/AllBase/AllBase.csproj index ed308f3..95c28a4 100644 --- a/AllBase/AllBase.csproj +++ b/AllBase/AllBase.csproj @@ -195,6 +195,7 @@ + diff --git a/AllBase/BaseClass.cs b/AllBase/BaseClass.cs index 000cd52..6242c5c 100644 --- a/AllBase/BaseClass.cs +++ b/AllBase/BaseClass.cs @@ -27,7 +27,7 @@ namespace AllBase /// /// 版本ID /// - public static int VersionCount = 873; + public static int VersionCount = 875; //public static int VersionCount = 613; /// diff --git a/AllBase/Model/Param/WXParam/WXCateAuthParam.cs b/AllBase/Model/Param/WXParam/WXCateAuthParam.cs new file mode 100644 index 0000000..1bd8cf4 --- /dev/null +++ b/AllBase/Model/Param/WXParam/WXCateAuthParam.cs @@ -0,0 +1,51 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AllBase.Model.Param.WXParam +{ + public class WXCateAuthParam + { + public categoryAuthInfoParam categoryInfo { get; set; } = new categoryAuthInfoParam(); + public List brandIdList { get; set; } = new List(); + public long? leafCategoryId { get; set; } // 7483 + public int? reuse { get; set; } = 0; + public string applyType { get; set; } = "normalApply"; + } + public class categoryAuthInfoParam + { + public List categories { get; set; } = new List(); + public string categoryDeposit { get; set; } // "1000.00"; + public bool? isNewApplyCat { get; set; } = true; + public List licenseGroupList { get; set; } = new List(); + public int? ruleVersion { get; set; } + public List certificate { get; set; } = new List(); + } + + public class licenseGroup + { + public string licenseGroupId { get; set; } = "1"; + public licenseParam license { get; set; } = new licenseParam(); + } + + public class licenseParam + { + public string licenseId { get; set; } = "4"; + public List cosIdList { get; set; } = new List(); + public List licenseFieldList { get; set; } = new List(); + public bool? isReuse { get; set; } = true; + } + + public class KeyValueParam + { + public string key { get; set; } // "audit_license_registration_no" // "search_url" + public string value { get; set; } // "YB23509020049441" // "" + } + + public class WXCateId + { + public long? id { get; set; } // 10000215 + } +} diff --git a/TEMUKJD/WXForms/ProductForms/WXDBProdUploadForm.cs b/TEMUKJD/WXForms/ProductForms/WXDBProdUploadForm.cs index c6dd2ba..3ac7b06 100644 --- a/TEMUKJD/WXForms/ProductForms/WXDBProdUploadForm.cs +++ b/TEMUKJD/WXForms/ProductForms/WXDBProdUploadForm.cs @@ -1951,6 +1951,8 @@ namespace TemuKJD.WXForms.ProductForms // 检测是否有类目上传权限 var cateUpCheckRst = WXUpload.batchCheckCategoryRelation(shop, leafCatId); + //"{\"code\":0,\"list\":[{\"category_id\":\"1427\",\"result\":0,\"no_auth_reason_type\":0}]}" + //"{\"code\":0,\"list\":[{\"category_id\":\"7486\",\"result\":0,\"no_auth_reason_type\":0}]}" if (!cateUpCheckRst.Contains("\"code\":0") && !cateUpCheckRst.Contains("\"success\":true")) { var error = BaseRegex.GetStringJson(ref cateUpCheckRst, "msg"); @@ -1960,14 +1962,82 @@ namespace TemuKJD.WXForms.ProductForms } if (!cateUpCheckRst.Contains("\"result\":1")) { - Thread.Sleep(Randomx.GetId(1000, 2000)); - var cateAuthorRst = WXUpload.addFinderCategoryV2(shop, leafCatId); - if (!cateAuthorRst.Contains("\"code\":0") && !cateAuthorRst.Contains("\"success\":true")) + if (aiCateIdLst.FirstOrDefault() == 10000215) { - var error = BaseRegex.GetStringJson(ref cateAuthorRst, "msg"); - if (string.IsNullOrEmpty(error)) - error = cateAuthorRst; - return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"类目申请错误 " + error + "\"}"; + //@"{""categoryInfo"":{""categories"":[{""id"":10000215},{""id"":10000222},{""id"":7483}],""categoryDeposit"":""1000.00"",""isNewApplyCat"":true,""licenseGroupList"":[{""licenseGroupId"":""1"",""license"":{""licenseId"":""4"",""cosIdList"":[""1771897594802-oM5657FQAaKYlf2uP300NBgx9HYY-0581""],""licenseFieldList"":[{""key"":""audit_license_registration_no"",""value"":""YB23509020049441""},{""key"":""search_url"",""value"":""""}],""isReuse"":true}}],""ruleVersion"":5234,""certificate"":[]},""brandIdList"":[],""leafCategoryId"":7483,""reuse"":0,""applyType"":""normalApply""}"; + var getCatDataRst = WXUpload.getSingleCategoryData(shop, leafCatId, aiCateIdLst); + if (!getCatDataRst.Contains("\"code\":0") && !getCatDataRst.Contains("\"success\":true")) + { + return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"类目申请失败 查询类目资质文件失败" + "\"}"; + } + + WXCateAuthParam wxCateAuthParam = new WXCateAuthParam(); + wxCateAuthParam.leafCategoryId = leafCatId; + wxCateAuthParam.categoryInfo.categoryDeposit = bound.cat_bound.ToString("0.00"); + wxCateAuthParam.categoryInfo.ruleVersion = BaseRegex.GetIntJson(ref getCatDataRst, "ruleVersion"); + foreach (var cateId in aiCateIdLst) + { + wxCateAuthParam.categoryInfo.categories.Add(new WXCateId() { id = cateId }); + } + try + { + if (!JsonHelper.JObjectParse(getCatDataRst)["reuseApplyData"].IsJTokenNullOrEmpty()) + { + var jlicenseGroupList = JsonHelper.JObjectParse(getCatDataRst)["reuseApplyData"]["catInfo"]["licenseGroupList"]; + var licenseGroupListStr = JsonHelper.SerializeObject(jlicenseGroupList); + wxCateAuthParam.categoryInfo.licenseGroupList = JsonHelper.DeserializeJsonToList(licenseGroupListStr); + } + else + { + var licenseGroup = new licenseGroup(); + wxCateAuthParam.categoryInfo.licenseGroupList.Add(licenseGroup); + licenseGroup.license.licenseId = "4"; + var cosIdList = "[" + BaseRegex.GetMatchRegexString(ref getCatDataRst, "\"cosIdList\":\\[([\\s\\S]*?)\\]") + "]"; + licenseGroup.license.cosIdList = JsonHelper.DeserializeJsonToList(cosIdList); + var licenseFieldList = "[" + BaseRegex.GetMatchRegexString(ref getCatDataRst, "\"licenseFieldList\":\\[([\\s\\S]*?)\\]") + "]"; + licenseGroup.license.licenseFieldList = JsonHelper.DeserializeJsonToList(licenseFieldList); + } + var authCateRst = WXUpload.wxCateAuth(shop, aiCateIdLst, wxCateAuthParam); + if (!authCateRst.Contains("\"code\":0") && !authCateRst.Contains("\"success\":true")) + { + var error = BaseRegex.GetStringJson(ref authCateRst, "msg"); + if (string.IsNullOrEmpty(error)) + error = BaseRegex.GetStringJson(ref authCateRst, "errmsg"); + if (string.IsNullOrEmpty(error)) + error = authCateRst; + return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"类目申请失败 " + error + "\"}"; + } + Thread.Sleep(Randomx.GetId(5000, 7000)); + cateUpCheckRst = WXUpload.batchCheckCategoryRelation(shop, leafCatId); + if (!cateUpCheckRst.Contains("\"code\":0") && !cateUpCheckRst.Contains("\"success\":true")) + { + var error = BaseRegex.GetStringJson(ref cateUpCheckRst, "msg"); + if (string.IsNullOrEmpty(error)) + error = cateUpCheckRst; + return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"类目申请校验错误 " + error + "\"}"; + } + if (!cateUpCheckRst.Contains("\"result\":1")) + return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"类目申请审核中 请稍后再试\"}"; + } + catch + { + return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"类目申请失败 复用资质文件失败,请重新提交资质文件" + "\"}"; + } + //return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"类目申请失败 请手动申请资质类目" + "\"}"; + } + else + { + Thread.Sleep(Randomx.GetId(1000, 2000)); + var cateAuthorRst = WXUpload.addFinderCategoryV2(shop, leafCatId); + if (!cateAuthorRst.Contains("\"code\":0") && !cateAuthorRst.Contains("\"success\":true")) + { + var error = BaseRegex.GetStringJson(ref cateAuthorRst, "msg"); + if (string.IsNullOrEmpty(error)) + error = BaseRegex.GetStringJson(ref cateAuthorRst, "errmsg"); + if (string.IsNullOrEmpty(error)) + error = cateAuthorRst; + return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"类目申请错误 " + error + "\"}"; + } } } #endregion @@ -2408,8 +2478,11 @@ namespace TemuKJD.WXForms.ProductForms var productAttr = upProdParam.product.info.category.LastOrDefault().catInfo.productAttr; foreach (var propInfo in prodInfo.property.goods_properties) { + if (propInfo.values.Count == 0) + continue; + var attr = productAttr.attr.FirstOrDefault(r => r.name == propInfo.name); - if (propInfo.name == "生产日期") + if (propInfo.name == "生产日期" && propInfo.values.Count > 0) { propInfo.values.FirstOrDefault().value = DateTime.Now.Date.AddDays(-15).ToString("yyyy-MM-dd"); propInfo.values.FirstOrDefault().raw_value = propInfo.values.FirstOrDefault().value; @@ -2466,7 +2539,11 @@ namespace TemuKJD.WXForms.ProductForms attr = productAttr.attr.FirstOrDefault(r => r.name == "生产日期"); } else if (propInfo.name == "产品重量") + { attr = productAttr.attr.FirstOrDefault(r => r.name == "单件净含量"); + if (attr == null) + attr = productAttr.attr.FirstOrDefault(r => r.name == "净含量"); + } else if (propInfo.name == "包装方式") attr = productAttr.attr.FirstOrDefault(r => r.name == "包装方式"); //else if (propInfo.name == "配料表") @@ -2484,19 +2561,22 @@ namespace TemuKJD.WXForms.ProductForms continue; } var attrValueLst = attr.value.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries).ToList(); - var attrValue = attrValueLst.FirstOrDefault(v => v == propInfo.values.FirstOrDefault().value); + var attrValue = attrValueLst.FirstOrDefault(v => v == propInfo.values.FirstOrDefault()?.value); if (propInfo.name == "保质期" ) { attrValue = "30 天"; - if (propInfo.values.FirstOrDefault().value.Contains("年") || propInfo.values.FirstOrDefault().value.Contains("月") - || propInfo.values.FirstOrDefault().value.Contains("日") || propInfo.values.FirstOrDefault().value.Contains("天") - || propInfo.values.FirstOrDefault().value.Contains("见包装")) + if (propInfo.values.Count > 0) { - attrValue = propInfo.values.FirstOrDefault().value; - } - if (attrValue.Contains("天") && attrValue.Replace("天", "").ParseToInt() < 30) - { - return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"食品保质期小于30天,跳过上传\"}"; + if (propInfo.values.FirstOrDefault().value.Contains("年") || propInfo.values.FirstOrDefault().value.Contains("月") + || propInfo.values.FirstOrDefault().value.Contains("日") || propInfo.values.FirstOrDefault().value.Contains("天") + || propInfo.values.FirstOrDefault().value.Contains("见包装")) + { + attrValue = propInfo.values.FirstOrDefault().value; + } + if (attrValue.Contains("天") && attrValue.Replace("天", "").ParseToInt() < 30) + { + return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"食品保质期小于30天,跳过上传\"}"; + } } } @@ -2666,7 +2746,7 @@ namespace TemuKJD.WXForms.ProductForms attrValue = "见包装"; if (attr.name == "单件净含量") { - //attrValue = "见包装"; + attrValue = "见包装"; } if (attr.name == "包装方式") attrValue = "袋装"; @@ -4345,6 +4425,34 @@ Content-Type: image/jpeg return result; } + /// + /// 申请资质类目前获取类目信息 + /// + /// + /// + /// + public static string getSingleCategoryData(ShopLoginInfo shop, long catId, List catIdLst) + { + var catIds = "[\"" + string.Join("\",\"", catIdLst) + "\"]"; + string url = "https://store.weixin.qq.com/shop-faas/mmchannelstradecategory/cgi/getSingleCategoryData?token=&lang=zh_CN&categoryId=" + catId; + string referer = "https://store.weixin.qq.com/shop/brandAndCat/category/apply?defaultCategoryIds=" + GetHtml.UrlEncodeUtf8(catIds) + "&source=goods&type=apply"; + var result = WXHttpResponseBLL.WeiXinGetResponse(shop, url, referer); + + return result; + } + + public static string wxCateAuth(ShopLoginInfo shop, List catIdLst, WXCateAuthParam wxCateAuthParam) + { + var catIds = "[\"" + string.Join("\",\"", catIdLst) + "\"]"; + string url = "https://store.weixin.qq.com/shop-faas/mmchannelstradecategory/cgi/addFinderCategoryV2?token=&lang=zh_CN"; + string referer = "https://store.weixin.qq.com/shop/brandAndCat/category/apply?defaultCategoryIds=" + GetHtml.UrlEncodeUtf8(catIds) + "&source=goods&type=apply"; + string data = JsonHelper.SerializeObject(wxCateAuthParam); + var result = WXHttpResponseBLL.WeiXinPostResponse(shop, url, data, referer); + return result; + } + + + public static string genProductShortTitle(ShopLoginInfo shop, WXGetShortTitleParam getShortTitleParam) { string url = "https://store.weixin.qq.com/shop-faas/mmecnodeproductupload/common/cgi/goods/genProductShortTitle?token=&lang=zh_CN";