merge goldali with abshode_khanegi branch

This commit is contained in:
2026-06-04 12:18:53 +03:30
parent aea3cbbc6e
commit a9815fa717
28 changed files with 1359 additions and 379 deletions
@@ -5,8 +5,10 @@ namespace App\Http\Controllers\Customer;
use App\DB\Te\TableEngine;
use App\Http\Controllers\Controller;
use App\Jobs\CheckOrder;
use App\Models\Customer;
use App\Models\Order;
use App\Models\Price;
use App\Models\Setting;
use App\Models\User;
use Carbon\Carbon;
use Illuminate\Http\Request;
@@ -111,6 +113,38 @@ class OrderController extends Controller
$this->Send(auth('customer')->user()->mobile,$message);
return response()->json($order);
}
public function profit_gold()
{
$customer = Customer::with(['wallet', 'orders'])
->findOrFail(auth('customer')->id());
$lastPrice = Price::latest('created_at')->value('price') ?? 0;
$goldAmount = $customer->wallet->first()->gold ?? 0;
$orders = $customer->orders;
$averagePrice = $orders->avg('price') ?? 0;
$averageFee = $orders->avg('fee') ?? 0;
$totalProfit = $orders->sum(fn ($order) => $order->direction === 1
? $order->profit_per_moment
: -$order->profit_per_moment);
$feeSingle = (float) (Setting::where('key', 'fee_single')->value('value') ?? config('fee.single', 0));
$currentPriceWithFee = $lastPrice + $feeSingle;
$averagePriceWithFee = $averagePrice + $averageFee;
return response()->json([
'current_portfolio_value' => $currentPriceWithFee * $goldAmount,
'average_portfolio_value' => $averagePriceWithFee * $goldAmount,
'unrealized_profit' => ($currentPriceWithFee - $averagePriceWithFee) * $goldAmount,
'average_price' => $averagePrice,
'average_fee' => $averageFee,
'total_profit' => $totalProfit,
'gold_holdings' => $goldAmount,
'customer' => $customer->makeHidden(['password', 'token_sms']),
]);
}
public function table(Request $request){
$records = Order::where('customer_id',auth('customer')->id())
->where('type',1);