M241204120305AddShippedColumnToOrderDetail.php 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. namespace app\migrations;
  3. use yii\db\Migration;
  4. /**
  5. * Class M241204120305AddShippedColumnToOrderDetail
  6. */
  7. class M241204120305AddShippedColumnToOrderDetail extends Migration
  8. {
  9. /**
  10. * {@inheritdoc}
  11. */
  12. public function safeUp()
  13. {
  14. $sql = <<<SQL
  15. ALTER TABLE `qimall_order_detail`
  16. ADD COLUMN `shipped_num` int UNSIGNED NOT NULL DEFAULT 0 COMMENT '已发货数量';
  17. UPDATE `qimall_order_detail` SET `unshipped_num` = `num` WHERE `shipping_status` = 0 and `unshipped_num` = 0;
  18. UPDATE `qimall_order_detail` SET `shipped_num` = `num` - `unshipped_num`;
  19. ALTER TABLE `qimall_order_detail`
  20. DROP COLUMN `unshipped_num`;
  21. SQL;
  22. $this->execute($sql);
  23. }
  24. /**
  25. * {@inheritdoc}
  26. */
  27. public function safeDown()
  28. {
  29. return false;
  30. }
  31. /*
  32. // Use up()/down() to run migration code without a transaction.
  33. public function up()
  34. {
  35. }
  36. public function down()
  37. {
  38. echo "M241204120305AddShippedColumnToOrderDetail cannot be reverted.\n";
  39. return false;
  40. }
  41. */
  42. }