M241206074356NewAlterScoreRulesField.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. namespace addons\Store\console\migrations;
  3. use addons\Store\common\models\StoreGoodsCate;
  4. use addons\Store\common\models\StoreScoreStoreApply;
  5. use yii\db\Migration;
  6. /**
  7. * Class M241206074356NewAlterScoreRulesField
  8. */
  9. class M241206074356NewAlterScoreRulesField extends Migration
  10. {
  11. /**
  12. * {@inheritdoc}
  13. */
  14. public function safeUp()
  15. {
  16. try {
  17. $goods_cate_field = StoreGoodsCate::getTableSchema()->getColumnNames();
  18. $score_store_apply_feild = StoreScoreStoreApply::getTableSchema()->getColumnNames();
  19. if (!in_array('mall_goods_cate_id', $goods_cate_field) && !in_array('score_method', $score_store_apply_feild)) {
  20. $sql = <<<SQL
  21. ALTER TABLE `qimall_addons_store_goods_cate` ADD COLUMN `mall_goods_cate_id` int(11) DEFAULT '0' COMMENT '关联主商城商品分类ID' AFTER `sort`;
  22. ALTER TABLE `qimall_addons_store_score_store_apply` ADD COLUMN `score_method` tinyint(1) DEFAULT '1' COMMENT '积分操作,1积分赠送,2积分抵扣,默认1' AFTER `store_c_id`;
  23. SQL;
  24. $this->execute($sql);
  25. }
  26. }catch (\Exception $e){}
  27. return true;
  28. }
  29. /**
  30. * {@inheritdoc}
  31. */
  32. public function safeDown()
  33. {
  34. echo "M241206074356NewAlterScoreRulesField cannot be reverted.\n";
  35. return false;
  36. }
  37. /*
  38. // Use up()/down() to run migration code without a transaction.
  39. public function up()
  40. {
  41. }
  42. public function down()
  43. {
  44. echo "M241206074356NewAlterScoreRulesField cannot be reverted.\n";
  45. return false;
  46. }
  47. */
  48. }