feat(ux): after-sale multi-step, ban appeal, message types, coupon wallet
Orders center gains after-sale tickets (return ship/cancel/timeline), coupon wallet list, ban-appeal page, and expanded message center tabs.
This commit is contained in:
@@ -71,6 +71,30 @@ class ShopController extends ControllerBase {
|
||||
'permission_callback' => [$this, 'check_logged_in_permission'],
|
||||
]);
|
||||
|
||||
register_rest_route(self::API_NAMESPACE, '/shop/frontend/after-sale', [
|
||||
'methods' => 'GET',
|
||||
'callback' => [$this, 'get_frontend_after_sales'],
|
||||
'permission_callback' => [$this, 'check_logged_in_permission'],
|
||||
]);
|
||||
|
||||
register_rest_route(self::API_NAMESPACE, '/shop/frontend/after-sale/(?P<id>\d+)/return-shipping', [
|
||||
'methods' => 'POST',
|
||||
'callback' => [$this, 'submit_frontend_return_shipping'],
|
||||
'permission_callback' => [$this, 'check_logged_in_permission'],
|
||||
]);
|
||||
|
||||
register_rest_route(self::API_NAMESPACE, '/shop/frontend/after-sale/(?P<id>\d+)/cancel', [
|
||||
'methods' => 'POST',
|
||||
'callback' => [$this, 'cancel_frontend_after_sale'],
|
||||
'permission_callback' => [$this, 'check_logged_in_permission'],
|
||||
]);
|
||||
|
||||
register_rest_route(self::API_NAMESPACE, '/shop/frontend/coupons', [
|
||||
'methods' => 'GET',
|
||||
'callback' => [$this, 'get_frontend_coupons'],
|
||||
'permission_callback' => [$this, 'check_logged_in_permission'],
|
||||
]);
|
||||
|
||||
// ── Address book CRUD (frontend) ──
|
||||
|
||||
register_rest_route(self::API_NAMESPACE, '/shop/frontend/address', [
|
||||
|
||||
@@ -123,6 +123,76 @@ trait ShopControllerFrontendFlowOperations {
|
||||
], 201);
|
||||
}
|
||||
|
||||
public function get_frontend_after_sales(\WP_REST_Request $request): \WP_REST_Response {
|
||||
if (!class_exists('\AKSRT\Shop\Shop')) {
|
||||
return $this->error('商城服务不可用', 500);
|
||||
}
|
||||
$data = \AKSRT\Shop\Shop::get_instance()->get_user_after_sales(get_current_user_id());
|
||||
return $this->success(['data' => $data]);
|
||||
}
|
||||
|
||||
public function submit_frontend_return_shipping(\WP_REST_Request $request): \WP_REST_Response {
|
||||
if (!class_exists('\AKSRT\Shop\Shop')) {
|
||||
return $this->error('商城服务不可用', 500);
|
||||
}
|
||||
$id = (int) $request->get_param('id');
|
||||
$params = $this->get_json_params($request);
|
||||
$result = \AKSRT\Shop\Shop::get_instance()->submit_after_sale_return(get_current_user_id(), $id, $params);
|
||||
if (empty($result['success'])) {
|
||||
return $this->error($result['message'] ?? '提交退货物流失败');
|
||||
}
|
||||
return $this->success([
|
||||
'message' => $result['message'] ?? __('退货物流已提交', 'aksrt'),
|
||||
'data' => $result['data'] ?? [],
|
||||
]);
|
||||
}
|
||||
|
||||
public function cancel_frontend_after_sale(\WP_REST_Request $request): \WP_REST_Response {
|
||||
if (!class_exists('\AKSRT\Shop\Shop')) {
|
||||
return $this->error('商城服务不可用', 500);
|
||||
}
|
||||
$id = (int) $request->get_param('id');
|
||||
$params = $this->get_json_params($request);
|
||||
$reason = sanitize_text_field((string) ($params['reason'] ?? ''));
|
||||
$result = \AKSRT\Shop\Shop::get_instance()->cancel_after_sale(get_current_user_id(), $id, $reason);
|
||||
if (empty($result['success'])) {
|
||||
return $this->error($result['message'] ?? '取消售后失败');
|
||||
}
|
||||
return $this->success(['message' => $result['message'] ?? __('已取消', 'aksrt')]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Active public coupons for wallet UI (not personal inventory — site-wide active codes).
|
||||
*/
|
||||
public function get_frontend_coupons(\WP_REST_Request $request): \WP_REST_Response {
|
||||
if (!class_exists('\AKSRT\Payment\Coupon')) {
|
||||
return $this->error('优惠券不可用', 500);
|
||||
}
|
||||
$list = \AKSRT\Payment\Coupon::get_instance()->get_list([
|
||||
'status' => 'active',
|
||||
'limit' => 50,
|
||||
'offset' => 0,
|
||||
]);
|
||||
$user_id = get_current_user_id();
|
||||
$items = [];
|
||||
foreach ((array) ($list['items'] ?? []) as $c) {
|
||||
$items[] = [
|
||||
'id' => (int) ($c['id'] ?? 0),
|
||||
'code' => (string) ($c['code'] ?? ''),
|
||||
'type' => (string) ($c['type'] ?? ''),
|
||||
'value' => (float) ($c['value'] ?? 0),
|
||||
'min_amount' => (float) ($c['min_amount'] ?? 0),
|
||||
'max_discount' => (float) ($c['max_discount'] ?? 0),
|
||||
'expires_at' => (string) ($c['expires_at'] ?? ''),
|
||||
'user_used' => $user_id > 0
|
||||
? (int) \AKSRT\Payment\Coupon::get_instance()->get_user_usage_count((int) ($c['id'] ?? 0), $user_id)
|
||||
: 0,
|
||||
'per_user_limit' => (int) ($c['per_user_limit'] ?? 0),
|
||||
];
|
||||
}
|
||||
return $this->success(['data' => ['items' => $items]]);
|
||||
}
|
||||
|
||||
public function get_cart(\WP_REST_Request $request): \WP_REST_Response {
|
||||
$user_id = get_current_user_id();
|
||||
$shop = \AKSRT\Shop\Shop::get_instance();
|
||||
|
||||
Reference in New Issue
Block a user