| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- <?php
- namespace addons\DoubleCopy\console\migrations;
- use yii\db\Migration;
- /**
- * 判断 allowance_prize 字段是否存在
- * Class M250825152436AddCommissionItemSettingDetail
- */
- class M250825152436AddCommissionItemSettingDetail extends Migration
- {
- /**
- * {@inheritdoc}
- */
- public function safeUp()
- {
- try {
- // 要操作的表名
- $tableName = 'qimall_addons_double_copy_commission_item_setting_detail';
- // 要检查的字段名
- $columnName = 'allowance_price';
- if (!$this->columnExists($tableName, $columnName)) {
- $sql = <<<SQL
- ALTER TABLE `qimall_addons_double_copy_commission_item_setting_detail`
- ADD COLUMN `allowance_price` decimal(10, 2) NOT NULL COMMENT '津贴奖' AFTER `repurchase_prize`;
- SQL;
- $this->execute($sql);
- }
- } catch (\Exception $e) {
- }
- }
- protected function columnExists($tableName, $columnName): bool
- {
- $tableSchema = \Yii::$app->db->getTableSchema($tableName, true);
- return $tableSchema && in_array($columnName, $tableSchema->columnNames);
- }
- /**
- * {@inheritdoc}
- */
- public function safeDown()
- {
- echo "M250825152436AddCommissionItemSettingDetail cannot be reverted.\n";
- return false;
- }
- }
|