fix: colleague price products use DealProduct, not indexGold
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -54,11 +54,19 @@ export function resolveMeltedPriceSource(product?: {
|
||||
/** قیمت از همکار: قیمت هر عدد، نه هر گرم */
|
||||
export function isColleaguePriceProduct(product?: {
|
||||
colleague_price?: boolean | number | null
|
||||
colleague_price_product_id?: string | number | null
|
||||
} | null) {
|
||||
if (!product) {
|
||||
return false
|
||||
}
|
||||
return product.colleague_price === true || Number(product.colleague_price) === 1
|
||||
const flagged = product.colleague_price === true || Number(product.colleague_price) === 1
|
||||
if (!flagged) {
|
||||
return false
|
||||
}
|
||||
if (product.colleague_price_product_id === undefined) {
|
||||
return true
|
||||
}
|
||||
return Number(product.colleague_price_product_id) > 0
|
||||
}
|
||||
|
||||
/** محصول با پرچم صریح «قیمت اپ» */
|
||||
@@ -79,8 +87,9 @@ export function isMeltedProductUsingAppPrice(product?: {
|
||||
direct_price?: number | null
|
||||
trade_by_quantity?: boolean | number | null
|
||||
price?: number | null
|
||||
colleague_price?: boolean | number | null
|
||||
} | null) {
|
||||
if (!product || resolveMeltedPriceSource(product) !== 'app') {
|
||||
if (!product || isColleaguePriceProduct(product) || resolveMeltedPriceSource(product) !== 'app') {
|
||||
return false
|
||||
}
|
||||
|
||||
|
||||
@@ -24,6 +24,17 @@ function hasReferenceReadingMethod(product: Product): boolean {
|
||||
return Boolean(product.reading_method)
|
||||
}
|
||||
|
||||
/** قیمت منبع همکار؛ اگر خالی بود آبشده همان مظنهٔ صفحه اصلی را میگیرد */
|
||||
function getColleagueSourcedUnitPrice(product: Product, live: number, apiPrice = Number(product.price ?? 0)): number {
|
||||
if (apiPrice > 0) {
|
||||
return apiPrice
|
||||
}
|
||||
if (isMeltedTradeGroup(product.group_type) && live > 0) {
|
||||
return applyPriceOffsetPercent(live, product.price_offset_percent)
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
function hasProductUnitWeight(product?: Product | null) {
|
||||
if (!product || isMeltedTradeGroup(product.group_type)) {
|
||||
return false
|
||||
@@ -85,6 +96,10 @@ export function getProductBaseBuyPrice(product?: Product | null): number {
|
||||
return 0
|
||||
}
|
||||
|
||||
if (isColleaguePriceProduct(product)) {
|
||||
return getColleagueSourcedUnitPrice(product, getTradeBuyPrice(lastPrice.value))
|
||||
}
|
||||
|
||||
if (isMeltedProductUsingAppPrice(product) || isAppPriceProduct(product)) {
|
||||
const apiPrice = Number(product.price ?? 0)
|
||||
const useLast = productUsesLastPriceIfZero(product)
|
||||
@@ -171,6 +186,14 @@ export function getProductBaseSellPrice(product?: Product | null): number {
|
||||
return 0
|
||||
}
|
||||
|
||||
if (isColleaguePriceProduct(product)) {
|
||||
return getColleagueSourcedUnitPrice(
|
||||
product,
|
||||
getTradeSellPrice(lastPrice.value),
|
||||
Number(product.sellPrice ?? product.price ?? 0),
|
||||
)
|
||||
}
|
||||
|
||||
if (isMeltedProductUsingAppPrice(product) || isAppPriceProduct(product)) {
|
||||
const apiPrice = Number(product.price ?? 0)
|
||||
const useLast = productUsesLastPriceIfZero(product)
|
||||
@@ -199,10 +222,6 @@ export function getProductBaseSellPrice(product?: Product | null): number {
|
||||
return Number(product.sellPrice ?? product.price ?? 0)
|
||||
}
|
||||
|
||||
if (isColleaguePriceProduct(product)) {
|
||||
return Number(product.sellPrice ?? product.price ?? 0)
|
||||
}
|
||||
|
||||
const serverSell = Number(product.sellPrice ?? 0)
|
||||
if (serverSell > 0) {
|
||||
return serverSell
|
||||
|
||||
Reference in New Issue
Block a user