52 lines
1.7 KiB
PHP
52 lines
1.7 KiB
PHP
<?php
|
|
namespace Database\Seeders;
|
|
|
|
use Illuminate\Database\Seeder;
|
|
use App\Models\Order;
|
|
use App\Models\OrderItem;
|
|
use App\Models\Stock;
|
|
|
|
class TestOrdersSeeder extends Seeder
|
|
{
|
|
public function run()
|
|
{
|
|
// 确保库存存在
|
|
$stock = Stock::firstOrCreate(
|
|
['sku_code' => 'SKU001', 'warehouse_id' => 1],
|
|
['quantity' => 100, 'locked_quantity' => 0, 'defective_quantity' => 0]
|
|
);
|
|
$stock->locked_quantity = 10;
|
|
$stock->save();
|
|
|
|
for ($i = 1; $i <= 10; $i++) {
|
|
$shortId = 'TEST' . date('Ymd') . str_pad($i, 4, '0', STR_PAD_LEFT);
|
|
$order = Order::create([
|
|
'short_id' => $shortId,
|
|
'platform_order_sn' => 'PLAT_' . time() . '_' . $i,
|
|
'platform' => 'taobao',
|
|
'shop_id' => 1,
|
|
'shop_name' => '测试店铺',
|
|
'order_time' => now(),
|
|
'receiver_name' => "测试用户{$i}",
|
|
'receiver_phone' => "1380000000{$i}",
|
|
'receiver_address' => "测试地址{$i}",
|
|
'goods_amount' => 100,
|
|
'total_amount' => 100,
|
|
'order_status' => 'auditing',
|
|
'platform_status' => 'WAIT_SELLER_SEND_GOODS',
|
|
'audit_status' => 'approved',
|
|
'delivery_status' => 'pending',
|
|
'warehouse_id' => 1,
|
|
]);
|
|
|
|
$order->items()->create([
|
|
'goods_name' => '测试商品',
|
|
'platform_sku' => 'SKU001',
|
|
'quantity' => 1,
|
|
'price' => 100,
|
|
'total_amount' => 100,
|
|
'erp_sku_id' => 1,
|
|
]);
|
|
}
|
|
}
|
|
} |