您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

DiscountFactory.php 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. namespace Database\Factories\Setting;
  3. use App\Enums\Setting\DiscountComputation;
  4. use App\Enums\Setting\DiscountScope;
  5. use App\Enums\Setting\DiscountType;
  6. use App\Models\Setting\Discount;
  7. use Illuminate\Database\Eloquent\Factories\Factory;
  8. /**
  9. * @extends Factory<Discount>
  10. */
  11. class DiscountFactory extends Factory
  12. {
  13. /**
  14. * The name of the factory's corresponding model.
  15. */
  16. protected $model = Discount::class;
  17. /**
  18. * Define the model's default state.
  19. *
  20. * @return array<string, mixed>
  21. */
  22. public function definition(): array
  23. {
  24. $startDate = $this->faker->dateTimeBetween('now', '+1 year');
  25. $endDate = $this->faker->dateTimeBetween($startDate, strtotime('+1 year'));
  26. return [
  27. 'description' => $this->faker->sentence,
  28. 'rate' => $this->faker->biasedNumberBetween(300, 5000) * 100, // 3% - 50%
  29. 'computation' => $this->faker->randomElement(DiscountComputation::class),
  30. 'scope' => $this->faker->randomElement(DiscountScope::class),
  31. 'start_date' => $startDate,
  32. 'end_date' => $endDate,
  33. 'enabled' => true,
  34. ];
  35. }
  36. public function salesDiscount(): self
  37. {
  38. return $this->state([
  39. 'name' => 'Summer Sale',
  40. 'rate' => $this->faker->biasedNumberBetween(300, 1200) * 100, // 3% - 12%
  41. 'type' => DiscountType::Sales,
  42. ]);
  43. }
  44. public function purchaseDiscount(): self
  45. {
  46. return $this->state([
  47. 'name' => 'Bulk Purchase',
  48. 'rate' => $this->faker->biasedNumberBetween(300, 1200) * 100, // 3% - 12%
  49. 'type' => DiscountType::Purchase,
  50. ]);
  51. }
  52. }