1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- <?php
- use app\model\BuildingLabel;
- use app\model\Company;
- use think\migration\Migrator;
- use think\migration\db\Column;
- class CreateBuildingLabelTable 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('building_label')
- ->addColumn('name', 'string', ['comment' => '标签名'])
- ->addColumn('root_id', 'integer', ['comment' => '企业id'])
- ->addColumn('addtime', 'integer', ['comment' => '添加时间'])
- ->create();
- $default = ['周边学校', '周边医院', '周边商超', '周边建材', '公园', '小区进度'];
- $rootList = Company::column('root_id');
- $data = [];
- foreach ($rootList as $id) {
- foreach ($default as $d) {
- $data[] = [
- 'name' => $d,
- 'root_id' => $id,
- 'addtime' => time()
- ];
- }
- }
- (new BuildingLabel)->saveAll($data);
- }
- }
|