sunshibo 1 неделя назад
Родитель
Сommit
fe8a91652a
1 измененных файлов с 60 добавлено и 37 удалено
  1. 60 37
      HBuilderProjects/secondShareGoods.html

+ 60 - 37
HBuilderProjects/secondShareGoods.html

@@ -1325,6 +1325,10 @@
 			if (custom) {
 				return custom.replace(/\/+$/, '');
 			}
+			var host = (location.hostname || '').toLowerCase();
+			if (host === 'test.ailien.shop' || host === 'uat.ailien.shop') {
+				return 'https://test.ailien.shop/alienSecond';
+			}
 			return 'http://120.26.186.130:8000/alienSecond';
 		}
 		var API_BASE_SECOND = resolveSecondApiBase();
@@ -1397,14 +1401,47 @@
 			if (Array.isArray(d)) {
 				return d.length && typeof d[0] === 'object' ? d[0] : null;
 			}
-			return typeof d === 'object' ? d : null;
+			if (typeof d !== 'object') return null;
+			var inner =
+				d.secondGoodsDetail ||
+				d.goodsDetail ||
+				d.goodsInfo ||
+				d.detail ||
+				d.record;
+			if (inner && typeof inner === 'object' && !Array.isArray(inner)) {
+				return inner;
+			}
+			return d;
 		}
 
-		function pickGoodsStatusFromDetail(d) {
-			if (!d || typeof d !== 'object') return null;
-			if (d.goodsStatus != null) return d.goodsStatus;
-			if (d.status != null) return d.status;
-			return null;
+		/** 详情里是否有可识别的商品实体(有则视为存在,不依赖 goodsStatus 数值) */
+		function hasSecondGoodsDetailPayload(d) {
+			if (!d || typeof d !== 'object') return false;
+			var id = d.goodsId != null ? d.goodsId : d.id;
+			if (id != null && String(id).trim() !== '' && String(id).trim() !== '0') {
+				return true;
+			}
+			var name = d.goodsName || d.title || d.secondGoodsTitle || d.name;
+			if (name != null && String(name).trim() !== '') return true;
+			var img =
+				d.coverUrl ||
+				d.mainImage ||
+				d.goodsImage ||
+				d.firstImage ||
+				(Array.isArray(d.goodsImageList) && d.goodsImageList[0]);
+			if (img != null && String(img).trim() !== '') return true;
+			return Object.keys(d).length > 0;
+		}
+
+		function isDetailDataExplicitlyDeleted(d) {
+			if (!d || typeof d !== 'object') return false;
+			if (d.deleteFlag === 1 || d.deleteFlag === '1' || Number(d.deleteFlag) === 1) {
+				return true;
+			}
+			if (d.deleted === true || d.isDelete === 1 || d.isDelete === '1') {
+				return true;
+			}
+			return false;
 		}
 
 		function isMsgIndicateGoodsGone(msg) {
@@ -1764,15 +1801,6 @@
 			});
 		}
 
-		/** 2=已卖出 3/4/5=下架或删除等不可用态 */
-		function isGoodsStatusUnavailable(gs) {
-			if (gs == null) return false;
-			var n = Number(gs);
-			if (!isNaN(n) && (n === 2 || n === 3 || n === 4 || n === 5)) return true;
-			var s = String(gs).trim();
-			return s === '2' || s === '3' || s === '4' || s === '5';
-		}
-
 		function buildShareUndefinedRedirectQuery(gs, ctx) {
 			ctx = ctx || {};
 			var uq = new URLSearchParams();
@@ -1799,18 +1827,14 @@
 		}
 
 		/**
-		 * 仅当明确「无商品 / 已下架删除」时返回 true
-		 * 有 data 时只看 goodsStatus;不因 msg 含「删除」等字样误判(避免成功提示误跳转)
+		 * 存在性接口只判断「有没有商品数据」,不用 goodsStatus(在售也可能是 2)
+		 * 仅 deleteFlag/明确删除文案/无 data 且接口失败 时视为不可用
 		 */
 		function isDetailResponseGoodsUnavailable(res) {
 			if (!res || typeof res !== 'object') return true;
 			var d = pickSecondGoodsDetailData(res);
-			var gs = pickGoodsStatusFromDetail(d);
-			if (d && gs != null && isGoodsStatusUnavailable(gs)) {
-				return true;
-			}
-			if (d && typeof d === 'object' && Object.keys(d).length > 0) {
-				return false;
+			if (hasSecondGoodsDetailPayload(d)) {
+				return isDetailDataExplicitlyDeleted(d);
 			}
 			var msg = res.msg != null ? String(res.msg) : '';
 			if (isMsgIndicateGoodsGone(msg)) {
@@ -1873,22 +1897,17 @@
 				.then(function (res) {
 					redirectCtx = redirectCtx || {};
 					var d = pickSecondGoodsDetailData(res);
-					var gs = pickGoodsStatusFromDetail(d);
 					if (isDetailResponseGoodsUnavailable(res)) {
-						redirectToShareUndefined(gs, redirectCtx);
+						console.warn(
+							'[querySecondGoodsDetailWithOutJWT] unavailable',
+							res && res.code,
+							res && res.msg,
+							d
+						);
+						redirectToShareUndefined(null, redirectCtx);
 						return { redirected: true, exists: false };
 					}
-					if (d && Object.keys(d).length > 0) {
-						return { redirected: false, exists: true };
-					}
-					if (isSecondGoodsExistOk(res)) {
-						return { redirected: false, exists: true };
-					}
-					if (res && res.msg) {
-						console.warn('[querySecondGoodsDetailWithOutJWT]', res.msg);
-					}
-					redirectToShareUndefined(gs, redirectCtx);
-					return { redirected: true, exists: false };
+					return { redirected: false, exists: true };
 				});
 		}
 
@@ -1934,7 +1953,11 @@
 
 			bindCommentThreadDelegation();
 
-			if (String(q('goodsUnavailable') || '').trim() === '1') {
+			/* 分享卡片应带 goodsId;勿因 URL 残留 goodsUnavailable=1 跳过存在性校验直接进不可用页 */
+			if (
+				!goodsId &&
+				String(q('goodsUnavailable') || '').trim() === '1'
+			) {
 				redirectToShareUndefined(q('goodsStatus'), redirectCtx);
 				return;
 			}