Download app/Console/Commands/PopulateAnalyticsData.php from veela4/gamtest: direct link, hf CLI and curl.
- Browser
- Download file 2.27 kB
-
https://huggingface.co/veela4/gamtest/resolve/main/app/Console/Commands/PopulateAnalyticsData.php
- Command line
-
hf download hf://veela4/gamtest/app/Console/Commands/PopulateAnalyticsData.php
-
curl -L -o PopulateAnalyticsData.php https://huggingface.co/veela4/gamtest/resolve/main/app/Console/Commands/PopulateAnalyticsData.php
2.27 kB
| namespace App\Console\Commands; | |
| use Illuminate\Console\Command; | |
| use App\Models\Order; | |
| use App\Models\RevenueTracking; | |
| use Carbon\Carbon; | |
| class PopulateAnalyticsData extends Command | |
| { | |
| protected $signature = 'analytics:populate'; | |
| protected $description = 'Populate analytics data from existing orders'; | |
| public function handle() | |
| { | |
| $this->info('Populating analytics data from existing orders...'); | |
| // Get all orders and create revenue tracking entries | |
| $orders = Order::where('status', '!=', 'cancelled')->get(); | |
| foreach ($orders as $order) { | |
| // Parse cart data if it exists | |
| $cartData = json_decode($order->cart_data, true) ?? []; | |
| if (!empty($cartData)) { | |
| foreach ($cartData as $item) { | |
| RevenueTracking::updateOrCreate([ | |
| 'order_id' => $order->id, | |
| 'product_name' => $item['name'] ?? 'Unknown Product' | |
| ], [ | |
| 'amount' => $item['price'] ?? 0, | |
| 'cost' => ($item['price'] ?? 0) * 0.7, // 70% cost, 30% profit | |
| 'profit_margin' => 0.30, | |
| 'quantity' => $item['quantity'] ?? 1, | |
| 'created_at' => $order->created_at, | |
| 'updated_at' => $order->updated_at | |
| ]); | |
| } | |
| } else { | |
| // If no cart data, create a single entry for the order | |
| RevenueTracking::updateOrCreate([ | |
| 'order_id' => $order->id, | |
| 'product_name' => 'Order #' . $order->id | |
| ], [ | |
| 'amount' => $order->total_amount, | |
| 'cost' => $order->total_amount * 0.7, | |
| 'profit_margin' => 0.30, | |
| 'quantity' => 1, | |
| 'created_at' => $order->created_at, | |
| 'updated_at' => $order->updated_at | |
| ]); | |
| } | |
| } | |
| $this->info('Analytics data populated successfully!'); | |
| $this->info('Total revenue tracking entries: ' . RevenueTracking::count()); | |
| } | |
| } |