From 667e3736fb21525e4e8d23d39e1be7b839958722 Mon Sep 17 00:00:00 2001 From: adonis Date: Sat, 25 Jul 2026 16:47:30 +0330 Subject: [PATCH] fix pargar mande --- .../Controllers/Admin/DashboardController.php | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/app/Http/Controllers/Admin/DashboardController.php b/app/Http/Controllers/Admin/DashboardController.php index 360c28f..bb78c10 100644 --- a/app/Http/Controllers/Admin/DashboardController.php +++ b/app/Http/Controllers/Admin/DashboardController.php @@ -17,10 +17,14 @@ use Carbon\Carbon; use Hekmatinasser\Verta\Verta; use Illuminate\Http\Request; use Illuminate\Support\Facades\DB; +use Rooyesh\Wallet\models\Transaction; use Rooyesh\Wallet\models\Wallet; class DashboardController extends Controller { + /** نوع تراکنش‌های کیف که «هدیه» شمرده می‌شوند: ۸ پاداش معرفی/ثبت‌نام، ۹ سود زیرمجموعه */ + private const GIFT_TRANSACTION_TYPES = [8, 9]; + public function dashboardMaster(Request $request) { $tallaPrice = Price::latest()->first(); @@ -344,7 +348,6 @@ class DashboardController extends Controller $ords = Order::with(['product' => function ($q) use ($productSelect) { $q->withTrashed()->select($productSelect); }])->whereBetween('created_at', [$startDate, $endDate])->get(); - $TransactionsAdmin = TransactionsAdmin::whereBetween('created_at', [$startDate, $endDate])->get(); // Initialize response data $response = [ @@ -365,11 +368,12 @@ class DashboardController extends Controller "daily" => [], ]; - // Calculate total gold gifts from transactions - $giftsGold = 0.0; - foreach ($TransactionsAdmin as $TransactionAdmin) { - $giftsGold += (float) $TransactionAdmin->gold; - } + // هدیه = فقط پاداش معرفی/ثبت‌نام و سود زیرمجموعه. + // معاملهٔ مشتری و شارژ دستی طلا توسط ادمین هدیه نیستند. + $giftsGold = (float) Transaction::query() + ->whereIn('type', self::GIFT_TRANSACTION_TYPES) + ->whereBetween('created_at', [$startDate, $endDate]) + ->sum('gold'); $response['Gifts'] = number_format($giftsGold, 3); $lastGoldPrice = (float) (Price::latest()->first()?->price ?? 0);