fix up down price
This commit is contained in:
@@ -6,6 +6,7 @@ use App\Http\Controllers\Controller;
|
|||||||
use App\Http\Controllers\SuperController;
|
use App\Http\Controllers\SuperController;
|
||||||
use App\Models\Cnt;
|
use App\Models\Cnt;
|
||||||
use App\Models\Product;
|
use App\Models\Product;
|
||||||
|
use App\Models\Setting;
|
||||||
use App\DB\Te\TableEngine;
|
use App\DB\Te\TableEngine;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
@@ -140,6 +141,8 @@ class ProductController extends SuperController
|
|||||||
// }catch (\Exception $e){}
|
// }catch (\Exception $e){}
|
||||||
|
|
||||||
$config = app(ConfigService::class);
|
$config = app(ConfigService::class);
|
||||||
|
$mainProductId = Cnt::where('key', 'main_product')->value('value');
|
||||||
|
$hasExtremeKeys = Setting::whereIn('key', ['up_price', 'down_price'])->count() === 2;
|
||||||
$products = Product::with([])->whereNotNull('reading_method')->get();
|
$products = Product::with([])->whereNotNull('reading_method')->get();
|
||||||
foreach ($products as $product) {
|
foreach ($products as $product) {
|
||||||
$collection = collect($RPrices);
|
$collection = collect($RPrices);
|
||||||
@@ -160,9 +163,14 @@ class ProductController extends SuperController
|
|||||||
'price' => $RPrice['price'],
|
'price' => $RPrice['price'],
|
||||||
'price_profit' => $RPrice['profit'],
|
'price_profit' => $RPrice['profit'],
|
||||||
]);
|
]);
|
||||||
$config->trackDailyPriceExtreme(
|
$productPrice = (float) $RPrice['price'] + (float) ($RPrice['profit'] ?? 0);
|
||||||
(float) $RPrice['price'] + (float) ($RPrice['profit'] ?? 0)
|
if (
|
||||||
);
|
$hasExtremeKeys
|
||||||
|
&& $mainProductId
|
||||||
|
&& (int) $product->id === (int) $mainProductId
|
||||||
|
) {
|
||||||
|
$config->trackDailyPriceExtreme($productPrice);
|
||||||
|
}
|
||||||
|
|
||||||
if ($product->bubble == 1) {
|
if ($product->bubble == 1) {
|
||||||
$ReportController = new ReportController();
|
$ReportController = new ReportController();
|
||||||
@@ -181,7 +189,13 @@ class ProductController extends SuperController
|
|||||||
'price_profit' => 0,
|
'price_profit' => 0,
|
||||||
'updated_at' => \Carbon\Carbon::now()->format('Y-m-d H:i:s'),
|
'updated_at' => \Carbon\Carbon::now()->format('Y-m-d H:i:s'),
|
||||||
]);
|
]);
|
||||||
$config->trackDailyPriceExtreme((float) $cp);
|
if (
|
||||||
|
$hasExtremeKeys
|
||||||
|
&& $mainProductId
|
||||||
|
&& Product::where('id', $mainProductId)->where('metal_id', 3)->exists()
|
||||||
|
) {
|
||||||
|
$config->trackDailyPriceExtreme((float) $cp);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return response()->json(true);
|
return response()->json(true);
|
||||||
|
|||||||
@@ -85,20 +85,14 @@ class ReportController extends Controller
|
|||||||
$downSetting = Setting::where('key', 'down_price')->first();
|
$downSetting = Setting::where('key', 'down_price')->first();
|
||||||
|
|
||||||
if ($upSetting && $downSetting) {
|
if ($upSetting && $downSetting) {
|
||||||
$today = Carbon::now()->format('Y-m-d');
|
$down = (float) ($downSetting->value ?: 0);
|
||||||
$updatedToday = $upSetting->updated_at
|
$up = (float) ($upSetting->value ?: 0);
|
||||||
&& $upSetting->updated_at->format('Y-m-d') === $today;
|
|
||||||
|
|
||||||
if ($updatedToday) {
|
if ($down > 0 && $up > 0) {
|
||||||
$down = (float) $downSetting->value;
|
return [
|
||||||
$up = (float) $upSetting->value;
|
'sell' => $down - $diffSell,
|
||||||
|
'buy' => $up + $diffBuy,
|
||||||
if ($down > 0 && $up > 0) {
|
];
|
||||||
return [
|
|
||||||
'sell' => $down - $diffSell,
|
|
||||||
'buy' => $up + $diffBuy,
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -34,10 +34,12 @@ class ConfigService
|
|||||||
|
|
||||||
$priceInt = (int) round($price);
|
$priceInt = (int) round($price);
|
||||||
$today = now()->toDateString();
|
$today = now()->toDateString();
|
||||||
|
$extremeDate = $this->Config('price_extreme_date');
|
||||||
|
|
||||||
if (!$upSetting->updated_at || $upSetting->updated_at->toDateString() !== $today) {
|
if ($extremeDate !== $today) {
|
||||||
$this->UpdateConfig('up_price', $priceInt);
|
$this->UpdateConfig('up_price', $priceInt);
|
||||||
$this->UpdateConfig('down_price', $priceInt);
|
$this->UpdateConfig('down_price', $priceInt);
|
||||||
|
$this->UpdateConfig('price_extreme_date', $today);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user