create_discount_tables.php.stub 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. /*
  3. * This file is part of ibrand/discount.
  4. *
  5. * (c) iBrand <https://www.ibrand.cc>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. use Illuminate\Support\Facades\Schema;
  11. use Illuminate\Database\Schema\Blueprint;
  12. use Illuminate\Database\Migrations\Migration;
  13. class CreateDiscountTables extends Migration
  14. {
  15. /**
  16. * Run the migrations.
  17. *
  18. * @return void
  19. */
  20. public function up()
  21. {
  22. $prefix = config('ibrand.app.database.prefix', 'ibrand_');
  23. if (!Schema::hasTable($prefix . 'discount')) {
  24. Schema::create($prefix . 'discount', function (Blueprint $table) {
  25. $table->increments('id');
  26. $table->string('title');
  27. $table->string('code')->nullable();
  28. $table->string('label');
  29. $table->string('intro')->nullable();
  30. $table->tinyInteger('exclusive')->default(0);
  31. $table->integer('usage_limit')->nullable();
  32. $table->integer('per_usage_limit')->default(0)->nullable();
  33. $table->integer('used')->default(0);
  34. $table->tinyInteger('coupon_based')->default(0);
  35. $table->tinyInteger('status')->default(1);
  36. $table->timestamp('starts_at')->nullable();
  37. $table->timestamp('ends_at')->nullable();
  38. $table->timestamp('usestart_at')->nullable();
  39. $table->timestamp('useend_at')->nullable();
  40. $table->string('tags')->nullable();
  41. $table->timestamps();
  42. $table->softDeletes();
  43. });
  44. }
  45. if (!Schema::hasTable($prefix . 'discount_coupon')) {
  46. Schema::create($prefix . 'discount_coupon', function (Blueprint $table) use ($prefix) {
  47. $table->increments('id');
  48. $table->unsignedInteger('discount_id');
  49. $table->unsignedInteger('user_id');
  50. $table->string('code')->nullable();
  51. $table->timestamp('used_at')->nullable();
  52. $table->timestamp('expires_at')->nullable();
  53. $table->foreign('discount_id')
  54. ->references('id')
  55. ->on($prefix . 'discount')
  56. ->onDelete('cascade');
  57. $table->timestamps();
  58. $table->softDeletes();
  59. });
  60. }
  61. if (!Schema::hasTable($prefix . 'discount_action')) {
  62. Schema::create($prefix . 'discount_action', function (Blueprint $table) use ($prefix) {
  63. $table->increments('id');
  64. $table->unsignedInteger('discount_id');
  65. $table->string('type');
  66. $table->text('configuration')->nullable();
  67. $table->foreign('discount_id')
  68. ->references('id')
  69. ->on($prefix . 'discount')
  70. ->onDelete('cascade');
  71. });
  72. }
  73. if (!Schema::hasTable($prefix . 'discount_rule')) {
  74. Schema::create($prefix . 'discount_rule', function (Blueprint $table) use ($prefix) {
  75. $table->increments('id');
  76. $table->unsignedInteger('discount_id');
  77. $table->string('type');
  78. $table->mediumText('configuration')->nullable();
  79. $table->foreign('discount_id')
  80. ->references('id')
  81. ->on($prefix . 'discount')
  82. ->onDelete('cascade');
  83. });
  84. }
  85. }
  86. /**
  87. * Reverse the migrations.
  88. *
  89. * @return void
  90. */
  91. public function down()
  92. {
  93. $prefix = config('ibrand.app.database.prefix', 'ibrand_');
  94. Schema::dropIfExists($prefix . 'discount_rule');
  95. Schema::dropIfExists($prefix . 'discount_action');
  96. Schema::dropIfExists($prefix . 'discount_coupon');
  97. Schema::dropIfExists($prefix . 'discount');
  98. }
  99. }