Upload via GUI (1 Datei)
This commit is contained in:
@@ -3,7 +3,7 @@
|
|||||||
Plugin Name: WP Ingame Shop Pro
|
Plugin Name: WP Ingame Shop Pro
|
||||||
Plugin URI:https://git.viper.ipv64.net/M_Viper/WP-Ingame-Shop-Pro
|
Plugin URI:https://git.viper.ipv64.net/M_Viper/WP-Ingame-Shop-Pro
|
||||||
Description: Vollautomatischer Shop mit Warenkorb (kein echtgeld Handel)
|
Description: Vollautomatischer Shop mit Warenkorb (kein echtgeld Handel)
|
||||||
Version: 2.1.3
|
Version: 2.1.4
|
||||||
Author: M_Viper
|
Author: M_Viper
|
||||||
Author URI: https://m-viper.de
|
Author URI: https://m-viper.de
|
||||||
Requires at least: 6.9.1
|
Requires at least: 6.9.1
|
||||||
@@ -20,7 +20,7 @@ Support: [Telegram Support](https://t.me/M_Viper04)
|
|||||||
if (!defined('ABSPATH')) exit;
|
if (!defined('ABSPATH')) exit;
|
||||||
|
|
||||||
// Plugin Constants
|
// Plugin Constants
|
||||||
define('WIS_VERSION', '2.1.3');
|
define('WIS_VERSION', '2.1.4');
|
||||||
define('WIS_PLUGIN_DIR', plugin_dir_path(__FILE__));
|
define('WIS_PLUGIN_DIR', plugin_dir_path(__FILE__));
|
||||||
define('WIS_PLUGIN_URL', plugin_dir_url(__FILE__));
|
define('WIS_PLUGIN_URL', plugin_dir_url(__FILE__));
|
||||||
|
|
||||||
@@ -4402,13 +4402,18 @@ class WIS_Admin {
|
|||||||
$abo_id = intval($_POST['wis_abo_id'] ?? 0);
|
$abo_id = intval($_POST['wis_abo_id'] ?? 0);
|
||||||
|
|
||||||
if ($abo_id > 0) {
|
if ($abo_id > 0) {
|
||||||
if ($abo_type === 'fly') {
|
if ($abo_type === 'plot') {
|
||||||
|
echo '<div class="error"><p>Plot-Abos werden im Spiel verwaltet (/plotabo, /plotabocancel).</p></div>';
|
||||||
|
$table = null;
|
||||||
|
} elseif ($abo_type === 'fly') {
|
||||||
$table = $wpdb->prefix . 'wis_fly_abo_subs';
|
$table = $wpdb->prefix . 'wis_fly_abo_subs';
|
||||||
} else {
|
} else {
|
||||||
$table = $wpdb->prefix . 'wis_item_abo_subs';
|
$table = $wpdb->prefix . 'wis_item_abo_subs';
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($action === 'cancel') {
|
if ($table === null) {
|
||||||
|
// Plot-Abo bereits oben behandelt
|
||||||
|
} elseif ($action === 'cancel') {
|
||||||
$wpdb->update($table,
|
$wpdb->update($table,
|
||||||
['cancelled' => 1, 'cancelled_at' => current_time('mysql')],
|
['cancelled' => 1, 'cancelled_at' => current_time('mysql')],
|
||||||
['id' => $abo_id]
|
['id' => $abo_id]
|
||||||
@@ -4434,19 +4439,51 @@ class WIS_Admin {
|
|||||||
|
|
||||||
$currency = esc_html(get_option('wis_currency_name', '$'));
|
$currency = esc_html(get_option('wis_currency_name', '$'));
|
||||||
|
|
||||||
// ── Fly-Abos laden ────────────────────────────────────────────────
|
// ── Fly-Abos laden (maßgeblich: Spiegel aus dem Spigot-Plugin) ────
|
||||||
$fly_table = $wpdb->prefix . 'wis_fly_abo_subs';
|
$fly_table = $wpdb->prefix . 'wis_fly_abos_mirror';
|
||||||
$fly_exists = $wpdb->get_var("SHOW TABLES LIKE '{$fly_table}'");
|
$fly_exists = $wpdb->get_var("SHOW TABLES LIKE '{$fly_table}'");
|
||||||
$fly_rows = [];
|
$fly_rows = [];
|
||||||
|
// Solange der Spigot-Abgleich noch keine Fly-Abos geliefert hat, die bisherige WP-Tabelle anzeigen
|
||||||
|
if ($fly_exists && !(int) $wpdb->get_var("SELECT COUNT(*) FROM {$fly_table}")) {
|
||||||
|
$fly_exists = false;
|
||||||
|
}
|
||||||
|
if (!$fly_exists) {
|
||||||
|
$legacy_fly = $wpdb->prefix . 'wis_fly_abo_subs';
|
||||||
|
if ($wpdb->get_var("SHOW TABLES LIKE '{$legacy_fly}'") && in_array($f_type, ['all', 'fly'])) {
|
||||||
|
$where = '1=1';
|
||||||
|
$args = [];
|
||||||
|
if ($f_status === 'active') { $where .= " AND status = 'active' AND cancelled = 0 AND expires_at > NOW()"; }
|
||||||
|
elseif ($f_status === 'cancelled') { $where .= " AND cancelled = 1"; }
|
||||||
|
elseif ($f_status === 'expired') { $where .= " AND (status = 'expired' OR expires_at <= NOW())"; }
|
||||||
|
if ($f_player) { $where .= " AND player_name LIKE %s"; $args[] = '%' . $wpdb->esc_like($f_player) . '%'; }
|
||||||
|
$sql = "SELECT *, 'fly' AS abo_type FROM {$legacy_fly} WHERE {$where} ORDER BY created_at DESC LIMIT 200";
|
||||||
|
$fly_rows = $args ? $wpdb->get_results($wpdb->prepare($sql, ...$args)) : $wpdb->get_results($sql);
|
||||||
|
}
|
||||||
|
}
|
||||||
if ($fly_exists && in_array($f_type, ['all', 'fly'])) {
|
if ($fly_exists && in_array($f_type, ['all', 'fly'])) {
|
||||||
$where = '1=1';
|
$where = '1=1';
|
||||||
$args = [];
|
$args = [];
|
||||||
if ($f_status === 'active') { $where .= " AND status = 'active' AND cancelled = 0 AND expires_at > NOW()"; }
|
if ($f_status === 'active') { $where .= " AND period_end >= CURDATE() AND cancelled = 0"; }
|
||||||
elseif ($f_status === 'cancelled') { $where .= " AND cancelled = 1"; }
|
elseif ($f_status === 'cancelled') { $where .= " AND cancelled = 1"; }
|
||||||
elseif ($f_status === 'expired') { $where .= " AND (status = 'expired' OR expires_at <= NOW())"; }
|
elseif ($f_status === 'expired') { $where .= " AND period_end < CURDATE()"; }
|
||||||
if ($f_player) { $where .= " AND player_name LIKE %s"; $args[] = '%' . $f_player . '%'; }
|
if ($f_player) { $where .= " AND player_name LIKE %s"; $args[] = '%' . $wpdb->esc_like($f_player) . '%'; }
|
||||||
$sql = "SELECT *, 'fly' AS abo_type FROM {$fly_table} WHERE {$where} ORDER BY created_at DESC LIMIT 200";
|
$sql = "SELECT * FROM {$fly_table} WHERE {$where} ORDER BY granted_at DESC LIMIT 200";
|
||||||
$fly_rows = $args ? $wpdb->get_results($wpdb->prepare($sql, ...$args)) : $wpdb->get_results($sql);
|
$raw = $args ? $wpdb->get_results($wpdb->prepare($sql, ...$args)) : $wpdb->get_results($sql);
|
||||||
|
foreach ((array) $raw as $r) {
|
||||||
|
$o = new stdClass();
|
||||||
|
$o->id = $r->id;
|
||||||
|
$o->abo_type = 'fly';
|
||||||
|
$o->player_name = $r->player_name;
|
||||||
|
$o->server = '–';
|
||||||
|
$o->label = $r->label;
|
||||||
|
$o->price = $r->monthly_price;
|
||||||
|
$o->created_at = $r->granted_at;
|
||||||
|
$o->expires_at = $r->period_end . ' 23:59:59';
|
||||||
|
$o->cancelled = (int) $r->cancelled;
|
||||||
|
$o->status = (strtotime($o->expires_at) > time()) ? 'active' : 'expired';
|
||||||
|
$o->readonly = true;
|
||||||
|
$fly_rows[] = $o;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ── Item-Abos laden ───────────────────────────────────────────────
|
// ── Item-Abos laden ───────────────────────────────────────────────
|
||||||
@@ -4464,8 +4501,39 @@ class WIS_Admin {
|
|||||||
$item_rows = $args ? $wpdb->get_results($wpdb->prepare($sql, ...$args)) : $wpdb->get_results($sql);
|
$item_rows = $args ? $wpdb->get_results($wpdb->prepare($sql, ...$args)) : $wpdb->get_results($sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ── Plot-Abos laden (Tabelle wird vom Spigot-Plugin verwaltet) ────
|
||||||
|
$plot_table = $wpdb->prefix . 'wis_plot_abos_mirror';
|
||||||
|
if (!$wpdb->get_var("SHOW TABLES LIKE '{$plot_table}'")) $plot_table = '';
|
||||||
|
$plot_rows = [];
|
||||||
|
if ($plot_table && in_array($f_type, ['all', 'plot'])) {
|
||||||
|
$where = '1=1';
|
||||||
|
$args = [];
|
||||||
|
if ($f_status === 'active') { $where .= " AND period_end >= CURDATE() AND cancelled = 0"; }
|
||||||
|
elseif ($f_status === 'cancelled') { $where .= " AND cancelled = 1"; }
|
||||||
|
elseif ($f_status === 'expired') { $where .= " AND period_end < CURDATE()"; }
|
||||||
|
if ($f_player) { $where .= " AND player_name LIKE %s"; $args[] = '%' . $wpdb->esc_like($f_player) . '%'; }
|
||||||
|
$sql = "SELECT * FROM {$plot_table} WHERE {$where} ORDER BY granted_at DESC LIMIT 200";
|
||||||
|
$raw = $args ? $wpdb->get_results($wpdb->prepare($sql, ...$args)) : $wpdb->get_results($sql);
|
||||||
|
foreach ((array) $raw as $r) {
|
||||||
|
$o = new stdClass();
|
||||||
|
$o->id = $r->id;
|
||||||
|
$o->abo_type = 'plot';
|
||||||
|
$o->player_name = $r->player_name;
|
||||||
|
$o->server = '–';
|
||||||
|
$o->label = $r->label;
|
||||||
|
$o->price = $r->monthly_price;
|
||||||
|
$o->created_at = $r->granted_at;
|
||||||
|
$o->expires_at = $r->period_end . ' 23:59:59';
|
||||||
|
$o->cancelled = (int) $r->cancelled;
|
||||||
|
$o->status = (strtotime($o->expires_at) > time()) ? 'active' : 'expired';
|
||||||
|
$o->slots = $r->abo_slots;
|
||||||
|
$o->frozen_at = $r->frozen_at ?? null;
|
||||||
|
$plot_rows[] = $o;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Zusammenführen und nach Datum sortieren
|
// Zusammenführen und nach Datum sortieren
|
||||||
$all_rows = array_merge($fly_rows, $item_rows);
|
$all_rows = array_merge($fly_rows, $item_rows, $plot_rows);
|
||||||
usort($all_rows, fn($a, $b) => strcmp($b->created_at, $a->created_at));
|
usort($all_rows, fn($a, $b) => strcmp($b->created_at, $a->created_at));
|
||||||
|
|
||||||
$nonce = wp_create_nonce('wis_abo_admin_action');
|
$nonce = wp_create_nonce('wis_abo_admin_action');
|
||||||
@@ -4484,6 +4552,7 @@ class WIS_Admin {
|
|||||||
<option value="all" <?php selected($f_type,'all'); ?>>Alle Typen</option>
|
<option value="all" <?php selected($f_type,'all'); ?>>Alle Typen</option>
|
||||||
<option value="fly" <?php selected($f_type,'fly'); ?>>✈ Fly-Abo</option>
|
<option value="fly" <?php selected($f_type,'fly'); ?>>✈ Fly-Abo</option>
|
||||||
<option value="item" <?php selected($f_type,'item'); ?>>📦 Item-Abo</option>
|
<option value="item" <?php selected($f_type,'item'); ?>>📦 Item-Abo</option>
|
||||||
|
<option value="plot" <?php selected($f_type,'plot'); ?>>🏠 Plot-Abo</option>
|
||||||
</select>
|
</select>
|
||||||
<select name="abo_status">
|
<select name="abo_status">
|
||||||
<option value="active" <?php selected($f_status,'active'); ?>>Aktiv</option>
|
<option value="active" <?php selected($f_status,'active'); ?>>Aktiv</option>
|
||||||
@@ -4516,6 +4585,7 @@ class WIS_Admin {
|
|||||||
<tbody>
|
<tbody>
|
||||||
<?php foreach ($all_rows as $row):
|
<?php foreach ($all_rows as $row):
|
||||||
$is_fly = $row->abo_type === 'fly';
|
$is_fly = $row->abo_type === 'fly';
|
||||||
|
$is_plot = $row->abo_type === 'plot';
|
||||||
$is_active = $row->status === 'active' && !$row->cancelled && strtotime($row->expires_at) > time();
|
$is_active = $row->status === 'active' && !$row->cancelled && strtotime($row->expires_at) > time();
|
||||||
$is_cancelled = (bool) $row->cancelled;
|
$is_cancelled = (bool) $row->cancelled;
|
||||||
$is_expired = !$is_active && !$is_cancelled;
|
$is_expired = !$is_active && !$is_cancelled;
|
||||||
@@ -4525,24 +4595,30 @@ class WIS_Admin {
|
|||||||
: ($is_active
|
: ($is_active
|
||||||
? '<span style="color:#27ae60;font-weight:600;">✔ Aktiv</span>'
|
? '<span style="color:#27ae60;font-weight:600;">✔ Aktiv</span>'
|
||||||
: '<span style="color:#888;">⏱ Abgelaufen</span>');
|
: '<span style="color:#888;">⏱ Abgelaufen</span>');
|
||||||
|
if ($is_plot && !empty($row->frozen_at)) {
|
||||||
|
$left = max(0, 7 - (int) floor((time() - strtotime($row->frozen_at)) / 86400));
|
||||||
|
$status_html = '<span style="color:#2980b9;font-weight:600;">❄ Eingefroren</span><br><small>Freigabe in ' . $left . ' Tg.</small>';
|
||||||
|
}
|
||||||
|
|
||||||
$detail = $is_fly
|
$detail = $is_plot
|
||||||
|
? '🏠 +' . intval($row->slots) . ' Plot-Slots · ' . number_format($row->price) . ' ' . $currency . '/Monat'
|
||||||
|
: ($is_fly
|
||||||
? 'Fly-Abo · ' . number_format($row->price) . ' ' . $currency . '/Monat'
|
? 'Fly-Abo · ' . number_format($row->price) . ' ' . $currency . '/Monat'
|
||||||
: '📦 ' . esc_html($row->item_id) . ' · ' . intval($row->daily_qty) . 'x täglich';
|
: '📦 ' . esc_html($row->item_id) . ' · ' . intval($row->daily_qty) . 'x täglich');
|
||||||
?>
|
?>
|
||||||
<tr>
|
<tr>
|
||||||
<td><strong>#<?php echo $row->id; ?></strong></td>
|
<td><strong>#<?php echo $row->id; ?></strong></td>
|
||||||
<td><?php echo $is_fly ? '✈ Fly' : '📦 Item'; ?></td>
|
<td><?php echo $is_plot ? '🏠 Plot' : ($is_fly ? '✈ Fly' : '📦 Item'); ?></td>
|
||||||
<td><strong><?php echo esc_html($row->player_name); ?></strong></td>
|
<td><strong><?php echo esc_html($row->player_name); ?></strong></td>
|
||||||
<td><?php echo esc_html($row->server); ?></td>
|
<td><?php echo esc_html($row->server); ?></td>
|
||||||
<td>
|
<td>
|
||||||
<strong><?php echo esc_html($row->label); ?></strong>
|
<strong><?php echo esc_html($row->label); ?></strong>
|
||||||
<br><small style="color:#888;"><?php echo $detail; ?></small>
|
<br><small style="color:#888;"><?php echo $detail; ?></small>
|
||||||
<?php if (!$is_fly && !empty($row->last_delivered)): ?>
|
<?php if (!$is_fly && !$is_plot && !empty($row->last_delivered)): ?>
|
||||||
<br><small style="color:#aaa;">Zuletzt geliefert: <?php echo date('d.m.Y', strtotime($row->last_delivered)); ?></small>
|
<br><small style="color:#aaa;">Zuletzt geliefert: <?php echo date('d.m.Y', strtotime($row->last_delivered)); ?></small>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
</td>
|
</td>
|
||||||
<td><?php echo $is_fly ? number_format($row->price) . ' ' . $currency : '–'; ?></td>
|
<td><?php echo ($is_fly || $is_plot) ? number_format($row->price) . ' ' . $currency : '–'; ?></td>
|
||||||
<td><?php echo date('d.m.Y', strtotime($row->expires_at)); ?></td>
|
<td><?php echo date('d.m.Y', strtotime($row->expires_at)); ?></td>
|
||||||
<td><?php echo $status_html; ?></td>
|
<td><?php echo $status_html; ?></td>
|
||||||
<td>
|
<td>
|
||||||
@@ -4550,7 +4626,9 @@ class WIS_Admin {
|
|||||||
<input type="hidden" name="wis_abo_nonce" value="<?php echo $nonce; ?>">
|
<input type="hidden" name="wis_abo_nonce" value="<?php echo $nonce; ?>">
|
||||||
<input type="hidden" name="wis_abo_type" value="<?php echo esc_attr($row->abo_type); ?>">
|
<input type="hidden" name="wis_abo_type" value="<?php echo esc_attr($row->abo_type); ?>">
|
||||||
<input type="hidden" name="wis_abo_id" value="<?php echo $row->id; ?>">
|
<input type="hidden" name="wis_abo_id" value="<?php echo $row->id; ?>">
|
||||||
<?php if ($is_active): ?>
|
<?php if ($is_plot || !empty($row->readonly)): ?>
|
||||||
|
<small style="color:#888;">Verwaltung im Spiel</small>
|
||||||
|
<?php elseif ($is_active): ?>
|
||||||
<button name="wis_abo_action" value="cancel"
|
<button name="wis_abo_action" value="cancel"
|
||||||
class="button button-small"
|
class="button button-small"
|
||||||
style="color:#c0392b;border-color:#c0392b;"
|
style="color:#c0392b;border-color:#c0392b;"
|
||||||
@@ -4561,11 +4639,13 @@ class WIS_Admin {
|
|||||||
style="color:#27ae60;border-color:#27ae60;"
|
style="color:#27ae60;border-color:#27ae60;"
|
||||||
title="Reaktivieren">✔ Reaktivieren</button>
|
title="Reaktivieren">✔ Reaktivieren</button>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
|
<?php if (!$is_plot && empty($row->readonly)): ?>
|
||||||
<button name="wis_abo_action" value="delete"
|
<button name="wis_abo_action" value="delete"
|
||||||
class="button button-small"
|
class="button button-small"
|
||||||
style="color:#888;"
|
style="color:#888;"
|
||||||
title="Eintrag löschen"
|
title="Eintrag löschen"
|
||||||
onclick="return confirm('Abo #<?php echo $row->id; ?> wirklich dauerhaft löschen?');">🗑</button>
|
onclick="return confirm('Abo #<?php echo $row->id; ?> wirklich dauerhaft löschen?');">🗑</button>
|
||||||
|
<?php endif; ?>
|
||||||
</form>
|
</form>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
@@ -5368,12 +5448,30 @@ class WIS_API {
|
|||||||
'permission_callback' => [WIS_Activator::class, 'spigot_permission'],
|
'permission_callback' => [WIS_Activator::class, 'spigot_permission'],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
register_rest_route('wis/v1', '/abo_offers', [
|
||||||
|
'methods' => 'GET',
|
||||||
|
'callback' => [self::class, 'abo_offers'],
|
||||||
|
'permission_callback' => [WIS_Activator::class, 'spigot_permission'],
|
||||||
|
]);
|
||||||
|
|
||||||
|
register_rest_route('wis/v1', '/item_abo_reactivate', [
|
||||||
|
'methods' => 'POST',
|
||||||
|
'callback' => [self::class, 'item_abo_reactivate'],
|
||||||
|
'permission_callback' => [WIS_Activator::class, 'spigot_permission'],
|
||||||
|
]);
|
||||||
|
|
||||||
register_rest_route('wis/v1', '/item_abo_cancel', [
|
register_rest_route('wis/v1', '/item_abo_cancel', [
|
||||||
'methods' => 'POST',
|
'methods' => 'POST',
|
||||||
'callback' => [self::class, 'item_abo_cancel'],
|
'callback' => [self::class, 'item_abo_cancel'],
|
||||||
'permission_callback' => [WIS_Activator::class, 'spigot_permission'],
|
'permission_callback' => [WIS_Activator::class, 'spigot_permission'],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
register_rest_route('wis/v1', '/plot_abo_sync', [
|
||||||
|
'methods' => 'POST',
|
||||||
|
'callback' => [self::class, 'plot_abo_sync'],
|
||||||
|
'permission_callback' => [WIS_Activator::class, 'spigot_permission'],
|
||||||
|
]);
|
||||||
|
|
||||||
register_rest_route('wis/v1', '/trigger_abo_delivery', [
|
register_rest_route('wis/v1', '/trigger_abo_delivery', [
|
||||||
'methods' => 'POST',
|
'methods' => 'POST',
|
||||||
'callback' => [self::class, 'trigger_abo_delivery'],
|
'callback' => [self::class, 'trigger_abo_delivery'],
|
||||||
@@ -5450,6 +5548,78 @@ class WIS_API {
|
|||||||
* GET /wis/v1/item_abo_status?player=<name>
|
* GET /wis/v1/item_abo_status?player=<name>
|
||||||
* Gibt alle aktiven Item-Abos eines Spielers zurück.
|
* Gibt alle aktiven Item-Abos eines Spielers zurück.
|
||||||
*/
|
*/
|
||||||
|
/** Spigot schickt einen Snapshot aller Plot-Abos; wird als Spiegeltabelle für die Abo-Verwaltung abgelegt. */
|
||||||
|
public static function plot_abo_sync($request) {
|
||||||
|
global $wpdb;
|
||||||
|
$json = $request->get_json_params();
|
||||||
|
$abos = $json['abos'] ?? null;
|
||||||
|
if (!is_array($abos)) {
|
||||||
|
return new WP_REST_Response(['success' => false, 'message' => 'abos fehlt'], 400);
|
||||||
|
}
|
||||||
|
$table = $wpdb->prefix . 'wis_plot_abos_mirror';
|
||||||
|
$wpdb->query("CREATE TABLE IF NOT EXISTS {$table} (
|
||||||
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||||
|
player_name VARCHAR(64) NOT NULL,
|
||||||
|
label VARCHAR(128) NOT NULL,
|
||||||
|
abo_slots INT NOT NULL DEFAULT 1,
|
||||||
|
monthly_price INT NOT NULL DEFAULT 0,
|
||||||
|
cancelled TINYINT(1) NOT NULL DEFAULT 0,
|
||||||
|
cancellation_reason VARCHAR(32) NULL,
|
||||||
|
next_billing_date DATE NULL,
|
||||||
|
period_end DATE NULL,
|
||||||
|
frozen_at DATE NULL,
|
||||||
|
granted_at DATETIME NULL
|
||||||
|
) " . $wpdb->get_charset_collate());
|
||||||
|
$wpdb->query("DELETE FROM {$table}");
|
||||||
|
|
||||||
|
// Fly-Abos (Spigot ist maßgeblich für Preis/Laufzeit/Abbuchung)
|
||||||
|
$fly_table = $wpdb->prefix . 'wis_fly_abos_mirror';
|
||||||
|
$wpdb->query("CREATE TABLE IF NOT EXISTS {$fly_table} (
|
||||||
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||||
|
player_name VARCHAR(64) NOT NULL,
|
||||||
|
label VARCHAR(128) NOT NULL,
|
||||||
|
monthly_price INT NOT NULL DEFAULT 0,
|
||||||
|
cancelled TINYINT(1) NOT NULL DEFAULT 0,
|
||||||
|
cancellation_reason VARCHAR(32) NULL,
|
||||||
|
next_billing_date DATE NULL,
|
||||||
|
period_end DATE NULL,
|
||||||
|
granted_at DATETIME NULL
|
||||||
|
) " . $wpdb->get_charset_collate());
|
||||||
|
if (isset($json['fly']) && is_array($json['fly'])) {
|
||||||
|
$wpdb->query("DELETE FROM {$fly_table}");
|
||||||
|
foreach ($json['fly'] as $f) {
|
||||||
|
$wpdb->insert($fly_table, [
|
||||||
|
'player_name' => sanitize_text_field($f['player_name'] ?? ''),
|
||||||
|
'label' => sanitize_text_field($f['label'] ?? ''),
|
||||||
|
'monthly_price' => intval($f['monthly_price'] ?? 0),
|
||||||
|
'cancelled' => intval($f['cancelled'] ?? 0),
|
||||||
|
'cancellation_reason' => !empty($f['cancellation_reason']) ? sanitize_text_field($f['cancellation_reason']) : null,
|
||||||
|
'next_billing_date' => sanitize_text_field($f['next_billing_date'] ?? '') ?: null,
|
||||||
|
'period_end' => sanitize_text_field($f['period_end'] ?? '') ?: null,
|
||||||
|
'granted_at' => sanitize_text_field($f['granted_at'] ?? '') ?: null,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$n = 0;
|
||||||
|
foreach ($abos as $a) {
|
||||||
|
$wpdb->insert($table, [
|
||||||
|
'player_name' => sanitize_text_field($a['player_name'] ?? ''),
|
||||||
|
'label' => sanitize_text_field($a['label'] ?? ''),
|
||||||
|
'abo_slots' => intval($a['abo_slots'] ?? 0),
|
||||||
|
'monthly_price' => intval($a['monthly_price'] ?? 0),
|
||||||
|
'cancelled' => intval($a['cancelled'] ?? 0),
|
||||||
|
'cancellation_reason' => !empty($a['cancellation_reason']) ? sanitize_text_field($a['cancellation_reason']) : null,
|
||||||
|
'next_billing_date' => sanitize_text_field($a['next_billing_date'] ?? '') ?: null,
|
||||||
|
'period_end' => sanitize_text_field($a['period_end'] ?? '') ?: null,
|
||||||
|
'frozen_at' => !empty($a['frozen_at']) ? sanitize_text_field($a['frozen_at']) : null,
|
||||||
|
'granted_at' => sanitize_text_field($a['granted_at'] ?? '') ?: null,
|
||||||
|
]);
|
||||||
|
$n++;
|
||||||
|
}
|
||||||
|
return new WP_REST_Response(['success' => true, 'count' => $n], 200);
|
||||||
|
}
|
||||||
|
|
||||||
public static function item_abo_status($request) {
|
public static function item_abo_status($request) {
|
||||||
global $wpdb;
|
global $wpdb;
|
||||||
$player = sanitize_text_field($request->get_param('player') ?? '');
|
$player = sanitize_text_field($request->get_param('player') ?? '');
|
||||||
@@ -5489,6 +5659,69 @@ class WIS_API {
|
|||||||
* Kündigt genau das Item-Abo mit der angegebenen ID – nur wenn es dem Spieler gehört.
|
* Kündigt genau das Item-Abo mit der angegebenen ID – nur wenn es dem Spieler gehört.
|
||||||
* Gibt 200 bei Erfolg, 403 bei falschem Besitzer, 404 wenn nicht gefunden.
|
* Gibt 200 bei Erfolg, 403 bei falschem Besitzer, 404 wenn nicht gefunden.
|
||||||
*/
|
*/
|
||||||
|
/** Abo-Angebote aus dem Shop (Preis inkl. Steuer wie beim Kauf im Shop). */
|
||||||
|
public static function abo_offers($request) {
|
||||||
|
global $wpdb;
|
||||||
|
$server = sanitize_text_field($request->get_param('server') ?? '');
|
||||||
|
$items = $wpdb->get_results(
|
||||||
|
"SELECT * FROM {$wpdb->prefix}wis_items
|
||||||
|
WHERE status = 'publish' AND (item_id REGEXP '^fly_abo' OR item_id REGEXP '^plot_abo_' OR item_id REGEXP '^item_abo_')
|
||||||
|
ORDER BY name ASC"
|
||||||
|
);
|
||||||
|
$tax_rate = (get_option('wis_tax_enabled', '0') === '1') ? floatval(get_option('wis_tax_rate', '0')) : 0;
|
||||||
|
$names = [];
|
||||||
|
foreach ((array) $wpdb->get_results("SELECT slug, name FROM {$wpdb->prefix}wis_servers") as $sv) {
|
||||||
|
$names[$sv->slug] = $sv->name;
|
||||||
|
}
|
||||||
|
$out = [];
|
||||||
|
foreach ((array) $items as $it) {
|
||||||
|
$slugs = json_decode($it->servers, true) ?: [];
|
||||||
|
if ($server !== '' && !in_array($server, $slugs)) continue;
|
||||||
|
$price = intval($it->offer_price > 0 ? $it->offer_price : $it->price);
|
||||||
|
$tax = $tax_rate > 0 ? intval(floor($price * $tax_rate / 100)) : 0;
|
||||||
|
$type = preg_match('/^fly_abo/', $it->item_id) ? 'fly' : (preg_match('/^plot_abo_/', $it->item_id) ? 'plot' : 'item');
|
||||||
|
$slots = preg_match('/^plot_abo_(\d+)$/', $it->item_id, $m) ? intval($m[1]) : 0;
|
||||||
|
$out[] = [
|
||||||
|
'id' => intval($it->id),
|
||||||
|
'item_id' => $it->item_id,
|
||||||
|
'title' => $it->name,
|
||||||
|
'type' => $type,
|
||||||
|
'slots' => $slots,
|
||||||
|
'price' => $price,
|
||||||
|
'total' => $price + $tax,
|
||||||
|
'servers' => implode(', ', array_map(function ($s) use ($names) { return $names[$s] ?? $s; }, $slugs)),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
return new WP_REST_Response(['offers' => $out], 200);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Kündigung eines noch laufenden Item-Abos zurücknehmen. */
|
||||||
|
public static function item_abo_reactivate($request) {
|
||||||
|
global $wpdb;
|
||||||
|
$body = json_decode($request->get_body(), true);
|
||||||
|
$player = sanitize_text_field($body['player'] ?? '');
|
||||||
|
$abo_id = intval($body['abo_id'] ?? 0);
|
||||||
|
|
||||||
|
if (empty($player) || $abo_id <= 0) {
|
||||||
|
return new WP_REST_Response(['success' => false, 'message' => 'Ungültige Parameter'], 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
$table = $wpdb->prefix . 'wis_item_abo_subs';
|
||||||
|
$row = $wpdb->get_row($wpdb->prepare(
|
||||||
|
"SELECT id, player_name FROM {$table}
|
||||||
|
WHERE id = %d AND status = 'active' AND cancelled = 1 AND expires_at > NOW()",
|
||||||
|
$abo_id
|
||||||
|
));
|
||||||
|
if (!$row) {
|
||||||
|
return new WP_REST_Response(['success' => false, 'message' => 'Abo nicht gefunden oder nicht gekündigt'], 404);
|
||||||
|
}
|
||||||
|
if (strcasecmp($row->player_name, $player) !== 0) {
|
||||||
|
return new WP_REST_Response(['success' => false, 'message' => 'Nicht dein Abo'], 403);
|
||||||
|
}
|
||||||
|
$wpdb->update($table, ['cancelled' => 0, 'cancelled_at' => null], ['id' => $abo_id]);
|
||||||
|
return new WP_REST_Response(['success' => true], 200);
|
||||||
|
}
|
||||||
|
|
||||||
public static function item_abo_cancel($request) {
|
public static function item_abo_cancel($request) {
|
||||||
global $wpdb;
|
global $wpdb;
|
||||||
$body = json_decode($request->get_body(), true);
|
$body = json_decode($request->get_body(), true);
|
||||||
@@ -5842,19 +6075,51 @@ class WIS_API {
|
|||||||
public static function get_orders_history($request) {
|
public static function get_orders_history($request) {
|
||||||
global $wpdb;
|
global $wpdb;
|
||||||
$player = sanitize_text_field($request->get_param('player'));
|
$player = sanitize_text_field($request->get_param('player'));
|
||||||
|
$limit = intval($request->get_param('limit'));
|
||||||
|
$limit = $limit > 0 ? min($limit, 200) : 10;
|
||||||
|
|
||||||
if (!$player) {
|
if (!$player) {
|
||||||
return new WP_REST_Response(['orders' => []]);
|
return new WP_REST_Response(['orders' => []]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Tägliche Item-Abo-Lieferungen (0 $) sind keine Käufe und gehören nicht auf den Beleg
|
||||||
$results = $wpdb->get_results($wpdb->prepare(
|
$results = $wpdb->get_results($wpdb->prepare(
|
||||||
"SELECT id, item_title, price, status, created_at
|
"SELECT id, item_title, price, quantity, server, status, created_at
|
||||||
FROM {$wpdb->prefix}wis_orders
|
FROM {$wpdb->prefix}wis_orders
|
||||||
WHERE player_name = %s
|
WHERE player_name = %s AND item_id <> 'item_abo_delivery'
|
||||||
ORDER BY created_at DESC LIMIT 10",
|
ORDER BY created_at DESC, id DESC LIMIT %d",
|
||||||
$player
|
$player, $limit
|
||||||
));
|
));
|
||||||
|
|
||||||
|
// Bei Abos: alle Server, auf denen das Abo nutzbar ist (aus dem Shop-Artikel)
|
||||||
|
$abo_re = '^(fly_abo|plot_abo|item_abo)';
|
||||||
|
$names = [];
|
||||||
|
foreach ((array) $wpdb->get_results("SELECT slug, name FROM {$wpdb->prefix}wis_servers") as $sv) {
|
||||||
|
$names[$sv->slug] = $sv->name;
|
||||||
|
}
|
||||||
|
foreach ((array) $results as $r) {
|
||||||
|
$slugs = [];
|
||||||
|
$rows = $wpdb->get_col($wpdb->prepare(
|
||||||
|
"SELECT i.servers FROM {$wpdb->prefix}wis_order_items oi
|
||||||
|
JOIN {$wpdb->prefix}wis_items i ON i.item_id = oi.item_id
|
||||||
|
WHERE oi.order_id = %d AND (oi.item_id REGEXP %s OR oi.item_type LIKE %s)",
|
||||||
|
$r->id, $abo_re, '%abo%'
|
||||||
|
));
|
||||||
|
if (!$rows) {
|
||||||
|
// Fallback: Artikel anhand des Titels finden
|
||||||
|
$rows = $wpdb->get_col($wpdb->prepare(
|
||||||
|
"SELECT servers FROM {$wpdb->prefix}wis_items WHERE name = %s AND item_id REGEXP %s",
|
||||||
|
$r->item_title, $abo_re
|
||||||
|
));
|
||||||
|
}
|
||||||
|
foreach ((array) $rows as $json) {
|
||||||
|
foreach ((array) (json_decode($json, true) ?: []) as $slug) $slugs[$slug] = true;
|
||||||
|
}
|
||||||
|
$labels = [];
|
||||||
|
foreach (array_keys($slugs) as $slug) $labels[] = $names[$slug] ?? $slug;
|
||||||
|
$r->usable_servers = implode(', ', $labels);
|
||||||
|
}
|
||||||
|
|
||||||
return new WP_REST_Response(['orders' => $results]);
|
return new WP_REST_Response(['orders' => $results]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user