M250610102639InsertRegion.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. namespace app\migrations;
  3. use yii\db\Migration;
  4. /**
  5. * 因为区域管理表不是自增Id。所以需要指定ID 之前有错误数据需要删除
  6. * Class M250610102639InsertRegion
  7. */
  8. class M250610102639InsertRegion extends Migration
  9. {
  10. /**
  11. * {@inheritdoc}
  12. */
  13. public function safeUp()
  14. {
  15. // 先执行之前数据的删除 在重新插入
  16. try {
  17. $sql = <<<SQL
  18. DELETE FROM `qimall_region` WHERE `name` = '大亚湾经济技术开发区' OR `name` = '仲恺高新技术产业开发区';
  19. INSERT INTO `qimall_region` (`id`, `name`, `parent_id`, `level`, `short_title`, `areacode`, `zipcode`, `initial`, `lng`, `lat`) VALUES (10320, '大亚湾经济技术开发区',2025,3,'',0,0,'D','114.52193199999','22.715671999999');
  20. INSERT INTO `qimall_region` (`id`, `name`, `parent_id`, `level`, `short_title`, `areacode`, `zipcode`, `initial`, `lng`, `lat`) VALUES (10321, '仲恺高新技术产业开发区',2025,3,'',0,0,'Z','114.29527199999','23.034215000000');
  21. SQL;
  22. $this->execute($sql);
  23. } catch (\Exception $e) {
  24. }
  25. }
  26. /**
  27. * {@inheritdoc}
  28. */
  29. public function safeDown()
  30. {
  31. echo "M250610102639InsertRegion cannot be reverted.\n";
  32. return false;
  33. }
  34. }