M230210075004AddComponentsToDiyComponents.php 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. namespace app\migrations;
  3. use yii\db\Migration;
  4. /**
  5. * Class M230210075004AddComponentsToDiyComponents
  6. */
  7. class M230210075004AddComponentsToDiyComponents extends Migration
  8. {
  9. /**
  10. * {@inheritdoc}
  11. */
  12. public function safeUp()
  13. {
  14. $list = $this->db->createCommand("select * from qimall_diy_components where id in (38,39,40,41) ")->queryAll();
  15. if($list && count($list) == 4) return true;
  16. $list = array_column($list,null,'id');
  17. if(!isset($list['38'])){
  18. $sql[] = 'INSERT INTO `qimall_diy_components` (`id`, `code`, `title`, `group`, `icon`, `count`, `is_top`, `permission`, `sort`, `source`, `status`, `created_at`, `updated_at`) VALUES (\'38\', \'goods-coupon\', \'领券信息\', \'goods\', \'\', \'1\', \'0\', \'{\"is_drag\":\"false\",\"is_up\":\"false\",\"id_down\":\"false\",\"is_copy\":\"false\"}\', \'999\', \'\', \'1\', \'1634538238\', \'1634538238\');
  19. ';
  20. }
  21. if(!isset($list['39'])) {
  22. $sql[] = 'INSERT INTO `qimall_diy_components` (`id`, `code`, `title`, `group`, `icon`, `count`, `is_top`, `permission`, `sort`, `source`, `status`, `created_at`, `updated_at`) VALUES (\'39\', \'goods-stock\', \'库存\', \'goods\', \'\', \'1\', \'0\', \'{\"is_drag\":\"false\",\"is_up\":\"false\",\"id_down\":\"false\",\"is_copy\":\"false\"}\', \'999\', \'\', \'1\', \'1634538238\', \'1634538238\');
  23. ';
  24. }
  25. if(!isset($list['40'])) {
  26. $sql[] = 'INSERT INTO `qimall_diy_components` (`id`, `code`, `title`, `group`, `icon`, `count`, `is_top`, `permission`, `sort`, `source`, `status`, `created_at`, `updated_at`) VALUES (\'40\', \'goods-service\', \'服务\', \'goods\', \'\', \'1\', \'0\', \'{\"is_drag\":\"false\",\"is_up\":\"false\",\"id_down\":\"false\",\"is_copy\":\"false\"}\', \'999\', \'\', \'1\', \'1634538238\', \'1634538238\');
  27. ';
  28. }
  29. if(!isset($list['41'])) {
  30. $sql[] = 'INSERT INTO `qimall_diy_components` (`id`, `code`, `title`, `group`, `icon`, `count`, `is_top`, `permission`, `sort`, `source`, `status`, `created_at`, `updated_at`) VALUES (\'41\', \'goods-attr\', \'规格\', \'goods\', \'\', \'1\', \'0\', \'{\"is_drag\":\"false\",\"is_up\":\"false\",\"id_down\":\"false\",\"is_copy\":\"false\"}\', \'999\', \'\', \'1\', \'1634538238\', \'1634538238\');
  31. ';
  32. }
  33. $sql = implode(' ',$sql);
  34. $this->execute($sql);
  35. }
  36. /**
  37. * {@inheritdoc}
  38. */
  39. public function safeDown()
  40. {
  41. echo "M230210075004AddComponentsToDiyComponents cannot be reverted.\n";
  42. return false;
  43. }
  44. /*
  45. // Use up()/down() to run migration code without a transaction.
  46. public function up()
  47. {
  48. }
  49. public function down()
  50. {
  51. echo "M230210075004AddComponentsToDiyComponents cannot be reverted.\n";
  52. return false;
  53. }
  54. */
  55. }