feat(admin): coupon field parity/batch and charge-card UX polish

Native coupons expose per-user limit, max discount, batch generate, enable;
charge cards support expires_at, code dump after batch, search and CN labels.
This commit is contained in:
2026-07-15 02:54:54 +08:00
parent 7a1069f003
commit d1697c19d9
4 changed files with 221 additions and 22 deletions
+36
View File
@@ -245,6 +245,42 @@ class AKSRT_Coupon {
return $wpdb->update($this->table(), ['status' => 'disabled'], ['id' => $id], ['%s'], ['%d']) !== false;
}
public function enable(int $id): bool {
global $wpdb;
return $wpdb->update($this->table(), ['status' => 'active'], ['id' => $id], ['%s'], ['%d']) !== false;
}
/**
* Batch-create coupons with auto-generated codes.
*
* @return array{created:int,codes:array<int,string>}
*/
public function batch_create(array $data, int $count = 1, int $length = 10, string $prefix = ''): array {
$count = max(1, min(100, $count));
$length = max(6, min(24, $length));
$prefix = sanitize_text_field($prefix);
$codes = [];
$created = 0;
for ($i = 0; $i < $count; $i++) {
$code = $prefix !== ''
? $prefix . strtoupper(wp_generate_password($length, false, false))
: strtoupper(wp_generate_password($length, false, false));
$payload = $data;
$payload['code'] = $code;
$id = $this->create($payload);
if ($id > 0) {
$created++;
$codes[] = $code;
}
}
return [
'created' => $created,
'codes' => $codes,
];
}
/**
* Count how many times a user has used a specific coupon.
*/