*/ class StoreOrderItemModelFactory extends Factory { protected $model = StoreOrderItemModel::class; public function definition(): array { return [ 'order_id' => 0, 'store_id' => 0, 'product_id' => 0, 'product_name' => '测试商品', 'product_spec' => '500g/袋', 'price' => number_format(random_int(100, 5000) / 100, 2, '.', ''), 'quantity' => number_format(random_int(100, 10000) / 100, 2, '.', ''), 'weight' => 0, 'amount' => 0, 'remark' => '', ]; } public function configure(): static { return $this->afterMaking(function (StoreOrderItemModel $item): void { if ((float) $item->amount === 0.0 && (float) $item->price > 0 && (float) $item->quantity > 0) { $item->amount = bcmul((string) $item->price, (string) $item->quantity, 2); } }); } }