fix table bug
This commit is contained in:
@@ -16,6 +16,7 @@ use \App\Http\Controllers\Customer\FundController;
|
||||
use App\Http\Controllers\Site\ReportController;
|
||||
use App\Services\ConfigService;
|
||||
use App\Services\ProductPriceService;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
|
||||
class ProductController extends SuperController
|
||||
@@ -46,11 +47,17 @@ class ProductController extends SuperController
|
||||
->initSearch($this->search)
|
||||
->select($this->select)
|
||||
->export($query_table);
|
||||
$query_table['auto_open_at'] = Product::selectRaw(
|
||||
'SEC_TO_TIME(AVG(TIME_TO_SEC(TIME(auto_open_at)))) as avg_time'
|
||||
)->value('avg_time'); $query_table['auto_close_at'] = Product::selectRaw(
|
||||
'SEC_TO_TIME(AVG(TIME_TO_SEC(TIME(auto_close_at)))) as avg_time'
|
||||
)->value('avg_time');
|
||||
|
||||
if (Schema::hasColumn((new Product)->getTable(), 'auto_open_at')) {
|
||||
$query_table['auto_open_at'] = Product::selectRaw(
|
||||
'SEC_TO_TIME(AVG(TIME_TO_SEC(TIME(auto_open_at)))) as avg_time'
|
||||
)->value('avg_time');
|
||||
}
|
||||
if (Schema::hasColumn((new Product)->getTable(), 'auto_close_at')) {
|
||||
$query_table['auto_close_at'] = Product::selectRaw(
|
||||
'SEC_TO_TIME(AVG(TIME_TO_SEC(TIME(auto_close_at)))) as avg_time'
|
||||
)->value('avg_time');
|
||||
}
|
||||
|
||||
// $query_table['11'] = $avgDuration;
|
||||
// $query_table['11'] = Product::avg('auto_open_at');
|
||||
|
||||
@@ -70,15 +70,13 @@ class SingleOrderController extends Controller
|
||||
$data['all_price'] = $latestPrice;
|
||||
$data['price'] = $latestPrice->price;
|
||||
$data['price_id'] = $latestPrice->id;
|
||||
// $data['difference'] = config('fee.cash');
|
||||
$feeCash = Setting::where('key', 'fee_cash')->first();
|
||||
$feeServiceCharge = Setting::where('key', 'fee_service_charge_percentage')->first();
|
||||
if (!$feeCash || !$feeServiceCharge) {
|
||||
throw new UnprocessableEntityHttpException('تنظیمات کارمزد یافت نشد.');
|
||||
}
|
||||
$data['difference'] = $feeCash->value;
|
||||
// $data['service_charge_percentage'] = config('fee.service_charge_percentage');
|
||||
$data['service_charge_percentage'] = $feeServiceCharge->value;
|
||||
$data['difference'] = (float) $feeCash->value;
|
||||
$data['service_charge_percentage'] = (float) $feeServiceCharge->value;
|
||||
|
||||
$fee_free = Setting::where('key', 'fee_free')->where('is_active', true)->value('value');
|
||||
|
||||
@@ -151,12 +149,20 @@ class SingleOrderController extends Controller
|
||||
} else {
|
||||
// Calculate total price and fee for non-product (gold) transaction
|
||||
$data['total_price_original'] = $data['amount'] * ($data['price_original'] ?? 0);
|
||||
$data['total_fee'] = $data['amount'] * $data['difference'];
|
||||
$mainProductId = Cnt::where('key', 'main_product')->value('value');
|
||||
$data['product'] = $mainProductId ? Product::find($mainProductId) : null;
|
||||
$productId = $data['abshode_id'] ?? $data['product_id'] ?? $mainProductId;
|
||||
$data['product'] = $productId ? Product::find($productId) : null;
|
||||
if (!$data['product']) {
|
||||
throw new UnprocessableEntityHttpException('محصول آبشده یافت نشد.');
|
||||
}
|
||||
if ($data['direction'] == 1) {
|
||||
$data['difference'] = $data['product']['cash_fee_buy'];
|
||||
$data['service_charge_percentage'] = $data['product']['percent_fee_buy'];
|
||||
} elseif ($data['direction'] == 2) {
|
||||
$data['difference'] = $data['product']['cash_fee_sell'];
|
||||
$data['service_charge_percentage'] = $data['product']['percent_fee_sell'];
|
||||
}
|
||||
$data['total_fee'] = $data['amount'] * $data['difference'];
|
||||
$data['product_id'] = $data['product']->id;
|
||||
// Check if the user wants to buy
|
||||
if ($data['direction'] == 1) {
|
||||
@@ -172,7 +178,7 @@ class SingleOrderController extends Controller
|
||||
$response['sell'] = $this->processSellTransaction($data, $wallet, $wallet_interface);
|
||||
}
|
||||
}
|
||||
if (Setting::where('key', 'send_to_tahesab')->first()->value == "true") {
|
||||
if ($config->getString('send_to_tahesab', 'false') === 'true') {
|
||||
try {
|
||||
$tahesab = new TahesabController();
|
||||
$data['tahesab'] = $tahesab->storeTrade($data);
|
||||
|
||||
@@ -232,9 +232,11 @@ class ReportController extends Controller
|
||||
| اتحادیه (گلد علی / refPricer) — فقط وقتی price_provider=etehadie
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
$etehadie_order_price = 0;
|
||||
if ($priceProvider === 'etehadie' && !$closed) {
|
||||
$etehadie = app(EtehadiePriceService::class)->fetchMainGramPrice();
|
||||
$etehadie_teh = (int) ($etehadie['price'] ?? 0);
|
||||
$etehadie_order_price = (int) ($etehadie['order_price'] ?? 0);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -422,15 +424,20 @@ class ReportController extends Controller
|
||||
| ذخیره قیمت
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
$priceToStore = $priceValue;
|
||||
if ($priceProvider === 'etehadie' && $etehadie_order_price > 0) {
|
||||
$priceToStore = $etehadie_order_price;
|
||||
}
|
||||
|
||||
$lastPrice = Price::latest()->first();
|
||||
|
||||
if (
|
||||
!$closed &&
|
||||
(!$lastPrice || (float) $lastPrice->price != (float) $priceValue) &&
|
||||
$priceValue > 30000000
|
||||
(!$lastPrice || (float) $lastPrice->price != (float) $priceToStore) &&
|
||||
$priceToStore > 30000000
|
||||
) {
|
||||
$price = new Price();
|
||||
$price->price = $priceValue;
|
||||
$price->price = $priceToStore;
|
||||
$price->time_at = Carbon::now()->toTimeString();
|
||||
$price->date_at = Carbon::now()->toDateString();
|
||||
$price->save();
|
||||
@@ -440,24 +447,26 @@ class ReportController extends Controller
|
||||
$candle = PriceCandle::whereDate('date_at', date("Y-m-d"))->first();
|
||||
|
||||
if (!is_null($candle)) {
|
||||
$candle->end = $priceValue;
|
||||
$candle->end = $priceToStore;
|
||||
|
||||
if ($priceValue < $candle->low) {
|
||||
$candle->low = $priceValue;
|
||||
} elseif ($priceValue > $candle->high) {
|
||||
$candle->high = $priceValue;
|
||||
if ($priceToStore < $candle->low) {
|
||||
$candle->low = $priceToStore;
|
||||
} elseif ($priceToStore > $candle->high) {
|
||||
$candle->high = $priceToStore;
|
||||
}
|
||||
|
||||
$candle->save();
|
||||
} else {
|
||||
PriceCandle::create([
|
||||
'start' => $priceValue,
|
||||
'end' => $priceValue,
|
||||
'high' => $priceValue,
|
||||
'low' => $priceValue,
|
||||
'start' => $priceToStore,
|
||||
'end' => $priceToStore,
|
||||
'high' => $priceToStore,
|
||||
'low' => $priceToStore,
|
||||
'date_at' => date('Y-m-d'),
|
||||
]);
|
||||
}
|
||||
|
||||
$lastPrice = $price;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -492,6 +501,21 @@ class ReportController extends Controller
|
||||
$priceLast = ceil($priceValue + $difference);
|
||||
}
|
||||
|
||||
/*
|
||||
| گلد علی (etehadie): سفارش از Price::latest() میخواند؛
|
||||
| buy/sell/price_last هم از همان ردیف (مثل goldAliii قبل از مرج).
|
||||
| etehadie_teh فقط در فیلد price / etehadie_teh میماند.
|
||||
*/
|
||||
if ($priceProvider === 'etehadie' && !$closed) {
|
||||
$storedPrice = $lastPrice ?? Price::latest()->first();
|
||||
if ($storedPrice && (float) $storedPrice->price > 0) {
|
||||
$base = (float) $storedPrice->price;
|
||||
$sell = $open_sell ? (int) ceil($base - $difference) : 0;
|
||||
$buy = $open_buy ? (int) ceil($base + $difference) : 0;
|
||||
$priceLast = (int) ceil($base + $difference);
|
||||
}
|
||||
}
|
||||
|
||||
if (!$closed && $priceValue > 0) {
|
||||
$config->trackDailyPriceExtreme((float) $priceValue);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user