DataSeeder.php 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. <?php
  2. namespace App\Console\Commands;
  3. use App\Model\AccountInfo;
  4. use App\Model\BaseArea;
  5. use App\Model\WithdrawInfo;
  6. use App\Model\DeliverInfo;
  7. use App\Model\DeviceInfo;
  8. use App\Model\RechargeInfo;
  9. use App\Model\TransportInfo;
  10. use App\Model\UserInfo;
  11. use Illuminate\Console\Command;
  12. /**
  13. * 数据填充器
  14. * Class DataSeeder.
  15. */
  16. class DataSeeder extends Command
  17. {
  18. /**
  19. * The name and signature of the console command.
  20. *
  21. * @var string
  22. */
  23. protected $signature = 'data:seeder';
  24. /**
  25. * The console command description.
  26. *
  27. * @var string
  28. */
  29. protected $description = 'Command description';
  30. /**
  31. * Create a new command instance.
  32. *
  33. * @return void
  34. */
  35. public function __construct()
  36. {
  37. parent::__construct();
  38. }
  39. /**
  40. * Execute the console command.
  41. */
  42. public function handle()
  43. {
  44. // 用户表数据填充300条
  45. $faker_zh = \Faker\Factory::create('zh_CN');
  46. $faker_en = \Faker\Factory::create();
  47. $cities = BaseArea::where('pid', '510117')->with(['communities' => function ($query) {
  48. $query->select(['area_id', 'id']);
  49. }])->get(['id'])->toArray();
  50. $area_ids = [];
  51. $communities_ids = [];
  52. $city_max = 0;
  53. $com_max = 0;
  54. foreach ($cities as $city) {
  55. $area_ids[] = $city['id'];
  56. $city_max++;
  57. foreach ($city['communities'] as $community) {
  58. $communities_ids[] = $community['id'];
  59. $com_max++;
  60. }
  61. }
  62. $us = UserInfo::all(['id', 'role'])->toArray();
  63. $user_common = [];
  64. $user_agent = [];
  65. $user_agent_user = [];
  66. foreach ($us as $u) {
  67. if (UserInfo::Role_Common == $u['role']) {
  68. $user_common[] = $u['id'];
  69. }
  70. if (UserInfo::Role_Agent == $u['role']) {
  71. $user_agent[] = $u['id'];
  72. }
  73. if (UserInfo::Role_Agent_User == $u['role']) {
  74. $user_agent_user[] = $u['id'];
  75. }
  76. }
  77. $us = DeviceInfo::all(['id'])->toArray();
  78. $device_ids = [];
  79. $device_max = 0;
  80. foreach ($us as $u) {
  81. $device_max++;
  82. $device_ids[] = $u['id'];
  83. }
  84. for ($i = 0; $i < 2000; $i++) {
  85. echo "第{$i}个投放记录开始创建\r\n";
  86. $tempRow = [];
  87. $tempRow['device_id'] = $device_ids[rand(0, $device_max - 1)];
  88. $tempRow['user_id'] = $user_common[rand(0, count($user_common) - 1)];
  89. $tempRow['no'] = strtoupper(uniqid());
  90. $tempRow['weight'] = rand(1, 99999);
  91. $tempRow['money'] = rand(0, 1000);
  92. $tempRow['finished_at'] = date('Y-m-d H:i:s');
  93. $tempRow['status'] = rand(1, 3);
  94. $tempRow['created_at'] = date('Y-m-d H:i:s', strtotime('-' . rand(1, 365) . ' days'));
  95. DeliverInfo::create($tempRow);
  96. }
  97. for ($i = 0; $i < 2000; $i++) {
  98. echo "第{$i}个收运记录开始创建\r\n";
  99. $tempRow = [];
  100. $tempRow['device_id'] = $device_ids[rand(0, $device_max - 1)];
  101. $tempRow['user_id'] = $user_agent_user[rand(0, count($user_agent_user) - 1)];
  102. $tempRow['no'] = strtoupper(uniqid());
  103. $tempRow['weight'] = rand(1, 999999);
  104. $tempRow['money'] = rand(0, 1000);
  105. $tempRow['created_at'] = date('Y-m-d H:i:s', strtotime('-' . rand(1, 365) . ' days'));
  106. $tempRow['status'] = rand(1, 2);
  107. TransportInfo::create($tempRow);
  108. }
  109. $banks = [
  110. '渤海银行',
  111. '广发银行',
  112. '国家开发银行',
  113. '恒丰银行',
  114. '华夏银行',
  115. '交通银行',
  116. '平安银行',
  117. '上海浦东发展银行',
  118. '兴业银行',
  119. '招商银行',
  120. '浙商银行',
  121. '中国工商银行',
  122. '中国光大银行',
  123. '中国建设银行',
  124. '中国民生银行',
  125. '中国农业银行',
  126. '中国银行',
  127. '中国邮政储蓄银行',
  128. '中信银行',
  129. ];
  130. for ($i = 0; $i < 2000; $i++) {
  131. echo "第{$i}个提现记录开始创建\r\n";
  132. $tempRow = [];
  133. $tempRow['user_id'] = $user_common[rand(0, count($user_common) - 1)];
  134. $tempRow['order_no'] = strtoupper(uniqid());
  135. $tempRow['money'] = rand(0, 3000);
  136. $tempRow['poundage'] = rand(0, 200);
  137. $tempRow['pay_money'] = $tempRow['money'] - $tempRow['poundage'];
  138. $tempRow['paid_at'] = date('Y-m-d H:i:s');
  139. $tempRow['bank_card'] = $faker_zh->phoneNumber;
  140. $tempRow['bank_name'] = $banks[rand(0, count($banks) - 1)];
  141. $tempRow['name'] = $faker_zh->name;
  142. $tempRow['mobile'] = $faker_zh->phoneNumber;
  143. $tempRow['ali_account'] = $faker_zh->phoneNumber;
  144. $tempRow['ali_name'] = $faker_zh->name;
  145. $tempRow['status'] = rand(0, 1);
  146. $tempRow['type'] = rand(0, 2);
  147. $tempRow['created_at'] = date('Y-m-d H:i:s', strtotime('-' . rand(1, 365) . ' days'));
  148. $tempRow['reason'] = $faker_en->company;
  149. WithdrawInfo::create($tempRow);
  150. }
  151. for ($i = 0; $i < 2000; $i++) {
  152. echo "第{$i}个充值记录开始创建\r\n";
  153. $tempRow = [];
  154. $tempRow['user_id'] = $user_common[rand(0, count($user_common) - 1)];
  155. $tempRow['order_no'] = strtoupper(uniqid());
  156. $tempRow['money'] = rand(0, 1000);
  157. $tempRow['type'] = rand(0, 1);
  158. $tempRow['created_at'] = date('Y-m-d H:i:s', strtotime('-' . rand(1, 365) . ' days'));
  159. $tempRow['finished_at'] = date('Y-m-d H:i:s', strtotime('-' . rand(1, 365) . ' days'));
  160. $tempRow['status'] = rand(0, 1);
  161. RechargeInfo::create($tempRow);
  162. }
  163. for ($i = 0; $i < 2000; $i++) {
  164. echo "第{$i}个余额记录开始创建\r\n";
  165. $tempRow = [];
  166. $tempRow['user_id'] = $user_common[rand(0, count($user_common) - 1)];
  167. $tempRow['method'] = rand(1, 6);
  168. $s = [-1, 1];
  169. $tempRow['admin_id'] = $s[rand(0, 1)];
  170. $tempRow['balance'] = rand(10, 1000);
  171. $tempRow['money'] = rand(10, 1000);
  172. $tempRow['detail'] = $faker_en->text;
  173. AccountInfo::create($tempRow);
  174. }
  175. }
  176. }