1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- <?php
- use app\model\Permission;
- use app\model\Grant;
- use think\migration\Migrator;
- use think\migration\db\Column;
- class AddCustomerChannelIndexToPermissionTable extends Migrator
- {
- /**
- * Change Method.
- *
- * Write your reversible migrations using this method.
- *
- * More information on writing migrations is available here:
- * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
- *
- * The following commands can be used in this method and Phinx will
- * automatically reverse them when rolling back:
- *
- * createTable
- * renameTable
- * addColumn
- * renameColumn
- * addIndex
- * addForeignKey
- *
- * Remember to call "create()" or "update()" and NOT "save()" when working
- * with the Table class.
- */
- public function change()
- {
- $this->table('company')->addColumn('channel_setting', 'text', ['comment'=>'网销渠道配置', 'default'=>'', 'null'=>true])->update();
- $p = Permission::where([['auth_name', '=', 'CRM客户管理']])->find();
- $pn = Permission::create([
- 'pid' => $p->id,
- 'auth_name' => '网销渠道设置',
- 'uri' => 'crm/channel_index',
- 'relation' => 'crm/channel_index,crm/channel_edit,crm/synchronize_fish_data',
- 'is_menu' => 1
- ]);
- $grant = Grant::where(['type'=>'m'])->select();
- foreach($grant as $g){
- $permission = json_decode(json_encode($g->permission), true);
- $permission[] = $pn->id;
- $g->permission = $permission;
- $g->save();
- }
- }
- }
|