Wire product cat/tag archives to settings-driven sort and AJAX paging, seller product options/video/params editing, revenue withdraw form and order review submit — finishing remaining shop frontend gaps after buy-path.
564 lines
23 KiB
PHP
564 lines
23 KiB
PHP
<?php
|
|
/**
|
|
* AKSRT admin shop frontend flow operations.
|
|
*
|
|
* @package AKSRT
|
|
*/
|
|
|
|
defined('ABSPATH') || exit;
|
|
|
|
trait AKSRT_Admin_Shop_Controller_Frontend_Flow_Operations {
|
|
|
|
public function check_logged_in_permission(): bool {
|
|
return is_user_logged_in();
|
|
}
|
|
|
|
public function preview_checkout(WP_REST_Request $request): WP_REST_Response {
|
|
if (!class_exists('AKSRT_Shop')) {
|
|
return $this->error('商城服务不可用', 500);
|
|
}
|
|
|
|
$result = AKSRT_Shop::get_instance()->preview_checkout(get_current_user_id(), $this->get_json_params($request));
|
|
if (empty($result['success'])) {
|
|
return $this->error($result['message'] ?? '结算预览失败');
|
|
}
|
|
|
|
return $this->success(['data' => $result['data']]);
|
|
}
|
|
|
|
public function create_frontend_order(WP_REST_Request $request): WP_REST_Response {
|
|
if (!class_exists('AKSRT_Shop')) {
|
|
return $this->error('商城服务不可用', 500);
|
|
}
|
|
|
|
$result = AKSRT_Shop::get_instance()->create_checkout_order(get_current_user_id(), $this->get_json_params($request));
|
|
if (empty($result['success'])) {
|
|
return $this->error($result['message'] ?? '订单创建失败');
|
|
}
|
|
|
|
return $this->success([
|
|
'message' => __('订单已创建', 'aksrt'),
|
|
'data' => $result['data'],
|
|
], 201);
|
|
}
|
|
|
|
public function get_frontend_orders(WP_REST_Request $request): WP_REST_Response {
|
|
if (!class_exists('AKSRT_Shop')) {
|
|
return $this->success(['data' => ['items' => [], 'total' => 0, 'total_pages' => 1, 'page' => 1]]);
|
|
}
|
|
|
|
$page = max(1, (int) $request->get_param('page'));
|
|
$per_page = max(1, min(50, (int) $request->get_param('per_page'))) ?: 20;
|
|
$status = sanitize_key((string) $request->get_param('status'));
|
|
|
|
$view = AKSRT_Shop::get_instance()->get_order_center_view(get_current_user_id(), [
|
|
'page' => $page,
|
|
'per_page' => $per_page,
|
|
'status' => $status,
|
|
]);
|
|
|
|
return $this->success(['data' => $view]);
|
|
}
|
|
|
|
public function get_frontend_order(WP_REST_Request $request): WP_REST_Response {
|
|
if (!class_exists('AKSRT_Shop')) {
|
|
return $this->error('商城服务不可用', 500);
|
|
}
|
|
|
|
$order_number = sanitize_text_field((string) $request->get_param('order_number'));
|
|
$order = AKSRT_Shop::get_instance()->get_order_detail_view(get_current_user_id(), $order_number);
|
|
if (!$order) {
|
|
return $this->error('订单不存在', 404);
|
|
}
|
|
|
|
return $this->success(['data' => $order]);
|
|
}
|
|
|
|
public function pay_frontend_order(WP_REST_Request $request): WP_REST_Response {
|
|
if (!class_exists('AKSRT_Shop')) {
|
|
return $this->error('商城服务不可用', 500);
|
|
}
|
|
|
|
$params = $this->get_json_params($request);
|
|
$payment_method = sanitize_key((string) ($params['payment_method'] ?? 'balance'));
|
|
$order_number = sanitize_text_field((string) $request->get_param('order_number'));
|
|
|
|
$result = AKSRT_Shop::get_instance()->pay_order(get_current_user_id(), $order_number, $payment_method);
|
|
if (empty($result['success'])) {
|
|
return $this->error($result['message'] ?? '支付失败');
|
|
}
|
|
|
|
return $this->success(['data' => $result['data']]);
|
|
}
|
|
|
|
public function cancel_frontend_order(WP_REST_Request $request): WP_REST_Response {
|
|
if (!class_exists('AKSRT_Shop')) {
|
|
return $this->error('商城服务不可用', 500);
|
|
}
|
|
|
|
$order_number = sanitize_text_field((string) $request->get_param('order_number'));
|
|
$result = AKSRT_Shop::get_instance()->cancel_order(get_current_user_id(), $order_number);
|
|
if (empty($result['success'])) {
|
|
return $this->error($result['message'] ?? '取消订单失败');
|
|
}
|
|
|
|
return $this->success(['data' => $result['data']]);
|
|
}
|
|
|
|
public function create_frontend_after_sale(WP_REST_Request $request): WP_REST_Response {
|
|
if (!class_exists('AKSRT_Shop')) {
|
|
return $this->error('商城服务不可用', 500);
|
|
}
|
|
|
|
$params = $this->get_json_params($request);
|
|
$params['order_number'] = sanitize_text_field((string) $request->get_param('order_number'));
|
|
$result = AKSRT_Shop::get_instance()->create_after_sale_request(get_current_user_id(), $params);
|
|
if (empty($result['success'])) {
|
|
return $this->error($result['message'] ?? '提交售后失败');
|
|
}
|
|
|
|
return $this->success([
|
|
'message' => __('售后申请已提交', 'aksrt'),
|
|
'data' => $result['data'],
|
|
], 201);
|
|
}
|
|
|
|
public function get_cart(WP_REST_Request $request): WP_REST_Response {
|
|
$user_id = get_current_user_id();
|
|
$shop = AKSRT_Shop::get_instance();
|
|
$cart = $shop->get_cart($user_id);
|
|
|
|
$items = [];
|
|
foreach ($cart as $pid => $opts_map) {
|
|
$product_id = (int) $pid;
|
|
$product = $shop->build_product_card_view($product_id);
|
|
if (empty($product) || !is_array($opts_map)) {
|
|
continue;
|
|
}
|
|
foreach ($opts_map as $opt_str => $qty) {
|
|
$options_string = $opt_str === '_default' ? '' : (string) $opt_str;
|
|
$unit_price = method_exists($shop, 'resolve_option_price')
|
|
? (float) $shop->resolve_option_price($product_id, $options_string !== '' ? $options_string : '_default')
|
|
: (float) ($product['price'] ?? 0);
|
|
$options_label = method_exists($shop, 'resolve_option_labels')
|
|
? (string) $shop->resolve_option_labels($product_id, $options_string !== '' ? $options_string : '_default')
|
|
: '';
|
|
$option_image = method_exists($shop, 'get_option_image')
|
|
? (string) $shop->get_option_image($product_id, $options_string !== '' ? $options_string : '_default')
|
|
: '';
|
|
$stock = method_exists($shop, 'resolve_option_stock')
|
|
? (int) $shop->resolve_option_stock($product_id, $options_string !== '' ? $options_string : '_default')
|
|
: (int) ($product['stock'] ?? 0);
|
|
|
|
$items[] = [
|
|
'product_id' => $product_id,
|
|
'options_string' => $options_string,
|
|
'options_label' => $options_label,
|
|
'quantity' => (int) $qty,
|
|
'unit_price' => $unit_price,
|
|
'line_total' => round($unit_price * (int) $qty, 2),
|
|
'stock' => $stock,
|
|
'image' => $option_image !== '' ? $option_image : (string) ($product['image'] ?? ''),
|
|
'title' => (string) ($product['title'] ?? ''),
|
|
'product' => $product,
|
|
];
|
|
}
|
|
}
|
|
|
|
return $this->success([
|
|
'data' => [
|
|
'items' => $items,
|
|
'count' => $shop->get_cart_count($user_id),
|
|
],
|
|
]);
|
|
}
|
|
|
|
public function get_cart_count(WP_REST_Request $request): WP_REST_Response {
|
|
$user_id = get_current_user_id();
|
|
return $this->success(['data' => ['count' => AKSRT_Shop::get_instance()->get_cart_count($user_id)]]);
|
|
}
|
|
|
|
public function handle_add_to_cart(WP_REST_Request $request): WP_REST_Response {
|
|
$params = $this->get_json_params($request);
|
|
$product_id = (int) ($params['product_id'] ?? 0);
|
|
$options_string = sanitize_text_field((string) ($params['options_string'] ?? ''));
|
|
$count = max(1, (int) ($params['count'] ?? 1));
|
|
|
|
$result = AKSRT_Shop::get_instance()->add_to_cart(get_current_user_id(), $product_id, $options_string, $count);
|
|
|
|
if (isset($result['error'])) {
|
|
return $this->error($result['error']);
|
|
}
|
|
return $this->success(['data' => $result]);
|
|
}
|
|
|
|
public function handle_reduce_from_cart(WP_REST_Request $request): WP_REST_Response {
|
|
$params = $this->get_json_params($request);
|
|
$product_id = (int) ($params['product_id'] ?? 0);
|
|
$options_string = sanitize_text_field((string) ($params['options_string'] ?? ''));
|
|
$count = max(1, (int) ($params['count'] ?? 1));
|
|
|
|
$result = AKSRT_Shop::get_instance()->reduce_from_cart(get_current_user_id(), $product_id, $options_string, $count);
|
|
|
|
if (isset($result['error'])) {
|
|
return $this->error($result['error']);
|
|
}
|
|
return $this->success(['data' => $result]);
|
|
}
|
|
|
|
public function handle_remove_from_cart(WP_REST_Request $request): WP_REST_Response {
|
|
$params = $this->get_json_params($request);
|
|
$product_id = (int) ($params['product_id'] ?? 0);
|
|
$options_string = sanitize_text_field((string) ($params['options_string'] ?? ''));
|
|
|
|
$result = AKSRT_Shop::get_instance()->remove_from_cart(get_current_user_id(), $product_id, $options_string);
|
|
|
|
if (isset($result['error'])) {
|
|
return $this->error($result['error']);
|
|
}
|
|
return $this->success(['data' => $result]);
|
|
}
|
|
|
|
public function handle_remove_multi_from_cart(WP_REST_Request $request): WP_REST_Response {
|
|
$params = $this->get_json_params($request);
|
|
$items = is_array($params['items'] ?? null) ? $params['items'] : [];
|
|
|
|
$result = AKSRT_Shop::get_instance()->remove_multi_from_cart(get_current_user_id(), $items);
|
|
|
|
if (isset($result['error'])) {
|
|
return $this->error($result['error']);
|
|
}
|
|
return $this->success(['data' => $result]);
|
|
}
|
|
|
|
public function handle_empty_cart(WP_REST_Request $request): WP_REST_Response {
|
|
$result = AKSRT_Shop::get_instance()->empty_cart(get_current_user_id());
|
|
|
|
if (isset($result['error'])) {
|
|
return $this->error($result['error']);
|
|
}
|
|
return $this->success(['data' => $result]);
|
|
}
|
|
|
|
public function toggle_frontend_product_favorite(WP_REST_Request $request): WP_REST_Response {
|
|
if (!class_exists('AKSRT_Shop')) {
|
|
return $this->error('商城服务不可用', 500);
|
|
}
|
|
|
|
$product_id = (int) $request->get_param('id');
|
|
$result = AKSRT_Shop::get_instance()->toggle_favorite(get_current_user_id(), $product_id);
|
|
if (empty($result['success'])) {
|
|
return $this->error(__('收藏操作失败', 'aksrt'));
|
|
}
|
|
|
|
return $this->success([
|
|
'message' => !empty($result['is_favorite']) ? __('已收藏', 'aksrt') : __('已取消收藏', 'aksrt'),
|
|
'data' => $result,
|
|
]);
|
|
}
|
|
|
|
public function rebuy_frontend_order(WP_REST_Request $request): WP_REST_Response {
|
|
if (!class_exists('AKSRT_Shop')) {
|
|
return $this->error('商城服务不可用', 500);
|
|
}
|
|
|
|
$order_number = sanitize_text_field((string) $request->get_param('order_number'));
|
|
$result = AKSRT_Shop::get_instance()->re_purchase(get_current_user_id(), $order_number);
|
|
if (empty($result['success'])) {
|
|
return $this->error($result['message'] ?? __('再次购买失败', 'aksrt'));
|
|
}
|
|
|
|
return $this->success([
|
|
'message' => __('商品已加入购物车', 'aksrt'),
|
|
'data' => $result,
|
|
]);
|
|
}
|
|
|
|
public function get_frontend_addresses(): WP_REST_Response {
|
|
if (!class_exists('AKSRT_Shop')) {
|
|
return $this->success(['data' => ['addresses' => []]]);
|
|
}
|
|
|
|
$addresses = AKSRT_Shop::get_instance()->get_address_book(get_current_user_id());
|
|
return $this->success(['data' => ['addresses' => $addresses]]);
|
|
}
|
|
|
|
public function create_frontend_address(WP_REST_Request $request): WP_REST_Response {
|
|
if (!class_exists('AKSRT_Shop')) {
|
|
return $this->error('商城服务不可用', 500);
|
|
}
|
|
|
|
$params = $this->get_json_params($request);
|
|
$user_id = get_current_user_id();
|
|
$result = AKSRT_Shop::get_instance()->add_address($user_id, $params);
|
|
|
|
if (empty($result['success'])) {
|
|
return $this->error($result['error'] ?? '添加地址失败');
|
|
}
|
|
|
|
return $this->success([
|
|
'message' => __('地址已添加', 'aksrt'),
|
|
'data' => ['address' => $result['address']],
|
|
], 201);
|
|
}
|
|
|
|
public function update_frontend_address(WP_REST_Request $request): WP_REST_Response {
|
|
if (!class_exists('AKSRT_Shop')) {
|
|
return $this->error('商城服务不可用', 500);
|
|
}
|
|
|
|
$address_id = (int) $request->get_param('id');
|
|
$params = $this->get_json_params($request);
|
|
$user_id = get_current_user_id();
|
|
$result = AKSRT_Shop::get_instance()->update_address($user_id, $address_id, $params);
|
|
|
|
if (empty($result['success'])) {
|
|
return $this->error($result['error'] ?? '更新地址失败');
|
|
}
|
|
|
|
return $this->success([
|
|
'message' => __('地址已更新', 'aksrt'),
|
|
'data' => ['address' => $result['address']],
|
|
]);
|
|
}
|
|
|
|
public function delete_frontend_address(WP_REST_Request $request): WP_REST_Response {
|
|
if (!class_exists('AKSRT_Shop')) {
|
|
return $this->error('商城服务不可用', 500);
|
|
}
|
|
|
|
$address_id = (int) $request->get_param('id');
|
|
$user_id = get_current_user_id();
|
|
$result = AKSRT_Shop::get_instance()->delete_address($user_id, $address_id);
|
|
|
|
if (empty($result['success'])) {
|
|
return $this->error($result['error'] ?? '删除地址失败');
|
|
}
|
|
|
|
return $this->success(['message' => __('地址已删除', 'aksrt')]);
|
|
}
|
|
|
|
public function set_default_frontend_address(WP_REST_Request $request): WP_REST_Response {
|
|
if (!class_exists('AKSRT_Shop')) {
|
|
return $this->error('商城服务不可用', 500);
|
|
}
|
|
|
|
$address_id = (int) $request->get_param('id');
|
|
$user_id = get_current_user_id();
|
|
$result = AKSRT_Shop::get_instance()->set_default_address($user_id, $address_id);
|
|
|
|
if (empty($result['success'])) {
|
|
return $this->error($result['error'] ?? '设置默认地址失败');
|
|
}
|
|
|
|
return $this->success(['message' => __('已设为默认地址', 'aksrt')]);
|
|
}
|
|
|
|
public function get_frontend_product_archive(WP_REST_Request $request): WP_REST_Response {
|
|
if (!class_exists('AKSRT_Shop')) {
|
|
return $this->error('商城服务不可用', 500);
|
|
}
|
|
|
|
$taxonomy = sanitize_key((string) ($request->get_param('taxonomy') ?? ''));
|
|
$term_id = (int) ($request->get_param('term_id') ?? 0);
|
|
$page = max(1, (int) ($request->get_param('page') ?? 1));
|
|
$orderby = sanitize_key((string) ($request->get_param('orderby') ?? ''));
|
|
|
|
$view = AKSRT_Shop::get_instance()->get_product_archive_view([
|
|
'taxonomy' => $taxonomy,
|
|
'term_id' => $term_id,
|
|
'paged' => $page,
|
|
'orderby' => $orderby,
|
|
]);
|
|
|
|
$html = '';
|
|
if (!empty($view['products']) && is_array($view['products'])) {
|
|
ob_start();
|
|
foreach ($view['products'] as $product) {
|
|
$this->render_product_card_html($product, $view);
|
|
}
|
|
$html = (string) ob_get_clean();
|
|
}
|
|
|
|
return $this->success([
|
|
'data' => array_merge($view, [
|
|
'html' => $html,
|
|
'has_more' => (int) ($view['page'] ?? 1) < (int) ($view['max_pages'] ?? 1),
|
|
]),
|
|
]);
|
|
}
|
|
|
|
private function render_product_card_html(array $product, array $view = []): void {
|
|
$sales_cfg = is_array($view['sales'] ?? null) ? $view['sales'] : [];
|
|
$mode = (string) ($sales_cfg['show'] ?? 'show');
|
|
$min_sales = max(0, (int) ($sales_cfg['show_min'] ?? 0));
|
|
$sales = (int) ($product['sales'] ?? 0);
|
|
$can_show_sales = false;
|
|
if ($mode === 'show') {
|
|
$can_show_sales = $sales > 0;
|
|
} elseif ($mode === 'threshold') {
|
|
$can_show_sales = $sales >= $min_sales;
|
|
}
|
|
|
|
$permalink = (string) ($product['permalink'] ?? '#');
|
|
$title = (string) ($product['title'] ?? '');
|
|
$image = (string) ($product['image'] ?? '');
|
|
$price = (float) ($product['price'] ?? 0);
|
|
$excerpt = (string) ($product['excerpt'] ?? '');
|
|
?>
|
|
<article class="aksrt-product-card">
|
|
<a href="<?php echo esc_url($permalink); ?>" class="aksrt-product-card__link">
|
|
<?php if ($image !== '') : ?>
|
|
<div class="aksrt-product-card__image">
|
|
<img src="<?php echo esc_url($image); ?>" alt="<?php echo esc_attr($title); ?>" loading="lazy">
|
|
</div>
|
|
<?php else : ?>
|
|
<div class="aksrt-product-card__image aksrt-product-card__image--placeholder">
|
|
<i class="fas fa-image"></i>
|
|
</div>
|
|
<?php endif; ?>
|
|
<div class="aksrt-product-card__body">
|
|
<h3 class="aksrt-product-card__title"><?php echo esc_html($title); ?></h3>
|
|
<?php if ($excerpt !== '') : ?>
|
|
<p class="aksrt-product-card__excerpt"><?php echo esc_html(wp_trim_words($excerpt, 15)); ?></p>
|
|
<?php endif; ?>
|
|
<div class="aksrt-product-card__footer">
|
|
<span class="aksrt-product-card__price">¥<?php echo esc_html(number_format($price, 2)); ?></span>
|
|
<?php if ($can_show_sales) : ?>
|
|
<span class="aksrt-product-card__sales"><?php printf(esc_html__('已售 %d', 'aksrt'), $sales); ?></span>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
</a>
|
|
</article>
|
|
<?php
|
|
}
|
|
|
|
public function get_frontend_revenue(WP_REST_Request $request): WP_REST_Response {
|
|
if (!function_exists('aksrt_get_revenue_page_view')) {
|
|
return $this->error('收益服务不可用', 500);
|
|
}
|
|
$view = aksrt_get_revenue_page_view(get_current_user_id());
|
|
$withdrawals = [];
|
|
if (class_exists('AKSRT_Withdrawal')) {
|
|
$rows = AKSRT_Withdrawal::get_instance()->get_user_withdrawals(get_current_user_id(), ['limit' => 20]);
|
|
foreach ($rows as $row) {
|
|
$withdrawals[] = [
|
|
'id' => (int) ($row['id'] ?? 0),
|
|
'amount' => (float) ($row['amount'] ?? 0),
|
|
'status' => (string) ($row['status'] ?? ''),
|
|
'method' => (string) ($row['method'] ?? ''),
|
|
'created_at' => (string) ($row['created_at'] ?? ''),
|
|
'note' => (string) ($row['note'] ?? ''),
|
|
];
|
|
}
|
|
}
|
|
$settings = class_exists('AKSRT_Settings') ? AKSRT_Settings::get_withdrawal_settings() : [];
|
|
return $this->success([
|
|
'data' => array_merge($view, [
|
|
'withdrawals' => $withdrawals,
|
|
'settings' => [
|
|
'min_amount' => (float) ($settings['min_amount'] ?? 50),
|
|
'service_charge_rate' => (float) ($settings['service_charge_rate'] ?? 0),
|
|
'text' => (string) ($settings['text'] ?? ''),
|
|
],
|
|
]),
|
|
]);
|
|
}
|
|
|
|
public function create_frontend_withdraw(WP_REST_Request $request): WP_REST_Response {
|
|
if (!class_exists('AKSRT_Withdrawal') || !class_exists('AKSRT_Credits')) {
|
|
return $this->error('提现服务不可用', 500);
|
|
}
|
|
|
|
$params = $this->get_json_params($request);
|
|
$amount = (float) ($params['amount'] ?? 0);
|
|
$method = sanitize_key((string) ($params['method'] ?? 'alipay'));
|
|
$account = sanitize_textarea_field((string) ($params['account_info'] ?? $params['account'] ?? ''));
|
|
|
|
$settings = class_exists('AKSRT_Settings') ? AKSRT_Settings::get_withdrawal_settings() : [];
|
|
$min = (float) ($settings['min_amount'] ?? 50);
|
|
if ($amount < $min) {
|
|
return $this->error(sprintf(__('最低提现金额为 %s', 'aksrt'), $min));
|
|
}
|
|
if ($account === '') {
|
|
return $this->error(__('请填写收款账户信息', 'aksrt'));
|
|
}
|
|
|
|
$user_id = get_current_user_id();
|
|
$balance = (float) AKSRT_Credits::balance($user_id);
|
|
if ($amount > $balance) {
|
|
return $this->error(__('可提现余额不足', 'aksrt'));
|
|
}
|
|
|
|
$cost = (int) round($amount);
|
|
if ($cost <= 0) {
|
|
return $this->error(__('提现金额无效', 'aksrt'));
|
|
}
|
|
$deducted = AKSRT_Credits::deduct($user_id, $cost, 'withdraw', ['type' => 'withdraw'], __('用户提现申请', 'aksrt'));
|
|
if (is_wp_error($deducted)) {
|
|
return $this->error($deducted->get_error_message());
|
|
}
|
|
|
|
$id = AKSRT_Withdrawal::get_instance()->create($user_id, $amount, $method, $account);
|
|
if ($id <= 0) {
|
|
AKSRT_Credits::add($user_id, $cost, 'withdraw_refund', ['type' => 'withdraw'], __('提现失败退回', 'aksrt'));
|
|
return $this->error(__('提现申请创建失败', 'aksrt'), 500);
|
|
}
|
|
|
|
return $this->success([
|
|
'message' => __('提现申请已提交', 'aksrt'),
|
|
'data' => [
|
|
'id' => $id,
|
|
'amount' => $amount,
|
|
'balance' => (float) AKSRT_Credits::balance($user_id),
|
|
],
|
|
], 201);
|
|
}
|
|
|
|
public function submit_frontend_product_review(WP_REST_Request $request): WP_REST_Response {
|
|
if (!class_exists('AKSRT_Product_Review')) {
|
|
return $this->error('评价服务不可用', 500);
|
|
}
|
|
$params = $this->get_json_params($request);
|
|
$order_number = sanitize_text_field((string) $request->get_param('order_number'));
|
|
$product_id = (int) ($params['product_id'] ?? 0);
|
|
$result = AKSRT_Product_Review::get_instance()->submit_review(
|
|
get_current_user_id(),
|
|
$order_number,
|
|
$product_id,
|
|
$params
|
|
);
|
|
if (empty($result['success'])) {
|
|
return $this->error($result['message'] ?? __('评价失败', 'aksrt'));
|
|
}
|
|
return $this->success([
|
|
'message' => __('评价已提交', 'aksrt'),
|
|
'data' => $result,
|
|
], 201);
|
|
}
|
|
|
|
public function create_frontend_product(WP_REST_Request $request): WP_REST_Response {
|
|
$params = $this->get_json_params($request);
|
|
$params['author_id'] = get_current_user_id();
|
|
$frontend_request = new WP_REST_Request('POST', '/');
|
|
$frontend_request->set_body(wp_json_encode($params));
|
|
|
|
return $this->create_product($frontend_request);
|
|
}
|
|
|
|
public function update_frontend_product(WP_REST_Request $request): WP_REST_Response {
|
|
$id = (int) $request->get_param('id');
|
|
$post = get_post($id);
|
|
if (!$post || $post->post_type !== 'aksrt_product') {
|
|
return $this->error('商品不存在', 404);
|
|
}
|
|
|
|
if ((int) $post->post_author !== get_current_user_id() && !current_user_can('manage_options')) {
|
|
return $this->error('没有权限编辑该商品', 403);
|
|
}
|
|
|
|
return $this->update_product($request);
|
|
}
|
|
}
|