2021_03_06_090856_create_tax_rates_table.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. use Illuminate\Database\Migrations\Migration;
  3. use Illuminate\Database\Schema\Blueprint;
  4. use Illuminate\Support\Facades\DB;
  5. use Illuminate\Support\Facades\Schema;
  6. class CreateTaxRatesTable extends Migration
  7. {
  8. protected $values = [
  9. 0,3,6,11
  10. ];
  11. /**
  12. * Run the migrations.
  13. *
  14. * @return void
  15. */
  16. public function up()
  17. {
  18. Schema::create('tax_rates', function (Blueprint $table) {
  19. $table->id();
  20. $table->decimal("value",5,2)->unique()->comment("值");
  21. $table->timestamps();
  22. });
  23. Schema::table('owners', function (Blueprint $table) {
  24. $table->dropColumn("tax_rate");
  25. $table->bigInteger("tax_rate_id")->nullable()->comment("外键税率");
  26. $table->string("relevance")->nullable()->comment("关联模型的JSON数组");
  27. });
  28. foreach ($this->values as $value) DB::insert(DB::raw("INSERT INTO tax_rates(value) VALUES(?)"),[$value]);
  29. Schema::table('warehouses', function (Blueprint $table) {
  30. $table->decimal("production_capacity")->default(0)->comment("产能");
  31. $table->integer("reduced_production_capacity_coefficient")->default(0)->comment("SKU减产系数");
  32. });
  33. }
  34. /**
  35. * Reverse the migrations.
  36. *
  37. * @return void
  38. */
  39. public function down()
  40. {
  41. Schema::dropIfExists('tax_rates');
  42. Schema::table('owners', function (Blueprint $table) {
  43. $table->dropColumn("tax_rate_id");
  44. $table->decimal("tax_rate")->nullable()->comment("税率");
  45. $table->dropColumn("relevance");
  46. });
  47. Schema::table('warehouses', function (Blueprint $table) {
  48. $table->dropColumn("production_capacity");
  49. $table->dropColumn("reduced_production_capacity_coefficient");
  50. });
  51. }
  52. }