2025_06_16_145512_create_ticket_logs_table.php 1.6 KB
<?php

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

class CreateTicketLogsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('gl_ticket_logs', function (Blueprint $table) {
            $table->id();
            $table->foreignId('ticket_id')->constrained('gl_tickets')->onDelete('cascade')->comment('工单ID');
            $table->unsignedInteger('engineer_id')->comment('处理人 gl_manage ID');
            $table->foreign('engineer_id')->references('id')->on('gl_manage')->onDelete('cascade');
            $table->longText('reply')->nullable()->comment('回复内容可以为空');
            $table->integer('status')->default(0)->index()->comment('工单状态,0:待处理, 1:处理中,2:已完成, 3:已关闭');
            $table->boolean('ding')->default(false)->index()->comment('钉钉通知');
            $table->timestamp('end_at')->nullable()->comment('结束时间,工单状态为已完成或已关闭时有值');
            $table->unique(['ticket_id', 'engineer_id'], 'ticket_engineer_unique');  # 唯一索引,防止同一工单被同一人多次操作,同一工单,可以多人协作
            $table->timestamps();
        });
        \Illuminate\Support\Facades\DB::statement("ALTER TABLE `gl_ticket_logs` comment '工单操作日志表,记录工单的分配处理任务等'");
    }

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