20230518171606_add_office_statistics_permission.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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 AddOfficeStatisticsPermission 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 = (new Permission())->where('auth_name', '=', '线上巡店')->value('id');
  32. $data['pid'] = $pid;
  33. $data['auth_name'] = '总经办报表';
  34. $data['uri'] = 'statistics/officeStatistics';
  35. $data['is_menu'] = 0;
  36. $data['sort'] = 50;
  37. $data['relation'] = 'statistics/officeStatistics,statistics/office_table_data';
  38. $result = Permission::create($data);
  39. // 要添加权限的企业
  40. $c = [941, 1847, 1977]; // 馨居尚组织跟id 菡萏怡景组织跟id 臻品软装组织跟id
  41. foreach($c as $k=>$v){
  42. $grant = Grant::where([['root_id','=',$v],['type','=','m']])->find();
  43. $permission = array_merge(json_decode(json_encode($grant->permission), true),[$result->id]);
  44. asort($permission);
  45. $grant->permission = array_values($permission);
  46. $grant->save();
  47. }
  48. }
  49. }