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);
@@ -226,27 +226,6 @@ class WalletController extends Controller
if (Customer::where("id", $customer->id)->first()->token_sms != $request->otp) {
return response()->json(['message' => 'رمز دوم اشتباه میباشد'], 422);
}
/* try {
$response = Http::withHeaders([
'Authorization' => 'Bearer ' . $this->ConfigService('liman_token')
])->post('https://limangold.ir/kernel/customer/fin', [
'receive_bank_shaba' => $bCart->shaba_number,
'receive_bank_card' => $bCart->cart_number,
'receive_name' => $customer->name,
'receive_account_number' => $bCart->account_number,
'description' => $this->ConfigService('name_fa') . ' | ' . $customer->mobile . ' | ' . $customer->name . ' | ' . $Withdraw->id,
'amount' => '1000'
])->json();
if (isset($response['id'])) {
$Withdraw->note = $response['id'];
$Withdraw->save();
$message = "کاربر $userName با شماره موبایل $userMobile درخواست برداشت مبلغ " . number_format($withdrawAmount) . " ثبت کرد و به لیمان منتقل شد. با تشکر، $companyName";
} else {
$message = "کاربر $userName با شماره موبایل $userMobile درخواست برداشت مبلغ " . number_format($withdrawAmount) . " ریال را دارد. با تشکر، $companyName";
}
} catch (Exception $e) {
$message = "کاربر $userName با شماره موبایل $userMobile درخواست برداشت مبلغ " . number_format($withdrawAmount) . " ریال را دارد. با تشکر، $companyName";
}*/
}
User::where('send_sms', 1)->get()->each(function ($admin) use ($message) {
$this->Send($admin->mobile, $message . ' ' . now()->format('H:i:s'));