1
0

20220912110823_add_train_studytime_permission.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. use think\migration\Migrator;
  3. use think\migration\db\Column;
  4. use app\model\Permission;
  5. use app\model\Grant;
  6. class AddTrainStudytimePermission 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. $pid = Permission::where([['auth_name','=','集团大学'],['pid','=',0]])->find();
  32. $save = [
  33. 'pid'=>$pid->id,
  34. 'auth_name'=>'学分设置',
  35. 'uri' => 'train/credit_setting',
  36. 'is_menu' => 1,
  37. 'sort' => 50,
  38. 'relation' => 'train/credit_setting,train/reward_credit_save,train/up_credit_status'
  39. ];
  40. $pid->save();
  41. $id = Permission::insertGetId($save);
  42. $info = Grant::where('id',1)->find();
  43. $pids = (array)$info->permission;
  44. $pids[] = (int)$id;
  45. $info->permission = array_values($pids);
  46. $info->save();
  47. }
  48. }