| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- <?php
- namespace Database\Seeders;
- use Illuminate\Database\Seeder;
- use Illuminate\Support\Facades\DB;
- class PayOrdersSeeder extends Seeder
- {
- /**
- * Run the database seeds.
- *
- * @return void
- */
- public function run()
- {
- $time = time();
- $orders = [];
- // 获取用户ID(假设有一些测试用户)
- $userIds = DB::table('member')->where('mark', 1)->limit(10)->pluck('id')->toArray();
-
- if (empty($userIds)) {
- $this->command->warn('没有找到用户数据,请先添加用户!');
- return;
- }
- // 状态数组
- $statuses = [1, 2, 3, 4, 5, 6]; // 1-待付款,2-已付款,3-充值中,4-充值成功,5-充值失败,6-已退款
- // 生成话费充值订单(type=1)
- for ($i = 1; $i <= 20; $i++) {
- $money = [10, 20, 30, 50, 100, 200][array_rand([10, 20, 30, 50, 100, 200])];
- $discount = rand(94, 99);
- $payTotal = round($money * $discount / 100, 2);
-
- $orders[] = [
- 'order_no' => 'PHB' . date('Ymd') . str_pad($i, 4, '0', STR_PAD_LEFT),
- 'total' => $money,
- 'type' => 1,
- 'discount' => $discount,
- 'pay_total' => $payTotal,
- 'account' => '1' . rand(3, 9) . str_pad(rand(0, 999999999), 9, '0', STR_PAD_LEFT),
- 'transaction_id' => 'WX' . time() . rand(1000, 9999),
- 'meal_id' => rand(1, 8),
- 'product_id' => 1100 + rand(1, 8),
- 'out_trade_num' => 'OUT' . time() . rand(1000, 9999),
- 'remark' => '话费充值',
- 'create_time' => $time - rand(0, 86400 * 30),
- 'update_time' => $time - rand(0, 86400 * 30),
- 'status' => $statuses[array_rand($statuses)],
- 'mark' => 1
- ];
- }
- // 生成电费充值订单(type=2)
- for ($i = 1; $i <= 15; $i++) {
- $money = [100, 200, 300, 500, 1000][array_rand([100, 200, 300, 500, 1000])];
- $discount = rand(96, 99);
- $payTotal = round($money * $discount / 100, 2);
-
- $orders[] = [
- 'order_no' => 'ELB' . date('Ymd') . str_pad($i, 4, '0', STR_PAD_LEFT),
- 'total' => $money,
- 'type' => 2,
- 'discount' => $discount,
- 'pay_total' => $payTotal,
- 'account' => rand(100000000000, 999999999999),
- 'transaction_id' => 'WX' . time() . rand(1000, 9999),
- 'meal_id' => rand(9, 13),
- 'product_id' => 1040 + rand(0, 4),
- 'out_trade_num' => 'OUT' . time() . rand(1000, 9999),
- 'remark' => '电费充值',
- 'create_time' => $time - rand(0, 86400 * 30),
- 'update_time' => $time - rand(0, 86400 * 30),
- 'status' => $statuses[array_rand($statuses)],
- 'mark' => 1
- ];
- }
- // 生成燃气充值订单(type=3)
- for ($i = 1; $i <= 15; $i++) {
- $money = [100, 200, 300, 500, 1000][array_rand([100, 200, 300, 500, 1000])];
- $discount = rand(96, 99);
- $payTotal = round($money * $discount / 100, 2);
-
- $orders[] = [
- 'order_no' => 'GAS' . date('Ymd') . str_pad($i, 4, '0', STR_PAD_LEFT),
- 'total' => $money,
- 'type' => 3,
- 'discount' => $discount,
- 'pay_total' => $payTotal,
- 'account' => rand(100000000000, 999999999999),
- 'transaction_id' => 'WX' . time() . rand(1000, 9999),
- 'meal_id' => rand(14, 18),
- 'product_id' => 1458 + rand(0, 4),
- 'out_trade_num' => 'OUT' . time() . rand(1000, 9999),
- 'remark' => '燃气充值',
- 'create_time' => $time - rand(0, 86400 * 30),
- 'update_time' => $time - rand(0, 86400 * 30),
- 'status' => $statuses[array_rand($statuses)],
- 'mark' => 1
- ];
- }
- // 插入数据
- DB::table('pay_orders')->insert($orders);
- $this->command->info('充值缴费订单测试数据添加成功!');
- $this->command->info('- 话费充值订单:20 条');
- $this->command->info('- 电费充值订单:15 条');
- $this->command->info('- 燃气充值订单:15 条');
- $this->command->info('- 总计:' . count($orders) . ' 条');
- }
- }
|