DataSeeder.php 6.5 KB

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