create_order_tables.php.stub 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <?php
  2. /*
  3. * This file is part of ibrand/order.
  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 CreateOrderTables 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 . 'order')) {
  24. Schema::create($prefix . 'order', function (Blueprint $table) {
  25. $table->increments('id');
  26. $table->integer('user_id')->unsigned();
  27. $table->string('order_no'); //订单编号
  28. //状态类信息
  29. $table->integer('status')->unsigned()->default(0); //订单状态:1生成订单,2支付订单,3取消订单,4作废订单,5完成订单,6退款
  30. $table->tinyInteger('pay_status')->unsigned()->default(0); //支付状态:0未支付,1已支付
  31. $table->integer('distribution_status')->unsigned()->default(0); //发货状态:0未发货,1已发货
  32. //商品金额类信息
  33. $table->integer('count')->unsigned()->default(0); //商品总数
  34. $table->integer('items_total'); //商品总金额
  35. $table->integer('adjustments_total')->default(0); //优惠金额,负数,包含了促销和优惠券以及其他优惠的总金额,默认为零因为可能没有优惠活动
  36. $table->integer('payable_freight')->default(0); //应付运费金额
  37. $table->integer('real_freight')->default(0); //实付运费金额
  38. $table->integer('total'); //订单总金额: items_total+adjustments_total+real_freight
  39. //收货人信息
  40. $table->string('accept_name')->nullable(); //收货人姓名
  41. $table->string('mobile')->nullable(); //电话号码
  42. $table->string('address')->nullable();
  43. $table->string('address_name')->nullable(); //备用:收货地//详细地址址省市区名称
  44. //时间类信息
  45. $table->timestamp('submit_time')->nullable(); //付款时间
  46. $table->timestamp('pay_time')->nullable(); //付款时间
  47. $table->timestamp('send_time')->nullable(); //发货时间
  48. $table->timestamp('completion_time')->nullable(); //订单完成时间
  49. $table->timestamp('accept_time')->nullable(); //客户收货时间
  50. $table->string('message')->nullable(); //用户留言
  51. $table->integer('type')->default(0); //各种订单类型,拼团订单,秒杀订单,折扣订单等
  52. $table->string('cancel_reason')->nullable(); //取消原因
  53. $table->string('note')->nullable(); //管理员备注
  54. $table->timestamps();
  55. $table->softDeletes();
  56. });
  57. }
  58. if (!Schema::hasTable($prefix . 'order_item')) {
  59. Schema::create($prefix . 'order_item', function (Blueprint $table) {
  60. $table->increments('id');
  61. $table->integer('order_id')->unsigned();
  62. $table->integer('item_id')->unsigned();
  63. $table->string('item_name');
  64. $table->string('type');
  65. $table->text('item_meta')->nullable()->default(null);
  66. $table->integer('quantity')->unsigned(); //商品数量
  67. $table->integer('unit_price'); //商品单价
  68. $table->integer('units_total')->unsigned(); //商品总价 = unit_price * quantity
  69. $table->integer('adjustments_total')->default(0)->nullable(); //总的优惠金额,负数
  70. $table->integer('total'); //unitPrice * quantity + adjustmentsTotal
  71. $table->integer('shipping_id')->default(0); //发货ID
  72. $table->tinyInteger('is_send')->default(0); //是否已发货
  73. $table->timestamps();
  74. $table->softDeletes();
  75. });
  76. }
  77. if (!Schema::hasTable($prefix . 'order_adjustment')) {
  78. Schema::create($prefix . 'order_adjustment', function (Blueprint $table) {
  79. $table->increments('id');
  80. $table->integer('order_id')->unsigned()->nullable();
  81. $table->integer('order_item_id')->unsigned()->nullable();
  82. $table->integer('order_item_unit_id')->unsigned()->nullable();
  83. $table->string('type'); //优惠对象,订单, 商品,运费等
  84. $table->string('label')->nullable(); // 文案描述:"9折"
  85. $table->integer('amount')->default(0); //优惠金额,统一用分来表示
  86. $table->string('origin_type')->nullable(); //优惠类型 discount, coupon ,membership,vip
  87. $table->integer('origin_id')->default(0); //优惠券ID或者discount ID,或者用户组group id
  88. $table->timestamps();
  89. $table->softDeletes();
  90. });
  91. }
  92. if (!Schema::hasTable($prefix . 'order_comment')) {
  93. Schema::create($prefix . 'order_comment', function (Blueprint $table) {
  94. $table->increments('id');
  95. $table->integer('order_id')->unsigned()->default(0);
  96. $table->integer('order_item_id')->unsigned()->default(0);
  97. $table->integer('item_id')->unsigned()->default(0); //评价的商品,应该使用goods_id
  98. $table->text('item_meta')->nullable();
  99. $table->integer('user_id')->unsigned();
  100. $table->text('user_meta')->nullable();
  101. $table->text('contents')->nullable();
  102. $table->integer('point')->nullable()->defalut(0); //评价分数
  103. $table->string('status')->nullable(); //评价状态
  104. $table->text('pic_list')->nullable();//评价的图片
  105. $table->tinyInteger('recommend')->default(0);//是否推荐
  106. $table->timestamp('recommend_at')->nullable(); //推荐时间
  107. $table->timestamps();
  108. $table->softDeletes();
  109. });
  110. }
  111. }
  112. /**
  113. * Reverse the migrations.
  114. *
  115. * @return void
  116. */
  117. public function down()
  118. {
  119. $prefix = config('ibrand.app.database.prefix') ?? 'ibrand_';
  120. Schema::dropIfExists($prefix . 'order_comment');
  121. Schema::dropIfExists($prefix . 'order_adjustment');
  122. Schema::dropIfExists($prefix . 'order_item');
  123. Schema::dropIfExists($prefix . 'order');
  124. }
  125. }