M230329074638CreateQimallMemberLabel.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. namespace app\migrations;
  3. use yii\db\Migration;
  4. /**
  5. * Class M230329074638CreateQimallMemberLabel
  6. */
  7. class M230329074638CreateQimallMemberLabel extends Migration
  8. {
  9. /**
  10. * {@inheritdoc}
  11. */
  12. public function safeUp()
  13. {
  14. try {
  15. $table = 'qimall_member_label';
  16. $sql="select * from information_schema.TABLES where TABLE_NAME = '{$table}';";
  17. $res = $this->db->createCommand($sql)->execute();
  18. if(!empty($res)) return '';
  19. $sql="CREATE TABLE `{$table}` (
  20. `id` int(10) NOT NULL AUTO_INCREMENT,
  21. `mall_id` int(10) NOT NULL DEFAULT '0' COMMENT '商城ID',
  22. `cate_id` int(10) NOT NULL DEFAULT '0' COMMENT '分类ID',
  23. `name` varchar(45) NOT NULL DEFAULT '' COMMENT '名称',
  24. `label_type` tinyint(1) NOT NULL DEFAULT '0' COMMENT '标签类型:1:自动;2:手动',
  25. `user_num` int(10) NOT NULL DEFAULT '0' COMMENT '会员数量',
  26. `condition` text NOT NULL COMMENT '达标条件',
  27. `color` varchar(255) NOT NULL DEFAULT '' COMMENT '颜色',
  28. `status` tinyint(4) DEFAULT '1' COMMENT '状态[-1:删除;0:禁用;1启用]',
  29. `created_at` int(10) NOT NULL DEFAULT '0',
  30. `updated_at` int(10) NOT NULL DEFAULT '0',
  31. PRIMARY KEY (`id`) USING BTREE,
  32. KEY `mall_id` (`mall_id`) USING BTREE
  33. ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='会员标签';";
  34. $this->execute($sql);
  35. } catch (\Exception $e) {
  36. }
  37. }
  38. /**
  39. * {@inheritdoc}
  40. */
  41. public function safeDown()
  42. {
  43. echo "M230329074638CreateQimallMemberLabel cannot be reverted.\n";
  44. return false;
  45. }
  46. /*
  47. // Use up()/down() to run migration code without a transaction.
  48. public function up()
  49. {
  50. }
  51. public function down()
  52. {
  53. echo "M230329074638CreateQimallMemberLabel cannot be reverted.\n";
  54. return false;
  55. }
  56. */
  57. }