20220819061103_add_menu_customer_setting_and_permission.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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 AddMenuCustomerSettingAndPermission 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. $data = [
  32. 'pid' => 7,
  33. 'auth_name'=> '客户设置',
  34. 'uri' => 'customerSetting/index',
  35. 'is_menu' => 1,
  36. 'sort'=> 50,
  37. 'relation' => 'customerSetting/index,customerSetting/setting,crm/portrait,crm/portrait_edit,crm/portrait_type'
  38. ];
  39. $per_ids = Permission::insertGetId($data);
  40. $info = Grant::where('id',1)->find();
  41. $pids = (array)$info->permission;
  42. $pids[] = (int)$per_ids;
  43. $info->permission = array_values($pids);
  44. $info->save();
  45. }
  46. }