修复支付状态问题
This commit is contained in:
1 parent
406fb8d6a6
commit
85a124b886
21 files changed
+198
-308
No files matched your search
@@ -50,16 +50,11 @@ class DomainModel {
|
||||
public const PAY_TYPE_VIDEO = 'video';
|
||||
public const PAY_TYPE_VIP = 'vip';
|
||||
|
||||
public const ORDER_STATUS_CREATED = 'created';
|
||||
public const ORDER_STATUS_PENDING = 'pending';
|
||||
public const ORDER_STATUS_PAID = 'paid';
|
||||
public const ORDER_STATUS_DELIVERED = 'delivered';
|
||||
public const ORDER_STATUS_COMPLETED = 'completed';
|
||||
public const ORDER_STATUS_CANCELLED = 'cancelled';
|
||||
public const ORDER_STATUS_EXPIRED = 'expired';
|
||||
public const ORDER_STATUS_REFUNDING = 'refunding';
|
||||
public const ORDER_STATUS_REFUNDED = 'refunded';
|
||||
public const ORDER_STATUS_PENDING_REVIEW = 'pending_review';
|
||||
public const ORDER_STATUS_CLOSED = 'closed';
|
||||
|
||||
public const SHIPPING_STATUS_PENDING = 0;
|
||||
public const SHIPPING_STATUS_SHIPPED = 1;
|
||||
@@ -390,16 +385,11 @@ class DomainModel {
|
||||
*/
|
||||
public static function order_status_labels(): array {
|
||||
return [
|
||||
self::ORDER_STATUS_CREATED => __('已创建', 'aksrt'),
|
||||
self::ORDER_STATUS_PENDING => __('待支付', 'aksrt'),
|
||||
self::ORDER_STATUS_PAID => __('已支付', 'aksrt'),
|
||||
self::ORDER_STATUS_DELIVERED => __('已发货', 'aksrt'),
|
||||
self::ORDER_STATUS_COMPLETED => __('已完成', 'aksrt'),
|
||||
self::ORDER_STATUS_CANCELLED => __('已取消', 'aksrt'),
|
||||
self::ORDER_STATUS_EXPIRED => __('已过期', 'aksrt'),
|
||||
self::ORDER_STATUS_REFUNDING => __('退款中', 'aksrt'),
|
||||
self::ORDER_STATUS_REFUNDED => __('已退款', 'aksrt'),
|
||||
self::ORDER_STATUS_PENDING_REVIEW => __('待评价', 'aksrt'),
|
||||
self::ORDER_STATUS_CLOSED => __('已关闭', 'aksrt'),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -408,53 +398,30 @@ class DomainModel {
|
||||
*/
|
||||
public static function order_transitions(): array {
|
||||
return [
|
||||
self::ORDER_STATUS_CREATED => [
|
||||
self::ORDER_STATUS_PENDING,
|
||||
self::ORDER_STATUS_CANCELLED,
|
||||
],
|
||||
self::ORDER_STATUS_PENDING => [
|
||||
self::ORDER_STATUS_PAID,
|
||||
self::ORDER_STATUS_CANCELLED,
|
||||
self::ORDER_STATUS_EXPIRED,
|
||||
self::ORDER_STATUS_CLOSED,
|
||||
],
|
||||
self::ORDER_STATUS_PAID => [
|
||||
self::ORDER_STATUS_DELIVERED,
|
||||
self::ORDER_STATUS_COMPLETED,
|
||||
self::ORDER_STATUS_REFUNDING,
|
||||
],
|
||||
self::ORDER_STATUS_DELIVERED => [
|
||||
self::ORDER_STATUS_COMPLETED,
|
||||
self::ORDER_STATUS_PENDING_REVIEW,
|
||||
self::ORDER_STATUS_REFUNDING,
|
||||
],
|
||||
self::ORDER_STATUS_COMPLETED => [
|
||||
self::ORDER_STATUS_PENDING_REVIEW,
|
||||
self::ORDER_STATUS_REFUNDING,
|
||||
],
|
||||
self::ORDER_STATUS_CANCELLED => [],
|
||||
self::ORDER_STATUS_EXPIRED => [
|
||||
self::ORDER_STATUS_PENDING,
|
||||
],
|
||||
self::ORDER_STATUS_REFUNDING => [
|
||||
self::ORDER_STATUS_REFUNDED,
|
||||
self::ORDER_STATUS_PAID,
|
||||
],
|
||||
self::ORDER_STATUS_REFUNDED => [],
|
||||
self::ORDER_STATUS_PENDING_REVIEW => [
|
||||
self::ORDER_STATUS_COMPLETED,
|
||||
self::ORDER_STATUS_REFUNDING,
|
||||
],
|
||||
self::ORDER_STATUS_CLOSED => [],
|
||||
];
|
||||
}
|
||||
|
||||
public static function normalize_order_status(string $status, string $default = self::ORDER_STATUS_PENDING): string {
|
||||
public static function normalize_order_status(string $status): string {
|
||||
$status = sanitize_key($status);
|
||||
return array_key_exists($status, self::order_status_labels()) ? $status : $default;
|
||||
return array_key_exists($status, self::order_status_labels()) ? $status : '';
|
||||
}
|
||||
|
||||
public static function can_transition_order_status(string $from, string $to): bool {
|
||||
$from = self::normalize_order_status($from, self::ORDER_STATUS_CREATED);
|
||||
$to = self::normalize_order_status($to);
|
||||
$from = sanitize_key($from);
|
||||
$to = sanitize_key($to);
|
||||
$transitions = self::order_transitions();
|
||||
|
||||
return isset($transitions[$from]) && in_array($to, $transitions[$from], true);
|
||||
@@ -466,14 +433,11 @@ class DomainModel {
|
||||
public static function paid_order_statuses(): array {
|
||||
return [
|
||||
self::ORDER_STATUS_PAID,
|
||||
self::ORDER_STATUS_DELIVERED,
|
||||
self::ORDER_STATUS_COMPLETED,
|
||||
self::ORDER_STATUS_PENDING_REVIEW,
|
||||
];
|
||||
}
|
||||
|
||||
public static function is_paid_order_status(string $status): bool {
|
||||
return in_array(self::normalize_order_status($status), self::paid_order_statuses(), true);
|
||||
return in_array(sanitize_key($status), self::paid_order_statuses(), true);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user