12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- <?php
- use think\migration\Migrator;
- use think\migration\db\Column;
- use app\model\Permission;
- class AddWeworkPerToPermissionTable 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()
- {
- $parent = Permission::where('auth_name', '=', '企微管理')->findOrEmpty();
- if (!$parent->isEmpty()){
- $parent->auth_name = '企业微信';
- $parent->save();
- $old_per = Permission::where([['pid', '=', $parent['id']], ['auth_name', '=', '企微群发']])->findOrEmpty();
- if (!$old_per->isEmpty()) {
- $old_per->auth_name = '客户运营';
- $old_per->relation = 'wework/external_message,wework/uploadFile,wework/getUserList,wework/materialList,wework/add_external_message,wework/edit_external_message,wework/delete_external_message,wework/statistics_external_message,wework/refresh_external_message,wework/getContactCount,wework/getUserGroupChatsList,wework/external_message_remind';
- $old_per->save();
- }
- $data1 = [
- 'pid'=> $parent['id'],
- 'auth_name'=> '客户群管理',
- 'uri'=> 'wework/group_list',
- 'is_menu'=> 1,
- 'relation'=> 'wework/group_list,wework/group_view,wework/refresh_group,wework/refresh_group_one,wework/group_tag,wework/add_group_tag_group,wework/edit_group_tag_group,wework/add_group_tag,wework/edit_group_tag,wework/group_add_tag,wework/group_view_data'
- ];
- $result1 = Permission::create($data1);
- $id1 = $result1->id;
- $data2 = [
- 'pid'=> $parent['id'],
- 'auth_name'=> '数据统计',
- 'uri'=> 'wework/user_behavior_view',
- 'is_menu'=> 1,
- 'relation'=> 'wework/user_behavior_view,wework/user_behavior_data,wework/group_analysis,wework/group_number,wework/employee_analysis_view,wework/employee_analysis_data'
- ];
- $result2 = Permission::create($data2);
- $id2 = $result2->id;
- $grant = \app\model\Grant::find(1);
- $permission = array_merge(json_decode(json_encode($grant->permission), true), [intval($id1),intval($id2)]);
- asort($permission);
- $grant->permission = array_values(array_filter(array_unique($permission)));
- $grant->save();
- }
- }
- }
|