| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- <?php
- namespace app\migrations;
- use common\models\common\Region;
- use yii\db\Migration;
- /**
- * Class M250314082020AddRegion
- */
- class M250314082020AddRegion extends Migration
- {
- /**
- * {@inheritdoc}
- */
- public function safeUp()
- {
- try {
- $addressA = Region::findOne(['name' => '仲恺高新技术产业开发区']);
- $addressAid = $addressA['id'];
- $addressB = Region::findOne(['name' => '大亚湾经济技术开发区']);
- $addressBid = $addressB['id'];
- $sql = <<<SQL
- INSERT INTO `qimall_town` (`district_id`, `adcode`, `name`, `created_at`, `updated_at`) VALUES (2025, 441303, '澳头街道', 1742278841, 1742278841);
- INSERT INTO `qimall_town` (`district_id`, `adcode`, `name`, `created_at`, `updated_at`) VALUES (2025, 441303, '西区街道', 1742278841, 1742278841);
- INSERT INTO `qimall_town` (`district_id`, `adcode`, `name`, `created_at`, `updated_at`) VALUES (2025, 441303, '霞涌街道', 1742278841, 1742278841);
-
- INSERT INTO `qimall_town` (`district_id`, `adcode`, `name`, `created_at`, `updated_at`) VALUES (2026, 441302, '陈江街道', 1742278841, 1742278841);
- INSERT INTO `qimall_town` (`district_id`, `adcode`, `name`, `created_at`, `updated_at`) VALUES (2026, 441302, '惠环街道', 1742278841, 1742278841);
- INSERT INTO `qimall_town` (`district_id`, `adcode`, `name`, `created_at`, `updated_at`) VALUES (2026, 441302, '沥林镇', 1742278841, 1742278841);
- INSERT INTO `qimall_town` (`district_id`, `adcode`, `name`, `created_at`, `updated_at`) VALUES (2026, 441302, '潼侨镇', 1742278841, 1742278841);
- INSERT INTO `qimall_town` (`district_id`, `adcode`, `name`, `created_at`, `updated_at`) VALUES (2026, 441302, '潼湖镇', 1742278841, 1742278841);
- SQL;
- // 将parent_id替换为$addressAid
- $sql = str_replace("2025", $addressBid, $sql);
- $sql = str_replace("2026", $addressAid, $sql);
- $this->execute($sql);
- } catch (\Exception $e) {
- // 处理异常
- var_dump($e->getMessage());
- }
- }
- /**
- * {@inheritdoc}
- */
- public function safeDown()
- {
- echo "M250314082020AddRegion cannot be reverted.\n";
- return false;
- }
- }
|