YzUserRoleSeeder.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. use Illuminate\Database\Seeder;
  3. class YzUserRoleSeeder extends Seeder
  4. {
  5. protected $table = 'yz_user_role';
  6. protected $sourceTable = 'sz_yi_perm_role';
  7. /**
  8. * Run the database seeds.
  9. *
  10. * @return void
  11. */
  12. public function run()
  13. {
  14. return;
  15. $roles = \Illuminate\Support\Facades\DB::table($this->sourceTable)
  16. ->where(['status'=>'1','deleted'=>'0' ])
  17. ->where('uniacid','>','0')
  18. ->get();
  19. if($roles){
  20. foreach($roles as $role){
  21. $exists = \Illuminate\Support\Facades\DB::table($this->table)
  22. ->where(['uniacid'=>$role['uniacid'],'name'=>$role['rolename']])
  23. ->exists();
  24. if(!$exists){
  25. \Illuminate\Support\Facades\DB::table($this->table)->insert([
  26. 'name'=>$role['rolename'],
  27. 'uniacid'=>$role['uniacid'],
  28. 'created_at'=>time(),
  29. 'updated_at'=>time()
  30. ]);
  31. echo "迁移 uniacid:{$role['uniacid']} rolename:{$role['rolename']} 完成\n";
  32. }
  33. //@todo insert yz_permission
  34. }
  35. }
  36. }
  37. }