fix bug
This commit is contained in:
@@ -69,6 +69,30 @@ class ProductController extends SuperController
|
||||
|
||||
}
|
||||
|
||||
public function archiveTable(Request $request)
|
||||
{
|
||||
$data = $request->all();
|
||||
if (isset($data['select']) && is_null($data['select'])) {
|
||||
$data['select'] = [];
|
||||
}
|
||||
|
||||
$query_table = Product::onlyTrashed()->with($this->with);
|
||||
TableEngine::create($query_table, $data)
|
||||
->initSearch($this->search)
|
||||
->select($this->select)
|
||||
->export($query_table);
|
||||
|
||||
return $query_table;
|
||||
}
|
||||
|
||||
public function archive($id)
|
||||
{
|
||||
$product = Product::onlyTrashed()->findOrFail($id);
|
||||
$product->restore();
|
||||
|
||||
return response()->json(true);
|
||||
}
|
||||
|
||||
public function editProducts(Request $request)
|
||||
{
|
||||
if (isset($request->auto_open_at, $request->auto_close_at)) {
|
||||
|
||||
@@ -90,35 +90,24 @@ class Controller extends BaseController
|
||||
$send_sms = true;
|
||||
$user = User::where('mobile', $to)->first() ?: Customer::where('mobile', $to)->first();
|
||||
if ($user) {
|
||||
//
|
||||
// // Telegram
|
||||
// if (isset($credentials['telegram']) && $user->telegram) {
|
||||
// try {
|
||||
// $res = Http::get("https://api.wwwapp.ir/telegran_send.php", [
|
||||
// 'botToken' => $credentials['telegram']['token'],
|
||||
// 'chatId' => $user->telegram,
|
||||
// 'message' => "جناب {$user->name} {$msg}",
|
||||
// ]);
|
||||
// $data = $res->json();
|
||||
// if (isset($data['success']) && $data['success'] === true) {
|
||||
// $platforms[] = "telegram:{$user->telegram}";
|
||||
// $send_sms = false;
|
||||
// }
|
||||
// } catch (\Exception $e) {
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// Bale
|
||||
if (isset($credentials['bale']) && $user->bale) {
|
||||
$baleToken = trim((string) ($credentials['bale']['token'] ?? ''));
|
||||
$baleChatId = trim((string) ($user->bale ?? ''));
|
||||
if ($baleToken !== '' && $baleChatId !== '') {
|
||||
try {
|
||||
Http::withoutVerifying()->get("https://tapi.bale.ai/{$credentials['bale']['token']}/sendMessage", [
|
||||
'chat_id' => $user->bale,
|
||||
'text' => "جناب {$user->name} \n{$msg}",
|
||||
]);
|
||||
$platforms[] = "bale:{$user->bale}";
|
||||
$send_sms = false;
|
||||
} catch (\Exception $e) {
|
||||
return $e->getMessage();
|
||||
$baleResponse = Http::withoutVerifying()->get(
|
||||
"https://tapi.bale.ai/bot{$baleToken}/sendMessage",
|
||||
[
|
||||
'chat_id' => $baleChatId,
|
||||
'text' => "جناب {$user->name} \n{$msg}",
|
||||
]
|
||||
);
|
||||
$balePayload = $baleResponse->json();
|
||||
if ($baleResponse->successful() && ($balePayload['ok'] ?? false) === true) {
|
||||
$platforms[] = "bale:{$baleChatId}";
|
||||
$send_sms = false;
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
report($e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -153,7 +142,9 @@ class Controller extends BaseController
|
||||
'platform' => 'rayegansms',
|
||||
]);
|
||||
|
||||
$platforms[] = "rayegansms:{$to}";
|
||||
$platforms[] = $response->successful()
|
||||
? "rayegansms:{$to}"
|
||||
: "rayegansms_failed:{$to}:{$response->status()}";
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -583,13 +583,17 @@ class SingleOrderController extends Controller
|
||||
User::where('send_sms', 1)->get()->each(function ($admin) use ($message, $data, $transactionType, $companyName) {
|
||||
$this->send($admin->mobile, $message);
|
||||
});
|
||||
$wallet = Wallet::where('owner', $data['customer_id'])->whereNull('fund_id')->first();
|
||||
$wallet = Wallet::where('owner', $data['customer_id'])
|
||||
->whereNull('fund_id')
|
||||
->whereNull('product_id')
|
||||
->first();
|
||||
$balanceLabel = self::metalTypeLabel();
|
||||
// $pricePerGram = $totalPrice / $amount;
|
||||
$goldBalance = $wallet ? ($wallet->gold ?? 0) : 0;
|
||||
$cashBalance = $wallet ? ($wallet->cash ?? 0) : 0;
|
||||
$customerMessage = "$companyName\n$transactionType {$subjectTitle}\nگرم: {$amount}\n" .
|
||||
"مبلغ کل: " . number_format($totalPrice) . "\n\n" .
|
||||
"موجودی {$balanceLabel}: {$wallet->gold}\n" .
|
||||
"مانده ریالی: " . number_format($wallet->cash) . "\n" .
|
||||
"موجودی {$balanceLabel}: {$goldBalance}\n" .
|
||||
"مانده ریالی: " . number_format($cashBalance) . "\n" .
|
||||
$this->Config('app_url');
|
||||
|
||||
|
||||
|
||||
@@ -181,21 +181,27 @@ class RequestsController extends Controller
|
||||
// $this->send($admin->mobile, $messageExam);
|
||||
// });
|
||||
|
||||
$wallet = Wallet::where('owner', $data['customer_id'])->whereNull('fund_id')->first();
|
||||
$wallet = Wallet::where('owner', $data['customer_id'])
|
||||
->whereNull('fund_id')
|
||||
->whereNull('product_id')
|
||||
->first();
|
||||
if($data['method'] == 'cash') {
|
||||
$pricePerGram = $data['total_price'];
|
||||
}elseif ($data['method'] == 'gold') {
|
||||
$pricePerGram = $data['total_price'] / $data['amount'];
|
||||
}
|
||||
|
||||
$goldBalance = $wallet ? ($wallet->gold ?? 0) : 0;
|
||||
$cashBalance = $wallet ? ($wallet->cash ?? 0) : 0;
|
||||
|
||||
if($data['method'] == 'cash') {
|
||||
$customerMessage = "$companyName\nبرداشت ریالی \nمبلغ: {$data['amount']}\n" .
|
||||
"\nموجودی طلایی: {$wallet->gold}\n" .
|
||||
"مانده ریالی: " . number_format($wallet->cash) . "\n" . $this->Config('app_url');
|
||||
"\nموجودی طلایی: {$goldBalance}\n" .
|
||||
"مانده ریالی: " . number_format($cashBalance) . "\n" . $this->Config('app_url');
|
||||
}elseif ($data['method'] == 'gold') {
|
||||
$customerMessage = "$companyName\nبرداشت طلایی \nگرم: {$data['amount']}\nقیمت گرم: " . number_format($pricePerGram) .
|
||||
"\nمبلغ کل: " . number_format($data['total_price']) . "\nموجودی طلایی: {$wallet->gold}\n" .
|
||||
"مانده ریالی: " . number_format($wallet->cash) . "\n" . $this->Config('app_url');
|
||||
"\nمبلغ کل: " . number_format($data['total_price']) . "\nموجودی طلایی: {$goldBalance}\n" .
|
||||
"مانده ریالی: " . number_format($cashBalance) . "\n" . $this->Config('app_url');
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -29,8 +29,10 @@ class LivePriceTickService
|
||||
| (قبل از sync محصولات تا آبشدهٔ «قیمت اپ» تازه باشد)
|
||||
*/
|
||||
$request = Request::create('/api/price/last', 'GET', ['force_refresh' => '1']);
|
||||
$response = app(ReportController::class)->lastPrice($request);
|
||||
$payload = json_decode($response->getContent(), true);
|
||||
$result = app(ReportController::class)->lastPrice($request);
|
||||
$payload = is_array($result)
|
||||
? $result
|
||||
: (json_decode($result->getContent(), true) ?: []);
|
||||
if (! is_array($payload)) {
|
||||
$payload = [];
|
||||
}
|
||||
|
||||
@@ -8,13 +8,16 @@ use Carbon\Carbon;
|
||||
|
||||
class PriceSnapshotService
|
||||
{
|
||||
/** حداقل قیمت معتبر آبشده (ریال) — زیر این در نمودار نمایش داده نمیشود */
|
||||
public const MIN_VALID_CHART_PRICE_RIAL = 30_000_000;
|
||||
|
||||
/** هر تیک کران — ذخیره در prices برای نمودار (هرگز صفر ثبت نمیشود) */
|
||||
public function recordTick(array $payload): void
|
||||
{
|
||||
$priceValue = (int) ($payload['price'] ?? 0);
|
||||
if ($priceValue <= 30_000_000) {
|
||||
if ($priceValue <= self::MIN_VALID_CHART_PRICE_RIAL) {
|
||||
$last = Price::orderByDesc('id')->first();
|
||||
if (! $last || (int) $last->price <= 30_000_000) {
|
||||
if (! $last || (int) $last->price <= self::MIN_VALID_CHART_PRICE_RIAL) {
|
||||
return;
|
||||
}
|
||||
$priceValue = (int) $last->price;
|
||||
@@ -119,11 +122,7 @@ class PriceSnapshotService
|
||||
->orderBy('created_at')
|
||||
->get(['price', 'created_at']);
|
||||
|
||||
$dailyPoints = $daily->map(function (Price $row) {
|
||||
$ts = ($row->created_at ?? now())->timestamp * 1000;
|
||||
|
||||
return ['timestamp' => $ts, 'value' => (int) $row->price];
|
||||
})->values()->all();
|
||||
$dailyPoints = $this->mapValidPriceRows($daily);
|
||||
|
||||
$weekRows = Price::query()
|
||||
->where('created_at', '>=', now()->subDays(7))
|
||||
@@ -153,11 +152,16 @@ class PriceSnapshotService
|
||||
$lastBucket = null;
|
||||
|
||||
foreach ($rows as $row) {
|
||||
$price = (int) $row->price;
|
||||
if ($price <= self::MIN_VALID_CHART_PRICE_RIAL) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$ts = $row->created_at?->timestamp ?? 0;
|
||||
$bucket = (int) floor($ts / $bucketSeconds);
|
||||
$point = [
|
||||
'timestamp' => $ts * 1000,
|
||||
'value' => (int) $row->price,
|
||||
'value' => $price,
|
||||
];
|
||||
|
||||
if ($bucket !== $lastBucket) {
|
||||
@@ -170,4 +174,72 @@ class PriceSnapshotService
|
||||
|
||||
return $points;
|
||||
}
|
||||
|
||||
/** @param \Illuminate\Support\Collection<int, Price> $rows */
|
||||
private function mapValidPriceRows($rows): array
|
||||
{
|
||||
$points = [];
|
||||
|
||||
foreach ($rows as $row) {
|
||||
$price = (int) $row->price;
|
||||
if ($price <= self::MIN_VALID_CHART_PRICE_RIAL) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$points[] = [
|
||||
'timestamp' => ($row->created_at ?? now())->timestamp * 1000,
|
||||
'value' => $price,
|
||||
];
|
||||
}
|
||||
|
||||
return $points;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array{DAILY?: array, WEEKLY?: array, MONTHLY?: array} $prices
|
||||
* @return array{DAILY: array, WEEKLY: array, MONTHLY: array}
|
||||
*/
|
||||
public function sanitizeChartPrices(array $prices): array
|
||||
{
|
||||
$minScaled = intdiv(self::MIN_VALID_CHART_PRICE_RIAL, 1000);
|
||||
|
||||
foreach (['DAILY', 'WEEKLY', 'MONTHLY'] as $period) {
|
||||
if (! isset($prices[$period]) || ! is_array($prices[$period])) {
|
||||
$prices[$period] = [];
|
||||
continue;
|
||||
}
|
||||
|
||||
$lastValid = null;
|
||||
$sanitized = [];
|
||||
|
||||
foreach ($prices[$period] as $point) {
|
||||
$value = (int) ($point['value'] ?? 0);
|
||||
$timestamp = (int) ($point['timestamp'] ?? 0);
|
||||
|
||||
if ($timestamp <= 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$isValid = $value > self::MIN_VALID_CHART_PRICE_RIAL
|
||||
|| ($value > $minScaled && $value <= self::MIN_VALID_CHART_PRICE_RIAL);
|
||||
|
||||
if ($isValid) {
|
||||
$lastValid = $value;
|
||||
} elseif ($lastValid !== null) {
|
||||
$value = $lastValid;
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
|
||||
$sanitized[] = [
|
||||
'timestamp' => $timestamp,
|
||||
'value' => $value,
|
||||
];
|
||||
}
|
||||
|
||||
$prices[$period] = $sanitized;
|
||||
}
|
||||
|
||||
return $prices;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,17 +93,17 @@ class ZaarboxPriceService
|
||||
if ($this->config->getBool('chart_use_local_data', false)) {
|
||||
$local = app(PriceSnapshotService::class)->chartFromDatabase();
|
||||
if (! empty($local['DAILY'])) {
|
||||
return $local;
|
||||
return app(PriceSnapshotService::class)->sanitizeChartPrices($local);
|
||||
}
|
||||
}
|
||||
|
||||
$cached = Cache::get($this->cacheKey());
|
||||
|
||||
if (is_array($cached) && isset($cached['prices'])) {
|
||||
return $cached['prices'];
|
||||
return app(PriceSnapshotService::class)->sanitizeChartPrices($cached['prices']);
|
||||
}
|
||||
|
||||
return $this->refreshCache();
|
||||
return app(PriceSnapshotService::class)->sanitizeChartPrices($this->refreshCache());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -566,7 +566,9 @@ class ZaarboxPriceService
|
||||
|
||||
for ($bucket = $firstBucket; $bucket <= $endMs; $bucket += $intervalMs) {
|
||||
while ($index < $count && $points[$index]['timestamp'] <= $bucket) {
|
||||
$lastPoint = $points[$index];
|
||||
if ($points[$index]['price'] > PriceSnapshotService::MIN_VALID_CHART_PRICE_RIAL) {
|
||||
$lastPoint = $points[$index];
|
||||
}
|
||||
$index++;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user