2021_03_06_090856_create_tax_rates_table.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. use Illuminate\Database\Migrations\Migration;
  3. use Illuminate\Database\Schema\Blueprint;
  4. use Illuminate\Support\Facades\Schema;
  5. class CreateTaxRatesTable extends Migration
  6. {
  7. protected $values = [
  8. 0,3,6,11
  9. ];
  10. protected $authorities = [
  11. "税率",
  12. "税率-查询",
  13. "税率-编辑",
  14. "税率-删除",
  15. "入库管理-客户预约-预约",
  16. "入库管理-客户预约"
  17. ];
  18. /**
  19. * Run the migrations.
  20. *
  21. * @return void
  22. */
  23. public function up()
  24. {
  25. Schema::create('tax_rates', function (Blueprint $table) {
  26. $table->id();
  27. $table->decimal("value",5,2)->unique()->comment("值");
  28. $table->timestamps();
  29. });
  30. Schema::table('owners', function (Blueprint $table) {
  31. $table->dropColumn("tax_rate");
  32. $table->bigInteger("tax_rate_id")->nullable()->comment("外键税率");
  33. $table->string("relevance")->nullable()->comment("关联模型的JSON数组");
  34. });
  35. foreach ($this->values as $value) \App\TaxRate::query()->firstOrCreate(["value"=>$value]);
  36. foreach ($this->authorities as $authority)\App\Authority::query()->firstOrCreate(["name"=>$authority],["name"=>$authority,"alias_name"=>$authority]);
  37. \App\Authority::query()->where("name","入库管理-盘收一体-客户预约")->delete();
  38. Schema::table('warehouses', function (Blueprint $table) {
  39. $table->decimal("production_capacity")->default(0)->comment("产能");
  40. $table->integer("reduced_production_capacity_coefficient")->default(0)->comment("SKU减产系数");
  41. });
  42. }
  43. /**
  44. * Reverse the migrations.
  45. *
  46. * @return void
  47. */
  48. public function down()
  49. {
  50. Schema::dropIfExists('tax_rates');
  51. Schema::table('owners', function (Blueprint $table) {
  52. $table->dropColumn("tax_rate_id");
  53. $table->decimal("tax_rate")->nullable()->comment("税率");
  54. $table->dropColumn("relevance");
  55. });
  56. foreach ($this->authorities as $authority)\App\Authority::query()->where("name",$authority)->delete();
  57. \App\Authority::query()->firstOrCreate(["name"=>"入库管理-盘收一体-客户预约"],["name"=>"入库管理-盘收一体-客户预约","alias_name"=>"入库管理-盘收一体-客户预约"]);
  58. Schema::table('warehouses', function (Blueprint $table) {
  59. $table->dropColumn("production_capacity");
  60. $table->dropColumn("reduced_production_capacity_coefficient");
  61. });
  62. }
  63. }