feat(admin): batch activate from subscription show
This commit is contained in:
@@ -75,6 +75,22 @@
|
|||||||
<a href="/admin/platform-orders?site_subscription_id={{ $subscription->id }}&syncable_only=1" class="muted">查看可同步订单</a>
|
<a href="/admin/platform-orders?site_subscription_id={{ $subscription->id }}&syncable_only=1" class="muted">查看可同步订单</a>
|
||||||
@endif
|
@endif
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="mt-10">
|
||||||
|
<form method="post" action="/admin/platform-orders/batch-activate-subscriptions" onsubmit="return confirm('确认批量同步该订阅下“可同步”的订单?(仅处理:已支付+已生效+未同步)');">
|
||||||
|
@csrf
|
||||||
|
<input type="hidden" name="scope" value="filtered">
|
||||||
|
<input type="hidden" name="site_subscription_id" value="{{ $subscription->id }}">
|
||||||
|
<input type="hidden" name="syncable_only" value="1">
|
||||||
|
<label class="muted form-inline-row mb-8">
|
||||||
|
<span>本次最多处理</span>
|
||||||
|
<input type="number" name="limit" value="50" min="1" max="500" class="w-90">
|
||||||
|
<span>条(安全阀)</span>
|
||||||
|
</label>
|
||||||
|
<button type="submit">批量同步该订阅下可同步订单</button>
|
||||||
|
</form>
|
||||||
|
<div class="muted muted-xs mt-6">说明:该按钮等价于平台订单页的“批量同步订阅(当前筛选范围)”,已内置只处理可同步订单(已支付+已生效+未同步)。</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="grid-4 mb-20">
|
<div class="grid-4 mb-20">
|
||||||
|
|||||||
118
tests/Feature/AdminSiteSubscriptionBatchActivateFromShowTest.php
Normal file
118
tests/Feature/AdminSiteSubscriptionBatchActivateFromShowTest.php
Normal file
@@ -0,0 +1,118 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Feature;
|
||||||
|
|
||||||
|
use App\Models\Merchant;
|
||||||
|
use App\Models\Plan;
|
||||||
|
use App\Models\PlatformOrder;
|
||||||
|
use App\Models\SiteSubscription;
|
||||||
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
class AdminSiteSubscriptionBatchActivateFromShowTest extends TestCase
|
||||||
|
{
|
||||||
|
use RefreshDatabase;
|
||||||
|
|
||||||
|
protected function loginAsPlatformAdmin(): void
|
||||||
|
{
|
||||||
|
$this->seed();
|
||||||
|
|
||||||
|
$this->post('/admin/login', [
|
||||||
|
'email' => 'platform.admin@demo.local',
|
||||||
|
'password' => 'Platform@123456',
|
||||||
|
])->assertRedirect('/admin');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_platform_admin_can_batch_activate_syncable_orders_from_subscription_show_page(): void
|
||||||
|
{
|
||||||
|
$this->loginAsPlatformAdmin();
|
||||||
|
|
||||||
|
$merchant = Merchant::query()->firstOrFail();
|
||||||
|
$plan = Plan::query()->create([
|
||||||
|
'code' => 'sub_show_batch_sync',
|
||||||
|
'name' => '订阅详情页批量同步测试套餐',
|
||||||
|
'billing_cycle' => 'monthly',
|
||||||
|
'price' => 10,
|
||||||
|
'list_price' => 10,
|
||||||
|
'status' => 'active',
|
||||||
|
'sort' => 10,
|
||||||
|
'published_at' => now(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
$sub = SiteSubscription::query()->create([
|
||||||
|
'merchant_id' => $merchant->id,
|
||||||
|
'plan_id' => $plan->id,
|
||||||
|
'status' => 'activated',
|
||||||
|
'source' => 'manual',
|
||||||
|
'subscription_no' => 'SUB_BATCH_SHOW_0001',
|
||||||
|
'plan_name' => $plan->name,
|
||||||
|
'billing_cycle' => $plan->billing_cycle,
|
||||||
|
'period_months' => 1,
|
||||||
|
'amount' => 10,
|
||||||
|
'starts_at' => now()->subDay(),
|
||||||
|
'ends_at' => now()->addMonth(),
|
||||||
|
'activated_at' => now()->subDay(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
// 订单A:可同步(已支付+已生效+未同步)
|
||||||
|
$o1 = PlatformOrder::query()->create([
|
||||||
|
'merchant_id' => $merchant->id,
|
||||||
|
'plan_id' => $plan->id,
|
||||||
|
'site_subscription_id' => $sub->id,
|
||||||
|
'created_by_admin_id' => 1,
|
||||||
|
'order_no' => 'PO_SUB_BATCH_0001',
|
||||||
|
'order_type' => 'renewal',
|
||||||
|
'status' => 'activated',
|
||||||
|
'payment_status' => 'paid',
|
||||||
|
'plan_name' => $plan->name,
|
||||||
|
'billing_cycle' => $plan->billing_cycle,
|
||||||
|
'period_months' => 1,
|
||||||
|
'quantity' => 1,
|
||||||
|
'payable_amount' => 10,
|
||||||
|
'paid_amount' => 10,
|
||||||
|
'placed_at' => now()->subMinutes(5),
|
||||||
|
'paid_at' => now()->subMinutes(4),
|
||||||
|
'activated_at' => now()->subMinutes(3),
|
||||||
|
]);
|
||||||
|
|
||||||
|
// 订单B:同订阅但不可同步(未支付)
|
||||||
|
PlatformOrder::query()->create([
|
||||||
|
'merchant_id' => $merchant->id,
|
||||||
|
'plan_id' => $plan->id,
|
||||||
|
'site_subscription_id' => $sub->id,
|
||||||
|
'created_by_admin_id' => 1,
|
||||||
|
'order_no' => 'PO_SUB_BATCH_0002',
|
||||||
|
'order_type' => 'renewal',
|
||||||
|
'status' => 'pending',
|
||||||
|
'payment_status' => 'unpaid',
|
||||||
|
'plan_name' => $plan->name,
|
||||||
|
'billing_cycle' => $plan->billing_cycle,
|
||||||
|
'period_months' => 1,
|
||||||
|
'quantity' => 1,
|
||||||
|
'payable_amount' => 10,
|
||||||
|
'paid_amount' => 0,
|
||||||
|
'placed_at' => now()->subMinutes(2),
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->post('/admin/platform-orders/batch-activate-subscriptions', [
|
||||||
|
'scope' => 'filtered',
|
||||||
|
'site_subscription_id' => (string) $sub->id,
|
||||||
|
'syncable_only' => '1',
|
||||||
|
'limit' => 50,
|
||||||
|
])->assertRedirect();
|
||||||
|
|
||||||
|
$o1->refresh();
|
||||||
|
$this->assertNotNull(data_get($o1->meta, 'subscription_activation.subscription_id'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_guest_cannot_batch_activate_from_subscription_show_page(): void
|
||||||
|
{
|
||||||
|
$this->seed();
|
||||||
|
|
||||||
|
$this->post('/admin/platform-orders/batch-activate-subscriptions', [
|
||||||
|
'scope' => 'filtered',
|
||||||
|
'syncable_only' => '1',
|
||||||
|
'limit' => 10,
|
||||||
|
])->assertRedirect('/admin/login');
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user