123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- <?php
- use think\migration\Migrator;
- use think\migration\db\Column;
- use app\model\Company;
- use app\model\TrainClassCate;
- use app\model\Permission;
- class AddDataToTrainClassCate 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()
- {
- TrainClassCate::where('1=1')->delete();
- $root_ids = Company::where([['company_group', '>', 0]])->column('root_id');
- $saves = [];
- $arr = ['销冠分享','总裁讲堂','营销工具','工艺标准','营销管理','业务技能','设计常识','产品知识','企业文化','通用知识','其他'];
- foreach ($root_ids as $v) {
- foreach ($arr as $v2) {
- $saves[] = [
- 'root_id' => $v,
- 'name' => $v2
- ];
- }
- }
- (new TrainClassCate())->saveAll($saves);
-
- $per = ',train/class_label,train/class_label_list,train/class_label_edit,train/class_label_add,train/class_label_add_ajax,train/get_label';
- $w[] = ['auth_name', '=', '课程培训'];
- $w[] = ['pid', '>', 0];
- $w[] = ['is_menu', '=', 1];
- $info = Permission::where($w)->find();
- $per = $info->relation . $per;
- $info->relation = $per;
- $info->save();
- }
- }
|