YzStreetSeeder.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * Author: 芸众商城 www.yunzshop.com
  5. * Date: 2017/3/9
  6. * Time: 上午9:54
  7. */
  8. use Illuminate\Database\Seeder;
  9. //use Illuminate\Database\Schema\Blueprint;
  10. class YzStreetSeeder extends Seeder
  11. {
  12. protected $oldTable = 'sz_yi_street';
  13. protected $newTable = 'yz_street';
  14. public function run()
  15. {
  16. return;
  17. if (!Schema::hasTable($this->oldTable)) {
  18. echo $this->oldTable." 不存在 跳过\n";
  19. return;
  20. }
  21. $newList = \Illuminate\Support\Facades\DB::table($this->newTable)->get();
  22. if($newList->isNotEmpty()){
  23. echo "yz_street 已经有数据了跳过\n";
  24. return ;
  25. }
  26. $list = \Illuminate\Support\Facades\DB::table($this->oldTable)->get();
  27. if($list) {
  28. foreach ($list as $v) {
  29. \Illuminate\Support\Facades\DB::table($this->newTable)->insert([
  30. 'id'=>$v['id'],
  31. 'areaname'=>$v['areaname'],
  32. 'parentid'=>$v['parentid'],
  33. 'level'=>$v['level']
  34. ]);
  35. }
  36. }
  37. }
  38. }