20230627102316_add_renovate_quotation_menu.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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 AddRenovateQuotationMenu 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. $permission = Permission::where(['auth_name'=>'营销工具'])->find();
  32. $addnewpr = [
  33. 'pid' => $permission->id,
  34. 'auth_name' => '装修报价',
  35. 'uri' => 'tool/renovate_quotation',
  36. 'is_menu' => 1,
  37. 'relation' => 'tool/renovate_quotation'
  38. ];
  39. $parent = $permission->create($addnewpr);
  40. $grant = Grant::find(1);
  41. $permission = array_merge(json_decode(json_encode($grant->permission), true), [$parent->id]);
  42. asort($permission);
  43. $grant->permission = $permission;
  44. $grant->save();
  45. // 要单独添加权限的企业
  46. $c = [1023,2214]; // 鲁班装饰id,酷美鲁班装饰id
  47. foreach($c as $k=>$v){
  48. $grant = Grant::where([['root_id','=',$v],['type','=','m']])->find();
  49. $permission = array_merge(json_decode(json_encode($grant->permission), true),[$parent->id]);
  50. asort($permission);
  51. $grant->permission = array_values($permission);
  52. $grant->save();
  53. }
  54. }
  55. }