M230915025002AlterQimallAddonsCloudStockGoods.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. namespace addons\CloudStock\console\migrations;
  3. use common\models\common\Addons;
  4. use yii\db\Migration;
  5. /**
  6. * Class M230915025002AlterQimallAddonsCloudStockGoods
  7. */
  8. class M230915025002AlterQimallAddonsCloudStockGoods extends Migration
  9. {
  10. /**
  11. * {@inheritdoc}
  12. */
  13. public function safeUp()
  14. {
  15. $sql ="ALTER TABLE qimall_addons_cloud_stock_goods add monthly_purchase text COMMENT '月限购';";
  16. $this->execute($sql);
  17. $sql ="ALTER TABLE qimall_addons_cloud_stock_goods add additional_purchase_restrictions text COMMENT '增加额外限购';";
  18. $this->execute($sql);
  19. $table = 'qimall_addons_cloud_stock_agent_guota';
  20. $sql="select * from information_schema.TABLES where TABLE_NAME = '{$table}';";
  21. $res = $this->db->createCommand($sql)->execute();
  22. if(empty($res)) {
  23. $sql="CREATE TABLE `qimall_addons_cloud_stock_agent_guota` (
  24. `id` bigint(20) NOT NULL AUTO_INCREMENT,
  25. `mall_id` int(11) NOT NULL DEFAULT '0' COMMENT '商城id',
  26. `user_id` int(11) NOT NULL DEFAULT '0' COMMENT '用户id',
  27. `goods_id` int(11) NOT NULL COMMENT '商品id',
  28. `limit_nums` int(11) DEFAULT NULL COMMENT '增加额外限购数量',
  29. `status` tinyint(1) NOT NULL DEFAULT '1' COMMENT '状态[-1:删除;0:禁用;1启用]',
  30. `created_at` bigint(20) NOT NULL DEFAULT '0',
  31. `updated_at` bigint(20) NOT NULL DEFAULT '0',
  32. PRIMARY KEY (`id`) USING BTREE,
  33. KEY `idx_mId_uId_gId` (`mall_id`,`user_id`,`goods_id`) USING BTREE
  34. ) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT COMMENT='代理商额外限购表';";
  35. Addons::isInstall('CloudStock');
  36. $this->execute($sql);
  37. }
  38. }
  39. /**
  40. * {@inheritdoc}
  41. */
  42. public function safeDown()
  43. {
  44. echo "M230915025002AlterQimallAddonsCloudStockGoods cannot be reverted.\n";
  45. return false;
  46. }
  47. /*
  48. // Use up()/down() to run migration code without a transaction.
  49. public function up()
  50. {
  51. }
  52. public function down()
  53. {
  54. echo "M230915025002AlterQimallAddonsCloudStockGoods cannot be reverted.\n";
  55. return false;
  56. }
  57. */
  58. }