20220521031241_add_day_study_to_permission_table.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. use think\migration\Migrator;
  3. use \app\model\Permission;
  4. use \app\model\Grant;
  5. use think\migration\db\Column;
  6. class AddDayStudyToPermissionTable 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. $parent_id = (new Permission())->where('auth_name', '=', '集团大学')->value('id');
  32. $id = (new Permission())->insertGetId(
  33. ['pid' => $parent_id, 'auth_name' => '每日学练', 'uri' => 'dayStudy/index', 'is_menu' => 1, 'icon' => null, 'sort' => 50, 'relation' => 'dayStudy/index,dayStudy/setting,dayStudy/getTrainType,dayStudy/getQuestionCate,dayStudy/setting_detail']
  34. );
  35. $grant = Grant::find(1);
  36. $permission = array_merge(json_decode(json_encode($grant->permission), true), [intval($id)]);
  37. asort($permission);
  38. $grant->permission = array_values(array_filter(array_unique($permission)));
  39. $grant->save();
  40. }
  41. }