M250909101813AlterQimallStoreSettings.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. namespace addons\Store\console\migrations;
  3. use yii\db\Migration;
  4. /**
  5. * Class M250909101813AlterQimallStoreSettings.php
  6. */
  7. class M250909101813AlterQimallStoreSettings extends Migration
  8. {
  9. /**
  10. * {@inheritdoc}
  11. */
  12. public function safeUp()
  13. {
  14. if(!$this->columnExists('qimall_addons_store_settings', 'store_service_fee_settle_type')) {
  15. $sql = "ALTER TABLE `qimall_addons_store_settings` ADD COLUMN `store_service_fee_settle_type` tinyint(2) NOT NULL DEFAULT 1 COMMENT '服务费计算方式 1按订单实付金额 2按商品售价计算 3按商品成本价计算';";
  16. $this->execute($sql);
  17. }
  18. }
  19. /**
  20. * {@inheritdoc}
  21. */
  22. public function safeDown()
  23. {
  24. echo "M250909101813AlterQimallStoreSettings.php cannot be reverted.\n";
  25. return false;
  26. }
  27. protected function columnExists($tableName, $columnName)
  28. {
  29. $tableSchema = \Yii::$app->db->getTableSchema($tableName, true);
  30. return $tableSchema && in_array($columnName, $tableSchema->columnNames);
  31. }
  32. }