20230506021842_add_customer_channel_index_to_permission_table.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. use app\model\Permission;
  3. use app\model\Grant;
  4. use think\migration\Migrator;
  5. use think\migration\db\Column;
  6. class AddCustomerChannelIndexToPermissionTable 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. $this->table('company')->addColumn('channel_setting', 'text', ['comment'=>'网销渠道配置', 'default'=>'', 'null'=>true])->update();
  32. $p = Permission::where([['auth_name', '=', 'CRM客户管理']])->find();
  33. $pn = Permission::create([
  34. 'pid' => $p->id,
  35. 'auth_name' => '网销渠道设置',
  36. 'uri' => 'crm/channel_index',
  37. 'relation' => 'crm/channel_index,crm/channel_edit,crm/synchronize_fish_data',
  38. 'is_menu' => 1
  39. ]);
  40. $grant = Grant::where(['type'=>'m'])->select();
  41. foreach($grant as $g){
  42. $permission = json_decode(json_encode($g->permission), true);
  43. $permission[] = $pn->id;
  44. $g->permission = $permission;
  45. $g->save();
  46. }
  47. }
  48. }