1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- <?php
- use think\migration\Migrator;
- use think\migration\db\Column;
- use app\model\Company;
- use app\model\TalkskillUsersCate;
- use app\model\TrainClassCate;
- class CreateDefaultDataTalkskillCate 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()
- {
- //默认值修改
- TalkskillUsersCate::where('1=1')->delete();
- TrainClassCate::where('1=1')->delete();
- //默认数据
- $root_ids = Company::where('1=1')->column('root_id');
- $saves = $cates = [];
- $arr = ['业务部', '网销部', '设计师', '客户经理'];
- $cate = ['销冠分享','总裁讲堂','营销工具','工艺标准','营销管理','业务技能','设计常识','产品知识','企业文化','通用知识','其他'];
- foreach ($root_ids as $v) {
- foreach ($arr as $v2) {
- $saves[] = [
- 'root_id' => $v,
- 'name' => $v2
- ];
- }
- foreach ($cate as $v3) {
- $cates[] = [
- 'root_id' => $v,
- 'name' => $v3
- ];
- }
- }
- (new TalkskillUsersCate())->saveAll($saves);
- (new TrainClassCate())->saveAll($cates);
- }
- }
|