create_point_tables.php.sub 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. use Illuminate\Database\Migrations\Migration;
  3. use Illuminate\Database\Schema\Blueprint;
  4. use Illuminate\Support\Facades\Schema;
  5. class CreatePointTables extends Migration
  6. {
  7. /**
  8. * Run the migrations.
  9. *
  10. * @return void
  11. */
  12. public function up()
  13. {
  14. $prefix = config('ibrand.app.database.prefix', 'ibrand_');
  15. if(!Schema::hasTable($prefix . 'point')){
  16. Schema::create($prefix . 'point', function (Blueprint $table) {
  17. $table->increments('id');
  18. $table->unsignedInteger('user_id')->comment('用户id');
  19. // order_item: 订单商品获得积分
  20. // order_discount: 订单折扣使用积分
  21. // order_canceled: 取消订单返还积分
  22. $table->string('action')->default('order_item')->comment('action:产生积分变化的动作,用于查询');
  23. $table->string('note')->nullbale()->comment('积分变化的提示信息');
  24. $table->decimal('value', 10, 2)->nullable()->default(0)->comment('积分变化数值,可为负数');
  25. $table->timestamp('valid_time')->nullable()->comment('积分有效期 为空时永久有效');
  26. $table->unsignedInteger('status')->nullable()->default(1);
  27. $table->string('item_type')->nullable();
  28. $table->unsignedInteger('item_id')->nullable()->comment('积分变化动作对应表的id');
  29. $table->timestamps();
  30. $table->softDeletes();
  31. $table->index(['item_type', 'item_id']);
  32. });
  33. }
  34. }
  35. /**
  36. * Reverse the migrations.
  37. *
  38. * @return void
  39. */
  40. public function down()
  41. {
  42. $prefix = config('ibrand.app.database.prefix', 'ibrand_');
  43. Schema::drop($prefix . 'point');
  44. }
  45. }