20230629091806_add_new_renovate_quotation_menu.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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 AddNewRenovateQuotationMenu 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. $result = Permission::where(['uri'=>'tool/renovate_quotation'])->find();
  32. // 要添加权限的企业
  33. $c = Grant::where([['root_id','not in',[0,1023,2214]],['type','=','m']])->column('root_id');
  34. foreach($c as $k=>$v){
  35. $grant = Grant::where([['root_id','=',$v],['type','=','m']])->find();
  36. $permission = array_merge(json_decode(json_encode($grant->permission), true),[$result->id]);
  37. asort($permission);
  38. $grant->permission = array_values($permission);
  39. $grant->save();
  40. }
  41. }
  42. }