购物车悬浮

This commit is contained in:
liu
2026-08-27 18:13:43 +08:00
parent 52dc6efadf
commit f3e190f460
9 changed files with 330 additions and 6 deletions
+73
View File
@@ -2,8 +2,10 @@
namespace Tests\Feature;
use App\Models\BillModel;
use App\Models\CustomerLevelModel;
use App\Models\ProductModel;
use App\Models\PurchaseOrderModel;
use App\Models\StoreModel;
use App\Models\StoreOrderModel;
use Modules\SystemTool\Models\SysFileModel;
@@ -112,6 +114,77 @@ class StoreOrderTest extends ProcurementTestCase
$this->assertSame(StoreOrderModel::STATUS_SUMMARIZED, $order->refresh()->status);
}
/** 造一笔指定账单日期/状态的门店账单(默认总额 100.00 未支付) */
private function makeStoreBill(StoreModel $store, string $billDate, array $attributes = []): BillModel
{
return BillModel::create(array_merge([
'bill_no' => 'ZD' . random_int(100000000000, 999999999999),
'purchase_id' => PurchaseOrderModel::factory()->create()->id,
'store_id' => $store->id,
'bill_date' => $billDate,
'total_amount' => '100.00',
'status' => BillModel::STATUS_UNPAID,
], $attributes));
}
/** 回款周期校验:存在逾期未回款账单(含审核中)时禁止下单,结清后恢复 */
public function test_place_order_blocked_by_overdue_unpaid_bill(): void
{
$level = CustomerLevelModel::factory()->create();
$store = StoreModel::factory()->paymentCycle(7)->create(['level_id' => $level->id]);
$product = ProductModel::factory()->create(['status' => ProductModel::STATUS_ON, 'cost_price' => '5.00']);
// 账单日 10 天前(应结算日=3 天前,已逾期)且未支付 → 拒绝
$this->makeStoreBill($store, now()->subDays(10)->toDateString());
$this->actingAsMiniStore($store);
$response = $this->postJson('/mini/order', ['items' => [['product_id' => $product->id, 'quantity' => 1]]]);
$response->assertOk()->assertJsonPath('success', false);
$this->assertStringContainsString('已超过回款周期未回款', (string) $response->json('msg'));
$this->assertStringContainsString('¥100.00', (string) $response->json('msg'));
$this->assertSame(0, StoreOrderModel::count(), '拦截时不应生成订单');
// 审核中(已提交付款凭证)同样拦截
$this->makeStoreBill($store, now()->subDays(10)->toDateString(), ['payment_id' => 999]);
$blocked = $this->postJson('/mini/order', ['items' => [['product_id' => $product->id, 'quantity' => 1]]]);
$blocked->assertJsonPath('success', false);
$this->assertStringContainsString('2 笔', (string) $blocked->json('msg'));
// 全部结清后恢复下单
BillModel::where('store_id', $store->id)->update(['status' => BillModel::STATUS_PAID]);
$this->postJson('/mini/order', ['items' => [['product_id' => $product->id, 'quantity' => 1]]])
->assertJsonPath('success', true);
}
/** 回款周期校验:周期内账单与到期日当天均不拦截;回款周期 0 天=任何未回款账单(含当天)都拦截 */
public function test_place_order_allowed_within_payment_cycle(): void
{
$level = CustomerLevelModel::factory()->create();
$store = StoreModel::factory()->paymentCycle(7)->create(['level_id' => $level->id]);
$product = ProductModel::factory()->create(['status' => ProductModel::STATUS_ON, 'cost_price' => '5.00']);
$this->actingAsMiniStore($store);
// 账单日 7 天前 → 应结算日=今天,尚未超过周期,允许下单
$this->makeStoreBill($store, now()->subDays(7)->toDateString());
$this->postJson('/mini/order', ['items' => [['product_id' => $product->id, 'quantity' => 1]]])
->assertJsonPath('success', true);
// 回款周期 0 天:昨天的未回款账单拦截;当天的未回款账单同样拦截(立即结清口径)
$store->update(['payment_cycle_days' => 0]);
$this->makeStoreBill($store, now()->subDays(1)->toDateString());
$this->postJson('/mini/order', ['items' => [['product_id' => $product->id, 'quantity' => 1]]])
->assertJsonPath('success', false);
BillModel::where('store_id', $store->id)->delete();
$this->makeStoreBill($store, now()->toDateString());
$response = $this->postJson('/mini/order', ['items' => [['product_id' => $product->id, 'quantity' => 1]]]);
$response->assertJsonPath('success', false);
$this->assertStringContainsString('当日结清', (string) $response->json('msg'));
// 0 天周期下无未回款账单 → 正常下单
BillModel::where('store_id', $store->id)->update(['status' => BillModel::STATUS_PAID]);
$this->postJson('/mini/order', ['items' => [['product_id' => $product->id, 'quantity' => 1]]])
->assertJsonPath('success', true);
}
/** 门店数据隔离:只能查看本店订单 */
public function test_order_data_isolated_between_stores(): void
{