added merge wallet 5

This commit is contained in:
2026-06-10 18:38:01 +03:30
parent efd48c12a9
commit 85988bc212
5 changed files with 134 additions and 107 deletions
@@ -151,8 +151,9 @@ class ProductController extends SuperController
public function listProduct()
{
// $this->getPrice();
// $this->auto_close_open();
// قبل از برگرداندن لیست: قیمت محصولات متغیر از فید zaarbox (با کش کوتاه) sync شود
app(\App\Services\ProductPriceSyncService::class)->syncAll(false);
$products = Product::with(['file'])->where('active', 1)->get();
if (Product::hasPriceOffsetColumn() && str_contains(request()->path(), '/customer/')) {
@@ -168,85 +169,7 @@ class ProductController extends SuperController
public function getPrice()
{
// $RPrices =Http::timeout(40)->get('http://212.23.201.173:8381/price_list', [])->json();
$RPrices = Http::timeout(40)->get('http://109.122.246.48:4949/api/free', [])->json();
// try{
// $cooper =Http::timeout(40)->get('https://www.livedata.ir/main/static/p.json', [])->json();
// if(isset($cooper['s_301006']) && isset($cooper['s_200103'])){
// $CP = (($cooper['s_301006']/1000000)*$cooper['s_200103'])*10;
//// Cnt::where('key', 'cu_price')
// }
// }catch (\Exception $e){}
$config = app(ConfigService::class);
$mainProductId = app(ConfigService::class)->mainProductId();
$hasExtremeKeys = Setting::whereIn('key', ['up_price', 'down_price'])->count() === 2;
$products = Product::with([])->whereNotNull('reading_method')->get();
foreach ($products as $product) {
$collection = collect($RPrices);
$RPrice = $collection->firstWhere('key', $product->reading_method);
if (!empty($RPrice)) {
// foreach ($RPrices as $RPrice) {
// if ($product->reading_method == $RPrice['name']) {
if ($RPrice['name'] == 'TGJU فلز مس') {
$copper = $RPrice['price'] + $RPrice['profit'];
}
if ($RPrice['name'] == 'TGJU دلار') {
$dollar = $RPrice['price'] + $RPrice['profit'];
}
if ($RPrice['name'] == 'گلد دات ای از آبشده - رسمی - نقد فردا') {
$RPrice['price'] = $RPrice['price'] / 4.3318;
}
ProductPriceService::syncFromReference(
$product,
(int) $RPrice['price'],
(int) ($RPrice['profit'] ?? 0)
);
$productPrice = (float) ProductPriceService::adjustedTotal(
(int) $RPrice['price'],
(int) ($RPrice['profit'] ?? 0),
ProductPriceService::offsetPercent($product)
);
if (
$hasExtremeKeys
&& $mainProductId
&& (int) $product->id === (int) $mainProductId
) {
$config->trackDailyPriceExtreme($productPrice);
}
if ($product->bubble == 1) {
$ReportController = new ReportController();
$liquidGold = $ReportController->lastPrice();
$p = Product::find($product->id);
$p->amount = $RPrice['price'] / $liquidGold['price'];
$p->save();
}
}
}
if (isset($copper) && isset($dollar)) {
$cp = (int) round(($copper / 1000000) * $dollar);
$copperProducts = Product::where('metal_id', 3)->get();
foreach ($copperProducts as $copperProduct) {
ProductPriceService::syncFromReference($copperProduct, $cp, 0);
}
Product::where('metal_id', 3)->update([
'updated_at' => \Carbon\Carbon::now()->format('Y-m-d H:i:s'),
]);
if (
$hasExtremeKeys
&& $mainProductId
&& Product::where('id', $mainProductId)->where('metal_id', 3)->exists()
) {
$mainCopper = Product::find($mainProductId);
$extremePrice = $mainCopper
? (float) ($mainCopper->price + ($mainCopper->price_profit ?? 0))
: (float) $cp;
$config->trackDailyPriceExtreme($extremePrice);
}
}
app(\App\Services\ProductPriceSyncService::class)->syncAll(true);
return response()->json(true);
}