YzAddressSeeder.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. class YzAddressSeeder extends Seeder
  10. {
  11. protected $oldTable = 'sz_yi_address';
  12. protected $newTable = 'yz_address';
  13. public function run()
  14. {
  15. if (!Schema::hasTable($this->oldTable)) {
  16. echo $this->oldTable." 不存在 跳过\n";
  17. return;
  18. }
  19. $newList = \Illuminate\Support\Facades\DB::table($this->newTable)->get();
  20. if($newList->isNotEmpty()){
  21. echo "yz_address 已经有数据了跳过\n";
  22. return ;
  23. }
  24. $list = \Illuminate\Support\Facades\DB::table($this->oldTable)->get();
  25. if($list) {
  26. foreach ($list as $v) {
  27. \Illuminate\Support\Facades\DB::table($this->newTable)->insert([
  28. 'id'=>$v['id'],
  29. 'areaname'=>$v['areaname'],
  30. 'parentid'=>$v['parentid'],
  31. 'level'=>$v['level']
  32. ]);
  33. }
  34. }
  35. // TODO: Implement run() method.
  36. }
  37. }