feat(upsell): apply real cart discounts and track performance

This commit is contained in:
2026-05-08 19:16:01 +03:30
parent 8345e94a1b
commit fd9d29a0ee
19 changed files with 747 additions and 206 deletions

131
admin/views/tools.php Normal file
View File

@@ -0,0 +1,131 @@
<?php
// Prevent direct access
if (!defined('ABSPATH')) {
exit;
}
$current_page = sanitize_text_field($_GET['page'] ?? 'sodino-tools');
$toolsData = $toolsData ?? [];
$tables = $toolsData['tables'] ?? [];
$actions = $toolsData['actions'] ?? [];
$settings = $toolsData['settings'] ?? [];
$db_version = $toolsData['db_version'] ?? '0';
$expected_db_version = $toolsData['expected_db_version'] ?? SODINO_VERSION;
$old_event_count = (int) ($toolsData['old_event_count'] ?? 0);
$oldest_event = $toolsData['oldest_event'] ?? '';
?>
<div id="sodino-app" class="min-h-screen bg-gray-50" dir="rtl">
<div class="bg-white border-b border-gray-200">
<div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
<div class="py-6">
<h1 class="text-3xl font-bold text-gray-900"><?php _e('سودینو', 'sodino'); ?></h1>
<p class="mt-1 text-sm text-gray-500"><?php _e('ابزارهای نگهداری، سلامت و بهینه‌سازی افزونه', 'sodino'); ?></p>
</div>
</div>
</div>
<div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-8">
<?php if (function_exists('sodino_render_admin_notice')) { sodino_render_admin_notice(); } ?>
<div class="flex gap-8">
<?php include SODINO_PLUGIN_DIR . 'admin/components/sidebar.php'; ?>
<main class="flex-1 min-w-0 space-y-6">
<div class="bg-white rounded-lg shadow-sm border border-gray-200 p-6">
<div class="flex flex-col gap-4 lg:flex-row lg:items-center lg:justify-between">
<div>
<h2 class="text-2xl font-semibold text-gray-900"><?php _e('ابزارها و سلامت', 'sodino'); ?></h2>
<p class="mt-2 text-gray-600"><?php _e('وضعیت دیتابیس، کش و داده‌های تحلیلی سودینو را از اینجا مدیریت کنید.', 'sodino'); ?></p>
</div>
<div class="flex flex-wrap gap-3">
<a href="<?php echo esc_url($actions['clear_cache'] ?? '#'); ?>" class="inline-flex items-center justify-center rounded-lg bg-blue-600 px-4 py-2 text-sm font-semibold text-white hover:bg-blue-700">
<?php _e('پاک‌سازی کش', 'sodino'); ?>
</a>
<a href="<?php echo esc_url($actions['run_migrations'] ?? '#'); ?>" class="inline-flex items-center justify-center rounded-lg border border-gray-300 bg-white px-4 py-2 text-sm font-semibold text-gray-700 hover:bg-gray-50">
<?php _e('بررسی دیتابیس', 'sodino'); ?>
</a>
</div>
</div>
</div>
<div class="grid gap-6 lg:grid-cols-3">
<div class="bg-white rounded-lg shadow-sm border border-gray-200 p-6">
<p class="text-sm font-medium text-gray-500"><?php _e('نسخه دیتابیس', 'sodino'); ?></p>
<div class="mt-3 flex items-center justify-between">
<strong class="text-2xl text-gray-900"><?php echo esc_html($db_version); ?></strong>
<?php if (version_compare($db_version, $expected_db_version, '>=')) : ?>
<span class="rounded-full bg-green-50 px-3 py-1 text-xs font-semibold text-green-700"><?php _e('به‌روز', 'sodino'); ?></span>
<?php else : ?>
<span class="rounded-full bg-yellow-50 px-3 py-1 text-xs font-semibold text-yellow-700"><?php _e('نیازمند بررسی', 'sodino'); ?></span>
<?php endif; ?>
</div>
</div>
<div class="bg-white rounded-lg shadow-sm border border-gray-200 p-6">
<p class="text-sm font-medium text-gray-500"><?php _e('رویدادهای تحلیلی', 'sodino'); ?></p>
<strong class="mt-3 block text-2xl text-gray-900"><?php echo esc_html(number_format_i18n($tables['events']['count'] ?? 0)); ?></strong>
<p class="mt-2 text-sm text-gray-500">
<?php echo $oldest_event ? esc_html(sprintf(__('قدیمی‌ترین رویداد: %s', 'sodino'), mysql2date('Y/m/d H:i', $oldest_event))) : esc_html__('هنوز رویدادی ثبت نشده است.', 'sodino'); ?>
</p>
</div>
<div class="bg-white rounded-lg shadow-sm border border-gray-200 p-6">
<p class="text-sm font-medium text-gray-500"><?php _e('وضعیت قابلیت‌ها', 'sodino'); ?></p>
<div class="mt-3 flex flex-wrap gap-2">
<span class="rounded-full px-3 py-1 text-xs font-semibold <?php echo !empty($settings['pricing_enabled']) ? 'bg-green-50 text-green-700' : 'bg-gray-100 text-gray-600'; ?>"><?php _e('قیمت‌گذاری', 'sodino'); ?></span>
<span class="rounded-full px-3 py-1 text-xs font-semibold <?php echo !empty($settings['upsell_enabled']) ? 'bg-green-50 text-green-700' : 'bg-gray-100 text-gray-600'; ?>"><?php _e('آپسل', 'sodino'); ?></span>
<span class="rounded-full px-3 py-1 text-xs font-semibold <?php echo !empty($settings['banner_enabled']) ? 'bg-green-50 text-green-700' : 'bg-gray-100 text-gray-600'; ?>"><?php _e('بنر', 'sodino'); ?></span>
</div>
</div>
</div>
<div class="bg-white rounded-lg shadow-sm border border-gray-200 overflow-hidden">
<div class="px-6 py-5 border-b border-gray-200">
<h3 class="text-lg font-semibold text-gray-900"><?php _e('جدول‌های سودینو', 'sodino'); ?></h3>
</div>
<div class="overflow-x-auto">
<table class="min-w-full divide-y divide-gray-200 text-right text-sm">
<thead class="bg-gray-50 text-gray-500">
<tr>
<th class="px-6 py-3 font-medium"><?php _e('بخش', 'sodino'); ?></th>
<th class="px-6 py-3 font-medium"><?php _e('جدول', 'sodino'); ?></th>
<th class="px-6 py-3 font-medium"><?php _e('تعداد رکورد', 'sodino'); ?></th>
<th class="px-6 py-3 font-medium"><?php _e('وضعیت', 'sodino'); ?></th>
</tr>
</thead>
<tbody class="divide-y divide-gray-200 bg-white text-gray-700">
<?php foreach ($tables as $table) : ?>
<tr>
<td class="px-6 py-4 font-medium text-gray-900"><?php echo esc_html($table['label']); ?></td>
<td class="px-6 py-4"><code><?php echo esc_html($table['name']); ?></code></td>
<td class="px-6 py-4"><?php echo esc_html(number_format_i18n($table['count'])); ?></td>
<td class="px-6 py-4">
<?php if (!empty($table['exists'])) : ?>
<span class="rounded-full bg-green-50 px-3 py-1 text-xs font-semibold text-green-700"><?php _e('موجود', 'sodino'); ?></span>
<?php else : ?>
<span class="rounded-full bg-red-50 px-3 py-1 text-xs font-semibold text-red-700"><?php _e('نیازمند ساخت', 'sodino'); ?></span>
<?php endif; ?>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
</div>
<div class="bg-white rounded-lg shadow-sm border border-gray-200 p-6">
<div class="flex flex-col gap-4 lg:flex-row lg:items-center lg:justify-between">
<div>
<h3 class="text-lg font-semibold text-gray-900"><?php _e('پاک‌سازی داده‌های قدیمی', 'sodino'); ?></h3>
<p class="mt-2 text-sm text-gray-500">
<?php echo esc_html(sprintf(__('رویدادهای قدیمی‌تر از ۹۰ روز آماده حذف: %s', 'sodino'), number_format_i18n($old_event_count))); ?>
</p>
</div>
<a href="<?php echo esc_url($actions['prune_events'] ?? '#'); ?>" onclick="return confirm('<?php echo esc_js(__('رویدادهای قدیمی حذف شوند؟ این عملیات قابل بازگشت نیست.', 'sodino')); ?>');" class="inline-flex items-center justify-center rounded-lg border border-red-200 bg-red-50 px-4 py-2 text-sm font-semibold text-red-700 hover:bg-red-100">
<?php _e('حذف رویدادهای قدیمی', 'sodino'); ?>
</a>
</div>
</div>
</main>
</div>
</div>
</div>