fix bug
This commit is contained in:
@@ -7,6 +7,7 @@ use App\Http\Controllers\Controller;
|
||||
use App\Http\Controllers\SuperController;
|
||||
use App\Models\Fund;
|
||||
use App\Models\Product;
|
||||
use App\Services\AssetSummaryService;
|
||||
use Illuminate\Http\Request;
|
||||
use Rooyesh\Wallet\interfaces\TransactionInterface;
|
||||
use Rooyesh\Wallet\interfaces\WalletInterface;
|
||||
@@ -26,10 +27,13 @@ class ProductController extends SuperController
|
||||
$query = Product::with($this->with);
|
||||
parent::__construct($model, $this->with, $select, null,$query,$search);
|
||||
}
|
||||
public function pTable(Request $request)
|
||||
public function pTable(Request $request, AssetSummaryService $assetSummaryService)
|
||||
{
|
||||
$user = auth('customer')->user();
|
||||
$mainWalletProductIds = app(\App\Services\ConfigService::class)->mainWalletProductIds();
|
||||
$inventoryByProduct = collect(
|
||||
$assetSummaryService->buildForCustomer((int) $user->id, (int) $user->type)['inventory_cards'] ?? []
|
||||
)->keyBy('product_id');
|
||||
|
||||
$products = Product::where(function ($query) use ($user, $mainWalletProductIds) {
|
||||
$query->whereHas('wallet', function ($q) use ($user) {
|
||||
@@ -70,7 +74,7 @@ class ProductController extends SuperController
|
||||
}
|
||||
|
||||
// Prepare the response
|
||||
$user['rows'] = $products->map(function ($product) use ($user, $representativeId, $mainWalletGold) {
|
||||
$user['rows'] = $products->map(function ($product) use ($user, $representativeId, $mainWalletGold, $inventoryByProduct) {
|
||||
$product->unit = self::productQuantityUnit([
|
||||
'unit' => $product->unit ?? null,
|
||||
'direct_price' => $product->direct_price ?? null,
|
||||
@@ -81,12 +85,26 @@ class ProductController extends SuperController
|
||||
$product->file->setAttribute('full_src', $product->file->src);
|
||||
}
|
||||
|
||||
$card = $inventoryByProduct->get((int) $product->id);
|
||||
$displayQty = $card !== null
|
||||
? (float) ($card['quantity'] ?? 0)
|
||||
: null;
|
||||
|
||||
if ($representativeId !== null && (int) $product->id === $representativeId) {
|
||||
// کیف محصول فقط نقش هندل را دارد؛ موجودی واقعی از کیف اصلی است
|
||||
$walletInterface = new WalletInterface($user->id, $user->type, null, $product->id);
|
||||
$handleWallet = $walletInterface->wallet;
|
||||
$handleWallet->gold = $mainWalletGold;
|
||||
$handleWallet->gold = $displayQty ?? $mainWalletGold;
|
||||
$product->setRelation('wallet', $handleWallet);
|
||||
} elseif ($displayQty !== null) {
|
||||
if ($product->wallet) {
|
||||
$product->wallet->gold = $displayQty;
|
||||
} else {
|
||||
$walletInterface = new WalletInterface($user->id, $user->type, null, $product->id);
|
||||
$handleWallet = $walletInterface->wallet;
|
||||
$handleWallet->gold = $displayQty;
|
||||
$product->setRelation('wallet', $handleWallet);
|
||||
}
|
||||
}
|
||||
|
||||
return $product;
|
||||
|
||||
Reference in New Issue
Block a user