12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- <?php
- use think\migration\Migrator;
- use think\migration\db\Column;
- use app\model\Permission;
- use app\model\Grant;
- class CreateCompanyStrength 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()
- {
- //公司实力菜单
- $menu = [
- 'pid' => 1,
- 'uri' => 'companyStrength/index',
- 'auth_name' => '公司实力',
- 'is_menu' => 1,
- 'sort' => 50,
- 'relation' => 'companyStrength/index'
- ];
- $id = Permission::insertGetId($menu);
- //建表
- $table = $this->table('company_strength')->setComment('公司实力');
- $table->addColumn('root_id', 'integer', ['limit' => 10, 'comment' => '店面id', 'null' => true, 'default' => 0])
- ->addColumn('cate', 'string', ['limit' => 250, 'comment' => '分类', 'null' => true, 'default' => ''])
- ->addColumn('title', 'string', ['limit' => 255, 'comment' => '标题', 'null' => true, 'default' => ''])
- ->addColumn('media_ids', 'string', ['limit' => 255, 'comment' => '媒体链接', 'null' => true, 'default' => ''])
- ->addColumn('pics', 'string', ['limit' => 255, 'comment' => '图片/视频地址', 'null' => true, 'default' => ''])
- ->addColumn('cover', 'string', ['limit' => 255, 'comment' => '图片/视频封面图', 'null' => true, 'default' => ''])
- ->addColumn('desc', 'text', ['comment'=> '描述', 'null'=> true])
- ->addColumn('shared_times', 'integer', ['limit' => 10, 'comment' => '分享次数', 'null' => true, 'default' => 0])
- ->addColumn('addtime', 'timestamp', ['comment' => '添加时间', 'default' => 'CURRENT_TIMESTAMP', 'null' => true])
- ->addColumn('updatetime', 'timestamp', ['comment' => '修改时间', 'default' => 'CURRENT_TIMESTAMP', 'null' => true])
- ->addColumn('del', 'integer', ['limit' => 10, 'comment' => '1删除', 'null' => true, 'default' => 0])
- ->addColumn('publish', 'integer', ['limit' => 10, 'comment' => '1上架,0下架', 'null' => true, 'default' => 1])
- ->addColumn('view_times', 'integer', ['limit' => 10, 'comment' => '浏览次数', 'null' => true, 'default' => 0])
- ->addColumn('employee_id', 'integer', ['limit' => 10, 'comment' => '上传人员', 'null' => true, 'default' => 0])
- ->addColumn('difference', 'integer', ['limit' => 10, 'comment' => '1视频,2图文', 'null' => true, 'default' => 2])
- ->create();
- $table = $this->table('company_strength_cate')->setComment('公司实力分类');
- $table->addColumn('root_id', 'integer', ['limit' => 10, 'comment' => '店面id', 'null' => true, 'default' => 0])
- ->addColumn('name', 'string', ['limit' => 250, 'comment' => '分类', 'null' => true, 'default' => ''])
- ->addColumn('addtime', 'timestamp', ['comment' => '添加时间', 'default' => 'CURRENT_TIMESTAMP', 'null' => true])
- ->create();
- //菜单权限
- $info = Grant::where('id',1)->find();
- $pids = (array)$info->permission;
- $pids[] = (int)$id;
- $info->permission = array_values($pids);
- $info->save();
- //权限
- $per = ',companyStrength/list,companyStrength/apipublish,companyStrength/add,companyStrength/adding,companyStrength/edit,companyStrength/editing,companyStrength/del,companyStrength/imgUpload';
- $w[] = ['auth_name', '=', '公司实力'];
- $w[] = ['pid', '>', 0];
- $w[] = ['is_menu', '=', 1];
- $info = Permission::where($w)->find();
- $per = $info->relation . $per;
- $info->relation = $per;
- $info->save();
- }
- }
|