M231014155312AleterQimallAddonsBossLevelSetting.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. namespace addons\Boss\console\migrations;
  3. use addons\Boss\common\models\AddonsBossLevelSetting;
  4. use yii\db\Migration;
  5. /**
  6. * Class M231014155312AleterQimallAddonsBossLevelSetting
  7. */
  8. class M231014155312AleterQimallAddonsBossLevelSetting extends Migration
  9. {
  10. /**
  11. * {@inheritdoc}
  12. */
  13. public function safeUp()
  14. {
  15. $sql = "ALTER TABLE `qimall_addons_boss_level_setting`
  16. MODIFY COLUMN `extra_type` varchar(50) NOT NULL DEFAULT '' COMMENT '获取额外分红的类型:1条件,2购物,3手动';";
  17. $this->execute($sql);
  18. $this->setExtraType();
  19. }
  20. /**
  21. * {@inheritdoc}
  22. */
  23. public function safeDown()
  24. {
  25. echo "M231014155312AleterQimallAddonsBossLevelSetting cannot be reverted.\n";
  26. return false;
  27. }
  28. /**
  29. * 修改额外分红
  30. * @return void
  31. */
  32. public function setExtraType()
  33. {
  34. $i = 1;
  35. $page_size = 1000;
  36. while ($list = AddonsBossLevelSetting::find()->offset(($i - 1) * $page_size)->limit($page_size)->all()) {
  37. foreach ($list as $model) {
  38. if ($model->extra_type == 1) $model->extra_type = '["2"]';
  39. if ($model->extra_type == 2) $model->extra_type = '["1"]';
  40. if ($model->extra_type == 3) $model->extra_type = '["1","2","3"]';
  41. $model->save();
  42. }
  43. $i++;
  44. }
  45. }
  46. /*
  47. // Use up()/down() to run migration code without a transaction.
  48. public function up()
  49. {
  50. }
  51. public function down()
  52. {
  53. echo "M231014155312AleterQimallAddonsBossLevelSetting cannot be reverted.\n";
  54. return false;
  55. }
  56. */
  57. }