create_order_tables.php.stub 6.2 KB

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