TestInsertBigDataDepositCommand.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. namespace App\Console\Commands;
  3. use App\Models\DepositOrder;
  4. use App\Models\RefundLog;
  5. use App\Models\User;
  6. use Carbon\Carbon;
  7. use Illuminate\Console\Command;
  8. use Illuminate\Support\Facades\DB;
  9. use Illuminate\Support\Facades\Log;
  10. class TestInsertBigDataDepositCommand extends Command
  11. {
  12. /**
  13. * The name and signature of the console command.
  14. *
  15. * @var string
  16. */
  17. protected $signature = 'test:insert_big_data_deposit';
  18. /**
  19. * The console command description.
  20. *
  21. * @var string
  22. */
  23. protected $description = '测试押金记录增加';
  24. /**
  25. * Create a new command instance.
  26. *
  27. * @return void
  28. */
  29. public function __construct()
  30. {
  31. parent::__construct();
  32. }
  33. /**
  34. * Execute the console command.
  35. *
  36. * @return mixed
  37. */
  38. public function handle()
  39. {
  40. //
  41. // $deposit_orders = DepositOrder::query()->find(59)->toArray();
  42. $users = User::query()->whereBetween('id',[30020,40020])->get(['id']);
  43. // Log::info($users);
  44. $bar = $this->output->createProgressBar(count($users));
  45. $bar->start();
  46. // $datas = [];
  47. foreach ($users as $v){
  48. $rand = mt_rand(1,10);
  49. for ($rand;$rand>0;$rand--){
  50. $data = [
  51. 'user_id' => $v->id,
  52. 'no' => DepositOrder::makeNo(),
  53. 'money' => '59.00',
  54. 'type' => 0,
  55. 'area_id' => 1,
  56. 'pay_type' => 1,
  57. 'pay_money' => '59.00',
  58. 'pay_status' => 1,
  59. 'pay_time' => Carbon::now()->subDays(mt_rand(1,100))->subHours(mt_rand(1,24))->subMinutes(mt_rand(1,60))->format('Y-m-d H:i:s'),
  60. 'is_refund' => 1,
  61. 'status' => 1,
  62. ];
  63. $datas[] = $data;
  64. }
  65. if(count($datas) >=1000){
  66. DB::table('deposit_orders')->insert($datas);
  67. $datas = [];
  68. }
  69. $bar->advance();
  70. }
  71. $bar->finish();
  72. }
  73. }