2026-01-24 14:03:11 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\Site;
|
|
|
|
|
|
|
|
|
|
use App\Http\Controllers\Admin\PriceController;
|
|
|
|
|
use App\Http\Controllers\Controller;
|
|
|
|
|
use App\Mail\YourMailableClass;
|
|
|
|
|
use App\Models\Cnt;
|
2026-02-09 14:09:19 +03:30
|
|
|
use App\Models\Setting;
|
2026-01-24 14:03:11 +00:00
|
|
|
use App\Models\ConfigStatic;
|
|
|
|
|
use App\Models\Customer;
|
2026-05-25 12:47:04 +03:30
|
|
|
use App\Services\MontzarService;
|
2026-01-24 14:03:11 +00:00
|
|
|
use App\Models\Price;
|
|
|
|
|
use App\Models\PriceCandle;
|
|
|
|
|
use App\Models\PriceTrigger;
|
|
|
|
|
use App\Models\Product;
|
|
|
|
|
use Carbon\Carbon;
|
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
use Illuminate\Support\Facades\Http;
|
|
|
|
|
use Illuminate\Support\Facades\Mail;
|
|
|
|
|
use Morilog\Jalali\Jalalian;
|
2026-05-25 12:47:04 +03:30
|
|
|
use App\Services\ConfigService;
|
2026-01-24 14:03:11 +00:00
|
|
|
|
2026-05-11 17:21:56 +00:00
|
|
|
|
2026-01-24 14:03:11 +00:00
|
|
|
class ReportController extends Controller
|
|
|
|
|
{
|
|
|
|
|
public function candleChart()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
$candle = PriceCandle::select(["start",
|
|
|
|
|
"high",
|
|
|
|
|
"low",
|
|
|
|
|
"end",
|
|
|
|
|
"date_at"])->whereDate('date_at', '<=', date("Y-m-d"))
|
|
|
|
|
->whereDate('date_at', '>', Carbon::now()->subDays(30)->format("Y-m-d"))
|
|
|
|
|
->get()->toArray();
|
|
|
|
|
$a = [];
|
|
|
|
|
foreach ($candle as $c) {
|
|
|
|
|
$create['date'] = $c["date_at"];
|
|
|
|
|
unset($c["date_at"]);
|
|
|
|
|
$create['candle'] = array_values($c);
|
|
|
|
|
$a[] = array_values($create);
|
|
|
|
|
}
|
|
|
|
|
return response()->json($a);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function updatePrise()
|
|
|
|
|
{
|
2026-02-09 14:09:19 +03:30
|
|
|
// $difference = config('fee.single');
|
|
|
|
|
$difference = Setting::where('key', 'fee_single')->first()->value;
|
2026-01-24 14:03:11 +00:00
|
|
|
$lastPrice = Price::latest()->first();
|
|
|
|
|
$PriceTriggers = PriceTrigger::where("is_active", true)->get();
|
|
|
|
|
foreach ($PriceTriggers as $PriceTrigger) {
|
|
|
|
|
$priseGold = $PriceTrigger->dirction == 1
|
|
|
|
|
? $lastPrice->price - $difference
|
|
|
|
|
: ($PriceTrigger->dirction == 2 ? $lastPrice->price + $difference : $lastPrice->price);
|
|
|
|
|
|
|
|
|
|
if (eval('return $priseGold ' . $PriceTrigger->price_condition . ' $PriceTrigger->target_price;')) {
|
|
|
|
|
$customer = Customer::find($PriceTrigger->customer_id);
|
|
|
|
|
$message = "قیمت طلا به " . number_format($priseGold, -1) . " در هر گرم رسید\n" .$this->Config('name_fa');
|
|
|
|
|
if ($PriceTrigger->action == 'email') {
|
|
|
|
|
Mail::to("$customer->email")->send(new YourMailableClass($message, '', '', '', ''));
|
|
|
|
|
} elseif ($PriceTrigger->action == 'sms') {
|
|
|
|
|
$this->send($customer->mobile, $message);
|
|
|
|
|
}
|
|
|
|
|
$PriceTrigger->is_active = false;
|
|
|
|
|
$PriceTrigger->triggered_at = Carbon::now();
|
|
|
|
|
$PriceTrigger->save();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return response()->json();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function upDownPrice()
|
|
|
|
|
{
|
2026-02-09 14:09:19 +03:30
|
|
|
$difference = Setting::where('key', 'fee_single')->first()->value;
|
2026-01-24 14:03:11 +00:00
|
|
|
$today = Carbon::now()->format("Y-m-d");
|
|
|
|
|
$prises = Price::where('date_at', $today)->get("price");
|
|
|
|
|
|
|
|
|
|
$minP = 0; // Initialize to the highest possible value
|
|
|
|
|
$maxP = 0; // Initialize to the lowest possible value
|
|
|
|
|
|
|
|
|
|
foreach ($prises as $p) {
|
|
|
|
|
// Initialize $minP to the first price if it's null
|
|
|
|
|
if ($minP == 0 || $p->price < $minP) {
|
|
|
|
|
$minP = $p->price;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Initialize $maxP to the first price if it's null
|
|
|
|
|
if ($maxP == 0 || $p->price > $maxP) {
|
|
|
|
|
$maxP = $p->price;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (count($prises) === 0) {
|
2026-05-11 17:21:56 +00:00
|
|
|
$price = Price::orderBy('id', 'desc')->first();
|
|
|
|
|
$priceValue = $price->price;
|
2026-01-24 14:03:11 +00:00
|
|
|
|
2026-05-11 17:21:56 +00:00
|
|
|
return ['sell' => $priceValue - $difference, 'buy' => $priceValue + $difference];
|
2026-01-24 14:03:11 +00:00
|
|
|
} else {
|
|
|
|
|
|
|
|
|
|
// Assuming $minP and $maxP are defined elsewhere in your code
|
|
|
|
|
return ['sell' => $minP - $difference, 'buy' => $maxP + $difference];
|
|
|
|
|
}
|
|
|
|
|
// return $prises;
|
|
|
|
|
// $add_sell_price = config('add_sell_price.major');
|
|
|
|
|
// $price = PriceCandle::whereDate('date_at',)->first();
|
|
|
|
|
// $price_price = Price::orderBy('id','desc')->first();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function lastPrice()
|
|
|
|
|
{
|
2026-05-25 12:47:04 +03:30
|
|
|
$config = app(ConfigService::class);
|
|
|
|
|
|
2026-05-02 18:47:02 +00:00
|
|
|
$closed = false;
|
|
|
|
|
|
2026-05-25 12:47:04 +03:30
|
|
|
$montzar_price = 0;
|
2026-05-24 16:55:07 +03:30
|
|
|
$tgn = 0;
|
|
|
|
|
$pr_price = 0;
|
|
|
|
|
|
|
|
|
|
$open_buy = true;
|
|
|
|
|
$open_sell = true;
|
|
|
|
|
|
2026-05-25 12:47:04 +03:30
|
|
|
$montzar_open_buy = false;
|
|
|
|
|
$montzar_open_sell = false;
|
2026-05-24 16:55:07 +03:30
|
|
|
|
|
|
|
|
$priceSource = null;
|
2026-05-24 22:29:43 +03:30
|
|
|
$priceValue = 0;
|
2026-05-24 16:55:07 +03:30
|
|
|
|
|
|
|
|
$toBool = function ($value) {
|
|
|
|
|
return filter_var($value, FILTER_VALIDATE_BOOLEAN);
|
|
|
|
|
};
|
|
|
|
|
|
2026-05-25 12:47:04 +03:30
|
|
|
$zeroResponse = function () {
|
|
|
|
|
return [
|
|
|
|
|
'sell' => 0,
|
|
|
|
|
'buy' => 0,
|
|
|
|
|
'price_last' => 0,
|
|
|
|
|
'price' => 0,
|
|
|
|
|
'main_product' => 0,
|
|
|
|
|
'taban_gohar' => 0,
|
|
|
|
|
'montzar' => 0,
|
|
|
|
|
'closed' => true,
|
|
|
|
|
'time' => now(),
|
|
|
|
|
];
|
|
|
|
|
};
|
|
|
|
|
|
2026-05-24 16:55:07 +03:30
|
|
|
/*
|
|
|
|
|
|--------------------------------------------------------------------------
|
2026-05-24 22:29:43 +03:30
|
|
|
| بستن قیمت طبق منطق قبلی
|
2026-05-24 16:55:07 +03:30
|
|
|
|--------------------------------------------------------------------------
|
|
|
|
|
*/
|
2026-05-25 12:47:04 +03:30
|
|
|
if ($toBool($config->Config('close_price'))) {
|
|
|
|
|
$startDay = $config->Config('startDay') ?: '00:00';
|
2026-05-11 17:36:23 +00:00
|
|
|
[$startHour, $startMinute] = explode(':', $startDay);
|
|
|
|
|
|
2026-05-25 12:47:04 +03:30
|
|
|
$endDay = $config->Config('endDay') ?: '23:59';
|
2026-05-11 17:36:23 +00:00
|
|
|
[$endHour, $endMinute] = explode(':', $endDay);
|
|
|
|
|
|
2026-05-11 17:21:56 +00:00
|
|
|
$current = Carbon::now();
|
2026-05-24 22:29:43 +03:30
|
|
|
$start = Carbon::today()->setTime((int) $startHour, (int) $startMinute);
|
|
|
|
|
$end = Carbon::today()->setTime((int) $endHour, (int) $endMinute);
|
2026-05-11 17:21:56 +00:00
|
|
|
|
2026-05-24 16:55:07 +03:30
|
|
|
if (!$current->between($start, $end)) {
|
2026-05-25 12:47:04 +03:30
|
|
|
// عمومی: در Cnt بماند
|
|
|
|
|
Cnt::where('key', 'app_closed')->update(['value' => 'true']);
|
2026-05-24 16:55:07 +03:30
|
|
|
|
2026-05-25 12:47:04 +03:30
|
|
|
// مربوط به منتزر: settings
|
|
|
|
|
$config->UpdateConfig('montzar_closed', 'true');
|
|
|
|
|
|
|
|
|
|
return $zeroResponse();
|
2026-05-02 18:47:02 +00:00
|
|
|
}
|
2026-05-24 22:29:43 +03:30
|
|
|
|
2026-05-25 12:47:04 +03:30
|
|
|
Cnt::where('key', 'app_closed')->update(['value' => 'false']);
|
2026-05-02 18:47:02 +00:00
|
|
|
}
|
2026-05-11 17:36:23 +00:00
|
|
|
|
2026-05-24 16:55:07 +03:30
|
|
|
/*
|
|
|
|
|
|--------------------------------------------------------------------------
|
2026-05-24 22:29:43 +03:30
|
|
|
| Settings
|
2026-05-24 16:55:07 +03:30
|
|
|
|--------------------------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
$settings = Setting::whereIn('key', [
|
|
|
|
|
'fee_single',
|
|
|
|
|
'tabanGohar_price',
|
|
|
|
|
'main_product_price',
|
|
|
|
|
'buy_fee',
|
|
|
|
|
'sell_fee',
|
2026-05-25 12:47:04 +03:30
|
|
|
'show_last_price',
|
2026-05-24 16:55:07 +03:30
|
|
|
])->get();
|
|
|
|
|
|
2026-03-31 18:28:27 +03:30
|
|
|
$settingsMap = $settings->pluck('value', 'key');
|
2026-05-25 12:47:04 +03:30
|
|
|
$show_last_price = $toBool($settingsMap->get('show_last_price', false));
|
2026-03-31 18:28:27 +03:30
|
|
|
$taban_gohar_price = $settingsMap->get('tabanGohar_price');
|
|
|
|
|
$main_product_price = $settingsMap->get('main_product_price');
|
2026-01-24 14:03:11 +00:00
|
|
|
|
2026-05-25 12:47:04 +03:30
|
|
|
$difference = (float) $settingsMap->get('fee_single', 0);
|
2026-05-24 22:29:43 +03:30
|
|
|
$diff_buy = (float) $settingsMap->get('buy_fee', $difference);
|
|
|
|
|
$diff_sell = (float) $settingsMap->get('sell_fee', $difference);
|
2026-05-17 16:27:50 +00:00
|
|
|
|
2026-05-25 12:47:04 +03:30
|
|
|
$montzar_price_enabled = $toBool($config->Config('montzar_price'));
|
2026-05-24 22:29:43 +03:30
|
|
|
|
2026-05-24 16:55:07 +03:30
|
|
|
/*
|
|
|
|
|
|--------------------------------------------------------------------------
|
2026-05-25 12:47:04 +03:30
|
|
|
| Montzar - اولویت اول
|
2026-05-24 16:55:07 +03:30
|
|
|
|--------------------------------------------------------------------------
|
|
|
|
|
*/
|
2026-05-25 12:47:04 +03:30
|
|
|
if ($montzar_price_enabled && !$closed) {
|
2026-05-24 16:55:07 +03:30
|
|
|
try {
|
2026-05-25 12:47:04 +03:30
|
|
|
$montzarBaseUrl = rtrim($config->Config('montzar_base_url') ?: 'https://montpar.ir', '/');
|
|
|
|
|
$montzarProductId = (int) ($config->Config('montzar_product_id') ?: 25);
|
2026-05-24 16:55:07 +03:30
|
|
|
|
2026-05-25 12:47:04 +03:30
|
|
|
$montzar = app(MontzarService::class)->productList();
|
2026-05-24 16:55:07 +03:30
|
|
|
|
2026-05-25 12:47:04 +03:30
|
|
|
if (isset($montzar['message'])) {
|
|
|
|
|
throw new \Exception('Provider message: ' . $montzar['message']);
|
2026-05-24 16:55:07 +03:30
|
|
|
}
|
|
|
|
|
|
2026-05-25 12:47:04 +03:30
|
|
|
$collection = collect($montzar);
|
|
|
|
|
$montzarProduct = $collection->firstWhere('id', $montzarProductId);
|
2026-05-24 16:55:07 +03:30
|
|
|
|
2026-05-25 12:47:04 +03:30
|
|
|
if (!$montzarProduct) {
|
|
|
|
|
throw new \Exception("Provider product not found. product_id={$montzarProductId}");
|
2026-05-24 22:29:43 +03:30
|
|
|
}
|
2026-05-24 16:55:07 +03:30
|
|
|
|
2026-05-25 12:47:04 +03:30
|
|
|
if (!isset($montzarProduct['sub_agent'])) {
|
|
|
|
|
throw new \Exception("Provider product has no sub_agent. product_id={$montzarProductId}");
|
2026-05-24 22:29:43 +03:30
|
|
|
}
|
2026-05-24 16:55:07 +03:30
|
|
|
|
2026-05-25 12:47:04 +03:30
|
|
|
$buy = (float) ($montzarProduct['sub_agent']['rate_buy_gram_price'] ?? 0);
|
|
|
|
|
$sell = (float) ($montzarProduct['sub_agent']['rate_sell_gram_price'] ?? 0);
|
2026-05-24 16:55:07 +03:30
|
|
|
|
2026-05-24 22:29:43 +03:30
|
|
|
if ($buy <= 0 || $sell <= 0) {
|
|
|
|
|
throw new \Exception("Provider invalid gram price. buy={$buy}, sell={$sell}");
|
|
|
|
|
}
|
2026-05-24 16:55:07 +03:30
|
|
|
|
2026-05-24 22:29:43 +03:30
|
|
|
$customPrice = [];
|
|
|
|
|
$customPrice['price'] = ($buy + $sell) / 2;
|
|
|
|
|
$customPrice['diff'] = ($buy - $sell) / 2;
|
2026-05-24 16:55:07 +03:30
|
|
|
|
2026-05-25 12:47:04 +03:30
|
|
|
$config->UpdateConfig('montzar_price', (float) $customPrice['price']);
|
|
|
|
|
$config->UpdateConfig('montzar_diff', (float) $customPrice['diff']);
|
|
|
|
|
$config->UpdateConfig('montzar_mazaneh', ((float) $customPrice['price'] * 4.331802));
|
2026-05-24 16:55:07 +03:30
|
|
|
|
2026-05-25 12:47:04 +03:30
|
|
|
$config->UpdateConfig(
|
|
|
|
|
'montzar_truly_buy_mazaneh',
|
|
|
|
|
$montzarProduct['sub_agent']['rate_buy_price'] ?? 0
|
|
|
|
|
);
|
2026-05-24 16:55:07 +03:30
|
|
|
|
2026-05-25 12:47:04 +03:30
|
|
|
$config->UpdateConfig(
|
|
|
|
|
'montzar_truly_sell_mazaneh',
|
|
|
|
|
$montzarProduct['sub_agent']['rate_sell_price'] ?? 0
|
|
|
|
|
);
|
2026-05-24 16:55:07 +03:30
|
|
|
|
2026-05-25 12:47:04 +03:30
|
|
|
$config->UpdateConfig(
|
|
|
|
|
'montzar_last_product_log',
|
|
|
|
|
json_encode($montzarProduct, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT)
|
|
|
|
|
);
|
2026-05-24 16:55:07 +03:30
|
|
|
|
2026-05-25 12:47:04 +03:30
|
|
|
$montzar_open_sell = $toBool($montzarProduct['open_sell'] ?? false);
|
|
|
|
|
$montzar_open_buy = $toBool($montzarProduct['open_buy'] ?? false);
|
2026-05-24 22:29:43 +03:30
|
|
|
|
2026-05-25 12:47:04 +03:30
|
|
|
$config->UpdateConfig('montzar_open_sell', $montzar_open_sell ? 'true' : 'false');
|
|
|
|
|
$config->UpdateConfig('montzar_open_buy', $montzar_open_buy ? 'true' : 'false');
|
2026-05-24 22:29:43 +03:30
|
|
|
|
2026-05-25 12:47:04 +03:30
|
|
|
if ($montzar_open_sell || $montzar_open_buy) {
|
|
|
|
|
$montzar_price = (int) $customPrice['price'];
|
2026-05-24 16:55:07 +03:30
|
|
|
}
|
|
|
|
|
|
2026-05-25 12:47:04 +03:30
|
|
|
$config->UpdateConfig('montzar_closed', $montzar_price == 0 ? 'true' : 'false');
|
2026-05-24 22:29:43 +03:30
|
|
|
} catch (\Throwable $e) {
|
2026-05-25 12:47:04 +03:30
|
|
|
$montzar_price = 0;
|
2026-05-24 16:55:07 +03:30
|
|
|
|
2026-05-25 12:47:04 +03:30
|
|
|
\Log::error('MONZAR PRICE ERROR', [
|
2026-05-24 22:29:43 +03:30
|
|
|
'message' => $e->getMessage(),
|
2026-05-25 12:47:04 +03:30
|
|
|
'montzar_product_id' => $montzarProductId ?? null,
|
|
|
|
|
'montzar_response' => $montzar ?? null,
|
2026-05-24 22:29:43 +03:30
|
|
|
]);
|
|
|
|
|
|
2026-05-25 12:47:04 +03:30
|
|
|
$config->UpdateConfig('montzar_closed', 'true');
|
2026-05-24 16:55:07 +03:30
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|--------------------------------------------------------------------------
|
|
|
|
|
| Main Product
|
|
|
|
|
|--------------------------------------------------------------------------
|
2026-05-25 12:47:04 +03:30
|
|
|
| عمومی است، پس از Cnt خوانده میشود.
|
|
|
|
|
|--------------------------------------------------------------------------
|
2026-05-24 16:55:07 +03:30
|
|
|
*/
|
2026-05-25 12:47:04 +03:30
|
|
|
if ($toBool($main_product_price) && !$closed) {
|
2026-05-24 16:55:07 +03:30
|
|
|
$main_product_id = Cnt::where('key', 'main_product')->value('value');
|
2026-05-25 12:47:04 +03:30
|
|
|
$pr_product = $main_product_id ? Product::find($main_product_id) : null;
|
2026-05-24 16:55:07 +03:30
|
|
|
|
|
|
|
|
if ($pr_product) {
|
|
|
|
|
$pr_price = (float) $pr_product['price'] + (float) $pr_product['price_profit'];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|--------------------------------------------------------------------------
|
|
|
|
|
| Taban Gohar
|
|
|
|
|
|--------------------------------------------------------------------------
|
|
|
|
|
*/
|
2026-05-25 12:47:04 +03:30
|
|
|
if ($toBool($taban_gohar_price) && !$closed) {
|
2026-05-24 16:55:07 +03:30
|
|
|
try {
|
|
|
|
|
$taban_gohar = Http::withOptions([
|
2026-03-12 10:47:22 +00:00
|
|
|
'curl' => [
|
|
|
|
|
CURLOPT_IPRESOLVE => CURL_IPRESOLVE_V4,
|
|
|
|
|
CURLOPT_TCP_FASTOPEN => 1,
|
2026-05-25 12:47:04 +03:30
|
|
|
],
|
2026-03-12 10:47:22 +00:00
|
|
|
])
|
2026-05-24 16:55:07 +03:30
|
|
|
->withoutVerifying()
|
|
|
|
|
->timeout(2)
|
|
|
|
|
->get('https://tabangohar.com/GheymatKhan/prices_in_table.html')
|
|
|
|
|
->json();
|
2026-03-31 18:28:27 +03:30
|
|
|
|
2026-05-24 16:55:07 +03:30
|
|
|
$tgn = (int) $taban_gohar['c'] * 10;
|
2026-05-24 22:29:43 +03:30
|
|
|
} catch (\Throwable $e) {
|
2026-03-31 18:28:27 +03:30
|
|
|
$tgn = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-24 16:55:07 +03:30
|
|
|
/*
|
|
|
|
|
|--------------------------------------------------------------------------
|
|
|
|
|
| انتخاب قیمت اصلی
|
2026-05-24 22:29:43 +03:30
|
|
|
| اولویت:
|
2026-05-25 12:47:04 +03:30
|
|
|
| Montzar -> Taban Gohar -> Main Product
|
2026-05-24 16:55:07 +03:30
|
|
|
|--------------------------------------------------------------------------
|
|
|
|
|
*/
|
2026-05-25 12:47:04 +03:30
|
|
|
if ($montzar_price_enabled && ($montzar_price ?? 0) !== 0 && !$closed) {
|
|
|
|
|
$priceValue = (int) $montzar_price;
|
|
|
|
|
$priceSource = 'montzar';
|
|
|
|
|
} elseif ($toBool($taban_gohar_price) && ($tgn ?? 0) !== 0 && !$closed) {
|
2026-03-31 18:28:27 +03:30
|
|
|
$priceValue = $tgn;
|
2026-05-24 16:55:07 +03:30
|
|
|
$priceSource = 'taban_gohar';
|
2026-05-25 12:47:04 +03:30
|
|
|
} elseif ($toBool($main_product_price) && ($pr_price ?? 0) !== 0 && !$closed) {
|
2026-03-31 18:28:27 +03:30
|
|
|
$priceValue = $pr_price;
|
2026-05-24 16:55:07 +03:30
|
|
|
$priceSource = 'main_product';
|
|
|
|
|
} else {
|
2026-03-31 18:28:27 +03:30
|
|
|
$priceValue = 0;
|
2026-05-24 22:29:43 +03:30
|
|
|
$priceSource = null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($priceValue <= 0) {
|
2026-05-25 12:47:04 +03:30
|
|
|
if (!$show_last_price) {
|
|
|
|
|
return [
|
|
|
|
|
'sell' => 0,
|
|
|
|
|
'buy' => 0,
|
|
|
|
|
'price_last' => 0,
|
|
|
|
|
'price' => 0,
|
|
|
|
|
'main_product' => $pr_price ?? 0,
|
|
|
|
|
'taban_gohar' => $tgn ?? 0,
|
|
|
|
|
'montzar' => $montzar_price ?? 0,
|
|
|
|
|
'closed' => true,
|
|
|
|
|
'time' => now(),
|
|
|
|
|
];
|
|
|
|
|
}
|
2026-05-24 22:29:43 +03:30
|
|
|
|
2026-05-25 12:47:04 +03:30
|
|
|
$lastPrice = Price::latest()->first();
|
|
|
|
|
|
|
|
|
|
if (!$lastPrice || (float) $lastPrice->price <= 0) {
|
|
|
|
|
return [
|
|
|
|
|
'sell' => 0,
|
|
|
|
|
'buy' => 0,
|
|
|
|
|
'price_last' => 0,
|
|
|
|
|
'price' => 0,
|
|
|
|
|
'main_product' => $pr_price ?? 0,
|
|
|
|
|
'taban_gohar' => $tgn ?? 0,
|
|
|
|
|
'montzar' => $montzar_price ?? 0,
|
|
|
|
|
'closed' => true,
|
|
|
|
|
'time' => now(),
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$priceValue = (float) $lastPrice->price;
|
|
|
|
|
$priceSource = 'database_last';
|
2026-03-10 15:39:30 +03:30
|
|
|
}
|
2026-05-24 16:55:07 +03:30
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|--------------------------------------------------------------------------
|
|
|
|
|
| ذخیره قیمت
|
|
|
|
|
|--------------------------------------------------------------------------
|
|
|
|
|
*/
|
2026-01-24 14:03:11 +00:00
|
|
|
$lastPrice = Price::latest()->first();
|
2026-05-24 16:55:07 +03:30
|
|
|
|
|
|
|
|
if (
|
|
|
|
|
!$closed &&
|
|
|
|
|
(!$lastPrice || (float) $lastPrice->price != (float) $priceValue) &&
|
|
|
|
|
$priceValue > 30000000
|
|
|
|
|
) {
|
2026-01-24 14:03:11 +00:00
|
|
|
$price = new Price();
|
2026-05-24 16:55:07 +03:30
|
|
|
$price->price = $priceValue;
|
2026-01-24 14:03:11 +00:00
|
|
|
$price->time_at = Carbon::now()->toTimeString();
|
|
|
|
|
$price->date_at = Carbon::now()->toDateString();
|
|
|
|
|
$price->save();
|
2026-05-24 16:55:07 +03:30
|
|
|
|
2026-01-24 14:03:11 +00:00
|
|
|
$this->updatePrise();
|
|
|
|
|
|
2026-05-24 16:55:07 +03:30
|
|
|
$candle = PriceCandle::whereDate('date_at', date("Y-m-d"))->first();
|
|
|
|
|
|
|
|
|
|
if (!is_null($candle)) {
|
2026-01-24 14:03:11 +00:00
|
|
|
$candle->end = $priceValue;
|
2026-05-24 16:55:07 +03:30
|
|
|
|
|
|
|
|
if ($priceValue < $candle->low) {
|
|
|
|
|
$candle->low = $priceValue;
|
|
|
|
|
} elseif ($priceValue > $candle->high) {
|
|
|
|
|
$candle->high = $priceValue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$candle->save();
|
|
|
|
|
} else {
|
2026-01-24 14:03:11 +00:00
|
|
|
PriceCandle::create([
|
2026-05-25 12:47:04 +03:30
|
|
|
'start' => $priceValue,
|
|
|
|
|
'end' => $priceValue,
|
|
|
|
|
'high' => $priceValue,
|
|
|
|
|
'low' => $priceValue,
|
|
|
|
|
'date_at' => date('Y-m-d'),
|
2026-01-24 14:03:11 +00:00
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-05-24 16:55:07 +03:30
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|--------------------------------------------------------------------------
|
2026-05-25 12:47:04 +03:30
|
|
|
| محاسبه sell / buy
|
2026-05-24 16:55:07 +03:30
|
|
|
|--------------------------------------------------------------------------
|
|
|
|
|
*/
|
2026-05-25 12:47:04 +03:30
|
|
|
if ($priceSource === 'montzar') {
|
|
|
|
|
$montzar_profit = (float) $config->Config('montzar_diff');
|
2026-05-24 16:55:07 +03:30
|
|
|
|
2026-05-25 12:47:04 +03:30
|
|
|
$final_buy_diff = $diff_buy + $montzar_profit;
|
|
|
|
|
$final_sell_diff = $diff_sell + $montzar_profit;
|
2026-05-24 16:55:07 +03:30
|
|
|
|
2026-05-25 12:47:04 +03:30
|
|
|
$sell = $montzar_open_sell
|
2026-05-24 22:29:43 +03:30
|
|
|
? ceil($priceValue - $final_sell_diff)
|
2026-05-24 16:55:07 +03:30
|
|
|
: 0;
|
|
|
|
|
|
2026-05-25 12:47:04 +03:30
|
|
|
$buy = $montzar_open_buy
|
2026-05-24 22:29:43 +03:30
|
|
|
? ceil($priceValue + $final_buy_diff)
|
2026-05-24 16:55:07 +03:30
|
|
|
: 0;
|
|
|
|
|
|
2026-05-24 22:29:43 +03:30
|
|
|
$priceLast = ceil($priceValue + $final_buy_diff);
|
2026-05-24 16:55:07 +03:30
|
|
|
} else {
|
2026-05-24 22:29:43 +03:30
|
|
|
$sell = $open_sell
|
|
|
|
|
? ceil($priceValue - $difference)
|
2026-05-24 16:55:07 +03:30
|
|
|
: 0;
|
|
|
|
|
|
2026-05-24 22:29:43 +03:30
|
|
|
$buy = $open_buy
|
|
|
|
|
? ceil($priceValue + $difference)
|
2026-05-24 16:55:07 +03:30
|
|
|
: 0;
|
|
|
|
|
|
2026-05-24 22:29:43 +03:30
|
|
|
$priceLast = ceil($priceValue + $difference);
|
2026-05-24 16:55:07 +03:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return [
|
|
|
|
|
'sell' => $sell,
|
|
|
|
|
'buy' => $buy,
|
|
|
|
|
'price_last' => $priceLast,
|
|
|
|
|
'price' => $priceValue,
|
|
|
|
|
'main_product' => $pr_price ?? 0,
|
|
|
|
|
'taban_gohar' => $tgn ?? 0,
|
2026-05-25 12:47:04 +03:30
|
|
|
'montzar' => $montzar_price ?? 0,
|
2026-05-24 22:29:43 +03:30
|
|
|
'closed' => false,
|
2026-05-24 16:55:07 +03:30
|
|
|
'time' => now(),
|
|
|
|
|
];
|
2026-01-24 14:03:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function check()
|
|
|
|
|
{
|
|
|
|
|
$service = Http::
|
|
|
|
|
withHeaders([
|
|
|
|
|
'accept' => 'application/json',
|
|
|
|
|
'Authorization' => 'Bearer ohxsrbjagqvbt0glaygt'
|
|
|
|
|
])->get('https://studio.persianapi.com/index.php/web-service/common/gold-currency-coin?format=json&limit=30&page=1')
|
|
|
|
|
->json();
|
|
|
|
|
$list = [];
|
|
|
|
|
if (isset($service['result'])) {
|
|
|
|
|
foreach ($service['result'] as $item) {
|
|
|
|
|
if ($item['key'] == 137120 || $item['key'] == 137119) {
|
|
|
|
|
$list[] = $item;
|
|
|
|
|
if ($item['key'] == 137120) {
|
|
|
|
|
(new PriceController())->store(new Request(["price" => $item['price']]));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Cnt::where('key', 'price')->update(['value_json' => $list]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function test()
|
|
|
|
|
{
|
|
|
|
|
$a = '{{12, 23, {4, 0, {1}, {1}}}, 0, {1}}';
|
|
|
|
|
$b = str_split($a);
|
|
|
|
|
$c = [];
|
|
|
|
|
$str = "";
|
|
|
|
|
foreach ($b as $item) {
|
|
|
|
|
if ($item != " ") {
|
|
|
|
|
print_r($item);
|
|
|
|
|
print_r('++');
|
|
|
|
|
if ($item == ',' || $item == '}') {
|
|
|
|
|
if (!in_array($c[count($c) - 1], ['{', '}'])) {
|
|
|
|
|
$c[count($c) - 1] += (int)$str;
|
|
|
|
|
print_r((int)$str);
|
|
|
|
|
print_r('^^');
|
|
|
|
|
} else {
|
|
|
|
|
$c[] = $str;
|
|
|
|
|
print_r($c);
|
|
|
|
|
print_r('&&');
|
|
|
|
|
}
|
|
|
|
|
$str = "";
|
|
|
|
|
} elseif (in_array($item, ['{', '}'])) {
|
|
|
|
|
$c[] = $item;
|
|
|
|
|
print_r($c);
|
|
|
|
|
print_r('**');
|
|
|
|
|
} else {
|
|
|
|
|
$str .= $item;
|
|
|
|
|
print_r($str);
|
|
|
|
|
print_r('@@');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
dd($c);
|
|
|
|
|
$d = [];
|
|
|
|
|
$e = [];
|
|
|
|
|
foreach ($c as $item) {
|
|
|
|
|
if ($item == '}') {
|
|
|
|
|
print_r($d[count($d) - 1]);
|
|
|
|
|
print_r('***');
|
|
|
|
|
$e[] = $d[count($d) - 1];
|
|
|
|
|
} else {
|
|
|
|
|
$d[] = $item;
|
|
|
|
|
print_r($d);
|
|
|
|
|
print_r('-----');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
dd($e);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|