| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- <?php
- namespace addons\Boss\console\migrations;
- use addons\Boss\common\models\AddonsBossLevelSetting;
- use yii\db\Migration;
- /**
- * Class M231014155312AleterQimallAddonsBossLevelSetting
- */
- class M231014155312AleterQimallAddonsBossLevelSetting extends Migration
- {
- /**
- * {@inheritdoc}
- */
- public function safeUp()
- {
- $sql = "ALTER TABLE `qimall_addons_boss_level_setting`
- MODIFY COLUMN `extra_type` varchar(50) NOT NULL DEFAULT '' COMMENT '获取额外分红的类型:1条件,2购物,3手动';";
- $this->execute($sql);
- $this->setExtraType();
- }
- /**
- * {@inheritdoc}
- */
- public function safeDown()
- {
- echo "M231014155312AleterQimallAddonsBossLevelSetting cannot be reverted.\n";
- return false;
- }
- /**
- * 修改额外分红
- * @return void
- */
- public function setExtraType()
- {
- $i = 1;
- $page_size = 1000;
- while ($list = AddonsBossLevelSetting::find()->offset(($i - 1) * $page_size)->limit($page_size)->all()) {
- foreach ($list as $model) {
- if ($model->extra_type == 1) $model->extra_type = '["2"]';
- if ($model->extra_type == 2) $model->extra_type = '["1"]';
- if ($model->extra_type == 3) $model->extra_type = '["1","2","3"]';
- $model->save();
- }
- $i++;
- }
- }
- /*
- // Use up()/down() to run migration code without a transaction.
- public function up()
- {
- }
- public function down()
- {
- echo "M231014155312AleterQimallAddonsBossLevelSetting cannot be reverted.\n";
- return false;
- }
- */
- }
|