PayOrdersSeeder.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <?php
  2. namespace Database\Seeders;
  3. use Illuminate\Database\Seeder;
  4. use Illuminate\Support\Facades\DB;
  5. class PayOrdersSeeder extends Seeder
  6. {
  7. /**
  8. * Run the database seeds.
  9. *
  10. * @return void
  11. */
  12. public function run()
  13. {
  14. $time = time();
  15. $orders = [];
  16. // 获取用户ID(假设有一些测试用户)
  17. $userIds = DB::table('member')->where('mark', 1)->limit(10)->pluck('id')->toArray();
  18. if (empty($userIds)) {
  19. $this->command->warn('没有找到用户数据,请先添加用户!');
  20. return;
  21. }
  22. // 状态数组
  23. $statuses = [1, 2, 3, 4, 5, 6]; // 1-待付款,2-已付款,3-充值中,4-充值成功,5-充值失败,6-已退款
  24. // 生成话费充值订单(type=1)
  25. for ($i = 1; $i <= 20; $i++) {
  26. $money = [10, 20, 30, 50, 100, 200][array_rand([10, 20, 30, 50, 100, 200])];
  27. $discount = rand(94, 99);
  28. $payTotal = round($money * $discount / 100, 2);
  29. $orders[] = [
  30. 'order_no' => 'PHB' . date('Ymd') . str_pad($i, 4, '0', STR_PAD_LEFT),
  31. 'total' => $money,
  32. 'type' => 1,
  33. 'discount' => $discount,
  34. 'pay_total' => $payTotal,
  35. 'account' => '1' . rand(3, 9) . str_pad(rand(0, 999999999), 9, '0', STR_PAD_LEFT),
  36. 'transaction_id' => 'WX' . time() . rand(1000, 9999),
  37. 'meal_id' => rand(1, 8),
  38. 'product_id' => 1100 + rand(1, 8),
  39. 'out_trade_num' => 'OUT' . time() . rand(1000, 9999),
  40. 'remark' => '话费充值',
  41. 'create_time' => $time - rand(0, 86400 * 30),
  42. 'update_time' => $time - rand(0, 86400 * 30),
  43. 'status' => $statuses[array_rand($statuses)],
  44. 'mark' => 1
  45. ];
  46. }
  47. // 生成电费充值订单(type=2)
  48. for ($i = 1; $i <= 15; $i++) {
  49. $money = [100, 200, 300, 500, 1000][array_rand([100, 200, 300, 500, 1000])];
  50. $discount = rand(96, 99);
  51. $payTotal = round($money * $discount / 100, 2);
  52. $orders[] = [
  53. 'order_no' => 'ELB' . date('Ymd') . str_pad($i, 4, '0', STR_PAD_LEFT),
  54. 'total' => $money,
  55. 'type' => 2,
  56. 'discount' => $discount,
  57. 'pay_total' => $payTotal,
  58. 'account' => rand(100000000000, 999999999999),
  59. 'transaction_id' => 'WX' . time() . rand(1000, 9999),
  60. 'meal_id' => rand(9, 13),
  61. 'product_id' => 1040 + rand(0, 4),
  62. 'out_trade_num' => 'OUT' . time() . rand(1000, 9999),
  63. 'remark' => '电费充值',
  64. 'create_time' => $time - rand(0, 86400 * 30),
  65. 'update_time' => $time - rand(0, 86400 * 30),
  66. 'status' => $statuses[array_rand($statuses)],
  67. 'mark' => 1
  68. ];
  69. }
  70. // 生成燃气充值订单(type=3)
  71. for ($i = 1; $i <= 15; $i++) {
  72. $money = [100, 200, 300, 500, 1000][array_rand([100, 200, 300, 500, 1000])];
  73. $discount = rand(96, 99);
  74. $payTotal = round($money * $discount / 100, 2);
  75. $orders[] = [
  76. 'order_no' => 'GAS' . date('Ymd') . str_pad($i, 4, '0', STR_PAD_LEFT),
  77. 'total' => $money,
  78. 'type' => 3,
  79. 'discount' => $discount,
  80. 'pay_total' => $payTotal,
  81. 'account' => rand(100000000000, 999999999999),
  82. 'transaction_id' => 'WX' . time() . rand(1000, 9999),
  83. 'meal_id' => rand(14, 18),
  84. 'product_id' => 1458 + rand(0, 4),
  85. 'out_trade_num' => 'OUT' . time() . rand(1000, 9999),
  86. 'remark' => '燃气充值',
  87. 'create_time' => $time - rand(0, 86400 * 30),
  88. 'update_time' => $time - rand(0, 86400 * 30),
  89. 'status' => $statuses[array_rand($statuses)],
  90. 'mark' => 1
  91. ];
  92. }
  93. // 插入数据
  94. DB::table('pay_orders')->insert($orders);
  95. $this->command->info('充值缴费订单测试数据添加成功!');
  96. $this->command->info('- 话费充值订单:20 条');
  97. $this->command->info('- 电费充值订单:15 条');
  98. $this->command->info('- 燃气充值订单:15 条');
  99. $this->command->info('- 总计:' . count($orders) . ' 条');
  100. }
  101. }