1
0

20230423065546_create_permission_for_building_label.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. use app\model\Grant;
  3. use app\model\Permission;
  4. use think\migration\Migrator;
  5. use think\migration\db\Column;
  6. class CreatePermissionForBuildingLabel extends Migrator
  7. {
  8. /**
  9. * Change Method.
  10. *
  11. * Write your reversible migrations using this method.
  12. *
  13. * More information on writing migrations is available here:
  14. * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
  15. *
  16. * The following commands can be used in this method and Phinx will
  17. * automatically reverse them when rolling back:
  18. *
  19. * createTable
  20. * renameTable
  21. * addColumn
  22. * renameColumn
  23. * addIndex
  24. * addForeignKey
  25. *
  26. * Remember to call "create()" or "update()" and NOT "save()" when working
  27. * with the Table class.
  28. */
  29. public function change()
  30. {
  31. $p = Permission::where(['uri'=>'building/index'])->find();
  32. $pb = Permission::create([
  33. 'pid'=>$p->id,
  34. 'auth_name'=>'楼盘标签',
  35. 'uri'=>'buildingLabel/index',
  36. 'is_menu'=>0,
  37. 'relation'=>'buildingLabel/index,buildingLabel/save,buildingLabel/update,buildingLabel/delete'
  38. ]);
  39. $grant = Grant::where(['type'=>'m'])->select();
  40. foreach($grant as $g){
  41. $permission = json_decode(json_encode($g->permission), true);
  42. $permission[] = $pb->id;
  43. $g->permission = $permission;
  44. $g->save();
  45. }
  46. }
  47. }