<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateBusinessAfterSaleOrders extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('business_after_sale_orders', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->string('after_sales_biz_sn',100)->comment('售后单编号');
            $table->string('order_sn',100)->comment('父单编号');
            $table->integer('shop_id')->comment('门店id');
            $table->integer('after_sales_status')->default(0)->comment('售后单状态 
            0-未发起售后 1-退款中 2-退款成功 3-待处理 4-拒绝退款 6-待(顾客)退货 7-待(团长)确认退货 8-(顾客)撤销 9-(系统)关闭');
            $table->bigInteger('refund_amount')->default(0)->comment('退款金额');
            $table->bigInteger('refund_shipping_amount')->default(0)->comment('用户申请退运费金额');
            $table->string('description')->nullable()->comment('描述');
            $table->string('reason')->nullable()->comment('原因');
            $table->text('sub_extensions')->nullable()->comment('子单信息');
            $table->text('image_list')->nullable()->comment('图片列表');
            $table->text('return_goods_extension')->nullable()->comment('退款物流信息');
            $table->integer('apply_type')->default(0)->comment('售后单类型 0-仅退款 1-退货退款');
            $table->dateTime('after_sale_created_at')->nullable()->comment('售后单三方创建时间');
            $table->dateTime('after_sale_updated_at')->nullable()->comment('售后单三方更新时间');

            $table->unique(["shop_id",'order_sn'],"unique_shop_id_order_sn");
            $table->index('order_sn');
            $table->index(['after_sales_biz_sn',"apply_type"],"index_biz_sn_apply_type");
            $table->index('after_sale_created_at');
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('business_after_sale_orders');
    }
}
