|
@@ -1379,6 +1379,42 @@
|
|
|
return c === 200 || c === '200' || Number(c) === 200;
|
|
return c === 200 || c === '200' || Number(c) === 200;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /** 二手详情存在性接口:兼容 code 0 / success:true(与 alienSecond 常见返回一致) */
|
|
|
|
|
+ function isSecondGoodsExistOk(res) {
|
|
|
|
|
+ if (!res || typeof res !== 'object') return false;
|
|
|
|
|
+ if (res.success === false) return false;
|
|
|
|
|
+ if (res.success === true) return true;
|
|
|
|
|
+ var c = res.code;
|
|
|
|
|
+ if (c === 200 || c === '200' || Number(c) === 200) return true;
|
|
|
|
|
+ if (c === 0 || c === '0' || Number(c) === 0) return true;
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ function pickSecondGoodsDetailData(res) {
|
|
|
|
|
+ if (!res || typeof res !== 'object') return null;
|
|
|
|
|
+ var d = res.data != null ? res.data : res.result;
|
|
|
|
|
+ if (d == null) return null;
|
|
|
|
|
+ if (Array.isArray(d)) {
|
|
|
|
|
+ return d.length && typeof d[0] === 'object' ? d[0] : null;
|
|
|
|
|
+ }
|
|
|
|
|
+ return typeof d === 'object' ? d : null;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ 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;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ function isMsgIndicateGoodsGone(msg) {
|
|
|
|
|
+ msg = String(msg || '').trim();
|
|
|
|
|
+ if (!msg) return false;
|
|
|
|
|
+ return /已删除|已下架|已卖出|商品不存在|不存在该|查无此商品|找不到该商品|商品不可用/.test(
|
|
|
|
|
+ msg
|
|
|
|
|
+ );
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
function fmtPriceNum(v) {
|
|
function fmtPriceNum(v) {
|
|
|
var n = v != null ? Number(v) : NaN;
|
|
var n = v != null ? Number(v) : NaN;
|
|
|
return !isNaN(n) ? n.toFixed(2) : String(v != null ? v : '');
|
|
return !isNaN(n) ? n.toFixed(2) : String(v != null ? v : '');
|
|
@@ -1762,20 +1798,28 @@
|
|
|
);
|
|
);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 仅当明确「无商品 / 已下架删除」时返回 true。
|
|
|
|
|
+ * 有 data 时只看 goodsStatus;不因 msg 含「删除」等字样误判(避免成功提示误跳转)。
|
|
|
|
|
+ */
|
|
|
function isDetailResponseGoodsUnavailable(res) {
|
|
function isDetailResponseGoodsUnavailable(res) {
|
|
|
if (!res || typeof res !== 'object') return true;
|
|
if (!res || typeof res !== 'object') return true;
|
|
|
- var d = res.data != null ? res.data : res.result;
|
|
|
|
|
- if (d && typeof d === 'object' && d.goodsStatus != null) {
|
|
|
|
|
- return isGoodsStatusUnavailable(d.goodsStatus);
|
|
|
|
|
|
|
+ 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;
|
|
|
}
|
|
}
|
|
|
var msg = res.msg != null ? String(res.msg) : '';
|
|
var msg = res.msg != null ? String(res.msg) : '';
|
|
|
- if (/已删除|已下架|已卖出|不存在|不可用|下架|卖出|删除/.test(msg)) {
|
|
|
|
|
|
|
+ if (isMsgIndicateGoodsGone(msg)) {
|
|
|
return true;
|
|
return true;
|
|
|
}
|
|
}
|
|
|
- if (!isApiOk(res)) {
|
|
|
|
|
- return !d || (typeof d === 'object' && !Object.keys(d).length);
|
|
|
|
|
|
|
+ if (isSecondGoodsExistOk(res)) {
|
|
|
|
|
+ return false;
|
|
|
}
|
|
}
|
|
|
- return !d || (typeof d !== 'object');
|
|
|
|
|
|
|
+ return true;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -1828,22 +1872,22 @@
|
|
|
})
|
|
})
|
|
|
.then(function (res) {
|
|
.then(function (res) {
|
|
|
redirectCtx = redirectCtx || {};
|
|
redirectCtx = redirectCtx || {};
|
|
|
|
|
+ var d = pickSecondGoodsDetailData(res);
|
|
|
|
|
+ var gs = pickGoodsStatusFromDetail(d);
|
|
|
if (isDetailResponseGoodsUnavailable(res)) {
|
|
if (isDetailResponseGoodsUnavailable(res)) {
|
|
|
- var gsPick =
|
|
|
|
|
- res && res.data && res.data.goodsStatus != null
|
|
|
|
|
- ? res.data.goodsStatus
|
|
|
|
|
- : null;
|
|
|
|
|
- redirectToShareUndefined(gsPick, redirectCtx);
|
|
|
|
|
|
|
+ redirectToShareUndefined(gs, redirectCtx);
|
|
|
return { redirected: true, exists: false };
|
|
return { redirected: true, exists: false };
|
|
|
}
|
|
}
|
|
|
- var d = isApiOk(res) ? res.data || res.result : null;
|
|
|
|
|
- if (d && typeof d === 'object') {
|
|
|
|
|
|
|
+ if (d && Object.keys(d).length > 0) {
|
|
|
|
|
+ return { redirected: false, exists: true };
|
|
|
|
|
+ }
|
|
|
|
|
+ if (isSecondGoodsExistOk(res)) {
|
|
|
return { redirected: false, exists: true };
|
|
return { redirected: false, exists: true };
|
|
|
}
|
|
}
|
|
|
if (res && res.msg) {
|
|
if (res && res.msg) {
|
|
|
console.warn('[querySecondGoodsDetailWithOutJWT]', res.msg);
|
|
console.warn('[querySecondGoodsDetailWithOutJWT]', res.msg);
|
|
|
}
|
|
}
|
|
|
- redirectToShareUndefined(null, redirectCtx);
|
|
|
|
|
|
|
+ redirectToShareUndefined(gs, redirectCtx);
|
|
|
return { redirected: true, exists: false };
|
|
return { redirected: true, exists: false };
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|