refactor(autoload): migrate theme classes to Composer PSR-4
Move 288 types from global AKSRT_* + inc/classes manual requires into
namespace AKSRT\{Domain} under src/AKSRT/, wire composer.json psr-4,
and slim bootstrap to helpers/modules/hooks only. Split multi-class
widget/gateway files, update admin contract audit paths, and document
the layout in ADR/README.
This commit is contained in:
@@ -0,0 +1,97 @@
|
||||
<?php
|
||||
/**
|
||||
* @package AKSRT
|
||||
*/
|
||||
|
||||
namespace AKSRT\Admin;
|
||||
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
trait ShopControllerCouponGatewayOperations {
|
||||
|
||||
/**
|
||||
* GET /shop/coupons — 优惠券列表
|
||||
*/
|
||||
public function get_coupons(\WP_REST_Request $request): \WP_REST_Response {
|
||||
if (!class_exists('\AKSRT\Payment\Coupon')) {
|
||||
return $this->success(['data' => ['items' => [], 'total' => 0, 'page' => 1, 'total_pages' => 1]]);
|
||||
}
|
||||
|
||||
$page = max(1, (int) $request->get_param('page'));
|
||||
$per_page = max(1, min(100, (int) $request->get_param('per_page'))) ?: 20;
|
||||
$status = sanitize_key((string) $request->get_param('status'));
|
||||
$search = sanitize_text_field((string) $request->get_param('search'));
|
||||
|
||||
$result = \AKSRT\Payment\Coupon::get_instance()->get_list([
|
||||
'status' => $status,
|
||||
'search' => $search,
|
||||
'limit' => $per_page,
|
||||
'offset' => ($page - 1) * $per_page,
|
||||
]);
|
||||
|
||||
return $this->success(['data' => $result]);
|
||||
}
|
||||
|
||||
/**
|
||||
* POST /shop/coupons — 创建优惠券
|
||||
*/
|
||||
public function create_coupon(\WP_REST_Request $request): \WP_REST_Response {
|
||||
if (!class_exists('\AKSRT\Payment\Coupon')) {
|
||||
return $this->error('优惠券系统未启用', 500);
|
||||
}
|
||||
|
||||
$params = $this->get_json_params($request);
|
||||
$code = sanitize_text_field((string) ($params['code'] ?? ''));
|
||||
|
||||
if ($code === '') {
|
||||
return $this->error('优惠码不能为空');
|
||||
}
|
||||
|
||||
$id = \AKSRT\Payment\Coupon::get_instance()->create($params);
|
||||
|
||||
if ($id > 0) {
|
||||
return $this->success([
|
||||
'message' => __('优惠券已创建', 'aksrt'),
|
||||
'data' => ['id' => $id],
|
||||
], 201);
|
||||
}
|
||||
|
||||
return $this->error(__('创建失败(可能优惠码已存在)', 'aksrt'));
|
||||
}
|
||||
|
||||
/**
|
||||
* POST /shop/coupons/{id}/disable — 禁用优惠券
|
||||
*/
|
||||
public function disable_coupon(\WP_REST_Request $request): \WP_REST_Response {
|
||||
if (!class_exists('\AKSRT\Payment\Coupon')) {
|
||||
return $this->error('优惠券系统未启用', 500);
|
||||
}
|
||||
|
||||
$id = (int) $request->get_param('id');
|
||||
if ($id <= 0) {
|
||||
return $this->error('参数无效');
|
||||
}
|
||||
|
||||
$success = \AKSRT\Payment\Coupon::get_instance()->disable($id);
|
||||
|
||||
if ($success) {
|
||||
return $this->success(['message' => __('优惠券已禁用', 'aksrt')]);
|
||||
}
|
||||
return $this->error(__('操作失败', 'aksrt'));
|
||||
}
|
||||
|
||||
/**
|
||||
* GET /shop/gateways — 支付网关状态列表
|
||||
*/
|
||||
public function get_gateways(): \WP_REST_Response {
|
||||
if (!class_exists('\AKSRT\Payment\Gateway')) {
|
||||
return $this->success(['data' => ['gateways' => []]]);
|
||||
}
|
||||
|
||||
return $this->success([
|
||||
'data' => [
|
||||
'gateways' => \AKSRT\Payment\Gateway::get_instance()->get_status_summary(),
|
||||
],
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user