fix bug 2
This commit is contained in:
@@ -160,7 +160,13 @@ class ProductController extends SuperController
|
|||||||
$products = Product::with(['file'])->where('active', 1)->get();
|
$products = Product::with(['file'])->where('active', 1)->get();
|
||||||
|
|
||||||
if (str_contains(request()->path(), '/customer/')) {
|
if (str_contains(request()->path(), '/customer/')) {
|
||||||
app(ProductDisplayPriceService::class)->enrichForApi($products);
|
$displayPriceService = app(ProductDisplayPriceService::class);
|
||||||
|
$displayPriceService->enrichForApi($products);
|
||||||
|
$products->each(function (Product $product) use ($displayPriceService) {
|
||||||
|
if (!$displayPriceService->hasCustomerDisplayPrice($product)) {
|
||||||
|
$product->setAttribute('show', false);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Product::hasPriceOffsetColumn() && str_contains(request()->path(), '/customer/')) {
|
if (Product::hasPriceOffsetColumn() && str_contains(request()->path(), '/customer/')) {
|
||||||
|
|||||||
@@ -132,6 +132,8 @@ class CustomerController extends Controller
|
|||||||
$wallet->cash_from_silver = $count_cash_from_silver;
|
$wallet->cash_from_silver = $count_cash_from_silver;
|
||||||
$wallet->cash_from_copper = $count_cash_from_copper;
|
$wallet->cash_from_copper = $count_cash_from_copper;
|
||||||
$wallet->count_cash_total = $count_cash_total;
|
$wallet->count_cash_total = $count_cash_total;
|
||||||
|
// cash در پاسخ = موجودی ریالی کیف اصلی (نه کیف legacy محصولات main_wallet_products)
|
||||||
|
$wallet->cash = $count_cash_pure;
|
||||||
|
|
||||||
// جمع واقعی طلا از کیفها — همتراز wallet/me و کارت محصول (بدون دوبارهشماری customers.gold)
|
// جمع واقعی طلا از کیفها — همتراز wallet/me و کارت محصول (بدون دوبارهشماری customers.gold)
|
||||||
$wallet->gold_sum = round((float) $wallet->count_gold, 2);
|
$wallet->gold_sum = round((float) $wallet->count_gold, 2);
|
||||||
|
|||||||
@@ -40,11 +40,22 @@ class WalletController extends Controller
|
|||||||
|
|
||||||
public function walletMe()
|
public function walletMe()
|
||||||
{
|
{
|
||||||
$wallet = Wallet::select(['owner', 'id', 'gold', 'cash'])->where('owner', auth('customer')->id())
|
$customerId = auth('customer')->id();
|
||||||
|
$wallet = Wallet::select(['owner', 'id', 'gold', 'cash'])
|
||||||
|
->where('owner', $customerId)
|
||||||
|
->whereNull('product_id')
|
||||||
|
->whereNull('fund_id')
|
||||||
->first();
|
->first();
|
||||||
// $wallet['gold_sum'] = Wallet::where('owner', auth('customer')->id())->get();
|
|
||||||
|
|
||||||
$wallet['gold_sum'] = round(Wallet::where('owner', auth('customer')->id())->where('product_id', null)->sum('gold'), 2);
|
if (!$wallet) {
|
||||||
|
$wallet = Wallet::select(['owner', 'id', 'gold', 'cash'])
|
||||||
|
->where('owner', $customerId)
|
||||||
|
->whereNull('fund_id')
|
||||||
|
->first() ?? new Wallet();
|
||||||
|
}
|
||||||
|
|
||||||
|
$wallet['gold_sum'] = round(Wallet::where('owner', $customerId)->where('product_id', null)->sum('gold'), 2);
|
||||||
|
|
||||||
return response()->json($wallet);
|
return response()->json($wallet);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -65,7 +65,20 @@ class ProductDisplayPriceService
|
|||||||
|
|
||||||
private function applyAppPrice(Product $product, int $basePrice): void
|
private function applyAppPrice(Product $product, int $basePrice): void
|
||||||
{
|
{
|
||||||
|
$storedPrice = (int) ($product->price ?? 0);
|
||||||
|
$useLast = Product::hasUseLastPriceIfZeroColumn()
|
||||||
|
&& ($product->use_last_price_if_zero ?? false);
|
||||||
|
|
||||||
if ($basePrice <= 0) {
|
if ($basePrice <= 0) {
|
||||||
|
if ($useLast && $storedPrice > 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$product->setAttribute('price', 0);
|
||||||
|
if (Schema::hasColumn($product->getTable(), 'price_profit')) {
|
||||||
|
$product->setAttribute('price_profit', 0);
|
||||||
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -75,6 +88,15 @@ class ProductDisplayPriceService
|
|||||||
|
|
||||||
$computed = ProductPriceService::adjustedTotal($basePrice, 0, $offset);
|
$computed = ProductPriceService::adjustedTotal($basePrice, 0, $offset);
|
||||||
if ($computed <= 0) {
|
if ($computed <= 0) {
|
||||||
|
if ($useLast && $storedPrice > 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$product->setAttribute('price', 0);
|
||||||
|
if (Schema::hasColumn($product->getTable(), 'price_profit')) {
|
||||||
|
$product->setAttribute('price_profit', 0);
|
||||||
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -232,4 +254,23 @@ class ProductDisplayPriceService
|
|||||||
|
|
||||||
return in_array($group, ['آبشده', 'کاتد مس'], true);
|
return in_array($group, ['آبشده', 'کاتد مس'], true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* آیا بعد از enrich قیمت پایه برای نمایش در اپ کاربر وجود دارد؟
|
||||||
|
* کارمزد (cash_fee) بهتنهایی قیمت محسوب نمیشود.
|
||||||
|
*/
|
||||||
|
public function hasCustomerDisplayPrice(Product $product): bool
|
||||||
|
{
|
||||||
|
if ((int) ($product->price ?? 0) > 0) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Schema::hasColumn($product->getTable(), 'price_profit')) {
|
||||||
|
if ((int) ($product->price_profit ?? 0) > 0) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,6 +39,37 @@ class ProductPriceSyncService
|
|||||||
$synced = true;
|
$synced = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($this->syncAppPriceProducts()) {
|
||||||
|
$synced = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $synced;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** محصولات آبشده با مرجع «قیمت اپ» — ذخیره آخرین قیمت در DB برای fallback */
|
||||||
|
private function syncAppPriceProducts(): bool
|
||||||
|
{
|
||||||
|
$display = app(ProductDisplayPriceService::class);
|
||||||
|
$products = Product::query()
|
||||||
|
->where('active', 1)
|
||||||
|
->get()
|
||||||
|
->filter(static fn (Product $product) => $display->usesAppPrice($product));
|
||||||
|
|
||||||
|
if ($products->isEmpty()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$basePrice = $display->resolveAppBasePrice();
|
||||||
|
if ($basePrice <= 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$synced = false;
|
||||||
|
foreach ($products as $product) {
|
||||||
|
ProductPriceService::syncFromReference($product, $basePrice, 0);
|
||||||
|
$synced = true;
|
||||||
|
}
|
||||||
|
|
||||||
return $synced;
|
return $synced;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user