20230415135006_add_agent_menu_to_company.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. use app\model\Permission;
  3. use app\model\Grant;
  4. use think\migration\Migrator;
  5. class AddAgentMenuToCompany extends Migrator
  6. {
  7. /**
  8. * Change Method.
  9. *
  10. * Write your reversible migrations using this method.
  11. *
  12. * More information on writing migrations is available here:
  13. * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
  14. *
  15. * The following commands can be used in this method and Phinx will
  16. * automatically reverse them when rolling back:
  17. *
  18. * createTable
  19. * renameTable
  20. * addColumn
  21. * renameColumn
  22. * addIndex
  23. * addForeignKey
  24. *
  25. * Remember to call "create()" or "update()" and NOT "save()" when working
  26. * with the Table class.
  27. */
  28. public function change()
  29. {
  30. $addid = Permission::where([['uri','in',['renovatePriceSeet/price_setting','agents/agent_article_list']]])->column('id');
  31. $list = Grant::where([['type','=','m'],['root_id','<>',0]])->select()->toArray();
  32. foreach($list as $key=>$val){
  33. $permission = array_merge(json_decode(json_encode($val['permission']), true), $addid);
  34. asort($permission);
  35. $permission = array_values(array_filter(array_unique($permission)));
  36. Grant::where([['id','=',$val['id']],['root_id','=',$val['root_id']]])->update(['permission'=>$permission]);
  37. }
  38. }
  39. }