小程序接口

This commit is contained in:
liu
2026-08-14 18:02:32 +08:00
parent 969eabcd11
commit 9a0999742f
7 changed files with 434 additions and 188 deletions
+62
View File
@@ -130,6 +130,68 @@ class StoreOrderTest extends ProcurementTestCase
$this->getJson('/mini/order')->assertJsonPath('data.total', 0);
}
/** 列表输出:状态名 / 可取消标记 / 商品预览(前 3 条)与明细种数 */
public function test_order_list_outputs_status_name_and_item_preview(): void
{
$level = CustomerLevelModel::factory()->create();
$store = StoreModel::factory()->create(['level_id' => $level->id]);
$this->actingAsMiniUser(UserModel::factory()->forStore($store->id)->create());
$items = [];
foreach (['白菜', '土豆', '番茄', '黄瓜'] as $name) {
$product = ProductModel::factory()->create(['name' => $name, 'status' => ProductModel::STATUS_ON]);
ProductPriceModel::factory()->create(['product_id' => $product->id, 'level_id' => $level->id, 'price' => 5.00]);
$items[] = ['product_id' => $product->id, 'quantity' => 2];
}
$this->postJson('/mini/order', ['items' => $items])->assertJsonPath('success', true);
$order = StoreOrderModel::where('store_id', $store->id)->first();
$row = collect($this->getJson('/mini/order')->assertOk()->json('data.data'))->firstWhere('id', $order->id);
$this->assertSame('待接单', $row['status_name']);
$this->assertTrue($row['can_cancel']);
$this->assertSame(4, $row['item_count']);
$this->assertCount(3, $row['items'], '预览仅输出前 3 条明细,完整明细走详情接口');
$this->assertSame('白菜', $row['items'][0]['product_name']);
$this->assertSame(2, $row['items'][0]['quantity']);
// 已接单后状态名变化且不可取消
$order->update(['status' => StoreOrderModel::STATUS_SUMMARIZED]);
$row = collect($this->getJson('/mini/order')->json('data.data'))->firstWhere('id', $order->id);
$this->assertSame('已接单', $row['status_name']);
$this->assertFalse($row['can_cancel']);
}
/** 订货日期区间筛选(配合 /order/summary 周期下钻) */
public function test_order_list_filters_by_order_date_range(): void
{
[$store, $product, $user] = $this->makeStoreWithProduct();
$this->actingAsMiniUser($user);
foreach ([1, 1, 1] as $qty) {
$this->postJson('/mini/order', ['items' => [['product_id' => $product->id, 'quantity' => $qty]]])
->assertJsonPath('success', true);
}
$orders = StoreOrderModel::where('store_id', $store->id)->orderBy('id')->get();
$orders[0]->update(['order_date' => '2026-08-01']);
$orders[1]->update(['order_date' => '2026-08-05']);
$orders[2]->update(['order_date' => '2026-08-10']);
$this->getJson('/mini/order?start_date=2026-08-03')->assertJsonPath('data.total', 2);
$this->getJson('/mini/order?start_date=2026-08-03&end_date=2026-08-06')->assertJsonPath('data.total', 1);
$this->getJson('/mini/order?end_date=2026-08-06')->assertJsonPath('data.total', 2);
}
/** 非法筛选参数被拦截(状态枚举 / 分页上限 / 日期区间倒置) */
public function test_order_list_rejects_invalid_filters(): void
{
[, , $user] = $this->makeStoreWithProduct();
$this->actingAsMiniUser($user);
$this->getJson('/mini/order?status=7')->assertJsonPath('success', false);
$this->getJson('/mini/order?pageSize=100')->assertJsonPath('success', false);
$this->getJson('/mini/order?start_date=2026-08-10&end_date=2026-08-01')->assertJsonPath('success', false);
}
/** 造一笔指定状态的订单(商品 5.00 × 2 = 10.00 */
private function makeOrderWithStatus(int $status): StoreOrderModel
{