feat(admin): add Montzar partner product list API for settings select

Expose GET /admin/montzar/products using MontzarService::listProductOptions().

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-08-19 14:02:48 +03:30
co-authored by Cursor
parent a321ebdaad
commit 08d51ab1d1
3 changed files with 63 additions and 0 deletions
@@ -6,6 +6,7 @@ use App\DB\Te\TableEngine;
use App\Http\Controllers\Controller;
use App\Models\Price;
use App\Models\PriceCandle;
use App\Services\MontzarService;
use App\Services\ZaarboxPriceService;
use Illuminate\Http\Request;
@@ -71,6 +72,17 @@ class PriceController extends Controller
]);
}
public function montzarProducts(MontzarService $montzarService)
{
return response()->json([
'code' => 0,
'message' => 'عملیات با موفقیت انجام شد.',
'data' => [
'items' => $montzarService->listProductOptions(),
],
]);
}
/** لیست مرجع قیمت برای ادمین قدیمی (ghatreh_admin) — GET /admin/p */
public function methodPrices(ZaarboxPriceService $zaarboxPriceService)
{
+50
View File
@@ -118,6 +118,56 @@ class MontzarService
return $response;
}
/**
* @return array<int, array{id: string, name: string, price: int, buy: int, sell: int}>
*/
public function listProductOptions(): array
{
try {
$response = $this->productList();
} catch (\Throwable $e) {
Log::warning('Montzar product options failed', ['error' => $e->getMessage()]);
return [];
}
if (! is_array($response) || (isset($response['message']) && ! array_is_list($response))) {
return [];
}
return collect($response)
->filter(fn ($row) => is_array($row) && array_key_exists('id', $row))
->map(function (array $row) {
$sub = is_array($row['sub_agent'] ?? null) ? $row['sub_agent'] : [];
$buy = (float) ($sub['rate_buy_gram_price'] ?? 0);
$sell = (float) ($sub['rate_sell_gram_price'] ?? 0);
$price = ($buy > 0 && $sell > 0)
? (int) round(($buy + $sell) / 2)
: (int) round(max($buy, $sell));
$id = (int) ($row['id'] ?? 0);
$name = trim((string) (
$row['name_fa']
?? $row['name']
?? $row['title']
?? $row['product_name']
?? ''
));
return [
'id' => (string) $id,
'name' => $name !== '' ? $name : ('محصول #' . $id),
'price' => $price,
'buy' => (int) round($buy),
'sell' => (int) round($sell),
];
})
->filter(fn (array $row) => $row['id'] !== '' && $row['id'] !== '0')
->sortBy('name', SORT_NATURAL | SORT_FLAG_CASE)
->values()
->all();
}
/**
* مانده طلا/ریال اکانت اپ روی نود همکار (دفتر پنل همکار — نه ته‌حساب اپ).
*
+1
View File
@@ -187,6 +187,7 @@ Route::middleware('auth:user')->group(function (){
Route::get('price-sync-logs/{id}', [PriceSyncLogController::class, 'show']);
Route::post('price-sync/run', [PriceSyncLogController::class, 'runSync']);
Route::get('zaarbox/products', [PriceController::class, 'zaarboxProducts']);
Route::get('montzar/products', [PriceController::class, 'montzarProducts']);
Route::post('finance', [FinanceController::class, 'fall']);